Re: A bug in GtkTree?



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

This isn't a bug, I don't think. What you need to do is call gtk_widget_ref
on the subtree, then remove the item and unref the subtree again..
>From the tutorial

If you remove all the items from a subtree, it will be destroyed and
unparented, unless you reference it beforehand, and the TreeItem which owns
it will be collapsed. So, if you want it to stick around, do something like
the following:


gtk_widget_ref (tree);
owner = GTK_TREE(tree)->tree_owner;
gtk_container_remove (GTK_CONTAINER(tree), item);
if (tree->parent == NULL){
  gtk_tree_item_expand (GTK_TREE_ITEM(owner));
  gtk_tree_item_set_subtree (GTK_TREE_ITEM(owner), tree);
}
else
  gtk_widget_unref (tree);


Hope that helps
Iain



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