[gtk+/gtk-style-context] Make "button" class depend on mode for GtkToggleButtons



commit d6992a993012e9c387580e4f5ec49112724bc020
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Nov 19 19:56:25 2010 +0100

    Make "button" class depend on mode for GtkToggleButtons

 gtk/gtkcheckbutton.c  |    9 ---------
 gtk/gtktogglebutton.c |   12 ++++++++++++
 2 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index a4028fc..9e637f0 100644
--- a/gtk/gtkcheckbutton.c
+++ b/gtk/gtkcheckbutton.c
@@ -92,18 +92,9 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
 static void
 gtk_check_button_init (GtkCheckButton *check_button)
 {
-  GtkStyleContext *context;
-
   gtk_widget_set_has_window (GTK_WIDGET (check_button), FALSE);
   gtk_widget_set_receives_default (GTK_WIDGET (check_button), FALSE);
   gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (check_button), TRUE);
-
-  /* Remove the "button" class added in GtkButton constructor,
-   * since this widget implementation doesn't look like a button
-   * at all.
-   */
-  context = gtk_widget_get_style_context (GTK_WIDGET (check_button));
-  gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
 }
 
 GtkWidget*
diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c
index cdd8f20..d34c413 100644
--- a/gtk/gtktogglebutton.c
+++ b/gtk/gtktogglebutton.c
@@ -326,6 +326,8 @@ gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
 
   if (priv->draw_indicator != draw_indicator)
     {
+      GtkStyleContext *context;
+
       priv->draw_indicator = draw_indicator;
       GTK_BUTTON (toggle_button)->depress_on_activate = !draw_indicator;
       
@@ -333,6 +335,16 @@ gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
 	gtk_widget_queue_resize (GTK_WIDGET (toggle_button));
 
       g_object_notify (G_OBJECT (toggle_button), "draw-indicator");
+
+      /* Make toggle buttons conditionally have the "button"
+       * class depending on draw_indicator.
+       */
+      context = gtk_widget_get_style_context (GTK_WIDGET (toggle_button));
+
+      if (draw_indicator)
+        gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
+      else
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]