TreeModel and rows-reordered signal



Hi,

I have a problem with the rows-reordered signal for GtkTreeModel.  It
doesn't seem to be emitted.  I have the TreeView set to allow dnd
reordering, and it works, but I get no signal on the TreeModel as
expected.

I have libgtk2 version 2.2.1, installed from Debian testing/unstable.

Here is a sample program exibiting the problem.  It is possible to
reorder the rows, but the callback is never called, so the program
doesn't know the model has changed.

------------------------------------------------------------------------
#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");
}


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

    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]