RE: get text from GtkCTree



a) Ok, I suspect this is a list of child nodes beneath or at the same level.  If you look at the header file, you will find that GTK_CTREE_NODE is infact a definition for casting to a GList *node
 
b) I have had problems with this recently!  It seems that there has been a bug reported (if you look around the web for it) which means that if you want to get the text of a cell which is a parent node, the text returned is NULL.  Similarly I tried casting it back to its inherited GtkCList and getting the row text... that didnt work either.  As a result I had to use gtk_ctree_node_set_row_data.  When setting and getting you parse a gpointer, however, all you have to do is cast past it on both occasions.  Eg: If you wanted to pass a gchar*, you would do the following:
 
    gchar *mytext = "helloworld";
    GtkCTreeNode *node = NULL;
 
    ...
    node = gtk_ctree_node_insert(...);
    gtk_ctree_node_set_row_data(ctree,node,(gchar*)mytext);
    ...
 
    getmytext = (gchar*) gtk_ctree_node_get_row_data(ctree,node);
    ...
 
c) Unless you set data, you will (if you try to extract data) receive NULL when you call gtk_ctree_node_get_row_data
 
 
Also, be careful to make sure that the mytext variable you will be using doesn't get freed, or when you come to extract the data, it wont be what you expect, usually, I call g_strdup(mytext).  To clean the memory up, there is a function called: gtk_ctree_node_set_row_data_full which allows you to specify a destructor function for the data, I passed it (GtkDestroyNotify) g_free.  That seems to work fine (found here: http://developer.gnome.org/doc/API/gtk/gtkctree.html#GTK-CTREE-NODE-SET-ROW-DATA-FULL).
 
Regards,
 
Martyn
-----Original Message-----
From: Sunil Kumar K [mailto:sunilk_kumar hotmail com]
Sent: Sunday, May 19, 2002 10:43 AM
To: gtk-app-devel-list
Subject: get text from GtkCTree



In the mail dated : Fri, 25 Jan 2002 17:10:35 +1100
Ishan wanted to know how to get the text from a GtkCTree.
James Cameron replied :
void
on_tree_select_row                     (GtkCTree        *ctree,
                                        GList           *node,
                                        gint             column,
                                        gpointer         user_data)
{
  gchar *text = gtk_ctree_node_get_row_data
(ctree,GTK_CTREE_NODE(node));
}

a) What does "Glist *node" contain ?
b) What does the pointer returned from   "gtk_ctree_node_get_row_data(...)" contain ?
c) When I used it in my application, it returned NULL.
I used the following construct to try to get the text.
void
on_tree_select_row                     (GtkCTree        *ctree,
                                        GList           *node,
                                        gint             column,
                                        gpointer         user_data)
{
gchar *text;
text = g_malloc(25);                    // allocate memory to hold text
gtk_ctree_node_get_text(GTK_CTREE(ctree),GTK_CTREE_NODE(node), 0, &text);
g_print("\n Content = %s",text);        // Print the retrieved text on screen
}
Is the argument "GTK_CTREE_NODE(node)" right ?
The above mentioned get_text(...) function returns TRUE if text is present
but here it returns FALSE even when text IS Present ?
Where am I going wrong ?
Any other method to get the text from a CTree ?

SOMEBODY HELP ME !


Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com



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