1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 2001 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkscaleprivate.h"
33 #include "gtkadjustment.h"
34 #include "gtkbindings.h"
35 #include "gtkbuildable.h"
36 #include "gtkbuilderprivate.h"
37 #include "gtkiconfactory.h"
38 #include "gtkicontheme.h"
40 #include "gtkmarshalers.h"
41 #include "gtkorientable.h"
42 #include "gtkprivate.h"
43 #include "gtktypebuiltins.h"
45 #include "a11y/gtkscaleaccessible.h"
50 * @Short_description: A slider widget for selecting a value from a range
53 * A GtkScale is a slider control used to select a numeric value.
54 * To use it, you'll probably want to investigate the methods on
55 * its base class, #GtkRange, in addition to the methods for GtkScale itself.
56 * To set the value of a scale, you would normally use gtk_range_set_value().
57 * To detect changes to the value, you would normally use the
58 * #GtkRange::value-changed signal.
60 * Note that using the same upper and lower bounds for the #GtkScale (through
61 * the #GtkRange methods) will hide the slider itself. This is useful for
62 * applications that want to show an undeterminate value on the scale, without
63 * changing the layout of the application (such as movie or music players).
65 * <refsect2 id="GtkScale-BUILDER-UI"><title>GtkScale as GtkBuildable</title>
66 * GtkScale supports a custom <marks> element, which
67 * can contain multiple <mark> elements. The "value" and "position"
68 * attributes have the same meaning as gtk_scale_add_mark() parameters of the
69 * same name. If the element is not empty, its content is taken as the markup
70 * to show at the mark. It can be translated with the usual "translatable and
71 * "context" attributes.
76 #define MAX_DIGITS (64) /* don't change this,
77 * a) you don't need to and
78 * b) you might cause buffer owerflows in
79 * unrelated code portions otherwise
82 typedef struct _GtkScaleMark GtkScaleMark;
84 struct _GtkScalePrivate
100 GtkPositionType position; /* always GTK_POS_TOP or GTK_POS_BOTTOM */
116 static guint signals[LAST_SIGNAL];
118 static void gtk_scale_set_property (GObject *object,
122 static void gtk_scale_get_property (GObject *object,
126 static void gtk_scale_get_preferred_width (GtkWidget *widget,
129 static void gtk_scale_get_preferred_height (GtkWidget *widget,
132 static void gtk_scale_style_updated (GtkWidget *widget);
133 static void gtk_scale_get_range_border (GtkRange *range,
135 static void gtk_scale_get_mark_label_size (GtkScale *scale,
136 GtkPositionType position,
143 static void gtk_scale_finalize (GObject *object);
144 static void gtk_scale_screen_changed (GtkWidget *widget,
145 GdkScreen *old_screen);
146 static gboolean gtk_scale_draw (GtkWidget *widget,
148 static void gtk_scale_real_get_layout_offsets (GtkScale *scale,
151 static void gtk_scale_buildable_interface_init (GtkBuildableIface *iface);
152 static gboolean gtk_scale_buildable_custom_tag_start (GtkBuildable *buildable,
155 const gchar *tagname,
156 GMarkupParser *parser,
158 static void gtk_scale_buildable_custom_finished (GtkBuildable *buildable,
161 const gchar *tagname,
165 G_DEFINE_TYPE_WITH_CODE (GtkScale, gtk_scale, GTK_TYPE_RANGE,
166 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
167 gtk_scale_buildable_interface_init))
170 compare_marks (gconstpointer a, gconstpointer b, gpointer data)
172 gboolean inverted = GPOINTER_TO_INT (data);
174 const GtkScaleMark *ma, *mb;
176 val = inverted ? -1 : 1;
180 return (ma->value > mb->value) ? val : ((ma->value < mb->value) ? -val : 0);
184 gtk_scale_notify (GObject *object,
187 if (strcmp (pspec->name, "orientation") == 0)
189 GtkOrientation orientation;
191 orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (object));
192 gtk_range_set_flippable (GTK_RANGE (object),
193 orientation == GTK_ORIENTATION_HORIZONTAL);
195 else if (strcmp (pspec->name, "inverted") == 0)
197 GtkScale *scale = GTK_SCALE (object);
203 scale->priv->marks = g_slist_sort_with_data (scale->priv->marks,
205 GINT_TO_POINTER (gtk_range_get_inverted (GTK_RANGE (scale))));
207 n = g_slist_length (scale->priv->marks);
208 values = g_new (gdouble, n);
209 for (m = scale->priv->marks, i = 0; m; m = m->next, i++)
212 values[i] = mark->value;
215 _gtk_range_set_stop_values (GTK_RANGE (scale), values, n);
220 if (G_OBJECT_CLASS (gtk_scale_parent_class)->notify)
221 G_OBJECT_CLASS (gtk_scale_parent_class)->notify (object, pspec);
225 gtk_scale_update_style (GtkScale *scale)
230 range = GTK_RANGE (scale);
232 gtk_widget_style_get (GTK_WIDGET (scale),
233 "slider-length", &slider_length,
236 gtk_range_set_min_slider_size (range, slider_length);
237 _gtk_scale_clear_layout (scale);
240 #define add_slider_binding(binding_set, keyval, mask, scroll) \
241 gtk_binding_entry_add_signal (binding_set, keyval, mask, \
242 I_("move-slider"), 1, \
243 GTK_TYPE_SCROLL_TYPE, scroll)
246 gtk_scale_class_init (GtkScaleClass *class)
248 GObjectClass *gobject_class;
249 GtkWidgetClass *widget_class;
250 GtkRangeClass *range_class;
251 GtkBindingSet *binding_set;
253 gobject_class = G_OBJECT_CLASS (class);
254 range_class = (GtkRangeClass*) class;
255 widget_class = (GtkWidgetClass*) class;
257 gobject_class->set_property = gtk_scale_set_property;
258 gobject_class->get_property = gtk_scale_get_property;
259 gobject_class->notify = gtk_scale_notify;
260 gobject_class->finalize = gtk_scale_finalize;
262 widget_class->style_updated = gtk_scale_style_updated;
263 widget_class->screen_changed = gtk_scale_screen_changed;
264 widget_class->draw = gtk_scale_draw;
265 widget_class->get_preferred_width = gtk_scale_get_preferred_width;
266 widget_class->get_preferred_height = gtk_scale_get_preferred_height;
268 range_class->slider_detail = "Xscale";
269 range_class->get_range_border = gtk_scale_get_range_border;
271 class->get_layout_offsets = gtk_scale_real_get_layout_offsets;
274 * GtkScale::format-value:
275 * @scale: the object which received the signal
276 * @value: the value to format
278 * Signal which allows you to change how the scale value is displayed.
279 * Connect a signal handler which returns an allocated string representing
280 * @value. That string will then be used to display the scale's value.
282 * Here's an example signal handler which displays a value 1.0 as
283 * with "-->1.0<--".
286 * format_value_callback (GtkScale *scale,
289 * return g_strdup_printf ("-->%0.*g<--",
290 * gtk_scale_get_digits (scale), value);
294 * Return value: allocated string representing @value
296 signals[FORMAT_VALUE] =
297 g_signal_new (I_("format-value"),
298 G_TYPE_FROM_CLASS (gobject_class),
300 G_STRUCT_OFFSET (GtkScaleClass, format_value),
301 _gtk_single_string_accumulator, NULL,
302 _gtk_marshal_STRING__DOUBLE,
306 g_object_class_install_property (gobject_class,
308 g_param_spec_int ("digits",
310 P_("The number of decimal places that are displayed in the value"),
314 GTK_PARAM_READWRITE));
316 g_object_class_install_property (gobject_class,
318 g_param_spec_boolean ("draw-value",
320 P_("Whether the current value is displayed as a string next to the slider"),
322 GTK_PARAM_READWRITE));
324 g_object_class_install_property (gobject_class,
326 g_param_spec_boolean ("has-origin",
328 P_("Whether the scale has an origin"),
330 GTK_PARAM_READWRITE));
332 g_object_class_install_property (gobject_class,
334 g_param_spec_enum ("value-pos",
335 P_("Value Position"),
336 P_("The position in which the current value is displayed"),
337 GTK_TYPE_POSITION_TYPE,
339 GTK_PARAM_READWRITE));
341 gtk_widget_class_install_style_property (widget_class,
342 g_param_spec_int ("slider-length",
344 P_("Length of scale's slider"),
348 GTK_PARAM_READABLE));
350 gtk_widget_class_install_style_property (widget_class,
351 g_param_spec_int ("value-spacing",
353 P_("Space between value text and the slider/trough area"),
357 GTK_PARAM_READABLE));
359 /* All bindings (even arrow keys) are on both h/v scale, because
360 * blind users etc. don't care about scale orientation.
363 binding_set = gtk_binding_set_by_class (class);
365 add_slider_binding (binding_set, GDK_KEY_Left, 0,
366 GTK_SCROLL_STEP_LEFT);
368 add_slider_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
369 GTK_SCROLL_PAGE_LEFT);
371 add_slider_binding (binding_set, GDK_KEY_KP_Left, 0,
372 GTK_SCROLL_STEP_LEFT);
374 add_slider_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
375 GTK_SCROLL_PAGE_LEFT);
377 add_slider_binding (binding_set, GDK_KEY_Right, 0,
378 GTK_SCROLL_STEP_RIGHT);
380 add_slider_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
381 GTK_SCROLL_PAGE_RIGHT);
383 add_slider_binding (binding_set, GDK_KEY_KP_Right, 0,
384 GTK_SCROLL_STEP_RIGHT);
386 add_slider_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
387 GTK_SCROLL_PAGE_RIGHT);
389 add_slider_binding (binding_set, GDK_KEY_Up, 0,
392 add_slider_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK,
395 add_slider_binding (binding_set, GDK_KEY_KP_Up, 0,
398 add_slider_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK,
401 add_slider_binding (binding_set, GDK_KEY_Down, 0,
402 GTK_SCROLL_STEP_DOWN);
404 add_slider_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK,
405 GTK_SCROLL_PAGE_DOWN);
407 add_slider_binding (binding_set, GDK_KEY_KP_Down, 0,
408 GTK_SCROLL_STEP_DOWN);
410 add_slider_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK,
411 GTK_SCROLL_PAGE_DOWN);
413 add_slider_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK,
414 GTK_SCROLL_PAGE_LEFT);
416 add_slider_binding (binding_set, GDK_KEY_KP_Page_Up, GDK_CONTROL_MASK,
417 GTK_SCROLL_PAGE_LEFT);
419 add_slider_binding (binding_set, GDK_KEY_Page_Up, 0,
422 add_slider_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
425 add_slider_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK,
426 GTK_SCROLL_PAGE_RIGHT);
428 add_slider_binding (binding_set, GDK_KEY_KP_Page_Down, GDK_CONTROL_MASK,
429 GTK_SCROLL_PAGE_RIGHT);
431 add_slider_binding (binding_set, GDK_KEY_Page_Down, 0,
432 GTK_SCROLL_PAGE_DOWN);
434 add_slider_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
435 GTK_SCROLL_PAGE_DOWN);
437 /* Logical bindings (vs. visual bindings above) */
439 add_slider_binding (binding_set, GDK_KEY_plus, 0,
440 GTK_SCROLL_STEP_FORWARD);
442 add_slider_binding (binding_set, GDK_KEY_minus, 0,
443 GTK_SCROLL_STEP_BACKWARD);
445 add_slider_binding (binding_set, GDK_KEY_plus, GDK_CONTROL_MASK,
446 GTK_SCROLL_PAGE_FORWARD);
448 add_slider_binding (binding_set, GDK_KEY_minus, GDK_CONTROL_MASK,
449 GTK_SCROLL_PAGE_BACKWARD);
452 add_slider_binding (binding_set, GDK_KEY_KP_Add, 0,
453 GTK_SCROLL_STEP_FORWARD);
455 add_slider_binding (binding_set, GDK_KEY_KP_Subtract, 0,
456 GTK_SCROLL_STEP_BACKWARD);
458 add_slider_binding (binding_set, GDK_KEY_KP_Add, GDK_CONTROL_MASK,
459 GTK_SCROLL_PAGE_FORWARD);
461 add_slider_binding (binding_set, GDK_KEY_KP_Subtract, GDK_CONTROL_MASK,
462 GTK_SCROLL_PAGE_BACKWARD);
465 add_slider_binding (binding_set, GDK_KEY_Home, 0,
468 add_slider_binding (binding_set, GDK_KEY_KP_Home, 0,
471 add_slider_binding (binding_set, GDK_KEY_End, 0,
474 add_slider_binding (binding_set, GDK_KEY_KP_End, 0,
477 g_type_class_add_private (gobject_class, sizeof (GtkScalePrivate));
479 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCALE_ACCESSIBLE);
483 gtk_scale_init (GtkScale *scale)
485 GtkScalePrivate *priv;
486 GtkRange *range = GTK_RANGE (scale);
487 GtkStyleContext *context;
489 scale->priv = G_TYPE_INSTANCE_GET_PRIVATE (scale,
494 gtk_widget_set_can_focus (GTK_WIDGET (scale), TRUE);
496 gtk_range_set_slider_size_fixed (range, TRUE);
498 _gtk_range_set_has_origin (range, TRUE);
500 priv->draw_value = TRUE;
501 priv->value_pos = GTK_POS_TOP;
503 gtk_range_set_round_digits (range, priv->digits);
505 gtk_range_set_flippable (range,
506 gtk_orientable_get_orientation (GTK_ORIENTABLE (range))== GTK_ORIENTATION_HORIZONTAL);
508 context = gtk_widget_get_style_context (GTK_WIDGET (scale));
509 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE);
510 gtk_scale_update_style (scale);
514 gtk_scale_set_property (GObject *object,
521 scale = GTK_SCALE (object);
526 gtk_scale_set_digits (scale, g_value_get_int (value));
528 case PROP_DRAW_VALUE:
529 gtk_scale_set_draw_value (scale, g_value_get_boolean (value));
531 case PROP_HAS_ORIGIN:
532 gtk_scale_set_has_origin (scale, g_value_get_boolean (value));
535 gtk_scale_set_value_pos (scale, g_value_get_enum (value));
538 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
544 gtk_scale_get_property (GObject *object,
549 GtkScale *scale = GTK_SCALE (object);
550 GtkScalePrivate *priv = scale->priv;
555 g_value_set_int (value, priv->digits);
557 case PROP_DRAW_VALUE:
558 g_value_set_boolean (value, priv->draw_value);
560 case PROP_HAS_ORIGIN:
561 g_value_set_boolean (value, gtk_scale_get_has_origin (scale));
564 g_value_set_enum (value, priv->value_pos);
567 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
574 * @orientation: the scale's orientation.
575 * @adjustment: (allow-none): the #GtkAdjustment which sets the range
576 * of the scale, or %NULL to create a new adjustment.
578 * Creates a new #GtkScale.
580 * Return value: a new #GtkScale
585 gtk_scale_new (GtkOrientation orientation,
586 GtkAdjustment *adjustment)
588 g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
591 return g_object_new (GTK_TYPE_SCALE,
592 "orientation", orientation,
593 "adjustment", adjustment,
598 * gtk_scale_new_with_range:
599 * @orientation: the scale's orientation.
600 * @min: minimum value
601 * @max: maximum value
602 * @step: step increment (tick size) used with keyboard shortcuts
604 * Creates a new scale widget with the given orientation that lets the
605 * user input a number between @min and @max (including @min and @max)
606 * with the increment @step. @step must be nonzero; it's the distance
607 * the slider moves when using the arrow keys to adjust the scale
610 * Note that the way in which the precision is derived works best if @step
611 * is a power of ten. If the resulting precision is not suitable for your
612 * needs, use gtk_scale_set_digits() to correct it.
614 * Return value: a new #GtkScale
619 gtk_scale_new_with_range (GtkOrientation orientation,
627 g_return_val_if_fail (min < max, NULL);
628 g_return_val_if_fail (step != 0.0, NULL);
630 adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
632 if (fabs (step) >= 1.0 || step == 0.0)
638 digits = abs ((gint) floor (log10 (fabs (step))));
643 return g_object_new (GTK_TYPE_SCALE,
644 "orientation", orientation,
651 * gtk_scale_set_digits:
652 * @scale: a #GtkScale
653 * @digits: the number of decimal places to display,
654 * e.g. use 1 to display 1.0, 2 to display 1.00, etc
656 * Sets the number of decimal places that are displayed in the value.
657 * Also causes the value of the adjustment to be rounded off to this
658 * number of digits, so the retrieved value matches the value the user saw.
661 gtk_scale_set_digits (GtkScale *scale,
664 GtkScalePrivate *priv;
667 g_return_if_fail (GTK_IS_SCALE (scale));
670 range = GTK_RANGE (scale);
672 digits = CLAMP (digits, -1, MAX_DIGITS);
674 if (priv->digits != digits)
676 priv->digits = digits;
677 if (priv->draw_value)
678 gtk_range_set_round_digits (range, digits);
680 _gtk_scale_clear_layout (scale);
681 gtk_widget_queue_resize (GTK_WIDGET (scale));
683 g_object_notify (G_OBJECT (scale), "digits");
688 * gtk_scale_get_digits:
689 * @scale: a #GtkScale
691 * Gets the number of decimal places that are displayed in the value.
693 * Returns: the number of decimal places that are displayed
696 gtk_scale_get_digits (GtkScale *scale)
698 g_return_val_if_fail (GTK_IS_SCALE (scale), -1);
700 return scale->priv->digits;
704 * gtk_scale_set_draw_value:
705 * @scale: a #GtkScale
706 * @draw_value: %TRUE to draw the value
708 * Specifies whether the current value is displayed as a string next
712 gtk_scale_set_draw_value (GtkScale *scale,
715 GtkScalePrivate *priv;
717 g_return_if_fail (GTK_IS_SCALE (scale));
721 draw_value = draw_value != FALSE;
723 if (priv->draw_value != draw_value)
725 priv->draw_value = draw_value;
727 gtk_range_set_round_digits (GTK_RANGE (scale), priv->digits);
729 gtk_range_set_round_digits (GTK_RANGE (scale), -1);
731 _gtk_scale_clear_layout (scale);
733 gtk_widget_queue_resize (GTK_WIDGET (scale));
735 g_object_notify (G_OBJECT (scale), "draw-value");
740 * gtk_scale_get_draw_value:
741 * @scale: a #GtkScale
743 * Returns whether the current value is displayed as a string
744 * next to the slider.
746 * Returns: whether the current value is displayed as a string
749 gtk_scale_get_draw_value (GtkScale *scale)
751 g_return_val_if_fail (GTK_IS_SCALE (scale), FALSE);
753 return scale->priv->draw_value;
757 * gtk_scale_set_has_origin:
758 * @scale: a #GtkScale
759 * @has_origin: %TRUE if the scale has an origin
761 * If @has_origin is set to %TRUE (the default),
762 * the scale will highlight the part of the scale
763 * between the origin (bottom or left side) of the scale
764 * and the current value.
769 gtk_scale_set_has_origin (GtkScale *scale,
772 g_return_if_fail (GTK_IS_SCALE (scale));
774 has_origin = has_origin != FALSE;
776 if (_gtk_range_get_has_origin (GTK_RANGE (scale)) != has_origin)
778 _gtk_range_set_has_origin (GTK_RANGE (scale), has_origin);
780 gtk_widget_queue_draw (GTK_WIDGET (scale));
782 g_object_notify (G_OBJECT (scale), "has-origin");
787 * gtk_scale_get_has_origin:
788 * @scale: a #GtkScale
790 * Returns whether the scale has an origin.
792 * Returns: %TRUE if the scale has an origin.
797 gtk_scale_get_has_origin (GtkScale *scale)
799 g_return_val_if_fail (GTK_IS_SCALE (scale), FALSE);
801 return _gtk_range_get_has_origin (GTK_RANGE (scale));
805 * gtk_scale_set_value_pos:
806 * @scale: a #GtkScale
807 * @pos: the position in which the current value is displayed
809 * Sets the position in which the current value is displayed.
812 gtk_scale_set_value_pos (GtkScale *scale,
815 GtkScalePrivate *priv;
818 g_return_if_fail (GTK_IS_SCALE (scale));
822 if (priv->value_pos != pos)
824 priv->value_pos = pos;
825 widget = GTK_WIDGET (scale);
827 _gtk_scale_clear_layout (scale);
828 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget))
829 gtk_widget_queue_resize (widget);
831 g_object_notify (G_OBJECT (scale), "value-pos");
836 * gtk_scale_get_value_pos:
837 * @scale: a #GtkScale
839 * Gets the position in which the current value is displayed.
841 * Returns: the position in which the current value is displayed
844 gtk_scale_get_value_pos (GtkScale *scale)
846 g_return_val_if_fail (GTK_IS_SCALE (scale), 0);
848 return scale->priv->value_pos;
852 gtk_scale_get_range_border (GtkRange *range,
855 GtkScalePrivate *priv;
860 widget = GTK_WIDGET (range);
861 scale = GTK_SCALE (range);
864 _gtk_scale_get_value_size (scale, &w, &h);
871 if (priv->draw_value)
874 gtk_widget_style_get (widget, "value-spacing", &value_spacing, NULL);
876 switch (priv->value_pos)
879 border->left += w + value_spacing;
882 border->right += w + value_spacing;
885 border->top += h + value_spacing;
888 border->bottom += h + value_spacing;
897 gint n1, w1, h1, n2, w2, h2;
899 gtk_widget_style_get (widget,
900 "slider-width", &slider_width,
901 "value-spacing", &value_spacing,
905 gtk_scale_get_mark_label_size (scale, GTK_POS_TOP, &n1, &w1, &h1, &n2, &w2, &h2);
907 if (gtk_orientable_get_orientation (GTK_ORIENTABLE (scale)) == GTK_ORIENTATION_HORIZONTAL)
910 border->top += h1 + value_spacing + slider_width / 2;
912 border->bottom += h2 + value_spacing + slider_width / 2;
917 border->left += w1 + value_spacing + slider_width / 2;
919 border->right += w2 + value_spacing + slider_width / 2;
924 /* FIXME this could actually be static at the moment. */
926 _gtk_scale_get_value_size (GtkScale *scale,
930 GtkScalePrivate *priv = scale->priv;
933 if (priv->draw_value)
935 GtkAdjustment *adjustment;
937 PangoRectangle logical_rect;
940 range = GTK_RANGE (scale);
942 layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL);
943 adjustment = gtk_range_get_adjustment (range);
945 txt = _gtk_scale_format_value (scale, gtk_adjustment_get_lower (adjustment));
946 pango_layout_set_text (layout, txt, -1);
949 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
952 *width = logical_rect.width;
954 *height = logical_rect.height;
956 txt = _gtk_scale_format_value (scale, gtk_adjustment_get_upper (adjustment));
957 pango_layout_set_text (layout, txt, -1);
960 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
963 *width = MAX (*width, logical_rect.width);
965 *height = MAX (*height, logical_rect.height);
967 g_object_unref (layout);
980 gtk_scale_get_mark_label_size (GtkScale *scale,
981 GtkPositionType position,
989 GtkScalePrivate *priv = scale->priv;
991 PangoRectangle logical_rect;
995 *count1 = *count2 = 0;
996 *width1 = *width2 = 0;
997 *height1 = *height2 = 0;
999 layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL);
1001 for (m = priv->marks; m; m = m->next)
1003 GtkScaleMark *mark = m->data;
1005 if (mark->markup && *mark->markup)
1007 pango_layout_set_markup (layout, mark->markup, -1);
1008 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1010 w = logical_rect.width;
1011 h = logical_rect.height;
1019 if (mark->position == position)
1022 *width1 = MAX (*width1, w);
1023 *height1 = MAX (*height1, h);
1028 *width2 = MAX (*width2, w);
1029 *height2 = MAX (*height2, h);
1033 g_object_unref (layout);
1037 gtk_scale_style_updated (GtkWidget *widget)
1039 gtk_scale_update_style (GTK_SCALE (widget));
1041 GTK_WIDGET_CLASS (gtk_scale_parent_class)->style_updated (widget);
1045 gtk_scale_screen_changed (GtkWidget *widget,
1046 GdkScreen *old_screen)
1048 _gtk_scale_clear_layout (GTK_SCALE (widget));
1052 gtk_scale_get_preferred_width (GtkWidget *widget,
1056 GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_width (widget, minimum, natural);
1058 if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL)
1060 gint n1, w1, h1, n2, w2, h2;
1064 gtk_widget_style_get (widget, "slider-length", &slider_length, NULL);
1066 gtk_scale_get_mark_label_size (GTK_SCALE (widget), GTK_POS_TOP, &n1, &w1, &h1, &n2, &w2, &h2);
1068 w1 = (n1 - 1) * w1 + MAX (w1, slider_length);
1069 w2 = (n2 - 1) * w2 + MAX (w2, slider_length);
1072 *minimum = MAX (*minimum, w);
1073 *natural = MAX (*natural, w);
1078 gtk_scale_get_preferred_height (GtkWidget *widget,
1082 GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_height (widget, minimum, natural);
1085 if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_VERTICAL)
1087 gint n1, w1, h1, n2, w2, h2;
1091 gtk_widget_style_get (widget, "slider-length", &slider_length, NULL);
1093 gtk_scale_get_mark_label_size (GTK_SCALE (widget), GTK_POS_TOP, &n1, &w1, &h1, &n2, &w2, &h2);
1094 h1 = (n1 - 1) * h1 + MAX (h1, slider_length);
1095 h2 = (n2 - 1) * h1 + MAX (h2, slider_length);
1098 *minimum = MAX (*minimum, h);
1099 *natural = MAX (*natural, h);
1104 find_next_pos (GtkWidget *widget,
1107 GtkPositionType pos)
1109 GtkAllocation allocation;
1113 for (m = list->next, i = 1; m; m = m->next, i++)
1115 GtkScaleMark *mark = m->data;
1117 if (mark->position == pos)
1121 gtk_widget_get_allocation (widget, &allocation);
1122 if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL)
1123 return allocation.width;
1125 return allocation.height;
1129 gtk_scale_draw (GtkWidget *widget,
1132 GtkScale *scale = GTK_SCALE (widget);
1133 GtkScalePrivate *priv = scale->priv;
1134 GtkRange *range = GTK_RANGE (scale);
1135 GtkStyleContext *context;
1142 context = gtk_widget_get_style_context (widget);
1143 gtk_widget_style_get (widget,
1144 "focus-padding", &focus_padding,
1145 "slider-width", &slider_width,
1146 "value-spacing", &value_spacing,
1149 /* We need to chain up _first_ so the various geometry members of
1150 * GtkRange struct are updated.
1152 GTK_WIDGET_CLASS (gtk_scale_parent_class)->draw (widget, cr);
1156 GtkOrientation orientation;
1157 GdkRectangle range_rect;
1159 gint x1, x2, x3, y1, y2, y3;
1160 PangoLayout *layout;
1161 PangoRectangle logical_rect;
1163 gint min_pos_before, min_pos_after;
1164 gint min_pos, max_pos;
1166 orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (range));
1167 _gtk_range_get_stop_positions (range, &marks);
1169 layout = gtk_widget_create_pango_layout (widget, NULL);
1170 gtk_range_get_range_rect (range, &range_rect);
1172 min_pos_before = min_pos_after = 0;
1174 for (m = priv->marks, i = 0; m; m = m->next, i++)
1176 GtkScaleMark *mark = m->data;
1178 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1181 if (mark->position == GTK_POS_TOP)
1184 y2 = y1 - slider_width / 2;
1185 min_pos = min_pos_before;
1186 max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep;
1190 y1 = range_rect.y + range_rect.height;
1191 y2 = y1 + slider_width / 2;
1192 min_pos = min_pos_after;
1193 max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep;
1196 gtk_style_context_save (context);
1197 gtk_style_context_add_class (context, GTK_STYLE_CLASS_MARK);
1199 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SEPARATOR);
1200 gtk_render_line (context, cr, x1, y1, x1, y2);
1201 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SEPARATOR);
1205 pango_layout_set_markup (layout, mark->markup, -1);
1206 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1208 x3 = x1 - logical_rect.width / 2;
1211 if (x3 + logical_rect.width > max_pos)
1212 x3 = max_pos - logical_rect.width;
1215 if (mark->position == GTK_POS_TOP)
1217 y3 = y2 - value_spacing - logical_rect.height;
1218 min_pos_before = x3 + logical_rect.width + min_sep;
1222 y3 = y2 + value_spacing;
1223 min_pos_after = x3 + logical_rect.width + min_sep;
1226 gtk_render_layout (context, cr, x3, y3, layout);
1229 gtk_style_context_restore (context);
1233 if (mark->position == GTK_POS_TOP)
1236 x2 = range_rect.x - slider_width / 2;
1237 min_pos = min_pos_before;
1238 max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep;
1242 x1 = range_rect.x + range_rect.width;
1243 x2 = range_rect.x + range_rect.width + slider_width / 2;
1244 min_pos = min_pos_after;
1245 max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep;
1249 gtk_style_context_save (context);
1250 gtk_style_context_add_class (context, GTK_STYLE_CLASS_MARK);
1252 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SEPARATOR);
1253 gtk_render_line (context, cr, x1, y1, x2, y1);
1254 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SEPARATOR);
1258 pango_layout_set_markup (layout, mark->markup, -1);
1259 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1261 y3 = y1 - logical_rect.height / 2;
1264 if (y3 + logical_rect.height > max_pos)
1265 y3 = max_pos - logical_rect.height;
1268 if (mark->position == GTK_POS_TOP)
1270 x3 = x2 - value_spacing - logical_rect.width;
1271 min_pos_before = y3 + logical_rect.height + min_sep;
1275 x3 = x2 + value_spacing;
1276 min_pos_after = y3 + logical_rect.height + min_sep;
1279 gtk_render_layout (context, cr, x3, y3, layout);
1282 gtk_style_context_restore (context);
1286 g_object_unref (layout);
1290 if (priv->draw_value)
1292 GtkAllocation allocation;
1294 PangoLayout *layout;
1297 layout = gtk_scale_get_layout (scale);
1298 gtk_scale_get_layout_offsets (scale, &x, &y);
1299 gtk_widget_get_allocation (widget, &allocation);
1301 gtk_render_layout (context, cr,
1311 gtk_scale_real_get_layout_offsets (GtkScale *scale,
1315 GtkScalePrivate *priv = scale->priv;
1316 GtkAllocation allocation;
1317 GtkWidget *widget = GTK_WIDGET (scale);
1318 GtkRange *range = GTK_RANGE (widget);
1319 GdkRectangle range_rect;
1320 PangoLayout *layout = gtk_scale_get_layout (scale);
1321 PangoRectangle logical_rect;
1322 gint slider_start, slider_end;
1333 gtk_widget_style_get (widget, "value-spacing", &value_spacing, NULL);
1335 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1337 gtk_widget_get_allocation (widget, &allocation);
1338 gtk_range_get_range_rect (range, &range_rect);
1339 gtk_range_get_slider_range (range,
1343 if (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)) == GTK_ORIENTATION_HORIZONTAL)
1345 switch (priv->value_pos)
1348 *x = range_rect.x - value_spacing - logical_rect.width;
1349 *y = range_rect.y + (range_rect.height - logical_rect.height) / 2;
1353 *x = range_rect.x + range_rect.width + value_spacing;
1354 *y = range_rect.y + (range_rect.height - logical_rect.height) / 2;
1358 *x = slider_start + (slider_end - slider_start - logical_rect.width) / 2;
1359 *x = CLAMP (*x, 0, allocation.width - logical_rect.width);
1360 *y = range_rect.y - logical_rect.height - value_spacing;
1363 case GTK_POS_BOTTOM:
1364 *x = slider_start + (slider_end - slider_start - logical_rect.width) / 2;
1365 *x = CLAMP (*x, 0, allocation.width - logical_rect.width);
1366 *y = range_rect.y + range_rect.height + value_spacing;
1370 g_return_if_reached ();
1376 switch (priv->value_pos)
1379 *x = range_rect.x - logical_rect.width - value_spacing;
1380 *y = slider_start + (slider_end - slider_start - logical_rect.height) / 2;
1381 *y = CLAMP (*y, 0, allocation.height - logical_rect.height);
1385 *x = range_rect.x + range_rect.width + value_spacing;
1386 *y = slider_start + (slider_end - slider_start - logical_rect.height) / 2;
1387 *y = CLAMP (*y, 0, allocation.height - logical_rect.height);
1391 *x = range_rect.x + (range_rect.width - logical_rect.width) / 2;
1392 *y = range_rect.y - logical_rect.height - value_spacing;
1395 case GTK_POS_BOTTOM:
1396 *x = range_rect.x + (range_rect.width - logical_rect.width) / 2;
1397 *y = range_rect.y + range_rect.height + value_spacing;
1401 g_return_if_reached ();
1410 * _gtk_scale_format_value:
1411 * @scale: a #GtkScale
1412 * @value: adjustment value
1414 * Emits #GtkScale::format-value signal to format the value,
1415 * if no user signal handlers, falls back to a default format.
1417 * Return value: formatted value
1420 _gtk_scale_format_value (GtkScale *scale,
1423 GtkScalePrivate *priv = scale->priv;
1426 g_signal_emit (scale,
1427 signals[FORMAT_VALUE],
1435 return g_strdup_printf ("%0.*f", priv->digits, value);
1439 gtk_scale_finalize (GObject *object)
1441 GtkScale *scale = GTK_SCALE (object);
1443 _gtk_scale_clear_layout (scale);
1444 gtk_scale_clear_marks (scale);
1446 G_OBJECT_CLASS (gtk_scale_parent_class)->finalize (object);
1450 * gtk_scale_get_layout:
1451 * @scale: A #GtkScale
1453 * Gets the #PangoLayout used to display the scale. The returned
1454 * object is owned by the scale so does not need to be freed by
1457 * Return value: (transfer none): the #PangoLayout for this scale,
1458 * or %NULL if the #GtkScale:draw-value property is %FALSE.
1463 gtk_scale_get_layout (GtkScale *scale)
1465 GtkScalePrivate *priv;
1468 g_return_val_if_fail (GTK_IS_SCALE (scale), NULL);
1474 if (priv->draw_value)
1475 priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL);
1478 if (priv->draw_value)
1480 txt = _gtk_scale_format_value (scale,
1481 gtk_adjustment_get_value (gtk_range_get_adjustment (GTK_RANGE (scale))));
1482 pango_layout_set_text (priv->layout, txt, -1);
1486 return priv->layout;
1490 * gtk_scale_get_layout_offsets:
1491 * @scale: a #GtkScale
1492 * @x: (out) (allow-none): location to store X offset of layout, or %NULL
1493 * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
1495 * Obtains the coordinates where the scale will draw the
1496 * #PangoLayout representing the text in the scale. Remember
1497 * when using the #PangoLayout function you need to convert to
1498 * and from pixels using PANGO_PIXELS() or #PANGO_SCALE.
1500 * If the #GtkScale:draw-value property is %FALSE, the return
1501 * values are undefined.
1506 gtk_scale_get_layout_offsets (GtkScale *scale,
1513 g_return_if_fail (GTK_IS_SCALE (scale));
1515 if (GTK_SCALE_GET_CLASS (scale)->get_layout_offsets)
1516 (GTK_SCALE_GET_CLASS (scale)->get_layout_offsets) (scale, &local_x, &local_y);
1526 _gtk_scale_clear_layout (GtkScale *scale)
1528 GtkScalePrivate *priv = scale->priv;
1530 g_return_if_fail (GTK_IS_SCALE (scale));
1534 g_object_unref (priv->layout);
1535 priv->layout = NULL;
1540 gtk_scale_mark_free (gpointer data)
1542 GtkScaleMark *mark = data;
1544 g_free (mark->markup);
1549 * gtk_scale_clear_marks:
1550 * @scale: a #GtkScale
1552 * Removes any marks that have been added with gtk_scale_add_mark().
1557 gtk_scale_clear_marks (GtkScale *scale)
1559 GtkScalePrivate *priv;
1560 GtkStyleContext *context;
1562 g_return_if_fail (GTK_IS_SCALE (scale));
1566 g_slist_free_full (priv->marks, gtk_scale_mark_free);
1569 context = gtk_widget_get_style_context (GTK_WIDGET (scale));
1570 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
1571 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
1573 _gtk_range_set_stop_values (GTK_RANGE (scale), NULL, 0);
1575 gtk_widget_queue_resize (GTK_WIDGET (scale));
1579 * gtk_scale_add_mark:
1580 * @scale: a #GtkScale
1581 * @value: the value at which the mark is placed, must be between
1582 * the lower and upper limits of the scales' adjustment
1583 * @position: where to draw the mark. For a horizontal scale, #GTK_POS_TOP
1584 * and %GTK_POS_LEFT are drawn above the scale, anything else below.
1585 * For a vertical scale, #GTK_POS_LEFT and %GTK_POS_TOP are drawn to
1586 * the left of the scale, anything else to the right.
1587 * @markup: (allow-none): Text to be shown at the mark, using <link linkend="PangoMarkupFormat">Pango markup</link>, or %NULL
1590 * Adds a mark at @value.
1592 * A mark is indicated visually by drawing a tick mark next to the scale,
1593 * and GTK+ makes it easy for the user to position the scale exactly at the
1596 * If @markup is not %NULL, text is shown next to the tick mark.
1598 * To remove marks from a scale, use gtk_scale_clear_marks().
1603 gtk_scale_add_mark (GtkScale *scale,
1605 GtkPositionType position,
1606 const gchar *markup)
1608 GtkScalePrivate *priv;
1613 GtkStyleContext *context;
1616 g_return_if_fail (GTK_IS_SCALE (scale));
1620 mark = g_new (GtkScaleMark, 1);
1621 mark->value = value;
1622 mark->markup = g_strdup (markup);
1623 if (position == GTK_POS_LEFT ||
1624 position == GTK_POS_TOP)
1625 mark->position = GTK_POS_TOP;
1627 mark->position = GTK_POS_BOTTOM;
1629 priv->marks = g_slist_insert_sorted_with_data (priv->marks, mark,
1631 GINT_TO_POINTER (gtk_range_get_inverted (GTK_RANGE (scale))));
1633 #define MARKS_ABOVE 1
1634 #define MARKS_BELOW 2
1637 n = g_slist_length (priv->marks);
1638 values = g_new (gdouble, n);
1639 for (m = priv->marks, i = 0; m; m = m->next, i++)
1642 values[i] = mark->value;
1643 if (mark->position == GTK_POS_TOP)
1644 all_pos |= MARKS_ABOVE;
1646 all_pos |= MARKS_BELOW;
1649 _gtk_range_set_stop_values (GTK_RANGE (scale), values, n);
1653 /* Set the style classes for the slider, so it could
1654 * point to the right direction when marks are present
1656 context = gtk_widget_get_style_context (GTK_WIDGET (scale));
1658 if (all_pos & MARKS_ABOVE)
1659 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
1661 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
1662 if (all_pos & MARKS_BELOW)
1663 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
1665 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
1667 gtk_widget_queue_resize (GTK_WIDGET (scale));
1670 static GtkBuildableIface *parent_buildable_iface;
1673 gtk_scale_buildable_interface_init (GtkBuildableIface *iface)
1675 parent_buildable_iface = g_type_interface_peek_parent (iface);
1676 iface->custom_tag_start = gtk_scale_buildable_custom_tag_start;
1677 iface->custom_finished = gtk_scale_buildable_custom_finished;
1683 GtkBuilder *builder;
1685 } MarksSubparserData;
1690 GtkPositionType position;
1693 gboolean translatable;
1697 mark_data_free (MarkData *data)
1699 g_string_free (data->markup, TRUE);
1700 g_free (data->context);
1701 g_slice_free (MarkData, data);
1705 marks_start_element (GMarkupParseContext *context,
1706 const gchar *element_name,
1707 const gchar **names,
1708 const gchar **values,
1712 MarksSubparserData *parser_data = (MarksSubparserData*)user_data;
1714 gint line_number, char_number;
1716 if (strcmp (element_name, "marks") == 0)
1718 else if (strcmp (element_name, "mark") == 0)
1721 gboolean has_value = FALSE;
1722 GtkPositionType position = GTK_POS_BOTTOM;
1723 const gchar *msg_context = NULL;
1724 gboolean translatable = FALSE;
1727 for (i = 0; names[i]; i++)
1729 if (strcmp (names[i], "translatable") == 0)
1731 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
1734 else if (strcmp (names[i], "comments") == 0)
1736 /* do nothing, comments are for translators */
1738 else if (strcmp (names[i], "context") == 0)
1739 msg_context = values[i];
1740 else if (strcmp (names[i], "value") == 0)
1742 GValue gvalue = G_VALUE_INIT;
1744 if (!gtk_builder_value_from_string_type (parser_data->builder, G_TYPE_DOUBLE, values[i], &gvalue, error))
1747 value = g_value_get_double (&gvalue);
1750 else if (strcmp (names[i], "position") == 0)
1752 GValue gvalue = G_VALUE_INIT;
1754 if (!gtk_builder_value_from_string_type (parser_data->builder, GTK_TYPE_POSITION_TYPE, values[i], &gvalue, error))
1757 position = g_value_get_enum (&gvalue);
1761 g_markup_parse_context_get_position (context,
1766 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
1767 "%s:%d:%d '%s' is not a valid attribute of <%s>",
1769 line_number, char_number, names[i], "mark");
1776 g_markup_parse_context_get_position (context,
1781 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
1782 "%s:%d:%d <%s> requires attribute \"%s\"",
1784 line_number, char_number, "mark",
1789 mark = g_slice_new (MarkData);
1790 mark->value = value;
1791 if (position == GTK_POS_LEFT ||
1792 position == GTK_POS_TOP)
1793 mark->position = GTK_POS_TOP;
1795 mark->position = GTK_POS_BOTTOM;
1796 mark->markup = g_string_new ("");
1797 mark->context = g_strdup (msg_context);
1798 mark->translatable = translatable;
1800 parser_data->marks = g_slist_prepend (parser_data->marks, mark);
1804 g_markup_parse_context_get_position (context,
1809 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
1810 "%s:%d:%d unsupported tag for GtkScale: \"%s\"",
1812 line_number, char_number, element_name);
1818 marks_text (GMarkupParseContext *context,
1824 MarksSubparserData *data = (MarksSubparserData*)user_data;
1826 if (strcmp (g_markup_parse_context_get_element (context), "mark") == 0)
1828 MarkData *mark = data->marks->data;
1830 g_string_append_len (mark->markup, text, text_len);
1834 static const GMarkupParser marks_parser =
1836 marks_start_element,
1843 gtk_scale_buildable_custom_tag_start (GtkBuildable *buildable,
1844 GtkBuilder *builder,
1846 const gchar *tagname,
1847 GMarkupParser *parser,
1850 MarksSubparserData *parser_data;
1855 if (strcmp (tagname, "marks") == 0)
1857 parser_data = g_slice_new0 (MarksSubparserData);
1858 parser_data->scale = GTK_SCALE (buildable);
1859 parser_data->marks = NULL;
1861 *parser = marks_parser;
1862 *data = parser_data;
1866 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
1867 tagname, parser, data);
1871 gtk_scale_buildable_custom_finished (GtkBuildable *buildable,
1872 GtkBuilder *builder,
1874 const gchar *tagname,
1877 GtkScale *scale = GTK_SCALE (buildable);
1878 MarksSubparserData *marks_data;
1880 if (strcmp (tagname, "marks") == 0)
1885 marks_data = (MarksSubparserData *)user_data;
1887 for (m = marks_data->marks; m; m = m->next)
1889 MarkData *mdata = m->data;
1891 if (mdata->translatable && mdata->markup->len)
1892 markup = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
1894 mdata->markup->str);
1896 markup = mdata->markup->str;
1898 gtk_scale_add_mark (scale, mdata->value, mdata->position, markup);
1900 mark_data_free (mdata);
1903 g_slist_free (marks_data->marks);
1904 g_slice_free (MarksSubparserData, marks_data);