Commit 94018521 authored by Mikael Hallendal's avatar Mikael Hallendal Committed by Mikael Hallendal

- Removed temporary hack


2005-01-16  Mikael Hallendal  <micke@imendio.com>

	* src/glade-gtk.c: (glade_gtk_menu_bar_post_create):
	- Removed temporary hack
	* src/glade-widget-class.[ch]:
	(glade_widget_class_free):
	- Free default packing list
	(glade_widget_class_set_packing_defaults_from_node):
	- Read default child packings from catalog file.
	(glade_widget_class_get_child_packing):
	(glade_widget_class_get_packing_default_internal):
	- Added
	(glade_widget_class_get_packing_default):
	- Added, used to get the default child packing when packing a widget
	  into a specific container.
	* src/glade-widget.c: (glade_widget_copy_packing_props),
	(glade_widget_set_default_packing_properties):
	- Added, sets the default packing properties.
	(glade_widget_set_packing_properties):
	- Call set_default_packing_properties.
	* widgets/gtk+.xml:
	- Added default packings for some widgets. Should be added to a lot
	  more of them.
parent dc3bbb14
2005-01-16 Mikael Hallendal <micke@imendio.com>
* src/glade-gtk.c: (glade_gtk_menu_bar_post_create):
- Removed temporary hack
* src/glade-widget-class.[ch]:
(glade_widget_class_free):
- Free default packing list
(glade_widget_class_set_packing_defaults_from_node):
- Read default child packings from catalog file.
(glade_widget_class_get_child_packing):
(glade_widget_class_get_packing_default_internal):
- Added
(glade_widget_class_get_packing_default):
- Added, used to get the default child packing when packing a widget
into a specific container.
* src/glade-widget.c: (glade_widget_copy_packing_props),
(glade_widget_set_default_packing_properties):
- Added, sets the default packing properties.
(glade_widget_set_packing_properties):
- Call set_default_packing_properties.
* widgets/gtk+.xml:
- Added default packings for some widgets. Should be added to a lot
more of them.
2005-01-13 Mikael Hallendal <micke@imendio.com>
* src/glade-gtk.c: (glade_gtk_menu_bar_post_create):
......
......@@ -803,7 +803,6 @@ glade_command_create (GladeWidgetClass *class,
me->widgets = g_list_append (me->widgets, cdata);
/* widget may be null, e.g. the user clicked cancel on a query */
if ((widget = glade_widget_new (parent, class, project)) == NULL)
{
......
......@@ -1155,18 +1155,10 @@ glade_gtk_menu_bar_post_create (GObject *object)
{
GtkMenuBar *menu_bar;
GtkWidget *item;
GtkWidget *parent;
g_return_if_fail (GTK_IS_MENU_BAR (object));
menu_bar = GTK_MENU_BAR (object);
parent = gtk_widget_get_parent (GTK_WIDGET (menu_bar));
if (!parent)
g_print ("NOOOOO PARENT\n");
gtk_box_set_child_packing (GTK_BOX (parent), GTK_WIDGET (menu_bar),
FALSE, TRUE, 0, GTK_PACK_START);
item = gtk_menu_item_new_with_mnemonic (_("_File"));
gtk_menu_bar_append (menu_bar, item);
......
......@@ -113,6 +113,7 @@ glade_popup_add_item_cb (GtkMenuItem *item,
GladeWidget *widget)
{
GladeWidgetClass *class;
if ((class =
g_object_get_data (G_OBJECT (item), "widget_class")) != 0)
glade_command_create (class, widget, NULL, NULL);
......
......@@ -101,7 +101,11 @@ glade_widget_class_free (GladeWidgetClass *widget_class)
g_list_foreach (widget_class->children, (GFunc) glade_widget_class_free_child, NULL);
g_list_free (widget_class->children);
g_list_foreach (widget_class->child_packings,
(GFunc) glade_widget_class_child_packing_free,
NULL);
g_list_free (widget_class->child_packings);
g_list_foreach (widget_class->signals, (GFunc) glade_signal_free, NULL);
g_list_free (widget_class->signals);
......@@ -425,6 +429,8 @@ glade_widget_class_set_packing_defaults_from_node (GladeXmlNode *node,
packing->parent_name = name;
packing->packing_defaults = NULL;
widget_class->child_packings = g_list_prepend (widget_class->child_packings, packing);
prop_node = glade_xml_node_get_children (child);
for (; prop_node; prop_node = glade_xml_node_next (prop_node))
{
......@@ -446,7 +452,7 @@ glade_widget_class_set_packing_defaults_from_node (GladeXmlNode *node,
g_free (id);
continue;
}
def = g_new0 (GladePackingDefault, 1);
def->id = id;
def->value = value;
......@@ -1182,7 +1188,7 @@ glade_widget_class_container_add (GladeWidgetClass *class,
if ((support =
glade_widget_class_get_child_support (class, G_OBJECT_TYPE (child))) != NULL)
{
if (support->add)
if (support->add)
support->add (container, child);
else
g_warning ("No add support for type %s in %s",
......@@ -1350,23 +1356,79 @@ glade_widget_class_contains_non_widgets (GladeWidgetClass *class)
return FALSE;
}
/* Returned list should be freed with g_list_free */
GList *
glade_widget_class_get_packing_defaults (GladeWidgetClass *class,
GladeWidgetClass *parent)
static GladeChildPacking *
glade_widget_class_get_child_packing (GladeWidgetClass *child_class,
GladeWidgetClass *parent_class)
{
GList *l;
for (l = class->packing_defaults; l; l = l->next)
{
GList *l;
for (l = child_class->child_packings; l; l = l->next)
{
GladeChildPacking *packing;
packing = (GladeChildPacking *) l->data;
/* FIXME: Chain up */
if (strcmp (packing->parent_name, parent->name) == 0)
return g_list_copy (packing->packing_defaults);
if (strcmp (packing->parent_name, parent_class->name) == 0)
return packing;
}
return NULL;
return NULL;
}
static GladePackingDefault *
glade_widget_class_get_packing_default_internal (GladeChildPacking *packing,
const gchar *id)
{
GList *l;
for (l = packing->packing_defaults; l; l = l->next)
{
GladePackingDefault *def;
def = (GladePackingDefault *) l->data;
if (strcmp (def->id, id) == 0)
return def;
}
return NULL;
}
GladePackingDefault *
glade_widget_class_get_packing_default (GladeWidgetClass *child_class,
GladeWidgetClass *container_class,
const gchar *id)
{
GladeChildPacking *packing = NULL;
GladeWidgetClass *p_class;
GType p_type;
p_type = container_class->type;
p_class = container_class;
while (p_class)
{
GType old_p_type;
packing = glade_widget_class_get_child_packing (child_class,
p_class);
if (packing)
{
GladePackingDefault *def;
def = glade_widget_class_get_packing_default_internal (packing, id);
if (def)
return def;
}
old_p_type = p_type;
p_type = g_type_parent (p_type);
if (!p_type)
break;
p_class = glade_widget_class_get_by_type (p_type);
}
return NULL;
}
......@@ -64,7 +64,7 @@ struct _GladeWidgetClass
GList *signals; /* List of GladeWidgetClassSignal objects */
GList *children; /* List of GladeSupportedChild objects */
GList *packing_defaults; /* List of GladeChildProperty objects */
GList *child_packings; /* Private */
GModule *module; /* Module with the (optional) special functions
* needed for placeholder_replace, post_create_function
......@@ -190,8 +190,10 @@ void glade_widget_class_container_replace_child (GladeWidgetC
GObject *new);
gboolean glade_widget_class_contains_non_widgets (GladeWidgetClass *class);
GList * glade_widget_class_get_packing_defaults (GladeWidgetClass *class,
GladeWidgetClass *parent);
GladePackingDefault *glade_widget_class_get_packing_default (GladeWidgetClass *child_class,
GladeWidgetClass *container_class,
const gchar *propert_id);
G_END_DECLS
#endif /* __GLADE_WIDGET_CLASS_H__ */
......@@ -309,6 +309,7 @@ glade_widget_copy_packing_props (GladeWidget *parent,
GladeWidget *template)
{
GList *l;
glade_widget_set_packing_properties (child, parent);
for (l = child->packing_properties; l && l->data; l = l->next)
......@@ -476,7 +477,7 @@ glade_widget_build_object (GladeWidgetClass *klass, GladeWidget *widget)
*/
object = g_object_newv(klass->type, params->len,
(GParameter *)params->data);
/* Cleanup parameters
*/
for (i = 0; i < params->len; i++)
......@@ -489,6 +490,50 @@ glade_widget_build_object (GladeWidgetClass *klass, GladeWidget *widget)
return object;
}
static void
glade_widget_set_default_packing_properties (GladeWidget *container,
GladeWidget *child)
{
GladeSupportedChild *support;
support = glade_widget_class_get_child_support (container->widget_class,
child->widget_class->type);
if (support) {
GladePropertyClass *property_class;
GladeProperty *property;
GList *l;
for (l = support->properties; l; l = l->next)
{
GladePackingDefault *def;
GValue *value;
property_class = l->data;
def = glade_widget_class_get_packing_default (child->widget_class,
container->widget_class,
property_class->id);
if (!def)
continue;
/* Check value type */
value = glade_property_class_make_gvalue_from_string (property_class,
def->value);
glade_widget_class_container_set_property (container->widget_class,
container->object,
child->object,
property_class->id,
value);
g_value_unset (value);
g_free (value);
}
}
}
static GladeWidget *
glade_widget_internal_new (const gchar *name,
GladeWidget *parent,
......@@ -499,7 +544,7 @@ glade_widget_internal_new (const gchar *name,
GObject *object;
GObject *glade_widget;
GList *properties = NULL;
object = glade_widget_build_object(klass, template);
if (template)
properties = glade_widget_dup_properties (template->properties);
......@@ -532,7 +577,7 @@ glade_widget_new (GladeWidget *parent, GladeWidgetClass *klass, GladeProject *pr
gchar *widget_name =
glade_project_new_widget_name
(project, klass->generic_name);
if ((widget = glade_widget_internal_new
(widget_name, parent, klass, project, NULL)) != NULL)
{
......@@ -1626,6 +1671,9 @@ glade_widget_set_packing_properties (GladeWidget *widget,
g_list_foreach (widget->packing_properties, (GFunc) glade_property_free, NULL);
g_list_free (widget->packing_properties);
glade_widget_set_default_packing_properties (container, widget);
widget->packing_properties = glade_widget_create_packing_properties (container, widget);
/* update the values of the properties to the ones we get from gtk */
......@@ -1672,9 +1720,8 @@ glade_widget_replace (GladeWidget *parent, GObject *old_object, GObject *new_obj
(parent->widget_class, parent->object,
old_object, new_object);
if (gnew_widget)
if (gnew_widget)
glade_widget_set_packing_properties (gnew_widget, parent);
}
/* XML Serialization */
......@@ -2137,7 +2184,7 @@ glade_widget_new_from_widget_info (GladeWidgetInfo *info,
g_warning ("Widget class %s unknown.", info->classname);
return NULL;
}
params = glade_widget_params_from_widget_info (klass, info);
properties = glade_widget_properties_from_widget_info (klass, info);
......
......@@ -138,7 +138,6 @@ GladeWidget *glade_widget_get_parent (GladeWidget *w
void glade_widget_set_parent (GladeWidget *widget,
GladeWidget *parent);
G_END_DECLS
#endif /* __GLADE_WIDGET_H__ */
......@@ -100,9 +100,6 @@
<glade-widget-class name="GtkMenuBar" generic-name="menubar" title="Menu Bar">
<post-create-function>glade_gtk_menu_bar_post_create</post-create-function>
<properties>
<property id="expand" default="False"/>
</properties>
<!-- menubar is a container you can't add placeholders to it -->
<children>
<child>
......@@ -111,7 +108,7 @@
</child>
</children>
<packing-defaults>
<parent-class name="GtkBox">
<parent-class name="GtkVBox">
<child-property id="expand" default="false"/>
</parent-class>
</packing-defaults>
......@@ -363,10 +360,24 @@
<glade-widget-class name="GtkVButtonBox" generic-name="vbuttonbox" title="Vertical Button Box"/>
<glade-widget-class name="GtkHSeparator" generic-name="hseparator" title="Horizontal Separator"/>
<glade-widget-class name="GtkHSeparator" generic-name="hseparator" title="Horizontal Separator">
<packing-defaults>
<parent-class name="GtkVBox">
<child-property id="expand" default="false"/>
</parent-class>
</packing-defaults>
<glade-widget-class name="GtkVSeparator" generic-name="vseparator" title="Vertical Separator"/>
</glade-widget-class>
<glade-widget-class name="GtkVSeparator" generic-name="vseparator" title="Vertical Separator">
<packing-defaults>
<parent-class name="GtkHBox">
<child-property id="expand" default="false"/>
</parent-class>
</packing-defaults>
</glade-widget-class>
<glade-widget-class name="GtkStatusbar" generic-name="statusbar" title="Status Bar">
<properties>
<property id="size" disabled="TRUE" />
......@@ -384,6 +395,11 @@
<fill-empty-function>empty</fill-empty-function>
</child>
</children>
<packing-defaults>
<parent-class name="GtkVBox">
<child-property id="expand" default="false"/>
</parent-class>
</packing-defaults>
</glade-widget-class>
<glade-widget-class name="GtkArrow" generic-name="arrow" title="Arrow"/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment