Rearrange things so that setting multiple properties causes not more than

2007-01-27  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtktoolbar.c:
        * gtk/gtktoolitem.c:
        * gtk/gtktoolbutton.c: Rearrange things so that setting
        multiple properties causes not more than a single
        reconstruction of the contents.

        * gtk/gtkaction.c (connect_proxy): Set all tool button
        properties in one go.



svn path=/trunk/; revision=17227
This commit is contained in:
Matthias Clasen 2007-01-28 03:16:30 +00:00 committed by Matthias Clasen
parent 0030448e26
commit d465fbeda7
5 changed files with 92 additions and 83 deletions

View File

@ -1,3 +1,14 @@
2007-01-27 Matthias Clasen <mclasen@redhat.com>
* gtk/gtktoolbar.c:
* gtk/gtktoolitem.c:
* gtk/gtktoolbutton.c: Rearrange things so that setting
multiple properties causes not more than a single
reconstruction of the contents.
* gtk/gtkaction.c (connect_proxy): Set all tool button
properties in one go.
2007-01-27 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkstatusicon.c:

View File

@ -739,26 +739,13 @@ connect_proxy (GtkAction *action,
}
else if (GTK_IS_TOOL_ITEM (proxy))
{
/* toolbar item specific synchronisers ... */
g_object_set (proxy,
"visible-horizontal", action->private_data->visible_horizontal,
"visible-vertical", action->private_data->visible_vertical,
"is-important", action->private_data->is_important,
NULL);
gtk_action_sync_tooltip (action, proxy);
g_signal_connect_object (proxy, "create_menu_proxy",
G_CALLBACK (gtk_action_create_menu_proxy),
action, 0);
gtk_tool_item_rebuild_menu (GTK_TOOL_ITEM (proxy));
/* toolbar button specific synchronisers ... */
if (GTK_IS_TOOL_BUTTON (proxy))
{
g_object_set (proxy,
"visible-horizontal", action->private_data->visible_horizontal,
"visible-vertical", action->private_data->visible_vertical,
"is-important", action->private_data->is_important,
"label", action->private_data->short_label,
"use-underline", TRUE,
"stock-id", action->private_data->stock_id,
@ -768,7 +755,23 @@ connect_proxy (GtkAction *action,
g_signal_connect_object (proxy, "clicked",
G_CALLBACK (gtk_action_activate), action,
G_CONNECT_SWAPPED);
}
}
else
{
g_object_set (proxy,
"visible-horizontal", action->private_data->visible_horizontal,
"visible-vertical", action->private_data->visible_vertical,
"is-important", action->private_data->is_important,
NULL);
}
gtk_action_sync_tooltip (action, proxy);
g_signal_connect_object (proxy, "create_menu_proxy",
G_CALLBACK (gtk_action_create_menu_proxy),
action, 0);
gtk_tool_item_rebuild_menu (GTK_TOOL_ITEM (proxy));
}
else if (GTK_IS_BUTTON (proxy))
{

View File

@ -1445,6 +1445,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
gboolean overflowing;
gboolean size_changed;
GtkAllocation item_area;
GtkShadowType shadow_type;
size_changed = FALSE;
if (widget->allocation.x != allocation->x ||
@ -1476,13 +1477,15 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
&arrow_requisition);
shadow_type = get_shadow_type (toolbar);
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
{
available_size = size = allocation->width - 2 * border_width;
short_size = allocation->height - 2 * border_width;
arrow_size = arrow_requisition.width;
if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
if (shadow_type != GTK_SHADOW_NONE)
{
available_size -= 2 * widget->style->xthickness;
short_size -= 2 * widget->style->ythickness;
@ -1494,7 +1497,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
short_size = allocation->width - 2 * border_width;
arrow_size = arrow_requisition.height;
if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
if (shadow_type != GTK_SHADOW_NONE)
{
available_size -= 2 * widget->style->ythickness;
short_size -= 2 * widget->style->xthickness;
@ -1672,7 +1675,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
allocations[i].x += allocation->x;
allocations[i].y += allocation->y;
if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
if (shadow_type != GTK_SHADOW_NONE)
{
allocations[i].x += widget->style->xthickness;
allocations[i].y += widget->style->ythickness;
@ -1684,7 +1687,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
arrow_allocation.x += allocation->x;
arrow_allocation.y += allocation->y;
if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
if (shadow_type != GTK_SHADOW_NONE)
{
arrow_allocation.x += widget->style->xthickness;
arrow_allocation.y += widget->style->ythickness;
@ -1693,7 +1696,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
item_area.x += allocation->x;
item_area.y += allocation->y;
if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
if (shadow_type != GTK_SHADOW_NONE)
{
item_area.x += widget->style->xthickness;
item_area.y += widget->style->ythickness;
@ -1803,10 +1806,16 @@ static void
gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
{
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
GtkReliefStyle relief;
relief = get_button_relief (toolbar);
if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
{
gtk_toolbar_reconfigured (toolbar);
gtk_toolbar_reconfigured (toolbar);
gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar));
gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
}
}
static void
@ -1816,7 +1825,7 @@ gtk_toolbar_style_set (GtkWidget *widget,
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
priv->max_homogeneous_pixels = -1;
if (GTK_WIDGET_REALIZED (widget))
gtk_style_set_background (widget->style, widget->window, widget->state);
@ -2064,13 +2073,13 @@ gtk_toolbar_screen_changed (GtkWidget *widget,
toolbar);
priv->settings = g_object_ref (settings);
style_change_notify (toolbar);
icon_size_change_notify (toolbar);
animation_change_notify (toolbar);
}
else
priv->settings = NULL;
style_change_notify (toolbar);
icon_size_change_notify (toolbar);
animation_change_notify (toolbar);
}
static int
@ -3994,13 +4003,11 @@ toolbar_content_expose (ToolbarContent *content,
if (child->type == GTK_TOOLBAR_CHILD_SPACE)
{
if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE &&
content->u.compatibility.space_visible)
{
_gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
&expose->area,
&content->u.compatibility.space_allocation);
}
if (content->u.compatibility.space_visible &&
get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
_gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
&expose->area,
&content->u.compatibility.space_allocation);
return;
}
@ -4028,15 +4035,11 @@ toolbar_content_visible (ToolbarContent *content,
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_tool_item_get_visible_horizontal (item))
{
return TRUE;
}
return TRUE;
if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
gtk_tool_item_get_visible_vertical (item)))
{
return TRUE;
}
return TRUE;
return FALSE;
break;

View File

@ -94,6 +94,7 @@ struct _GtkToolButtonPrivate
GtkWidget *icon_widget;
guint use_underline : 1;
guint contents_invalid : 1;
};
GType
@ -269,6 +270,8 @@ gtk_tool_button_init (GtkToolButton *button,
button->priv = GTK_TOOL_BUTTON_GET_PRIVATE (button);
button->priv->contents_invalid = TRUE;
gtk_tool_item_set_homogeneous (toolitem, TRUE);
/* create button */
@ -294,6 +297,8 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item)
GtkWidget *box = NULL;
guint icon_spacing;
button->priv->contents_invalid = FALSE;
gtk_widget_style_get (GTK_WIDGET (tool_item),
"icon-spacing", &icon_spacing,
NULL);
@ -494,7 +499,9 @@ static void
gtk_tool_button_property_notify (GObject *object,
GParamSpec *pspec)
{
if (strcmp (pspec->name, "is-important") == 0)
GtkToolButton *button = GTK_TOOL_BUTTON (object);
if (button->priv->contents_invalid)
gtk_tool_button_construct_contents (GTK_TOOL_ITEM (object));
if (parent_class->notify)
@ -735,13 +742,9 @@ gtk_tool_button_new (GtkWidget *icon_widget,
GtkToolButton *button;
button = g_object_new (GTK_TYPE_TOOL_BUTTON,
"label", label,
"icon-widget", icon_widget,
NULL);
if (label)
gtk_tool_button_set_label (button, label);
if (icon_widget)
gtk_tool_button_set_icon_widget (button, icon_widget);
return GTK_TOOL_ITEM (button);
}
@ -770,12 +773,11 @@ gtk_tool_button_set_label (GtkToolButton *button,
old_label = button->priv->label_text;
button->priv->label_text = g_strdup (label);
gtk_tool_button_construct_contents (GTK_TOOL_ITEM (button));
g_object_notify (G_OBJECT (button), "label");
button->priv->contents_invalid = TRUE;
if (old_label)
g_free (old_label);
g_free (old_label);
g_object_notify (G_OBJECT (button), "label");
}
/**
@ -825,8 +827,7 @@ gtk_tool_button_set_use_underline (GtkToolButton *button,
if (use_underline != button->priv->use_underline)
{
button->priv->use_underline = use_underline;
gtk_tool_button_construct_contents (GTK_TOOL_ITEM (button));
button->priv->contents_invalid = TRUE;
g_object_notify (G_OBJECT (button), "use-underline");
}
@ -874,11 +875,11 @@ gtk_tool_button_set_stock_id (GtkToolButton *button,
old_stock_id = button->priv->stock_id;
button->priv->stock_id = g_strdup (stock_id);
gtk_tool_button_construct_contents (GTK_TOOL_ITEM (button));
g_object_notify (G_OBJECT (button), "stock-id");
button->priv->contents_invalid = TRUE;
g_free (old_stock_id);
g_object_notify (G_OBJECT (button), "stock-id");
}
/**
@ -924,11 +925,11 @@ gtk_tool_button_set_icon_name (GtkToolButton *button,
old_icon_name = button->priv->icon_name;
button->priv->icon_name = g_strdup (icon_name);
gtk_tool_button_construct_contents (GTK_TOOL_ITEM (button));
g_object_notify (G_OBJECT (button), "icon-name");
button->priv->contents_invalid = TRUE;
g_free (old_icon_name);
g_object_notify (G_OBJECT (button), "icon-name");
}
/**
@ -974,22 +975,17 @@ gtk_tool_button_set_icon_widget (GtkToolButton *button,
if (button->priv->icon_widget)
{
if (button->priv->icon_widget->parent)
{
gtk_container_remove (GTK_CONTAINER (button->priv->icon_widget->parent),
gtk_container_remove (GTK_CONTAINER (button->priv->icon_widget->parent),
button->priv->icon_widget);
}
g_object_unref (button->priv->icon_widget);
}
if (icon_widget)
{
g_object_ref_sink (icon_widget);
}
g_object_ref_sink (icon_widget);
button->priv->icon_widget = icon_widget;
gtk_tool_button_construct_contents (GTK_TOOL_ITEM (button));
button->priv->contents_invalid = TRUE;
g_object_notify (G_OBJECT (button), "icon-widget");
}
@ -1020,22 +1016,17 @@ gtk_tool_button_set_label_widget (GtkToolButton *button,
if (button->priv->label_widget)
{
if (button->priv->label_widget->parent)
{
gtk_container_remove (GTK_CONTAINER (button->priv->label_widget->parent),
button->priv->label_widget);
}
gtk_container_remove (GTK_CONTAINER (button->priv->label_widget->parent),
button->priv->label_widget);
g_object_unref (button->priv->label_widget);
}
if (label_widget)
{
g_object_ref_sink (label_widget);
}
g_object_ref_sink (label_widget);
button->priv->label_widget = label_widget;
gtk_tool_button_construct_contents (GTK_TOOL_ITEM (button));
button->priv->contents_invalid = TRUE;
g_object_notify (G_OBJECT (button), "label-widget");
}

View File

@ -265,10 +265,11 @@ gtk_tool_item_finalize (GObject *object)
}
static void
gtk_tool_item_parent_set (GtkWidget *toolitem,
GtkWidget *prev_parent)
gtk_tool_item_parent_set (GtkWidget *toolitem,
GtkWidget *prev_parent)
{
_gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
if (GTK_WIDGET (toolitem)->parent != NULL)
_gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
}
static void