[gtk+] Provide a way to force showing icons in buttons
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Provide a way to force showing icons in buttons
- Date: Mon, 21 May 2012 17:59:22 +0000 (UTC)
commit 346b933a854512653310772e4d6985f56b62b4ac
Author: William Jon McCann <jmccann redhat com>
Date: Sun May 20 11:58:45 2012 -0400
Provide a way to force showing icons in buttons
https://bugzilla.gnome.org/show_bug.cgi?id=676429
gtk/gtk.symbols | 2 +
gtk/gtkbutton.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++-
gtk/gtkbutton.h | 3 ++
gtk/gtkbuttonprivate.h | 1 +
4 files changed, 95 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index b4f47ae..6f2be20 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -355,6 +355,7 @@ gtk_button_box_style_get_type
gtk_button_clicked
gtk_button_enter
gtk_button_get_alignment
+gtk_button_get_always_show_image
gtk_button_get_event_window
gtk_button_get_focus_on_click
gtk_button_get_image
@@ -372,6 +373,7 @@ gtk_button_new_with_mnemonic
gtk_button_pressed
gtk_button_released
gtk_button_set_alignment
+gtk_button_set_always_show_image
gtk_button_set_focus_on_click
gtk_button_set_image
gtk_button_set_image_position
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 7957f48..545434c 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -91,6 +91,7 @@ enum {
PROP_IMAGE_POSITION,
PROP_ACTION_NAME,
PROP_ACTION_TARGET,
+ PROP_ALWAYS_SHOW_IMAGE,
/* activatable properties */
PROP_ACTIVATABLE_RELATED_ACTION,
@@ -339,6 +340,25 @@ gtk_button_class_init (GtkButtonClass *klass)
GTK_POS_LEFT,
GTK_PARAM_READWRITE));
+ /**
+ * GtkButton:always-show-image:
+ *
+ * If %TRUE, the button will ignore the #GtkSettings:gtk-button-images
+ * setting and always show the image, if available.
+ *
+ * Use this property if the button would be useless or hard to use
+ * without the image.
+ *
+ * Since: 3.6
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_ALWAYS_SHOW_IMAGE,
+ g_param_spec_boolean ("always-show-image",
+ P_("Always show image"),
+ P_("Whether the image will always be shown"),
+ FALSE,
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
g_object_class_override_property (gobject_class, PROP_ACTION_NAME, "action-name");
g_object_class_override_property (gobject_class, PROP_ACTION_TARGET, "action-target");
@@ -786,6 +806,9 @@ gtk_button_set_property (GObject *object,
case PROP_IMAGE:
gtk_button_set_image (button, (GtkWidget *) g_value_get_object (value));
break;
+ case PROP_ALWAYS_SHOW_IMAGE:
+ gtk_button_set_always_show_image (button, g_value_get_boolean (value));
+ break;
case PROP_RELIEF:
gtk_button_set_relief (button, g_value_get_enum (value));
break;
@@ -842,6 +865,9 @@ gtk_button_get_property (GObject *object,
case PROP_IMAGE:
g_value_set_object (value, (GObject *)priv->image);
break;
+ case PROP_ALWAYS_SHOW_IMAGE:
+ g_value_set_boolean (value, gtk_button_get_always_show_image (button));
+ break;
case PROP_RELIEF:
g_value_set_enum (value, priv->relief);
break;
@@ -1032,6 +1058,9 @@ gtk_button_sync_action_properties (GtkActivatable *activatable,
activatable_update_gicon (GTK_BUTTON (activatable), action);
activatable_update_icon_name (GTK_BUTTON (activatable), action);
}
+
+ gtk_button_set_always_show_image (button,
+ gtk_action_get_always_show_image (action));
}
static void
@@ -1093,7 +1122,7 @@ show_image (GtkButton *button)
GtkButtonPrivate *priv = button->priv;
gboolean show;
- if (priv->label_text)
+ if (priv->label_text && !priv->always_show_image)
{
GtkSettings *settings;
@@ -1106,6 +1135,7 @@ show_image (GtkButton *button)
return show;
}
+
static void
gtk_button_construct_child (GtkButton *button)
{
@@ -2726,6 +2756,64 @@ gtk_button_get_image_position (GtkButton *button)
}
/**
+ * gtk_button_set_always_show_image:
+ * @button: a #GtkButton
+ * @always_show: %TRUE if the menuitem should always show the image
+ *
+ * If %TRUE, the button will ignore the #GtkSettings:gtk-button-images
+ * setting and always show the image, if available.
+ *
+ * Use this property if the button would be useless or hard to use
+ * without the image.
+ *
+ * Since: 3.6
+ */
+void
+gtk_button_set_always_show_image (GtkButton *button,
+ gboolean always_show)
+{
+ GtkButtonPrivate *priv;
+
+ g_return_if_fail (GTK_IS_BUTTON (button));
+
+ priv = button->priv;
+
+ if (priv->always_show_image != always_show)
+ {
+ priv->always_show_image = always_show;
+
+ if (priv->image)
+ {
+ if (show_image (button))
+ gtk_widget_show (priv->image);
+ else
+ gtk_widget_hide (priv->image);
+ }
+
+ g_object_notify (G_OBJECT (button), "always-show-image");
+ }
+}
+
+/**
+ * gtk_button_get_always_show_image:
+ * @button: a #GtkButton
+ *
+ * Returns whether the button will ignore the #GtkSettings:gtk-button-images
+ * setting and always show the image, if available.
+ *
+ * Returns: %TRUE if the button will always show the image
+ *
+ * Since: 3.6
+ */
+gboolean
+gtk_button_get_always_show_image (GtkButton *button)
+{
+ g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
+
+ return button->priv->always_show_image;
+}
+
+/**
* gtk_button_get_event_window:
* @button: a #GtkButton
*
diff --git a/gtk/gtkbutton.h b/gtk/gtkbutton.h
index d14179f..96f5000 100644
--- a/gtk/gtkbutton.h
+++ b/gtk/gtkbutton.h
@@ -116,6 +116,9 @@ GtkWidget* gtk_button_get_image (GtkButton *button);
void gtk_button_set_image_position (GtkButton *button,
GtkPositionType position);
GtkPositionType gtk_button_get_image_position (GtkButton *button);
+void gtk_button_set_always_show_image (GtkButton *button,
+ gboolean always_show);
+gboolean gtk_button_get_always_show_image (GtkButton *image_menu_item);
GdkWindow* gtk_button_get_event_window (GtkButton *button);
diff --git a/gtk/gtkbuttonprivate.h b/gtk/gtkbuttonprivate.h
index 22d6b3d..8d7966e 100644
--- a/gtk/gtkbuttonprivate.h
+++ b/gtk/gtkbuttonprivate.h
@@ -59,6 +59,7 @@ struct _GtkButtonPrivate
guint use_action_appearance : 1;
guint use_stock : 1;
guint use_underline : 1;
+ guint always_show_image : 1;
};
void _gtk_button_set_depressed (GtkButton *button,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]