View Issue Details

IDProjectCategoryView StatusLast Update
0019820LazarusWidgetsetpublic2011-12-25 19:15
ReporterBart BroersmaAssigned ToZeljan Rikalo 
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSSuse LinuxOS Version10.0
Product Version0.9.30.1 (SVN)Product Build31810 
Target Version1.0.0Fixed in Version0.9.31 (SVN) 
Summary0019820: TListView: cannot select items (gtk2 2.8.3-4)
DescriptionI cannot select any item from a TListView, neither by mouse nor by keyboard.

It is however possible to select items by code (setting ItemIndex or Selected).
Steps To ReproduceBuild and run attached sample project.

Try and select item 0 from the listbox and press Button1

Expected output:
ListView1.Selected.Caption = Item0
ListView1.ItemIndex = 0

Observed output:
ListView1.ItemIndex = -1
ListView1: nothing selected


Press Button2
Now an item gets selected (at random) and the output is something like
ListView1.ItemIndex = 2
ListView1.Selected.Caption = Item2

However visually I cannot see any feedback that an item is selected in the ListView at all.
Additional InformationThis bug seems to be the main culprit for bug 0019819

Tested only (so far) on Suse 10.0

bart@simenon:~> uname -a
Linux simenon 2.6.13-15-default 0000001 Tue Sep 13 14:56:15 UTC 2005 i686 i686 i386 GNU/Linux
bart@simenon:~> rpm -q gtk2
gtk2-2.8.3-4
TagsNo tags attached.
Fixed in Revision34355
LazTarget1.0
WidgetsetGTK 2
Attached Files

Relationships

parent of 0019819 closedJuha Manninen IDE crash on File -> New .. -> Inherited Project Component 
related to 0020554 closedJuha Manninen GTK2 Listview: stefocus patch for GTK_IS_ICON_VIEW(MainView) 

Activities

2011-07-27 14:16

 

listviewbug.tgz (2,247 bytes)

Bart Broersma

2011-07-27 15:00

developer   ~0050209

Works fine on Win32, so it is a widgetset problem.

Bart Broersma

2011-07-28 12:00

developer   ~0050231

Tested the binary compiled on Suse (see above) with Ubuntu (GTK2 2.24): works just fine.
So it seems to be yet another GTK version issue.

Mike Thompson

2011-07-30 09:22

developer   ~0050278

I've been hammering TListView under GTK2 quite hard - I've got GTK2 2.24. I've witnessed this once or twice using the latest copy of gtk2wscustomlistview.inc from SVN. Unfortunately I haven't worked out the exact sequence I need to go through to reproduce - but just letting you know at least a variation of this issue appears unrelated to the GTK2 version.

Bart Broersma

2011-07-30 16:22

developer   ~0050285

FWIW: rebuilding LCL with -dGTK_2_8 has no influence on the subject.

Felipe Monteiro de Carvalho

2011-08-03 14:38

developer   ~0050400

The default minimum Gtk version is hard-coded to 2.8 in the Free Pascal Gtk units. Functions from newer versions are dynamically loaded if they exist in the system. On top of that, GTK_2_8 is also defined in gtk2includes.inc in the LCL. So -dGTK_2_8 would never change anything.

Bart Broersma

2011-08-03 18:22

developer   ~0050407

Last edited: 2011-08-03 18:40

@Felipe: why not just remove these then?

Probably not related, but take a look at this code (appr. line 1298 of gtk2customlistview.inc)

        {$IFDEF GTK_2_8}
          else
          if GTK_IS_ICON_VIEW(MainView) then
          begin
            if AIsSet then
              gtk_icon_view_set_cursor(PGtkIconView(MainView), Path, nil, False)
            else
              gtk_icon_view_set_cursor(PGtkIconView(MainView), Path, nil, False);
          end
        {$ENDIF};

Isn't this a little strange: the same action is performed if AIsSet is True or False...

Mike Thompson

2011-08-07 20:09

developer   ~0050595

Last edited: 2011-08-08 03:46

Good pick up there Bart, looks like a copy paste issue. The second set_cursor should read gtk_icon_view_set_cursor(PGtkIconView(MainView), nil, nil, False). There's only limited visual support in the icon view for focussed items which is probably why no-one has picked up on the error before. However I've confirmed that changing the second line ensures the corrected line now causes the item to lose focus. However, as you said, this probably isn't related to the bug as it's in code to set Focus, not Selection

Bart Broersma

2011-08-09 13:20

developer   ~0050640

@Mike: can you create a new issue for this in the bugtracker and attach a patch?
As you can understand, I obviously can't test this...

Bart Broersma

2011-10-24 17:40

developer   ~0053370

FWIW: I can see Gtk2WSLV_ItemSelected being called if I click on an item, and gtk_tree_path_get_indices(path)^ indeed holds the correct value.

Zeljan Rikalo

2011-10-24 18:30

developer   ~0053372

@Bart, problem is that developers don't use such old gtk, so cannot make tests.
It will be hard to fix without your help.
I'll dig into now and make some cleanups.

Zeljan Rikalo

2011-10-24 18:44

developer   ~0053373

@Bart, you should check
TGtk2WSCustomListView.ItemSetState and lisSelected part.
lisSelected:
begin
  Path := gtk_tree_path_new_from_string(PChar(IntToStr(AIndex)));
  if GTK_IS_TREE_VIEW(MainView) then
  begin
    // Try to see what returns
    // gtk_tree_selection_path_is_selected(TreeSelection, Path)
    // if your listview returns correct
    // then after gtk_tree_path_free(Path) add one gtk_queue_draw(MainView);
    if AIsSet and not gtk_tree_selection_path_is_selected(TreeSelection, Path) then
      gtk_tree_selection_select_path(TreeSelection, Path)
    else
    // Try to see what returns
    // gtk_tree_selection_path_is_selected(TreeSelection, Path)
    if not AIsSet and gtk_tree_selection_path_is_selected(TreeSelection, Path) then
      gtk_tree_selection_unselect_path(TreeSelection, Path);
  end else
  if GTK_IS_ICON_VIEW(MainView) then
  begin
    if AIsSet and not gtk_icon_view_path_is_selected(PGtkIconView(MainView), Path) then
      gtk_icon_view_select_path(PGtkIconView(MainView), Path)
    else
    if not AIsSet and gtk_icon_view_path_is_selected(PGtkIconView(MainView), Path) then
      gtk_icon_view_unselect_path(PGtkIconView(MainView), Path);
  end;
  gtk_tree_path_free(Path);
end;

Bart Broersma

2011-10-25 15:40

developer   ~0053427

@Zeljan

I attached an example program (so you can see what I'm doing)
This is the output when I run the program:

bart@simenon:~> ~/LazarusProjecten/bugs/ListView/test

(test:6184): Gtk-CRITICAL **: gtk_tree_view_set_cursor_on_cell: assertion `path != NULL' failed
TGtk2WSCustomListView.ItemSetState: lisSelected
  AIndex = 0
  AIsSet = False
  Assigned(AItem) = True
  AItem.Caption = Item0
  gtk_tree_selection_path_is_selected(TreeSelection, Path) = False

(test:6184): Gtk-CRITICAL **: gtk_tree_view_set_cursor_on_cell: assertion `path != NULL' failed
TGtk2WSCustomListView.ItemSetState: lisSelected
  AIndex = 1
  AIsSet = False
  Assigned(AItem) = True
  AItem.Caption = Item1
  gtk_tree_selection_path_is_selected(TreeSelection, Path) = False

(test:6184): Gtk-CRITICAL **: gtk_tree_view_set_cursor_on_cell: assertion `path != NULL' failed
TGtk2WSCustomListView.ItemSetState: lisSelected
  AIndex = 2
  AIsSet = False
  Assigned(AItem) = True
  AItem.Caption = Item2
  gtk_tree_selection_path_is_selected(TreeSelection, Path) = False


I guess the three itmes are created here.
Note the Gtk-CRITICAL (3x)

Clicking on the listview does nothing at all.

Now setting ItemIndex by code:

TForm1.Button3Click: setting ItemIndex := 0
TGtk2WSCustomListView.ItemSetState: lisSelected
  AIndex = 0
  AIsSet = True
  Assigned(AItem) = True
  AItem.Caption = Item0
  gtk_tree_selection_path_is_selected(TreeSelection, Path) = False
  // we end up here: AIsSet and not gtk_tree_selection_path_is_selected(TreeSelection, Path)
  gtk_tree_selection_select_path(TreeSelection, Path)
  gtk_tree_selection_path_is_selected(TreeSelection, Path) = False
TForm1.Button3Click end.

Notice that gtk_tree_selection_path_is_selected remaisn False, even after gtk_tree_selection_select_path.

B.t.w. I couldn't find gtk_queue_draw() anywhere, so I did not test it.

2011-10-25 15:41

 

listview-test.tgz (3,585 bytes)

Zeljan Rikalo

2011-10-25 20:21

developer   ~0053434

Ok, then just try (in lisSelected)
if AIsSet then
  gtk_tree_selection_select_path(TreeSelection, Path)
else
  gtk_tree_selection_unselect_path(TreeSelection, Path);

Bart Broersma

2011-10-26 23:59

developer   ~0053490

Tried that, makes no difference (as compared to note 0053427).

Zeljan Rikalo

2011-10-27 16:33

developer   ~0053501

Then you have to find root of problems by your self and prepare patch.
Just separate it from current implementation using
 if gtk_version_major = 2 and gtk_version_minor < 10 then ...

Bart Broersma

2011-10-28 18:23

developer   ~0053553

I have been playing with this for some time now, and I really have no clue where to look further.
I can find my way (just a little) into the win32 widgetset, but I cannot get the grasp on GTK.
I'll let it lie for a while.
Anyhow, thanks for trying and donating time.

Zeljan Rikalo

2011-10-30 12:06

developer   ~0053628

Oldest gtk2 I have is 2.12 and there it works fine.

Juha Manninen

2011-11-17 21:13

developer   ~0054173

Bart, does this still happen to you?

Bart Broersma

2011-12-03 14:21

developer   ~0054666

Still there in r33911

Bernd Kreuss

2011-12-20 14:50

reporter   ~0055182

Last edited: 2011-12-20 15:14

I assume a regression must have been introduced recently regarding the selection of items in TListView with all the bug fixing in TListView going on. Here on GTK2 (quite old version that came with Ubuntu Hardy)

$ pkg-config --modversion gtk+-2.0
2.12.9

I can select items (so strictly speaking I am not affected by *this* bug) but in the OnSelectItem event in the event procedure there suddenly is now a difference between TListView.Selected (which is correct) and the Item argument passed to this procedure which now always is the item that was *previously* selected. (see attached TListView_2_bugs_GTK2.tar.gz)

It does not happen when selecting with the keyboard.

I'm 99.9% sure that this bug has definitely not always been there but it could have been introduced months ago already (because didn't use it for a while). If you fix this selection bug (and maybe others too) then please also test with the attached demo program TListView_2_bugs_GTK2.tar.gz which demonstrates the discrepancy between TListView.Selected and Item in the event procedure.

If this is a totally separate bug then I can also file a separate bug but I suspect it is somehow related.

2011-12-20 14:57

 

TListView_2_bugs_GTK2.tar.gz (66,349 bytes)

Juha Manninen

2011-12-20 16:24

developer   ~0055185

Last edited: 2011-12-20 16:55

Bernd, I found my old similar case for QT, but it works with all widgetsets now:
 http://bugs.freepascal.org/view.php?id=16712

Your issue is a user error. You forgot the "Selected" parameter. Try this and you get an idea of what is happening:

procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
begin
  ShowMessage('item: ' + Item.Caption + ', Selected: ' + BoolToStr(Selected, True));
  if Selected then
    Caption := 'Item.Caption / ListView1.Selected.Caption ---- ' +
              Item.Caption + ' / ' + ListView1.Selected.Caption;
end;


OnClick event may be better for your needs.

Bernd Kreuss

2011-12-20 19:11

reporter   ~0055187

Oh... I see. this was my error, I stand corrected.

Zeljan Rikalo

2011-12-21 09:43

developer   ~0055197

But right click (when context menu is shown), doesn't select item, so that's bug.

Zeljan Rikalo

2011-12-21 09:53

developer   ~0055198

Downgraded gtk to 2.10 and selection works ... now must find 2.8 and build rpms...

Zeljan Rikalo

2011-12-21 17:38

developer   ~0055205

Please test and close if ok.
NOTE: I've tested with 2.8.15 (cannot compile anything under that version).
Also, looked into changes of 2.8 and there was some changes in treeview selections in 2.8.7(9) (can be related).

Bart Broersma

2011-12-25 19:15

developer   ~0055282

Fixed. Thanks for all your time!!!!!

Issue History

Date Modified Username Field Change
2011-07-27 14:16 Bart Broersma New Issue
2011-07-27 14:16 Bart Broersma File Added: listviewbug.tgz
2011-07-27 14:16 Bart Broersma LazTarget => -
2011-07-27 14:16 Bart Broersma Widgetset => GTK 2
2011-07-27 14:17 Bart Broersma Relationship added parent of 0019819
2011-07-27 15:00 Bart Broersma Note Added: 0050209
2011-07-27 15:00 Bart Broersma Category LCL => Widgetset
2011-07-28 12:00 Bart Broersma Note Added: 0050231
2011-07-28 13:38 Bart Broersma Summary TListView: cannot select items => TListView: cannot select items (gtk2 2.8.3-4)
2011-07-30 09:22 Mike Thompson Note Added: 0050278
2011-07-30 16:22 Bart Broersma Note Added: 0050285
2011-08-03 14:38 Felipe Monteiro de Carvalho Note Added: 0050400
2011-08-03 18:22 Bart Broersma Note Added: 0050407
2011-08-03 18:40 Bart Broersma Note Edited: 0050407
2011-08-03 18:40 Bart Broersma Note Edited: 0050407
2011-08-07 20:09 Mike Thompson Note Added: 0050595
2011-08-08 03:46 Mike Thompson Note Edited: 0050595
2011-08-09 13:20 Bart Broersma Note Added: 0050640
2011-10-06 14:13 Vincent Snijders LazTarget - => 1.0
2011-10-06 14:13 Vincent Snijders Status new => acknowledged
2011-10-06 14:13 Vincent Snijders Target Version => 1.0.0
2011-10-24 17:40 Bart Broersma Note Added: 0053370
2011-10-24 18:30 Zeljan Rikalo Note Added: 0053372
2011-10-24 18:44 Zeljan Rikalo Note Added: 0053373
2011-10-24 23:51 Juha Manninen Relationship added related to 0020554
2011-10-25 15:40 Bart Broersma Note Added: 0053427
2011-10-25 15:41 Bart Broersma File Added: listview-test.tgz
2011-10-25 20:21 Zeljan Rikalo Note Added: 0053434
2011-10-26 23:59 Bart Broersma Note Added: 0053490
2011-10-27 16:33 Zeljan Rikalo Note Added: 0053501
2011-10-27 16:33 Zeljan Rikalo Status acknowledged => feedback
2011-10-28 18:23 Bart Broersma Note Added: 0053553
2011-10-28 18:24 Bart Broersma Status feedback => acknowledged
2011-10-30 12:06 Zeljan Rikalo Note Added: 0053628
2011-11-17 21:13 Juha Manninen Note Added: 0054173
2011-11-17 21:13 Juha Manninen Status acknowledged => feedback
2011-12-03 14:21 Bart Broersma Note Added: 0054666
2011-12-20 14:50 Bernd Kreuss Note Added: 0055182
2011-12-20 14:57 Bernd Kreuss File Added: TListView_2_bugs_GTK2.tar.gz
2011-12-20 15:14 Bernd Kreuss Note Edited: 0055182
2011-12-20 16:24 Juha Manninen Note Added: 0055185
2011-12-20 16:51 Juha Manninen Note Edited: 0055185
2011-12-20 16:55 Juha Manninen Note Edited: 0055185
2011-12-20 19:11 Bernd Kreuss Note Added: 0055187
2011-12-21 09:43 Zeljan Rikalo Note Added: 0055197
2011-12-21 09:53 Zeljan Rikalo Note Added: 0055198
2011-12-21 17:38 Zeljan Rikalo Fixed in Revision => 34355
2011-12-21 17:38 Zeljan Rikalo Status feedback => resolved
2011-12-21 17:38 Zeljan Rikalo Resolution open => fixed
2011-12-21 17:38 Zeljan Rikalo Assigned To => Zeljan Rikalo
2011-12-21 17:38 Zeljan Rikalo Note Added: 0055205
2011-12-25 19:15 Bart Broersma Status resolved => closed
2011-12-25 19:15 Bart Broersma Note Added: 0055282
2011-12-25 19:15 Bart Broersma Fixed in Version => 0.9.31 (SVN)