diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2011-03-01 08:59:02 -0500 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2011-03-03 17:48:25 -0500 |
commit | 6abbd68674dc9b1ff53ce2e9d1c6ee0b3310c794 (patch) | |
tree | 5ddabaf823385d12450497f2d70e27f197d5d6c4 /gtk/gtkswitch.c | |
parent | c310c35a7a87307c1534a932f43f9255d26faa9b (diff) | |
download | gtk+-6abbd68674dc9b1ff53ce2e9d1c6ee0b3310c794.tar.gz |
switch: fetch the padding values from the slider
It's the slider which acts as a child inside the container through, so
we should fetch the slider padding when computing height/width.
Diffstat (limited to 'gtk/gtkswitch.c')
-rw-r--r-- | gtk/gtkswitch.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index 1a8e42762d..0ea741bbaa 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -285,19 +285,30 @@ gtk_switch_get_preferred_width (GtkWidget *widget, gint *minimum, gint *natural) { + GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv; GtkStyleContext *context; GtkStateFlags state; - GtkBorder padding; + GtkBorder padding, border; gint width, slider_width, focus_width, focus_pad; PangoLayout *layout; PangoRectangle logical_rect; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); + + if (priv->is_active) + state |= GTK_STATE_FLAG_ACTIVE; + + gtk_style_context_save (context); + + gtk_style_context_set_state (context, state); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER); gtk_style_context_get_padding (context, state, &padding); width = padding.left + padding.right; + gtk_style_context_restore (context); + gtk_widget_style_get (widget, "slider-width", &slider_width, "focus-line-width", &focus_width, @@ -337,6 +348,7 @@ gtk_switch_get_preferred_height (GtkWidget *widget, gint *minimum, gint *natural) { + GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv; GtkStyleContext *context; GtkStateFlags state; GtkBorder padding; @@ -347,10 +359,20 @@ gtk_switch_get_preferred_height (GtkWidget *widget, context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); + + if (priv->is_active) + state |= GTK_STATE_FLAG_ACTIVE; + + gtk_style_context_save (context); + + gtk_style_context_set_state (context, state); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER); gtk_style_context_get_padding (context, state, &padding); height = padding.top + padding.bottom; + gtk_style_context_restore (context); + gtk_widget_style_get (widget, "focus-line-width", &focus_width, "focus-padding", &focus_pad, @@ -520,8 +542,15 @@ gtk_switch_draw (GtkWidget *widget, if (priv->is_active) state |= GTK_STATE_FLAG_ACTIVE; + gtk_style_context_save (context); + + gtk_style_context_set_state (context, state); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER); + gtk_style_context_get_padding (context, state, &padding); + gtk_style_context_restore (context); + x = 0; y = 0; width = gtk_widget_get_allocated_width (widget); @@ -530,15 +559,14 @@ gtk_switch_draw (GtkWidget *widget, if (gtk_widget_has_focus (widget)) gtk_render_focus (context, cr, x, y, width, height); - gtk_style_context_save (context); - gtk_style_context_set_state (context, state); - x += focus_width + focus_pad; y += focus_width + focus_pad; width -= 2 * (focus_width + focus_pad); height -= 2 * (focus_width + focus_pad); + gtk_style_context_save (context); gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH); + gtk_style_context_set_state (context, state); gtk_render_background (context, cr, x, y, width, height); gtk_render_frame (context, cr, x, y, width, height); |