Re: CTree "tree-expand" signal



faboo wrote:

(snipped quoted text)

I've also come accross this same problem with the "tree-select-row" signal of
the GtkCTree. Specifically, when the signal is called, I call a function to
get text from the row, like so:
<code>
void CTreeTreeSelectRow(GtkCTree *folders, GList *nodeList, gpointer object){
      char *text;
      gtk_ctree_node_get_text(folders, GTK_CTREE_NODE(node), 0, &text);
</code>
This call returns false, and 'text' is not filled. (This error showed up in
1.2.8 and 1.2.10)
Any thoughts anybody?

I was having the exact same problem yesterday (with GTK+ 1.2.8).  The
problem is that the gtk_ctree_node_get_text function will only work
with text-only cells.  If you have any pixtext cells, for example if
you are putting pixmaps in your CTree, then it will fail.

A fixed version (which adds code to handle pixtext cells) follows:

gint
gtk_ctree_node_get_text (GtkCTree      *ctree,
                         GtkCTreeNode  *node,
                         gint           column,
                         gchar        **text)
{
  g_return_val_if_fail (ctree != NULL, 0);
  g_return_val_if_fail (GTK_IS_CTREE (ctree), 0);
  g_return_val_if_fail (node != NULL, 0);

  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:
    if (text)
      *text = GTK_CELL_TEXT (GTK_CTREE_ROW(node)->row.cell[column])->text;
    return 1;
  case GTK_CELL_PIXTEXT:
    if (text)
      *text = GTK_CELL_PIXTEXT (GTK_CTREE_ROW(node)->row.cell[column])->text;

    if (*text)
      return 1;
  default:
  }

  return 0;
}

I would recommend renaming it and including it in your program's
source, so that your program remains compatible across as many GTK+
versions as possible.

I'll send a bug report once I have checked to see whether this has
been fixed already in later versions of GTK.

Jonathan





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