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

Added GladeWidgetAdaptor destroy_object method.

The destroy_object method gives the chance to plugins to undo
anything which might have added a reference to the object.
parent d5a2961a
......@@ -898,6 +898,13 @@ glade_widget_adaptor_object_construct_object (GladeWidgetAdaptor *adaptor,
return g_object_newv (adaptor->priv->type, n_parameters, parameters);
}
static void
glade_widget_adaptor_object_destroy_object (GladeWidgetAdaptor *adaptor,
GObject *object)
{
/* Do nothing, just have a method here incase classes chain up */
}
static GObject *
glade_widget_adaptor_object_get_internal_child (GladeWidgetAdaptor *adaptor,
......@@ -1369,6 +1376,7 @@ glade_widget_adaptor_class_init (GladeWidgetAdaptorClass *adaptor_class)
/* Class methods */
adaptor_class->create_widget = glade_widget_adaptor_object_create_widget;
adaptor_class->construct_object = glade_widget_adaptor_object_construct_object;
adaptor_class->destroy_object = glade_widget_adaptor_object_destroy_object;
adaptor_class->deep_post_create = NULL;
adaptor_class->post_create = NULL;
adaptor_class->get_internal_child = glade_widget_adaptor_object_get_internal_child;
......@@ -1529,6 +1537,11 @@ gwa_extend_with_node_load_sym (GladeWidgetAdaptorClass *klass,
&symbol))
klass->construct_object = symbol;
if (glade_xml_load_sym_from_node (node, module,
GLADE_TAG_DESTROY_OBJECT_FUNCTION,
&symbol))
klass->destroy_object = symbol;
if (glade_xml_load_sym_from_node (node, module,
GLADE_TAG_DEEP_POST_CREATE_FUNCTION,
&symbol))
......@@ -3238,6 +3251,22 @@ glade_widget_adaptor_construct_object (GladeWidgetAdaptor *adaptor,
parameters);
}
/**
* glade_widget_adaptor_destroy_object:
* @adaptor: A #GladeWidgetAdaptor
* @object: The object to destroy
*
* This function is called to destroy a GObject instance.
*/
void
glade_widget_adaptor_destroy_object (GladeWidgetAdaptor *adaptor,
GObject *object)
{
g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));
GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->destroy_object (adaptor, object);
}
static void
gwa_internal_children_create (GladeWidgetAdaptor *adaptor,
GObject *parent_object,
......
......@@ -385,6 +385,27 @@ typedef GObject *(* GladeConstructObjectFunc) (GladeWidgetAdaptor *adaptor,
guint n_parameters,
GParameter *parameters);
/**
* GladeDestroyObjectFunc:
* @adaptor: A #GladeWidgetAdaptor
* @object: The #GObject to destroy
*
* This function is called to break any additional references to
* a GObject instance. Note that this function is not responsible
* for calling g_object_unref() on @object, the reference count
* of @object belongs to it's #GladeWidget wrapper.
*
* The #GtkWidget adaptor will call gtk_widget_destroy() before
* chaining up in this function.
*
* If your adaptor adds any references in any way at
* #GladePostCreateFunc time or #GladeConstructObjectFunc
* time, then this function must be implemented to also
* remove that reference.
*
*/
typedef void (* GladeDestroyObjectFunc) (GladeWidgetAdaptor *adaptor,
GObject *object);
/**
......@@ -590,6 +611,8 @@ struct _GladeWidgetAdaptorClass
GladeConstructObjectFunc construct_object; /* Object constructor
*/
GladeDestroyObjectFunc destroy_object; /* Object destructor */
GladePostCreateFunc deep_post_create; /* Executed after widget creation:
* plugins use this to setup various
* support codes (adaptors must always
......@@ -667,7 +690,6 @@ struct _GladeWidgetAdaptorClass
void (* glade_reserved5) (void);
void (* glade_reserved6) (void);
void (* glade_reserved7) (void);
void (* glade_reserved8) (void);
};
#define glade_widget_adaptor_create_widget(adaptor, query, ...) \
......@@ -724,6 +746,8 @@ GParameter *glade_widget_adaptor_default_params (GladeWidgetAdapto
GObject *glade_widget_adaptor_construct_object (GladeWidgetAdaptor *adaptor,
guint n_parameters,
GParameter *parameters);
void glade_widget_adaptor_destroy_object (GladeWidgetAdaptor *adaptor,
GObject *object);
void glade_widget_adaptor_post_create (GladeWidgetAdaptor *adaptor,
GObject *object,
GladeCreateReason reason);
......
......@@ -3375,11 +3375,11 @@ glade_widget_set_object (GladeWidget * gwidget, GObject * new_object)
gwidget->priv->name ? gwidget->priv->name : "(unknown)",
old_object->ref_count);
#endif
if (GTK_IS_WIDGET (old_object))
gtk_widget_destroy (GTK_WIDGET (old_object));
g_object_unref (old_object);
/* Have the adaptor for this widget break any additional references */
glade_widget_adaptor_destroy_object (gwidget->priv->adaptor, old_object);
g_object_unref (old_object);
}
}
g_object_notify_by_pspec (G_OBJECT (gwidget), properties[PROP_OBJECT]);
......
......@@ -91,6 +91,7 @@ typedef struct _GladeProject GladeProject;
#define GLADE_TAG_REPLACE_CHILD_FUNCTION "replace-child-function"
#define GLADE_TAG_CREATE_WIDGET_FUNCTION "create-widget-function"
#define GLADE_TAG_CONSTRUCT_OBJECT_FUNCTION "construct-object-function"
#define GLADE_TAG_DESTROY_OBJECT_FUNCTION "destroy-object-function"
#define GLADE_TAG_DEEP_POST_CREATE_FUNCTION "deep-post-create-function"
#define GLADE_TAG_POST_CREATE_FUNCTION "post-create-function"
#define GLADE_TAG_GET_INTERNAL_CHILD_FUNCTION "get-internal-child-function"
......
......@@ -94,6 +94,15 @@ glade_gtk_init (const gchar * name)
}
/* ----------------------------- GtkWidget ------------------------------ */
void
glade_gtk_widget_destroy_object (GladeWidgetAdaptor * adaptor,
GObject *object)
{
gtk_widget_destroy (GTK_WIDGET (object));
GWA_GET_CLASS (G_TYPE_OBJECT)->destroy_object (adaptor, object);
}
gboolean
glade_gtk_widget_depends (GladeWidgetAdaptor * adaptor,
GladeWidget * widget, GladeWidget * another)
......
......@@ -9,6 +9,7 @@
<glade-widget-class name="GtkWidget" _title="Widget" default-width="100" default-height="60">
<destroy-object-function>glade_gtk_widget_destroy_object</destroy-object-function>
<deep-post-create-function>glade_gtk_widget_deep_post_create</deep-post-create-function>
<set-property-function>glade_gtk_widget_set_property</set-property-function>
<get-property-function>glade_gtk_widget_get_property</get-property-function>
......@@ -19,7 +20,6 @@
<write-widget-function>glade_gtk_widget_write_widget</write-widget-function>
<create-editor-property-function>glade_gtk_widget_create_eprop</create-editor-property-function>
<string-from-value-function>glade_gtk_widget_string_from_value</string-from-value-function>
<destroy-object-function>glade_gtk_widget_destroy_widget</destroy-object-function>
<signals>
<signal id="drag-failed" since="2.12"/>
......
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