GtkTree*



hi jonathan,

i tried to wade my way through the GtkTree* API and test implemented
a list, i kept notes on my way so you got something to fix when you feel
bored ;)



GtkTreeView ignores GtkContainer::border_width


void (* changed) (GtkTreeView *tree_view); in _GtkTreeSelectionClass
should be GtkTreeSelection*.


setting up a static model for a treeview, then adding columns, then doing
gtk_tree_selection_select_path (tsel, path); doesn't result in a selection
because gtk_tree_view_setup_model() aborts on tree_view->priv->columns == NULL.
i guess you should setup tree_view->priv->tree as soon as the first column is
added (and you have a model). (though, i'm not sure why you can't setup the
rbtree right when you have a model and no columns yet).


static void
gtk_tree_selection_finalize (GObject *object)
{
  if (GTK_TREE_SELECTION (object)->destroy)
      (* GTK_TREE_SELECTION (object)->destroy) (GTK_TREE_SELECTION (object)->user_data);
}
you don't chain your parent class handler here. people should really develop
with GRUNTIME_DEBUG=objects which catches those things (or maybe i should do
the instance debugging hashtable lookups upon last-unref unconditionally
for --enable-debug=yes).


variables like:
  column->property_changed_signal =
          g_signal_connect_swapped (GTK_OBJECT (tree_view),
                                    "notify::model",
                                    GTK_SIGNAL_FUNC (gtk_tree_view_column_setup_sort_column_id_callback),
                                    column);
are better named _handler or _id, since you're storing a signal handler id
there, and not a signal id.


sinking objects:
  renderer = gtk_cell_renderer_text_new ();
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
                                                            -1, "Holiday",
                                                            renderer,
                                                            "text", HOLIDAY_COLUMN, NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
  g_object_unref (renderer);
the urnef here doesn't look right. cell renderers are GtkObjects and
those always need to get sunken, either you make them GObjects and then the
above code would be ok, or, if they need to stay GtkObjects,
gtk_tree_view_insert_column_with_attributes()
should ref+sink the renderer, and the g_object_unref() needs to vanish.


renderer::can_activate:
  g_object_class_install_property (object_class,
                                   PROP_CAN_ACTIVATE,
                                   g_param_spec_boolean ("can_activate",
                                                         _("can_activate"),
                                                         _("Cell can get activate events."),
                                                         FALSE,
                                                         G_PARAM_READABLE |
                                                         G_PARAM_WRITABLE));
i think renderer::activatable would be a better name, it sounds more
like a property. and we don't have anything literally like "activate events",
so you should probably say:        g_param_spec_boolean ("activatable",
                                                         _("Activatable"),
                                                         _("Cell receives activation events like "
                                                           "button presses or focus events."),
                                                         FALSE,
                                                         G_PARAM_READABLE |
                                                         G_PARAM_WRITABLE));


why is there gtk_tree_view_column_set_cell_renderer() if a
column can have multiple renderers? for that kind of
setup, there should only be add/remove or pack_{start|end}/remove
APIs.


gtk_tree_view_column_pack_start_cell_renderer(),
gtk_tree_view_column_pack_end_cell_renderer(),
the "_cell_renderer" is somewhat extraneous, the function names are
long enough already, and it's not like you could pack things other
than cell renderers into a column, right? (and even then, pack_start/end
could figure the object type on its own)


the treeview doesn't default-select an item for TREE_SELCTION_SINGLE
if there are any. alos, why is there GtkTreeSelectionMode, and not
just GtkSelectionMode being used with support for all four modes?


gtk_tree_path_new_from_string() should take "const" char.


all the gtk_tree_view_{insert|append|...}_column[_with_attributes]() API is
pretty clumsy. setting up a column is a fairly common task and should
be as convenient as possible. the first thing i did was coding up:
guint
gtk_tree_view_add_column (GtkTreeView       *tree_view,
                          gint               position,
                          GtkTreeViewColumn *column,
                          GtkCellRenderer   *cell,
                          const gchar       *attrib_name,
                          ...)
{
  guint n_cols;
  va_list var_args;

  g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), 0);
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (column), 0);
  g_return_val_if_fail (column->tree_view == NULL, 0);
  g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), 0);

  g_object_ref (column);
  g_object_ref (cell);
  gtk_object_sink (GTK_OBJECT (column));
  gtk_object_sink (GTK_OBJECT (cell));
  gtk_tree_view_column_pack_start_cell_renderer (column, cell, TRUE, TRUE, 2);

  va_start (var_args, attrib_name);
  while (attrib_name)
    {
      guint col = va_arg (var_args, guint);

      gtk_tree_view_column_add_attribute (column, cell, attrib_name, col);
      attrib_name = va_arg (var_args, const gchar*);
    }
  va_end (var_args);

  n_cols = gtk_tree_view_insert_column (tree_view, column, position);

  g_object_unref (column);
  g_object_unref (cell);

  return n_cols;
}
so i could setup columns with one renderer in a single statement:
  gtk_tree_view_add_column (GTK_TREE_VIEW (tree), -1,
                            g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
                                          "title", "MixFreq",
                                          "sizing", GTK_TREE_VIEW_COLUMN_RESIZABLE,
                                          NULL),
                            g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
                                          "xalign", 0.0,
                                          NULL),
                            "text", COL_MIX_FREQ,
                            NULL);


other convenience functions i felt need for:
void
gtk_tree_selection_select_spath (GtkTreeSelection *tree_selection,
                                 const gchar      *str_path)
{
  GtkTreePath *path;

  g_return_if_fail (GTK_IS_TREE_SELECTION (tree_selection));
  g_return_if_fail (str_path != NULL);

  path = gtk_tree_path_new_from_string (str_path);
  gtk_tree_selection_select_path (tree_selection, path);
  gtk_tree_path_free (path);
}
void
gtk_tree_selection_unselect_spath (GtkTreeSelection *tree_selection,
                                   const gchar      *str_path)
{
  GtkTreePath *path;

  g_return_if_fail (GTK_IS_TREE_SELECTION (tree_selection));
  g_return_if_fail (str_path != NULL);

  path = gtk_tree_path_new_from_string (str_path);
  gtk_tree_selection_unselect_path (tree_selection, path);
  gtk_tree_path_free (path);
}


---
ciaoTJ





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