Commit fe7a5ebb authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Make actions work with named icons. (#323484, Jorn Baayen)

2006-03-13  Matthias Clasen  <mclasen@redhat.com>

	Make actions work with named icons.  (#323484, Jorn Baayen)

	* gtk/gtkactiongroup.c: If the stock-id field of a GtkActionEntry
	does not contain a registered stock id, interpret it as an
	icon name.

	* gtk/gtkaction.c: Add an icon-name property to actions and
	use it for icons if a stock-id is not specified.
parent a83b6158
2006-03-13 Matthias Clasen <mclasen@redhat.com>
Make actions work with named icons. (#323484, Jorn Baayen)
* gtk/gtkactiongroup.c: If the stock-id field of a GtkActionEntry
does not contain a registered stock id, interpret it as an
icon name.
* gtk/gtkaction.c: Add an icon-name property to actions and
use it for icons if a stock-id is not specified.
2006-03-12 Matthias Clasen <mclasen@redhat.com> 2006-03-12 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkwindow.c (gtk_window_compute_configure_request): Don't * gtk/gtkwindow.c (gtk_window_compute_configure_request): Don't
......
2006-03-13 Matthias Clasen <mclasen@redhat.com>
Make actions work with named icons. (#323484, Jorn Baayen)
* gtk/gtkactiongroup.c: If the stock-id field of a GtkActionEntry
does not contain a registered stock id, interpret it as an
icon name.
* gtk/gtkaction.c: Add an icon-name property to actions and
use it for icons if a stock-id is not specified.
2006-03-12 Matthias Clasen <mclasen@redhat.com> 2006-03-12 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkwindow.c (gtk_window_compute_configure_request): Don't * gtk/gtkwindow.c (gtk_window_compute_configure_request): Don't
......
...@@ -200,7 +200,8 @@ gtk_action_group_add_actions() to construct actions. ...@@ -200,7 +200,8 @@ gtk_action_group_add_actions() to construct actions.
</para> </para>
@name: The name of the action. @name: The name of the action.
@stock_id: The stock id for the action. @stock_id: The stock id for the action, or the name of an icon from the icon
theme.
@label: The label for the action. This field should typically be marked for @label: The label for the action. This field should typically be marked for
translation, see gtk_action_group_set_translation_domain(). translation, see gtk_action_group_set_translation_domain().
@accelerator: The accelerator for the action, in the format understood by @accelerator: The accelerator for the action, in the format understood by
...@@ -239,7 +240,8 @@ gtk_action_group_add_toggle_actions() to construct toggle actions. ...@@ -239,7 +240,8 @@ gtk_action_group_add_toggle_actions() to construct toggle actions.
</para> </para>
@name: The name of the action. @name: The name of the action.
@stock_id: The stock id for the action. @stock_id: The stock id for the action, or the name of an icon from the icon
theme.
@label: The label for the action. This field should typically be marked for @label: The label for the action. This field should typically be marked for
translation, see gtk_action_group_set_translation_domain(). translation, see gtk_action_group_set_translation_domain().
@accelerator: The accelerator for the action, in the format understood by @accelerator: The accelerator for the action, in the format understood by
...@@ -279,7 +281,8 @@ gtk_action_group_add_radio_actions() to construct groups of radio actions. ...@@ -279,7 +281,8 @@ gtk_action_group_add_radio_actions() to construct groups of radio actions.
</para> </para>
@name: The name of the action. @name: The name of the action.
@stock_id: The stock id for the action. @stock_id: The stock id for the action, or the name of an icon from the icon
theme.
@label: The label for the action. This field should typically be marked for @label: The label for the action. This field should typically be marked for
translation, see gtk_action_group_set_translation_domain(). translation, see gtk_action_group_set_translation_domain().
@accelerator: The accelerator for the action, in the format understood by @accelerator: The accelerator for the action, in the format understood by
......
...@@ -56,7 +56,8 @@ struct _GtkActionPrivate ...@@ -56,7 +56,8 @@ struct _GtkActionPrivate
gchar *label; gchar *label;
gchar *short_label; gchar *short_label;
gchar *tooltip; gchar *tooltip;
gchar *stock_id; /* icon */ gchar *stock_id; /* stock icon */
gchar *icon_name; /* themed icon */
guint sensitive : 1; guint sensitive : 1;
guint visible : 1; guint visible : 1;
...@@ -94,6 +95,7 @@ enum ...@@ -94,6 +95,7 @@ enum
PROP_SHORT_LABEL, PROP_SHORT_LABEL,
PROP_TOOLTIP, PROP_TOOLTIP,
PROP_STOCK_ID, PROP_STOCK_ID,
PROP_ICON_NAME,
PROP_VISIBLE_HORIZONTAL, PROP_VISIBLE_HORIZONTAL,
PROP_VISIBLE_VERTICAL, PROP_VISIBLE_VERTICAL,
PROP_VISIBLE_OVERFLOWN, PROP_VISIBLE_OVERFLOWN,
...@@ -165,6 +167,8 @@ static void gtk_action_set_tooltip (GtkAction *action, ...@@ -165,6 +167,8 @@ static void gtk_action_set_tooltip (GtkAction *action,
const gchar *tooltip); const gchar *tooltip);
static void gtk_action_set_stock_id (GtkAction *action, static void gtk_action_set_stock_id (GtkAction *action,
const gchar *stock_id); const gchar *stock_id);
static void gtk_action_set_icon_name (GtkAction *action,
const gchar *icon_name);
static void gtk_action_sync_tooltip (GtkAction *action, static void gtk_action_sync_tooltip (GtkAction *action,
GtkWidget *proxy); GtkWidget *proxy);
...@@ -248,6 +252,23 @@ gtk_action_class_init (GtkActionClass *klass) ...@@ -248,6 +252,23 @@ gtk_action_class_init (GtkActionClass *klass)
"this action."), "this action."),
NULL, NULL,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
/**
* GtkAction::icon-name:
*
* The name of the icon from the icon theme.
* Note that the stock icon is preferred, if
* the ::stock-id property holds the id of an
* existing stock icon.
*
* Since: 2.10
*/
g_object_class_install_property (gobject_class,
PROP_ICON_NAME,
g_param_spec_string ("icon-name",
P_("Icon Name"),
P_("The name of the icon from the icon theme"),
NULL,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_VISIBLE_HORIZONTAL, PROP_VISIBLE_HORIZONTAL,
g_param_spec_boolean ("visible-horizontal", g_param_spec_boolean ("visible-horizontal",
...@@ -348,6 +369,7 @@ gtk_action_init (GtkAction *action) ...@@ -348,6 +369,7 @@ gtk_action_init (GtkAction *action)
action->private_data->short_label = NULL; action->private_data->short_label = NULL;
action->private_data->tooltip = NULL; action->private_data->tooltip = NULL;
action->private_data->stock_id = NULL; action->private_data->stock_id = NULL;
action->private_data->icon_name = NULL;
action->private_data->visible_horizontal = TRUE; action->private_data->visible_horizontal = TRUE;
action->private_data->visible_vertical = TRUE; action->private_data->visible_vertical = TRUE;
action->private_data->visible_overflown = TRUE; action->private_data->visible_overflown = TRUE;
...@@ -421,6 +443,7 @@ gtk_action_finalize (GObject *object) ...@@ -421,6 +443,7 @@ gtk_action_finalize (GObject *object)
g_free (action->private_data->short_label); g_free (action->private_data->short_label);
g_free (action->private_data->tooltip); g_free (action->private_data->tooltip);
g_free (action->private_data->stock_id); g_free (action->private_data->stock_id);
g_free (action->private_data->icon_name);
g_closure_unref (action->private_data->accel_closure); g_closure_unref (action->private_data->accel_closure);
if (action->private_data->accel_group) if (action->private_data->accel_group)
...@@ -459,6 +482,9 @@ gtk_action_set_property (GObject *object, ...@@ -459,6 +482,9 @@ gtk_action_set_property (GObject *object,
case PROP_STOCK_ID: case PROP_STOCK_ID:
gtk_action_set_stock_id (action, g_value_get_string (value)); gtk_action_set_stock_id (action, g_value_get_string (value));
break; break;
case PROP_ICON_NAME:
gtk_action_set_icon_name (action, g_value_get_string (value));
break;
case PROP_VISIBLE_HORIZONTAL: case PROP_VISIBLE_HORIZONTAL:
gtk_action_set_visible_horizontal (action, g_value_get_boolean (value)); gtk_action_set_visible_horizontal (action, g_value_get_boolean (value));
break; break;
...@@ -516,6 +542,9 @@ gtk_action_get_property (GObject *object, ...@@ -516,6 +542,9 @@ gtk_action_get_property (GObject *object,
case PROP_STOCK_ID: case PROP_STOCK_ID:
g_value_set_string (value, action->private_data->stock_id); g_value_set_string (value, action->private_data->stock_id);
break; break;
case PROP_ICON_NAME:
g_value_set_string (value, action->private_data->icon_name);
break;
case PROP_VISIBLE_HORIZONTAL: case PROP_VISIBLE_HORIZONTAL:
g_value_set_boolean (value, action->private_data->visible_horizontal); g_value_set_boolean (value, action->private_data->visible_horizontal);
break; break;
...@@ -708,16 +737,19 @@ connect_proxy (GtkAction *action, ...@@ -708,16 +737,19 @@ connect_proxy (GtkAction *action,
} }
if (!image) if (!image)
{ {
image = gtk_image_new_from_stock (NULL, image = gtk_image_new ();
GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy),
image); image);
gtk_widget_show (image); gtk_widget_show (image);
} }
gtk_image_set_from_stock (GTK_IMAGE (image), if (action->private_data->stock_id)
action->private_data->stock_id, GTK_ICON_SIZE_MENU); gtk_image_set_from_stock (GTK_IMAGE (image),
action->private_data->stock_id, GTK_ICON_SIZE_MENU);
else if (action->private_data->icon_name)
gtk_image_set_from_icon_name (GTK_IMAGE (image),
action->private_data->icon_name, GTK_ICON_SIZE_MENU);
} }
if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)) == NULL) if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)) == NULL)
g_signal_connect_object (proxy, "activate", g_signal_connect_object (proxy, "activate",
G_CALLBACK (gtk_action_activate), action, G_CALLBACK (gtk_action_activate), action,
...@@ -747,8 +779,9 @@ connect_proxy (GtkAction *action, ...@@ -747,8 +779,9 @@ connect_proxy (GtkAction *action,
{ {
g_object_set (proxy, g_object_set (proxy,
"label", action->private_data->short_label, "label", action->private_data->short_label,
"use_underline", TRUE, "use-underline", TRUE,
"stock_id", action->private_data->stock_id, "stock-id", action->private_data->stock_id,
"icon-name", action->private_data->icon_name,
NULL); NULL);
g_signal_connect_object (proxy, "clicked", g_signal_connect_object (proxy, "clicked",
...@@ -766,16 +799,22 @@ connect_proxy (GtkAction *action, ...@@ -766,16 +799,22 @@ connect_proxy (GtkAction *action,
"label", action->private_data->stock_id, "label", action->private_data->stock_id,
NULL); NULL);
} }
else if (GTK_BIN (proxy)->child == NULL || else
GTK_IS_LABEL (GTK_BIN (proxy)->child))
{ {
/* synchronise the label */ GtkWidget *image;
g_object_set (proxy,
"label", action->private_data->short_label, image = gtk_button_get_image (GTK_BUTTON (proxy));
"use_underline", TRUE,
NULL); if (GTK_BIN (proxy)->child == NULL ||
GTK_IS_LABEL (GTK_BIN (proxy)->child))
{
/* synchronise the label */
g_object_set (proxy,
"label", action->private_data->short_label,
"use_underline", TRUE,
NULL);
}
} }
/* we leave the button alone if there is a custom child */ /* we leave the button alone if there is a custom child */
g_signal_connect_object (proxy, "clicked", g_signal_connect_object (proxy, "clicked",
G_CALLBACK (gtk_action_activate), action, G_CALLBACK (gtk_action_activate), action,
...@@ -869,6 +908,8 @@ gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size) ...@@ -869,6 +908,8 @@ gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
if (action->private_data->stock_id) if (action->private_data->stock_id)
return gtk_image_new_from_stock (action->private_data->stock_id, icon_size); return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
else if (action->private_data->icon_name)
return gtk_image_new_from_icon_name (action->private_data->icon_name, icon_size);
else else
return NULL; return NULL;
} }
...@@ -1469,7 +1510,8 @@ gtk_action_set_stock_id (GtkAction *action, ...@@ -1469,7 +1510,8 @@ gtk_action_set_stock_id (GtkAction *action,
{ {
GtkStockItem stock_item; GtkStockItem stock_item;
if (gtk_stock_lookup (action->private_data->stock_id, &stock_item)) if (action->private_data->stock_id &&
gtk_stock_lookup (action->private_data->stock_id, &stock_item))
gtk_action_set_label (action, stock_item.label); gtk_action_set_label (action, stock_item.label);
else else
gtk_action_set_label (action, NULL); gtk_action_set_label (action, NULL);
...@@ -1478,6 +1520,55 @@ gtk_action_set_stock_id (GtkAction *action, ...@@ -1478,6 +1520,55 @@ gtk_action_set_stock_id (GtkAction *action,
} }
} }
static void
gtk_action_set_icon_name (GtkAction *action,
const gchar *icon_name)
{
GSList *p;
GtkWidget *proxy, *image;
gchar *tmp;
tmp = action->private_data->icon_name;
action->private_data->icon_name = g_strdup (icon_name);
g_free (tmp);
for (p = action->private_data->proxies; p; p = p->next)
{
proxy = (GtkWidget *)p->data;
if (GTK_IS_IMAGE_MENU_ITEM (proxy))
{
image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
if (GTK_IS_IMAGE (image) &&
(gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_EMPTY ||
gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_ICON_NAME))
gtk_image_set_from_icon_name (GTK_IMAGE (image),
action->private_data->icon_name, GTK_ICON_SIZE_MENU);
}
else if (GTK_IS_TOOL_BUTTON (proxy))
{
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (proxy),
action->private_data->icon_name);
}
else if (GTK_IS_BUTTON (proxy) &&
!gtk_button_get_use_stock (GTK_BUTTON (proxy)))
{
GtkWidget *image;
image = gtk_button_get_image (GTK_BUTTON (proxy));
if (GTK_IS_IMAGE (image) &&
(gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_EMPTY ||
gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_ICON_NAME))
gtk_image_set_from_icon_name (GTK_IMAGE (image),
action->private_data->icon_name, GTK_ICON_SIZE_MENU);
}
}
g_object_notify (G_OBJECT (action), "icon-name");
}
/** /**
* gtk_action_block_activate_from: * gtk_action_block_activate_from:
......
...@@ -777,8 +777,18 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group, ...@@ -777,8 +777,18 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group,
action = gtk_action_new (entries[i].name, action = gtk_action_new (entries[i].name,
label, label,
tooltip, tooltip,
entries[i].stock_id); NULL);
if (entries[i].stock_id)
{
GtkStockItem item;
if (gtk_stock_lookup (entries[i].stock_id, &item))
g_object_set (action, "stock-id", entries[i].stock_id, NULL);
else
g_object_set (action, "icon-name", entries[i].stock_id, NULL);
}
if (entries[i].callback) if (entries[i].callback)
{ {
GClosure *closure; GClosure *closure;
...@@ -873,7 +883,17 @@ gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_gro ...@@ -873,7 +883,17 @@ gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_gro
action = gtk_toggle_action_new (entries[i].name, action = gtk_toggle_action_new (entries[i].name,
label, label,
tooltip, tooltip,
entries[i].stock_id); NULL);
if (entries[i].stock_id)
{
GtkStockItem item;
if (gtk_stock_lookup (entries[i].stock_id, &item))
g_object_set (action, "stock-id", entries[i].stock_id, NULL);
else
g_object_set (action, "icon-name", entries[i].stock_id, NULL);
}
gtk_toggle_action_set_active (action, entries[i].is_active); gtk_toggle_action_set_active (action, entries[i].is_active);
...@@ -977,9 +997,19 @@ gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group ...@@ -977,9 +997,19 @@ gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group
action = gtk_radio_action_new (entries[i].name, action = gtk_radio_action_new (entries[i].name,
label, label,
tooltip, tooltip,
entries[i].stock_id, NULL,
entries[i].value); entries[i].value);
if (entries[i].stock_id)
{
GtkStockItem item;
if (gtk_stock_lookup (entries[i].stock_id, &item))
g_object_set (action, "stock-id", entries[i].stock_id, NULL);
else
g_object_set (action, "icon-name", entries[i].stock_id, NULL);
}
if (i == 0) if (i == 0)
first_action = action; first_action = action;
......
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