Re: [gtk-list] CTree confusion/bug
- From: andrew <andrew fangorn ryazan ru>
- To: Lee <lee0 callnetuk com>
- cc: gtk-list redhat com
- Subject: Re: [gtk-list] CTree confusion/bug
- Date: Fri, 23 Apr 1999 11:00:06 +0400 (MSD)
Hi, Lee.
On Thu, 22 Apr 1999, Lee wrote:
> Hi,
>
> I've run into some confusion while using the CTree widget.
> What I wish to do is a gtk_ctree_post_recursive call on a node, which
> will then refresh the pixmap of that node (leaving the text label
> intact), according to some condition.
>
> However, the result I get is that the pixmap is changed, but the labels
> are for the most part completely garbled.
>
> I have included a function below, which when called from a
> gtk_ctree_post_recursive() shows the problem.
> I can send the entire test program which demonstrates this, if required,
> but I suspect the problem is more likely a misunderstanding on my part.
>
> Here's a test function I'm using...
>
> void pixmap_refresh (GtkCTree *tree, GtkCTreeNode *node) {
> extern int state;
> guint8 spaces;
> gchar *node_text;
> gboolean is_a_leaf, open;
> GdkBitmap *red_file_map, *orange_file_map;
> GdkPixmap *red_file, *orange_file;
> GtkStyle *style;
> style = gtk_widget_get_style (window1);
>
> /* Just creating 2 GdkPixmap's */
> orange_file = gdk_pixmap_create_from_xpm_d (window1->window,
> &orange_file_map,
> &style->bg[GTK_STATE_NORMAL],
> (gchar **) orange_file_xpm);
> red_file = gdk_pixmap_create_from_xpm_d (window1->window,
> &red_file_map,
> &style->bg[GTK_STATE_NORMAL],
> (gchar **) red_file_xpm);
>
> node_text = (gchar *) malloc (100);
> memset (node_text, 0, 100);
Delete two previous lines.
>
>
> /* Get everything about the node except the pixmaps */
> gtk_ctree_get_node_info (GTK_CTREE (tree),
> GTK_CTREE_NODE (node),
> &node_text, &spaces,
> NULL, NULL, NULL, NULL,
> &is_a_leaf, &open);
> /* printf shows the node label to have been grabbed correctly. */
> printf ("Node label is %s.\n", node_text);
>
Insert here the following command:
node_text = g_strdup(node_text);
> /* Dependant upon state, change the node's pixmap fields */
> if (state == 1) {
> gtk_ctree_set_node_info (GTK_CTREE (tree),
> GTK_CTREE_NODE (node),
> node_text,
> spaces, orange_file, orange_file_map,
> orange_file, orange_file_map,
> is_a_leaf, open);
> } else {
> gtk_ctree_set_node_info (GTK_CTREE (tree),
> GTK_CTREE_NODE (node),
> node_text,
> spaces, red_file, red_file_map,
> red_file, red_file_map,
> is_a_leaf, open);
> }
And here insert the next line:
g_free(node_text);
> }
When you call gtk_ctree_set_node_info, it destroys old label of the node
and only after that it set new label to your new text. But in your case
old and new labels are the same pointers :(
Andrew Klochkov
andrew@fangorn.ryazan.ru
p.s. sorry for my english, i'm russian :)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]