1Upstream-Status: Pending
2
3Index: gtk/gtkcellrenderertoggle.c
4===================================================================
5--- gtk/gtkcellrenderertoggle.c.orig	2010-06-22 18:11:33.000000000 +0800
6+++ gtk/gtkcellrenderertoggle.c	2010-06-22 18:11:43.000000000 +0800
7@@ -71,6 +71,8 @@
8   PROP_INDICATOR_SIZE
9 };
10
11+/* This is a hard-coded default which promptly gets overridden by a size
12+   calculated from the font size. */
13 #define TOGGLE_WIDTH 13
14
15 static guint toggle_cell_signals[LAST_SIGNAL] = { 0 };
16@@ -80,8 +82,9 @@
17 typedef struct _GtkCellRendererTogglePrivate GtkCellRendererTogglePrivate;
18 struct _GtkCellRendererTogglePrivate
19 {
20-  gint indicator_size;
21-
22+  gint indicator_size; /* This is the real size */
23+  gint override_size; /* This is the size set from the indicator-size property */
24+  GtkWidget *cached_widget;
25   guint inconsistent : 1;
26 };
27
28@@ -104,6 +107,7 @@
29   GTK_CELL_RENDERER (celltoggle)->ypad = 2;
30
31   priv->indicator_size = TOGGLE_WIDTH;
32+  priv->override_size = 0;
33   priv->inconsistent = FALSE;
34 }
35
36@@ -210,7 +214,7 @@
37       g_value_set_boolean (value, celltoggle->radio);
38       break;
39     case PROP_INDICATOR_SIZE:
40-      g_value_set_int (value, priv->indicator_size);
41+      g_value_set_int (value, priv->override_size ? priv->override_size : priv->indicator_size);
42       break;
43     default:
44       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
45@@ -245,7 +249,7 @@
46       celltoggle->radio = g_value_get_boolean (value);
47       break;
48     case PROP_INDICATOR_SIZE:
49-      priv->indicator_size = g_value_get_int (value);
50+      priv->override_size = g_value_get_int (value);
51       break;
52     default:
53       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
54@@ -273,6 +277,27 @@
55 }
56
57 static void
58+on_widget_style_set (GtkWidget *widget, GtkStyle *previous, gpointer user_data)
59+{
60+  GtkCellRendererTogglePrivate *priv = user_data;
61+  PangoContext *context;
62+  PangoFontMetrics *metrics;
63+  int height;
64+
65+  context = gtk_widget_get_pango_context (widget);
66+  metrics = pango_context_get_metrics (context,
67+                                       widget->style->font_desc,
68+                                       pango_context_get_language (context));
69+
70+  height = pango_font_metrics_get_ascent (metrics) +
71+    pango_font_metrics_get_descent (metrics);
72+
73+  pango_font_metrics_unref (metrics);
74+
75+  priv->indicator_size = PANGO_PIXELS (height * 0.85);
76+}
77+
78+static void
79 gtk_cell_renderer_toggle_get_size (GtkCellRenderer *cell,
80 				   GtkWidget       *widget,
81 				   GdkRectangle    *cell_area,
82@@ -287,6 +312,20 @@
83
84   priv = GTK_CELL_RENDERER_TOGGLE_GET_PRIVATE (cell);
85
86+  if (priv->override_size) {
87+    priv->indicator_size = priv->override_size;
88+  } else if (priv->cached_widget != widget) {
89+    if (priv->cached_widget) {
90+      g_object_remove_weak_pointer (widget, &priv->cached_widget);
91+      g_signal_handlers_disconnect_by_func (priv->cached_widget, on_widget_style_set, priv);
92+    }
93+    priv->cached_widget = widget;
94+    g_object_add_weak_pointer (widget, &priv->cached_widget);
95+    g_signal_connect (widget, "style-set", on_widget_style_set, priv);
96+
97+    on_widget_style_set (widget, NULL, priv);
98+  }
99+
100   calc_width = (gint) cell->xpad * 2 + priv->indicator_size;
101   calc_height = (gint) cell->ypad * 2 + priv->indicator_size;
102
103