diff options
-rw-r--r-- | ChangeLog | 24 | ||||
-rw-r--r-- | acconfig.h | 1 | ||||
-rw-r--r-- | config.h.win | 3 | ||||
-rw-r--r-- | configure.in | 15 | ||||
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/glade-catalog.c | 45 | ||||
-rw-r--r-- | src/glade-gtk.c | 146 | ||||
-rw-r--r-- | src/glade-property-class.c | 69 | ||||
-rw-r--r-- | src/glade-widget-class.c | 192 | ||||
-rw-r--r-- | src/glade-widget-class.h | 11 | ||||
-rw-r--r-- | src/glade-widget.c | 1 | ||||
-rw-r--r-- | widgets/gtk-additional.xml | 2 | ||||
-rw-r--r-- | widgets/gtk-base.xml | 2 | ||||
-rw-r--r-- | widgets/gtkwidget.xml | 6 | ||||
-rw-r--r-- | widgets/gtkwindow.xml | 4 |
15 files changed, 192 insertions, 338 deletions
@@ -1,3 +1,27 @@ +2003-10-04 Joaquin Cuenca Abela <e98cuenc@yahoo.com> + + * src/glade-catalog.c: read the name of the plugin to be used by each + catalog and pass it to the constructor of glade-widget-class. Also + if a specific class has a specific plugin name to be used, use it instead + of the generic of the whole catalog. + * src/glade-gtk.c: remove the "static" from the functions that should + be exported, and remove the "temp hack" that was used to load the + address of the functions, as it's no more needed. + * src/glade-property-class.c: remove glade_property_class_get_{get,set}_function + and use g_module_symbol instead. + * src/glade-widget-class.c: use g_module_symbol instead of the previous {get,set} + functions. Remove unused functions. Rename glade_widget_class_new_from_name2 + to glade_widget_class_new as it's the only constructor. Use the plugin + name that glade-widget-class passed to the constructor and load it. + * src/glade-widget-class.h: add a GModule* by GladeWidgetClass. + * src/glade-widget.c: remove the #include <glade-gtk.h> + * widgets/gtk-additional.xml: add the name of the plugin ("gtk") for all the + widgets on gtk-additional. + * widgets/gtk-base.xml: ditto + * widgets/gtkwidget.xml: remove the "name" tag, as it's not need. + * widgets/gtkwindow.xml: change glade_gtk_widget_{get,set}_tooltip by "ignore", + as that's what these functions do. + 2003-09-02 Paolo Borelli <pborelli@katamail.com> * src/glade.h: add the internal child tag. @@ -15,4 +15,5 @@ #undef PIXMAPS_DIR #undef WIDGETS_DIR #undef CATALOGS_DIR +#undef MODULES_DIR #undef GETTEXT_PACKAGE diff --git a/config.h.win b/config.h.win index 34ca950a..b693f797 100644 --- a/config.h.win +++ b/config.h.win @@ -2,7 +2,8 @@ #define CONFIG_H__ #define PIXMAPS_DIR "./pixmaps" -#define CATALOGS_DIR "./catalog" +#define CATALOGS_DIR "./catalog" #define WIDGETS_DIR "./widgets" +#define MODULES_DIR "./modules" #endif diff --git a/configure.in b/configure.in index 9444531a..7762b8b2 100644 --- a/configure.in +++ b/configure.in @@ -12,13 +12,14 @@ AC_PROG_INTLTOOL([0.11]) GNOME_COMMON_INIT GNOME_PLATFORM_GNOME_2(yes, force) -AM_PROG_LIBTOOL - AC_ISC_POSIX AC_PROG_CC AC_PROG_INSTALL AC_PROG_MAKE_SET +AC_LIBTOOL_DLOPEN +AC_PROG_LIBTOOL + AC_CHECK_HEADERS(os2.h) dnl ================================================================ @@ -77,9 +78,19 @@ else catalogsdir="${prefix}/${DATADIRNAME}/${PACKAGE}-${VERSION}/catalogs" fi +dnl ================================================================ +dnl MODULES +dnl ================================================================ +if test "x${libdir}" = "xNONE"; then + modulesdir="${ac_default_libdir}/${PACKAGE}" +else + modulesdir="${libdir}/${PACKAGE}" +fi + AC_SUBST(pixmapsdir) AC_SUBST(widgetsdir) AC_SUBST(catalogsdir) +AC_SUBST(modulesdir) AC_OUTPUT([ Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 80b93aa1..f6a88cba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,12 @@ SUBDIRS= bin_PROGRAMS = glade-3 +gladegtk_LTLIBRARIES = libgladegtk.la +gladegtkdir = $(modulesdir) + +libgladegtk_la_SOURCES = glade-gtk.c +libgladegtk_la_LDFLAGS = -module -avoid-version + INCLUDES = \ -I$(top_srcdir) \ -I$(top_builddir) \ @@ -13,6 +19,7 @@ INCLUDES = \ -DGLADE_ICONDIR=\""$(datadir)/pixmaps"\" \ -DGLADE_LOCALSTATEDIR=\""$(localstatedir)"\" \ -DGLADE_LOCALEDIR=\""$(datadir)/locale"\" \ + -DMODULES_DIR=\""@modulesdir@"\" \ -DG_LOG_DOMAIN=\"Glade\" CFLAGS = -g -O2 -Wall @@ -39,7 +46,6 @@ glade_3_SOURCES = \ glade-catalog.c \ glade-choice.c \ glade-editor.c \ - glade-gtk.c \ glade-utils.c \ glade-signal.c \ glade-signal-editor.c \ @@ -69,7 +75,6 @@ noinst_HEADERS = \ glade-property-class.h \ glade-popup.h \ glade-choice.h \ - glade-gtk.h \ glade-catalog.h \ glade-utils.h \ glade-signal.h \ diff --git a/src/glade-catalog.c b/src/glade-catalog.c index 4dd41960..4282359d 100644 --- a/src/glade-catalog.c +++ b/src/glade-catalog.c @@ -37,7 +37,6 @@ #define GLADE_TAG_PALETTE "GladePalette" -static GList *glade_catalog_list = NULL; /* A list of GladeCatalog items */ static GList *widget_class_list = NULL; /* A list of all the GladeWidgetClass objects loaded */ GList * @@ -80,12 +79,14 @@ glade_catalog_load (const char *base_catalog_filename) char *generic_name = NULL; char *catalog_filename = NULL; char *base_filename = NULL; + char *partial_library = NULL; + char *base_library = NULL; GList *last_widget_class = NULL; catalog_filename = g_strdup_printf ("%s%c%s", CATALOGS_DIR, G_DIR_SEPARATOR, base_catalog_filename); if (catalog_filename == NULL) { - g_critical ("Not enough memory."); + g_critical (_("Not enough memory.")); goto lblError; } @@ -93,7 +94,7 @@ glade_catalog_load (const char *base_catalog_filename) context = glade_xml_context_new_from_path (catalog_filename, NULL, GLADE_TAG_CATALOG); if (context == NULL) { - g_warning ("Impossible to open the catalog [%s].", catalog_filename); + g_warning (_("Impossible to open the catalog [%s]."), catalog_filename); goto lblError; } @@ -104,7 +105,7 @@ glade_catalog_load (const char *base_catalog_filename) catalog = g_new0 (GladeCatalog, 1); if (catalog == NULL) { - g_critical ("Not enough memory."); + g_critical (_("Not enough memory.")); goto lblError; } @@ -115,14 +116,29 @@ glade_catalog_load (const char *base_catalog_filename) if (!glade_xml_node_verify (root, GLADE_TAG_CATALOG)) { - g_warning ("The root node of [%s] has a name different from %s.", catalog_filename, GLADE_TAG_CATALOG); + g_warning (_("The root node of [%s] has a name different from %s."), catalog_filename, GLADE_TAG_CATALOG); goto lblError; } + /* get the library to be used by this catalog (if any) */ + partial_library = glade_xml_get_property_string (root, "library"); + if (partial_library && *partial_library) + { + base_library = g_strdup_printf ("libglade%s", partial_library); + if (!base_library) + { + g_critical (_("Not enough memory.")); + goto lblError; + } + } + /* build all the GladeWidgetClass'es associated with this catalog */ widget_node = glade_xml_node_get_children (root); for (; widget_node != NULL; widget_node = glade_xml_node_next (widget_node)) { + char *partial_widget_class_library = NULL; + char *base_widget_class_library = NULL; + if (!glade_xml_node_verify (widget_node, GLADE_TAG_GLADE_WIDGET)) continue; @@ -130,10 +146,23 @@ glade_catalog_load (const char *base_catalog_filename) if (name == NULL) continue; + /* get the specific library to the widget class, if any */ + partial_widget_class_library = glade_xml_get_property_string (widget_node, "library"); + if (partial_widget_class_library && *partial_widget_class_library) + { + base_widget_class_library = g_strdup_printf ("libglade%s", partial_widget_class_library); + if (!base_widget_class_library) + { + g_critical (_("Not enough memory.")); + continue; + } + } + generic_name = glade_xml_get_property_string (widget_node, "generic_name"); base_filename = glade_xml_get_property_string (widget_node, "filename"); - widget_class = glade_widget_class_new_from_name2 (name, generic_name, base_filename); + widget_class = glade_widget_class_new (name, generic_name, base_filename, + base_widget_class_library ? base_widget_class_library : base_library); if (widget_class) { last_widget_class = g_list_append (last_widget_class, widget_class); @@ -147,6 +176,8 @@ glade_catalog_load (const char *base_catalog_filename) g_free (name); g_free (generic_name); g_free (base_filename); + g_free (partial_widget_class_library); + g_free (base_widget_class_library); } glade_xml_context_free (context); @@ -157,6 +188,8 @@ lblError: glade_xml_context_free (context); g_free (catalog_filename); g_free (catalog); + g_free (partial_library); + g_free (base_library); return NULL; } diff --git a/src/glade-gtk.c b/src/glade-gtk.c index 0f28b663..f6ca4392 100644 --- a/src/glade-gtk.c +++ b/src/glade-gtk.c @@ -34,7 +34,7 @@ #include "glade-command.h" -static void +void glade_gtk_entry_set_text (GObject *object, GValue *value) { GtkEditable *editable = GTK_EDITABLE (object); @@ -54,7 +54,7 @@ glade_gtk_entry_set_text (GObject *object, GValue *value) gtk_editable_set_position (editable, pos); } -static void +void glade_gtk_entry_get_text (GObject *object, GValue *value) { GtkEntry *entry = GTK_ENTRY (object); @@ -68,7 +68,7 @@ glade_gtk_entry_get_text (GObject *object, GValue *value) g_value_set_string (value, text); } -static void +void glade_gtk_option_menu_set_items (GObject *object, GValue *value) { GtkOptionMenu *option_menu; @@ -107,7 +107,7 @@ glade_gtk_option_menu_set_items (GObject *object, GValue *value) } -static void +void glade_gtk_progress_bar_set_format (GObject *object, GValue *value) { GtkProgressBar *bar; @@ -119,7 +119,7 @@ glade_gtk_progress_bar_set_format (GObject *object, GValue *value) gtk_progress_set_format_string (GTK_PROGRESS (bar), format); } -static void +void glade_gtk_spin_button_set_max (GObject *object, GValue *value) { GtkAdjustment *adjustment; @@ -131,7 +131,7 @@ glade_gtk_spin_button_set_max (GObject *object, GValue *value) } -static void +void glade_gtk_spin_button_set_min (GObject *object, GValue *value) { GtkAdjustment *adjustment; @@ -142,7 +142,7 @@ glade_gtk_spin_button_set_min (GObject *object, GValue *value) gtk_adjustment_changed (adjustment); } -static void +void glade_gtk_spin_button_set_step_increment (GObject *object, GValue *value) { GtkAdjustment *adjustment; @@ -153,7 +153,7 @@ glade_gtk_spin_button_set_step_increment (GObject *object, GValue *value) gtk_adjustment_changed (adjustment); } -static void +void glade_gtk_spin_button_set_page_increment (GObject *object, GValue *value) { GtkAdjustment *adjustment; @@ -164,7 +164,7 @@ glade_gtk_spin_button_set_page_increment (GObject *object, GValue *value) gtk_adjustment_changed (adjustment); } -static void +void glade_gtk_spin_button_set_page_size (GObject *object, GValue *value) { GtkAdjustment *adjustment; @@ -176,7 +176,7 @@ glade_gtk_spin_button_set_page_size (GObject *object, GValue *value) } -static void +void glade_gtk_box_get_size (GObject *object, GValue *value) { GtkBox *box; @@ -189,7 +189,7 @@ glade_gtk_box_get_size (GObject *object, GValue *value) g_value_set_int (value, g_list_length (box->children)); } -static void +void glade_gtk_box_set_size (GObject *object, GValue *value) { GladeWidget *widget; @@ -238,7 +238,7 @@ glade_gtk_box_set_size (GObject *object, GValue *value) g_object_set_data (object, "glade_nb_placeholders", GINT_TO_POINTER (new_size)); } -static void +void glade_gtk_notebook_get_n_pages (GObject *object, GValue *value) { GtkNotebook *notebook; @@ -251,7 +251,7 @@ glade_gtk_notebook_get_n_pages (GObject *object, GValue *value) g_value_set_int (value, g_list_length (notebook->children)); } -static void +void glade_gtk_notebook_set_n_pages (GObject *object, GValue *value) { GladeWidget *widget; @@ -310,7 +310,7 @@ glade_gtk_notebook_set_n_pages (GObject *object, GValue *value) #if 0 /* This code is working but i don't think we need it. Chema */ -static void +void glade_gtk_table_get_n_rows (GObject *object, GValue *value) { GtkTable *table; @@ -323,7 +323,7 @@ glade_gtk_table_get_n_rows (GObject *object, GValue *value) g_value_set_int (value, table->nrows); } -static void +void glade_gtk_table_get_n_columns (GObject *object, GValue *value) { GtkTable *table; @@ -337,7 +337,7 @@ glade_gtk_table_get_n_columns (GObject *object, GValue *value) } #endif -static void +void glade_gtk_table_set_n_common (GObject *object, GValue *value, gboolean for_rows) { GladeWidget *widget; @@ -408,19 +408,19 @@ glade_gtk_table_set_n_common (GObject *object, GValue *value, gboolean for_rows) g_object_set_data (object, "glade_nb_placeholders", GINT_TO_POINTER (new_size * (for_rows ? table->ncols : table->nrows))); } -static void +void glade_gtk_table_set_n_rows (GObject *object, GValue *value) { glade_gtk_table_set_n_common (object, value, TRUE); } -static void +void glade_gtk_table_set_n_columns (GObject *object, GValue *value) { glade_gtk_table_set_n_common (object, value, FALSE); } -static void +void glade_gtk_button_set_stock (GObject *object, GValue *value) { GladeWidget *glade_widget; @@ -486,14 +486,19 @@ glade_gtk_button_set_stock (GObject *object, GValue *value) } } -static void +void empty (GObject *object, GValue *value) { } +void +ignore (GObject *object, GValue *value) +{ +} + /* ------------------------------------ Post Create functions ------------------------------ */ -static void +void glade_gtk_window_post_create (GObject *object, GValue *not_used) { GtkWindow *window = GTK_WINDOW (object); @@ -503,7 +508,7 @@ glade_gtk_window_post_create (GObject *object, GValue *not_used) gtk_window_set_default_size (window, 440, 250); } -static void +void glade_gtk_dialog_post_create (GObject *object, GValue *not_used) { GtkDialog *dialog = GTK_DIALOG (object); @@ -513,7 +518,7 @@ glade_gtk_dialog_post_create (GObject *object, GValue *not_used) gtk_window_set_default_size (GTK_WINDOW (dialog), 320, 260); } -static void +void glade_gtk_message_dialog_post_create (GObject *object, GValue *not_used) { GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object); @@ -523,7 +528,7 @@ glade_gtk_message_dialog_post_create (GObject *object, GValue *not_used) gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 115); } -static void +void glade_gtk_check_button_post_create (GObject *object, GValue *not_used) { GtkCheckButton *button = GTK_CHECK_BUTTON (object); @@ -538,7 +543,7 @@ glade_gtk_check_button_post_create (GObject *object, GValue *not_used) } -static void +void glade_gtk_table_post_create (GObject *object, GValue *value) { GtkTable *table = GTK_TABLE (object); @@ -561,94 +566,3 @@ glade_gtk_table_post_create (GObject *object, GValue *value) } } -/* ================ Temp hack =================== */ -/* We have this table, but what we should do is use gmodule for this, - * however this requires that we link with libtool cause right now - * we are loosing the symbols. Chema - */ -typedef struct _GladeGtkFunction GladeGtkFunction; - -struct _GladeGtkFunction { - const gchar *name; - void (* function) (GObject *object, GValue *value); -}; - -#define GLADE_NEW_FUNCTION(name) {#name, name} -#define GLADE_NEW_EMPTY_FUNCTION(name) {#name, empty} - -GladeGtkFunction functions [] = { - GLADE_NEW_FUNCTION(glade_gtk_entry_get_text), - GLADE_NEW_FUNCTION(glade_gtk_box_get_size), - GLADE_NEW_EMPTY_FUNCTION(glade_gtk_widget_get_tooltip), - - GLADE_NEW_FUNCTION(glade_gtk_button_set_stock), - -#if 0 - GLADE_NEW_FUNCTION(glade_gtk_table_get_n_rows), - GLADE_NEW_FUNCTION(glade_gtk_table_get_n_columns), -#endif - GLADE_NEW_FUNCTION(glade_gtk_table_set_n_rows), - GLADE_NEW_FUNCTION(glade_gtk_table_set_n_columns), - - GLADE_NEW_FUNCTION(glade_gtk_entry_set_text), - GLADE_NEW_FUNCTION(glade_gtk_option_menu_set_items), - GLADE_NEW_FUNCTION(glade_gtk_progress_bar_set_format), - GLADE_NEW_FUNCTION(glade_gtk_box_set_size), - GLADE_NEW_EMPTY_FUNCTION(glade_gtk_widget_set_tooltip), - GLADE_NEW_EMPTY_FUNCTION(ignore), /* For example for gtkwindow::modal, we want to ignore the set */ - - GLADE_NEW_FUNCTION(glade_gtk_notebook_get_n_pages), - GLADE_NEW_FUNCTION(glade_gtk_notebook_set_n_pages), - - GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_max), - GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_min), - GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_step_increment), - GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_page_increment), - GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_page_size), - - GLADE_NEW_FUNCTION(glade_gtk_check_button_post_create), - GLADE_NEW_FUNCTION(glade_gtk_window_post_create), - GLADE_NEW_FUNCTION(glade_gtk_dialog_post_create), - GLADE_NEW_FUNCTION(glade_gtk_message_dialog_post_create), - GLADE_NEW_FUNCTION(glade_gtk_table_post_create) -}; - -#undef GLADE_NEW_FUNCTION -#undef GLADE_NEW_EMPTY_FUNCTION - -gpointer -glade_gtk_get_function (const gchar *name) -{ - gint num; - gint i; - - num = sizeof (functions) / sizeof (GladeGtkFunction); - for (i = 0; i < num; i++) { - if (strcmp (name, functions[i].name) == 0) - break; - } - if (i == num) { - g_warning ("Could not find the function %s\n", - name); - return NULL; - } - - return functions[i].function; -} - -gboolean -glade_gtk_get_set_function_hack (GladePropertyClass *class, const gchar *name) -{ - class->set_function = glade_gtk_get_function (name); - - return TRUE; -} - -gboolean -glade_gtk_get_get_function_hack (GladePropertyClass *class, const gchar *name) -{ - class->get_function = glade_gtk_get_function (name); - - return TRUE; -} - diff --git a/src/glade-property-class.c b/src/glade-property-class.c index 9a504fe7..2a7b0eb8 100644 --- a/src/glade-property-class.c +++ b/src/glade-property-class.c @@ -35,7 +35,6 @@ #include "glade-parameter.h" #include "glade-property.h" #include "glade-property-class.h" -#include "glade-gtk.h" #include "glade-debug.h" #if 0 @@ -842,39 +841,6 @@ glade_property_class_load_from_param_spec (const gchar *name, } #endif -static gboolean -glade_property_class_get_get_function (GladePropertyClass *class, const gchar *function_name) -{ - return glade_gtk_get_get_function_hack (class, function_name); -} - -static gboolean -glade_property_class_get_set_function (GladePropertyClass *class, const gchar *function_name) -{ - static GModule *allsymbols; - - /* This is not working ... So add a temp hack */ - return glade_gtk_get_set_function_hack (class, function_name); - - g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (class), FALSE); - g_return_val_if_fail (class->set_function == NULL, FALSE); - g_return_val_if_fail (function_name != NULL, FALSE); - - if (!allsymbols) - allsymbols = g_module_open (NULL, 0); - - if (!g_module_symbol (allsymbols, function_name, - (gpointer) &class->set_function)) { - g_warning (_("We could not find the symbol \"%s\" while trying to load \"%s\""), - function_name, class->name); - return FALSE; - } - - g_assert (class->set_function); - - return TRUE; -} - static GList * glade_xml_read_list (GladeXmlNode *node, const gchar *list_tag, const gchar *item_tag) { @@ -1006,6 +972,7 @@ glade_property_class_update_from_node (GladeXmlNode *node, *property_class = pproperty_class; } else { +#if 0 /* If the property is an object Load it */ if (pproperty_class->type == GLADE_PROPERTY_TYPE_OBJECT) { child = glade_xml_search_child_required (node, GLADE_TAG_GLADE_WIDGET_CLASS); @@ -1017,6 +984,7 @@ glade_property_class_update_from_node (GladeXmlNode *node, pproperty_class->child = glade_widget_class_new_from_node (child); } +#endif pproperty_class->def = glade_property_class_get_default (node, pproperty_class); glade_property_class_free (*property_class); @@ -1056,20 +1024,41 @@ glade_property_class_update_from_node (GladeXmlNode *node, /* If this property can't be set with g_object_set, get the workarround * function */ + /* I use here a g_warning to signal these errors instead of a dialog box, as if there is one + * of this kind of errors, there will probably a lot of them, and we don't want to inflict + * the user the pain of plenty of dialog boxes. Ideally, we should collect these errors, + * and show all of them at the end of the load processus. */ child = glade_xml_search_child (node, GLADE_TAG_SET_FUNCTION); if (child != NULL) { - gchar * content = glade_xml_get_content (child); - glade_property_class_get_set_function (pproperty_class, content); - g_free (content); + gchar *symbol_name = glade_xml_get_content (child); + + if (!widget_class->module) + g_warning (_("The property [%s] of the widget's class [%s] needs a special \"set\" function, but there is no library associated to this widget's class."), + pproperty_class->name, widget_class->name); + + if (!g_module_symbol (widget_class->module, symbol_name, (gpointer *) &pproperty_class->set_function)) + g_warning (_("Unable to get the \"set\" function [%s] of the property [%s] of the widget's class [%s] from the module [%s]: %s"), + symbol_name, pproperty_class->name, widget_class->name, g_module_name (widget_class->module), g_module_error ()); + + g_free (symbol_name); } + /* If this property can't be get with g_object_get, get the workarround * function */ child = glade_xml_search_child (node, GLADE_TAG_GET_FUNCTION); if (child != NULL) { - gchar * content = glade_xml_get_content (child); - glade_property_class_get_get_function (pproperty_class, content); - g_free (content); + gchar *symbol_name = glade_xml_get_content (child); + + if (!widget_class->module) + g_warning (_("The property [%s] of the widget's class [%s] needs a special \"get\" function, but there is no library associated to this widget's class."), + pproperty_class->name, widget_class->name); + + if (!g_module_symbol(widget_class->module, symbol_name, (gpointer *) &pproperty_class->get_function)) + g_warning (_("Unable to get the \"get\" function [%s] of the property [%s] of the widget's class [%s] from the module [%s]: %s"), + symbol_name, pproperty_class->name, widget_class->name, g_module_name (widget_class->module), g_module_error ()); + + g_free (symbol_name); } return; diff --git a/src/glade-widget-class.c b/src/glade-widget-class.c index 2ebdb32f..e35af56c 100644 --- a/src/glade-widget-class.c +++ b/src/glade-widget-class.c @@ -44,7 +44,6 @@ #include "glade-catalog.h" #include "glade-choice.h" #include "glade-parameter.h" -#include "glade-gtk.h" #include "glade-debug.h" /* hash table that will contain all the GtkWidgetClass'es created, indexed by its name */ @@ -83,21 +82,6 @@ glade_widget_class_compose_get_type_func (GladeWidgetClass *class) return retval; } -static GladeWidgetClass * -glade_widget_class_new (void) -{ - GladeWidgetClass *class; - - class = g_new0 (GladeWidgetClass, 1); - class->flags = 0; - class->placeholder_replace = NULL; - class->type = 0; - class->properties = NULL; - class->child_properties = NULL; - - return class; -} - void glade_widget_class_free (GladeWidgetClass *widget_class) { @@ -277,29 +261,6 @@ glade_widget_class_list_signals (GladeWidgetClass *class) return signals; } -static gboolean -glade_widget_class_set_type (GladeWidgetClass *class, - const gchar *init_function_name) -{ - 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); - - type = glade_util_get_type_from_name (init_function_name); - if (type == 0) - return FALSE; - - class->type = type; - - if (type == 0) - return FALSE; - - return TRUE; -} - static void glade_widget_class_add_virtual_methods (GladeWidgetClass *class) { @@ -309,83 +270,6 @@ glade_widget_class_add_virtual_methods (GladeWidgetClass *class) glade_placeholder_add_methods_to_class (class); } -GladeWidgetClass * -glade_widget_class_new_from_node (GladeXmlNode *node) -{ - GladeWidgetClass *class; - GladeXmlNode *child; - gchar *init_function_name; - gchar *post_create_function_name; - - if (!glade_xml_node_verify (node, GLADE_TAG_GLADE_WIDGET_CLASS)) - return NULL; - - class = glade_widget_class_new (); - - 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); - - if (!class->name || !class->generic_name) { - g_warning ("Invalid XML file. Widget Class %s\n", class->name); - return NULL; - } - - init_function_name = glade_xml_get_value_string (node, GLADE_TAG_GET_TYPE_FUNCTION); - if (!init_function_name) { - init_function_name = glade_widget_class_compose_get_type_func (class); - if (!init_function_name) - return FALSE; - } - - if (!glade_widget_class_set_type (class, init_function_name)) - return NULL; - g_free (init_function_name); - - /* Properties. - * if needed add/override properties listed in the xml file. - */ - class->properties = glade_widget_class_list_properties (class); - child = glade_xml_search_child (node, GLADE_TAG_PROPERTIES); - if (child) - glade_property_class_list_add_from_node (child, class, &class->properties); - - /* Child properties */ - /* TODO: we probably want to override/add some packing properties from - * the xml file like we do foe normal properties, in other words we may - * need a function similar to glade_property_class_list_add_from_node - */ - class->child_properties = glade_widget_class_list_child_properties (class); - - /* Signals */ - class->signals = glade_widget_class_list_signals (class); - - /* Get the flags */ - if (glade_xml_get_boolean (node, GLADE_TAG_TOPLEVEL, FALSE)) - GLADE_WIDGET_CLASS_SET_FLAGS (class, GLADE_TOPLEVEL); - else - GLADE_WIDGET_CLASS_UNSET_FLAGS (class, GLADE_TOPLEVEL); - if (glade_xml_get_boolean (node, GLADE_TAG_PLACEHOLDER, FALSE)) - GLADE_WIDGET_CLASS_SET_FLAGS (class, GLADE_ADD_PLACEHOLDER); - else - GLADE_WIDGET_CLASS_UNSET_FLAGS (class, GLADE_ADD_PLACEHOLDER); - - /* placeholder_replace */ - glade_widget_class_add_virtual_methods (class); - - /* PostCreateFunction */ - post_create_function_name = glade_xml_get_value_string (node, GLADE_TAG_POST_CREATE_FUNCTION); - if (post_create_function_name) { - class->post_create_function = glade_gtk_get_function (post_create_function_name); - if (!class->post_create_function) - g_warning ("Could not find %s\n", post_create_function_name); - } - g_free (post_create_function_name); - - class->in_palette = glade_xml_get_boolean (node, GLADE_TAG_IN_PALETTE, TRUE); - - return class; -} - static GtkWidget * glade_widget_class_create_icon (GladeWidgetClass *class) { @@ -426,9 +310,8 @@ glade_widget_class_extend_with_file (GladeWidgetClass *widget_class, const char node = glade_xml_doc_get_root (doc); post_create_function_name = glade_xml_get_value_string (node, GLADE_TAG_POST_CREATE_FUNCTION); - if (post_create_function_name) { - widget_class->post_create_function = glade_gtk_get_function (post_create_function_name); - if (!widget_class->post_create_function) + if (post_create_function_name && widget_class->module) { + if (!g_module_symbol (widget_class->module, post_create_function_name, (void **) &widget_class->post_create_function)) g_warning ("Could not find %s\n", post_create_function_name); } g_free (post_create_function_name); @@ -464,7 +347,7 @@ glade_widget_class_store_with_name (GladeWidgetClass *widget_class) } /** - * glade_widget_class_get_from_name: + * glade_widget_class_get_by_name: * @name: name of the widget class (for instance: GtkButton) * * Returns an already created GladeWidgetClass with the name passed as argument. @@ -545,8 +428,8 @@ glade_widget_class_remove_duplicated_properties (GladeWidgetClass *widget_class) GList *old_property; /* if it's the first time we see this property, then we add it to the list of - * properties that we will keep the property. Idem if the last time we saw - * this property it was not modified, and this time the property is modified + * properties that we will keep for this widget. Idem if the last time we saw + * this property, it was not modified, and this time the property is modified * (ie, we change the non modified property by the modified one). */ if ((old_property = g_hash_table_lookup (hash_properties, property_class->id)) == NULL || (!((GladePropertyClass*) old_property->data)->is_modified && property_class->is_modified)) @@ -582,7 +465,7 @@ glade_widget_class_remove_duplicated_properties (GladeWidgetClass *widget_class) } /** - * glade_widget_class_new_from_name2: + * glade_widget_class_new: * @name: name of the widget class (for instance: GtkButton) * @generic_name: base of the name for the widgets of this class (for instance: button). * This parameter is optional. For abstract classes there is no need to supply a generic_name. @@ -597,17 +480,16 @@ glade_widget_class_remove_duplicated_properties (GladeWidgetClass *widget_class) * the xml filename. * * Return Value: The new GladeWidgetClass, or %NULL if there are any errors. - * - * TODO: this function should replace glade_widget_class_new_from_name & new_from_node - * when done, we should of course rename it. **/ GladeWidgetClass * -glade_widget_class_new_from_name2 (const char *name, - const char *generic_name, - const char *base_filename) +glade_widget_class_new (const char *name, + const char *generic_name, + const char *base_filename, + const char *base_library) { GladeWidgetClass *widget_class = NULL; char *filename = NULL; + char *library = NULL; char *init_function_name = NULL; GType parent_type; @@ -621,18 +503,26 @@ glade_widget_class_new_from_name2 (const char *name, if (base_filename != NULL) { filename = g_strconcat (WIDGETS_DIR, "/", base_filename, NULL); if (filename == NULL) { - g_warning ("Not enough memory."); + g_warning (_("Not enough memory.")); + goto lblError; + } + } + + if (base_library != NULL) { + library = g_strconcat (MODULES_DIR G_DIR_SEPARATOR_S, base_library, NULL); + if (library == NULL) { + g_warning (_("Not enough memory.")); goto lblError; } } - widget_class = glade_widget_class_new (); + widget_class = g_new0 (GladeWidgetClass, 1); if (!widget_class) { - g_warning ("Not enough memory."); + g_warning (_("Not enough memory.")); goto lblError; } - widget_class->generic_name = g_strdup (generic_name); + widget_class->generic_name = generic_name ? g_strdup (generic_name) : NULL; widget_class->name = g_strdup (name); widget_class->in_palette = generic_name ? TRUE : FALSE; @@ -641,7 +531,7 @@ glade_widget_class_new_from_name2 (const char *name, * type is to call foo_bar_get_type() */ init_function_name = glade_widget_class_compose_get_type_func (widget_class); if (!init_function_name) { - g_warning ("Not enough memory."); + g_warning (_("Not enough memory.")); goto lblError; } @@ -665,6 +555,14 @@ glade_widget_class_new_from_name2 (const char *name, widget_class->icon = glade_widget_class_create_icon (widget_class); + if (library != NULL) { + widget_class->module = g_module_open (library, G_MODULE_BIND_LAZY); + if (!widget_class->module) { + g_warning (_("Unable to open the module %s."), library); + goto lblError; + } + } + /* if there is an associated filename, then open and parse it */ if (filename != NULL) glade_widget_class_extend_with_file (widget_class, filename); @@ -693,36 +591,12 @@ glade_widget_class_new_from_name2 (const char *name, lblError: g_free (filename); + g_free (library); g_free (init_function_name); glade_widget_class_free (widget_class); return NULL; } -GladeWidgetClass * -glade_widget_class_new_from_name (const gchar *name) -{ - GladeWidgetClass *class; - GladeXmlContext *context; - GladeXmlDoc *doc; - gchar *file_name; - - file_name = g_strconcat (WIDGETS_DIR, "/", name, ".xml", NULL); - - context = glade_xml_context_new_from_path (file_name, NULL, GLADE_TAG_GLADE_WIDGET_CLASS); - if (!context) - return NULL; - doc = glade_xml_context_get_doc (context); - class = glade_widget_class_new_from_node (glade_xml_doc_get_root (doc)); - class->xml_file = g_strdup (name); - glade_xml_context_free (context); - - class->icon = glade_widget_class_create_icon (class); - - g_free (file_name); - - return class; -} - const gchar * glade_widget_class_get_name (GladeWidgetClass *widget) { diff --git a/src/glade-widget-class.h b/src/glade-widget-class.h index a29f8de2..23d95e31 100644 --- a/src/glade-widget-class.h +++ b/src/glade-widget-class.h @@ -2,8 +2,9 @@ #ifndef __GLADE_WIDGET_CLASS_H__ #define __GLADE_WIDGET_CLASS_H__ -G_BEGIN_DECLS +#include <gmodule.h> +G_BEGIN_DECLS typedef enum { GLADE_TOPLEVEL = 1 << 2, @@ -65,6 +66,11 @@ struct _GladeWidgetClass * are edited when the _child_ is selected. */ + GModule *module; /* Module with the (optional) special functions + * needed for placeholder_replace, post_create_function + * and the set & get functions of the properties + * of this class */ + void (*placeholder_replace) (GtkWidget *current, GtkWidget *new, GtkWidget *container); @@ -84,8 +90,7 @@ struct _GladeWidgetClassSignal * eg GtkButton */ }; -GladeWidgetClass *glade_widget_class_new_from_name (const char *name); -GladeWidgetClass *glade_widget_class_new_from_name2 (const char *name, const char *generic_name, const char *base_filename); +GladeWidgetClass *glade_widget_class_new (const char *name, const char *generic_name, const char *base_filename, const char *base_library); GladeWidgetClass *glade_widget_class_new_from_node (GladeXmlNode *node); void glade_widget_class_free (GladeWidgetClass *widget_class); GladeWidgetClass *glade_widget_class_get_by_name (const char *name); diff --git a/src/glade-widget.c b/src/glade-widget.c index 415b5f42..b02938a7 100644 --- a/src/glade-widget.c +++ b/src/glade-widget.c @@ -34,7 +34,6 @@ #include "glade-popup.h" #include "glade-placeholder.h" #include "glade-signal.h" -#include "glade-gtk.h" #include "glade-clipboard.h" #include "glade-command.h" #include "glade-debug.h" diff --git a/widgets/gtk-additional.xml b/widgets/gtk-additional.xml index 8c619a8a..72b0db09 100644 --- a/widgets/gtk-additional.xml +++ b/widgets/gtk-additional.xml @@ -1,4 +1,4 @@ -<GladeCatalog Title="Gtk+ Additional"> +<GladeCatalog Title="Gtk+ Additional" library="gtk"> <GladeWidget name="GtkHScale" generic_name="hscale"/> <GladeWidget name="GtkVScale" generic_name="vscale"/> diff --git a/widgets/gtk-base.xml b/widgets/gtk-base.xml index 04c44a2b..87e24899 100644 --- a/widgets/gtk-base.xml +++ b/widgets/gtk-base.xml @@ -1,4 +1,4 @@ -<GladeCatalog Title="Gtk+ Basic"> +<GladeCatalog Title="Gtk+ Basic" library="gtk"> <GladeWidget name="GtkWidget" filename="gtkwidget.xml"/> <GladeWidget name="GtkBox" filename="gtkbox.xml"/> diff --git a/widgets/gtkwidget.xml b/widgets/gtkwidget.xml index 3284f815..5d48b8c6 100644 --- a/widgets/gtkwidget.xml +++ b/widgets/gtkwidget.xml @@ -1,13 +1,11 @@ <GladeWidgetClass> - <Name>GtkWidget</Name> - <Properties> <Property Common="True" Id="visible"> <SetFunction>ignore</SetFunction> <GetFunction>ignore</GetFunction> </Property> - <Property Common="True" Optional="True" OptionalDefault="False" Default="0" Id="width-request"/> - <Property Common="True" Optional="True" OptionalDefault="False" Default="0" Id="height-request"/> + <Property Common="True" Optional="True" OptionalDefault="False" Default="0" Id="width-request"/> + <Property Common="True" Optional="True" OptionalDefault="False" Default="0" Id="height-request"/> </Properties> </GladeWidgetClass> diff --git a/widgets/gtkwindow.xml b/widgets/gtkwindow.xml index 171cd5c6..6f98e062 100644 --- a/widgets/gtkwindow.xml +++ b/widgets/gtkwindow.xml @@ -11,8 +11,8 @@ <Property Common="True" Id="tooltip" ParamSpec="False" Name="Tooltip"> <Type>String</Type> - <SetFunction>glade_gtk_widget_set_tooltip</SetFunction> - <GetFunction>glade_gtk_widget_get_tooltip</GetFunction> + <SetFunction>ignore</SetFunction> + <GetFunction>ignore</GetFunction> </Property> </Properties> |