Commit 92708591 authored by Tristan Van Berkom's avatar Tristan Van Berkom

gladeui/glade-widget-adaptor.[ch], gladeui/glade-xml-utils.h, allow the


	* 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).


svn path=/trunk/; revision=1769
parent 14cc6063
......@@ -5,6 +5,12 @@
children, allowiong you to do stuff before or after children
are written/read from the xml file.
* 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).
2008-04-04 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-project.c: Resurected <requires> code and
......
......@@ -858,6 +858,113 @@ glade_widget_adaptor_object_write_widget (GladeWidgetAdaptor *adaptor,
}
}
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 @@ glade_widget_adaptor_class_init (GladeWidgetAdaptorClass *adaptor_class)
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;
......@@ -1245,6 +1354,16 @@ gwa_extend_with_node_load_sym (GladeWidgetAdaptorClass *klass,
&symbol))
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))
......@@ -3035,8 +3154,8 @@ glade_widget_adaptor_read_widget (GladeWidgetAdaptor *adaptor,
* @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,
......@@ -3053,6 +3172,55 @@ glade_widget_adaptor_write_widget (GladeWidgetAdaptor *adaptor,
}
/**
* 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
......
......@@ -542,6 +542,12 @@ struct _GladeWidgetAdaptorClass
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 @@ void glade_widget_adaptor_write_widget (GladeWidgetAdaptor
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);
......
......@@ -3289,7 +3289,8 @@ glade_widget_replace (GladeWidget *parent, GObject *old_object, GObject *new_obj
/*******************************************************************************
* 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 @@ void
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 @@ glade_widget_read (GladeProject *project,
return widget;
}
static void
/* XXX Doc me !*/
void
glade_widget_write_special_child_prop (GladeWidget *parent,
GObject *object,
GladeXmlContext *context,
......@@ -3546,43 +3487,8 @@ glade_widget_write_child (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);
}
glade_widget_adaptor_write_child (widget->adaptor,
widget, context, node);
}
......
......@@ -233,6 +233,16 @@ GladeWidget *glade_widget_read (GladeProject *p
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,
......
......@@ -68,6 +68,8 @@ typedef struct _GladeXmlDoc GladeXmlDoc;
#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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment