From 39dd3c2680f769818533b65d80ba91ef067d2b35 Mon Sep 17 00:00:00 2001 From: Paolo Borelli Date: Thu, 23 Oct 2003 17:40:27 +0000 Subject: [PATCH] First support for internal children. Now you can add widgets to dialogs. Still doesn't handle xml reading and writing. --- ChangeLog | 11 +++++++++++ src/glade-command.c | 8 ++++++++ src/glade-gtk.c | 34 ++++++++++++++++++++++++++++++++- src/glade-placeholder.c | 15 ++++++--------- src/glade-widget-class.h | 3 ++- src/glade-widget.c | 41 ++++++++++++++++++++++++++++++++++++---- src/glade-widget.h | 11 +++++++++++ 7 files changed, 108 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8c21bd7..2c1692d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-10-23 Paolo Borelli + + * src/glade-widget.[ch]: add glade_widget_new_for_internal_child and + add an internal field to the GladeWidget struct. + * src/glade-gtk.c: create the GladeWidgets for the internal children + in dialog_fill_empty + * src/glade-placeholder.c: don't walk up the widget hierarchy when + getting the parent. + * src/glade-widget-class.h: add comment about internal children. + * src/glade-command.c: prevent internal children from being deleted. + 2003-10-22 Paolo Borelli * widgets/gtk-base.xml: readd hseparator and vseparator since they diff --git a/src/glade-command.c b/src/glade-command.c index 07655c85..402674c0 100644 --- a/src/glade-command.c +++ b/src/glade-command.c @@ -691,6 +691,10 @@ glade_command_delete (GladeWidget *widget) { g_return_if_fail (GLADE_IS_WIDGET (widget)); + /* internal children cannot be deleted. Should we notify the user? */ + if (widget->internal) + return; + glade_command_create_delete_common (widget, NULL, FALSE); } @@ -941,6 +945,10 @@ glade_command_cut (GladeWidget *widget) g_return_if_fail (GLADE_IS_WIDGET (widget)); + /* internal children cannot be cut. Should we notify the user? */ + if (widget->internal) + return; + glade_command_cut_paste_common (widget, NULL, widget->project, TRUE); } diff --git a/src/glade-gtk.c b/src/glade-gtk.c index 36ef0fc3..27f33e80 100644 --- a/src/glade-gtk.c +++ b/src/glade-gtk.c @@ -698,9 +698,41 @@ glade_gtk_container_fill_empty (GObject *container) void glade_gtk_dialog_fill_empty (GObject *dialog) { + GtkWidget *vbox; + GtkWidget *action_area; + GladeWidget *widget; + GladeWidget *vbox_widget; + GladeWidget *actionarea_widget; + GladeWidgetClass *child_class; + g_return_if_fail (GTK_IS_DIALOG (dialog)); - GtkWidget *vbox = GTK_DIALOG (dialog)->vbox; + widget = glade_widget_get_from_gtk_widget (GTK_WIDGET (dialog)); + if (!widget) + return; + + /* create the GladeWidgets for internal childrens */ + vbox = GTK_DIALOG (dialog)->vbox; + child_class = glade_widget_class_get_by_name ("GtkVBox"); + if (!child_class) + return; + + vbox_widget = glade_widget_new_for_internal_child (child_class, widget, + vbox, "vbox"); + if (!vbox_widget) + return; + + action_area = GTK_DIALOG (dialog)->action_area; + child_class = glade_widget_class_get_by_name ("GtkHButtonBox"); + if (!child_class) + return; + + actionarea_widget = glade_widget_new_for_internal_child (child_class, vbox_widget, + action_area, "action_area"); + if (!actionarea_widget) + return; + + /* add a placeholder in the vbox */ gtk_box_pack_start_defaults (GTK_BOX (vbox), glade_placeholder_new ()); } diff --git a/src/glade-placeholder.c b/src/glade-placeholder.c index a820fd71..7dfb2870 100644 --- a/src/glade-placeholder.c +++ b/src/glade-placeholder.c @@ -178,20 +178,17 @@ GladeWidget * glade_placeholder_get_parent (GladePlaceholder *placeholder) { GladeWidget *parent = NULL; - GtkWidget *widget = gtk_widget_get_parent (placeholder); + GtkWidget *widget; g_return_val_if_fail (GLADE_IS_PLACEHOLDER (placeholder), NULL); - while (widget != NULL) { - parent = glade_widget_get_from_gtk_widget (widget); + widget = gtk_widget_get_parent (placeholder); + g_return_val_if_fail (widget != NULL, NULL); - if (parent != NULL) - return parent; + parent = glade_widget_get_from_gtk_widget (widget); + g_return_val_if_fail (parent != NULL, NULL); - widget = gtk_widget_get_parent (widget); - } - - return NULL; + return parent; } void diff --git a/src/glade-widget-class.h b/src/glade-widget-class.h index be48afa6..412443c0 100644 --- a/src/glade-widget-class.h +++ b/src/glade-widget-class.h @@ -89,7 +89,8 @@ struct _GladeWidgetClass void (*post_create_function) (GObject *gobject); /* If the widget is a container, this method takes care of adding the - * needed placeholders. + * needed placeholders. If the widget has internal children, this method + * must create the associated GladeWidgets. */ void (*fill_empty) (GtkWidget *widget); }; diff --git a/src/glade-widget.c b/src/glade-widget.c index 49dd2843..0c85db35 100644 --- a/src/glade-widget.c +++ b/src/glade-widget.c @@ -100,6 +100,7 @@ glade_widget_new (GladeWidgetClass *class, GladeProject *project) widget = g_new0 (GladeWidget, 1); widget->project = project; widget->name = glade_widget_new_name (project, class); + widget->internal = NULL; widget->widget = NULL; widget->class = class; widget->properties = glade_widget_properties_from_list (class->properties, widget); @@ -145,7 +146,7 @@ glade_widget_get_parent (GladeWidget *widget) g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - if (GLADE_WIDGET_IS_TOPLEVEL (widget)) + if (GTK_WIDGET_TOPLEVEL (widget->widget)) return NULL; parent_widget = gtk_widget_get_parent (widget->widget); @@ -555,9 +556,8 @@ glade_widget_free (GladeWidget *widget) widget->project = NULL; widget->widget = NULL; - if (widget->name) - g_free (widget->name); - widget->name = NULL; + g_free (widget->name); + g_free (widget->internal); g_list_foreach(widget->properties, (GFunc) glade_property_free, NULL); g_list_free (widget->properties); @@ -689,6 +689,39 @@ glade_widget_new_full (GladeWidgetClass *class, return widget; } +/** + * glade_widget_new_for_internal_child + * @class + * @parent + * @widget + * @internal + * + * Creates, fills and associate a GladeWidget to the GtkWidget of + * internal childern. + **/ +GladeWidget * +glade_widget_new_for_internal_child (GladeWidgetClass *class, + GladeWidget *parent, + GtkWidget *widget, + const gchar *internal) +{ + GladeWidget *glade_widget; + + g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), NULL); + g_return_val_if_fail (GLADE_IS_WIDGET (parent), NULL); + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); + g_return_val_if_fail (internal != NULL, NULL); + + glade_widget = glade_widget_new (class, parent->project); + if (!glade_widget) + return NULL; + + glade_widget_associate_with_gtk_widget (glade_widget, widget); + glade_widget_set_packing_properties (glade_widget, parent->class); + glade_widget->internal = g_strdup (internal); + + return glade_widget; +} /** * Temp struct to hold the results of a query. * The keys of the hashtable are the GladePropertyClass->id , while the diff --git a/src/glade-widget.h b/src/glade-widget.h index d526bc60..40a2ec43 100644 --- a/src/glade-widget.h +++ b/src/glade-widget.h @@ -26,6 +26,12 @@ struct _GladeWidget * used when loading widget with libglade */ + gchar *internal; /* If the widget is an internal child of + * another widget this is the name of the + * internal child, otherwise is NULL. + * Internal children cannot be deleted. + */ + GtkWidget *widget; /* A pointer to the widget that was created. * and is shown as a "view" of the GladeWidget. * This widget is updated as the properties are @@ -65,6 +71,11 @@ GladeWidget *glade_widget_new_from_class (GladeWidgetClass *class, GladeProject *project, GladeWidget *parent); +GladeWidget *glade_widget_new_for_internal_child (GladeWidgetClass *class, + GladeWidget *parent, + GtkWidget *widget, + const gchar *internal); + void glade_widget_set_default_packing_options (GladeWidget *widget); const gchar *glade_widget_get_name (GladeWidget *widget);