A bug in GtkTree?



Greetings all,

[ I sent this e-mail to the list two weeks ago and had no reply, so I am
  resubmitting it. ]

I apologize in advance if I am submitting a bug report to this list in
error; but the GTK+ FAQ and the GNOME bug submission web page instructions
conflict on this issue (the FAQ suggests bug reports go to the mailing
list and http://bugs.gnome.org/Reporting.html suggests they are filed
to submit@bugs.gnome.org), and I figured this is the fastest way to make
others aware of the problem. That said:

I am using GTK+ 1.2.3. I believe there is a bug in how removal of subtree
elements is handled in the GtkTree widget. Here is what happens: if the last
item in a subtree is removed via gtk_container_remove() (and possibly by
other methods, I have not tried this), the subtree ceases being a subtree.
The +/- note disappears from the window and it seems like the subtree
is being treated as a simple GtkTreeItem. The GTK_IS_TREE assertion fails
if it is called on the subtree (and thus obviously nothing can be added
to it).

I have kludged around this problem by adding a check in my application
that recreates the subtree if it was destroyed by this side effect.
I assume this is a bug.

Attached is the simplest program I could come up with that shows this
problem (50 lines of code).

Regards,
Constantine Vetoshev
#include <gtk/gtk.h>


int main(int argc, char **argv)
{
   GtkWidget *window, *tree,
      *item_1, *subtree_1, *subitem_1,
      *item_2, *subtree_2, *subitem_2;

   gtk_init (&argc, &argv);

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_signal_connect (GTK_OBJECT(window), "delete_event",
		       GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
   gtk_container_set_border_width (GTK_CONTAINER(window), 0);

   tree = gtk_tree_new();
   gtk_tree_set_selection_mode(GTK_TREE(tree),
			       GTK_SELECTION_MULTIPLE);
   gtk_container_add(GTK_CONTAINER(window), tree);
   gtk_widget_show(tree);

   /* Add stuff. */
   item_1 = gtk_tree_item_new_with_label("One");
   gtk_tree_append(GTK_TREE(tree), item_1);
   gtk_widget_show(item_1);
   subtree_1 = gtk_tree_new();
   gtk_tree_item_set_subtree(GTK_TREE_ITEM(item_1), subtree_1);
   subitem_1 = gtk_tree_item_new_with_label("Sub One");
   gtk_tree_append(GTK_TREE(subtree_1), subitem_1);
   gtk_widget_show(subitem_1);

   item_2 = gtk_tree_item_new_with_label("Two");
   gtk_tree_append(GTK_TREE(tree), item_2);
   gtk_widget_show(item_2);
   subtree_2 = gtk_tree_new();
   gtk_tree_item_set_subtree(GTK_TREE_ITEM(item_2), subtree_2);
   subitem_2 = gtk_tree_item_new_with_label("Sub Two");
   gtk_tree_append(GTK_TREE(subtree_2), subitem_2);
   gtk_widget_show(subitem_2);

   /* Remove stuff. */
   gtk_container_remove(GTK_CONTAINER(subtree_2), subitem_2);

   /* Run. */
   gtk_widget_show(window);
   gtk_main();
   return 0;
}

PGP signature



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