First support for internal children. Now you can add widgets to dialogs. Still

doesn't handle xml reading and writing.
This commit is contained in:
Paolo Borelli 2003-10-23 17:40:27 +00:00
parent 333ccf945d
commit 39dd3c2680
7 changed files with 108 additions and 15 deletions

View File

@ -1,3 +1,14 @@
2003-10-23 Paolo Borelli <pborelli@katamail.com>
* 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 <pborelli@katamail.com>
* widgets/gtk-base.xml: readd hseparator and vseparator since they

View File

@ -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);
}

View File

@ -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 ());
}

View File

@ -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

View File

@ -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);
};

View File

@ -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

View File

@ -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);