scale: port marks size request to gadgets

This commit is contained in:
Cosimo Cecchi 2016-02-27 15:24:32 -08:00
parent 2f420d0e14
commit 562a501f3b

View File

@ -176,13 +176,6 @@ static void gtk_scale_get_preferred_height (GtkWidget *widget,
static void gtk_scale_style_updated (GtkWidget *widget); static void gtk_scale_style_updated (GtkWidget *widget);
static void gtk_scale_get_range_border (GtkRange *range, static void gtk_scale_get_range_border (GtkRange *range,
GtkBorder *border); GtkBorder *border);
static void gtk_scale_get_mark_label_size (GtkScale *scale,
gint *count_top,
gint *width_top,
gint *height_top,
gint *count_bottom,
gint *width_bottom,
gint *height_bottom);
static void gtk_scale_finalize (GObject *object); static void gtk_scale_finalize (GObject *object);
static void gtk_scale_screen_changed (GtkWidget *widget, static void gtk_scale_screen_changed (GtkWidget *widget,
GdkScreen *old_screen); GdkScreen *old_screen);
@ -876,11 +869,13 @@ gtk_scale_get_range_border (GtkRange *range,
GtkWidget *widget; GtkWidget *widget;
GtkScale *scale; GtkScale *scale;
gint w, h; gint w, h;
gint value_spacing;
widget = GTK_WIDGET (range); widget = GTK_WIDGET (range);
scale = GTK_SCALE (range); scale = GTK_SCALE (range);
priv = scale->priv; priv = scale->priv;
gtk_widget_style_get (widget, "value-spacing", &value_spacing, NULL);
gtk_scale_get_value_size (scale, &w, &h); gtk_scale_get_value_size (scale, &w, &h);
border->left = 0; border->left = 0;
@ -890,9 +885,6 @@ gtk_scale_get_range_border (GtkRange *range,
if (priv->draw_value) if (priv->draw_value)
{ {
gint value_spacing;
gtk_widget_style_get (widget, "value-spacing", &value_spacing, NULL);
switch (priv->value_pos) switch (priv->value_pos)
{ {
case GTK_POS_LEFT: case GTK_POS_LEFT:
@ -910,32 +902,52 @@ gtk_scale_get_range_border (GtkRange *range,
} }
} }
if (priv->marks) if (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)) == GTK_ORIENTATION_HORIZONTAL)
{ {
gint value_spacing; int height;
gint n_top, w_top, h_top, n_bottom, w_bottom, h_bottom;
gtk_widget_style_get (widget, if (priv->top_marks_gadget)
"value-spacing", &value_spacing,
NULL);
gtk_scale_get_mark_label_size (scale,
&n_top, &w_top, &h_top,
&n_bottom, &w_bottom, &h_bottom);
if (gtk_orientable_get_orientation (GTK_ORIENTABLE (scale)) == GTK_ORIENTATION_HORIZONTAL)
{ {
if (h_top > 0) gtk_css_gadget_get_preferred_size (priv->top_marks_gadget,
border->top += h_top + value_spacing; GTK_ORIENTATION_VERTICAL, -1,
if (h_bottom > 0) &height, NULL,
border->bottom += h_bottom + value_spacing; NULL, NULL);
if (height > 0)
border->top += height + value_spacing;
} }
else
if (priv->bottom_marks_gadget)
{ {
if (w_top > 0) gtk_css_gadget_get_preferred_size (priv->bottom_marks_gadget,
border->left += w_top + value_spacing; GTK_ORIENTATION_VERTICAL, -1,
if (w_bottom > 0) &height, NULL,
border->right += w_bottom + value_spacing; NULL, NULL);
if (height > 0)
border->bottom += height + value_spacing;
}
}
else
{
int width;
if (priv->top_marks_gadget)
{
gtk_css_gadget_get_preferred_size (priv->top_marks_gadget,
GTK_ORIENTATION_HORIZONTAL, -1,
&width, NULL,
NULL, NULL);
if (width > 0)
border->left += width + value_spacing;
}
if (priv->bottom_marks_gadget)
{
gtk_css_gadget_get_preferred_size (priv->bottom_marks_gadget,
GTK_ORIENTATION_HORIZONTAL, -1,
&width, NULL,
NULL, NULL);
if (width > 0)
border->right += width + value_spacing;
} }
} }
} }
@ -1065,36 +1077,97 @@ gtk_scale_screen_changed (GtkWidget *widget,
gtk_scale_clear_layout (GTK_SCALE (widget)); gtk_scale_clear_layout (GTK_SCALE (widget));
} }
static void
gtk_scale_measure_marks (GtkCssGadget *gadget,
GtkOrientation orientation,
gint for_size,
gint *minimum,
gint *natural,
gint *minimum_baseline,
gint *natural_baseline,
gpointer user_data)
{
GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
GtkScale *scale = GTK_SCALE (widget);
GtkScalePrivate *priv = scale->priv;
GtkCssGadget *slider_gadget = gtk_range_get_slider_gadget (GTK_RANGE (scale));
GtkOrientation scale_orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (scale));
int n_top, w_top, h_top, n_bottom, w_bottom, h_bottom;
int slider_length;
gtk_scale_get_mark_label_size (scale,
&n_top, &w_top, &h_top,
&n_bottom, &w_bottom, &h_bottom);
gtk_css_gadget_get_preferred_size (slider_gadget,
orientation, -1,
&slider_length, NULL,
NULL, NULL);
if (gadget == priv->top_marks_gadget)
{
if (scale_orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
*minimum = *natural = (n_top - 1) * w_top + MAX (w_top, slider_length);
else
*minimum = *natural = h_top;
}
else
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
*minimum = *natural = w_top;
else
*minimum = *natural = (n_top - 1) * h_top + MAX (h_top, slider_length);
}
}
else
{
if (scale_orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
*minimum = *natural = (n_bottom - 1) * w_bottom + MAX (w_bottom, slider_length);
else
*minimum = *natural = h_bottom;
}
else
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
*minimum = *natural = w_bottom;
else
*minimum = *natural = (n_bottom - 1) * h_bottom + MAX (h_bottom, slider_length);
}
}
}
static void static void
gtk_scale_get_preferred_width (GtkWidget *widget, gtk_scale_get_preferred_width (GtkWidget *widget,
gint *minimum, gint *minimum,
gint *natural) gint *natural)
{ {
GtkScale *scale = GTK_SCALE (widget);
GtkScalePrivate *priv = scale->priv;
GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_width (widget, minimum, natural); GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_width (widget, minimum, natural);
if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL) if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL)
{ {
gint n_top, w_top, h_top, n_bottom, w_bottom, h_bottom; int top_marks_width = 0, bottom_marks_width = 0, marks_width;
GtkCssGadget *slider_gadget;
gint slider_length;
gint w;
slider_gadget = gtk_range_get_slider_gadget (GTK_RANGE (widget)); if (priv->top_marks_gadget)
gtk_css_gadget_get_preferred_size (slider_gadget, gtk_css_gadget_get_preferred_size (priv->top_marks_gadget,
GTK_ORIENTATION_HORIZONTAL, -1, GTK_ORIENTATION_HORIZONTAL, -1,
&slider_length, NULL, &top_marks_width, NULL,
NULL, 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);
gtk_scale_get_mark_label_size (GTK_SCALE (widget), marks_width = MAX (top_marks_width, bottom_marks_width);
&n_top, &w_top, &h_top,
&n_bottom, &w_bottom, &h_bottom);
w_top = (n_top - 1) * w_top + MAX (w_top, slider_length); *minimum = MAX (*minimum, marks_width);
w_bottom = (n_bottom - 1) * w_bottom + MAX (w_bottom, slider_length); *natural = MAX (*natural, marks_width);
w = MAX (w_top, w_bottom);
*minimum = MAX (*minimum, w);
*natural = MAX (*natural, w);
} }
} }
@ -1103,31 +1176,30 @@ gtk_scale_get_preferred_height (GtkWidget *widget,
gint *minimum, gint *minimum,
gint *natural) gint *natural)
{ {
GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_height (widget, minimum, natural); GtkScale *scale = GTK_SCALE (widget);
GtkScalePrivate *priv = scale->priv;
GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_height (widget, minimum, natural);
if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_VERTICAL) if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_VERTICAL)
{ {
gint n_top, w_top, h_top, n_bottom, w_bottom, h_bottom; int top_marks_height = 0, bottom_marks_height = 0, marks_height;
GtkCssGadget *slider_gadget;
gint slider_length;
gint h;
slider_gadget = gtk_range_get_slider_gadget (GTK_RANGE (widget)); if (priv->top_marks_gadget)
gtk_css_gadget_get_preferred_size (slider_gadget, gtk_css_gadget_get_preferred_size (priv->top_marks_gadget,
GTK_ORIENTATION_VERTICAL, -1, GTK_ORIENTATION_VERTICAL, -1,
&slider_length, NULL, &top_marks_height, NULL,
NULL, 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,
NULL, NULL);
gtk_scale_get_mark_label_size (GTK_SCALE (widget), marks_height = MAX (top_marks_height, bottom_marks_height);
&n_top, &w_top, &h_top,
&n_bottom, &w_bottom, &h_bottom);
h_top = (n_top - 1) * h_top + MAX (h_top, slider_length);
h_bottom = (n_bottom - 1) * h_top + MAX (h_bottom, slider_length);
h = MAX (h_top, h_bottom);
*minimum = MAX (*minimum, h); *minimum = MAX (*minimum, marks_height);
*natural = MAX (*natural, h); *natural = MAX (*natural, marks_height);
} }
} }
@ -1639,7 +1711,7 @@ gtk_scale_add_mark (GtkScale *scale,
priv->top_marks_gadget = priv->top_marks_gadget =
gtk_css_custom_gadget_new ("marks", gtk_css_custom_gadget_new ("marks",
GTK_WIDGET (scale), NULL, NULL, GTK_WIDGET (scale), NULL, NULL,
NULL, gtk_scale_measure_marks,
NULL, NULL,
NULL, NULL,
NULL, NULL); NULL, NULL);
@ -1656,7 +1728,7 @@ gtk_scale_add_mark (GtkScale *scale,
priv->bottom_marks_gadget = priv->bottom_marks_gadget =
gtk_css_custom_gadget_new ("marks", gtk_css_custom_gadget_new ("marks",
GTK_WIDGET (scale), NULL, NULL, GTK_WIDGET (scale), NULL, NULL,
NULL, gtk_scale_measure_marks,
NULL, NULL,
NULL, NULL,
NULL, NULL); NULL, NULL);