patch for non-GObject property handlers



hello,

this patch adds an function to libglade to handle non-GObject properties
of widgets.  this is often needed when there are things glade needs to
set, but there are not GObject properties for them.

i've tested this patch with one such "fake" property: tooltips on
GtkToolbars.

james, is this an ok api, or do you have a better suggestion?

it would be helpful to get this in soon, as it aids in finishing the
libglade 2 support of libglade 1 files, and in getting as many
properties into gtk 2 as possible.

i've also attached an example of how this can be used.

jacob
-- 
"Beat mixing is 10000 times more fun than even video games."
	-- bt
Index: glade-build.h
===================================================================
RCS file: /cvs/gnome/libglade/glade/glade-build.h,v
retrieving revision 1.33
diff -u -r1.33 glade-build.h
--- glade-build.h	2001/10/24 23:31:10	1.33
+++ glade-build.h	2001/11/13 22:37:48
@@ -47,6 +47,10 @@
 						   GtkWidget *parent,
 						   const char *childname);
 
+typedef gboolean (* GladeCustomPropertyFunc)      (const char *name,
+						   const char *value,
+						   gpointer data);
+
 /* register handlers for a widget */
 void glade_register_widget(GType type,
 			   GladeNewFunc new,
@@ -91,6 +95,11 @@
 
 GtkWidget *glade_standard_build_widget(GladeXML *xml, GType widget_type,
 				       GladeWidgetInfo *info);
+
+GtkWidget *glade_standard_build_widget_full(GladeXML *xml, GType widget_type,
+					    GladeWidgetInfo *info,
+					    GladeCustomPropertyFunc custom_property,
+					    gpointer custom_property_data);
 
 /* A standard child building routine that can be used in widget builders */
 void glade_standard_build_children(GladeXML *self, GtkWidget *parent,
Index: glade-xml.c
===================================================================
RCS file: /cvs/gnome/libglade/glade/glade-xml.c,v
retrieving revision 1.80
diff -u -r1.80 glade-xml.c
--- glade-xml.c	2001/11/13 00:26:08	1.80
+++ glade-xml.c	2001/11/13 22:37:48
@@ -1405,10 +1405,12 @@
 }
 
 /**
- * glade_standard_build_widget
+ * glade_standard_build_widget_full
  * @xml: the GladeXML object.
  * @widget_type: the GType of the widget.
  * @info: the GladeWidgetInfo structure.
+ * @custom_property: handler of non-GObject properties
+ * @custom_property_data: data passed to custom property handler
  *
  * This is the standard widget building function.  It processes all
  * the widget properties using the standard object properties
@@ -1418,8 +1420,10 @@
  * Returns: the constructed widget.
  */
 GtkWidget *
-glade_standard_build_widget(GladeXML *xml, GType widget_type,
-			    GladeWidgetInfo *info)
+glade_standard_build_widget_full(GladeXML *xml, GType widget_type,
+				 GladeWidgetInfo *info,
+				 GladeCustomPropertyFunc custom_property,
+				 gpointer custom_property_data)
 {
     static GArray *props_array = NULL;
     GObjectClass *oclass;
@@ -1440,6 +1444,12 @@
 
 	pspec = g_object_class_find_property(oclass, info->properties[i].name);
 	if (!pspec) {
+	    if (custom_property && 
+		custom_property (info->properties[i].name,
+				 info->properties[i].value,
+				 custom_property_data))
+		continue;
+	    
 	    g_warning("unknown property `%s' for class `%s'",
 		      info->properties[i].name, g_type_name(widget_type));
 	    continue;
@@ -1487,6 +1497,26 @@
     g_type_class_unref(oclass);
 
     return widget;
+}
+
+/**
+ * glade_standard_build_widget
+ * @xml: the GladeXML object.
+ * @widget_type: the GType of the widget.
+ * @info: the GladeWidgetInfo structure.
+ *
+ * This is the standard widget building function.  It processes all
+ * the widget properties using the standard object properties
+ * interfaces.  This function will be sufficient for most widget
+ * types, thus reducing the ammount of work needed to wrap a library.
+ *
+ * Returns: the constructed widget.
+ */
+GtkWidget *
+glade_standard_build_widget(GladeXML *xml, GType widget_type,
+			    GladeWidgetInfo *info)
+{
+    return glade_standard_build_widget_full (xml, widget_type, info, NULL, NULL);
 }
 
 /**
static gboolean
toolbar_custom_property (const char *name, const char *value, gpointer data)
{
    gboolean *tooltips = data;

    if (strcmp (name, "tooltips"))
	return FALSE;

    *tooltips = (*value == 'T' || *value == 'y');
    return TRUE;
}

static GtkWidget *
build_toolbar (GladeXML *xml, GType widget_type,
	       GladeWidgetInfo *info)
{
    GtkWidget *toolbar;
    gboolean tooltips = TRUE;

    toolbar = glade_standard_build_widget_full (xml, widget_type, info, 
						toolbar_custom_property, 
						&tooltips);
    
    if (!tooltips)
	gtk_toolbar_set_tooltips (GTK_TOOLBAR (toolbar), tooltips);

    return toolbar;
}


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