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 value = CLAMP (value, range->adjustment->lower,
994 (range->adjustment->upper - range->adjustment->page_size));
996 gtk_adjustment_set_value (range->adjustment, value);
997 gtk_adjustment_changed (range->adjustment);
1001 * gtk_range_set_value:
1002 * @range: a #GtkRange
1003 * @value: new value of the range
1005 * Sets the current value of the range; if the value is outside the
1006 * minimum or maximum range values, it will be clamped to fit inside
1007 * them. The range emits the #GtkRange::value-changed signal if the
1011 gtk_range_set_value (GtkRange *range,
1014 g_return_if_fail (GTK_IS_RANGE (range));
1016 if (range->layout->restrict_to_fill_level)
1017 value = MIN (value, MAX (range->adjustment->lower,
1018 range->layout->fill_level));
1020 value = CLAMP (value, range->adjustment->lower,
1021 (range->adjustment->upper - range->adjustment->page_size));
1023 gtk_adjustment_set_value (range->adjustment, value);
1027 * gtk_range_get_value:
1028 * @range: a #GtkRange
1030 * Gets the current value of the range.
1032 * Return value: current value of the range.
1035 gtk_range_get_value (GtkRange *range)
1037 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1039 return range->adjustment->value;
1043 * gtk_range_set_show_fill_level:
1044 * @range: A #GtkRange
1045 * @show_fill_level: Whether a fill level indicator graphics is shown.
1047 * Sets whether a graphical fill level is show on the trough. See
1048 * gtk_range_set_fill_level() for a general description of the fill
1054 gtk_range_set_show_fill_level (GtkRange *range,
1055 gboolean show_fill_level)
1057 g_return_if_fail (GTK_IS_RANGE (range));
1059 show_fill_level = show_fill_level ? TRUE : FALSE;
1061 if (show_fill_level != range->layout->show_fill_level)
1063 range->layout->show_fill_level = show_fill_level;
1064 g_object_notify (G_OBJECT (range), "show-fill-level");
1065 gtk_widget_queue_draw (GTK_WIDGET (range));
1070 * gtk_range_get_show_fill_level:
1071 * @range: A #GtkRange
1073 * Gets whether the range displays the fill level graphically.
1075 * Return value: %TRUE if @range shows the fill level.
1080 gtk_range_get_show_fill_level (GtkRange *range)
1082 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1084 return range->layout->show_fill_level;
1088 * gtk_range_set_restrict_to_fill_level:
1089 * @range: A #GtkRange
1090 * @restrict_to_fill_level: Whether the fill level restricts slider movement.
1092 * Sets whether the slider is restricted to the fill level. See
1093 * gtk_range_set_fill_level() for a general description of the fill
1099 gtk_range_set_restrict_to_fill_level (GtkRange *range,
1100 gboolean restrict_to_fill_level)
1102 g_return_if_fail (GTK_IS_RANGE (range));
1104 restrict_to_fill_level = restrict_to_fill_level ? TRUE : FALSE;
1106 if (restrict_to_fill_level != range->layout->restrict_to_fill_level)
1108 range->layout->restrict_to_fill_level = restrict_to_fill_level;
1109 g_object_notify (G_OBJECT (range), "restrict-to-fill-level");
1111 gtk_range_set_value (range, gtk_range_get_value (range));
1116 * gtk_range_get_restrict_to_fill_level:
1117 * @range: A #GtkRange
1119 * Gets whether the range is restricted to the fill level.
1121 * Return value: %TRUE if @range is restricted to the fill level.
1126 gtk_range_get_restrict_to_fill_level (GtkRange *range)
1128 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1130 return range->layout->restrict_to_fill_level;
1134 * gtk_range_set_fill_level:
1135 * @range: a #GtkRange
1136 * @fill_level: the new position of the fill level indicator
1138 * Set the new position of the fill level indicator.
1140 * The "fill level" is probably best described by its most prominent
1141 * use case, which is an indicator for the amount of pre-buffering in
1142 * a streaming media player. In that use case, the value of the range
1143 * would indicate the current play position, and the fill level would
1144 * be the position up to which the file/stream has been downloaded.
1146 * This amount of prebuffering can be displayed on the range's trough
1147 * and is themeable separately from the trough. To enable fill level
1148 * display, use gtk_range_set_show_fill_level(). The range defaults
1149 * to not showing the fill level.
1151 * Additionally, it's possible to restrict the range's slider position
1152 * to values which are smaller than the fill level. This is controller
1153 * by gtk_range_set_restrict_to_fill_level() and is by default
1159 gtk_range_set_fill_level (GtkRange *range,
1162 g_return_if_fail (GTK_IS_RANGE (range));
1164 if (fill_level != range->layout->fill_level)
1166 range->layout->fill_level = fill_level;
1167 g_object_notify (G_OBJECT (range), "fill-level");
1169 if (range->layout->show_fill_level)
1170 gtk_widget_queue_draw (GTK_WIDGET (range));
1172 if (range->layout->restrict_to_fill_level)
1173 gtk_range_set_value (range, gtk_range_get_value (range));
1178 * gtk_range_get_fill_level:
1179 * @range : A #GtkRange
1181 * Gets the current position of the fill level indicator.
1183 * Return value: The current fill level
1188 gtk_range_get_fill_level (GtkRange *range)
1190 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1192 return range->layout->fill_level;
1196 should_invert (GtkRange *range)
1198 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1200 (range->inverted && !range->flippable) ||
1201 (range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_LTR) ||
1202 (!range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_RTL);
1204 return range->inverted;
1208 gtk_range_destroy (GtkObject *object)
1210 GtkRange *range = GTK_RANGE (object);
1212 gtk_range_remove_step_timer (range);
1213 gtk_range_remove_update_timer (range);
1215 if (range->layout->repaint_id)
1216 g_source_remove (range->layout->repaint_id);
1217 range->layout->repaint_id = 0;
1219 if (range->adjustment)
1221 g_signal_handlers_disconnect_by_func (range->adjustment,
1222 gtk_range_adjustment_changed,
1224 g_signal_handlers_disconnect_by_func (range->adjustment,
1225 gtk_range_adjustment_value_changed,
1227 g_object_unref (range->adjustment);
1228 range->adjustment = NULL;
1231 if (range->layout->n_marks)
1233 g_free (range->layout->marks);
1234 range->layout->marks = NULL;
1235 g_free (range->layout->mark_pos);
1236 range->layout->mark_pos = NULL;
1237 range->layout->n_marks = 0;
1240 GTK_OBJECT_CLASS (gtk_range_parent_class)->destroy (object);
1244 gtk_range_size_request (GtkWidget *widget,
1245 GtkRequisition *requisition)
1248 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
1249 GdkRectangle range_rect;
1252 range = GTK_RANGE (widget);
1254 gtk_range_get_props (range,
1255 &slider_width, &stepper_size,
1256 &focus_width, &trough_border,
1257 &stepper_spacing, NULL,
1260 gtk_range_calc_request (range,
1261 slider_width, stepper_size,
1262 focus_width, trough_border, stepper_spacing,
1263 &range_rect, &border, NULL, NULL, NULL, NULL);
1265 requisition->width = range_rect.width + border.left + border.right;
1266 requisition->height = range_rect.height + border.top + border.bottom;
1270 gtk_range_size_allocate (GtkWidget *widget,
1271 GtkAllocation *allocation)
1275 range = GTK_RANGE (widget);
1277 widget->allocation = *allocation;
1279 range->layout->recalc_marks = TRUE;
1281 range->need_recalc = TRUE;
1282 gtk_range_calc_layout (range, range->adjustment->value);
1284 if (GTK_WIDGET_REALIZED (range))
1285 gdk_window_move_resize (range->event_window,
1286 widget->allocation.x,
1287 widget->allocation.y,
1288 widget->allocation.width,
1289 widget->allocation.height);
1293 gtk_range_realize (GtkWidget *widget)
1296 GdkWindowAttr attributes;
1297 gint attributes_mask;
1299 range = GTK_RANGE (widget);
1301 gtk_range_calc_layout (range, range->adjustment->value);
1303 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1305 widget->window = gtk_widget_get_parent_window (widget);
1306 g_object_ref (widget->window);
1308 attributes.window_type = GDK_WINDOW_CHILD;
1309 attributes.x = widget->allocation.x;
1310 attributes.y = widget->allocation.y;
1311 attributes.width = widget->allocation.width;
1312 attributes.height = widget->allocation.height;
1313 attributes.wclass = GDK_INPUT_ONLY;
1314 attributes.event_mask = gtk_widget_get_events (widget);
1315 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1316 GDK_BUTTON_RELEASE_MASK |
1317 GDK_ENTER_NOTIFY_MASK |
1318 GDK_LEAVE_NOTIFY_MASK |
1319 GDK_POINTER_MOTION_MASK |
1320 GDK_POINTER_MOTION_HINT_MASK);
1322 attributes_mask = GDK_WA_X | GDK_WA_Y;
1324 range->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1325 &attributes, attributes_mask);
1326 gdk_window_set_user_data (range->event_window, range);
1328 widget->style = gtk_style_attach (widget->style, widget->window);
1332 gtk_range_unrealize (GtkWidget *widget)
1334 GtkRange *range = GTK_RANGE (widget);
1336 gtk_range_remove_step_timer (range);
1337 gtk_range_remove_update_timer (range);
1339 gdk_window_set_user_data (range->event_window, NULL);
1340 gdk_window_destroy (range->event_window);
1341 range->event_window = NULL;
1343 GTK_WIDGET_CLASS (gtk_range_parent_class)->unrealize (widget);
1347 gtk_range_map (GtkWidget *widget)
1349 GtkRange *range = GTK_RANGE (widget);
1351 gdk_window_show (range->event_window);
1353 GTK_WIDGET_CLASS (gtk_range_parent_class)->map (widget);
1357 gtk_range_unmap (GtkWidget *widget)
1359 GtkRange *range = GTK_RANGE (widget);
1361 stop_scrolling (range);
1363 gdk_window_hide (range->event_window);
1365 GTK_WIDGET_CLASS (gtk_range_parent_class)->unmap (widget);
1368 static const gchar *
1369 gtk_range_get_slider_detail (GtkRange *range)
1371 const gchar *slider_detail;
1373 if (range->layout->slider_detail_quark)
1374 return g_quark_to_string (range->layout->slider_detail_quark);
1376 slider_detail = GTK_RANGE_GET_CLASS (range)->slider_detail;
1378 if (slider_detail && slider_detail[0] == 'X')
1380 gchar *detail = g_strdup (slider_detail);
1382 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1384 range->layout->slider_detail_quark = g_quark_from_string (detail);
1388 return g_quark_to_string (range->layout->slider_detail_quark);
1391 return slider_detail;
1394 static const gchar *
1395 gtk_range_get_stepper_detail (GtkRange *range)
1397 const gchar *stepper_detail;
1399 if (range->layout->stepper_detail_quark)
1400 return g_quark_to_string (range->layout->stepper_detail_quark);
1402 stepper_detail = GTK_RANGE_GET_CLASS (range)->stepper_detail;
1404 if (stepper_detail && stepper_detail[0] == 'X')
1406 gchar *detail = g_strdup (stepper_detail);
1408 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1410 range->layout->stepper_detail_quark = g_quark_from_string (detail);
1414 return g_quark_to_string (range->layout->stepper_detail_quark);
1417 return stepper_detail;
1421 draw_stepper (GtkRange *range,
1423 GtkArrowType arrow_type,
1425 gboolean prelighted,
1428 GtkStateType state_type;
1429 GtkShadowType shadow_type;
1430 GdkRectangle intersection;
1431 GtkWidget *widget = GTK_WIDGET (range);
1432 gfloat arrow_scaling;
1439 gboolean arrow_sensitive = TRUE;
1441 /* More to get the right clip region than for efficiency */
1442 if (!gdk_rectangle_intersect (area, rect, &intersection))
1445 intersection.x += widget->allocation.x;
1446 intersection.y += widget->allocation.y;
1448 if ((!range->inverted && (arrow_type == GTK_ARROW_DOWN ||
1449 arrow_type == GTK_ARROW_RIGHT)) ||
1450 (range->inverted && (arrow_type == GTK_ARROW_UP ||
1451 arrow_type == GTK_ARROW_LEFT)))
1453 arrow_sensitive = range->layout->upper_sensitive;
1457 arrow_sensitive = range->layout->lower_sensitive;
1460 if (!GTK_WIDGET_IS_SENSITIVE (range) || !arrow_sensitive)
1461 state_type = GTK_STATE_INSENSITIVE;
1463 state_type = GTK_STATE_ACTIVE;
1464 else if (prelighted)
1465 state_type = GTK_STATE_PRELIGHT;
1467 state_type = GTK_STATE_NORMAL;
1469 if (clicked && arrow_sensitive)
1470 shadow_type = GTK_SHADOW_IN;
1472 shadow_type = GTK_SHADOW_OUT;
1474 gtk_paint_box (widget->style,
1476 state_type, shadow_type,
1477 &intersection, widget,
1478 gtk_range_get_stepper_detail (range),
1479 widget->allocation.x + rect->x,
1480 widget->allocation.y + rect->y,
1484 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
1486 arrow_width = rect->width * arrow_scaling;
1487 arrow_height = rect->height * arrow_scaling;
1488 arrow_x = widget->allocation.x + rect->x + (rect->width - arrow_width) / 2;
1489 arrow_y = widget->allocation.y + rect->y + (rect->height - arrow_height) / 2;
1491 if (clicked && arrow_sensitive)
1493 gint arrow_displacement_x;
1494 gint arrow_displacement_y;
1496 gtk_range_get_props (GTK_RANGE (widget),
1497 NULL, NULL, NULL, NULL, NULL, NULL,
1498 &arrow_displacement_x, &arrow_displacement_y);
1500 arrow_x += arrow_displacement_x;
1501 arrow_y += arrow_displacement_y;
1504 gtk_paint_arrow (widget->style,
1506 state_type, shadow_type,
1507 &intersection, widget,
1508 gtk_range_get_stepper_detail (range),
1511 arrow_x, arrow_y, arrow_width, arrow_height);
1515 gtk_range_expose (GtkWidget *widget,
1516 GdkEventExpose *event)
1518 GtkRange *range = GTK_RANGE (widget);
1521 GtkShadowType shadow_type;
1522 GdkRectangle expose_area; /* Relative to widget->allocation */
1524 gint focus_line_width = 0;
1525 gint focus_padding = 0;
1526 gboolean touchscreen;
1528 g_object_get (gtk_widget_get_settings (widget),
1529 "gtk-touchscreen-mode", &touchscreen,
1531 if (GTK_WIDGET_CAN_FOCUS (range))
1532 gtk_widget_style_get (GTK_WIDGET (range),
1533 "focus-line-width", &focus_line_width,
1534 "focus-padding", &focus_padding,
1537 /* we're now exposing, so there's no need to force early repaints */
1538 if (range->layout->repaint_id)
1539 g_source_remove (range->layout->repaint_id);
1540 range->layout->repaint_id = 0;
1542 expose_area = event->area;
1543 expose_area.x -= widget->allocation.x;
1544 expose_area.y -= widget->allocation.y;
1546 gtk_range_calc_marks (range);
1547 gtk_range_calc_layout (range, range->adjustment->value);
1549 sensitive = GTK_WIDGET_IS_SENSITIVE (widget);
1551 /* Just to be confusing, we draw the trough for the whole
1552 * range rectangle, not the trough rectangle (the trough
1553 * rectangle is just for hit detection)
1555 /* The gdk_rectangle_intersect is more to get the right
1556 * clip region (limited to range_rect) than for efficiency
1558 if (gdk_rectangle_intersect (&expose_area, &range->range_rect,
1561 gint x = (widget->allocation.x + range->range_rect.x +
1562 focus_line_width + focus_padding);
1563 gint y = (widget->allocation.y + range->range_rect.y +
1564 focus_line_width + focus_padding);
1565 gint width = (range->range_rect.width -
1566 2 * (focus_line_width + focus_padding));
1567 gint height = (range->range_rect.height -
1568 2 * (focus_line_width + focus_padding));
1569 gboolean trough_side_details;
1570 gboolean trough_under_steppers;
1572 gint stepper_spacing;
1574 area.x += widget->allocation.x;
1575 area.y += widget->allocation.y;
1577 gtk_widget_style_get (GTK_WIDGET (range),
1578 "trough-side-details", &trough_side_details,
1579 "trough-under-steppers", &trough_under_steppers,
1580 "stepper-size", &stepper_size,
1581 "stepper-spacing", &stepper_spacing,
1584 if (stepper_spacing > 0)
1585 trough_under_steppers = FALSE;
1587 if (! trough_under_steppers)
1592 if (range->has_stepper_a)
1593 offset += stepper_size;
1595 if (range->has_stepper_b)
1596 offset += stepper_size;
1600 if (range->has_stepper_c)
1601 shorter += stepper_size;
1603 if (range->has_stepper_d)
1604 shorter += stepper_size;
1606 if (range->has_stepper_a || range->has_stepper_b)
1608 offset += stepper_spacing;
1609 shorter += stepper_spacing;
1612 if (range->has_stepper_c || range->has_stepper_d)
1614 shorter += stepper_spacing;
1617 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1629 if (! trough_side_details)
1631 gtk_paint_box (widget->style,
1633 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1635 &area, GTK_WIDGET(range), "trough",
1641 gint trough_change_pos_x = width;
1642 gint trough_change_pos_y = height;
1644 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1645 trough_change_pos_x = (range->layout->slider.x +
1646 range->layout->slider.width / 2 -
1647 (x - widget->allocation.x));
1649 trough_change_pos_y = (range->layout->slider.y +
1650 range->layout->slider.height / 2 -
1651 (y - widget->allocation.y));
1653 gtk_paint_box (widget->style,
1655 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1657 &area, GTK_WIDGET (range),
1658 should_invert (range) ? "trough-upper" : "trough-lower",
1660 trough_change_pos_x, trough_change_pos_y);
1662 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1663 trough_change_pos_y = 0;
1665 trough_change_pos_x = 0;
1667 gtk_paint_box (widget->style,
1669 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1671 &area, GTK_WIDGET (range),
1672 should_invert (range) ? "trough-lower" : "trough-upper",
1673 x + trough_change_pos_x, y + trough_change_pos_y,
1674 width - trough_change_pos_x,
1675 height - trough_change_pos_y);
1678 if (range->layout->show_fill_level &&
1679 range->adjustment->upper - range->adjustment->page_size -
1680 range->adjustment->lower != 0)
1682 gdouble fill_level = range->layout->fill_level;
1685 gint fill_width = width;
1686 gint fill_height = height;
1689 fill_level = CLAMP (fill_level, range->adjustment->lower,
1690 range->adjustment->upper -
1691 range->adjustment->page_size);
1693 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1695 fill_x = widget->allocation.x + range->layout->trough.x;
1696 fill_width = (range->layout->slider.width +
1697 (fill_level - range->adjustment->lower) /
1698 (range->adjustment->upper -
1699 range->adjustment->lower -
1700 range->adjustment->page_size) *
1701 (range->layout->trough.width -
1702 range->layout->slider.width));
1704 if (should_invert (range))
1705 fill_x += range->layout->trough.width - fill_width;
1709 fill_y = widget->allocation.y + range->layout->trough.y;
1710 fill_height = (range->layout->slider.height +
1711 (fill_level - range->adjustment->lower) /
1712 (range->adjustment->upper -
1713 range->adjustment->lower -
1714 range->adjustment->page_size) *
1715 (range->layout->trough.height -
1716 range->layout->slider.height));
1718 if (should_invert (range))
1719 fill_y += range->layout->trough.height - fill_height;
1722 if (fill_level < range->adjustment->upper - range->adjustment->page_size)
1723 fill_detail = "trough-fill-level-full";
1725 fill_detail = "trough-fill-level";
1727 gtk_paint_box (widget->style,
1729 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1731 &area, GTK_WIDGET (range), fill_detail,
1733 fill_width, fill_height);
1737 GTK_WIDGET_HAS_FOCUS (range))
1738 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
1739 &area, widget, "trough",
1740 widget->allocation.x + range->range_rect.x,
1741 widget->allocation.y + range->range_rect.y,
1742 range->range_rect.width,
1743 range->range_rect.height);
1746 shadow_type = GTK_SHADOW_OUT;
1749 state = GTK_STATE_INSENSITIVE;
1750 else if (!touchscreen && range->layout->mouse_location == MOUSE_SLIDER)
1751 state = GTK_STATE_PRELIGHT;
1753 state = GTK_STATE_NORMAL;
1755 if (range->layout->grab_location == MOUSE_SLIDER)
1757 gboolean activate_slider;
1759 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
1761 if (activate_slider)
1763 state = GTK_STATE_ACTIVE;
1764 shadow_type = GTK_SHADOW_IN;
1768 if (gdk_rectangle_intersect (&expose_area,
1769 &range->layout->slider,
1772 area.x += widget->allocation.x;
1773 area.y += widget->allocation.y;
1775 gtk_paint_slider (widget->style,
1781 gtk_range_get_slider_detail (range),
1782 widget->allocation.x + range->layout->slider.x,
1783 widget->allocation.y + range->layout->slider.y,
1784 range->layout->slider.width,
1785 range->layout->slider.height,
1786 range->orientation);
1789 if (range->has_stepper_a)
1790 draw_stepper (range, &range->layout->stepper_a,
1791 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
1792 range->layout->grab_location == MOUSE_STEPPER_A,
1793 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_A,
1796 if (range->has_stepper_b)
1797 draw_stepper (range, &range->layout->stepper_b,
1798 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
1799 range->layout->grab_location == MOUSE_STEPPER_B,
1800 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_B,
1803 if (range->has_stepper_c)
1804 draw_stepper (range, &range->layout->stepper_c,
1805 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
1806 range->layout->grab_location == MOUSE_STEPPER_C,
1807 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_C,
1810 if (range->has_stepper_d)
1811 draw_stepper (range, &range->layout->stepper_d,
1812 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
1813 range->layout->grab_location == MOUSE_STEPPER_D,
1814 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_D,
1821 range_grab_add (GtkRange *range,
1822 MouseLocation location,
1825 /* we don't actually gtk_grab, since a button is down */
1827 gtk_grab_add (GTK_WIDGET (range));
1829 range->layout->grab_location = location;
1830 range->layout->grab_button = button;
1832 if (gtk_range_update_mouse_location (range))
1833 gtk_widget_queue_draw (GTK_WIDGET (range));
1837 range_grab_remove (GtkRange *range)
1839 MouseLocation location;
1841 gtk_grab_remove (GTK_WIDGET (range));
1843 location = range->layout->grab_location;
1844 range->layout->grab_location = MOUSE_OUTSIDE;
1845 range->layout->grab_button = 0;
1847 if (gtk_range_update_mouse_location (range) ||
1848 location != MOUSE_OUTSIDE)
1849 gtk_widget_queue_draw (GTK_WIDGET (range));
1852 static GtkScrollType
1853 range_get_scroll_for_grab (GtkRange *range)
1857 invert = should_invert (range);
1858 switch (range->layout->grab_location)
1860 /* Backward stepper */
1861 case MOUSE_STEPPER_A:
1862 case MOUSE_STEPPER_C:
1863 switch (range->layout->grab_button)
1866 return invert ? GTK_SCROLL_STEP_FORWARD : GTK_SCROLL_STEP_BACKWARD;
1869 return invert ? GTK_SCROLL_PAGE_FORWARD : GTK_SCROLL_PAGE_BACKWARD;
1872 return invert ? GTK_SCROLL_END : GTK_SCROLL_START;
1877 /* Forward stepper */
1878 case MOUSE_STEPPER_B:
1879 case MOUSE_STEPPER_D:
1880 switch (range->layout->grab_button)
1883 return invert ? GTK_SCROLL_STEP_BACKWARD : GTK_SCROLL_STEP_FORWARD;
1886 return invert ? GTK_SCROLL_PAGE_BACKWARD : GTK_SCROLL_PAGE_FORWARD;
1889 return invert ? GTK_SCROLL_START : GTK_SCROLL_END;
1897 if (range->trough_click_forward)
1898 return GTK_SCROLL_PAGE_FORWARD;
1900 return GTK_SCROLL_PAGE_BACKWARD;
1910 return GTK_SCROLL_NONE;
1914 coord_to_value (GtkRange *range,
1923 gint trough_under_steppers;
1925 if (range->orientation == GTK_ORIENTATION_VERTICAL)
1927 trough_length = range->layout->trough.height;
1928 trough_start = range->layout->trough.y;
1929 slider_length = range->layout->slider.height;
1933 trough_length = range->layout->trough.width;
1934 trough_start = range->layout->trough.x;
1935 slider_length = range->layout->slider.width;
1938 gtk_range_get_props (range, NULL, NULL, NULL, &trough_border, NULL,
1939 &trough_under_steppers, NULL, NULL);
1941 if (! trough_under_steppers)
1943 trough_start += trough_border;
1944 trough_length -= 2 * trough_border;
1947 if (trough_length == slider_length)
1950 frac = (MAX (0, coord - trough_start) /
1951 (gdouble) (trough_length - slider_length));
1953 if (should_invert (range))
1956 value = range->adjustment->lower + frac * (range->adjustment->upper -
1957 range->adjustment->lower -
1958 range->adjustment->page_size);
1964 gtk_range_key_press (GtkWidget *widget,
1967 GtkRange *range = GTK_RANGE (widget);
1969 if (event->keyval == GDK_Escape &&
1970 range->layout->grab_location != MOUSE_OUTSIDE)
1972 stop_scrolling (range);
1974 update_slider_position (range,
1975 range->slide_initial_coordinate,
1976 range->slide_initial_coordinate);
1981 return GTK_WIDGET_CLASS (gtk_range_parent_class)->key_press_event (widget, event);
1985 gtk_range_button_press (GtkWidget *widget,
1986 GdkEventButton *event)
1988 GtkRange *range = GTK_RANGE (widget);
1990 if (!GTK_WIDGET_HAS_FOCUS (widget))
1991 gtk_widget_grab_focus (widget);
1993 /* ignore presses when we're already doing something else. */
1994 if (range->layout->grab_location != MOUSE_OUTSIDE)
1997 range->layout->mouse_x = event->x;
1998 range->layout->mouse_y = event->y;
1999 if (gtk_range_update_mouse_location (range))
2000 gtk_widget_queue_draw (widget);
2002 if (range->layout->mouse_location == MOUSE_TROUGH &&
2005 /* button 1 steps by page increment, as with button 2 on a stepper
2007 GtkScrollType scroll;
2008 gdouble click_value;
2010 click_value = coord_to_value (range,
2011 range->orientation == GTK_ORIENTATION_VERTICAL ?
2012 event->y : event->x);
2014 range->trough_click_forward = click_value > range->adjustment->value;
2015 range_grab_add (range, MOUSE_TROUGH, event->button);
2017 scroll = range_get_scroll_for_grab (range);
2019 gtk_range_add_step_timer (range, scroll);
2023 else if ((range->layout->mouse_location == MOUSE_STEPPER_A ||
2024 range->layout->mouse_location == MOUSE_STEPPER_B ||
2025 range->layout->mouse_location == MOUSE_STEPPER_C ||
2026 range->layout->mouse_location == MOUSE_STEPPER_D) &&
2027 (event->button == 1 || event->button == 2 || event->button == 3))
2029 GdkRectangle *stepper_area;
2030 GtkScrollType scroll;
2032 range_grab_add (range, range->layout->mouse_location, event->button);
2034 stepper_area = get_area (range, range->layout->mouse_location);
2035 gtk_widget_queue_draw_area (widget,
2036 widget->allocation.x + stepper_area->x,
2037 widget->allocation.y + stepper_area->y,
2038 stepper_area->width,
2039 stepper_area->height);
2041 scroll = range_get_scroll_for_grab (range);
2042 if (scroll != GTK_SCROLL_NONE)
2043 gtk_range_add_step_timer (range, scroll);
2047 else if ((range->layout->mouse_location == MOUSE_TROUGH &&
2048 event->button == 2) ||
2049 range->layout->mouse_location == MOUSE_SLIDER)
2051 gboolean need_value_update = FALSE;
2052 gboolean activate_slider;
2054 /* Any button can be used to drag the slider, but you can start
2055 * dragging the slider with a trough click using button 2;
2056 * On button 2 press, we warp the slider to mouse position,
2057 * then begin the slider drag.
2059 if (event->button == 2)
2061 gdouble slider_low_value, slider_high_value, new_value;
2064 coord_to_value (range,
2065 range->orientation == GTK_ORIENTATION_VERTICAL ?
2066 event->y : event->x);
2068 coord_to_value (range,
2069 range->orientation == GTK_ORIENTATION_VERTICAL ?
2070 event->y - range->layout->slider.height :
2071 event->x - range->layout->slider.width);
2073 /* compute new value for warped slider */
2074 new_value = slider_low_value + (slider_high_value - slider_low_value) / 2;
2076 /* recalc slider, so we can set slide_initial_slider_position
2079 range->need_recalc = TRUE;
2080 gtk_range_calc_layout (range, new_value);
2082 /* defer adjustment updates to update_slider_position() in order
2083 * to keep pixel quantisation
2085 need_value_update = TRUE;
2088 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2090 range->slide_initial_slider_position = range->layout->slider.y;
2091 range->slide_initial_coordinate = event->y;
2095 range->slide_initial_slider_position = range->layout->slider.x;
2096 range->slide_initial_coordinate = event->x;
2099 range_grab_add (range, MOUSE_SLIDER, event->button);
2101 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
2103 /* force a redraw, if the active slider is drawn differently to the
2106 if (activate_slider)
2107 gtk_widget_queue_draw (widget);
2109 if (need_value_update)
2110 update_slider_position (range, event->x, event->y);
2118 /* During a slide, move the slider as required given new mouse position */
2120 update_slider_position (GtkRange *range,
2133 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2134 delta = mouse_y - range->slide_initial_coordinate;
2136 delta = mouse_x - range->slide_initial_coordinate;
2138 c = range->slide_initial_slider_position + delta;
2140 new_value = coord_to_value (range, c);
2141 next_value = coord_to_value (range, c + 1);
2142 mark_delta = fabs (next_value - new_value);
2144 for (i = 0; i < range->layout->n_marks; i++)
2146 mark_value = range->layout->marks[i];
2148 if (fabs (range->adjustment->value - mark_value) < 3 * mark_delta)
2150 if (fabs (new_value - mark_value) < (range->slider_end - range->slider_start) * 0.5 * mark_delta)
2152 new_value = mark_value;
2158 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_JUMP, new_value,
2163 stop_scrolling (GtkRange *range)
2165 range_grab_remove (range);
2166 gtk_range_remove_step_timer (range);
2167 /* Flush any pending discontinuous/delayed updates */
2168 gtk_range_update_value (range);
2172 gtk_range_grab_broken (GtkWidget *widget,
2173 GdkEventGrabBroken *event)
2175 GtkRange *range = GTK_RANGE (widget);
2177 if (range->layout->grab_location != MOUSE_OUTSIDE)
2179 if (range->layout->grab_location == MOUSE_SLIDER)
2180 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2182 stop_scrolling (range);
2191 gtk_range_button_release (GtkWidget *widget,
2192 GdkEventButton *event)
2194 GtkRange *range = GTK_RANGE (widget);
2196 if (event->window == range->event_window)
2198 range->layout->mouse_x = event->x;
2199 range->layout->mouse_y = event->y;
2203 gdk_window_get_pointer (range->event_window,
2204 &range->layout->mouse_x,
2205 &range->layout->mouse_y,
2209 if (range->layout->grab_button == event->button)
2211 if (range->layout->grab_location == MOUSE_SLIDER)
2212 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2214 stop_scrolling (range);
2223 * _gtk_range_get_wheel_delta:
2224 * @range: a #GtkRange
2225 * @direction: A #GdkScrollDirection
2227 * Returns a good step value for the mouse wheel.
2229 * Return value: A good step value for the mouse wheel.
2234 _gtk_range_get_wheel_delta (GtkRange *range,
2235 GdkScrollDirection direction)
2237 GtkAdjustment *adj = range->adjustment;
2240 if (GTK_IS_SCROLLBAR (range))
2241 delta = pow (adj->page_size, 2.0 / 3.0);
2243 delta = adj->step_increment * 2;
2245 if (direction == GDK_SCROLL_UP ||
2246 direction == GDK_SCROLL_LEFT)
2249 if (range->inverted)
2256 gtk_range_scroll_event (GtkWidget *widget,
2257 GdkEventScroll *event)
2259 GtkRange *range = GTK_RANGE (widget);
2261 if (GTK_WIDGET_REALIZED (range))
2263 GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
2267 delta = _gtk_range_get_wheel_delta (range, event->direction);
2269 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2270 GTK_SCROLL_JUMP, adj->value + delta,
2273 /* Policy DELAYED makes sense with scroll events,
2274 * but DISCONTINUOUS doesn't, so we update immediately
2277 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
2278 gtk_range_update_value (range);
2285 gtk_range_motion_notify (GtkWidget *widget,
2286 GdkEventMotion *event)
2290 range = GTK_RANGE (widget);
2292 gdk_event_request_motions (event);
2294 range->layout->mouse_x = event->x;
2295 range->layout->mouse_y = event->y;
2297 if (gtk_range_update_mouse_location (range))
2298 gtk_widget_queue_draw (widget);
2300 if (range->layout->grab_location == MOUSE_SLIDER)
2301 update_slider_position (range, event->x, event->y);
2303 /* We handled the event if the mouse was in the range_rect */
2304 return range->layout->mouse_location != MOUSE_OUTSIDE;
2308 gtk_range_enter_notify (GtkWidget *widget,
2309 GdkEventCrossing *event)
2311 GtkRange *range = GTK_RANGE (widget);
2313 range->layout->mouse_x = event->x;
2314 range->layout->mouse_y = event->y;
2316 if (gtk_range_update_mouse_location (range))
2317 gtk_widget_queue_draw (widget);
2323 gtk_range_leave_notify (GtkWidget *widget,
2324 GdkEventCrossing *event)
2326 GtkRange *range = GTK_RANGE (widget);
2328 range->layout->mouse_x = -1;
2329 range->layout->mouse_y = -1;
2331 if (gtk_range_update_mouse_location (range))
2332 gtk_widget_queue_draw (widget);
2338 gtk_range_grab_notify (GtkWidget *widget,
2339 gboolean was_grabbed)
2342 stop_scrolling (GTK_RANGE (widget));
2346 gtk_range_state_changed (GtkWidget *widget,
2347 GtkStateType previous_state)
2349 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2350 stop_scrolling (GTK_RANGE (widget));
2353 #define check_rectangle(rectangle1, rectangle2) \
2355 if (rectangle1.x != rectangle2.x) return TRUE; \
2356 if (rectangle1.y != rectangle2.y) return TRUE; \
2357 if (rectangle1.width != rectangle2.width) return TRUE; \
2358 if (rectangle1.height != rectangle2.height) return TRUE; \
2362 layout_changed (GtkRangeLayout *layout1,
2363 GtkRangeLayout *layout2)
2365 check_rectangle (layout1->slider, layout2->slider);
2366 check_rectangle (layout1->trough, layout2->trough);
2367 check_rectangle (layout1->stepper_a, layout2->stepper_a);
2368 check_rectangle (layout1->stepper_d, layout2->stepper_d);
2369 check_rectangle (layout1->stepper_b, layout2->stepper_b);
2370 check_rectangle (layout1->stepper_c, layout2->stepper_c);
2372 if (layout1->upper_sensitive != layout2->upper_sensitive) return TRUE;
2373 if (layout1->lower_sensitive != layout2->lower_sensitive) return TRUE;
2379 gtk_range_adjustment_changed (GtkAdjustment *adjustment,
2382 GtkRange *range = GTK_RANGE (data);
2383 /* create a copy of the layout */
2384 GtkRangeLayout layout = *range->layout;
2386 range->layout->recalc_marks = TRUE;
2387 range->need_recalc = TRUE;
2388 gtk_range_calc_layout (range, range->adjustment->value);
2390 /* now check whether the layout changed */
2391 if (layout_changed (range->layout, &layout))
2392 gtk_widget_queue_draw (GTK_WIDGET (range));
2394 /* Note that we don't round off to range->round_digits here.
2395 * that's because it's really broken to change a value
2396 * in response to a change signal on that value; round_digits
2397 * is therefore defined to be a filter on what the GtkRange
2398 * can input into the adjustment, not a filter that the GtkRange
2399 * will enforce on the adjustment.
2404 force_repaint (gpointer data)
2406 GtkRange *range = GTK_RANGE (data);
2407 range->layout->repaint_id = 0;
2408 if (GTK_WIDGET_DRAWABLE (range))
2409 gdk_window_process_updates (GTK_WIDGET (range)->window, FALSE);
2414 gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
2417 GtkRange *range = GTK_RANGE (data);
2418 /* create a copy of the layout */
2419 GtkRangeLayout layout = *range->layout;
2421 range->need_recalc = TRUE;
2422 gtk_range_calc_layout (range, range->adjustment->value);
2424 /* now check whether the layout changed */
2425 if (layout_changed (range->layout, &layout))
2427 gtk_widget_queue_draw (GTK_WIDGET (range));
2428 /* setup a timer to ensure the range isn't lagging too much behind the scroll position */
2429 if (!range->layout->repaint_id)
2430 range->layout->repaint_id = gdk_threads_add_timeout_full (GDK_PRIORITY_EVENTS, 181, force_repaint, range, NULL);
2433 /* Note that we don't round off to range->round_digits here.
2434 * that's because it's really broken to change a value
2435 * in response to a change signal on that value; round_digits
2436 * is therefore defined to be a filter on what the GtkRange
2437 * can input into the adjustment, not a filter that the GtkRange
2438 * will enforce on the adjustment.
2441 g_signal_emit (range, signals[VALUE_CHANGED], 0);
2445 gtk_range_style_set (GtkWidget *widget,
2446 GtkStyle *previous_style)
2448 GtkRange *range = GTK_RANGE (widget);
2450 range->need_recalc = TRUE;
2452 GTK_WIDGET_CLASS (gtk_range_parent_class)->style_set (widget, previous_style);
2456 apply_marks (GtkRange *range,
2463 for (i = 0; i < range->layout->n_marks; i++)
2465 mark = range->layout->marks[i];
2466 if ((oldval < mark && mark < *newval) ||
2467 (oldval > mark && mark > *newval))
2476 step_back (GtkRange *range)
2481 newval = range->adjustment->value - range->adjustment->step_increment;
2482 apply_marks (range, range->adjustment->value, &newval);
2483 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2484 GTK_SCROLL_STEP_BACKWARD, newval, &handled);
2488 step_forward (GtkRange *range)
2493 newval = range->adjustment->value + range->adjustment->step_increment;
2494 apply_marks (range, range->adjustment->value, &newval);
2495 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2496 GTK_SCROLL_STEP_FORWARD, newval, &handled);
2501 page_back (GtkRange *range)
2506 newval = range->adjustment->value - range->adjustment->page_increment;
2507 apply_marks (range, range->adjustment->value, &newval);
2508 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2509 GTK_SCROLL_PAGE_BACKWARD, newval, &handled);
2513 page_forward (GtkRange *range)
2518 newval = range->adjustment->value + range->adjustment->page_increment;
2519 apply_marks (range, range->adjustment->value, &newval);
2520 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2521 GTK_SCROLL_PAGE_FORWARD, newval, &handled);
2525 scroll_begin (GtkRange *range)
2528 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2529 GTK_SCROLL_START, range->adjustment->lower,
2534 scroll_end (GtkRange *range)
2539 newval = range->adjustment->upper - range->adjustment->page_size;
2540 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_END, newval,
2545 gtk_range_scroll (GtkRange *range,
2546 GtkScrollType scroll)
2548 gdouble old_value = range->adjustment->value;
2552 case GTK_SCROLL_STEP_LEFT:
2553 if (should_invert (range))
2554 step_forward (range);
2559 case GTK_SCROLL_STEP_UP:
2560 if (should_invert (range))
2561 step_forward (range);
2566 case GTK_SCROLL_STEP_RIGHT:
2567 if (should_invert (range))
2570 step_forward (range);
2573 case GTK_SCROLL_STEP_DOWN:
2574 if (should_invert (range))
2577 step_forward (range);
2580 case GTK_SCROLL_STEP_BACKWARD:
2584 case GTK_SCROLL_STEP_FORWARD:
2585 step_forward (range);
2588 case GTK_SCROLL_PAGE_LEFT:
2589 if (should_invert (range))
2590 page_forward (range);
2595 case GTK_SCROLL_PAGE_UP:
2596 if (should_invert (range))
2597 page_forward (range);
2602 case GTK_SCROLL_PAGE_RIGHT:
2603 if (should_invert (range))
2606 page_forward (range);
2609 case GTK_SCROLL_PAGE_DOWN:
2610 if (should_invert (range))
2613 page_forward (range);
2616 case GTK_SCROLL_PAGE_BACKWARD:
2620 case GTK_SCROLL_PAGE_FORWARD:
2621 page_forward (range);
2624 case GTK_SCROLL_START:
2625 scroll_begin (range);
2628 case GTK_SCROLL_END:
2632 case GTK_SCROLL_JUMP:
2633 /* Used by CList, range doesn't use it. */
2636 case GTK_SCROLL_NONE:
2640 return range->adjustment->value != old_value;
2644 gtk_range_move_slider (GtkRange *range,
2645 GtkScrollType scroll)
2647 gboolean cursor_only;
2649 g_object_get (gtk_widget_get_settings (GTK_WIDGET (range)),
2650 "gtk-keynav-cursor-only", &cursor_only,
2655 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (range));
2657 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
2659 if (scroll == GTK_SCROLL_STEP_UP ||
2660 scroll == GTK_SCROLL_STEP_DOWN)
2663 gtk_widget_child_focus (toplevel,
2664 scroll == GTK_SCROLL_STEP_UP ?
2665 GTK_DIR_UP : GTK_DIR_DOWN);
2671 if (scroll == GTK_SCROLL_STEP_LEFT ||
2672 scroll == GTK_SCROLL_STEP_RIGHT)
2675 gtk_widget_child_focus (toplevel,
2676 scroll == GTK_SCROLL_STEP_LEFT ?
2677 GTK_DIR_LEFT : GTK_DIR_RIGHT);
2683 if (! gtk_range_scroll (range, scroll))
2684 gtk_widget_error_bell (GTK_WIDGET (range));
2686 /* Policy DELAYED makes sense with key events,
2687 * but DISCONTINUOUS doesn't, so we update immediately
2690 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
2691 gtk_range_update_value (range);
2695 gtk_range_get_props (GtkRange *range,
2699 gint *trough_border,
2700 gint *stepper_spacing,
2701 gboolean *trough_under_steppers,
2702 gint *arrow_displacement_x,
2703 gint *arrow_displacement_y)
2705 GtkWidget *widget = GTK_WIDGET (range);
2706 gint tmp_slider_width, tmp_stepper_size, tmp_focus_width, tmp_trough_border;
2707 gint tmp_stepper_spacing, tmp_trough_under_steppers;
2708 gint tmp_arrow_displacement_x, tmp_arrow_displacement_y;
2710 gtk_widget_style_get (widget,
2711 "slider-width", &tmp_slider_width,
2712 "trough-border", &tmp_trough_border,
2713 "stepper-size", &tmp_stepper_size,
2714 "stepper-spacing", &tmp_stepper_spacing,
2715 "trough-under-steppers", &tmp_trough_under_steppers,
2716 "arrow-displacement-x", &tmp_arrow_displacement_x,
2717 "arrow-displacement-y", &tmp_arrow_displacement_y,
2720 if (tmp_stepper_spacing > 0)
2721 tmp_trough_under_steppers = FALSE;
2723 if (GTK_WIDGET_CAN_FOCUS (range))
2725 gint focus_line_width;
2728 gtk_widget_style_get (GTK_WIDGET (range),
2729 "focus-line-width", &focus_line_width,
2730 "focus-padding", &focus_padding,
2733 tmp_focus_width = focus_line_width + focus_padding;
2737 tmp_focus_width = 0;
2741 *slider_width = tmp_slider_width;
2744 *focus_width = tmp_focus_width;
2747 *trough_border = tmp_trough_border;
2750 *stepper_size = tmp_stepper_size;
2752 if (stepper_spacing)
2753 *stepper_spacing = tmp_stepper_spacing;
2755 if (trough_under_steppers)
2756 *trough_under_steppers = tmp_trough_under_steppers;
2758 if (arrow_displacement_x)
2759 *arrow_displacement_x = tmp_arrow_displacement_x;
2761 if (arrow_displacement_y)
2762 *arrow_displacement_y = tmp_arrow_displacement_y;
2765 #define POINT_IN_RECT(xcoord, ycoord, rect) \
2766 ((xcoord) >= (rect).x && \
2767 (xcoord) < ((rect).x + (rect).width) && \
2768 (ycoord) >= (rect).y && \
2769 (ycoord) < ((rect).y + (rect).height))
2771 /* Update mouse location, return TRUE if it changes */
2773 gtk_range_update_mouse_location (GtkRange *range)
2779 widget = GTK_WIDGET (range);
2781 old = range->layout->mouse_location;
2783 x = range->layout->mouse_x;
2784 y = range->layout->mouse_y;
2786 if (range->layout->grab_location != MOUSE_OUTSIDE)
2787 range->layout->mouse_location = range->layout->grab_location;
2788 else if (POINT_IN_RECT (x, y, range->layout->stepper_a))
2789 range->layout->mouse_location = MOUSE_STEPPER_A;
2790 else if (POINT_IN_RECT (x, y, range->layout->stepper_b))
2791 range->layout->mouse_location = MOUSE_STEPPER_B;
2792 else if (POINT_IN_RECT (x, y, range->layout->stepper_c))
2793 range->layout->mouse_location = MOUSE_STEPPER_C;
2794 else if (POINT_IN_RECT (x, y, range->layout->stepper_d))
2795 range->layout->mouse_location = MOUSE_STEPPER_D;
2796 else if (POINT_IN_RECT (x, y, range->layout->slider))
2797 range->layout->mouse_location = MOUSE_SLIDER;
2798 else if (POINT_IN_RECT (x, y, range->layout->trough))
2799 range->layout->mouse_location = MOUSE_TROUGH;
2800 else if (POINT_IN_RECT (x, y, widget->allocation))
2801 range->layout->mouse_location = MOUSE_WIDGET;
2803 range->layout->mouse_location = MOUSE_OUTSIDE;
2805 return old != range->layout->mouse_location;
2808 /* Clamp rect, border inside widget->allocation, such that we prefer
2809 * to take space from border not rect in all directions, and prefer to
2810 * give space to border over rect in one direction.
2813 clamp_dimensions (GtkWidget *widget,
2816 gboolean border_expands_horizontally)
2818 gint extra, shortage;
2820 g_return_if_fail (rect->x == 0);
2821 g_return_if_fail (rect->y == 0);
2822 g_return_if_fail (rect->width >= 0);
2823 g_return_if_fail (rect->height >= 0);
2827 extra = widget->allocation.width - border->left - border->right - rect->width;
2830 if (border_expands_horizontally)
2832 border->left += extra / 2;
2833 border->right += extra / 2 + extra % 2;
2837 rect->width += extra;
2841 /* See if we can fit rect, if not kill the border */
2842 shortage = rect->width - widget->allocation.width;
2845 rect->width = widget->allocation.width;
2846 /* lose the border */
2852 /* See if we can fit rect with borders */
2853 shortage = rect->width + border->left + border->right -
2854 widget->allocation.width;
2857 /* Shrink borders */
2858 border->left -= shortage / 2;
2859 border->right -= shortage / 2 + shortage % 2;
2865 extra = widget->allocation.height - border->top - border->bottom - rect->height;
2868 if (border_expands_horizontally)
2870 /* don't expand border vertically */
2871 rect->height += extra;
2875 border->top += extra / 2;
2876 border->bottom += extra / 2 + extra % 2;
2880 /* See if we can fit rect, if not kill the border */
2881 shortage = rect->height - widget->allocation.height;
2884 rect->height = widget->allocation.height;
2885 /* lose the border */
2891 /* See if we can fit rect with borders */
2892 shortage = rect->height + border->top + border->bottom -
2893 widget->allocation.height;
2896 /* Shrink borders */
2897 border->top -= shortage / 2;
2898 border->bottom -= shortage / 2 + shortage % 2;
2904 gtk_range_calc_request (GtkRange *range,
2909 gint stepper_spacing,
2910 GdkRectangle *range_rect,
2913 gboolean *has_steppers_ab,
2914 gboolean *has_steppers_cd,
2915 gint *slider_length_p)
2927 if (GTK_RANGE_GET_CLASS (range)->get_range_border)
2928 GTK_RANGE_GET_CLASS (range)->get_range_border (range, border);
2933 if (range->has_stepper_a)
2935 if (range->has_stepper_b)
2937 if (range->has_stepper_c)
2939 if (range->has_stepper_d)
2942 n_steppers = n_steppers_ab + n_steppers_cd;
2944 slider_length = range->min_slider_size;
2949 /* We never expand to fill available space in the small dimension
2950 * (i.e. vertical scrollbars are always a fixed width)
2952 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2954 range_rect->width = (focus_width + trough_border) * 2 + slider_width;
2955 range_rect->height = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
2957 if (n_steppers_ab > 0)
2958 range_rect->height += stepper_spacing;
2960 if (n_steppers_cd > 0)
2961 range_rect->height += stepper_spacing;
2965 range_rect->width = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
2966 range_rect->height = (focus_width + trough_border) * 2 + slider_width;
2968 if (n_steppers_ab > 0)
2969 range_rect->width += stepper_spacing;
2971 if (n_steppers_cd > 0)
2972 range_rect->width += stepper_spacing;
2976 *n_steppers_p = n_steppers;
2978 if (has_steppers_ab)
2979 *has_steppers_ab = (n_steppers_ab > 0);
2981 if (has_steppers_cd)
2982 *has_steppers_cd = (n_steppers_cd > 0);
2984 if (slider_length_p)
2985 *slider_length_p = slider_length;
2989 gtk_range_calc_layout (GtkRange *range,
2990 gdouble adjustment_value)
2992 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
2996 gboolean has_steppers_ab;
2997 gboolean has_steppers_cd;
2998 gboolean trough_under_steppers;
2999 GdkRectangle range_rect;
3000 GtkRangeLayout *layout;
3003 if (!range->need_recalc)
3006 /* If we have a too-small allocation, we prefer the steppers over
3007 * the trough/slider, probably the steppers are a more useful
3008 * feature in small spaces.
3010 * Also, we prefer to draw the range itself rather than the border
3011 * areas if there's a conflict, since the borders will be decoration
3012 * not controls. Though this depends on subclasses cooperating by
3013 * not drawing on range->range_rect.
3016 widget = GTK_WIDGET (range);
3017 layout = range->layout;
3019 gtk_range_get_props (range,
3020 &slider_width, &stepper_size,
3021 &focus_width, &trough_border,
3022 &stepper_spacing, &trough_under_steppers,
3025 gtk_range_calc_request (range,
3026 slider_width, stepper_size,
3027 focus_width, trough_border, stepper_spacing,
3028 &range_rect, &border, &n_steppers,
3029 &has_steppers_ab, &has_steppers_cd, &slider_length);
3031 /* We never expand to fill available space in the small dimension
3032 * (i.e. vertical scrollbars are always a fixed width)
3034 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3036 clamp_dimensions (widget, &range_rect, &border, TRUE);
3040 clamp_dimensions (widget, &range_rect, &border, FALSE);
3043 range_rect.x = border.left;
3044 range_rect.y = border.top;
3046 range->range_rect = range_rect;
3048 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3050 gint stepper_width, stepper_height;
3052 /* Steppers are the width of the range, and stepper_size in
3053 * height, or if we don't have enough height, divided equally
3054 * among available space.
3056 stepper_width = range_rect.width - focus_width * 2;
3058 if (trough_under_steppers)
3059 stepper_width -= trough_border * 2;
3061 if (stepper_width < 1)
3062 stepper_width = range_rect.width; /* screw the trough border */
3064 if (n_steppers == 0)
3065 stepper_height = 0; /* avoid divide by n_steppers */
3067 stepper_height = MIN (stepper_size, (range_rect.height / n_steppers));
3071 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3072 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3074 if (range->has_stepper_a)
3076 layout->stepper_a.width = stepper_width;
3077 layout->stepper_a.height = stepper_height;
3081 layout->stepper_a.width = 0;
3082 layout->stepper_a.height = 0;
3087 layout->stepper_b.x = layout->stepper_a.x;
3088 layout->stepper_b.y = layout->stepper_a.y + layout->stepper_a.height;
3090 if (range->has_stepper_b)
3092 layout->stepper_b.width = stepper_width;
3093 layout->stepper_b.height = stepper_height;
3097 layout->stepper_b.width = 0;
3098 layout->stepper_b.height = 0;
3103 if (range->has_stepper_d)
3105 layout->stepper_d.width = stepper_width;
3106 layout->stepper_d.height = stepper_height;
3110 layout->stepper_d.width = 0;
3111 layout->stepper_d.height = 0;
3114 layout->stepper_d.x = layout->stepper_a.x;
3115 layout->stepper_d.y = range_rect.y + range_rect.height - layout->stepper_d.height - focus_width - trough_border * trough_under_steppers;
3119 if (range->has_stepper_c)
3121 layout->stepper_c.width = stepper_width;
3122 layout->stepper_c.height = stepper_height;
3126 layout->stepper_c.width = 0;
3127 layout->stepper_c.height = 0;
3130 layout->stepper_c.x = layout->stepper_a.x;
3131 layout->stepper_c.y = layout->stepper_d.y - layout->stepper_c.height;
3133 /* Now the trough is the remaining space between steppers B and C,
3134 * if any, minus spacing
3136 layout->trough.x = range_rect.x;
3137 layout->trough.y = layout->stepper_b.y + layout->stepper_b.height + stepper_spacing * has_steppers_ab;
3138 layout->trough.width = range_rect.width;
3139 layout->trough.height = layout->stepper_c.y - layout->trough.y - stepper_spacing * has_steppers_cd;
3141 /* Slider fits into the trough, with stepper_spacing on either side,
3142 * and the size/position based on the adjustment or fixed, depending.
3144 layout->slider.x = layout->trough.x + focus_width + trough_border;
3145 layout->slider.width = layout->trough.width - (focus_width + trough_border) * 2;
3147 /* Compute slider position/length */
3149 gint y, bottom, top, height;
3151 top = layout->trough.y;
3152 bottom = layout->trough.y + layout->trough.height;
3154 if (! trough_under_steppers)
3156 top += trough_border;
3157 bottom -= trough_border;
3160 /* slider height is the fraction (page_size /
3161 * total_adjustment_range) times the trough height in pixels
3164 if (range->adjustment->upper - range->adjustment->lower != 0)
3165 height = ((bottom - top) * (range->adjustment->page_size /
3166 (range->adjustment->upper - range->adjustment->lower)));
3168 height = range->min_slider_size;
3170 if (height < range->min_slider_size ||
3171 range->slider_size_fixed)
3172 height = range->min_slider_size;
3174 height = MIN (height, layout->trough.height);
3178 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3179 y += (bottom - top - height) * ((adjustment_value - range->adjustment->lower) /
3180 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3182 y = CLAMP (y, top, bottom);
3184 if (should_invert (range))
3185 y = bottom - (y - top + height);
3187 layout->slider.y = y;
3188 layout->slider.height = height;
3190 /* These are publically exported */
3191 range->slider_start = layout->slider.y;
3192 range->slider_end = layout->slider.y + layout->slider.height;
3197 gint stepper_width, stepper_height;
3199 /* Steppers are the height of the range, and stepper_size in
3200 * width, or if we don't have enough width, divided equally
3201 * among available space.
3203 stepper_height = range_rect.height + focus_width * 2;
3205 if (trough_under_steppers)
3206 stepper_height -= trough_border * 2;
3208 if (stepper_height < 1)
3209 stepper_height = range_rect.height; /* screw the trough border */
3211 if (n_steppers == 0)
3212 stepper_width = 0; /* avoid divide by n_steppers */
3214 stepper_width = MIN (stepper_size, (range_rect.width / n_steppers));
3218 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3219 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3221 if (range->has_stepper_a)
3223 layout->stepper_a.width = stepper_width;
3224 layout->stepper_a.height = stepper_height;
3228 layout->stepper_a.width = 0;
3229 layout->stepper_a.height = 0;
3234 layout->stepper_b.x = layout->stepper_a.x + layout->stepper_a.width;
3235 layout->stepper_b.y = layout->stepper_a.y;
3237 if (range->has_stepper_b)
3239 layout->stepper_b.width = stepper_width;
3240 layout->stepper_b.height = stepper_height;
3244 layout->stepper_b.width = 0;
3245 layout->stepper_b.height = 0;
3250 if (range->has_stepper_d)
3252 layout->stepper_d.width = stepper_width;
3253 layout->stepper_d.height = stepper_height;
3257 layout->stepper_d.width = 0;
3258 layout->stepper_d.height = 0;
3261 layout->stepper_d.x = range_rect.x + range_rect.width - layout->stepper_d.width - focus_width - trough_border * trough_under_steppers;
3262 layout->stepper_d.y = layout->stepper_a.y;
3267 if (range->has_stepper_c)
3269 layout->stepper_c.width = stepper_width;
3270 layout->stepper_c.height = stepper_height;
3274 layout->stepper_c.width = 0;
3275 layout->stepper_c.height = 0;
3278 layout->stepper_c.x = layout->stepper_d.x - layout->stepper_c.width;
3279 layout->stepper_c.y = layout->stepper_a.y;
3281 /* Now the trough is the remaining space between steppers B and C,
3284 layout->trough.x = layout->stepper_b.x + layout->stepper_b.width + stepper_spacing * has_steppers_ab;
3285 layout->trough.y = range_rect.y;
3287 layout->trough.width = layout->stepper_c.x - layout->trough.x - stepper_spacing * has_steppers_cd;
3288 layout->trough.height = range_rect.height;
3290 /* Slider fits into the trough, with stepper_spacing on either side,
3291 * and the size/position based on the adjustment or fixed, depending.
3293 layout->slider.y = layout->trough.y + focus_width + trough_border;
3294 layout->slider.height = layout->trough.height - (focus_width + trough_border) * 2;
3296 /* Compute slider position/length */
3298 gint x, left, right, width;
3300 left = layout->trough.x;
3301 right = layout->trough.x + layout->trough.width;
3303 if (! trough_under_steppers)
3305 left += trough_border;
3306 right -= trough_border;
3309 /* slider width is the fraction (page_size /
3310 * total_adjustment_range) times the trough width in pixels
3313 if (range->adjustment->upper - range->adjustment->lower != 0)
3314 width = ((right - left) * (range->adjustment->page_size /
3315 (range->adjustment->upper - range->adjustment->lower)));
3317 width = range->min_slider_size;
3319 if (width < range->min_slider_size ||
3320 range->slider_size_fixed)
3321 width = range->min_slider_size;
3323 width = MIN (width, layout->trough.width);
3327 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3328 x += (right - left - width) * ((adjustment_value - range->adjustment->lower) /
3329 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3331 x = CLAMP (x, left, right);
3333 if (should_invert (range))
3334 x = right - (x - left + width);
3336 layout->slider.x = x;
3337 layout->slider.width = width;
3339 /* These are publically exported */
3340 range->slider_start = layout->slider.x;
3341 range->slider_end = layout->slider.x + layout->slider.width;
3345 gtk_range_update_mouse_location (range);
3347 switch (range->layout->upper_sensitivity)
3349 case GTK_SENSITIVITY_AUTO:
3350 range->layout->upper_sensitive =
3351 (range->adjustment->value <
3352 (range->adjustment->upper - range->adjustment->page_size));
3355 case GTK_SENSITIVITY_ON:
3356 range->layout->upper_sensitive = TRUE;
3359 case GTK_SENSITIVITY_OFF:
3360 range->layout->upper_sensitive = FALSE;
3364 switch (range->layout->lower_sensitivity)
3366 case GTK_SENSITIVITY_AUTO:
3367 range->layout->lower_sensitive =
3368 (range->adjustment->value > range->adjustment->lower);
3371 case GTK_SENSITIVITY_ON:
3372 range->layout->lower_sensitive = TRUE;
3375 case GTK_SENSITIVITY_OFF:
3376 range->layout->lower_sensitive = FALSE;
3381 static GdkRectangle*
3382 get_area (GtkRange *range,
3383 MouseLocation location)
3387 case MOUSE_STEPPER_A:
3388 return &range->layout->stepper_a;
3389 case MOUSE_STEPPER_B:
3390 return &range->layout->stepper_b;
3391 case MOUSE_STEPPER_C:
3392 return &range->layout->stepper_c;
3393 case MOUSE_STEPPER_D:
3394 return &range->layout->stepper_d;
3396 return &range->layout->trough;
3398 return &range->layout->slider;
3404 g_warning (G_STRLOC": bug");
3409 gtk_range_calc_marks (GtkRange *range)
3413 if (!range->layout->recalc_marks)
3416 range->layout->recalc_marks = FALSE;
3418 for (i = 0; i < range->layout->n_marks; i++)
3420 range->need_recalc = TRUE;
3421 gtk_range_calc_layout (range, range->layout->marks[i]);
3422 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
3423 range->layout->mark_pos[i] = range->layout->slider.x + range->layout->slider.width / 2;
3425 range->layout->mark_pos[i] = range->layout->slider.y + range->layout->slider.height / 2;
3428 range->need_recalc = TRUE;
3432 gtk_range_real_change_value (GtkRange *range,
3433 GtkScrollType scroll,
3436 /* potentially adjust the bounds _before we clamp */
3437 g_signal_emit (range, signals[ADJUST_BOUNDS], 0, value);
3439 if (range->layout->restrict_to_fill_level)
3440 value = MIN (value, MAX (range->adjustment->lower,
3441 range->layout->fill_level));
3443 value = CLAMP (value, range->adjustment->lower,
3444 (range->adjustment->upper - range->adjustment->page_size));
3446 if (range->round_digits >= 0)
3451 i = range->round_digits;
3456 value = floor ((value * power) + 0.5) / power;
3459 if (range->adjustment->value != value)
3461 range->need_recalc = TRUE;
3463 gtk_widget_queue_draw (GTK_WIDGET (range));
3465 switch (range->update_policy)
3467 case GTK_UPDATE_CONTINUOUS:
3468 gtk_adjustment_set_value (range->adjustment, value);
3471 /* Delayed means we update after a period of inactivity */
3472 case GTK_UPDATE_DELAYED:
3473 gtk_range_reset_update_timer (range);
3476 /* Discontinuous means we update on button release */
3477 case GTK_UPDATE_DISCONTINUOUS:
3478 /* don't emit value_changed signal */
3479 range->adjustment->value = value;
3480 range->update_pending = TRUE;
3488 gtk_range_update_value (GtkRange *range)
3490 gtk_range_remove_update_timer (range);
3492 if (range->update_pending)
3494 gtk_adjustment_value_changed (range->adjustment);
3496 range->update_pending = FALSE;
3500 struct _GtkRangeStepTimer
3507 second_timeout (gpointer data)
3511 range = GTK_RANGE (data);
3512 gtk_range_scroll (range, range->timer->step);
3518 initial_timeout (gpointer data)
3521 GtkSettings *settings;
3524 settings = gtk_widget_get_settings (GTK_WIDGET (data));
3525 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3527 range = GTK_RANGE (data);
3528 range->timer->timeout_id = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3536 gtk_range_add_step_timer (GtkRange *range,
3539 GtkSettings *settings;
3542 g_return_if_fail (range->timer == NULL);
3543 g_return_if_fail (step != GTK_SCROLL_NONE);
3545 settings = gtk_widget_get_settings (GTK_WIDGET (range));
3546 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
3548 range->timer = g_new (GtkRangeStepTimer, 1);
3550 range->timer->timeout_id = gdk_threads_add_timeout (timeout,
3553 range->timer->step = step;
3555 gtk_range_scroll (range, range->timer->step);
3559 gtk_range_remove_step_timer (GtkRange *range)
3563 if (range->timer->timeout_id != 0)
3564 g_source_remove (range->timer->timeout_id);
3566 g_free (range->timer);
3568 range->timer = NULL;
3573 update_timeout (gpointer data)
3577 range = GTK_RANGE (data);
3578 gtk_range_update_value (range);
3579 range->update_timeout_id = 0;
3586 gtk_range_reset_update_timer (GtkRange *range)
3588 gtk_range_remove_update_timer (range);
3590 range->update_timeout_id = gdk_threads_add_timeout (UPDATE_DELAY,
3596 gtk_range_remove_update_timer (GtkRange *range)
3598 if (range->update_timeout_id != 0)
3600 g_source_remove (range->update_timeout_id);
3601 range->update_timeout_id = 0;
3606 _gtk_range_set_stop_values (GtkRange *range,
3612 g_free (range->layout->marks);
3613 range->layout->marks = g_new (gdouble, n_values);
3615 g_free (range->layout->mark_pos);
3616 range->layout->mark_pos = g_new (gint, n_values);
3618 range->layout->n_marks = n_values;
3620 for (i = 0; i < n_values; i++)
3621 range->layout->marks[i] = values[i];
3623 range->layout->recalc_marks = TRUE;
3627 _gtk_range_get_stop_positions (GtkRange *range,
3630 gtk_range_calc_marks (range);
3633 *values = g_memdup (range->layout->mark_pos, range->layout->n_marks * sizeof (gint));
3635 return range->layout->n_marks;
3638 #define __GTK_RANGE_C__
3639 #include "gtkaliasdef.c"