diff options
author | Timm Bäder <mail@baedert.org> | 2016-10-22 16:06:14 +0200 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2016-10-22 19:05:47 +0200 |
commit | 9992a616efa47205ac16ed8be255eda5e7aadf6c (patch) | |
tree | 3879538642de33a77472bafe3e6e8afea3b3e343 /gtk/gtkscale.c | |
parent | 6525b95e2502080c08b65317c910204c2b6125da (diff) | |
download | gtk+-9992a616efa47205ac16ed8be255eda5e7aadf6c.tar.gz |
widget: Use ::measure vfunc to measure size
Add a new ::measure vfunc similar to GtkCssGadget's that widget
implementations have to override instead of the old get_preferred_width,
get_preferred_height, get_preferred_width_for_height,
get_preferred_height_for_width and
get_preferred_height_and_baseline_for_width.
Diffstat (limited to 'gtk/gtkscale.c')
-rw-r--r-- | gtk/gtkscale.c | 82 |
1 files changed, 29 insertions, 53 deletions
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c index 2ca27647c6..f621ab40e1 100644 --- a/gtk/gtkscale.c +++ b/gtk/gtkscale.c @@ -190,12 +190,13 @@ static void gtk_scale_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gtk_scale_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural); -static void gtk_scale_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural); +static void gtk_scale_measure (GtkWidget *widget, + GtkOrientation orientation, + int for_size, + int *minimum, + int *natural, + int *minimum_baseline, + int *natural_baseline); static void gtk_scale_get_range_border (GtkRange *range, GtkBorder *border); static void gtk_scale_get_range_size_request (GtkRange *range, @@ -718,8 +719,7 @@ gtk_scale_class_init (GtkScaleClass *class) widget_class->screen_changed = gtk_scale_screen_changed; widget_class->draw = gtk_scale_draw; widget_class->size_allocate = gtk_scale_size_allocate; - widget_class->get_preferred_width = gtk_scale_get_preferred_width; - widget_class->get_preferred_height = gtk_scale_get_preferred_height; + widget_class->measure = gtk_scale_measure; range_class->get_range_border = gtk_scale_get_range_border; range_class->get_range_size_request = gtk_scale_get_range_size_request; @@ -1699,66 +1699,42 @@ gtk_scale_measure_marks (GtkCssGadget *gadget, } static void -gtk_scale_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - GtkScale *scale = GTK_SCALE (widget); - GtkScalePrivate *priv = scale->priv; - - GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_width (widget, minimum, natural); - - if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL) - { - int top_marks_width = 0, bottom_marks_width = 0, marks_width; - - if (priv->top_marks_gadget) - gtk_css_gadget_get_preferred_size (priv->top_marks_gadget, - GTK_ORIENTATION_HORIZONTAL, -1, - &top_marks_width, NULL, - NULL, NULL); - if (priv->bottom_marks_gadget) - gtk_css_gadget_get_preferred_size (priv->bottom_marks_gadget, - GTK_ORIENTATION_HORIZONTAL, -1, - &bottom_marks_width, NULL, - NULL, NULL); - - marks_width = MAX (top_marks_width, bottom_marks_width); - - *minimum = MAX (*minimum, marks_width); - *natural = MAX (*natural, marks_width); - } -} - -static void -gtk_scale_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural) +gtk_scale_measure (GtkWidget *widget, + GtkOrientation orientation, + int for_size, + int *minimum, + int *natural, + int *minimum_baseline, + int *natural_baseline) { GtkScale *scale = GTK_SCALE (widget); GtkScalePrivate *priv = scale->priv; - GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_height (widget, minimum, natural); + GTK_WIDGET_CLASS (gtk_scale_parent_class)->measure (widget, + orientation, + for_size, + minimum, natural, + minimum_baseline, natural_baseline); - if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_VERTICAL) + if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == orientation) { - int top_marks_height = 0, bottom_marks_height = 0, marks_height; + int top_marks_size = 0, bottom_marks_size = 0, marks_size; if (priv->top_marks_gadget) gtk_css_gadget_get_preferred_size (priv->top_marks_gadget, - GTK_ORIENTATION_VERTICAL, -1, - &top_marks_height, NULL, + orientation, for_size, + &top_marks_size, NULL, NULL, NULL); if (priv->bottom_marks_gadget) gtk_css_gadget_get_preferred_size (priv->bottom_marks_gadget, - GTK_ORIENTATION_VERTICAL, -1, - &bottom_marks_height, NULL, + orientation, for_size, + &bottom_marks_size, NULL, NULL, NULL); - marks_height = MAX (top_marks_height, bottom_marks_height); + marks_size = MAX (top_marks_size, bottom_marks_size); - *minimum = MAX (*minimum, marks_height); - *natural = MAX (*natural, marks_height); + *minimum = MAX (*minimum, marks_size); + *natural = MAX (*natural, marks_size); } } |