Re: [gtk-list] [PATCH] Code examples for CTree in EXTENDED selection mode?

> Anybody have any examples of how to get at the text on selected lines
> of a CTree?  I attempted to use the row accessor functions on the embedded
> CList but got a core dump.  Any help/examples would be appreciated.

I've had a problem with this myself before, but I never bothered to
look closely enough at it until now. As it turns out, there's a bug in
gtk+ which needs fixing -- a suitable patch is below (applies to
1.1.13, don't know about other versions).

It's probably the same problem that you're experiencing -- the
function "gtk_ctree_node_get_text" will not return text if the cell is
of type "PIXTEXT", i.e. contains its own pixmaps as well. Anyway, here
is a callback for printing the strings at each selected node:

  void print_node(gpointer data, gpointer user_data)
    GtkCTreeNode *node = GTK_CTREE_NODE(data);
    GtkCTree *tree = GTK_CTREE(user_data);
    gchar *text;
     if (gtk_ctree_node_get_text(tree, node, 0, &text))
         g_print("Text is %s\n", text);	

Call this using:

  g_list_foreach(GTK_CLIST(tree)->selection, print_node, (gpointer)tree);

Which works fine once the patch below has been applied to gtk+.

Matt Aubury

diff -u ../gtk+-1.1.13/gtk/gtkctree.c gtk/gtkctree.c 
--- ../gtk+-1.1.13/gtk/gtkctree.c       Thu Jan 21 12:20:11 1999
+++ gtk/gtkctree.c      Thu Jan 21 11:59:54 1999
@@ -4845,8 +4845,15 @@
   if (column < 0 || column >= GTK_CLIST (ctree)->columns)
     return 0;
-  if (GTK_CTREE_ROW (node)->row.cell[column].type != GTK_CELL_TEXT)
-    return 0;
+  switch (GTK_CTREE_ROW (node)->row.cell[column].type)
+    {
+    case GTK_CELL_TEXT:
+      break;
+    default:
+      return 0;
+    }
   if (text)
     *text = GTK_CELL_TEXT (GTK_CTREE_ROW (node)->row.cell[column])->text;

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