diff --git a/ChangeLog b/ChangeLog index 59c4c458..f0b584d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2001-06-28 Archit Baweja + + * src/glade.h (GLADE_TAB_GET_TYPE_FUNCTION): new #define. + + * src/glade-widget-class.c (glade_widget_class_new_from_node): added + code to search for _get_type () function and initialize the GType. + (glade_widget_class_compose_get_type_func): new function. + (glade_widget_class_get_type): new function. + 2001-06-27 Chema Celorio * src/glade-widget-class.[ch], src/glade-widget.[ch]: Store signals @@ -16,7 +25,7 @@ * missing, mkinstalldirs: Removed, are generated files. * ChangeLog: Changed the previous date entry to the Gnome's standar one. - + 2001-06-21 Jonathan Blandford * src/glade-property-class.c (glade_property_class_get_specs): diff --git a/src/glade-parameter.c b/src/glade-parameter.c index ce88e64b..490fb576 100644 --- a/src/glade-parameter.c +++ b/src/glade-parameter.c @@ -185,7 +185,6 @@ glade_parameter_list_new_from_node (GList *list, xmlNodePtr node) findme = glade_parameter_list_find_by_key (list, parameter->key); if (findme) { - g_print ("We foind one, replace it\n"); glade_parameter_free (findme->data); findme->data = parameter; child = child->next; diff --git a/src/glade-placeholder.c b/src/glade-placeholder.c index 818eb92e..7c2196da 100644 --- a/src/glade-placeholder.c +++ b/src/glade-placeholder.c @@ -21,6 +21,7 @@ */ #include +#include #include "glade.h" #include "glade-placeholder.h" diff --git a/src/glade-property-class.c b/src/glade-property-class.c index 8291a89d..e6a99e3a 100644 --- a/src/glade-property-class.c +++ b/src/glade-property-class.c @@ -131,8 +131,8 @@ glade_property_class_get_specs (GladeWidgetClass *class, GParamSpec ***specs, gi { GObjectClass *object_class; GType type; - - type = gtk_window_get_type (); + + type = glade_widget_class_get_type (class); g_type_class_ref (type); /* hmm */ /* We count on the fact we have an instance, or else we'd have * touse g_type_class_ref (); @@ -250,8 +250,6 @@ glade_property_get_parameters_boolean (GParamSpec *spec, parameter->key = g_strdup ("Default"); parameter->value = def ? g_strdup (GLADE_TAG_TRUE) : g_strdup (GLADE_TAG_FALSE); - g_print ("Para %s\n", parameter->value); - return g_list_prepend (NULL, parameter); } @@ -317,7 +315,6 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec, GList *parameters = NULL; xmlNodePtr child; - g_print ("Go %s\n", class->name); switch (class->type) { case GLADE_PROPERTY_TYPE_CHOICE: parameters = glade_property_get_parameters_choice (spec, @@ -336,7 +333,6 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec, class); break; default: - g_print ("No parameters for %s\n", class->name); } /* Get the parameters that are specified on the glade file, diff --git a/src/glade-widget-class.c b/src/glade-widget-class.c index 5ec38cf7..04ff4d80 100644 --- a/src/glade-widget-class.c +++ b/src/glade-widget-class.c @@ -32,6 +32,8 @@ #include "glade-xml-utils.h" #include +#include +#include #include /* This should go away. Chema */ #include @@ -43,6 +45,32 @@ #include "glade-parameter.h" #include "glade-widget-class.h" +#if 0 /* Keep arround */ +static gchar * +glade_widget_class_compose_get_type_func (GladeWidgetClass *class) +{ + gchar *retval; + GString *tmp; + gint i = 1; + + tmp = g_string_new (class->name); + + while (tmp->str[i]) { + if (isupper (tmp->str[i])) { + tmp = g_string_insert_c (tmp, i, '_'); + i+=2; + continue; + } + i++; + } + + retval = g_strconcat (g_strdup (tmp->str), "_get_type", NULL); + g_strdown (retval); + g_string_free (tmp, TRUE); + + return retval; +} +#endif static GladeWidgetClass * glade_widget_class_new (void) @@ -52,6 +80,7 @@ glade_widget_class_new (void) widget = g_new0 (GladeWidgetClass, 1); widget->flags = 0; widget->placeholder_replace = NULL; + widget->type = 0; return widget; } @@ -111,12 +140,60 @@ glade_widget_class_list_signals (GladeWidgetClass *class) return signals; } +static gboolean +glade_widget_class_set_type (GladeWidgetClass *class, const gchar *init_function_name) +{ + static GModule *allsymbols; + guint (*get_type) (); + GType type; + + class->type = 0; + + g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), FALSE); + g_return_val_if_fail (init_function_name != NULL, FALSE); + + if (!g_module_supported ()) { + g_warning (_("gmodule support not found. gmodule support is requiered " + "for glade to work")); + return FALSE; + } + + if (!allsymbols) + allsymbols = g_module_open (NULL, 0); + + if (!g_module_symbol (allsymbols, init_function_name, + (gpointer) &get_type)) { + g_warning (_("We could not find the symbol \"%s\" while trying to load \"%s\""), + init_function_name, class->name); + return FALSE; + } + + g_assert (get_type); + type = get_type (); + + if (type == 0) { + g_warning(_("Could not get the type from \"%s\" while trying to load \"%s\""), class->name); + return FALSE; + } + + if (!g_type_is_a (type, gtk_widget_get_type ())) { + g_warning (_("The loaded type is not a GtkWidget, while trying to load \"%s\""), + class->name); + return FALSE; + } + + class->type = type; + + return TRUE; +} + static GladeWidgetClass * glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node) { GladeWidgetClass *class; xmlNodePtr child; - + gchar *init_function_name; + if (!glade_xml_node_verify (node, GLADE_TAG_GLADE_WIDGET_CLASS)) return NULL; @@ -129,6 +206,14 @@ glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node) class->name = glade_xml_get_value_string_required (node, GLADE_TAG_NAME, NULL); class->generic_name = glade_xml_get_value_string_required (node, GLADE_TAG_GENERIC_NAME, NULL); class->icon = glade_xml_get_value_string_required (node, GLADE_TAG_ICON, NULL); + + init_function_name = glade_xml_get_value_string_required (node, GLADE_TAG_GET_TYPE_FUNCTION, NULL); + if (!init_function_name) + return FALSE; + if (!glade_widget_class_set_type (class, init_function_name)) + return NULL; + g_free (init_function_name); + class->properties = glade_property_class_list_new_from_node (child, class); class->signals = glade_widget_class_list_signals (class); @@ -160,6 +245,8 @@ glade_widget_class_create_pixmap (GladeWidgetClass *class) struct stat s; GtkWidget *widget; gchar *full_path; + + g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), FALSE); widget = gtk_button_new (); @@ -185,7 +272,7 @@ GladeWidgetClass * glade_widget_class_new_from_name (const gchar *name) { XmlParseContext *context; - GladeWidgetClass *widget; + GladeWidgetClass *class; gchar *file_name; file_name = g_strconcat (WIDGETS_DIR, "/", name, ".xml", NULL); @@ -193,15 +280,15 @@ glade_widget_class_new_from_name (const gchar *name) context = glade_xml_parse_context_new_from_path (file_name, NULL, GLADE_TAG_GLADE_WIDGET_CLASS); if (context == NULL) return NULL; - widget = glade_widget_class_new_from_node (context, context->doc->children); + class = glade_widget_class_new_from_node (context, context->doc->children); glade_xml_parse_context_free (context); - if (!glade_widget_class_create_pixmap (widget)) + if (!glade_widget_class_create_pixmap (class)) return NULL; g_free (file_name); - return widget; + return class; } const gchar * @@ -210,6 +297,12 @@ glade_widget_class_get_name (GladeWidgetClass *widget) return widget->name; } +GType +glade_widget_class_get_type (GladeWidgetClass *widget) +{ + return widget->type; +} + void glade_widget_class_create (GladeWidgetClass *glade_widget) { diff --git a/src/glade-widget-class.h b/src/glade-widget-class.h index c4377503..36feb9aa 100644 --- a/src/glade-widget-class.h +++ b/src/glade-widget-class.h @@ -10,6 +10,7 @@ typedef enum { } GladeWidgetClassFlags; #define GLADE_WIDGET_CLASS(gwc) ((GladeWidgetClass *) gwc) +#define GLADE_IS_WIDGET_CLASS(gwc) (gwc != NULL) #define GLADE_WIDGET_FLAGS(gw) ((GLADE_WIDGET(gw)->class)->flags) #define GLADE_WIDGET_TOPLEVEL(gw) ((GLADE_WIDGET_FLAGS(gw) & GLADE_TOPLEVEL) != 0) @@ -28,6 +29,8 @@ typedef enum { */ struct _GladeWidgetClass { + GType type; /* GType of the widget */ + gchar *name; /* Name of the widget, for example GtkButton */ gchar *icon; /* Name of the icon without the prefix, for example "button" */ @@ -70,6 +73,7 @@ struct _GladeWidgetClassSignal { GladeWidgetClass * glade_widget_class_new_from_name (const gchar *name); const gchar * glade_widget_class_get_name (GladeWidgetClass *class); +GType glade_widget_class_get_type (GladeWidgetClass *class); gboolean glade_widget_class_has_queries (GladeWidgetClass *class); G_END_DECLS diff --git a/src/glade.h b/src/glade.h index fe879105..b01cbde3 100644 --- a/src/glade.h +++ b/src/glade.h @@ -11,6 +11,7 @@ gchar * _ (gchar * name); #define GLADE_PATH_SEP_STR "/" #define GLADE_TAG_GLADE_WIDGET_CLASS "GladeWidgetClass" +#define GLADE_TAG_GET_TYPE_FUNCTION "GetTypeFunction" #define GLADE_TAG_GENERIC_NAME "GenericName" #define GLADE_TAG_NAME "Name" #define GLADE_TAG_KEY "Key" diff --git a/widgets/gtkbutton.xml b/widgets/gtkbutton.xml index 7eea821a..38df4da0 100644 --- a/widgets/gtkbutton.xml +++ b/widgets/gtkbutton.xml @@ -1,5 +1,6 @@ GtkButton + gtk_button_get_type button False button @@ -59,4 +60,4 @@ - \ No newline at end of file + diff --git a/widgets/gtkcheckbutton.xml b/widgets/gtkcheckbutton.xml index e79e2daa..aa3463f9 100644 --- a/widgets/gtkcheckbutton.xml +++ b/widgets/gtkcheckbutton.xml @@ -1,5 +1,6 @@ GtkCheckButton + gtk_check_button_get_type checkbutton False checkbutton diff --git a/widgets/gtkhbox.xml b/widgets/gtkhbox.xml index c9e5bb92..30f805f4 100644 --- a/widgets/gtkhbox.xml +++ b/widgets/gtkhbox.xml @@ -1,5 +1,6 @@ GtkHBox + gtk_hbox_get_type hbox False True @@ -56,4 +57,4 @@ - \ No newline at end of file + diff --git a/widgets/gtklabel.xml b/widgets/gtklabel.xml index 8caf5049..ff61201d 100644 --- a/widgets/gtklabel.xml +++ b/widgets/gtklabel.xml @@ -1,5 +1,6 @@ GtkLabel + gtk_label_get_type label False label @@ -14,4 +15,4 @@ label - \ No newline at end of file + diff --git a/widgets/gtktable.xml b/widgets/gtktable.xml index 2c5aaf65..89354e34 100644 --- a/widgets/gtktable.xml +++ b/widgets/gtktable.xml @@ -1,5 +1,6 @@ GtkTable + gtk_table_get_type table False table @@ -97,4 +98,4 @@ - \ No newline at end of file + diff --git a/widgets/gtkvbox.xml b/widgets/gtkvbox.xml index 5eb50750..0672d28f 100644 --- a/widgets/gtkvbox.xml +++ b/widgets/gtkvbox.xml @@ -1,5 +1,6 @@ GtkVBox + gtk_vbox_get_type vbox False vbox @@ -56,4 +57,4 @@ - \ No newline at end of file + diff --git a/widgets/gtkwindow.xml b/widgets/gtkwindow.xml index ccdd4436..a01792d4 100644 --- a/widgets/gtkwindow.xml +++ b/widgets/gtkwindow.xml @@ -1,5 +1,6 @@ GtkWindow + gtk_window_get_type window True window @@ -79,4 +80,4 @@ - \ No newline at end of file +