[gtk+/gtk-3-10] Respect deprecated button images setting
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-10] Respect deprecated button images setting
- Date: Fri, 25 Oct 2013 00:37:56 +0000 (UTC)
commit 8ee2c87acbccadf9d300b9891ce4aa9e02fda7eb
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Oct 24 20:35:55 2013 -0400
Respect deprecated button images setting
I have been convinced that it is a bad idea to change the behaviour
at the same time as deprecating it, so go back to respecting the
Gtk/ButtonImages xsetting in buttons created with
gtk_button_new_from_stock() when it is set.
The setting as well as the function are still deprecated, and the
default value of the setting will remain FALSE.
gdk/x11/gdksettings.c | 1 +
gtk/gtkbutton.c | 77 +++++++++++++++++++++++++++++++++++++++++++------
gtk/gtksettings.c | 2 +-
3 files changed, 70 insertions(+), 10 deletions(-)
---
diff --git a/gdk/x11/gdksettings.c b/gdk/x11/gdksettings.c
index e98b33e..6d2f87d 100644
--- a/gdk/x11/gdksettings.c
+++ b/gdk/x11/gdksettings.c
@@ -36,6 +36,7 @@ static const struct {
{"Gtk/FontName", "gtk-font-name"},
{"Gtk/KeyThemeName", "gtk-key-theme-name"},
{"Gtk/Modules", "gtk-modules"},
+ {"Gtk/ButtonImages", "gtk-button-images"},
{"Gtk/MenuImages", "gtk-menu-images"},
{"Gtk/CursorThemeName", "gtk-cursor-theme-name"},
{"Gtk/CursorThemeSize", "gtk-cursor-theme-size"},
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 20b15a6..6305f0c 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -364,8 +364,8 @@ gtk_button_class_init (GtkButtonClass *klass)
/**
* GtkButton:always-show-image:
*
- * If %TRUE, the button will show the image in addition to the
- * label, if available.
+ * 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.
@@ -1137,10 +1137,15 @@ show_image (GtkButton *button)
GtkButtonPrivate *priv = button->priv;
gboolean show;
- if (priv->label_text == NULL || priv->always_show_image)
- show = TRUE;
+ if (priv->label_text && !priv->always_show_image)
+ {
+ GtkSettings *settings;
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (button));
+ g_object_get (settings, "gtk-button-images", &show, NULL);
+ }
else
- show = FALSE;
+ show = TRUE;
return show;
}
@@ -2617,12 +2622,52 @@ gtk_button_update_state (GtkButton *button)
gtk_widget_set_state_flags (GTK_WIDGET (button), new_state, TRUE);
}
+static void
+show_image_change_notify (GtkButton *button)
+{
+ GtkButtonPrivate *priv = button->priv;
+
+ if (priv->image)
+ {
+ if (show_image (button))
+ gtk_widget_show (priv->image);
+ else
+ gtk_widget_hide (priv->image);
+ }
+}
+
+static void
+traverse_container (GtkWidget *widget,
+ gpointer data)
+{
+ if (GTK_IS_BUTTON (widget))
+ show_image_change_notify (GTK_BUTTON (widget));
+ else if (GTK_IS_CONTAINER (widget))
+ gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
+}
+
+static void
+gtk_button_setting_changed (GtkSettings *settings)
+{
+ GList *list, *l;
+
+ list = gtk_window_list_toplevels ();
+
+ for (l = list; l; l = l->next)
+ gtk_container_forall (GTK_CONTAINER (l->data),
+ traverse_container, NULL);
+
+ g_list_free (list);
+}
+
static void
gtk_button_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen)
{
GtkButton *button;
GtkButtonPrivate *priv;
+ GtkSettings *settings;
+ gulong show_image_connection;
if (!gtk_widget_has_screen (widget))
return;
@@ -2637,6 +2682,20 @@ gtk_button_screen_changed (GtkWidget *widget,
priv->button_down = FALSE;
gtk_button_update_state (button);
}
+
+ settings = gtk_widget_get_settings (widget);
+
+ show_image_connection =
+ g_signal_handler_find (settings, G_SIGNAL_MATCH_FUNC, 0, 0,
+ NULL, gtk_button_setting_changed, NULL);
+
+ if (show_image_connection)
+ return;
+
+ g_signal_connect (settings, "notify::gtk-button-images",
+ G_CALLBACK (gtk_button_setting_changed), NULL);
+
+ show_image_change_notify (button);
}
static void
@@ -2793,8 +2852,8 @@ gtk_button_get_image_position (GtkButton *button)
* @button: a #GtkButton
* @always_show: %TRUE if the menuitem should always show the image
*
- * If %TRUE, the button will always show the image in addition to the
- * label, if available.
+ * 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.
@@ -2831,8 +2890,8 @@ gtk_button_set_always_show_image (GtkButton *button,
* gtk_button_get_always_show_image:
* @button: a #GtkButton
*
- * Returns whether the button will always show the image in addition
- * to the label, if available.
+ * 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
*
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index 0c79c4a..2640b3d 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -1306,7 +1306,7 @@ gtk_settings_class_init (GtkSettingsClass *class)
*
* Since: 2.4
*
- * Deprecated: 3.10: This setting is ignored
+ * Deprecated: 3.10: This setting is deprecated
*/
result = settings_install_property_parser (class,
g_param_spec_boolean ("gtk-button-images",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]