diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2016-02-27 13:31:26 -0800 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2016-02-29 10:45:13 -0800 |
commit | 424f17c0fbd6a97132c73a3fb7f3fb374615384d (patch) | |
tree | 7bbf59f26b381eebeefb26446b70a9ab310474e9 | |
parent | 0468ff15459b4e01ca57e4a057908de70e502456 (diff) | |
download | gtk+-424f17c0fbd6a97132c73a3fb7f3fb374615384d.tar.gz |
range: don't use gtk_range_set_min_slider_size()
The way this method is used from the GtkRange subclasses doesn't really
work well when the slider properties change as a consequence of e.g. a
style class being applied (e.g. the fine-tune style class).
In fact, there's no need to read the minimum slider size out of band,
and we can obtain the same result in a way that always work by setting a
private property on GtkRange.
-rw-r--r-- | gtk/gtkrange.c | 44 | ||||
-rw-r--r-- | gtk/gtkrangeprivate.h | 4 | ||||
-rw-r--r-- | gtk/gtkscale.c | 37 | ||||
-rw-r--r-- | gtk/gtkscrollbar.c | 9 |
4 files changed, 51 insertions, 43 deletions
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index d712346340..edb9ba4ee4 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -128,6 +128,7 @@ struct _GtkRangePrivate guint flippable : 1; guint inverted : 1; guint slider_size_fixed : 1; + guint slider_use_min_size : 1; guint trough_click_forward : 1; /* trough click was on the forward side of slider */ /* Stepper sensitivity */ @@ -1110,6 +1111,19 @@ gtk_range_get_flippable (GtkRange *range) return range->priv->flippable; } +void +gtk_range_set_slider_use_min_size (GtkRange *range, + gboolean use_min_size) +{ + GtkRangePrivate *priv = range->priv; + + if (use_min_size != priv->slider_use_min_size) + { + priv->slider_use_min_size = use_min_size; + gtk_css_gadget_queue_resize (priv->slider_gadget); + } +} + /** * gtk_range_set_slider_size_fixed: * @range: a #GtkRange @@ -3425,11 +3439,13 @@ gtk_range_compute_slider_position (GtkRange *range, { GtkRangePrivate *priv = range->priv; GtkAllocation trough_content_alloc; - int slider_width, slider_height; + int slider_width, slider_height, min_slider_size; measure_one_gadget (priv->slider_gadget, &slider_width, &slider_height); gtk_css_gadget_get_content_box (priv->trough_gadget, &trough_content_alloc); + min_slider_size = priv->min_slider_size; + if (priv->orientation == GTK_ORIENTATION_VERTICAL) { gint y, bottom, top, height; @@ -3440,6 +3456,9 @@ gtk_range_compute_slider_position (GtkRange *range, slider_rect->x = trough_content_alloc.x + (int) floor ((trough_content_alloc.width - slider_width) / 2); slider_rect->width = slider_width; + if (priv->slider_use_min_size) + min_slider_size = slider_height; + /* Compute slider position/length */ top = trough_content_alloc.y; bottom = top + trough_content_alloc.height; @@ -3447,8 +3466,8 @@ gtk_range_compute_slider_position (GtkRange *range, /* Scale slider half extends over the trough edge */ if (GTK_IS_SCALE (range)) { - top -= priv->min_slider_size / 2; - bottom += priv->min_slider_size / 2; + top -= min_slider_size / 2; + bottom += min_slider_size / 2; } /* slider height is the fraction (page_size / @@ -3459,11 +3478,11 @@ gtk_range_compute_slider_position (GtkRange *range, height = ((bottom - top) * (gtk_adjustment_get_page_size (priv->adjustment) / (gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment)))); else - height = priv->min_slider_size; + height = min_slider_size; - if (height < priv->min_slider_size || + if (height < min_slider_size || priv->slider_size_fixed) - height = priv->min_slider_size; + height = min_slider_size; height = MIN (height, trough_content_alloc.height); @@ -3491,6 +3510,9 @@ gtk_range_compute_slider_position (GtkRange *range, slider_rect->y = trough_content_alloc.y + (int) floor ((trough_content_alloc.height - slider_height) / 2); slider_rect->height = slider_height; + if (priv->slider_use_min_size) + min_slider_size = slider_width; + /* Compute slider position/length */ left = trough_content_alloc.x; right = left + trough_content_alloc.width; @@ -3498,8 +3520,8 @@ gtk_range_compute_slider_position (GtkRange *range, /* Scale slider half extends over the trough edge */ if (GTK_IS_SCALE (range)) { - left -= priv->min_slider_size / 2; - right += priv->min_slider_size / 2; + left -= min_slider_size / 2; + right += min_slider_size / 2; } /* slider width is the fraction (page_size / @@ -3510,11 +3532,11 @@ gtk_range_compute_slider_position (GtkRange *range, width = ((right - left) * (gtk_adjustment_get_page_size (priv->adjustment) / (gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment)))); else - width = priv->min_slider_size; + width = min_slider_size; - if (width < priv->min_slider_size || + if (width < min_slider_size || priv->slider_size_fixed) - width = priv->min_slider_size; + width = min_slider_size; width = MIN (width, trough_content_alloc.width); diff --git a/gtk/gtkrangeprivate.h b/gtk/gtkrangeprivate.h index 4376b0347a..055c5acbae 100644 --- a/gtk/gtkrangeprivate.h +++ b/gtk/gtkrangeprivate.h @@ -49,7 +49,9 @@ void _gtk_range_set_steppers (GtkRange *range gboolean has_c, gboolean has_d); -GtkCssGadget *gtk_range_get_slider_gadget (GtkRange *range); +void gtk_range_set_slider_use_min_size (GtkRange *range, + gboolean use_min_size); +GtkCssGadget *gtk_range_get_slider_gadget (GtkRange *range); G_END_DECLS diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c index 523bccb327..eee070821d 100644 --- a/gtk/gtkscale.c +++ b/gtk/gtkscale.c @@ -263,24 +263,6 @@ gtk_scale_notify (GObject *object, G_OBJECT_CLASS (gtk_scale_parent_class)->notify (object, pspec); } -static void -gtk_scale_update_style (GtkScale *scale) -{ - gint slider_length; - GtkRange *range; - GtkCssGadget *slider_gadget; - - range = GTK_RANGE (scale); - slider_gadget = gtk_range_get_slider_gadget (range); - gtk_css_gadget_get_preferred_size (slider_gadget, - gtk_orientable_get_orientation (GTK_ORIENTABLE (scale)), -1, - &slider_length, NULL, - NULL, NULL); - - gtk_range_set_min_slider_size (range, slider_length); - gtk_scale_clear_layout (scale); -} - #define add_slider_binding(binding_set, keyval, mask, scroll) \ gtk_binding_entry_add_signal (binding_set, keyval, mask, \ I_("move-slider"), 1, \ @@ -536,6 +518,7 @@ gtk_scale_init (GtkScale *scale) gtk_widget_set_can_focus (GTK_WIDGET (scale), TRUE); gtk_range_set_slider_size_fixed (range, TRUE); + gtk_range_set_slider_use_min_size (range, TRUE); _gtk_range_set_has_origin (range, TRUE); @@ -545,8 +528,6 @@ gtk_scale_init (GtkScale *scale) gtk_range_set_round_digits (range, priv->digits); gtk_range_set_flippable (range, TRUE); - - gtk_scale_update_style (scale); } static void @@ -1071,7 +1052,7 @@ gtk_scale_get_mark_label_size (GtkScale *scale, static void gtk_scale_style_updated (GtkWidget *widget) { - gtk_scale_update_style (GTK_SCALE (widget)); + gtk_scale_clear_layout (GTK_SCALE (widget)); GTK_WIDGET_CLASS (gtk_scale_parent_class)->style_updated (widget); } @@ -1093,10 +1074,15 @@ gtk_scale_get_preferred_width (GtkWidget *widget, if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL) { gint n1, w1, h1, n2, w2, h2; + GtkCssGadget *slider_gadget; gint slider_length; gint w; - slider_length = gtk_range_get_min_slider_size (GTK_RANGE (widget)); + slider_gadget = gtk_range_get_slider_gadget (GTK_RANGE (widget)); + gtk_css_gadget_get_preferred_size (slider_gadget, + GTK_ORIENTATION_HORIZONTAL, -1, + &slider_length, NULL, + NULL, NULL); gtk_scale_get_mark_label_size (GTK_SCALE (widget), GTK_POS_TOP, &n1, &w1, &h1, &n2, &w2, &h2); @@ -1120,10 +1106,15 @@ gtk_scale_get_preferred_height (GtkWidget *widget, if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_VERTICAL) { gint n1, w1, h1, n2, w2, h2; + GtkCssGadget *slider_gadget; gint slider_length; gint h; - slider_length = gtk_range_get_min_slider_size (GTK_RANGE (widget)); + slider_gadget = gtk_range_get_slider_gadget (GTK_RANGE (widget)); + gtk_css_gadget_get_preferred_size (slider_gadget, + GTK_ORIENTATION_VERTICAL, -1, + &slider_length, NULL, + NULL, NULL); gtk_scale_get_mark_label_size (GTK_SCALE (widget), GTK_POS_TOP, &n1, &w1, &h1, &n2, &w2, &h2); h1 = (n1 - 1) * h1 + MAX (h1, slider_length); diff --git a/gtk/gtkscrollbar.c b/gtk/gtkscrollbar.c index 1656415d83..0f4ca11291 100644 --- a/gtk/gtkscrollbar.c +++ b/gtk/gtkscrollbar.c @@ -152,17 +152,10 @@ gtk_scrollbar_class_init (GtkScrollbarClass *class) static void gtk_scrollbar_update_style (GtkScrollbar *scrollbar) { - gint slider_length; gboolean fixed_size; gboolean has_a, has_b, has_c, has_d; GtkRange *range = GTK_RANGE (scrollbar); GtkWidget *widget = GTK_WIDGET (scrollbar); - GtkCssGadget *slider_gadget = gtk_range_get_slider_gadget (range); - - gtk_css_gadget_get_preferred_size (slider_gadget, - gtk_orientable_get_orientation (GTK_ORIENTABLE (scrollbar)), -1, - &slider_length, NULL, - NULL, NULL); gtk_widget_style_get (widget, "fixed-slider-length", &fixed_size, @@ -172,7 +165,6 @@ gtk_scrollbar_update_style (GtkScrollbar *scrollbar) "has-forward-stepper", &has_d, NULL); - gtk_range_set_min_slider_size (range, slider_length); gtk_range_set_slider_size_fixed (range, fixed_size); _gtk_range_set_steppers (range, has_a, has_b, has_c, has_d); } @@ -181,6 +173,7 @@ static void gtk_scrollbar_init (GtkScrollbar *scrollbar) { gtk_scrollbar_update_style (scrollbar); + gtk_range_set_slider_use_min_size (GTK_RANGE (scrollbar), TRUE); } static void |