[gtk+/treeview-refactor-staging] Added GtkTreeViewColumn:cell-area construct-only property.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/treeview-refactor-staging] Added GtkTreeViewColumn:cell-area construct-only property.
- Date: Wed, 1 Dec 2010 14:24:18 +0000 (UTC)
commit 197eb47e146908d323f11fa3f7c461234328b16e
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Wed Dec 1 23:26:25 2010 +0900
Added GtkTreeViewColumn:cell-area construct-only property.
Allow feeding treeviewcolumn a custom cell-area (or not a custom one,
but allow sharing the cell-area with say, the combo-box area).
This patch also:
- Fixes signal connections to the area (now they do eventually get
disconnected at dispose time, they are handled regardless if a
treeview is set but execute safely, at least there is only one
connection/disconnection).
- Fixes refcounting on the cell_area (GtkCellArea is GInitiallyUnowned).
- Adds a constructor() in order to build the cell-area if one has
not been provided by the caller before hand at g_object_new()
construct time.
gtk/gtktreeviewcolumn.c | 113 +++++++++++++++++++++++++++++++++++++----------
1 files changed, 90 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index 0232955..0278e57 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -70,6 +70,9 @@ static void gtk_tree_view_column_get_property (GObject
GParamSpec *pspec);
static void gtk_tree_view_column_finalize (GObject *object);
static void gtk_tree_view_column_dispose (GObject *object);
+static GObject *gtk_tree_view_column_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties);
/* GtkCellLayout implementation */
static GtkCellArea *gtk_tree_view_column_cell_layout_get_area (GtkCellLayout *cell_layout);
@@ -190,7 +193,8 @@ enum
PROP_REORDERABLE,
PROP_SORT_INDICATOR,
PROP_SORT_ORDER,
- PROP_SORT_COLUMN_ID
+ PROP_SORT_COLUMN_ID,
+ PROP_CELL_AREA
};
enum
@@ -217,6 +221,7 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
class->clicked = NULL;
+ object_class->constructor = gtk_tree_view_column_constructor;
object_class->finalize = gtk_tree_view_column_finalize;
object_class->dispose = gtk_tree_view_column_dispose;
object_class->set_property = gtk_tree_view_column_set_property;
@@ -390,6 +395,21 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
-1,
GTK_PARAM_READWRITE));
+ /**
+ * GtkTreeViewColumn:cell-area:
+ *
+ * The #GtkCellArea used to layout cell renderers for this column.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (object_class,
+ PROP_CELL_AREA,
+ g_param_spec_object ("cell-area",
+ P_("Cell Area"),
+ P_("The GtkCellArea used to layout cells"),
+ GTK_TYPE_CELL_AREA,
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
g_type_class_add_private (class, sizeof (GtkTreeViewColumnPrivate));
}
@@ -441,15 +461,47 @@ gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
priv->fixed_width = 1;
priv->use_resized_width = FALSE;
priv->title = g_strdup ("");
+}
+
+static GObject *
+gtk_tree_view_column_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
+{
+ GtkTreeViewColumn *tree_column;
+ GtkTreeViewColumnPrivate *priv;
+ GObject *object;
+
+ object = G_OBJECT_CLASS (gtk_tree_view_column_parent_class)->constructor
+ (type, n_construct_properties, construct_properties);
+
+ tree_column = (GtkTreeViewColumn *) object;
+ priv = tree_column->priv;
+
+ if (!priv->cell_area)
+ {
+ priv->cell_area = gtk_cell_area_box_new ();
+ g_object_ref_sink (priv->cell_area);
+ }
- priv->cell_area = gtk_cell_area_box_new ();
gtk_cell_area_set_style_detail (priv->cell_area, "treeview");
+
+ priv->add_editable_signal =
+ g_signal_connect (priv->cell_area, "add-editable",
+ G_CALLBACK (gtk_tree_view_column_add_editable_callback),
+ tree_column);
+ priv->remove_editable_signal =
+ g_signal_connect (priv->cell_area, "remove-editable",
+ G_CALLBACK (gtk_tree_view_column_remove_editable_callback),
+ tree_column);
+
priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
priv->context_changed_signal =
g_signal_connect (priv->cell_area_context, "notify",
G_CALLBACK (gtk_tree_view_column_context_changed), tree_column);
+ return object;
}
static void
@@ -471,8 +523,15 @@ gtk_tree_view_column_dispose (GObject *object)
if (priv->cell_area)
{
+ g_signal_handler_disconnect (priv->cell_area,
+ priv->add_editable_signal);
+ g_signal_handler_disconnect (priv->cell_area,
+ priv->remove_editable_signal);
+
g_object_unref (priv->cell_area);
priv->cell_area = NULL;
+ priv->add_editable_signal = 0;
+ priv->remove_editable_signal = 0;
}
if (priv->child)
@@ -502,6 +561,7 @@ gtk_tree_view_column_set_property (GObject *object,
GParamSpec *pspec)
{
GtkTreeViewColumn *tree_column;
+ GtkCellArea *area;
tree_column = GTK_TREE_VIEW_COLUMN (object);
@@ -586,6 +646,14 @@ gtk_tree_view_column_set_property (GObject *object,
gtk_tree_view_column_set_sort_column_id (tree_column,
g_value_get_int (value));
break;
+
+ case PROP_CELL_AREA:
+ /* Construct-only, can only be assigned once */
+ area = g_value_get_object (value);
+
+ if (area)
+ tree_column->priv->cell_area = g_object_ref_sink (area);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -689,6 +757,10 @@ gtk_tree_view_column_get_property (GObject *object,
g_value_set_int (value,
gtk_tree_view_column_get_sort_column_id (tree_column));
break;
+
+ case PROP_CELL_AREA:
+ g_value_set_object (value, tree_column->priv->cell_area);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1188,15 +1260,18 @@ gtk_tree_view_column_add_editable_callback (GtkCellArea *area,
GtkTreeViewColumnPrivate *priv = column->priv;
GtkTreePath *path;
- path = gtk_tree_path_new_from_string (path_string);
-
- _gtk_tree_view_add_editable (GTK_TREE_VIEW (priv->tree_view),
- column,
- path,
- edit_widget,
- cell_area);
-
- gtk_tree_path_free (path);
+ if (priv->tree_view)
+ {
+ path = gtk_tree_path_new_from_string (path_string);
+
+ _gtk_tree_view_add_editable (GTK_TREE_VIEW (priv->tree_view),
+ column,
+ path,
+ edit_widget,
+ cell_area);
+
+ gtk_tree_path_free (path);
+ }
}
static void
@@ -1208,9 +1283,10 @@ gtk_tree_view_column_remove_editable_callback (GtkCellArea *area,
GtkTreeViewColumn *column = user_data;
GtkTreeViewColumnPrivate *priv = column->priv;
- _gtk_tree_view_remove_editable (GTK_TREE_VIEW (priv->tree_view),
- column,
- edit_widget);
+ if (priv->tree_view)
+ _gtk_tree_view_remove_editable (GTK_TREE_VIEW (priv->tree_view),
+ column,
+ edit_widget);
}
/* Exported Private Functions.
@@ -1307,15 +1383,6 @@ _gtk_tree_view_column_set_tree_view (GtkTreeViewColumn *column,
priv->tree_view = GTK_WIDGET (tree_view);
gtk_tree_view_column_create_button (column);
- priv->add_editable_signal =
- g_signal_connect (priv->cell_area, "add-editable",
- G_CALLBACK (gtk_tree_view_column_add_editable_callback),
- column);
- priv->remove_editable_signal =
- g_signal_connect (priv->cell_area, "remove-editable",
- G_CALLBACK (gtk_tree_view_column_remove_editable_callback),
- column);
-
priv->property_changed_signal =
g_signal_connect_swapped (tree_view,
"notify::model",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]