Commit e12d5fb2 authored by Daniel Elstner's avatar Daniel Elstner Committed by Daniel Elstner

New helper function that sets the icon's and label's packing options and

2003-01-30  Daniel Elstner  <daniel.elstner@gmx.net>

	* gtk/gtktoolbar.c (set_child_packing_and_visibility): New helper
	function that sets the icon's and label's packing options and
	visibility based on toolbar->style.

	(gtk_toolbar_internal_insert_element):
	(gtk_real_toolbar_style_changed): Make use of
	set_child_packing_and_visibility() to clean up the code and get
	the packing right for icon-only/text-only toolbars. (#104679)

	(get_first_child): Remove, and use gtk_bin_get_child() instead.
parent e40cc693
2003-01-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktoolbar.c (set_child_packing_and_visibility): New helper
function that sets the icon's and label's packing options and
visibility based on toolbar->style.
(gtk_toolbar_internal_insert_element):
(gtk_real_toolbar_style_changed): Make use of
set_child_packing_and_visibility() to clean up the code and get
the packing right for icon-only/text-only toolbars. (#104679)
(get_first_child): Remove, and use gtk_bin_get_child() instead.
2003-01-30 Matthias Clasen <maclas@gmx.de>
* gtk/gtktextview.c: Replace PAGE_HORIZONTALLY_HACK_VALUE by
......@@ -17,7 +30,7 @@ Thu Jan 30 16:01:29 2003 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcolorsel.c (palette_paint): Explicitely draw an opaque
rectangle using the background color rather than relying on
gdk_window_clear_area(), so that the palette works properly with
pixmap themes.
pixmap themes. (#101732)
* demos/gtk-demo/colorsel.c: Install an "expose_event" handler
to fill the drawing area in the background color.
......
2003-01-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktoolbar.c (set_child_packing_and_visibility): New helper
function that sets the icon's and label's packing options and
visibility based on toolbar->style.
(gtk_toolbar_internal_insert_element):
(gtk_real_toolbar_style_changed): Make use of
set_child_packing_and_visibility() to clean up the code and get
the packing right for icon-only/text-only toolbars. (#104679)
(get_first_child): Remove, and use gtk_bin_get_child() instead.
2003-01-30 Matthias Clasen <maclas@gmx.de>
* gtk/gtktextview.c: Replace PAGE_HORIZONTALLY_HACK_VALUE by
......@@ -17,7 +30,7 @@ Thu Jan 30 16:01:29 2003 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcolorsel.c (palette_paint): Explicitely draw an opaque
rectangle using the background color rather than relying on
gdk_window_clear_area(), so that the palette works properly with
pixmap themes.
pixmap themes. (#101732)
* demos/gtk-demo/colorsel.c: Install an "expose_event" handler
to fill the drawing area in the background color.
......
2003-01-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktoolbar.c (set_child_packing_and_visibility): New helper
function that sets the icon's and label's packing options and
visibility based on toolbar->style.
(gtk_toolbar_internal_insert_element):
(gtk_real_toolbar_style_changed): Make use of
set_child_packing_and_visibility() to clean up the code and get
the packing right for icon-only/text-only toolbars. (#104679)
(get_first_child): Remove, and use gtk_bin_get_child() instead.
2003-01-30 Matthias Clasen <maclas@gmx.de>
* gtk/gtktextview.c: Replace PAGE_HORIZONTALLY_HACK_VALUE by
......@@ -17,7 +30,7 @@ Thu Jan 30 16:01:29 2003 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcolorsel.c (palette_paint): Explicitely draw an opaque
rectangle using the background color rather than relying on
gdk_window_clear_area(), so that the palette works properly with
pixmap themes.
pixmap themes. (#101732)
* demos/gtk-demo/colorsel.c: Install an "expose_event" handler
to fill the drawing area in the background color.
......
2003-01-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktoolbar.c (set_child_packing_and_visibility): New helper
function that sets the icon's and label's packing options and
visibility based on toolbar->style.
(gtk_toolbar_internal_insert_element):
(gtk_real_toolbar_style_changed): Make use of
set_child_packing_and_visibility() to clean up the code and get
the packing right for icon-only/text-only toolbars. (#104679)
(get_first_child): Remove, and use gtk_bin_get_child() instead.
2003-01-30 Matthias Clasen <maclas@gmx.de>
* gtk/gtktextview.c: Replace PAGE_HORIZONTALLY_HACK_VALUE by
......@@ -17,7 +30,7 @@ Thu Jan 30 16:01:29 2003 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcolorsel.c (palette_paint): Explicitely draw an opaque
rectangle using the background color rather than relying on
gdk_window_clear_area(), so that the palette works properly with
pixmap themes.
pixmap themes. (#101732)
* demos/gtk-demo/colorsel.c: Install an "expose_event" handler
to fill the drawing area in the background color.
......
2003-01-30 Daniel Elstner <daniel.elstner@gmx.net>
* gtk/gtktoolbar.c (set_child_packing_and_visibility): New helper
function that sets the icon's and label's packing options and
visibility based on toolbar->style.
(gtk_toolbar_internal_insert_element):
(gtk_real_toolbar_style_changed): Make use of
set_child_packing_and_visibility() to clean up the code and get
the packing right for icon-only/text-only toolbars. (#104679)
(get_first_child): Remove, and use gtk_bin_get_child() instead.
2003-01-30 Matthias Clasen <maclas@gmx.de>
* gtk/gtktextview.c: Replace PAGE_HORIZONTALLY_HACK_VALUE by
......@@ -17,7 +30,7 @@ Thu Jan 30 16:01:29 2003 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcolorsel.c (palette_paint): Explicitely draw an opaque
rectangle using the background color rather than relying on
gdk_window_clear_area(), so that the palette works properly with
pixmap themes.
pixmap themes. (#101732)
* demos/gtk-demo/colorsel.c: Install an "expose_event" handler
to fill the drawing area in the background color.
......
......@@ -1416,6 +1416,44 @@ gtk_toolbar_insert_element (GtkToolbar *toolbar,
position);
}
static void
set_child_packing_and_visibility(GtkToolbar *toolbar,
GtkToolbarChild *child)
{
GtkWidget *box;
gboolean expand;
box = gtk_bin_get_child (GTK_BIN (child->widget));
g_return_if_fail (GTK_IS_BOX (box));
if (child->label)
{
expand = (toolbar->style != GTK_TOOLBAR_BOTH);
gtk_box_set_child_packing (GTK_BOX (box), child->label,
expand, expand, 0, GTK_PACK_END);
if (toolbar->style != GTK_TOOLBAR_ICONS)
gtk_widget_show (child->label);
else
gtk_widget_hide (child->label);
}
if (child->icon)
{
expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
gtk_box_set_child_packing (GTK_BOX (box), child->icon,
expand, expand, 0, GTK_PACK_END);
if (toolbar->style != GTK_TOOLBAR_TEXT)
gtk_widget_show (child->icon);
else
gtk_widget_hide (child->icon);
}
}
static GtkWidget *
gtk_toolbar_internal_insert_element (GtkToolbar *toolbar,
GtkToolbarChildType type,
......@@ -1500,26 +1538,22 @@ gtk_toolbar_internal_insert_element (GtkToolbar *toolbar,
if (text)
{
child->label = gtk_label_new (text);
gtk_box_pack_end (GTK_BOX (box), child->label, FALSE, FALSE, 0);
if (toolbar->style != GTK_TOOLBAR_ICONS)
gtk_widget_show (child->label);
gtk_container_add (GTK_CONTAINER (box), child->label);
}
if (icon)
{
child->icon = GTK_WIDGET (icon);
gtk_box_pack_end (GTK_BOX (box), child->icon, FALSE, FALSE, 0);
if (toolbar->style != GTK_TOOLBAR_TEXT)
gtk_widget_show (child->icon);
gtk_container_add (GTK_CONTAINER (box), child->icon);
}
if (type != GTK_TOOLBAR_CHILD_WIDGET)
{
/* Mark child as ours */
g_object_set_data (G_OBJECT (child->widget),
"gtk-toolbar-is-child",
GINT_TO_POINTER (TRUE));
}
set_child_packing_and_visibility (toolbar, child);
/* Mark child as ours */
g_object_set_data (G_OBJECT (child->widget),
"gtk-toolbar-is-child",
GINT_TO_POINTER (TRUE));
gtk_widget_show (child->widget);
break;
......@@ -1691,23 +1725,13 @@ gtk_real_toolbar_orientation_changed (GtkToolbar *toolbar,
}
}
static GtkWidget *
get_first_child (GtkContainer *container)
{
GList *children = gtk_container_get_children (container);
GtkWidget *result = children ? children->data : NULL;
g_list_free (children);
return result;
}
static void
gtk_real_toolbar_style_changed (GtkToolbar *toolbar,
GtkToolbarStyle style)
{
GList *children;
GtkToolbarChild *child;
GtkWidget* box = NULL;
GtkWidget* box;
g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
......@@ -1722,118 +1746,44 @@ gtk_real_toolbar_style_changed (GtkToolbar *toolbar,
if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
switch (style)
{
case GTK_TOOLBAR_ICONS:
if (child->icon && !GTK_WIDGET_VISIBLE (child->icon))
gtk_widget_show (child->icon);
if (child->label && GTK_WIDGET_VISIBLE (child->label))
gtk_widget_hide (child->label);
break;
case GTK_TOOLBAR_TEXT:
if (child->icon && GTK_WIDGET_VISIBLE (child->icon))
gtk_widget_hide (child->icon);
if (child->label && !GTK_WIDGET_VISIBLE (child->label))
gtk_widget_show (child->label);
break;
case GTK_TOOLBAR_BOTH:
if (child->icon && !GTK_WIDGET_VISIBLE (child->icon))
gtk_widget_show (child->icon);
if (child->label && !GTK_WIDGET_VISIBLE (child->label))
gtk_widget_show (child->label);
box = get_first_child (GTK_CONTAINER (child->widget));
if (GTK_IS_HBOX (box))
{
if (child->icon)
{
g_object_ref (child->icon);
gtk_container_remove (GTK_CONTAINER (box),
child->icon);
}
if (child->label)
{
g_object_ref (child->label);
gtk_container_remove (GTK_CONTAINER (box),
child->label);
}
gtk_container_remove (GTK_CONTAINER (child->widget),
box);
box = gtk_vbox_new (FALSE, 0);
gtk_widget_show (box);
if (child->label)
{
gtk_box_pack_end (GTK_BOX (box), child->label, FALSE, FALSE, 0);
g_object_unref (child->label);
}
if (child->icon)
{
gtk_box_pack_end (GTK_BOX (box), child->icon, FALSE, FALSE, 0);
g_object_unref (child->icon);
}
gtk_container_add (GTK_CONTAINER (child->widget),
box);
}
break;
case GTK_TOOLBAR_BOTH_HORIZ:
if (child->icon && !GTK_WIDGET_VISIBLE (child->icon))
gtk_widget_show (child->icon);
if (child->label && !GTK_WIDGET_VISIBLE (child->label))
gtk_widget_show (child->label);
box = get_first_child (GTK_CONTAINER (child->widget));
if (GTK_IS_VBOX (box))
{
if (child->icon)
{
g_object_ref (child->icon);
gtk_container_remove (GTK_CONTAINER (box),
child->icon);
}
if (child->label)
{
g_object_ref (child->label);
gtk_container_remove (GTK_CONTAINER (box),
child->label);
}
gtk_container_remove (GTK_CONTAINER (child->widget),
box);
box = gtk_hbox_new (FALSE, 0);
gtk_widget_show (box);
if (child->label)
{
gtk_box_pack_end (GTK_BOX (box), child->label, TRUE, TRUE, 0);
g_object_unref (child->label);
}
if (child->icon)
{
gtk_box_pack_end (GTK_BOX (box), child->icon, FALSE, FALSE, 0);
g_object_unref (child->icon);
}
gtk_container_add (GTK_CONTAINER (child->widget), box);
}
break;
default:
g_assert_not_reached ();
}
{
box = gtk_bin_get_child (GTK_BIN (child->widget));
if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
{
GtkWidget *vbox;
vbox = gtk_vbox_new (FALSE, 0);
if (child->label)
gtk_widget_reparent (child->label, vbox);
if (child->icon)
gtk_widget_reparent (child->icon, vbox);
gtk_widget_destroy (box);
gtk_container_add (GTK_CONTAINER (child->widget), vbox);
gtk_widget_show (vbox);
}
else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
{
GtkWidget *hbox;
hbox = gtk_hbox_new (FALSE, 0);
if (child->label)
gtk_widget_reparent (child->label, hbox);
if (child->icon)
gtk_widget_reparent (child->icon, hbox);
gtk_widget_destroy (box);
gtk_container_add (GTK_CONTAINER (child->widget), hbox);
gtk_widget_show (hbox);
}
set_child_packing_and_visibility (toolbar, child);
}
}
gtk_widget_queue_resize (GTK_WIDGET (toolbar));
......
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