]> Pileus Git - ~andy/gtk/commitdiff
Provide a way to force showing icons in buttons
authorWilliam Jon McCann <jmccann@redhat.com>
Sun, 20 May 2012 15:58:45 +0000 (11:58 -0400)
committerWilliam Jon McCann <jmccann@redhat.com>
Mon, 21 May 2012 17:57:18 +0000 (13:57 -0400)
https://bugzilla.gnome.org/show_bug.cgi?id=676429

gtk/gtk.symbols
gtk/gtkbutton.c
gtk/gtkbutton.h
gtk/gtkbuttonprivate.h

index b4f47ae1807d0a2dad381f6aa40faf78f0cc27c0..6f2be2048eca699db11c93969510bc44253cb43d 100644 (file)
@@ -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
index 7957f48a528f2d599c62d3182c8c3f0b2d25229d..545434cb29225bea2b302292f11926ba156d9325 100644 (file)
@@ -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)
 {
@@ -2725,6 +2755,64 @@ gtk_button_get_image_position (GtkButton *button)
   return button->priv->image_position;
 }
 
+/**
+ * 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
index d14179ffb1d664c91a1b86e42a19155dfd5ad857..96f500036b88ddffb38bcc7c47ee9ab101095127 100644 (file)
@@ -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);
 
index 22d6b3df63161ecc46ea9487869b385f461b849b..8d7966ec32a33a257e9c9baed097b7452b968572 100644 (file)
@@ -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,