diff --git a/ChangeLog b/ChangeLog index 1f81629d..59c4c458 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2001-06-27 Chema Celorio + + * src/glade-widget-class.[ch], src/glade-widget.[ch]: Store signals + available to a widget in the GladeWidgetClass and instances and their + handlers in GladeWidget. + * src/glade-editor.[ch], src/glade-signal-editor.[ch]: Add new signal editor + and add provsions for GladeEditor to use. + * src/glade-types.h: Add typedefs for GladeSignalEditor, GladeWidgetSignal + and GladeWidgetClassSignal. + 2001-06-27 Chema Celorio * src/glade-property-class.c (glade_property_class_get_specs): diff --git a/pixmaps/Makefile.am b/pixmaps/Makefile.am index d08fa834..ba92d2ae 100644 --- a/pixmaps/Makefile.am +++ b/pixmaps/Makefile.am @@ -1,6 +1,7 @@ pixmaps_DATA = \ window.xpm \ button.xpm \ + checkbutton.xpm \ vbox.xpm \ hbox.xpm \ label.xpm \ diff --git a/src/Makefile.am b/src/Makefile.am index cd30d278..da8ab052 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,7 +36,8 @@ glade2_SOURCES = \ glade-widget.c \ glade-catalog.c \ glade-choice.c \ - glade-editor.c + glade-editor.c \ + glade-signal-editor.c noinst_HEADERS = \ glade.h \ @@ -45,6 +46,7 @@ noinst_HEADERS = \ glade-parameter.h \ glade-placeholder.h \ glade-editor.h \ + glade-signal-editor.h \ glade-palette.h \ glade-cursor.h \ glade-project-window.h \ diff --git a/src/glade-editor.c b/src/glade-editor.c index f189da23..c3d1d6d9 100644 --- a/src/glade-editor.c +++ b/src/glade-editor.c @@ -24,6 +24,7 @@ #define GLADE_PROPERY_TABLE_ROW_SPACING 2 #include /* for atoi and atof */ +#include #include "glade.h" @@ -31,6 +32,7 @@ #include "glade-widget-class.h" #include "glade-choice.h" #include "glade-editor.h" +#include "glade-signal-editor.h" #include "glade-parameter.h" #include "glade-project-window.h" #include "glade-property.h" @@ -733,10 +735,22 @@ glade_editor_load_widget_page (GladeEditor *editor, GladeWidgetClass *class) TRUE, TRUE, 0); } +static void +glade_editor_load_signal_page (GladeEditor *editor, GladeWidgetClass *class) +{ + + if (editor->signal_editor == NULL) { + editor->signal_editor = glade_signal_editor_new (); + gtk_box_pack_start (GTK_BOX (editor->vbox_signals), glade_signal_editor_get_widget (editor->signal_editor), + TRUE, TRUE, 0); + } +} + static void glade_editor_load_class (GladeEditor *editor, GladeWidgetClass *class) { glade_editor_load_widget_page (editor, class); + glade_editor_load_signal_page (editor, class); editor->loaded_class = class; } @@ -997,6 +1011,8 @@ glade_editor_load_item (GladeEditor *editor, GladeWidget *item) property = list->data; glade_editor_property_load (property, item); } + + glade_signal_editor_load_widget (editor->signal_editor, item); } diff --git a/src/glade-editor.h b/src/glade-editor.h index 3e38a069..753b0b99 100644 --- a/src/glade-editor.h +++ b/src/glade-editor.h @@ -64,9 +64,10 @@ struct _GladeEditor GtkWidget *vbox_common; /* We might not need this pointer. Not yet * implemented */ - GtkWidget *vbox_signals; /* We might not need this pointer. Not yet - * implemented. - */ + GtkWidget *vbox_signals; /* Widget from the GladeSignalEditor is placed + * here + */ + GladeSignalEditor *signal_editor; GList * widget_tables; /* A list of GladeEditorTable. We have a table * (gtktable) for each GladeWidgetClass, if diff --git a/src/glade-parameter.c b/src/glade-parameter.c index d85b1244..ce88e64b 100644 --- a/src/glade-parameter.c +++ b/src/glade-parameter.c @@ -21,6 +21,7 @@ */ #include /* for atoi and atof */ +#include #include "glade.h" #include "glade-xml-utils.h" @@ -98,6 +99,20 @@ glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value) } } } + +static void +glade_parameter_free (GladeParameter *parameter) +{ + g_return_if_fail (parameter->key); + g_return_if_fail (parameter->value); + + g_free (parameter->key); + g_free (parameter->value); + parameter->key = NULL; + parameter->value = NULL; + g_free (parameter); +} + GladeParameter * glade_parameter_new (void) { @@ -127,11 +142,27 @@ glade_parameter_new_from_node (xmlNodePtr node) } GList * -glade_parameter_list_new_from_node (xmlNodePtr node) +glade_parameter_list_find_by_key (GList *list, const gchar *key) +{ + GladeParameter *parameter; + + for (; list != NULL; list = list->next) { + parameter = list->data; + g_return_val_if_fail (parameter->key != NULL, NULL); + if (strcmp (parameter->key, key) == 0) + return list; + } + + return NULL; +} + + +GList * +glade_parameter_list_new_from_node (GList *list, xmlNodePtr node) { GladeParameter *parameter; xmlNodePtr child; - GList *list; + GList *findme; if (!glade_xml_node_verify (node, GLADE_TAG_PARAMETERS)) return NULL; @@ -139,7 +170,6 @@ glade_parameter_list_new_from_node (xmlNodePtr node) if (child == NULL) return NULL; - list = NULL; child = node->children; while (child != NULL) { @@ -149,6 +179,18 @@ glade_parameter_list_new_from_node (xmlNodePtr node) parameter = glade_parameter_new_from_node (child); if (parameter == NULL) return NULL; + /* Is this parameter already there ? just replace + * the pointer and free the old one + */ + 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; + } + list = g_list_prepend (list, parameter); child = child->next; } diff --git a/src/glade-parameter.h b/src/glade-parameter.h index e6912b09..545e8f29 100644 --- a/src/glade-parameter.h +++ b/src/glade-parameter.h @@ -39,7 +39,7 @@ void glade_parameter_get_boolean (GList *parameters, const gchar *key, gboolean void glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value); -GList * glade_parameter_list_new_from_node (xmlNodePtr node); +GList * glade_parameter_list_new_from_node (GList *list, xmlNodePtr node); /* Convenience functions */ GtkAdjustment * glade_parameter_adjustment_new (GList *parameters); diff --git a/src/glade-project-view.c b/src/glade-project-view.c index 8fe86cbf..7d4f4309 100644 --- a/src/glade-project-view.c +++ b/src/glade-project-view.c @@ -88,10 +88,10 @@ glade_project_view_find_iter (GtkTreeModel *model, return gtk_tree_iter_copy (next); /* Me ? leaking ? nah .... */ #if 1 - if (gtk_tree_model_iter_has_child (model, iter)) { + if (gtk_tree_model_iter_has_child (model, next)) { GtkTreeIter *child = g_new0 (GtkTreeIter, 1); - GtkTreeIter *retval = g_new0 (GtkTreeIter, 1); - gtk_tree_model_iter_children (model, child, iter); + GtkTreeIter *retval = NULL; + gtk_tree_model_iter_children (model, child, next); retval = glade_project_view_find_iter (model, child, findme); diff --git a/src/glade-property-class.c b/src/glade-property-class.c index 3b1b6d43..8291a89d 100644 --- a/src/glade-property-class.c +++ b/src/glade-property-class.c @@ -181,10 +181,11 @@ glade_property_class_get_type_from_spec (GParamSpec *spec) { switch (G_PARAM_SPEC_TYPE (spec)) { -#if 0 case G_TYPE_PARAM_INT: + return GLADE_PROPERTY_TYPE_INTEGER; case G_TYPE_PARAM_FLOAT: -#endif + g_warning ("Float not yet implemented\n"); + break; case G_TYPE_PARAM_BOOLEAN: return GLADE_PROPERTY_TYPE_BOOLEAN; case G_TYPE_PARAM_STRING: @@ -193,9 +194,9 @@ glade_property_class_get_type_from_spec (GParamSpec *spec) return GLADE_PROPERTY_TYPE_CHOICE; default: g_warning ("Could not determine GladePropertyType from spec"); - return GLADE_PROPERTY_TYPE_ERROR; } - + + return GLADE_PROPERTY_TYPE_ERROR; } static GladeChoice * @@ -234,15 +235,55 @@ glade_property_class_get_choices_from_spec (GParamSpec *spec) return list; } -static GladeParameter * -glade_property_get_parameter_default_choice (GParamSpec *spec, - GladePropertyClass *class) +static GList * +glade_property_get_parameters_boolean (GParamSpec *spec, + GladePropertyClass *class) +{ + GladeParameter *parameter; + gint def; + + g_return_val_if_fail (G_IS_PARAM_SPEC_BOOLEAN (spec), NULL); + + def = (gint) G_PARAM_SPEC_BOOLEAN (spec)->default_value; + + parameter = glade_parameter_new (); + 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); +} + +static GList * +glade_property_get_parameters_integer (GParamSpec *spec, + GladePropertyClass *class) +{ + GladeParameter *parameter; + gint def; + + g_return_val_if_fail (G_IS_PARAM_SPEC_INT (spec), NULL); + + def = (gint) G_PARAM_SPEC_INT (spec)->default_value; + + parameter = glade_parameter_new (); + parameter->key = g_strdup ("Default"); + parameter->value = g_strdup_printf ("%i", def); + + return g_list_prepend (NULL, parameter); +} + +static GList * +glade_property_get_parameters_choice (GParamSpec *spec, + GladePropertyClass *class) { GladeParameter *parameter; GladeChoice *choice = NULL; GList *list; gint def; - + + g_return_val_if_fail (G_IS_PARAM_SPEC_ENUM (spec), NULL); + def = (gint) G_PARAM_SPEC_ENUM (spec)->default_value; list = class->choices; @@ -257,44 +298,64 @@ glade_property_get_parameter_default_choice (GParamSpec *spec, return NULL; choice = class->choices->data; } - + parameter = glade_parameter_new (); parameter->key = g_strdup ("Default"); parameter->value = g_strdup (choice->symbol); - return parameter; + /* The "list" pointer is now used for something else */ + list = g_list_prepend (NULL, parameter); + + return list; } static GList * glade_property_class_get_parameters_from_spec (GParamSpec *spec, - GladePropertyClass *class) + GladePropertyClass *class, + xmlNodePtr node) { - GladeParameter *parameter; GList *parameters = NULL; + xmlNodePtr child; + g_print ("Go %s\n", class->name); switch (class->type) { case GLADE_PROPERTY_TYPE_CHOICE: - parameter = glade_property_get_parameter_default_choice (spec, - class); - parameters = g_list_prepend (parameters, parameter); + parameters = glade_property_get_parameters_choice (spec, + class); break; case GLADE_PROPERTY_TYPE_TEXT: break; case GLADE_PROPERTY_TYPE_INTEGER: + parameters = glade_property_get_parameters_integer (spec, + class); break; case GLADE_PROPERTY_TYPE_FLOAT: break; case GLADE_PROPERTY_TYPE_BOOLEAN: + parameters = glade_property_get_parameters_boolean (spec, + class); break; default: + g_print ("No parameters for %s\n", class->name); } + /* Get the parameters that are specified on the glade file, + * they can overwrite gtk+ settings. For example the default + * size of a GtkWindow is 0,0 which we need to overwrite. + */ + child = glade_xml_search_child (node, GLADE_TAG_PARAMETERS); + if (child != NULL) + parameters = glade_parameter_list_new_from_node (parameters, + child); + return parameters; } static GladePropertyClass * -glade_property_class_new_from_param_spec (const gchar *name, GladeWidgetClass *widget_class) +glade_property_class_new_from_param_spec (const gchar *name, + GladeWidgetClass *widget_class, + xmlNodePtr node) { GladePropertyClass *class; GParamSpec *spec; @@ -315,7 +376,7 @@ glade_property_class_new_from_param_spec (const gchar *name, GladeWidgetClass *w if (class->type == GLADE_PROPERTY_TYPE_CHOICE) class->choices = glade_property_class_get_choices_from_spec (spec); - class->parameters = glade_property_class_get_parameters_from_spec (spec, class); + class->parameters = glade_property_class_get_parameters_from_spec (spec, class, node); return class; } @@ -337,10 +398,10 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl if (name == NULL) return NULL; - /* Can we load this property from the ParamSpec ? */ + /* Should we load this property from the ParamSpec ? */ child = glade_xml_search_child (node, GLADE_TAG_PARAM_SPEC); if (child) { - property_class = glade_property_class_new_from_param_spec (name, widget_class); + property_class = glade_property_class_new_from_param_spec (name, widget_class, node); g_free (name); return property_class; } @@ -363,7 +424,7 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl /* Get the Parameters */ child = glade_xml_search_child (node, GLADE_TAG_PARAMETERS); if (child != NULL) - property_class->parameters = glade_parameter_list_new_from_node (child); + property_class->parameters = glade_parameter_list_new_from_node (NULL, child); glade_parameter_get_boolean (property_class->parameters, "Optional", &property_class->optional); /* Get the Query */ diff --git a/src/glade-property.c b/src/glade-property.c index 68171e9a..e23f4430 100644 --- a/src/glade-property.c +++ b/src/glade-property.c @@ -21,6 +21,7 @@ */ #include /* for atoi and atof */ +#include #include "glade.h" #include "glade-choice.h" diff --git a/src/glade-types.h b/src/glade-types.h index 9fc5f269..fadafb2f 100644 --- a/src/glade-types.h +++ b/src/glade-types.h @@ -2,10 +2,13 @@ typedef struct _GladePaletteSection GladePaletteSection; typedef struct _GladePalette GladePalette; typedef struct _GladeEditor GladeEditor; +typedef struct _GladeSignalEditor GladeSignalEditor; typedef struct _GladeProject GladeProject; typedef struct _GladeWidget GladeWidget; +typedef struct _GladeWidgetSignal GladeWidgetSignal; typedef struct _GladeWidgetClass GladeWidgetClass; +typedef struct _GladeWidgetClassSignal GladeWidgetClassSignal; typedef struct _GladeProperty GladeProperty; typedef struct _GladePropertyClass GladePropertyClass; diff --git a/src/glade-widget-class.c b/src/glade-widget-class.c index 7556cf02..5ec38cf7 100644 --- a/src/glade-widget-class.c +++ b/src/glade-widget-class.c @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -72,6 +73,44 @@ glade_widget_class_add_virtual_methods (GladeWidgetClass *class) } +GList * +glade_widget_class_list_signals (GladeWidgetClass *class) +{ + GList *signals; + GType type; + guint count; + guint *sig_ids; + guint num_signals; + GladeWidgetClassSignal *cur; + + signals = NULL; + /* FIXME: This should work. Apparently this is because you need to have an + * instance of an object before you can get its type?!? need to fix this + * to use class->type when bighead applys his patch. - shane + */ + type = g_type_from_name (class->name); + + g_return_val_if_fail (type != 0, NULL); + + while (g_type_is_a (type, GTK_TYPE_OBJECT)) { + if (G_TYPE_IS_INSTANTIATABLE (type) || G_TYPE_IS_INTERFACE (type)) { + sig_ids = g_signal_list_ids (type, &num_signals); + + for (count = 0; count < num_signals; count++) { + cur = g_new0 (GladeWidgetClassSignal, 1); + cur->name = (gchar *) g_signal_name (sig_ids[count]); + cur->type = (gchar *) g_type_name (type); + + signals = g_list_append (signals, (GladeWidgetClassSignal *) cur); + } + } + + type = g_type_parent (type); + } + + return signals; +} + static GladeWidgetClass * glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node) { @@ -91,6 +130,7 @@ glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node) 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); class->properties = glade_property_class_list_new_from_node (child, class); + class->signals = glade_widget_class_list_signals (class); if (!class->name || !class->icon || diff --git a/src/glade-widget-class.h b/src/glade-widget-class.h index 3605b504..c4377503 100644 --- a/src/glade-widget-class.h +++ b/src/glade-widget-class.h @@ -50,11 +50,23 @@ struct _GladeWidgetClass { * editor. */ + GList *signals; /* List of GladeWidgetClassSignal objects */ + void (*placeholder_replace) (GladePlaceholder *placeholder, GladeWidget *widget, GladeWidget *parent); }; +/* GladeWidgetClassSignal contains all the info we need for a given signal, such as + * the signal name, and maybe more in the future + */ +struct _GladeWidgetClassSignal { + + gchar *name; /* Name of the signal, eg clicked */ + gchar *type; /* Name of the object class that this signal belongs to + * eg GtkButton */ +}; + GladeWidgetClass * glade_widget_class_new_from_name (const gchar *name); const gchar * glade_widget_class_get_name (GladeWidgetClass *class); diff --git a/src/glade-widget.c b/src/glade-widget.c index ec548aca..0ff7a249 100644 --- a/src/glade-widget.c +++ b/src/glade-widget.c @@ -284,7 +284,7 @@ glade_widget_button_release (GtkWidget *widget, GdkEventButton *event, GladeWidg } -#if 0 +#if 1 /** * glade_widget_set_default_options: * @widget: @@ -344,21 +344,6 @@ glade_widget_register (GladeProject *project, GladeWidgetClass *class, GtkWidget if (parent) parent->children = g_list_prepend (parent->children, glade_widget); -#if 0 - glade_widget_set_default_options (glade_widget); -#else - { - static gboolean warned = FALSE; - if (!warned) { - g_print ("Not setting the default options yet\n"); - warned = TRUE; - } - } -#endif - - /* Add a pointer to the GladeWidget in the GtkWidget */ - gtk_object_set_data (GTK_OBJECT (gtk_widget), GLADE_WIDGET_DATA_TAG, glade_widget); - return glade_widget; } @@ -502,7 +487,12 @@ glade_widget_create_gtk_widget (GladeProject *project, } glade_widget = glade_widget_register (project, class, widget, name, parent); + + glade_widget_set_default_options (glade_widget); + /* We need to be able to get to the GladeWidget * from a GtkWidget * */ + gtk_object_set_data (GTK_OBJECT (glade_widget->widget), GLADE_WIDGET_DATA_TAG, glade_widget); + /* FIXME */ if ((strcmp (class->name, "GtkLabel") == 0) || (strcmp (class->name, "GtkButton") == 0)) { @@ -592,7 +582,7 @@ GladeProperty * glade_widget_get_property_from_class (GladeWidget *widget, GladePropertyClass *property_class) { - GladeProperty *property; + GladeProperty *property = NULL; GList *list; list = widget->properties; diff --git a/src/glade-widget.h b/src/glade-widget.h index 79ece580..7ed9d394 100644 --- a/src/glade-widget.h +++ b/src/glade-widget.h @@ -40,6 +40,8 @@ struct _GladeWidget { * property is "Ok". */ + GList *signals; /* A list of GladeWidgetSignals */ + /* Tree Structure */ GladeWidget *parent; /* The parent of this widget, NULL if this is a * toplevel widget. @@ -50,6 +52,14 @@ struct _GladeWidget { gboolean selected; }; +/* GladeWidgetSignal is a structure that holds information about a signal a + * widget wants for handle / listen for. + */ +struct _GladeWidgetSignal { + gchar *name; /* Signal name eg "clicked" */ + gchar *handler; /* Handler function eg "gtk_main_quit" */ + gboolean after; /* Connect after TRUE or FALSE */ +}; GladeWidget * glade_widget_new_from_class (GladeProject *project, diff --git a/widgets/Makefile.am b/widgets/Makefile.am index 48431df9..3ee89ebd 100644 --- a/widgets/Makefile.am +++ b/widgets/Makefile.am @@ -2,6 +2,7 @@ widgets_DATA = \ catalog.xml \ gtkwindow.xml \ gtkbutton.xml \ + gtkcheckbutton.xml \ gtklabel.xml \ gtkvbox.xml \ gtkhbox.xml \ diff --git a/widgets/catalog.xml b/widgets/catalog.xml index 2b8e9316..c203a805 100644 --- a/widgets/catalog.xml +++ b/widgets/catalog.xml @@ -1,6 +1,7 @@ gtkwindow gtkbutton + gtkcheckbutton gtklabel gtkhbox gtkvbox diff --git a/widgets/gtkwindow.xml b/widgets/gtkwindow.xml index 8122bf48..ccdd4436 100644 --- a/widgets/gtkwindow.xml +++ b/widgets/gtkwindow.xml @@ -7,28 +7,6 @@ - - Integer - Border Width - The width of the border arround the container - border-width - - - - - - - - - - - - title @@ -48,41 +26,23 @@ modal - + - Integer - Default Width - The default width of the window - + default-width + - - - - - - - - - + + - + - Integer - Default Height - The default height of the window - + default-height + - - - - - - - - - + + - + allow-shrink @@ -99,19 +59,21 @@ + + fixme Text WM Class The class name to pass to the window manager - + fixme +-->