[cairo-commit] goocanvas/src goocanvasitem.c, 1.33, 1.34 goocanvasitem.h, 1.22, 1.23 goocanvasitemmodel.c, 1.16, 1.17 goocanvasitemmodel.h, 1.12, 1.13

Damon Chaplin commit at pdx.freedesktop.org
Sun Nov 18 05:57:43 PST 2007


Committed by: damon

Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv6965/src

Modified Files:
	goocanvasitem.c goocanvasitem.h goocanvasitemmodel.c 
	goocanvasitemmodel.h 
Log Message:
2007-11-18  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasitem.c (goo_canvas_item_get_child_property) 
	(goo_canvas_item_set_child_property): 
	* src/goocanvasitemmodel.c (goo_canvas_item_model_get_child_property) 
	(goo_canvas_item_model_set_child_property): new functions to get/set
	individual child properties (to help language bindings).

	* demo/demo-table.c (create_demo_item): 
	* demo/mv-demo-table.c (create_demo_item): test the above.

	* src/goocanvasitem.c:
	* src/goocanvasitemmodel.c: fixed some docs that wrongly say functions
	are for implementing new items only.



Index: goocanvasitem.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitem.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- goocanvasitem.c	13 Nov 2007 14:30:52 -0000	1.33
+++ goocanvasitem.c	18 Nov 2007 13:57:40 -0000	1.34
@@ -1608,6 +1608,100 @@
 /*
  * Child Properties.
  */
+static inline void
+item_get_child_property (GObject      *object,
+			 GObject      *child,
+			 GParamSpec   *pspec,
+			 GValue       *value,
+			 gboolean      is_model)
+{
+  GObjectClass *class;
+
+  class = g_type_class_peek (pspec->owner_type);
+
+  if (is_model)
+    {
+      GooCanvasItemModelIface *iface;
+
+      iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM_MODEL);
+      iface->get_child_property ((GooCanvasItemModel*) object,
+				 (GooCanvasItemModel*) child,
+				 pspec->param_id, value, pspec);
+    }
+  else
+    {
+      GooCanvasItemIface *iface;
+
+      iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM);
+      iface->get_child_property ((GooCanvasItem*) object,
+				 (GooCanvasItem*) child,
+				 pspec->param_id, value, pspec);
+    }
+}
+
+
+void
+_goo_canvas_item_get_child_property_internal (GObject              *object,
+					      GObject              *child,
+					      const gchar          *property_name,
+					      GValue               *value,
+					      GParamSpecPool       *property_pool,
+					      gboolean              is_model)
+{
+  GParamSpec *pspec;
+
+  g_object_ref (object);
+  g_object_ref (child);
+  pspec = g_param_spec_pool_lookup (property_pool, property_name,
+				    G_OBJECT_TYPE (object), TRUE);
+  if (!pspec)
+    g_warning ("%s: class `%s' has no child property named `%s'",
+	       G_STRLOC,
+	       G_OBJECT_TYPE_NAME (object),
+	       property_name);
+  else if (!(pspec->flags & G_PARAM_READABLE))
+    g_warning ("%s: child property `%s' of class `%s' is not readable",
+	       G_STRLOC,
+	       pspec->name,
+	       G_OBJECT_TYPE_NAME (object));
+  else
+    {
+      GValue *prop_value, tmp_value = { 0, };
+
+      /* auto-conversion of the callers value type
+       */
+      if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
+	{
+	  g_value_reset (value);
+	  prop_value = value;
+	}
+      else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
+	{
+	  g_warning ("can't retrieve child property `%s' of type `%s' as value of type `%s'",
+		     pspec->name,
+		     g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
+		     G_VALUE_TYPE_NAME (value));
+	  g_object_unref (child);
+	  g_object_unref (object);
+	  return;
+	}
+      else
+	{
+	  g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+	  prop_value = &tmp_value;
+	}
+      item_get_child_property (object, child, pspec, prop_value, is_model);
+      if (prop_value != value)
+	{
+	  g_value_transform (prop_value, value);
+	  g_value_unset (&tmp_value);
+	}
+    }
+  g_object_unref (child);
+  g_object_unref (object);
+}
+
+
 void
 _goo_canvas_item_get_child_properties_internal (GObject              *object,
 						GObject              *child,
@@ -1621,7 +1715,6 @@
 
   for (;;)
     {
-      GObjectClass *class;
       GValue value = { 0, };
       GParamSpec *pspec;
       gchar *name, *error = NULL;
@@ -1645,28 +1738,7 @@
 	  break;
 	}
       g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
-
-      class = g_type_class_peek (pspec->owner_type);
-
-      if (is_model)
-	{
-	  GooCanvasItemModelIface *iface;
-
-	  iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM_MODEL);
-	  iface->get_child_property ((GooCanvasItemModel*) object,
-				     (GooCanvasItemModel*) child,
-				     pspec->param_id, &value, pspec);
-	}
-      else
-	{
-	  GooCanvasItemIface *iface;
-
-	  iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM);
-	  iface->get_child_property ((GooCanvasItem*) object,
-				     (GooCanvasItem*) child,
-				     pspec->param_id, &value, pspec);
-	}
-
+      item_get_child_property (object, child, pspec, &value, is_model);
       G_VALUE_LCOPY (&value, var_args, 0, &error);
       if (error)
 	{
@@ -1741,6 +1813,45 @@
 
 
 void
+_goo_canvas_item_set_child_property_internal (GObject              *object,
+					      GObject              *child,
+					      const gchar          *property_name,
+					      const GValue         *value,
+					      GParamSpecPool       *property_pool,
+					      GObjectNotifyContext *notify_context,
+					      gboolean              is_model)
+{
+  GObjectNotifyQueue *nqueue;
+  GParamSpec *pspec;
+
+  g_object_ref (object);
+  g_object_ref (child);
+
+  nqueue = g_object_notify_queue_freeze (child, notify_context);
+  pspec = g_param_spec_pool_lookup (property_pool, property_name,
+				    G_OBJECT_TYPE (object), TRUE);
+  if (!pspec)
+    g_warning ("%s: class `%s' has no child property named `%s'",
+	       G_STRLOC,
+	       G_OBJECT_TYPE_NAME (object),
+	       property_name);
+  else if (!(pspec->flags & G_PARAM_WRITABLE))
+    g_warning ("%s: child property `%s' of class `%s' is not writable",
+	       G_STRLOC,
+	       pspec->name,
+	       G_OBJECT_TYPE_NAME (object));
+  else
+    {
+      canvas_item_set_child_property (object, child, pspec,
+				      value, nqueue, is_model);
+    }
+  g_object_notify_queue_thaw (child, nqueue);
+  g_object_unref (object);
+  g_object_unref (child);
+}
+
+
+void
 _goo_canvas_item_set_child_properties_internal (GObject              *object,
 						GObject              *child,
 						va_list	              var_args,
@@ -1803,16 +1914,61 @@
 
 
 /**
+ * goo_canvas_item_get_child_property:
+ * @item: a #GooCanvasItem.
+ * @child: a child #GooCanvasItem.
+ * @property_name: the name of the child property to get.
+ * @value: a location to return the value.
+ * 
+ * Gets a child property of @child.
+ **/
+void
+goo_canvas_item_get_child_property (GooCanvasItem *item,
+				    GooCanvasItem *child,
+				    const gchar   *property_name,
+				    GValue        *value)
+{
+  g_return_if_fail (GOO_IS_CANVAS_ITEM (item));
+  g_return_if_fail (GOO_IS_CANVAS_ITEM (child));
+  g_return_if_fail (property_name != NULL);
+  g_return_if_fail (G_IS_VALUE (value));
+
+  _goo_canvas_item_get_child_property_internal ((GObject*) item, (GObject*) child, property_name, value, _goo_canvas_item_child_property_pool, FALSE);
+}
+
+
+/**
+ * goo_canvas_item_set_child_property:
+ * @item: a #GooCanvasItem.
+ * @child: a child #GooCanvasItem.
+ * @property_name: the name of the child property to set.
+ * @value: the value to set the property to.
+ * 
+ * Sets a child property of @child.
+ **/
+void
+goo_canvas_item_set_child_property (GooCanvasItem   *item,
+				    GooCanvasItem   *child,
+				    const gchar     *property_name,
+				    const GValue    *value)
+{
+  g_return_if_fail (GOO_IS_CANVAS_ITEM (item));
+  g_return_if_fail (GOO_IS_CANVAS_ITEM (child));
+  g_return_if_fail (property_name != NULL);
+  g_return_if_fail (G_IS_VALUE (value));
+
+  _goo_canvas_item_set_child_property_internal ((GObject*) item, (GObject*) child, property_name, value, _goo_canvas_item_child_property_pool, _goo_canvas_item_child_property_notify_context, FALSE);
+}
+
+
+/**
  * goo_canvas_item_get_child_properties_valist:
  * @item: a #GooCanvasItem.
  * @child: a child #GooCanvasItem.
  * @var_args: pairs of property names and value pointers, and a terminating
  *  %NULL.
  * 
- * This function is only intended to be used when implementing new canvas
- * items, specifically layout container items such as #GooCanvasTable.
- *
- * It gets the values of one or more child properties of @child.
+ * Gets the values of one or more child properties of @child.
  **/
 void
 goo_canvas_item_get_child_properties_valist (GooCanvasItem   *item,
@@ -1832,10 +1988,7 @@
  * @child: a child #GooCanvasItem.
  * @var_args: pairs of property names and values, and a terminating %NULL.
  * 
- * This function is only intended to be used when implementing new canvas
- * items, specifically layout container items such as #GooCanvasTable.
- *
- * It sets the values of one or more child properties of @child.
+ * Sets the values of one or more child properties of @child.
  **/
 void
 goo_canvas_item_set_child_properties_valist (GooCanvasItem   *item,
@@ -1855,10 +2008,7 @@
  * @child: a child #GooCanvasItem.
  * @...: pairs of property names and value pointers, and a terminating %NULL.
  * 
- * This function is only intended to be used when implementing new canvas
- * items, specifically layout container items such as #GooCanvasTable.
- *
- * It gets the values of one or more child properties of @child.
+ * Gets the values of one or more child properties of @child.
  **/
 void
 goo_canvas_item_get_child_properties        (GooCanvasItem   *item,
@@ -1879,10 +2029,7 @@
  * @child: a child #GooCanvasItem.
  * @...: pairs of property names and values, and a terminating %NULL.
  * 
- * This function is only intended to be used when implementing new canvas
- * items, specifically layout container items such as #GooCanvasTable.
- *
- * It sets the values of one or more child properties of @child.
+ * Sets the values of one or more child properties of @child.
  **/
 void
 goo_canvas_item_set_child_properties        (GooCanvasItem   *item,

Index: goocanvasitem.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitem.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- goocanvasitem.h	27 Apr 2007 10:01:51 -0000	1.22
+++ goocanvasitem.h	18 Nov 2007 13:57:41 -0000	1.23
@@ -313,6 +313,14 @@
 void               goo_canvas_item_remove_child   (GooCanvasItem   *item,
 						   gint             child_num);
 
+void  goo_canvas_item_get_child_property	  (GooCanvasItem   *item,
+						   GooCanvasItem   *child,
+						   const gchar     *property_name,
+						   GValue          *value);
+void  goo_canvas_item_set_child_property	  (GooCanvasItem   *item,
+						   GooCanvasItem   *child,
+						   const gchar     *property_name,
+						   const GValue    *value);
 void  goo_canvas_item_get_child_properties        (GooCanvasItem   *item,
 						   GooCanvasItem   *child,
 						   ...) G_GNUC_NULL_TERMINATED;

Index: goocanvasitemmodel.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemmodel.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- goocanvasitemmodel.c	13 Nov 2007 14:30:52 -0000	1.16
+++ goocanvasitemmodel.c	18 Nov 2007 13:57:41 -0000	1.17
@@ -838,23 +838,69 @@
 /*
  * Child Properties.
  */
+extern void _goo_canvas_item_set_child_property_internal (GObject *object, GObject *child, const gchar *property_name, const GValue *value, GParamSpecPool *property_pool, GObjectNotifyContext *notify_context, gboolean is_model);
+
 extern void _goo_canvas_item_get_child_properties_internal (GObject *object, GObject *child, va_list var_args, GParamSpecPool *property_pool, GObjectNotifyContext *notify_context, gboolean is_model);
 
 extern void _goo_canvas_item_set_child_properties_internal (GObject *object, GObject *child, va_list var_args, GParamSpecPool *property_pool, GObjectNotifyContext *notify_context, gboolean is_model);
 
 
 /**
+ * goo_canvas_item_model_get_child_property:
+ * @model: a #GooCanvasItemModel.
+ * @child: a child #GooCanvasItemModel.
+ * @property_name: the name of the child property to get.
+ * @value: a location to return the value.
+ * 
+ * Gets a child property of @child.
+ **/
+void
+goo_canvas_item_model_get_child_property (GooCanvasItemModel *model,
+					  GooCanvasItemModel *child,
+					  const gchar        *property_name,
+					  GValue             *value)
+{
+  g_return_if_fail (GOO_IS_CANVAS_ITEM_MODEL (model));
+  g_return_if_fail (GOO_IS_CANVAS_ITEM_MODEL (child));
+  g_return_if_fail (property_name != NULL);
+  g_return_if_fail (G_IS_VALUE (value));
+
+  _goo_canvas_item_get_child_property_internal ((GObject*) model, (GObject*) child, property_name, value, _goo_canvas_item_model_child_property_pool, TRUE);
+}
+
+
+/**
+ * goo_canvas_item_model_set_child_property:
+ * @model: a #GooCanvasItemModel.
+ * @child: a child #GooCanvasItemModel.
+ * @property_name: the name of the child property to set.
+ * @value: the value to set the property to.
+ * 
+ * Sets a child property of @child.
+ **/
+void
+goo_canvas_item_model_set_child_property (GooCanvasItemModel *model,
+					  GooCanvasItemModel *child,
+					  const gchar        *property_name,
+					  const GValue       *value)
+{
+  g_return_if_fail (GOO_IS_CANVAS_ITEM_MODEL (model));
+  g_return_if_fail (GOO_IS_CANVAS_ITEM_MODEL (child));
+  g_return_if_fail (property_name != NULL);
+  g_return_if_fail (G_IS_VALUE (value));
+
+  _goo_canvas_item_set_child_property_internal ((GObject*) model, (GObject*) child, property_name, value, _goo_canvas_item_model_child_property_pool, _goo_canvas_item_model_child_property_notify_context, TRUE);
+}
+
+
+/**
  * goo_canvas_item_model_get_child_properties_valist:
  * @model: a #GooCanvasItemModel.
  * @child: a child #GooCanvasItemModel.
  * @var_args: pairs of property names and value pointers, and a terminating
  *  %NULL.
  * 
- * This function is only intended to be used when implementing new canvas
- * item models, specifically layout container item models such as
- * #GooCanvasTableModel.
- *
- * It gets the values of one or more child properties of @child.
+ * Gets the values of one or more child properties of @child.
  **/
 void
 goo_canvas_item_model_get_child_properties_valist (GooCanvasItemModel *model,
@@ -874,11 +920,7 @@
  * @child: a child #GooCanvasItemModel.
  * @var_args: pairs of property names and values, and a terminating %NULL.
  * 
- * This function is only intended to be used when implementing new canvas
- * item models, specifically layout container item models such as
- * #GooCanvasTableModel.
- *
- * It sets the values of one or more child properties of @child.
+ * Sets the values of one or more child properties of @child.
  **/
 void
 goo_canvas_item_model_set_child_properties_valist (GooCanvasItemModel *model,
@@ -898,11 +940,7 @@
  * @child: a child #GooCanvasItemModel.
  * @...: pairs of property names and value pointers, and a terminating %NULL.
  * 
- * This function is only intended to be used when implementing new canvas
- * item models, specifically layout container item models such as
- * #GooCanvasTableModel.
- *
- * It gets the values of one or more child properties of @child.
+ * Gets the values of one or more child properties of @child.
  **/
 void
 goo_canvas_item_model_get_child_properties  (GooCanvasItemModel   *model,
@@ -923,11 +961,7 @@
  * @child: a child #GooCanvasItemModel.
  * @...: pairs of property names and values, and a terminating %NULL.
  * 
- * This function is only intended to be used when implementing new canvas
- * item models, specifically layout container item models such as
- * #GooCanvasTableModel.
- *
- * It sets the values of one or more child properties of @child.
+ * Sets the values of one or more child properties of @child.
  **/
 void
 goo_canvas_item_model_set_child_properties  (GooCanvasItemModel   *model,

Index: goocanvasitemmodel.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvasitemmodel.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- goocanvasitemmodel.h	30 Mar 2007 11:40:28 -0000	1.12
+++ goocanvasitemmodel.h	18 Nov 2007 13:57:41 -0000	1.13
@@ -169,6 +169,14 @@
 gint                goo_canvas_item_model_find_child     (GooCanvasItemModel *model,
 							  GooCanvasItemModel *child);
 
+void     goo_canvas_item_model_get_child_property	 (GooCanvasItemModel   *model,
+							  GooCanvasItemModel   *child,
+							  const gchar          *property_name,
+							  GValue               *value);
+void     goo_canvas_item_model_set_child_property	 (GooCanvasItemModel   *model,
+							  GooCanvasItemModel   *child,
+							  const gchar          *property_name,
+							  const GValue         *value);
 void     goo_canvas_item_model_get_child_properties	 (GooCanvasItemModel   *model,
 							  GooCanvasItemModel   *child,
 							  ...) G_GNUC_NULL_TERMINATED;



More information about the cairo-commit mailing list