From 67f557226f8f96c7e7364ca3ace9f159cd19cefd Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 18 May 2005 05:38:50 +0000 Subject: [PATCH] Support named icons in tool buttons by adding a icon-name property. 2005-05-18 Matthias Clasen * gtk/gtk.symbols: * gtk/gtktoolbutton.h: * gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name) (gtk_tool_button_get_icon_name): Support named icons in tool buttons by adding a icon-name property. --- ChangeLog | 6 ++ ChangeLog.pre-2-10 | 6 ++ ChangeLog.pre-2-8 | 6 ++ docs/reference/gtk/gtk-sections.txt | 2 + gtk/gtk.symbols | 2 + gtk/gtktoolbutton.c | 98 ++++++++++++++++++++++++++--- gtk/gtktoolbutton.h | 3 + 7 files changed, 115 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49eab1da4d..86b8e9e9c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2005-05-18 Matthias Clasen + * gtk/gtk.symbols: + * gtk/gtktoolbutton.h: + * gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name) + (gtk_tool_button_get_icon_name): Support named icons in + tool buttons by adding a icon-name property. + * gtk/gtk.symbols: * gtk/gtkdnd.h: * gtk/gtkdnd.c (gtk_drag_source_set_icon_name) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 49eab1da4d..86b8e9e9c9 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,11 @@ 2005-05-18 Matthias Clasen + * gtk/gtk.symbols: + * gtk/gtktoolbutton.h: + * gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name) + (gtk_tool_button_get_icon_name): Support named icons in + tool buttons by adding a icon-name property. + * gtk/gtk.symbols: * gtk/gtkdnd.h: * gtk/gtkdnd.c (gtk_drag_source_set_icon_name) diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 49eab1da4d..86b8e9e9c9 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,11 @@ 2005-05-18 Matthias Clasen + * gtk/gtk.symbols: + * gtk/gtktoolbutton.h: + * gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name) + (gtk_tool_button_get_icon_name): Support named icons in + tool buttons by adding a icon-name property. + * gtk/gtk.symbols: * gtk/gtkdnd.h: * gtk/gtkdnd.c (gtk_drag_source_set_icon_name) diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 2f5cb7a7e9..a12471cd81 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -3530,6 +3530,8 @@ gtk_tool_button_set_use_underline gtk_tool_button_get_use_underline gtk_tool_button_set_stock_id gtk_tool_button_get_stock_id +gtk_tool_button_set_icon_name +gtk_tool_button_get_icon_name gtk_tool_button_set_icon_widget gtk_tool_button_get_icon_widget gtk_tool_button_set_label_widget diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 3bb417abfd..8ada4d4361 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -3219,6 +3219,7 @@ gtk_toolbar_unset_style #if IN_HEADER(__GTK_TOOL_BUTTON_H__) #if IN_FILE(__GTK_TOOL_BUTTON_C__) +gtk_tool_button_get_icon_name gtk_tool_button_get_icon_widget gtk_tool_button_get_label gtk_tool_button_get_label_widget @@ -3227,6 +3228,7 @@ gtk_tool_button_get_type G_GNUC_CONST gtk_tool_button_get_use_underline gtk_tool_button_new gtk_tool_button_new_from_stock +gtk_tool_button_set_icon_name gtk_tool_button_set_icon_widget gtk_tool_button_set_label gtk_tool_button_set_label_widget diff --git a/gtk/gtktoolbutton.c b/gtk/gtktoolbutton.c index 2281b643da..06cd32e81d 100644 --- a/gtk/gtktoolbutton.c +++ b/gtk/gtktoolbutton.c @@ -51,6 +51,7 @@ enum { PROP_USE_UNDERLINE, PROP_LABEL_WIDGET, PROP_STOCK_ID, + PROP_ICON_NAME, PROP_ICON_WIDGET }; @@ -86,6 +87,7 @@ struct _GtkToolButtonPrivate GtkWidget *button; gchar *stock_id; + gchar *icon_name; gchar *label_text; GtkWidget *label_widget; GtkWidget *icon_widget; @@ -148,14 +150,17 @@ gtk_tool_button_class_init (GtkToolButtonClass *klass) * - if the tool button has an icon_widget, then that widget * will be used as the icon. Otherwise, if the tool button * has a stock id, the corresponding stock icon will be - * used. Otherwise, the tool button will not have an icon. + * used. Otherwise, if the tool button has an icon name, + * the corresponding icon from the theme will be used. + * Otherwise, the tool button will not have an icon. * * - if the tool button has a label_widget then that widget * will be used as the label. Otherwise, if the tool button * has a label text, that text will be used as label. Otherwise, * if the toolbutton has a stock id, the corresponding text - * will be used as label. Otherwise, the toolbutton will - * have an empty label. + * will be used as label. Otherwise, if the tool button has + * an icon name, the corresponding icon name from the theme will + * be used. Otherwise, the toolbutton will have an empty label. * * - The use_underline property only has an effect when the label * on the toolbutton comes from the label property (ie. not from @@ -204,6 +209,23 @@ gtk_tool_button_class_init (GtkToolButtonClass *klass) P_("The stock icon displayed on the item"), NULL, GTK_PARAM_READWRITE)); + + /** + * GtkToolButton:icon-name: + * + * The name of the themed icon displayed on the item. + * This property only has an effect if not overridden by "label", + * "icon_widget" or "stock_id" properties. + * + * Since: 2.8 + */ + g_object_class_install_property (object_class, + PROP_ICON_NAME, + g_param_spec_string ("icon-name", + P_("Icon name"), + P_("The name of the themed icon displayed on the item"), + NULL, + GTK_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_ICON_WIDGET, g_param_spec_object ("icon-widget", @@ -358,6 +380,11 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item) icon = gtk_image_new_from_stock (button->priv->stock_id, icon_size); gtk_widget_show (icon); } + else if (button->priv->icon_name) + { + icon = gtk_image_new_from_icon_name (button->priv->icon_name, icon_size); + gtk_widget_show (icon); + } } switch (style) @@ -422,6 +449,9 @@ gtk_tool_button_set_property (GObject *object, case PROP_STOCK_ID: gtk_tool_button_set_stock_id (button, g_value_get_string (value)); break; + case PROP_ICON_NAME: + gtk_tool_button_set_icon_name (button, g_value_get_string (value)); + break; case PROP_ICON_WIDGET: gtk_tool_button_set_icon_widget (button, g_value_get_object (value)); break; @@ -463,6 +493,9 @@ gtk_tool_button_get_property (GObject *object, case PROP_STOCK_ID: g_value_set_string (value, button->priv->stock_id); break; + case PROP_ICON_NAME: + g_value_set_string (value, button->priv->icon_name); + break; case PROP_ICON_WIDGET: g_value_set_object (value, button->priv->icon_widget); break; @@ -476,11 +509,9 @@ gtk_tool_button_finalize (GObject *object) { GtkToolButton *button = GTK_TOOL_BUTTON (object); - if (button->priv->stock_id) - g_free (button->priv->stock_id); - - if (button->priv->label_text) - g_free (button->priv->label_text); + g_free (button->priv->stock_id); + g_free (button->priv->icon_name); + g_free (button->priv->label_text); if (button->priv->label_widget) g_object_unref (button->priv->label_widget); @@ -812,6 +843,57 @@ gtk_tool_button_get_stock_id (GtkToolButton *button) return button->priv->stock_id; } +/** + * gtk_tool_button_set_icon_name + * @button: a #GtkToolButton + * @stock_id: the name of the themed icon + * + * Sets the icon for the tool button from a named themed icon. + * See the docs for #GtkIconTheme for more details. + * The "icon_name" property only has an effect if not + * overridden by non-%NULL "label", "icon_widget" and "stock_id" + * properties. + * + * Since: 2.8 + **/ +void +gtk_tool_button_set_icon_name (GtkToolButton *button, + const gchar *icon_name) +{ + gchar *old_icon_name; + + g_return_if_fail (GTK_IS_TOOL_BUTTON (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"); + + g_free (old_icon_name); +} + +/** + * gtk_tool_button_get_icon_name + * @button: a #GtkToolButton + * + * Returns the name of the themed icon for the tool button, + * see gtk_tool_button_set_icon_name(). + * + * Returns: the icon name or %NULL if the tool button has + * no themed icon + * + * Since: 2.8 + **/ +G_CONST_RETURN gchar* +gtk_tool_button_get_icon_name (GtkToolButton *button) +{ + g_return_val_if_fail (GTK_IS_TOOL_BUTTON (button), NULL); + + return button->priv->icon_name; +} + /** * gtk_tool_button_set_icon_widget: * @button: a #GtkToolButton diff --git a/gtk/gtktoolbutton.h b/gtk/gtktoolbutton.h index 8a78a11fb8..b7329a02f8 100644 --- a/gtk/gtktoolbutton.h +++ b/gtk/gtktoolbutton.h @@ -76,6 +76,9 @@ gboolean gtk_tool_button_get_use_underline (GtkToolButton *button); void gtk_tool_button_set_stock_id (GtkToolButton *button, const gchar *stock_id); G_CONST_RETURN gchar *gtk_tool_button_get_stock_id (GtkToolButton *button); +void gtk_tool_button_set_icon_name (GtkToolButton *button, + const gchar *icon_name); +G_CONST_RETURN gchar *gtk_tool_button_get_icon_name (GtkToolButton *button); void gtk_tool_button_set_icon_widget (GtkToolButton *button, GtkWidget *icon_widget); GtkWidget * gtk_tool_button_get_icon_widget (GtkToolButton *button);