[gtk+] cellrenderertoggle: Change "indicator-size" handling



commit ab1906952e11a11737aec41e86ba81c050886845
Author: Benjamin Otte <otte redhat com>
Date:   Tue Feb 16 02:41:44 2016 +0100

    cellrenderertoggle: Change "indicator-size" handling
    
    The following changes were done to (hopefully) achieve backwards
    compatibility while allowing themes to change the size of the indicator.
    
    (1) Deprecate the property.
    (2) Change the default value of the property to 0. If it is not 0,
        use the property's value for the indicator size. This should make
        all programs that actually set it keep the size they set it to.
    (3) If set to other values than 0, use min-width/min-height of the
        check/radio node to size the indicator. This allows themes to change
        the size.
    (4) Fall back to the previous default size of 16px. This way themes that
        do not set the size keep the same behavior.

 gtk/gtkcellrenderertoggle.c |   36 ++++++++++++++++++++++++++++++------
 1 files changed, 30 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcellrenderertoggle.c b/gtk/gtkcellrenderertoggle.c
index d2f4889..fcf82ab 100644
--- a/gtk/gtkcellrenderertoggle.c
+++ b/gtk/gtkcellrenderertoggle.c
@@ -115,7 +115,7 @@ gtk_cell_renderer_toggle_init (GtkCellRendererToggle *celltoggle)
   g_object_set (celltoggle, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
   gtk_cell_renderer_set_padding (GTK_CELL_RENDERER (celltoggle), 2, 2);
 
-  priv->indicator_size = TOGGLE_WIDTH;
+  priv->indicator_size = 0;
   priv->inconsistent = FALSE;
 }
 
@@ -171,8 +171,8 @@ gtk_cell_renderer_toggle_class_init (GtkCellRendererToggleClass *class)
                                                     P_("Size of check or radio indicator"),
                                                     0,
                                                     G_MAXINT,
-                                                    TOGGLE_WIDTH,
-                                                    GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+                                                    0,
+                                                    
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_DEPRECATED));
 
   
   /**
@@ -321,7 +321,30 @@ gtk_cell_renderer_toggle_save_context (GtkCellRenderer *cell,
 
   return context;
 }
-                              
+ 
+static void
+calc_indicator_size (GtkStyleContext *context,
+                     gint             indicator_size,
+                     gint            *width,
+                     gint            *height)
+{
+  if (indicator_size != 0)
+    {
+      *width = *height = indicator_size;
+      return;
+    }
+
+  gtk_style_context_get (context, gtk_style_context_get_state (context),
+                         "min-width", width,
+                         "min-height", height,
+                         NULL);
+
+  if (*width == 0)
+    *width = TOGGLE_WIDTH;
+  if (*height == 0)
+    *height = TOGGLE_WIDTH;
+}
+
 static void
 gtk_cell_renderer_toggle_get_size (GtkCellRenderer    *cell,
                                   GtkWidget          *widget,
@@ -346,8 +369,9 @@ gtk_cell_renderer_toggle_get_size (GtkCellRenderer    *cell,
   gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
   gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border);
 
-  calc_width = xpad * 2 + priv->indicator_size + padding.left + padding.right + border.left + border.right;
-  calc_height = ypad * 2 + priv->indicator_size + padding.top + padding.bottom + border.top + border.bottom;
+  calc_indicator_size (context, priv->indicator_size, &calc_width, &calc_height);
+  calc_width += xpad * 2 + padding.left + padding.right + border.left + border.right;
+  calc_height += ypad * 2 + padding.top + padding.bottom + border.top + border.bottom;
 
   gtk_style_context_restore (context);
 


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