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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2004. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include <gdk/gdkkeysyms.h>
35 #include "gtkmarshalers.h"
36 #include "gtkorientable.h"
38 #include "gtkscrollbar.h"
39 #include "gtkprivate.h"
43 #define SCROLL_DELAY_FACTOR 5 /* Scroll repeat multiplier */
44 #define UPDATE_DELAY 300 /* Delay for queued update */
52 PROP_LOWER_STEPPER_SENSITIVITY,
53 PROP_UPPER_STEPPER_SENSITIVITY,
55 PROP_RESTRICT_TO_FILL_LEVEL,
75 MOUSE_WIDGET /* inside widget but not in any of the above GUI elements */
78 #define GTK_RANGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RANGE, GtkRangeLayout))
80 struct _GtkRangeLayout
82 /* These are in widget->window coordinates */
83 GdkRectangle stepper_a;
84 GdkRectangle stepper_b;
85 GdkRectangle stepper_c;
86 GdkRectangle stepper_d;
87 /* The trough rectangle is the area the thumb can slide in, not the
93 /* Layout-related state */
95 MouseLocation mouse_location;
96 /* last mouse coords we got, or -1 if mouse is outside the range */
100 /* "grabbed" mouse location, OUTSIDE for no grab */
101 MouseLocation grab_location;
102 guint grab_button : 8; /* 0 if none */
104 /* Stepper sensitivity */
105 guint lower_sensitive : 1;
106 guint upper_sensitive : 1;
109 guint show_fill_level : 1;
110 guint restrict_to_fill_level : 1;
112 GtkSensitivityType lower_sensitivity;
113 GtkSensitivityType upper_sensitivity;
118 GQuark slider_detail_quark;
119 GQuark stepper_detail_quark;
124 gboolean recalc_marks;
128 static void gtk_range_set_property (GObject *object,
132 static void gtk_range_get_property (GObject *object,
136 static void gtk_range_destroy (GtkObject *object);
137 static void gtk_range_size_request (GtkWidget *widget,
138 GtkRequisition *requisition);
139 static void gtk_range_size_allocate (GtkWidget *widget,
140 GtkAllocation *allocation);
141 static void gtk_range_realize (GtkWidget *widget);
142 static void gtk_range_unrealize (GtkWidget *widget);
143 static void gtk_range_map (GtkWidget *widget);
144 static void gtk_range_unmap (GtkWidget *widget);
145 static gboolean gtk_range_expose (GtkWidget *widget,
146 GdkEventExpose *event);
147 static gboolean gtk_range_button_press (GtkWidget *widget,
148 GdkEventButton *event);
149 static gboolean gtk_range_button_release (GtkWidget *widget,
150 GdkEventButton *event);
151 static gboolean gtk_range_motion_notify (GtkWidget *widget,
152 GdkEventMotion *event);
153 static gboolean gtk_range_enter_notify (GtkWidget *widget,
154 GdkEventCrossing *event);
155 static gboolean gtk_range_leave_notify (GtkWidget *widget,
156 GdkEventCrossing *event);
157 static gboolean gtk_range_grab_broken (GtkWidget *widget,
158 GdkEventGrabBroken *event);
159 static void gtk_range_grab_notify (GtkWidget *widget,
160 gboolean was_grabbed);
161 static void gtk_range_state_changed (GtkWidget *widget,
162 GtkStateType previous_state);
163 static gboolean gtk_range_scroll_event (GtkWidget *widget,
164 GdkEventScroll *event);
165 static void gtk_range_style_set (GtkWidget *widget,
166 GtkStyle *previous_style);
167 static void update_slider_position (GtkRange *range,
170 static void stop_scrolling (GtkRange *range);
174 static void gtk_range_move_slider (GtkRange *range,
175 GtkScrollType scroll);
178 static gboolean gtk_range_scroll (GtkRange *range,
179 GtkScrollType scroll);
180 static gboolean gtk_range_update_mouse_location (GtkRange *range);
181 static void gtk_range_calc_layout (GtkRange *range,
182 gdouble adjustment_value);
183 static void gtk_range_calc_marks (GtkRange *range);
184 static void gtk_range_get_props (GtkRange *range,
189 gint *stepper_spacing,
190 gboolean *trough_under_steppers,
191 gint *arrow_displacement_x,
192 gint *arrow_displacement_y);
193 static void gtk_range_calc_request (GtkRange *range,
198 gint stepper_spacing,
199 GdkRectangle *range_rect,
202 gboolean *has_steppers_ab,
203 gboolean *has_steppers_cd,
204 gint *slider_length_p);
205 static void gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
207 static void gtk_range_adjustment_changed (GtkAdjustment *adjustment,
209 static void gtk_range_add_step_timer (GtkRange *range,
211 static void gtk_range_remove_step_timer (GtkRange *range);
212 static void gtk_range_reset_update_timer (GtkRange *range);
213 static void gtk_range_remove_update_timer (GtkRange *range);
214 static GdkRectangle* get_area (GtkRange *range,
215 MouseLocation location);
216 static gboolean gtk_range_real_change_value (GtkRange *range,
217 GtkScrollType scroll,
219 static void gtk_range_update_value (GtkRange *range);
220 static gboolean gtk_range_key_press (GtkWidget *range,
224 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkRange, gtk_range, GTK_TYPE_WIDGET,
225 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
228 static guint signals[LAST_SIGNAL];
232 gtk_range_class_init (GtkRangeClass *class)
234 GObjectClass *gobject_class;
235 GtkObjectClass *object_class;
236 GtkWidgetClass *widget_class;
238 gobject_class = G_OBJECT_CLASS (class);
239 object_class = (GtkObjectClass*) class;
240 widget_class = (GtkWidgetClass*) class;
242 gobject_class->set_property = gtk_range_set_property;
243 gobject_class->get_property = gtk_range_get_property;
245 object_class->destroy = gtk_range_destroy;
247 widget_class->size_request = gtk_range_size_request;
248 widget_class->size_allocate = gtk_range_size_allocate;
249 widget_class->realize = gtk_range_realize;
250 widget_class->unrealize = gtk_range_unrealize;
251 widget_class->map = gtk_range_map;
252 widget_class->unmap = gtk_range_unmap;
253 widget_class->expose_event = gtk_range_expose;
254 widget_class->button_press_event = gtk_range_button_press;
255 widget_class->button_release_event = gtk_range_button_release;
256 widget_class->motion_notify_event = gtk_range_motion_notify;
257 widget_class->scroll_event = gtk_range_scroll_event;
258 widget_class->enter_notify_event = gtk_range_enter_notify;
259 widget_class->leave_notify_event = gtk_range_leave_notify;
260 widget_class->grab_broken_event = gtk_range_grab_broken;
261 widget_class->grab_notify = gtk_range_grab_notify;
262 widget_class->state_changed = gtk_range_state_changed;
263 widget_class->style_set = gtk_range_style_set;
264 widget_class->key_press_event = gtk_range_key_press;
266 class->move_slider = gtk_range_move_slider;
267 class->change_value = gtk_range_real_change_value;
269 class->slider_detail = "slider";
270 class->stepper_detail = "stepper";
273 * GtkRange::value-changed:
274 * @range: the #GtkRange
276 * Emitted when the range value changes.
278 signals[VALUE_CHANGED] =
279 g_signal_new (I_("value-changed"),
280 G_TYPE_FROM_CLASS (gobject_class),
282 G_STRUCT_OFFSET (GtkRangeClass, value_changed),
284 _gtk_marshal_VOID__VOID,
287 signals[ADJUST_BOUNDS] =
288 g_signal_new (I_("adjust-bounds"),
289 G_TYPE_FROM_CLASS (gobject_class),
291 G_STRUCT_OFFSET (GtkRangeClass, adjust_bounds),
293 _gtk_marshal_VOID__DOUBLE,
298 * GtkRange::move-slider:
299 * @range: the #GtkRange
300 * @step: how to move the slider
302 * Virtual function that moves the slider. Used for keybindings.
304 signals[MOVE_SLIDER] =
305 g_signal_new (I_("move-slider"),
306 G_TYPE_FROM_CLASS (gobject_class),
307 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
308 G_STRUCT_OFFSET (GtkRangeClass, move_slider),
310 _gtk_marshal_VOID__ENUM,
312 GTK_TYPE_SCROLL_TYPE);
315 * GtkRange::change-value:
316 * @range: the range that received the signal
317 * @scroll: the type of scroll action that was performed
318 * @value: the new value resulting from the scroll action
319 * @returns: %TRUE to prevent other handlers from being invoked for the
320 * signal, %FALSE to propagate the signal further
322 * The ::change-value signal is emitted when a scroll action is
323 * performed on a range. It allows an application to determine the
324 * type of scroll event that occurred and the resultant new value.
325 * The application can handle the event itself and return %TRUE to
326 * prevent further processing. Or, by returning %FALSE, it can pass
327 * the event to other handlers until the default GTK+ handler is
330 * The value parameter is unrounded. An application that overrides
331 * the ::change-value signal is responsible for clamping the value to
332 * the desired number of decimal digits; the default GTK+ handler
333 * clamps the value based on @range->round_digits.
335 * It is not possible to use delayed update policies in an overridden
336 * ::change-value handler.
340 signals[CHANGE_VALUE] =
341 g_signal_new (I_("change-value"),
342 G_TYPE_FROM_CLASS (gobject_class),
344 G_STRUCT_OFFSET (GtkRangeClass, change_value),
345 _gtk_boolean_handled_accumulator, NULL,
346 _gtk_marshal_BOOLEAN__ENUM_DOUBLE,
348 GTK_TYPE_SCROLL_TYPE,
351 g_object_class_override_property (gobject_class,
355 g_object_class_install_property (gobject_class,
357 g_param_spec_enum ("update-policy",
359 P_("How the range should be updated on the screen"),
360 GTK_TYPE_UPDATE_TYPE,
361 GTK_UPDATE_CONTINUOUS,
362 GTK_PARAM_READWRITE));
364 g_object_class_install_property (gobject_class,
366 g_param_spec_object ("adjustment",
368 P_("The GtkAdjustment that contains the current value of this range object"),
370 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
372 g_object_class_install_property (gobject_class,
374 g_param_spec_boolean ("inverted",
376 P_("Invert direction slider moves to increase range value"),
378 GTK_PARAM_READWRITE));
380 g_object_class_install_property (gobject_class,
381 PROP_LOWER_STEPPER_SENSITIVITY,
382 g_param_spec_enum ("lower-stepper-sensitivity",
383 P_("Lower stepper sensitivity"),
384 P_("The sensitivity policy for the stepper that points to the adjustment's lower side"),
385 GTK_TYPE_SENSITIVITY_TYPE,
386 GTK_SENSITIVITY_AUTO,
387 GTK_PARAM_READWRITE));
389 g_object_class_install_property (gobject_class,
390 PROP_UPPER_STEPPER_SENSITIVITY,
391 g_param_spec_enum ("upper-stepper-sensitivity",
392 P_("Upper stepper sensitivity"),
393 P_("The sensitivity policy for the stepper that points to the adjustment's upper side"),
394 GTK_TYPE_SENSITIVITY_TYPE,
395 GTK_SENSITIVITY_AUTO,
396 GTK_PARAM_READWRITE));
399 * GtkRange:show-fill-level:
401 * The show-fill-level property controls whether fill level indicator
402 * graphics are displayed on the trough. See
403 * gtk_range_set_show_fill_level().
407 g_object_class_install_property (gobject_class,
408 PROP_SHOW_FILL_LEVEL,
409 g_param_spec_boolean ("show-fill-level",
410 P_("Show Fill Level"),
411 P_("Whether to display a fill level indicator graphics on trough."),
413 GTK_PARAM_READWRITE));
416 * GtkRange:restrict-to-fill-level:
418 * The restrict-to-fill-level property controls whether slider
419 * movement is restricted to an upper boundary set by the
420 * fill level. See gtk_range_set_restrict_to_fill_level().
424 g_object_class_install_property (gobject_class,
425 PROP_RESTRICT_TO_FILL_LEVEL,
426 g_param_spec_boolean ("restrict-to-fill-level",
427 P_("Restrict to Fill Level"),
428 P_("Whether to restrict the upper boundary to the fill level."),
430 GTK_PARAM_READWRITE));
433 * GtkRange:fill-level:
435 * The fill level (e.g. prebuffering of a network stream).
436 * See gtk_range_set_fill_level().
440 g_object_class_install_property (gobject_class,
442 g_param_spec_double ("fill-level",
444 P_("The fill level."),
448 GTK_PARAM_READWRITE));
450 gtk_widget_class_install_style_property (widget_class,
451 g_param_spec_int ("slider-width",
453 P_("Width of scrollbar or scale thumb"),
457 GTK_PARAM_READABLE));
458 gtk_widget_class_install_style_property (widget_class,
459 g_param_spec_int ("trough-border",
461 P_("Spacing between thumb/steppers and outer trough bevel"),
465 GTK_PARAM_READABLE));
466 gtk_widget_class_install_style_property (widget_class,
467 g_param_spec_int ("stepper-size",
469 P_("Length of step buttons at ends"),
473 GTK_PARAM_READABLE));
475 * GtkRange:stepper-spacing:
477 * The spacing between the stepper buttons and thumb. Note that
478 * setting this value to anything > 0 will automatically set the
479 * trough-under-steppers style property to %TRUE as well. Also,
480 * stepper-spacing won't have any effect if there are no steppers.
482 gtk_widget_class_install_style_property (widget_class,
483 g_param_spec_int ("stepper-spacing",
484 P_("Stepper Spacing"),
485 P_("Spacing between step buttons and thumb"),
489 GTK_PARAM_READABLE));
490 gtk_widget_class_install_style_property (widget_class,
491 g_param_spec_int ("arrow-displacement-x",
492 P_("Arrow X Displacement"),
493 P_("How far in the x direction to move the arrow when the button is depressed"),
497 GTK_PARAM_READABLE));
498 gtk_widget_class_install_style_property (widget_class,
499 g_param_spec_int ("arrow-displacement-y",
500 P_("Arrow Y Displacement"),
501 P_("How far in the y direction to move the arrow when the button is depressed"),
505 GTK_PARAM_READABLE));
507 gtk_widget_class_install_style_property (widget_class,
508 g_param_spec_boolean ("activate-slider",
509 P_("Draw slider ACTIVE during drag"),
510 P_("With this option set to TRUE, sliders will be drawn ACTIVE and with shadow IN while they are dragged"),
512 GTK_PARAM_READABLE));
515 * GtkRange:trough-side-details:
517 * When %TRUE, the parts of the trough on the two sides of the
518 * slider are drawn with different details.
522 gtk_widget_class_install_style_property (widget_class,
523 g_param_spec_boolean ("trough-side-details",
524 P_("Trough Side Details"),
525 P_("When TRUE, the parts of the trough on the two sides of the slider are drawn with different details"),
527 GTK_PARAM_READABLE));
530 * GtkRange:trough-under-steppers:
532 * Whether to draw the trough across the full length of the range or
533 * to exclude the steppers and their spacing. Note that setting the
534 * #GtkRange:stepper-spacing style property to any value > 0 will
535 * automatically enable trough-under-steppers too.
539 gtk_widget_class_install_style_property (widget_class,
540 g_param_spec_boolean ("trough-under-steppers",
541 P_("Trough Under Steppers"),
542 P_("Whether to draw trough for full length of range or exclude the steppers and spacing"),
544 GTK_PARAM_READABLE));
547 * GtkRange:arrow-scaling:
549 * The arrow size proportion relative to the scroll button size.
553 gtk_widget_class_install_style_property (widget_class,
554 g_param_spec_float ("arrow-scaling",
556 P_("Arrow scaling with regard to scroll button size"),
558 GTK_PARAM_READABLE));
560 g_type_class_add_private (class, sizeof (GtkRangeLayout));
564 gtk_range_set_property (GObject *object,
569 GtkRange *range = GTK_RANGE (object);
573 case PROP_ORIENTATION:
574 range->orientation = g_value_get_enum (value);
576 range->layout->slider_detail_quark = 0;
577 range->layout->stepper_detail_quark = 0;
579 gtk_widget_queue_resize (GTK_WIDGET (range));
581 case PROP_UPDATE_POLICY:
582 gtk_range_set_update_policy (range, g_value_get_enum (value));
584 case PROP_ADJUSTMENT:
585 gtk_range_set_adjustment (range, g_value_get_object (value));
588 gtk_range_set_inverted (range, g_value_get_boolean (value));
590 case PROP_LOWER_STEPPER_SENSITIVITY:
591 gtk_range_set_lower_stepper_sensitivity (range, g_value_get_enum (value));
593 case PROP_UPPER_STEPPER_SENSITIVITY:
594 gtk_range_set_upper_stepper_sensitivity (range, g_value_get_enum (value));
596 case PROP_SHOW_FILL_LEVEL:
597 gtk_range_set_show_fill_level (range, g_value_get_boolean (value));
599 case PROP_RESTRICT_TO_FILL_LEVEL:
600 gtk_range_set_restrict_to_fill_level (range, g_value_get_boolean (value));
602 case PROP_FILL_LEVEL:
603 gtk_range_set_fill_level (range, g_value_get_double (value));
606 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
612 gtk_range_get_property (GObject *object,
617 GtkRange *range = GTK_RANGE (object);
621 case PROP_ORIENTATION:
622 g_value_set_enum (value, range->orientation);
624 case PROP_UPDATE_POLICY:
625 g_value_set_enum (value, range->update_policy);
627 case PROP_ADJUSTMENT:
628 g_value_set_object (value, range->adjustment);
631 g_value_set_boolean (value, range->inverted);
633 case PROP_LOWER_STEPPER_SENSITIVITY:
634 g_value_set_enum (value, gtk_range_get_lower_stepper_sensitivity (range));
636 case PROP_UPPER_STEPPER_SENSITIVITY:
637 g_value_set_enum (value, gtk_range_get_upper_stepper_sensitivity (range));
639 case PROP_SHOW_FILL_LEVEL:
640 g_value_set_boolean (value, gtk_range_get_show_fill_level (range));
642 case PROP_RESTRICT_TO_FILL_LEVEL:
643 g_value_set_boolean (value, gtk_range_get_restrict_to_fill_level (range));
645 case PROP_FILL_LEVEL:
646 g_value_set_double (value, gtk_range_get_fill_level (range));
649 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
655 gtk_range_init (GtkRange *range)
657 GTK_WIDGET_SET_FLAGS (range, GTK_NO_WINDOW);
659 range->orientation = GTK_ORIENTATION_HORIZONTAL;
660 range->adjustment = NULL;
661 range->update_policy = GTK_UPDATE_CONTINUOUS;
662 range->inverted = FALSE;
663 range->flippable = FALSE;
664 range->min_slider_size = 1;
665 range->has_stepper_a = FALSE;
666 range->has_stepper_b = FALSE;
667 range->has_stepper_c = FALSE;
668 range->has_stepper_d = FALSE;
669 range->need_recalc = TRUE;
670 range->round_digits = -1;
671 range->layout = GTK_RANGE_GET_PRIVATE (range);
672 range->layout->mouse_location = MOUSE_OUTSIDE;
673 range->layout->mouse_x = -1;
674 range->layout->mouse_y = -1;
675 range->layout->grab_location = MOUSE_OUTSIDE;
676 range->layout->grab_button = 0;
677 range->layout->lower_sensitivity = GTK_SENSITIVITY_AUTO;
678 range->layout->upper_sensitivity = GTK_SENSITIVITY_AUTO;
679 range->layout->lower_sensitive = TRUE;
680 range->layout->upper_sensitive = TRUE;
681 range->layout->show_fill_level = FALSE;
682 range->layout->restrict_to_fill_level = TRUE;
683 range->layout->fill_level = G_MAXDOUBLE;
688 * gtk_range_get_adjustment:
689 * @range: a #GtkRange
691 * Get the #GtkAdjustment which is the "model" object for #GtkRange.
692 * See gtk_range_set_adjustment() for details.
693 * The return value does not have a reference added, so should not
696 * Return value: a #GtkAdjustment
699 gtk_range_get_adjustment (GtkRange *range)
701 g_return_val_if_fail (GTK_IS_RANGE (range), NULL);
703 if (!range->adjustment)
704 gtk_range_set_adjustment (range, NULL);
706 return range->adjustment;
710 * gtk_range_set_update_policy:
711 * @range: a #GtkRange
712 * @policy: update policy
714 * Sets the update policy for the range. #GTK_UPDATE_CONTINUOUS means that
715 * anytime the range slider is moved, the range value will change and the
716 * value_changed signal will be emitted. #GTK_UPDATE_DELAYED means that
717 * the value will be updated after a brief timeout where no slider motion
718 * occurs, so updates are spaced by a short time rather than
719 * continuous. #GTK_UPDATE_DISCONTINUOUS means that the value will only
720 * be updated when the user releases the button and ends the slider
724 gtk_range_set_update_policy (GtkRange *range,
725 GtkUpdateType policy)
727 g_return_if_fail (GTK_IS_RANGE (range));
729 if (range->update_policy != policy)
731 range->update_policy = policy;
732 g_object_notify (G_OBJECT (range), "update-policy");
737 * gtk_range_get_update_policy:
738 * @range: a #GtkRange
740 * Gets the update policy of @range. See gtk_range_set_update_policy().
742 * Return value: the current update policy
745 gtk_range_get_update_policy (GtkRange *range)
747 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_UPDATE_CONTINUOUS);
749 return range->update_policy;
753 * gtk_range_set_adjustment:
754 * @range: a #GtkRange
755 * @adjustment: a #GtkAdjustment
757 * Sets the adjustment to be used as the "model" object for this range
758 * widget. The adjustment indicates the current range value, the
759 * minimum and maximum range values, the step/page increments used
760 * for keybindings and scrolling, and the page size. The page size
761 * is normally 0 for #GtkScale and nonzero for #GtkScrollbar, and
762 * indicates the size of the visible area of the widget being scrolled.
763 * The page size affects the size of the scrollbar slider.
766 gtk_range_set_adjustment (GtkRange *range,
767 GtkAdjustment *adjustment)
769 g_return_if_fail (GTK_IS_RANGE (range));
772 adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
774 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
776 if (range->adjustment != adjustment)
778 if (range->adjustment)
780 g_signal_handlers_disconnect_by_func (range->adjustment,
781 gtk_range_adjustment_changed,
783 g_signal_handlers_disconnect_by_func (range->adjustment,
784 gtk_range_adjustment_value_changed,
786 g_object_unref (range->adjustment);
789 range->adjustment = adjustment;
790 g_object_ref_sink (adjustment);
792 g_signal_connect (adjustment, "changed",
793 G_CALLBACK (gtk_range_adjustment_changed),
795 g_signal_connect (adjustment, "value-changed",
796 G_CALLBACK (gtk_range_adjustment_value_changed),
799 gtk_range_adjustment_changed (adjustment, range);
800 g_object_notify (G_OBJECT (range), "adjustment");
805 * gtk_range_set_inverted:
806 * @range: a #GtkRange
807 * @setting: %TRUE to invert the range
809 * Ranges normally move from lower to higher values as the
810 * slider moves from top to bottom or left to right. Inverted
811 * ranges have higher values at the top or on the right rather than
812 * on the bottom or left.
815 gtk_range_set_inverted (GtkRange *range,
818 g_return_if_fail (GTK_IS_RANGE (range));
820 setting = setting != FALSE;
822 if (setting != range->inverted)
824 range->inverted = setting;
825 g_object_notify (G_OBJECT (range), "inverted");
826 gtk_widget_queue_resize (GTK_WIDGET (range));
831 * gtk_range_get_inverted:
832 * @range: a #GtkRange
834 * Gets the value set by gtk_range_set_inverted().
836 * Return value: %TRUE if the range is inverted
839 gtk_range_get_inverted (GtkRange *range)
841 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
843 return range->inverted;
847 * gtk_range_set_lower_stepper_sensitivity:
848 * @range: a #GtkRange
849 * @sensitivity: the lower stepper's sensitivity policy.
851 * Sets the sensitivity policy for the stepper that points to the
852 * 'lower' end of the GtkRange's adjustment.
857 gtk_range_set_lower_stepper_sensitivity (GtkRange *range,
858 GtkSensitivityType sensitivity)
860 g_return_if_fail (GTK_IS_RANGE (range));
862 if (range->layout->lower_sensitivity != sensitivity)
864 range->layout->lower_sensitivity = sensitivity;
866 range->need_recalc = TRUE;
867 gtk_range_calc_layout (range, range->adjustment->value);
868 gtk_widget_queue_draw (GTK_WIDGET (range));
870 g_object_notify (G_OBJECT (range), "lower-stepper-sensitivity");
875 * gtk_range_get_lower_stepper_sensitivity:
876 * @range: a #GtkRange
878 * Gets the sensitivity policy for the stepper that points to the
879 * 'lower' end of the GtkRange's adjustment.
881 * Return value: The lower stepper's sensitivity policy.
886 gtk_range_get_lower_stepper_sensitivity (GtkRange *range)
888 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
890 return range->layout->lower_sensitivity;
894 * gtk_range_set_upper_stepper_sensitivity:
895 * @range: a #GtkRange
896 * @sensitivity: the upper stepper's sensitivity policy.
898 * Sets the sensitivity policy for the stepper that points to the
899 * 'upper' end of the GtkRange's adjustment.
904 gtk_range_set_upper_stepper_sensitivity (GtkRange *range,
905 GtkSensitivityType sensitivity)
907 g_return_if_fail (GTK_IS_RANGE (range));
909 if (range->layout->upper_sensitivity != sensitivity)
911 range->layout->upper_sensitivity = sensitivity;
913 range->need_recalc = TRUE;
914 gtk_range_calc_layout (range, range->adjustment->value);
915 gtk_widget_queue_draw (GTK_WIDGET (range));
917 g_object_notify (G_OBJECT (range), "upper-stepper-sensitivity");
922 * gtk_range_get_upper_stepper_sensitivity:
923 * @range: a #GtkRange
925 * Gets the sensitivity policy for the stepper that points to the
926 * 'upper' end of the GtkRange's adjustment.
928 * Return value: The upper stepper's sensitivity policy.
933 gtk_range_get_upper_stepper_sensitivity (GtkRange *range)
935 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
937 return range->layout->upper_sensitivity;
941 * gtk_range_set_increments:
942 * @range: a #GtkRange
946 * Sets the step and page sizes for the range.
947 * The step size is used when the user clicks the #GtkScrollbar
948 * arrows or moves #GtkScale via arrow keys. The page size
949 * is used for example when moving via Page Up or Page Down keys.
952 gtk_range_set_increments (GtkRange *range,
956 g_return_if_fail (GTK_IS_RANGE (range));
958 range->adjustment->step_increment = step;
959 range->adjustment->page_increment = page;
961 gtk_adjustment_changed (range->adjustment);
965 * gtk_range_set_range:
966 * @range: a #GtkRange
967 * @min: minimum range value
968 * @max: maximum range value
970 * Sets the allowable values in the #GtkRange, and clamps the range
971 * value to be between @min and @max. (If the range has a non-zero
972 * page size, it is clamped between @min and @max - page-size.)
975 gtk_range_set_range (GtkRange *range,
981 g_return_if_fail (GTK_IS_RANGE (range));
982 g_return_if_fail (min < max);
984 range->adjustment->lower = min;
985 range->adjustment->upper = max;
987 value = range->adjustment->value;
989 if (range->layout->restrict_to_fill_level)
990 value = MIN (value, MAX (range->adjustment->lower,
991 range->layout->fill_level));
993 gtk_adjustment_set_value (range->adjustment, value);
994 gtk_adjustment_changed (range->adjustment);
998 * gtk_range_set_value:
999 * @range: a #GtkRange
1000 * @value: new value of the range
1002 * Sets the current value of the range; if the value is outside the
1003 * minimum or maximum range values, it will be clamped to fit inside
1004 * them. The range emits the #GtkRange::value-changed signal if the
1008 gtk_range_set_value (GtkRange *range,
1011 g_return_if_fail (GTK_IS_RANGE (range));
1013 if (range->layout->restrict_to_fill_level)
1014 value = MIN (value, MAX (range->adjustment->lower,
1015 range->layout->fill_level));
1017 gtk_adjustment_set_value (range->adjustment, value);
1021 * gtk_range_get_value:
1022 * @range: a #GtkRange
1024 * Gets the current value of the range.
1026 * Return value: current value of the range.
1029 gtk_range_get_value (GtkRange *range)
1031 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1033 return range->adjustment->value;
1037 * gtk_range_set_show_fill_level:
1038 * @range: A #GtkRange
1039 * @show_fill_level: Whether a fill level indicator graphics is shown.
1041 * Sets whether a graphical fill level is show on the trough. See
1042 * gtk_range_set_fill_level() for a general description of the fill
1048 gtk_range_set_show_fill_level (GtkRange *range,
1049 gboolean show_fill_level)
1051 g_return_if_fail (GTK_IS_RANGE (range));
1053 show_fill_level = show_fill_level ? TRUE : FALSE;
1055 if (show_fill_level != range->layout->show_fill_level)
1057 range->layout->show_fill_level = show_fill_level;
1058 g_object_notify (G_OBJECT (range), "show-fill-level");
1059 gtk_widget_queue_draw (GTK_WIDGET (range));
1064 * gtk_range_get_show_fill_level:
1065 * @range: A #GtkRange
1067 * Gets whether the range displays the fill level graphically.
1069 * Return value: %TRUE if @range shows the fill level.
1074 gtk_range_get_show_fill_level (GtkRange *range)
1076 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1078 return range->layout->show_fill_level;
1082 * gtk_range_set_restrict_to_fill_level:
1083 * @range: A #GtkRange
1084 * @restrict_to_fill_level: Whether the fill level restricts slider movement.
1086 * Sets whether the slider is restricted to the fill level. See
1087 * gtk_range_set_fill_level() for a general description of the fill
1093 gtk_range_set_restrict_to_fill_level (GtkRange *range,
1094 gboolean restrict_to_fill_level)
1096 g_return_if_fail (GTK_IS_RANGE (range));
1098 restrict_to_fill_level = restrict_to_fill_level ? TRUE : FALSE;
1100 if (restrict_to_fill_level != range->layout->restrict_to_fill_level)
1102 range->layout->restrict_to_fill_level = restrict_to_fill_level;
1103 g_object_notify (G_OBJECT (range), "restrict-to-fill-level");
1105 gtk_range_set_value (range, gtk_range_get_value (range));
1110 * gtk_range_get_restrict_to_fill_level:
1111 * @range: A #GtkRange
1113 * Gets whether the range is restricted to the fill level.
1115 * Return value: %TRUE if @range is restricted to the fill level.
1120 gtk_range_get_restrict_to_fill_level (GtkRange *range)
1122 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1124 return range->layout->restrict_to_fill_level;
1128 * gtk_range_set_fill_level:
1129 * @range: a #GtkRange
1130 * @fill_level: the new position of the fill level indicator
1132 * Set the new position of the fill level indicator.
1134 * The "fill level" is probably best described by its most prominent
1135 * use case, which is an indicator for the amount of pre-buffering in
1136 * a streaming media player. In that use case, the value of the range
1137 * would indicate the current play position, and the fill level would
1138 * be the position up to which the file/stream has been downloaded.
1140 * This amount of prebuffering can be displayed on the range's trough
1141 * and is themeable separately from the trough. To enable fill level
1142 * display, use gtk_range_set_show_fill_level(). The range defaults
1143 * to not showing the fill level.
1145 * Additionally, it's possible to restrict the range's slider position
1146 * to values which are smaller than the fill level. This is controller
1147 * by gtk_range_set_restrict_to_fill_level() and is by default
1153 gtk_range_set_fill_level (GtkRange *range,
1156 g_return_if_fail (GTK_IS_RANGE (range));
1158 if (fill_level != range->layout->fill_level)
1160 range->layout->fill_level = fill_level;
1161 g_object_notify (G_OBJECT (range), "fill-level");
1163 if (range->layout->show_fill_level)
1164 gtk_widget_queue_draw (GTK_WIDGET (range));
1166 if (range->layout->restrict_to_fill_level)
1167 gtk_range_set_value (range, gtk_range_get_value (range));
1172 * gtk_range_get_fill_level:
1173 * @range : A #GtkRange
1175 * Gets the current position of the fill level indicator.
1177 * Return value: The current fill level
1182 gtk_range_get_fill_level (GtkRange *range)
1184 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1186 return range->layout->fill_level;
1190 should_invert (GtkRange *range)
1192 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1194 (range->inverted && !range->flippable) ||
1195 (range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_LTR) ||
1196 (!range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_RTL);
1198 return range->inverted;
1202 gtk_range_destroy (GtkObject *object)
1204 GtkRange *range = GTK_RANGE (object);
1206 gtk_range_remove_step_timer (range);
1207 gtk_range_remove_update_timer (range);
1209 if (range->layout->repaint_id)
1210 g_source_remove (range->layout->repaint_id);
1211 range->layout->repaint_id = 0;
1213 if (range->adjustment)
1215 g_signal_handlers_disconnect_by_func (range->adjustment,
1216 gtk_range_adjustment_changed,
1218 g_signal_handlers_disconnect_by_func (range->adjustment,
1219 gtk_range_adjustment_value_changed,
1221 g_object_unref (range->adjustment);
1222 range->adjustment = NULL;
1225 if (range->layout->n_marks)
1227 g_free (range->layout->marks);
1228 range->layout->marks = NULL;
1229 g_free (range->layout->mark_pos);
1230 range->layout->mark_pos = NULL;
1231 range->layout->n_marks = 0;
1234 GTK_OBJECT_CLASS (gtk_range_parent_class)->destroy (object);
1238 gtk_range_size_request (GtkWidget *widget,
1239 GtkRequisition *requisition)
1242 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
1243 GdkRectangle range_rect;
1246 range = GTK_RANGE (widget);
1248 gtk_range_get_props (range,
1249 &slider_width, &stepper_size,
1250 &focus_width, &trough_border,
1251 &stepper_spacing, NULL,
1254 gtk_range_calc_request (range,
1255 slider_width, stepper_size,
1256 focus_width, trough_border, stepper_spacing,
1257 &range_rect, &border, NULL, NULL, NULL, NULL);
1259 requisition->width = range_rect.width + border.left + border.right;
1260 requisition->height = range_rect.height + border.top + border.bottom;
1264 gtk_range_size_allocate (GtkWidget *widget,
1265 GtkAllocation *allocation)
1269 range = GTK_RANGE (widget);
1271 widget->allocation = *allocation;
1273 range->layout->recalc_marks = TRUE;
1275 range->need_recalc = TRUE;
1276 gtk_range_calc_layout (range, range->adjustment->value);
1278 if (GTK_WIDGET_REALIZED (range))
1279 gdk_window_move_resize (range->event_window,
1280 widget->allocation.x,
1281 widget->allocation.y,
1282 widget->allocation.width,
1283 widget->allocation.height);
1287 gtk_range_realize (GtkWidget *widget)
1290 GdkWindowAttr attributes;
1291 gint attributes_mask;
1293 range = GTK_RANGE (widget);
1295 gtk_range_calc_layout (range, range->adjustment->value);
1297 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1299 widget->window = gtk_widget_get_parent_window (widget);
1300 g_object_ref (widget->window);
1302 attributes.window_type = GDK_WINDOW_CHILD;
1303 attributes.x = widget->allocation.x;
1304 attributes.y = widget->allocation.y;
1305 attributes.width = widget->allocation.width;
1306 attributes.height = widget->allocation.height;
1307 attributes.wclass = GDK_INPUT_ONLY;
1308 attributes.event_mask = gtk_widget_get_events (widget);
1309 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1310 GDK_BUTTON_RELEASE_MASK |
1311 GDK_ENTER_NOTIFY_MASK |
1312 GDK_LEAVE_NOTIFY_MASK |
1313 GDK_POINTER_MOTION_MASK |
1314 GDK_POINTER_MOTION_HINT_MASK);
1316 attributes_mask = GDK_WA_X | GDK_WA_Y;
1318 range->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1319 &attributes, attributes_mask);
1320 gdk_window_set_user_data (range->event_window, range);
1322 widget->style = gtk_style_attach (widget->style, widget->window);
1326 gtk_range_unrealize (GtkWidget *widget)
1328 GtkRange *range = GTK_RANGE (widget);
1330 gtk_range_remove_step_timer (range);
1331 gtk_range_remove_update_timer (range);
1333 gdk_window_set_user_data (range->event_window, NULL);
1334 gdk_window_destroy (range->event_window);
1335 range->event_window = NULL;
1337 GTK_WIDGET_CLASS (gtk_range_parent_class)->unrealize (widget);
1341 gtk_range_map (GtkWidget *widget)
1343 GtkRange *range = GTK_RANGE (widget);
1345 gdk_window_show (range->event_window);
1347 GTK_WIDGET_CLASS (gtk_range_parent_class)->map (widget);
1351 gtk_range_unmap (GtkWidget *widget)
1353 GtkRange *range = GTK_RANGE (widget);
1355 stop_scrolling (range);
1357 gdk_window_hide (range->event_window);
1359 GTK_WIDGET_CLASS (gtk_range_parent_class)->unmap (widget);
1362 static const gchar *
1363 gtk_range_get_slider_detail (GtkRange *range)
1365 const gchar *slider_detail;
1367 if (range->layout->slider_detail_quark)
1368 return g_quark_to_string (range->layout->slider_detail_quark);
1370 slider_detail = GTK_RANGE_GET_CLASS (range)->slider_detail;
1372 if (slider_detail && slider_detail[0] == 'X')
1374 gchar *detail = g_strdup (slider_detail);
1376 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1378 range->layout->slider_detail_quark = g_quark_from_string (detail);
1382 return g_quark_to_string (range->layout->slider_detail_quark);
1385 return slider_detail;
1388 static const gchar *
1389 gtk_range_get_stepper_detail (GtkRange *range)
1391 const gchar *stepper_detail;
1393 if (range->layout->stepper_detail_quark)
1394 return g_quark_to_string (range->layout->stepper_detail_quark);
1396 stepper_detail = GTK_RANGE_GET_CLASS (range)->stepper_detail;
1398 if (stepper_detail && stepper_detail[0] == 'X')
1400 gchar *detail = g_strdup (stepper_detail);
1402 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1404 range->layout->stepper_detail_quark = g_quark_from_string (detail);
1408 return g_quark_to_string (range->layout->stepper_detail_quark);
1411 return stepper_detail;
1415 draw_stepper (GtkRange *range,
1417 GtkArrowType arrow_type,
1419 gboolean prelighted,
1422 GtkStateType state_type;
1423 GtkShadowType shadow_type;
1424 GdkRectangle intersection;
1425 GtkWidget *widget = GTK_WIDGET (range);
1426 gfloat arrow_scaling;
1433 gboolean arrow_sensitive = TRUE;
1435 /* More to get the right clip region than for efficiency */
1436 if (!gdk_rectangle_intersect (area, rect, &intersection))
1439 intersection.x += widget->allocation.x;
1440 intersection.y += widget->allocation.y;
1442 if ((!range->inverted && (arrow_type == GTK_ARROW_DOWN ||
1443 arrow_type == GTK_ARROW_RIGHT)) ||
1444 (range->inverted && (arrow_type == GTK_ARROW_UP ||
1445 arrow_type == GTK_ARROW_LEFT)))
1447 arrow_sensitive = range->layout->upper_sensitive;
1451 arrow_sensitive = range->layout->lower_sensitive;
1454 if (!GTK_WIDGET_IS_SENSITIVE (range) || !arrow_sensitive)
1455 state_type = GTK_STATE_INSENSITIVE;
1457 state_type = GTK_STATE_ACTIVE;
1458 else if (prelighted)
1459 state_type = GTK_STATE_PRELIGHT;
1461 state_type = GTK_STATE_NORMAL;
1463 if (clicked && arrow_sensitive)
1464 shadow_type = GTK_SHADOW_IN;
1466 shadow_type = GTK_SHADOW_OUT;
1468 gtk_paint_box (widget->style,
1470 state_type, shadow_type,
1471 &intersection, widget,
1472 gtk_range_get_stepper_detail (range),
1473 widget->allocation.x + rect->x,
1474 widget->allocation.y + rect->y,
1478 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
1480 arrow_width = rect->width * arrow_scaling;
1481 arrow_height = rect->height * arrow_scaling;
1482 arrow_x = widget->allocation.x + rect->x + (rect->width - arrow_width) / 2;
1483 arrow_y = widget->allocation.y + rect->y + (rect->height - arrow_height) / 2;
1485 if (clicked && arrow_sensitive)
1487 gint arrow_displacement_x;
1488 gint arrow_displacement_y;
1490 gtk_range_get_props (GTK_RANGE (widget),
1491 NULL, NULL, NULL, NULL, NULL, NULL,
1492 &arrow_displacement_x, &arrow_displacement_y);
1494 arrow_x += arrow_displacement_x;
1495 arrow_y += arrow_displacement_y;
1498 gtk_paint_arrow (widget->style,
1500 state_type, shadow_type,
1501 &intersection, widget,
1502 gtk_range_get_stepper_detail (range),
1505 arrow_x, arrow_y, arrow_width, arrow_height);
1509 gtk_range_expose (GtkWidget *widget,
1510 GdkEventExpose *event)
1512 GtkRange *range = GTK_RANGE (widget);
1515 GtkShadowType shadow_type;
1516 GdkRectangle expose_area; /* Relative to widget->allocation */
1518 gint focus_line_width = 0;
1519 gint focus_padding = 0;
1520 gboolean touchscreen;
1522 g_object_get (gtk_widget_get_settings (widget),
1523 "gtk-touchscreen-mode", &touchscreen,
1525 if (GTK_WIDGET_CAN_FOCUS (range))
1526 gtk_widget_style_get (GTK_WIDGET (range),
1527 "focus-line-width", &focus_line_width,
1528 "focus-padding", &focus_padding,
1531 /* we're now exposing, so there's no need to force early repaints */
1532 if (range->layout->repaint_id)
1533 g_source_remove (range->layout->repaint_id);
1534 range->layout->repaint_id = 0;
1536 expose_area = event->area;
1537 expose_area.x -= widget->allocation.x;
1538 expose_area.y -= widget->allocation.y;
1540 gtk_range_calc_marks (range);
1541 gtk_range_calc_layout (range, range->adjustment->value);
1543 sensitive = GTK_WIDGET_IS_SENSITIVE (widget);
1545 /* Just to be confusing, we draw the trough for the whole
1546 * range rectangle, not the trough rectangle (the trough
1547 * rectangle is just for hit detection)
1549 /* The gdk_rectangle_intersect is more to get the right
1550 * clip region (limited to range_rect) than for efficiency
1552 if (gdk_rectangle_intersect (&expose_area, &range->range_rect,
1555 gint x = (widget->allocation.x + range->range_rect.x +
1556 focus_line_width + focus_padding);
1557 gint y = (widget->allocation.y + range->range_rect.y +
1558 focus_line_width + focus_padding);
1559 gint width = (range->range_rect.width -
1560 2 * (focus_line_width + focus_padding));
1561 gint height = (range->range_rect.height -
1562 2 * (focus_line_width + focus_padding));
1563 gboolean trough_side_details;
1564 gboolean trough_under_steppers;
1566 gint stepper_spacing;
1568 area.x += widget->allocation.x;
1569 area.y += widget->allocation.y;
1571 gtk_widget_style_get (GTK_WIDGET (range),
1572 "trough-side-details", &trough_side_details,
1573 "trough-under-steppers", &trough_under_steppers,
1574 "stepper-size", &stepper_size,
1575 "stepper-spacing", &stepper_spacing,
1578 if (stepper_spacing > 0)
1579 trough_under_steppers = FALSE;
1581 if (! trough_under_steppers)
1586 if (range->has_stepper_a)
1587 offset += stepper_size;
1589 if (range->has_stepper_b)
1590 offset += stepper_size;
1594 if (range->has_stepper_c)
1595 shorter += stepper_size;
1597 if (range->has_stepper_d)
1598 shorter += stepper_size;
1600 if (range->has_stepper_a || range->has_stepper_b)
1602 offset += stepper_spacing;
1603 shorter += stepper_spacing;
1606 if (range->has_stepper_c || range->has_stepper_d)
1608 shorter += stepper_spacing;
1611 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1623 if (! trough_side_details)
1625 gtk_paint_box (widget->style,
1627 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1629 &area, GTK_WIDGET(range), "trough",
1635 gint trough_change_pos_x = width;
1636 gint trough_change_pos_y = height;
1638 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1639 trough_change_pos_x = (range->layout->slider.x +
1640 range->layout->slider.width / 2 -
1641 (x - widget->allocation.x));
1643 trough_change_pos_y = (range->layout->slider.y +
1644 range->layout->slider.height / 2 -
1645 (y - widget->allocation.y));
1647 gtk_paint_box (widget->style,
1649 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1651 &area, GTK_WIDGET (range),
1652 should_invert (range) ? "trough-upper" : "trough-lower",
1654 trough_change_pos_x, trough_change_pos_y);
1656 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1657 trough_change_pos_y = 0;
1659 trough_change_pos_x = 0;
1661 gtk_paint_box (widget->style,
1663 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1665 &area, GTK_WIDGET (range),
1666 should_invert (range) ? "trough-lower" : "trough-upper",
1667 x + trough_change_pos_x, y + trough_change_pos_y,
1668 width - trough_change_pos_x,
1669 height - trough_change_pos_y);
1672 if (range->layout->show_fill_level &&
1673 range->adjustment->upper - range->adjustment->page_size -
1674 range->adjustment->lower != 0)
1676 gdouble fill_level = range->layout->fill_level;
1679 gint fill_width = width;
1680 gint fill_height = height;
1683 fill_level = CLAMP (fill_level, range->adjustment->lower,
1684 range->adjustment->upper -
1685 range->adjustment->page_size);
1687 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1689 fill_x = widget->allocation.x + range->layout->trough.x;
1690 fill_width = (range->layout->slider.width +
1691 (fill_level - range->adjustment->lower) /
1692 (range->adjustment->upper -
1693 range->adjustment->lower -
1694 range->adjustment->page_size) *
1695 (range->layout->trough.width -
1696 range->layout->slider.width));
1698 if (should_invert (range))
1699 fill_x += range->layout->trough.width - fill_width;
1703 fill_y = widget->allocation.y + range->layout->trough.y;
1704 fill_height = (range->layout->slider.height +
1705 (fill_level - range->adjustment->lower) /
1706 (range->adjustment->upper -
1707 range->adjustment->lower -
1708 range->adjustment->page_size) *
1709 (range->layout->trough.height -
1710 range->layout->slider.height));
1712 if (should_invert (range))
1713 fill_y += range->layout->trough.height - fill_height;
1716 if (fill_level < range->adjustment->upper - range->adjustment->page_size)
1717 fill_detail = "trough-fill-level-full";
1719 fill_detail = "trough-fill-level";
1721 gtk_paint_box (widget->style,
1723 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1725 &area, GTK_WIDGET (range), fill_detail,
1727 fill_width, fill_height);
1731 GTK_WIDGET_HAS_FOCUS (range))
1732 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
1733 &area, widget, "trough",
1734 widget->allocation.x + range->range_rect.x,
1735 widget->allocation.y + range->range_rect.y,
1736 range->range_rect.width,
1737 range->range_rect.height);
1740 shadow_type = GTK_SHADOW_OUT;
1743 state = GTK_STATE_INSENSITIVE;
1744 else if (!touchscreen && range->layout->mouse_location == MOUSE_SLIDER)
1745 state = GTK_STATE_PRELIGHT;
1747 state = GTK_STATE_NORMAL;
1749 if (range->layout->grab_location == MOUSE_SLIDER)
1751 gboolean activate_slider;
1753 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
1755 if (activate_slider)
1757 state = GTK_STATE_ACTIVE;
1758 shadow_type = GTK_SHADOW_IN;
1762 if (gdk_rectangle_intersect (&expose_area,
1763 &range->layout->slider,
1766 area.x += widget->allocation.x;
1767 area.y += widget->allocation.y;
1769 gtk_paint_slider (widget->style,
1775 gtk_range_get_slider_detail (range),
1776 widget->allocation.x + range->layout->slider.x,
1777 widget->allocation.y + range->layout->slider.y,
1778 range->layout->slider.width,
1779 range->layout->slider.height,
1780 range->orientation);
1783 if (range->has_stepper_a)
1784 draw_stepper (range, &range->layout->stepper_a,
1785 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
1786 range->layout->grab_location == MOUSE_STEPPER_A,
1787 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_A,
1790 if (range->has_stepper_b)
1791 draw_stepper (range, &range->layout->stepper_b,
1792 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
1793 range->layout->grab_location == MOUSE_STEPPER_B,
1794 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_B,
1797 if (range->has_stepper_c)
1798 draw_stepper (range, &range->layout->stepper_c,
1799 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
1800 range->layout->grab_location == MOUSE_STEPPER_C,
1801 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_C,
1804 if (range->has_stepper_d)
1805 draw_stepper (range, &range->layout->stepper_d,
1806 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
1807 range->layout->grab_location == MOUSE_STEPPER_D,
1808 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_D,
1815 range_grab_add (GtkRange *range,
1816 MouseLocation location,
1819 /* we don't actually gtk_grab, since a button is down */
1821 gtk_grab_add (GTK_WIDGET (range));
1823 range->layout->grab_location = location;
1824 range->layout->grab_button = button;
1826 if (gtk_range_update_mouse_location (range))
1827 gtk_widget_queue_draw (GTK_WIDGET (range));
1831 range_grab_remove (GtkRange *range)
1833 MouseLocation location;
1835 gtk_grab_remove (GTK_WIDGET (range));
1837 location = range->layout->grab_location;
1838 range->layout->grab_location = MOUSE_OUTSIDE;
1839 range->layout->grab_button = 0;
1841 if (gtk_range_update_mouse_location (range) ||
1842 location != MOUSE_OUTSIDE)
1843 gtk_widget_queue_draw (GTK_WIDGET (range));
1846 static GtkScrollType
1847 range_get_scroll_for_grab (GtkRange *range)
1851 invert = should_invert (range);
1852 switch (range->layout->grab_location)
1854 /* Backward stepper */
1855 case MOUSE_STEPPER_A:
1856 case MOUSE_STEPPER_C:
1857 switch (range->layout->grab_button)
1860 return invert ? GTK_SCROLL_STEP_FORWARD : GTK_SCROLL_STEP_BACKWARD;
1863 return invert ? GTK_SCROLL_PAGE_FORWARD : GTK_SCROLL_PAGE_BACKWARD;
1866 return invert ? GTK_SCROLL_END : GTK_SCROLL_START;
1871 /* Forward stepper */
1872 case MOUSE_STEPPER_B:
1873 case MOUSE_STEPPER_D:
1874 switch (range->layout->grab_button)
1877 return invert ? GTK_SCROLL_STEP_BACKWARD : GTK_SCROLL_STEP_FORWARD;
1880 return invert ? GTK_SCROLL_PAGE_BACKWARD : GTK_SCROLL_PAGE_FORWARD;
1883 return invert ? GTK_SCROLL_START : GTK_SCROLL_END;
1891 if (range->trough_click_forward)
1892 return GTK_SCROLL_PAGE_FORWARD;
1894 return GTK_SCROLL_PAGE_BACKWARD;
1904 return GTK_SCROLL_NONE;
1908 coord_to_value (GtkRange *range,
1917 gint trough_under_steppers;
1919 if (range->orientation == GTK_ORIENTATION_VERTICAL)
1921 trough_length = range->layout->trough.height;
1922 trough_start = range->layout->trough.y;
1923 slider_length = range->layout->slider.height;
1927 trough_length = range->layout->trough.width;
1928 trough_start = range->layout->trough.x;
1929 slider_length = range->layout->slider.width;
1932 gtk_range_get_props (range, NULL, NULL, NULL, &trough_border, NULL,
1933 &trough_under_steppers, NULL, NULL);
1935 if (! trough_under_steppers)
1937 trough_start += trough_border;
1938 trough_length -= 2 * trough_border;
1941 if (trough_length == slider_length)
1944 frac = (MAX (0, coord - trough_start) /
1945 (gdouble) (trough_length - slider_length));
1947 if (should_invert (range))
1950 value = range->adjustment->lower + frac * (range->adjustment->upper -
1951 range->adjustment->lower -
1952 range->adjustment->page_size);
1958 gtk_range_key_press (GtkWidget *widget,
1961 GtkRange *range = GTK_RANGE (widget);
1963 if (event->keyval == GDK_Escape &&
1964 range->layout->grab_location != MOUSE_OUTSIDE)
1966 stop_scrolling (range);
1968 update_slider_position (range,
1969 range->slide_initial_coordinate,
1970 range->slide_initial_coordinate);
1975 return GTK_WIDGET_CLASS (gtk_range_parent_class)->key_press_event (widget, event);
1979 gtk_range_button_press (GtkWidget *widget,
1980 GdkEventButton *event)
1982 GtkRange *range = GTK_RANGE (widget);
1984 if (!GTK_WIDGET_HAS_FOCUS (widget))
1985 gtk_widget_grab_focus (widget);
1987 /* ignore presses when we're already doing something else. */
1988 if (range->layout->grab_location != MOUSE_OUTSIDE)
1991 range->layout->mouse_x = event->x;
1992 range->layout->mouse_y = event->y;
1993 if (gtk_range_update_mouse_location (range))
1994 gtk_widget_queue_draw (widget);
1996 if (range->layout->mouse_location == MOUSE_TROUGH &&
1999 /* button 1 steps by page increment, as with button 2 on a stepper
2001 GtkScrollType scroll;
2002 gdouble click_value;
2004 click_value = coord_to_value (range,
2005 range->orientation == GTK_ORIENTATION_VERTICAL ?
2006 event->y : event->x);
2008 range->trough_click_forward = click_value > range->adjustment->value;
2009 range_grab_add (range, MOUSE_TROUGH, event->button);
2011 scroll = range_get_scroll_for_grab (range);
2013 gtk_range_add_step_timer (range, scroll);
2017 else if ((range->layout->mouse_location == MOUSE_STEPPER_A ||
2018 range->layout->mouse_location == MOUSE_STEPPER_B ||
2019 range->layout->mouse_location == MOUSE_STEPPER_C ||
2020 range->layout->mouse_location == MOUSE_STEPPER_D) &&
2021 (event->button == 1 || event->button == 2 || event->button == 3))
2023 GdkRectangle *stepper_area;
2024 GtkScrollType scroll;
2026 range_grab_add (range, range->layout->mouse_location, event->button);
2028 stepper_area = get_area (range, range->layout->mouse_location);
2029 gtk_widget_queue_draw_area (widget,
2030 widget->allocation.x + stepper_area->x,
2031 widget->allocation.y + stepper_area->y,
2032 stepper_area->width,
2033 stepper_area->height);
2035 scroll = range_get_scroll_for_grab (range);
2036 if (scroll != GTK_SCROLL_NONE)
2037 gtk_range_add_step_timer (range, scroll);
2041 else if ((range->layout->mouse_location == MOUSE_TROUGH &&
2042 event->button == 2) ||
2043 range->layout->mouse_location == MOUSE_SLIDER)
2045 gboolean need_value_update = FALSE;
2046 gboolean activate_slider;
2048 /* Any button can be used to drag the slider, but you can start
2049 * dragging the slider with a trough click using button 2;
2050 * On button 2 press, we warp the slider to mouse position,
2051 * then begin the slider drag.
2053 if (event->button == 2)
2055 gdouble slider_low_value, slider_high_value, new_value;
2058 coord_to_value (range,
2059 range->orientation == GTK_ORIENTATION_VERTICAL ?
2060 event->y : event->x);
2062 coord_to_value (range,
2063 range->orientation == GTK_ORIENTATION_VERTICAL ?
2064 event->y - range->layout->slider.height :
2065 event->x - range->layout->slider.width);
2067 /* compute new value for warped slider */
2068 new_value = slider_low_value + (slider_high_value - slider_low_value) / 2;
2070 /* recalc slider, so we can set slide_initial_slider_position
2073 range->need_recalc = TRUE;
2074 gtk_range_calc_layout (range, new_value);
2076 /* defer adjustment updates to update_slider_position() in order
2077 * to keep pixel quantisation
2079 need_value_update = TRUE;
2082 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2084 range->slide_initial_slider_position = range->layout->slider.y;
2085 range->slide_initial_coordinate = event->y;
2089 range->slide_initial_slider_position = range->layout->slider.x;
2090 range->slide_initial_coordinate = event->x;
2093 range_grab_add (range, MOUSE_SLIDER, event->button);
2095 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
2097 /* force a redraw, if the active slider is drawn differently to the
2100 if (activate_slider)
2101 gtk_widget_queue_draw (widget);
2103 if (need_value_update)
2104 update_slider_position (range, event->x, event->y);
2112 /* During a slide, move the slider as required given new mouse position */
2114 update_slider_position (GtkRange *range,
2127 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2128 delta = mouse_y - range->slide_initial_coordinate;
2130 delta = mouse_x - range->slide_initial_coordinate;
2132 c = range->slide_initial_slider_position + delta;
2134 new_value = coord_to_value (range, c);
2135 next_value = coord_to_value (range, c + 1);
2136 mark_delta = fabs (next_value - new_value);
2138 for (i = 0; i < range->layout->n_marks; i++)
2140 mark_value = range->layout->marks[i];
2142 if (fabs (range->adjustment->value - mark_value) < 3 * mark_delta)
2144 if (fabs (new_value - mark_value) < (range->slider_end - range->slider_start) * 0.5 * mark_delta)
2146 new_value = mark_value;
2152 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_JUMP, new_value,
2157 stop_scrolling (GtkRange *range)
2159 range_grab_remove (range);
2160 gtk_range_remove_step_timer (range);
2161 /* Flush any pending discontinuous/delayed updates */
2162 gtk_range_update_value (range);
2166 gtk_range_grab_broken (GtkWidget *widget,
2167 GdkEventGrabBroken *event)
2169 GtkRange *range = GTK_RANGE (widget);
2171 if (range->layout->grab_location != MOUSE_OUTSIDE)
2173 if (range->layout->grab_location == MOUSE_SLIDER)
2174 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2176 stop_scrolling (range);
2185 gtk_range_button_release (GtkWidget *widget,
2186 GdkEventButton *event)
2188 GtkRange *range = GTK_RANGE (widget);
2190 if (event->window == range->event_window)
2192 range->layout->mouse_x = event->x;
2193 range->layout->mouse_y = event->y;
2197 gdk_window_get_pointer (range->event_window,
2198 &range->layout->mouse_x,
2199 &range->layout->mouse_y,
2203 if (range->layout->grab_button == event->button)
2205 if (range->layout->grab_location == MOUSE_SLIDER)
2206 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2208 stop_scrolling (range);
2217 * _gtk_range_get_wheel_delta:
2218 * @range: a #GtkRange
2219 * @direction: A #GdkScrollDirection
2221 * Returns a good step value for the mouse wheel.
2223 * Return value: A good step value for the mouse wheel.
2228 _gtk_range_get_wheel_delta (GtkRange *range,
2229 GdkScrollDirection direction)
2231 GtkAdjustment *adj = range->adjustment;
2234 if (GTK_IS_SCROLLBAR (range))
2235 delta = pow (adj->page_size, 2.0 / 3.0);
2237 delta = adj->step_increment * 2;
2239 if (direction == GDK_SCROLL_UP ||
2240 direction == GDK_SCROLL_LEFT)
2243 if (range->inverted)
2250 gtk_range_scroll_event (GtkWidget *widget,
2251 GdkEventScroll *event)
2253 GtkRange *range = GTK_RANGE (widget);
2255 if (GTK_WIDGET_REALIZED (range))
2257 GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
2261 delta = _gtk_range_get_wheel_delta (range, event->direction);
2263 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2264 GTK_SCROLL_JUMP, adj->value + delta,
2267 /* Policy DELAYED makes sense with scroll events,
2268 * but DISCONTINUOUS doesn't, so we update immediately
2271 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
2272 gtk_range_update_value (range);
2279 gtk_range_motion_notify (GtkWidget *widget,
2280 GdkEventMotion *event)
2285 range = GTK_RANGE (widget);
2287 gdk_window_get_pointer (range->event_window, &x, &y, NULL);
2289 range->layout->mouse_x = x;
2290 range->layout->mouse_y = y;
2292 if (gtk_range_update_mouse_location (range))
2293 gtk_widget_queue_draw (widget);
2295 if (range->layout->grab_location == MOUSE_SLIDER)
2296 update_slider_position (range, x, y);
2298 /* We handled the event if the mouse was in the range_rect */
2299 return range->layout->mouse_location != MOUSE_OUTSIDE;
2303 gtk_range_enter_notify (GtkWidget *widget,
2304 GdkEventCrossing *event)
2306 GtkRange *range = GTK_RANGE (widget);
2308 range->layout->mouse_x = event->x;
2309 range->layout->mouse_y = event->y;
2311 if (gtk_range_update_mouse_location (range))
2312 gtk_widget_queue_draw (widget);
2318 gtk_range_leave_notify (GtkWidget *widget,
2319 GdkEventCrossing *event)
2321 GtkRange *range = GTK_RANGE (widget);
2323 range->layout->mouse_x = -1;
2324 range->layout->mouse_y = -1;
2326 if (gtk_range_update_mouse_location (range))
2327 gtk_widget_queue_draw (widget);
2333 gtk_range_grab_notify (GtkWidget *widget,
2334 gboolean was_grabbed)
2337 stop_scrolling (GTK_RANGE (widget));
2341 gtk_range_state_changed (GtkWidget *widget,
2342 GtkStateType previous_state)
2344 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2345 stop_scrolling (GTK_RANGE (widget));
2348 #define check_rectangle(rectangle1, rectangle2) \
2350 if (rectangle1.x != rectangle2.x) return TRUE; \
2351 if (rectangle1.y != rectangle2.y) return TRUE; \
2352 if (rectangle1.width != rectangle2.width) return TRUE; \
2353 if (rectangle1.height != rectangle2.height) return TRUE; \
2357 layout_changed (GtkRangeLayout *layout1,
2358 GtkRangeLayout *layout2)
2360 check_rectangle (layout1->slider, layout2->slider);
2361 check_rectangle (layout1->trough, layout2->trough);
2362 check_rectangle (layout1->stepper_a, layout2->stepper_a);
2363 check_rectangle (layout1->stepper_d, layout2->stepper_d);
2364 check_rectangle (layout1->stepper_b, layout2->stepper_b);
2365 check_rectangle (layout1->stepper_c, layout2->stepper_c);
2367 if (layout1->upper_sensitive != layout2->upper_sensitive) return TRUE;
2368 if (layout1->lower_sensitive != layout2->lower_sensitive) return TRUE;
2374 gtk_range_adjustment_changed (GtkAdjustment *adjustment,
2377 GtkRange *range = GTK_RANGE (data);
2378 /* create a copy of the layout */
2379 GtkRangeLayout layout = *range->layout;
2381 range->layout->recalc_marks = TRUE;
2382 range->need_recalc = TRUE;
2383 gtk_range_calc_layout (range, range->adjustment->value);
2385 /* now check whether the layout changed */
2386 if (layout_changed (range->layout, &layout))
2387 gtk_widget_queue_draw (GTK_WIDGET (range));
2389 /* Note that we don't round off to range->round_digits here.
2390 * that's because it's really broken to change a value
2391 * in response to a change signal on that value; round_digits
2392 * is therefore defined to be a filter on what the GtkRange
2393 * can input into the adjustment, not a filter that the GtkRange
2394 * will enforce on the adjustment.
2399 force_repaint (gpointer data)
2401 GtkRange *range = GTK_RANGE (data);
2402 range->layout->repaint_id = 0;
2403 if (GTK_WIDGET_DRAWABLE (range))
2404 gdk_window_process_updates (GTK_WIDGET (range)->window, FALSE);
2409 gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
2412 GtkRange *range = GTK_RANGE (data);
2413 /* create a copy of the layout */
2414 GtkRangeLayout layout = *range->layout;
2416 range->need_recalc = TRUE;
2417 gtk_range_calc_layout (range, range->adjustment->value);
2419 /* now check whether the layout changed */
2420 if (layout_changed (range->layout, &layout))
2422 gtk_widget_queue_draw (GTK_WIDGET (range));
2423 /* setup a timer to ensure the range isn't lagging too much behind the scroll position */
2424 if (!range->layout->repaint_id)
2425 range->layout->repaint_id = gdk_threads_add_timeout_full (GDK_PRIORITY_EVENTS, 181, force_repaint, range, NULL);
2428 /* Note that we don't round off to range->round_digits here.
2429 * that's because it's really broken to change a value
2430 * in response to a change signal on that value; round_digits
2431 * is therefore defined to be a filter on what the GtkRange
2432 * can input into the adjustment, not a filter that the GtkRange
2433 * will enforce on the adjustment.
2436 g_signal_emit (range, signals[VALUE_CHANGED], 0);
2440 gtk_range_style_set (GtkWidget *widget,
2441 GtkStyle *previous_style)
2443 GtkRange *range = GTK_RANGE (widget);
2445 range->need_recalc = TRUE;
2447 GTK_WIDGET_CLASS (gtk_range_parent_class)->style_set (widget, previous_style);
2451 apply_marks (GtkRange *range,
2458 for (i = 0; i < range->layout->n_marks; i++)
2460 mark = range->layout->marks[i];
2461 if ((oldval < mark && mark < *newval) ||
2462 (oldval > mark && mark > *newval))
2471 step_back (GtkRange *range)
2476 newval = range->adjustment->value - range->adjustment->step_increment;
2477 apply_marks (range, range->adjustment->value, &newval);
2478 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2479 GTK_SCROLL_STEP_BACKWARD, newval, &handled);
2483 step_forward (GtkRange *range)
2488 newval = range->adjustment->value + range->adjustment->step_increment;
2489 apply_marks (range, range->adjustment->value, &newval);
2490 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2491 GTK_SCROLL_STEP_FORWARD, newval, &handled);
2496 page_back (GtkRange *range)
2501 newval = range->adjustment->value - range->adjustment->page_increment;
2502 apply_marks (range, range->adjustment->value, &newval);
2503 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2504 GTK_SCROLL_PAGE_BACKWARD, newval, &handled);
2508 page_forward (GtkRange *range)
2513 newval = range->adjustment->value + range->adjustment->page_increment;
2514 apply_marks (range, range->adjustment->value, &newval);
2515 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2516 GTK_SCROLL_PAGE_FORWARD, newval, &handled);
2520 scroll_begin (GtkRange *range)
2523 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2524 GTK_SCROLL_START, range->adjustment->lower,
2529 scroll_end (GtkRange *range)
2534 newval = range->adjustment->upper - range->adjustment->page_size;
2535 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_END, newval,
2540 gtk_range_scroll (GtkRange *range,
2541 GtkScrollType scroll)
2543 gdouble old_value = range->adjustment->value;
2547 case GTK_SCROLL_STEP_LEFT:
2548 if (should_invert (range))
2549 step_forward (range);
2554 case GTK_SCROLL_STEP_UP:
2555 if (should_invert (range))
2556 step_forward (range);
2561 case GTK_SCROLL_STEP_RIGHT:
2562 if (should_invert (range))
2565 step_forward (range);
2568 case GTK_SCROLL_STEP_DOWN:
2569 if (should_invert (range))
2572 step_forward (range);
2575 case GTK_SCROLL_STEP_BACKWARD:
2579 case GTK_SCROLL_STEP_FORWARD:
2580 step_forward (range);
2583 case GTK_SCROLL_PAGE_LEFT:
2584 if (should_invert (range))
2585 page_forward (range);
2590 case GTK_SCROLL_PAGE_UP:
2591 if (should_invert (range))
2592 page_forward (range);
2597 case GTK_SCROLL_PAGE_RIGHT:
2598 if (should_invert (range))
2601 page_forward (range);
2604 case GTK_SCROLL_PAGE_DOWN:
2605 if (should_invert (range))
2608 page_forward (range);
2611 case GTK_SCROLL_PAGE_BACKWARD:
2615 case GTK_SCROLL_PAGE_FORWARD:
2616 page_forward (range);
2619 case GTK_SCROLL_START:
2620 scroll_begin (range);
2623 case GTK_SCROLL_END:
2627 case GTK_SCROLL_JUMP:
2628 /* Used by CList, range doesn't use it. */
2631 case GTK_SCROLL_NONE:
2635 return range->adjustment->value != old_value;
2639 gtk_range_move_slider (GtkRange *range,
2640 GtkScrollType scroll)
2642 gboolean cursor_only;
2644 g_object_get (gtk_widget_get_settings (GTK_WIDGET (range)),
2645 "gtk-keynav-cursor-only", &cursor_only,
2650 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (range));
2652 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
2654 if (scroll == GTK_SCROLL_STEP_UP ||
2655 scroll == GTK_SCROLL_STEP_DOWN)
2658 gtk_widget_child_focus (toplevel,
2659 scroll == GTK_SCROLL_STEP_UP ?
2660 GTK_DIR_UP : GTK_DIR_DOWN);
2666 if (scroll == GTK_SCROLL_STEP_LEFT ||
2667 scroll == GTK_SCROLL_STEP_RIGHT)
2670 gtk_widget_child_focus (toplevel,
2671 scroll == GTK_SCROLL_STEP_LEFT ?
2672 GTK_DIR_LEFT : GTK_DIR_RIGHT);
2678 if (! gtk_range_scroll (range, scroll))
2679 gtk_widget_error_bell (GTK_WIDGET (range));
2681 /* Policy DELAYED makes sense with key events,
2682 * but DISCONTINUOUS doesn't, so we update immediately
2685 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
2686 gtk_range_update_value (range);
2690 gtk_range_get_props (GtkRange *range,
2694 gint *trough_border,
2695 gint *stepper_spacing,
2696 gboolean *trough_under_steppers,
2697 gint *arrow_displacement_x,
2698 gint *arrow_displacement_y)
2700 GtkWidget *widget = GTK_WIDGET (range);
2701 gint tmp_slider_width, tmp_stepper_size, tmp_focus_width, tmp_trough_border;
2702 gint tmp_stepper_spacing, tmp_trough_under_steppers;
2703 gint tmp_arrow_displacement_x, tmp_arrow_displacement_y;
2705 gtk_widget_style_get (widget,
2706 "slider-width", &tmp_slider_width,
2707 "trough-border", &tmp_trough_border,
2708 "stepper-size", &tmp_stepper_size,
2709 "stepper-spacing", &tmp_stepper_spacing,
2710 "trough-under-steppers", &tmp_trough_under_steppers,
2711 "arrow-displacement-x", &tmp_arrow_displacement_x,
2712 "arrow-displacement-y", &tmp_arrow_displacement_y,
2715 if (tmp_stepper_spacing > 0)
2716 tmp_trough_under_steppers = FALSE;
2718 if (GTK_WIDGET_CAN_FOCUS (range))
2720 gint focus_line_width;
2723 gtk_widget_style_get (GTK_WIDGET (range),
2724 "focus-line-width", &focus_line_width,
2725 "focus-padding", &focus_padding,
2728 tmp_focus_width = focus_line_width + focus_padding;
2732 tmp_focus_width = 0;
2736 *slider_width = tmp_slider_width;
2739 *focus_width = tmp_focus_width;
2742 *trough_border = tmp_trough_border;
2745 *stepper_size = tmp_stepper_size;
2747 if (stepper_spacing)
2748 *stepper_spacing = tmp_stepper_spacing;
2750 if (trough_under_steppers)
2751 *trough_under_steppers = tmp_trough_under_steppers;
2753 if (arrow_displacement_x)
2754 *arrow_displacement_x = tmp_arrow_displacement_x;
2756 if (arrow_displacement_y)
2757 *arrow_displacement_y = tmp_arrow_displacement_y;
2760 #define POINT_IN_RECT(xcoord, ycoord, rect) \
2761 ((xcoord) >= (rect).x && \
2762 (xcoord) < ((rect).x + (rect).width) && \
2763 (ycoord) >= (rect).y && \
2764 (ycoord) < ((rect).y + (rect).height))
2766 /* Update mouse location, return TRUE if it changes */
2768 gtk_range_update_mouse_location (GtkRange *range)
2774 widget = GTK_WIDGET (range);
2776 old = range->layout->mouse_location;
2778 x = range->layout->mouse_x;
2779 y = range->layout->mouse_y;
2781 if (range->layout->grab_location != MOUSE_OUTSIDE)
2782 range->layout->mouse_location = range->layout->grab_location;
2783 else if (POINT_IN_RECT (x, y, range->layout->stepper_a))
2784 range->layout->mouse_location = MOUSE_STEPPER_A;
2785 else if (POINT_IN_RECT (x, y, range->layout->stepper_b))
2786 range->layout->mouse_location = MOUSE_STEPPER_B;
2787 else if (POINT_IN_RECT (x, y, range->layout->stepper_c))
2788 range->layout->mouse_location = MOUSE_STEPPER_C;
2789 else if (POINT_IN_RECT (x, y, range->layout->stepper_d))
2790 range->layout->mouse_location = MOUSE_STEPPER_D;
2791 else if (POINT_IN_RECT (x, y, range->layout->slider))
2792 range->layout->mouse_location = MOUSE_SLIDER;
2793 else if (POINT_IN_RECT (x, y, range->layout->trough))
2794 range->layout->mouse_location = MOUSE_TROUGH;
2795 else if (POINT_IN_RECT (x, y, widget->allocation))
2796 range->layout->mouse_location = MOUSE_WIDGET;
2798 range->layout->mouse_location = MOUSE_OUTSIDE;
2800 return old != range->layout->mouse_location;
2803 /* Clamp rect, border inside widget->allocation, such that we prefer
2804 * to take space from border not rect in all directions, and prefer to
2805 * give space to border over rect in one direction.
2808 clamp_dimensions (GtkWidget *widget,
2811 gboolean border_expands_horizontally)
2813 gint extra, shortage;
2815 g_return_if_fail (rect->x == 0);
2816 g_return_if_fail (rect->y == 0);
2817 g_return_if_fail (rect->width >= 0);
2818 g_return_if_fail (rect->height >= 0);
2822 extra = widget->allocation.width - border->left - border->right - rect->width;
2825 if (border_expands_horizontally)
2827 border->left += extra / 2;
2828 border->right += extra / 2 + extra % 2;
2832 rect->width += extra;
2836 /* See if we can fit rect, if not kill the border */
2837 shortage = rect->width - widget->allocation.width;
2840 rect->width = widget->allocation.width;
2841 /* lose the border */
2847 /* See if we can fit rect with borders */
2848 shortage = rect->width + border->left + border->right -
2849 widget->allocation.width;
2852 /* Shrink borders */
2853 border->left -= shortage / 2;
2854 border->right -= shortage / 2 + shortage % 2;
2860 extra = widget->allocation.height - border->top - border->bottom - rect->height;
2863 if (border_expands_horizontally)
2865 /* don't expand border vertically */
2866 rect->height += extra;
2870 border->top += extra / 2;
2871 border->bottom += extra / 2 + extra % 2;
2875 /* See if we can fit rect, if not kill the border */
2876 shortage = rect->height - widget->allocation.height;
2879 rect->height = widget->allocation.height;
2880 /* lose the border */
2886 /* See if we can fit rect with borders */
2887 shortage = rect->height + border->top + border->bottom -
2888 widget->allocation.height;
2891 /* Shrink borders */
2892 border->top -= shortage / 2;
2893 border->bottom -= shortage / 2 + shortage % 2;
2899 gtk_range_calc_request (GtkRange *range,
2904 gint stepper_spacing,
2905 GdkRectangle *range_rect,
2908 gboolean *has_steppers_ab,
2909 gboolean *has_steppers_cd,
2910 gint *slider_length_p)
2922 if (GTK_RANGE_GET_CLASS (range)->get_range_border)
2923 GTK_RANGE_GET_CLASS (range)->get_range_border (range, border);
2928 if (range->has_stepper_a)
2930 if (range->has_stepper_b)
2932 if (range->has_stepper_c)
2934 if (range->has_stepper_d)
2937 n_steppers = n_steppers_ab + n_steppers_cd;
2939 slider_length = range->min_slider_size;
2944 /* We never expand to fill available space in the small dimension
2945 * (i.e. vertical scrollbars are always a fixed width)
2947 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2949 range_rect->width = (focus_width + trough_border) * 2 + slider_width;
2950 range_rect->height = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
2952 if (n_steppers_ab > 0)
2953 range_rect->height += stepper_spacing;
2955 if (n_steppers_cd > 0)
2956 range_rect->height += stepper_spacing;
2960 range_rect->width = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
2961 range_rect->height = (focus_width + trough_border) * 2 + slider_width;
2963 if (n_steppers_ab > 0)
2964 range_rect->width += stepper_spacing;
2966 if (n_steppers_cd > 0)
2967 range_rect->width += stepper_spacing;
2971 *n_steppers_p = n_steppers;
2973 if (has_steppers_ab)
2974 *has_steppers_ab = (n_steppers_ab > 0);
2976 if (has_steppers_cd)
2977 *has_steppers_cd = (n_steppers_cd > 0);
2979 if (slider_length_p)
2980 *slider_length_p = slider_length;
2984 gtk_range_calc_layout (GtkRange *range,
2985 gdouble adjustment_value)
2987 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
2991 gboolean has_steppers_ab;
2992 gboolean has_steppers_cd;
2993 gboolean trough_under_steppers;
2994 GdkRectangle range_rect;
2995 GtkRangeLayout *layout;
2998 if (!range->need_recalc)
3001 /* If we have a too-small allocation, we prefer the steppers over
3002 * the trough/slider, probably the steppers are a more useful
3003 * feature in small spaces.
3005 * Also, we prefer to draw the range itself rather than the border
3006 * areas if there's a conflict, since the borders will be decoration
3007 * not controls. Though this depends on subclasses cooperating by
3008 * not drawing on range->range_rect.
3011 widget = GTK_WIDGET (range);
3012 layout = range->layout;
3014 gtk_range_get_props (range,
3015 &slider_width, &stepper_size,
3016 &focus_width, &trough_border,
3017 &stepper_spacing, &trough_under_steppers,
3020 gtk_range_calc_request (range,
3021 slider_width, stepper_size,
3022 focus_width, trough_border, stepper_spacing,
3023 &range_rect, &border, &n_steppers,
3024 &has_steppers_ab, &has_steppers_cd, &slider_length);
3026 /* We never expand to fill available space in the small dimension
3027 * (i.e. vertical scrollbars are always a fixed width)
3029 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3031 clamp_dimensions (widget, &range_rect, &border, TRUE);
3035 clamp_dimensions (widget, &range_rect, &border, FALSE);
3038 range_rect.x = border.left;
3039 range_rect.y = border.top;
3041 range->range_rect = range_rect;
3043 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3045 gint stepper_width, stepper_height;
3047 /* Steppers are the width of the range, and stepper_size in
3048 * height, or if we don't have enough height, divided equally
3049 * among available space.
3051 stepper_width = range_rect.width - focus_width * 2;
3053 if (trough_under_steppers)
3054 stepper_width -= trough_border * 2;
3056 if (stepper_width < 1)
3057 stepper_width = range_rect.width; /* screw the trough border */
3059 if (n_steppers == 0)
3060 stepper_height = 0; /* avoid divide by n_steppers */
3062 stepper_height = MIN (stepper_size, (range_rect.height / n_steppers));
3066 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3067 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3069 if (range->has_stepper_a)
3071 layout->stepper_a.width = stepper_width;
3072 layout->stepper_a.height = stepper_height;
3076 layout->stepper_a.width = 0;
3077 layout->stepper_a.height = 0;
3082 layout->stepper_b.x = layout->stepper_a.x;
3083 layout->stepper_b.y = layout->stepper_a.y + layout->stepper_a.height;
3085 if (range->has_stepper_b)
3087 layout->stepper_b.width = stepper_width;
3088 layout->stepper_b.height = stepper_height;
3092 layout->stepper_b.width = 0;
3093 layout->stepper_b.height = 0;
3098 if (range->has_stepper_d)
3100 layout->stepper_d.width = stepper_width;
3101 layout->stepper_d.height = stepper_height;
3105 layout->stepper_d.width = 0;
3106 layout->stepper_d.height = 0;
3109 layout->stepper_d.x = layout->stepper_a.x;
3110 layout->stepper_d.y = range_rect.y + range_rect.height - layout->stepper_d.height - focus_width - trough_border * trough_under_steppers;
3114 if (range->has_stepper_c)
3116 layout->stepper_c.width = stepper_width;
3117 layout->stepper_c.height = stepper_height;
3121 layout->stepper_c.width = 0;
3122 layout->stepper_c.height = 0;
3125 layout->stepper_c.x = layout->stepper_a.x;
3126 layout->stepper_c.y = layout->stepper_d.y - layout->stepper_c.height;
3128 /* Now the trough is the remaining space between steppers B and C,
3129 * if any, minus spacing
3131 layout->trough.x = range_rect.x;
3132 layout->trough.y = layout->stepper_b.y + layout->stepper_b.height + stepper_spacing * has_steppers_ab;
3133 layout->trough.width = range_rect.width;
3134 layout->trough.height = layout->stepper_c.y - layout->trough.y - stepper_spacing * has_steppers_cd;
3136 /* Slider fits into the trough, with stepper_spacing on either side,
3137 * and the size/position based on the adjustment or fixed, depending.
3139 layout->slider.x = layout->trough.x + focus_width + trough_border;
3140 layout->slider.width = layout->trough.width - (focus_width + trough_border) * 2;
3142 /* Compute slider position/length */
3144 gint y, bottom, top, height;
3146 top = layout->trough.y;
3147 bottom = layout->trough.y + layout->trough.height;
3149 if (! trough_under_steppers)
3151 top += trough_border;
3152 bottom -= trough_border;
3155 /* slider height is the fraction (page_size /
3156 * total_adjustment_range) times the trough height in pixels
3159 if (range->adjustment->upper - range->adjustment->lower != 0)
3160 height = ((bottom - top) * (range->adjustment->page_size /
3161 (range->adjustment->upper - range->adjustment->lower)));
3163 height = range->min_slider_size;
3165 if (height < range->min_slider_size ||
3166 range->slider_size_fixed)
3167 height = range->min_slider_size;
3169 height = MIN (height, layout->trough.height);
3173 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3174 y += (bottom - top - height) * ((adjustment_value - range->adjustment->lower) /
3175 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3177 y = CLAMP (y, top, bottom);
3179 if (should_invert (range))
3180 y = bottom - (y - top + height);
3182 layout->slider.y = y;
3183 layout->slider.height = height;
3185 /* These are publically exported */
3186 range->slider_start = layout->slider.y;
3187 range->slider_end = layout->slider.y + layout->slider.height;
3192 gint stepper_width, stepper_height;
3194 /* Steppers are the height of the range, and stepper_size in
3195 * width, or if we don't have enough width, divided equally
3196 * among available space.
3198 stepper_height = range_rect.height + focus_width * 2;
3200 if (trough_under_steppers)
3201 stepper_height -= trough_border * 2;
3203 if (stepper_height < 1)
3204 stepper_height = range_rect.height; /* screw the trough border */
3206 if (n_steppers == 0)
3207 stepper_width = 0; /* avoid divide by n_steppers */
3209 stepper_width = MIN (stepper_size, (range_rect.width / n_steppers));
3213 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3214 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3216 if (range->has_stepper_a)
3218 layout->stepper_a.width = stepper_width;
3219 layout->stepper_a.height = stepper_height;
3223 layout->stepper_a.width = 0;
3224 layout->stepper_a.height = 0;
3229 layout->stepper_b.x = layout->stepper_a.x + layout->stepper_a.width;
3230 layout->stepper_b.y = layout->stepper_a.y;
3232 if (range->has_stepper_b)
3234 layout->stepper_b.width = stepper_width;
3235 layout->stepper_b.height = stepper_height;
3239 layout->stepper_b.width = 0;
3240 layout->stepper_b.height = 0;
3245 if (range->has_stepper_d)
3247 layout->stepper_d.width = stepper_width;
3248 layout->stepper_d.height = stepper_height;
3252 layout->stepper_d.width = 0;
3253 layout->stepper_d.height = 0;
3256 layout->stepper_d.x = range_rect.x + range_rect.width - layout->stepper_d.width - focus_width - trough_border * trough_under_steppers;
3257 layout->stepper_d.y = layout->stepper_a.y;
3262 if (range->has_stepper_c)
3264 layout->stepper_c.width = stepper_width;
3265 layout->stepper_c.height = stepper_height;
3269 layout->stepper_c.width = 0;
3270 layout->stepper_c.height = 0;
3273 layout->stepper_c.x = layout->stepper_d.x - layout->stepper_c.width;
3274 layout->stepper_c.y = layout->stepper_a.y;
3276 /* Now the trough is the remaining space between steppers B and C,
3279 layout->trough.x = layout->stepper_b.x + layout->stepper_b.width + stepper_spacing * has_steppers_ab;
3280 layout->trough.y = range_rect.y;
3282 layout->trough.width = layout->stepper_c.x - layout->trough.x - stepper_spacing * has_steppers_cd;
3283 layout->trough.height = range_rect.height;
3285 /* Slider fits into the trough, with stepper_spacing on either side,
3286 * and the size/position based on the adjustment or fixed, depending.
3288 layout->slider.y = layout->trough.y + focus_width + trough_border;
3289 layout->slider.height = layout->trough.height - (focus_width + trough_border) * 2;
3291 /* Compute slider position/length */
3293 gint x, left, right, width;
3295 left = layout->trough.x;
3296 right = layout->trough.x + layout->trough.width;
3298 if (! trough_under_steppers)
3300 left += trough_border;
3301 right -= trough_border;
3304 /* slider width is the fraction (page_size /
3305 * total_adjustment_range) times the trough width in pixels
3308 if (range->adjustment->upper - range->adjustment->lower != 0)
3309 width = ((right - left) * (range->adjustment->page_size /
3310 (range->adjustment->upper - range->adjustment->lower)));
3312 width = range->min_slider_size;
3314 if (width < range->min_slider_size ||
3315 range->slider_size_fixed)
3316 width = range->min_slider_size;
3318 width = MIN (width, layout->trough.width);
3322 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3323 x += (right - left - width) * ((adjustment_value - range->adjustment->lower) /
3324 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3326 x = CLAMP (x, left, right);
3328 if (should_invert (range))
3329 x = right - (x - left + width);
3331 layout->slider.x = x;
3332 layout->slider.width = width;
3334 /* These are publically exported */
3335 range->slider_start = layout->slider.x;
3336 range->slider_end = layout->slider.x + layout->slider.width;
3340 gtk_range_update_mouse_location (range);
3342 switch (range->layout->upper_sensitivity)
3344 case GTK_SENSITIVITY_AUTO:
3345 range->layout->upper_sensitive =
3346 (range->adjustment->value <
3347 (range->adjustment->upper - range->adjustment->page_size));
3350 case GTK_SENSITIVITY_ON:
3351 range->layout->upper_sensitive = TRUE;
3354 case GTK_SENSITIVITY_OFF:
3355 range->layout->upper_sensitive = FALSE;
3359 switch (range->layout->lower_sensitivity)
3361 case GTK_SENSITIVITY_AUTO:
3362 range->layout->lower_sensitive =
3363 (range->adjustment->value > range->adjustment->lower);
3366 case GTK_SENSITIVITY_ON:
3367 range->layout->lower_sensitive = TRUE;
3370 case GTK_SENSITIVITY_OFF:
3371 range->layout->lower_sensitive = FALSE;
3376 static GdkRectangle*
3377 get_area (GtkRange *range,
3378 MouseLocation location)
3382 case MOUSE_STEPPER_A:
3383 return &range->layout->stepper_a;
3384 case MOUSE_STEPPER_B:
3385 return &range->layout->stepper_b;
3386 case MOUSE_STEPPER_C:
3387 return &range->layout->stepper_c;
3388 case MOUSE_STEPPER_D:
3389 return &range->layout->stepper_d;
3391 return &range->layout->trough;
3393 return &range->layout->slider;
3399 g_warning (G_STRLOC": bug");
3404 gtk_range_calc_marks (GtkRange *range)
3408 if (!range->layout->recalc_marks)
3411 range->layout->recalc_marks = FALSE;
3413 for (i = 0; i < range->layout->n_marks; i++)
3415 range->need_recalc = TRUE;
3416 gtk_range_calc_layout (range, range->layout->marks[i]);
3417 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
3418 range->layout->mark_pos[i] = range->layout->slider.x + range->layout->slider.width / 2;
3420 range->layout->mark_pos[i] = range->layout->slider.y + range->layout->slider.height / 2;
3423 range->need_recalc = TRUE;
3427 gtk_range_real_change_value (GtkRange *range,
3428 GtkScrollType scroll,
3431 /* potentially adjust the bounds _before we clamp */
3432 g_signal_emit (range, signals[ADJUST_BOUNDS], 0, value);
3434 if (range->layout->restrict_to_fill_level)
3435 value = MIN (value, MAX (range->adjustment->lower,
3436 range->layout->fill_level));
3438 value = CLAMP (value, range->adjustment->lower,
3439 (range->adjustment->upper - range->adjustment->page_size));
3441 if (range->round_digits >= 0)
3446 i = range->round_digits;
3451 value = floor ((value * power) + 0.5) / power;
3454 if (range->adjustment->value != value)
3456 range->need_recalc = TRUE;
3458 gtk_widget_queue_draw (GTK_WIDGET (range));
3460 switch (range->update_policy)
3462 case GTK_UPDATE_CONTINUOUS:
3463 gtk_adjustment_set_value (range->adjustment, value);
3466 /* Delayed means we update after a period of inactivity */
3467 case GTK_UPDATE_DELAYED:
3468 gtk_range_reset_update_timer (range);
3471 /* Discontinuous means we update on button release */
3472 case GTK_UPDATE_DISCONTINUOUS:
3473 /* don't emit value_changed signal */
3474 range->adjustment->value = value;
3475 range->update_pending = TRUE;
3483 gtk_range_update_value (GtkRange *range)
3485 gtk_range_remove_update_timer (range);
3487 if (range->update_pending)
3489 gtk_adjustment_value_changed (range->adjustment);
3491 range->update_pending = FALSE;
3495 struct _GtkRangeStepTimer
3502 second_timeout (gpointer data)
3506 range = GTK_RANGE (data);
3507 gtk_range_scroll (range, range->timer->step);
3513 initial_timeout (gpointer data)
3516 GtkSettings *settings;
3519 settings = gtk_widget_get_settings (GTK_WIDGET (data));
3520 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3522 range = GTK_RANGE (data);
3523 range->timer->timeout_id = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3531 gtk_range_add_step_timer (GtkRange *range,
3534 GtkSettings *settings;
3537 g_return_if_fail (range->timer == NULL);
3538 g_return_if_fail (step != GTK_SCROLL_NONE);
3540 settings = gtk_widget_get_settings (GTK_WIDGET (range));
3541 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
3543 range->timer = g_new (GtkRangeStepTimer, 1);
3545 range->timer->timeout_id = gdk_threads_add_timeout (timeout,
3548 range->timer->step = step;
3550 gtk_range_scroll (range, range->timer->step);
3554 gtk_range_remove_step_timer (GtkRange *range)
3558 if (range->timer->timeout_id != 0)
3559 g_source_remove (range->timer->timeout_id);
3561 g_free (range->timer);
3563 range->timer = NULL;
3568 update_timeout (gpointer data)
3572 range = GTK_RANGE (data);
3573 gtk_range_update_value (range);
3574 range->update_timeout_id = 0;
3581 gtk_range_reset_update_timer (GtkRange *range)
3583 gtk_range_remove_update_timer (range);
3585 range->update_timeout_id = gdk_threads_add_timeout (UPDATE_DELAY,
3591 gtk_range_remove_update_timer (GtkRange *range)
3593 if (range->update_timeout_id != 0)
3595 g_source_remove (range->update_timeout_id);
3596 range->update_timeout_id = 0;
3601 _gtk_range_set_stop_values (GtkRange *range,
3607 g_free (range->layout->marks);
3608 range->layout->marks = g_new (gdouble, n_values);
3610 g_free (range->layout->mark_pos);
3611 range->layout->mark_pos = g_new (gint, n_values);
3613 range->layout->n_marks = n_values;
3615 for (i = 0; i < n_values; i++)
3616 range->layout->marks[i] = values[i];
3618 range->layout->recalc_marks = TRUE;
3622 _gtk_range_get_stop_positions (GtkRange *range,
3625 gtk_range_calc_marks (range);
3628 *values = g_memdup (range->layout->mark_pos, range->layout->n_marks * sizeof (gint));
3630 return range->layout->n_marks;
3633 #define __GTK_RANGE_C__
3634 #include "gtkaliasdef.c"