[Possible bug] Inserting nodes into ctree



Hi,

Using GTK+ 1.2.8, I have a problem in my application that can be reduced
to the following code:

/* sample code start */
#include <gtk/gtk.h>

void cb_row_selected(GtkCTree *tree, GtkCTreeNode *node, gint col,
		     gpointer gpo)
{
    gchar *data[] = { "new entry", NULL };
    gtk_signal_handler_block_by_func(GTK_OBJECT(tree),
				     GTK_SIGNAL_FUNC(cb_row_selected), NULL);
    gtk_ctree_insert_node(tree, NULL, NULL, data, 0, NULL, NULL, NULL, NULL,
			  FALSE, TRUE);
    gtk_signal_handler_unblock_by_func(GTK_OBJECT(tree),
				     GTK_SIGNAL_FUNC(cb_row_selected), NULL);
}

int main(int argc, gchar *argv[])
{
    GtkWidget *window, *ctree;
    gchar *data[] = { "first entry", NULL };
    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    ctree = gtk_ctree_new(1, 0);
    gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_EXTENDED);
    gtk_signal_connect(GTK_OBJECT(ctree), "tree_select_row",
                       GTK_SIGNAL_FUNC (cb_row_selected), NULL);
    gtk_ctree_insert_node(GTK_CTREE(ctree), NULL, NULL, data, 0, NULL, NULL,
			  NULL, NULL, FALSE, TRUE);
    gtk_container_add(GTK_CONTAINER(window), ctree);
    gtk_widget_show(ctree);
    gtk_window_set_default_size(GTK_WINDOW(window), 100, 200);
    gtk_widget_show(window);
    gtk_main();
    return(0);
}
/* sample code end */

As you can see, I want to add a node in the "tree_select_row" callback. If
I remove the "gtk_clist_set_selection_mode" line, this works perfectly.
Using GTK_SELECTION_EXTENDED, I first got a problem with endless recursion
because gtk_ctree_insert_node() would cause "tree_select_row" to be
emitted, which in turn activated my callback and so on. This is why I put
the gtk_signal_handler_block_by_func() call in there.

However, it still does not work: When I click on the first entry, the next
entry is added to the ctree, but not drawn -- it only appears when I click
the row *below* the first entry. When I do this a few times, the program
segfaults. Here is the top of the stack backtrace:

#0  0x40199eb5 in g_list_position () from /usr/lib/libglib-1.2.so.0
#1  0x40079e24 in gtk_ctree_link () from /usr/lib/libgtk-1.2.so.0
#2  0x4007cc1c in gtk_ctree_insert_node () from /usr/lib/libgtk-1.2.so.0
#3  0x8048b95 in cb_row_selected ()
[...]

I searched the mailing list archives for this, but could not find a thread
discussing it. If this is a known problem, I'd be grateful for a pointer.
I'll provide more information if needed.

Thanks,
Kind regards,
    Thomas Schultz




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