glade3 r1769 - in trunk: . gladeui



Author: tvb
Date: Sat Apr  5 21:28:08 2008
New Revision: 1769
URL: http://svn.gnome.org/viewvc/glade3?rev=1769&view=rev

Log:

	* gladeui/glade-widget-adaptor.[ch], gladeui/glade-xml-utils.h,
	  allow the plugin to handle read_child() write_child() (mostly
	  just to allow you to skip some children like fake AtkObjects,
	  but can also be used to parse/write packing stuff (i.e. the
	  <child> tag) in custom ways).



Modified:
   trunk/ChangeLog
   trunk/gladeui/glade-widget-adaptor.c
   trunk/gladeui/glade-widget-adaptor.h
   trunk/gladeui/glade-widget.c
   trunk/gladeui/glade-widget.h
   trunk/gladeui/glade-xml-utils.h

Modified: trunk/gladeui/glade-widget-adaptor.c
==============================================================================
--- trunk/gladeui/glade-widget-adaptor.c	(original)
+++ trunk/gladeui/glade-widget-adaptor.c	Sat Apr  5 21:28:08 2008
@@ -858,6 +858,113 @@
 	}
 }
 
+static void
+glade_widget_adaptor_object_read_child (GladeWidgetAdaptor *adaptor,
+					GladeWidget        *widget,
+					GladeXmlNode       *node)
+{
+	GladeXmlNode *widget_node, *packing_node;
+	GladeWidget  *child_widget;
+	GList        *packing;
+	gchar        *internal_name;
+
+	if (!glade_xml_node_verify (node, GLADE_XML_TAG_CHILD))
+		return;
+
+	internal_name = 
+		glade_xml_get_property_string 
+		(node, GLADE_XML_TAG_INTERNAL_CHILD);
+	
+	if ((widget_node = 
+	     glade_xml_search_child
+	     (node, GLADE_XML_TAG_WIDGET)) != NULL)
+	{
+		child_widget = 
+			glade_widget_read (widget->project, 
+					   widget, 
+					   widget_node, 
+					   internal_name);
+		
+		if (child_widget)
+		{
+			if (!internal_name) {
+				glade_widget_set_child_type_from_node 
+					(adaptor, child_widget->object, node);
+				glade_widget_add_child (widget, child_widget, FALSE);
+			}
+				
+			if ((packing_node =
+			     glade_xml_search_child
+			     (node, GLADE_XML_TAG_PACKING)) != NULL)
+			{
+				
+				/* Get the packing properties */
+				for (packing = child_widget->packing_properties; 
+				     packing; packing = packing->next)
+				{
+					GladeProperty *property = packing->data;
+					glade_property_read (property, 
+							     child_widget->project, 
+							     packing_node);
+				}
+			}
+		}
+		
+	} else {
+		GObject *palaceholder = 
+			G_OBJECT (glade_placeholder_new ());
+		glade_widget_set_child_type_from_node (adaptor, palaceholder, node);
+		glade_widget_adaptor_add (adaptor, widget->object, palaceholder);
+		
+	}
+	g_free (internal_name);
+}
+
+static void
+glade_widget_adaptor_object_write_child (GladeWidgetAdaptor *adaptor,
+					 GladeWidget        *widget,
+					 GladeXmlContext    *context,
+					 GladeXmlNode       *node)
+{
+	GladeXmlNode *child_node, *packing_node;
+	GList        *props;
+
+	child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD);
+	glade_xml_node_append_child (node, child_node);
+
+	/* Set internal child */
+	if (widget->internal)
+		glade_xml_node_set_property_string (child_node, 
+						    GLADE_XML_TAG_INTERNAL_CHILD, 
+						    widget->internal);
+
+	/* Write out the widget */
+	glade_widget_write (widget, context, child_node);
+
+	/* Write out packing properties and special-child-type */
+	packing_node = glade_xml_node_new (context, GLADE_XML_TAG_PACKING);
+	glade_xml_node_append_child (child_node, packing_node);
+
+	for (props = widget->packing_properties; 
+	     props; props = props->next)
+		glade_property_write (GLADE_PROPERTY (props->data), 
+				      context, packing_node);
+
+	glade_widget_write_special_child_prop (widget->parent,
+					       widget->object,
+					       context, packing_node);
+	
+	/* Default packing properties and such are not saved,
+	 * so lets check afterwords if there was anything saved
+	 * and then just remove the node.
+	 */
+	if (!glade_xml_node_get_children (packing_node))
+	{
+		glade_xml_node_remove (packing_node);
+		glade_xml_node_delete (packing_node);
+	}
+}
+
 static GType 
 glade_widget_adaptor_get_eprop_type (GParamSpec *pspec)
 {
@@ -990,6 +1097,8 @@
 	adaptor_class->child_action_activate= glade_widget_adaptor_object_child_action_activate;
 	adaptor_class->read_widget          = glade_widget_adaptor_object_read_widget;
 	adaptor_class->write_widget         = glade_widget_adaptor_object_write_widget;
+	adaptor_class->read_child           = glade_widget_adaptor_object_read_child;
+	adaptor_class->write_child          = glade_widget_adaptor_object_write_child;
 	adaptor_class->create_eprop         = glade_widget_adaptor_object_create_eprop;
 	adaptor_class->string_from_value    = glade_widget_adaptor_object_string_from_value;
 
@@ -1246,6 +1355,16 @@
 		klass->write_widget = symbol;
 
 	if (glade_xml_load_sym_from_node (node, module,
+					  GLADE_TAG_READ_CHILD_FUNCTION,
+					  &symbol))
+		klass->read_child = symbol;
+
+	if (glade_xml_load_sym_from_node (node, module,
+					  GLADE_TAG_WRITE_CHILD_FUNCTION,
+					  &symbol))
+		klass->write_child = symbol;
+
+	if (glade_xml_load_sym_from_node (node, module,
 					  GLADE_TAG_CREATE_EPROP_FUNCTION,
 					  &symbol))
 		klass->create_eprop = symbol;
@@ -3035,8 +3154,8 @@
  * @context: The #GladeXmlContext
  * @node: The #GladeXmlNode
  *
- * This function is called to update @widget from @node 
- * when loading xml files.
+ * This function is called to write @widget to @node 
+ * when writing xml files.
  */
 void
 glade_widget_adaptor_write_widget (GladeWidgetAdaptor *adaptor,
@@ -3054,6 +3173,55 @@
 
 
 /**
+ * glade_widget_adaptor_read_child:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @widget: The #GladeWidget
+ * @node: The #GladeXmlNode
+ *
+ * This function is called to update load a child @widget 
+ * from @node when loading xml files (will recurse into
+ * glade_widget_read())
+ */
+void
+glade_widget_adaptor_read_child (GladeWidgetAdaptor *adaptor,
+				 GladeWidget        *widget,
+				 GladeXmlNode       *node)
+{
+	g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));
+	g_return_if_fail (GLADE_IS_WIDGET (widget));
+	g_return_if_fail (node != NULL);
+
+	GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->read_child (adaptor, widget, node);
+}
+
+
+/**
+ * glade_widget_adaptor_write_child:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @widget: The #GladeWidget
+ * @context: The #GladeXmlContext
+ * @node: The #GladeXmlNode
+ *
+ * This function is called to write the child @widget to @node 
+ * when writing xml files (takes care of packing and recurses
+ * into glade_widget_write())
+ */
+void
+glade_widget_adaptor_write_child (GladeWidgetAdaptor *adaptor,
+				  GladeWidget        *widget,
+				  GladeXmlContext    *context,
+				  GladeXmlNode       *node)
+{
+	g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));
+	g_return_if_fail (GLADE_IS_WIDGET (widget));
+	g_return_if_fail (node != NULL);
+
+	GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->write_child (adaptor, widget, 
+							       context, node);
+}
+
+
+/**
  * glade_widget_adaptor_create_eprop:
  * @adaptor: A #GladeWidgetAdaptor
  * @klass: The #GladePropertyClass to be edited

Modified: trunk/gladeui/glade-widget-adaptor.h
==============================================================================
--- trunk/gladeui/glade-widget-adaptor.h	(original)
+++ trunk/gladeui/glade-widget-adaptor.h	Sat Apr  5 21:28:08 2008
@@ -542,6 +542,12 @@
 	
 	GladeWriteWidgetFunc         write_widget; /* Writes widget attributes to the xml */
 
+	GladeReadWidgetFunc          read_child; /* Reads widget attributes from xml */
+	
+	GladeWriteWidgetFunc         write_child; /* Writes widget attributes to the xml */
+
+
+
 	GladeCreateEPropFunc         create_eprop; /* Creates a GladeEditorProperty */
 
 	GladeStringFromValueFunc     string_from_value; /* Creates a string for a value */
@@ -705,6 +711,15 @@
 							      GladeXmlContext    *context,
 							      GladeXmlNode       *node);
 
+void                 glade_widget_adaptor_read_child         (GladeWidgetAdaptor *adaptor,
+							      GladeWidget        *widget,
+							      GladeXmlNode       *node);
+
+void                 glade_widget_adaptor_write_child        (GladeWidgetAdaptor *adaptor,
+							      GladeWidget        *widget,
+							      GladeXmlContext    *context,
+							      GladeXmlNode       *node);
+
 GladeEditorProperty *glade_widget_adaptor_create_eprop       (GladeWidgetAdaptor *adaptor,
 							      GladePropertyClass *klass,
 							      gboolean            use_command);

Modified: trunk/gladeui/glade-widget.c
==============================================================================
--- trunk/gladeui/glade-widget.c	(original)
+++ trunk/gladeui/glade-widget.c	Sat Apr  5 21:28:08 2008
@@ -3289,7 +3289,8 @@
 /*******************************************************************************
  *                           Xml Parsing code                                  *
  *******************************************************************************/
-static void
+/* XXX Doc me ! */
+void
 glade_widget_set_child_type_from_node (GladeWidgetAdaptor  *parent_adaptor,
 				       GObject             *child,
 				       GladeXmlNode        *node)
@@ -3352,68 +3353,7 @@
 glade_widget_read_child (GladeWidget  *widget,
 			 GladeXmlNode *node)
 {
-	GladeXmlNode *widget_node, *packing_node;
-	GladeWidget  *child_widget;
-	GList        *packing;
-	gchar        *internal_name;
-
-	if (!glade_xml_node_verify (node, GLADE_XML_TAG_CHILD))
-		return;
-
-	internal_name = 
-		glade_xml_get_property_string 
-		(node, GLADE_XML_TAG_INTERNAL_CHILD);
-	
-	if ((widget_node = 
-	     glade_xml_search_child
-	     (node, GLADE_XML_TAG_WIDGET)) != NULL)
-	{
-		child_widget = 
-			glade_widget_read (widget->project, 
-					   widget, 
-					   widget_node, 
-					   internal_name);
-		
-		if (child_widget)
-		{
-			if (!internal_name) {
-				glade_widget_set_child_type_from_node 
-					(widget->adaptor, 
-					 child_widget->object, node);
-				glade_widget_add_child (widget, child_widget, FALSE);
-			}
-				
-			if ((packing_node =
-			     glade_xml_search_child
-			     (node, GLADE_XML_TAG_PACKING)) != NULL)
-			{
-				
-				/* Get the packing properties */
-				for (packing = child_widget->packing_properties; 
-				     packing; packing = packing->next)
-				{
-					GladeProperty *property = packing->data;
-					glade_property_read (property, 
-							     child_widget->project, 
-							     packing_node);
-				}
-			}
-		}
-		
-	} else {
-		GObject *palaceholder = 
-			G_OBJECT (glade_placeholder_new ());
-		
-		glade_widget_set_child_type_from_node (widget->adaptor, 
-						       palaceholder,
-						       node);
-		
-		glade_widget_adaptor_add (widget->adaptor,
-					  widget->object,
-					  palaceholder);
-		
-	}
-	g_free (internal_name);
+	glade_widget_adaptor_read_child (widget->adaptor, widget, node);
 }
 
 /**
@@ -3502,7 +3442,8 @@
 	return widget;
 }
 
-static void
+/* XXX Doc me !*/
+void
 glade_widget_write_special_child_prop (GladeWidget     *parent, 
 				       GObject         *object,
 				       GladeXmlContext *context,
@@ -3546,43 +3487,8 @@
 			  GladeXmlContext *context,
 			  GladeXmlNode    *node)
 {
-	GladeXmlNode *child_node, *packing_node;
-	GList        *props;
-
-	child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD);
-	glade_xml_node_append_child (node, child_node);
-
-	/* Set internal child */
-	if (widget->internal)
-		glade_xml_node_set_property_string (child_node, 
-						    GLADE_XML_TAG_INTERNAL_CHILD, 
-						    widget->internal);
-
-	/* Write out the widget */
-	glade_widget_write (widget, context, child_node);
-
-	/* Write out packing properties and special-child-type */
-	packing_node = glade_xml_node_new (context, GLADE_XML_TAG_PACKING);
-	glade_xml_node_append_child (child_node, packing_node);
-
-	for (props = widget->packing_properties; 
-	     props; props = props->next)
-		glade_property_write (GLADE_PROPERTY (props->data), 
-				      context, packing_node);
-
-	glade_widget_write_special_child_prop (widget->parent,
-					       widget->object,
-					       context, packing_node);
-	
-	/* Default packing properties and such are not saved,
-	 * so lets check afterwords if there was anything saved
-	 * and then just remove the node.
-	 */
-	if (!glade_xml_node_get_children (packing_node))
-	{
-		glade_xml_node_remove (packing_node);
-		glade_xml_node_delete (packing_node);
-	}
+	glade_widget_adaptor_write_child (widget->adaptor,
+					  widget, context, node);
 }
 
 

Modified: trunk/gladeui/glade-widget.h
==============================================================================
--- trunk/gladeui/glade-widget.h	(original)
+++ trunk/gladeui/glade-widget.h	Sat Apr  5 21:28:08 2008
@@ -233,6 +233,16 @@
 void                    glade_widget_read_child             (GladeWidget      *widget,
 							     GladeXmlNode     *node);
 
+
+void                    glade_widget_write_special_child_prop (GladeWidget     *parent, 
+							       GObject         *object,
+							       GladeXmlContext *context,
+							       GladeXmlNode    *node);
+
+void                  glade_widget_set_child_type_from_node (GladeWidgetAdaptor  *parent_adaptor,
+							     GObject             *child,
+							     GladeXmlNode        *node);
+
 GladeEditorProperty    *glade_widget_create_editor_property (GladeWidget      *widget,
 							     const gchar      *property,
 							     gboolean          packing,

Modified: trunk/gladeui/glade-xml-utils.h
==============================================================================
--- trunk/gladeui/glade-xml-utils.h	(original)
+++ trunk/gladeui/glade-xml-utils.h	Sat Apr  5 21:28:08 2008
@@ -68,6 +68,8 @@
 #define GLADE_TAG_CHILD_ACTION_ACTIVATE_FUNCTION  "child-action-activate-function"
 #define GLADE_TAG_READ_WIDGET_FUNCTION            "read-widget-function"
 #define GLADE_TAG_WRITE_WIDGET_FUNCTION           "write-widget-function"
+#define GLADE_TAG_READ_CHILD_FUNCTION             "read-child-function"
+#define GLADE_TAG_WRITE_CHILD_FUNCTION            "write-child-function"
 #define GLADE_TAG_CREATE_EPROP_FUNCTION           "create-editor-property-function"
 #define GLADE_TAG_STRING_FROM_VALUE_FUNCTION      "string-from-value-function"
 #define GLADE_TAG_PROPERTIES                      "properties"



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