GtkTreeView, the activate signal and dialogs don't interoperate well



Hi,

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.

It looks like a bug to me.

Also, the rows-reordered signal is never emitted on the TreeModel.

This is with gtk+ 2.2.1 from Debian testing/unstable.

René Seindal (rene seindal dk)


------------------------------------------------------------------------
#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;

}


------------------------------------------------------------------------

-- 
René Seindal (rene seindal dk)			http://sights.seindal.dk/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]