GNOME Bugzilla – Bug 113904
GtkTreeView, dialogs and the activate signal
Last modified: 2011-02-04 16:12:02 UTC
I have run into a problem with a GtkTreeView. A small demonstration program is included below. I have a GtkTreeView which is reorderable. I have attached a function to the row_activated signal that pops up a dialog. When the dialog is closed and the mouse re-enteres the TreeView, it behaves as if a drag has been initated to reorder the entries of the view. I have tried running the dialog from an idle function, and it makes no difference. Apparently the idle function gets to run before the button release is sent to the TreeView, enticing the view to think a draw has been initiated. I have also tried with a timeout, and it seems to work if the timeout is on the order of 100ms, but that is going to be dependent on computer speed and load. Also it doesn't matter if the dialog is modal or not. On a side note, the rows-reordered does not appear to be emitted on the model when the view is reordered. This is with gtk+ 2.2.1 from Debian testing/unstable. Demonstration program: ------------------------------------------------------------------------ #include <gtk/gtk.h> #include <stdio.h> enum {STRING_COLUMN=0}; static GtkTreeModel * FillStore(void) { GtkTreeModel *result = GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_STRING)); GtkTreeIter iter; char tmp[4]; int i; for (i=0; i<50; i+=5){ snprintf((char*)tmp, 4, "%d", i); gtk_list_store_append(GTK_LIST_STORE(result), &iter); gtk_list_store_set(GTK_LIST_STORE(result), &iter, STRING_COLUMN, tmp, -1); } return result; } void callback(GtkTreeModel *treemodel, GtkTreePath *arg1, GtkTreeIter *arg2, gpointer arg3, gpointer user_data) { printf("Callback\n"); } void activate(GtkTreeView *tree_view, gpointer user_data) { GtkWidget *dialog = gtk_dialog_new_with_buttons ("My dialog", NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); gint result = gtk_dialog_run (GTK_DIALOG (dialog)); switch (result) { case GTK_RESPONSE_ACCEPT: printf("DIALOG Accept\n"); break; default: printf("DIALOG Cancel\n"); break; } gtk_widget_destroy (dialog); } int main (int argc, char *argv[]) { GtkWidget *window = NULL; GtkWidget *tree_view = NULL; GtkWidget *vb = NULL; GtkWidget *sw = NULL; GtkCellRenderer *renderer = NULL; GtkTreeViewColumn *column = NULL; GtkTreeModel * model; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(window, 150, 200); vb = gtk_vbox_new (FALSE, 8); gtk_container_add (GTK_CONTAINER (window), vb); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (vb), sw, TRUE, TRUE, 0); model = FillStore (); tree_view=gtk_tree_view_new_with_model(model); g_signal_connect (G_OBJECT (tree_view), "row_activated", G_CALLBACK (activate), NULL); gtk_tree_view_set_reorderable (GTK_TREE_VIEW(tree_view), TRUE); g_signal_connect (G_OBJECT (model), "rows-reordered", G_CALLBACK (callback), NULL); // gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), 0); gtk_container_set_border_width(GTK_CONTAINER(window), 3); gtk_container_add(GTK_CONTAINER(sw), tree_view); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes ("Some numbers", renderer, "text", STRING_COLUMN, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); gtk_widget_show_all(window); gtk_main(); return 0; } ------------------------------------------------------------------------
> On a side note, the rows-reordered does not appear to be emitted on > the model when the view is reordered. When a row is moved using a drag, the row will be deleted and re-inserted internally, so you won't get a rows-reordered signal but a row-deleted/row-inserted pair. The rows-reordered signal is used when sorting. Other issue will be hopefully fixed for 2.2.3.
Created attachment 17806 [details] [review] propsed patch
Doh, there's a silly typo in the patch. The "=" in the first if should of course be "==". Also with this change the patch works.
*** Bug 116263 has been marked as a duplicate of this bug. ***
Committed on gtk-2-2 and HEAD.