In my current project I have a tree view with drag and drop functionality. Beneath this treeview there is a table, and its fields are shown or hidden depending on the type of row that is currently selected, so the visualised size of the table differs.
The treeview is placed inside a scrolled window. There are cases that if one clicks on the last visible row of the treeview, the uppopping table overlaps this last row. Now I want to scroll to the last row to make it visible again. So I wrote his code:
path = gtk_tree_model_get_path (model, &iter);
while (gtk_events_pending ()) // Delay until the scrolling can be done properly.
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (treeview), path, NULL, FALSE, 0, 0);
This works, the while loop is necessary because otherwise the srolling would be done before the table beneath the treeview has popped up.
But I figured out that the while loop causes some kind of problem. Sometimes when I click randomly on a row of the tree view and move the mouse somewhere else after the row has been selected, the row is dragged (so even with a single click, not the usual way by keeping the mouse pressed).
If I remove the while loop this is not happening. I am not sure but it seems also that this dragging effect does rarely occur when the size of the table does not change, for example when I click on two rows of the same type (the treeview displays a context menu structure), so if I click on a menu item and then on a menu item again, the dragging effect won't occur, but if I click on a row representing a separator and afterwards a row representing a menu item, the size of the table changes, and the dragging effect is more likely to occur.
The code above is always executed when one of the rows is clicked, since gtk_tree_view_scroll_to_cell (as far as I could gather from the documentation) does nothing anyway when a scolling is not necessary.
Since this may sound a bit abstact I placed a Linux 32-Bit binary (Gtk3) inside http://download-mirror.savannah.gnu.org ... ladi/test/
if somebody wants to see this, it's just necessary to load the supplied menu.xml afterwards and click for example on a separator first and then on a menu (there is a "type" column to differentiate them) so the size of the table beneath the treeview changes. Source is placed inside http://download-mirror.savannah.gnu.org ... s//obladi/
, the code above is placed at the very end of editing.c . Source is also attached to this posting, a menu file can be found at http://download-mirror.savannah.gnu.org ... ladi/test/
By the way I encountered this problem on a slower machine than I am usually used to work with. I can't remember having seen this effect (at least that often) on my faster machine I usually work with. So I wonder if this is a problem related to speed/time in connection with that while loop or something similar.
Linux used: Linux Mint 13 with mate, GTk 3.4