Re: [gtk-list] Finding the parent tree of a GtkTreeItem



Quoting Chris Phelps (chicane@reninet.com):
> I need to find the parent tree of a GtkTreeItem that does not have a
> subtree. I know this must be possible, because
> gtk_tree_item_set_subtree() sets GtkTreeItem->subtree->root_tree to the
> parent tree of the original GtkTreeItem. I could hack this by setting a
> subtree for the GtkTreeItem and then getting the parent tree that way,
> but that seems a little crude, and I prefer not to code quite that badly
> if at all possible. If anyone knows how to find the GtkTree parent of a
> GtkTreeItem without a lot of hackish code, i would appreciate being
> informed.

I don't know exactly, what you intend to do, but i have this code
snippet (I need the text of the label from the parent of
all selected tree items:

GList *selection = GTK_TREE_SELECTION(Tree);

while (selection)
{
 GtkWidget *item = GTK_WIDGET(selection->data);

 /* the corresponding tree of the widget */
 GtkTree *my_tree = GTK_TREE(item->parent);

 /* does it have a daddy i.e. level >= 1 ? */
 if(my_tree->level) 
    {
     GtkTreeItem *daddy = GTK_TREE_ITEM(my_tree->tree_owner);

     gchar *text_daddy;
     gchar *text_son;

     /* get the caption of the selected item */
     gtk_label_get(GTK_LABEL(GTK_BIN(item)->child), &text_son);

     /* get the caption of its daddy */
     gtk_label_get(GTK_LABEL(GTK_BIN(daddy)->child), &text_daddy);
    }
}

I hope, this helps you.
I definitly think, something like that should go to the tutorial,
since i needed a long time to figure it out though it should be
an often performed task.

I'm sorry, but i am messing around with gtk for only one week now,
so i can't even tell you if i missed something obvious.

Bye,
Martin.

-- 
The early bird gets the worm. If you want something else for       
breakfast, get up later.



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