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_flippable:
848 * @range: a #GtkRange
849 * @flippable: %TRUE to make the range flippable
851 * If a range is flippable, it will switch its direction if it is
852 * horizontal and its direction is %GTK_TEXT_DIR_RTL.
854 * See gtk_widget_get_direction().
859 gtk_range_set_flippable (GtkRange *range,
862 g_return_if_fail (GTK_IS_RANGE (range));
864 flippable = flippable ? TRUE : FALSE;
866 if (flippable != range->flippable)
868 range->flippable = flippable;
870 gtk_widget_queue_draw (GTK_WIDGET (range));
875 * gtk_range_get_flippable:
876 * @range: a #GtkRange
878 * Gets the value set by gtk_range_set_flippable().
880 * Return value: %TRUE if the range is flippable
885 gtk_range_get_flippable (GtkRange *range)
887 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
889 return range->flippable;
893 * gtk_range_set_lower_stepper_sensitivity:
894 * @range: a #GtkRange
895 * @sensitivity: the lower stepper's sensitivity policy.
897 * Sets the sensitivity policy for the stepper that points to the
898 * 'lower' end of the GtkRange's adjustment.
903 gtk_range_set_lower_stepper_sensitivity (GtkRange *range,
904 GtkSensitivityType sensitivity)
906 g_return_if_fail (GTK_IS_RANGE (range));
908 if (range->layout->lower_sensitivity != sensitivity)
910 range->layout->lower_sensitivity = sensitivity;
912 range->need_recalc = TRUE;
913 gtk_range_calc_layout (range, range->adjustment->value);
914 gtk_widget_queue_draw (GTK_WIDGET (range));
916 g_object_notify (G_OBJECT (range), "lower-stepper-sensitivity");
921 * gtk_range_get_lower_stepper_sensitivity:
922 * @range: a #GtkRange
924 * Gets the sensitivity policy for the stepper that points to the
925 * 'lower' end of the GtkRange's adjustment.
927 * Return value: The lower stepper's sensitivity policy.
932 gtk_range_get_lower_stepper_sensitivity (GtkRange *range)
934 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
936 return range->layout->lower_sensitivity;
940 * gtk_range_set_upper_stepper_sensitivity:
941 * @range: a #GtkRange
942 * @sensitivity: the upper stepper's sensitivity policy.
944 * Sets the sensitivity policy for the stepper that points to the
945 * 'upper' end of the GtkRange's adjustment.
950 gtk_range_set_upper_stepper_sensitivity (GtkRange *range,
951 GtkSensitivityType sensitivity)
953 g_return_if_fail (GTK_IS_RANGE (range));
955 if (range->layout->upper_sensitivity != sensitivity)
957 range->layout->upper_sensitivity = sensitivity;
959 range->need_recalc = TRUE;
960 gtk_range_calc_layout (range, range->adjustment->value);
961 gtk_widget_queue_draw (GTK_WIDGET (range));
963 g_object_notify (G_OBJECT (range), "upper-stepper-sensitivity");
968 * gtk_range_get_upper_stepper_sensitivity:
969 * @range: a #GtkRange
971 * Gets the sensitivity policy for the stepper that points to the
972 * 'upper' end of the GtkRange's adjustment.
974 * Return value: The upper stepper's sensitivity policy.
979 gtk_range_get_upper_stepper_sensitivity (GtkRange *range)
981 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
983 return range->layout->upper_sensitivity;
987 * gtk_range_set_increments:
988 * @range: a #GtkRange
992 * Sets the step and page sizes for the range.
993 * The step size is used when the user clicks the #GtkScrollbar
994 * arrows or moves #GtkScale via arrow keys. The page size
995 * is used for example when moving via Page Up or Page Down keys.
998 gtk_range_set_increments (GtkRange *range,
1002 g_return_if_fail (GTK_IS_RANGE (range));
1004 range->adjustment->step_increment = step;
1005 range->adjustment->page_increment = page;
1007 gtk_adjustment_changed (range->adjustment);
1011 * gtk_range_set_range:
1012 * @range: a #GtkRange
1013 * @min: minimum range value
1014 * @max: maximum range value
1016 * Sets the allowable values in the #GtkRange, and clamps the range
1017 * value to be between @min and @max. (If the range has a non-zero
1018 * page size, it is clamped between @min and @max - page-size.)
1021 gtk_range_set_range (GtkRange *range,
1027 g_return_if_fail (GTK_IS_RANGE (range));
1028 g_return_if_fail (min < max);
1030 range->adjustment->lower = min;
1031 range->adjustment->upper = max;
1033 value = range->adjustment->value;
1035 if (range->layout->restrict_to_fill_level)
1036 value = MIN (value, MAX (range->adjustment->lower,
1037 range->layout->fill_level));
1039 value = CLAMP (value, range->adjustment->lower,
1040 (range->adjustment->upper - range->adjustment->page_size));
1042 gtk_adjustment_set_value (range->adjustment, value);
1043 gtk_adjustment_changed (range->adjustment);
1047 * gtk_range_set_value:
1048 * @range: a #GtkRange
1049 * @value: new value of the range
1051 * Sets the current value of the range; if the value is outside the
1052 * minimum or maximum range values, it will be clamped to fit inside
1053 * them. The range emits the #GtkRange::value-changed signal if the
1057 gtk_range_set_value (GtkRange *range,
1060 g_return_if_fail (GTK_IS_RANGE (range));
1062 if (range->layout->restrict_to_fill_level)
1063 value = MIN (value, MAX (range->adjustment->lower,
1064 range->layout->fill_level));
1066 value = CLAMP (value, range->adjustment->lower,
1067 (range->adjustment->upper - range->adjustment->page_size));
1069 gtk_adjustment_set_value (range->adjustment, value);
1073 * gtk_range_get_value:
1074 * @range: a #GtkRange
1076 * Gets the current value of the range.
1078 * Return value: current value of the range.
1081 gtk_range_get_value (GtkRange *range)
1083 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1085 return range->adjustment->value;
1089 * gtk_range_set_show_fill_level:
1090 * @range: A #GtkRange
1091 * @show_fill_level: Whether a fill level indicator graphics is shown.
1093 * Sets whether a graphical fill level is show on the trough. See
1094 * gtk_range_set_fill_level() for a general description of the fill
1100 gtk_range_set_show_fill_level (GtkRange *range,
1101 gboolean show_fill_level)
1103 g_return_if_fail (GTK_IS_RANGE (range));
1105 show_fill_level = show_fill_level ? TRUE : FALSE;
1107 if (show_fill_level != range->layout->show_fill_level)
1109 range->layout->show_fill_level = show_fill_level;
1110 g_object_notify (G_OBJECT (range), "show-fill-level");
1111 gtk_widget_queue_draw (GTK_WIDGET (range));
1116 * gtk_range_get_show_fill_level:
1117 * @range: A #GtkRange
1119 * Gets whether the range displays the fill level graphically.
1121 * Return value: %TRUE if @range shows the fill level.
1126 gtk_range_get_show_fill_level (GtkRange *range)
1128 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1130 return range->layout->show_fill_level;
1134 * gtk_range_set_restrict_to_fill_level:
1135 * @range: A #GtkRange
1136 * @restrict_to_fill_level: Whether the fill level restricts slider movement.
1138 * Sets whether the slider is restricted to the fill level. See
1139 * gtk_range_set_fill_level() for a general description of the fill
1145 gtk_range_set_restrict_to_fill_level (GtkRange *range,
1146 gboolean restrict_to_fill_level)
1148 g_return_if_fail (GTK_IS_RANGE (range));
1150 restrict_to_fill_level = restrict_to_fill_level ? TRUE : FALSE;
1152 if (restrict_to_fill_level != range->layout->restrict_to_fill_level)
1154 range->layout->restrict_to_fill_level = restrict_to_fill_level;
1155 g_object_notify (G_OBJECT (range), "restrict-to-fill-level");
1157 gtk_range_set_value (range, gtk_range_get_value (range));
1162 * gtk_range_get_restrict_to_fill_level:
1163 * @range: A #GtkRange
1165 * Gets whether the range is restricted to the fill level.
1167 * Return value: %TRUE if @range is restricted to the fill level.
1172 gtk_range_get_restrict_to_fill_level (GtkRange *range)
1174 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1176 return range->layout->restrict_to_fill_level;
1180 * gtk_range_set_fill_level:
1181 * @range: a #GtkRange
1182 * @fill_level: the new position of the fill level indicator
1184 * Set the new position of the fill level indicator.
1186 * The "fill level" is probably best described by its most prominent
1187 * use case, which is an indicator for the amount of pre-buffering in
1188 * a streaming media player. In that use case, the value of the range
1189 * would indicate the current play position, and the fill level would
1190 * be the position up to which the file/stream has been downloaded.
1192 * This amount of prebuffering can be displayed on the range's trough
1193 * and is themeable separately from the trough. To enable fill level
1194 * display, use gtk_range_set_show_fill_level(). The range defaults
1195 * to not showing the fill level.
1197 * Additionally, it's possible to restrict the range's slider position
1198 * to values which are smaller than the fill level. This is controller
1199 * by gtk_range_set_restrict_to_fill_level() and is by default
1205 gtk_range_set_fill_level (GtkRange *range,
1208 g_return_if_fail (GTK_IS_RANGE (range));
1210 if (fill_level != range->layout->fill_level)
1212 range->layout->fill_level = fill_level;
1213 g_object_notify (G_OBJECT (range), "fill-level");
1215 if (range->layout->show_fill_level)
1216 gtk_widget_queue_draw (GTK_WIDGET (range));
1218 if (range->layout->restrict_to_fill_level)
1219 gtk_range_set_value (range, gtk_range_get_value (range));
1224 * gtk_range_get_fill_level:
1225 * @range : A #GtkRange
1227 * Gets the current position of the fill level indicator.
1229 * Return value: The current fill level
1234 gtk_range_get_fill_level (GtkRange *range)
1236 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1238 return range->layout->fill_level;
1242 should_invert (GtkRange *range)
1244 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1246 (range->inverted && !range->flippable) ||
1247 (range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_LTR) ||
1248 (!range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_RTL);
1250 return range->inverted;
1254 gtk_range_destroy (GtkObject *object)
1256 GtkRange *range = GTK_RANGE (object);
1258 gtk_range_remove_step_timer (range);
1259 gtk_range_remove_update_timer (range);
1261 if (range->layout->repaint_id)
1262 g_source_remove (range->layout->repaint_id);
1263 range->layout->repaint_id = 0;
1265 if (range->adjustment)
1267 g_signal_handlers_disconnect_by_func (range->adjustment,
1268 gtk_range_adjustment_changed,
1270 g_signal_handlers_disconnect_by_func (range->adjustment,
1271 gtk_range_adjustment_value_changed,
1273 g_object_unref (range->adjustment);
1274 range->adjustment = NULL;
1277 if (range->layout->n_marks)
1279 g_free (range->layout->marks);
1280 range->layout->marks = NULL;
1281 g_free (range->layout->mark_pos);
1282 range->layout->mark_pos = NULL;
1283 range->layout->n_marks = 0;
1286 GTK_OBJECT_CLASS (gtk_range_parent_class)->destroy (object);
1290 gtk_range_size_request (GtkWidget *widget,
1291 GtkRequisition *requisition)
1294 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
1295 GdkRectangle range_rect;
1298 range = GTK_RANGE (widget);
1300 gtk_range_get_props (range,
1301 &slider_width, &stepper_size,
1302 &focus_width, &trough_border,
1303 &stepper_spacing, NULL,
1306 gtk_range_calc_request (range,
1307 slider_width, stepper_size,
1308 focus_width, trough_border, stepper_spacing,
1309 &range_rect, &border, NULL, NULL, NULL, NULL);
1311 requisition->width = range_rect.width + border.left + border.right;
1312 requisition->height = range_rect.height + border.top + border.bottom;
1316 gtk_range_size_allocate (GtkWidget *widget,
1317 GtkAllocation *allocation)
1321 range = GTK_RANGE (widget);
1323 widget->allocation = *allocation;
1325 range->layout->recalc_marks = TRUE;
1327 range->need_recalc = TRUE;
1328 gtk_range_calc_layout (range, range->adjustment->value);
1330 if (GTK_WIDGET_REALIZED (range))
1331 gdk_window_move_resize (range->event_window,
1332 widget->allocation.x,
1333 widget->allocation.y,
1334 widget->allocation.width,
1335 widget->allocation.height);
1339 gtk_range_realize (GtkWidget *widget)
1342 GdkWindowAttr attributes;
1343 gint attributes_mask;
1345 range = GTK_RANGE (widget);
1347 gtk_range_calc_layout (range, range->adjustment->value);
1349 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1351 widget->window = gtk_widget_get_parent_window (widget);
1352 g_object_ref (widget->window);
1354 attributes.window_type = GDK_WINDOW_CHILD;
1355 attributes.x = widget->allocation.x;
1356 attributes.y = widget->allocation.y;
1357 attributes.width = widget->allocation.width;
1358 attributes.height = widget->allocation.height;
1359 attributes.wclass = GDK_INPUT_ONLY;
1360 attributes.event_mask = gtk_widget_get_events (widget);
1361 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1362 GDK_BUTTON_RELEASE_MASK |
1363 GDK_ENTER_NOTIFY_MASK |
1364 GDK_LEAVE_NOTIFY_MASK |
1365 GDK_POINTER_MOTION_MASK |
1366 GDK_POINTER_MOTION_HINT_MASK);
1368 attributes_mask = GDK_WA_X | GDK_WA_Y;
1370 range->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1371 &attributes, attributes_mask);
1372 gdk_window_set_user_data (range->event_window, range);
1374 widget->style = gtk_style_attach (widget->style, widget->window);
1378 gtk_range_unrealize (GtkWidget *widget)
1380 GtkRange *range = GTK_RANGE (widget);
1382 gtk_range_remove_step_timer (range);
1383 gtk_range_remove_update_timer (range);
1385 gdk_window_set_user_data (range->event_window, NULL);
1386 gdk_window_destroy (range->event_window);
1387 range->event_window = NULL;
1389 GTK_WIDGET_CLASS (gtk_range_parent_class)->unrealize (widget);
1393 gtk_range_map (GtkWidget *widget)
1395 GtkRange *range = GTK_RANGE (widget);
1397 gdk_window_show (range->event_window);
1399 GTK_WIDGET_CLASS (gtk_range_parent_class)->map (widget);
1403 gtk_range_unmap (GtkWidget *widget)
1405 GtkRange *range = GTK_RANGE (widget);
1407 stop_scrolling (range);
1409 gdk_window_hide (range->event_window);
1411 GTK_WIDGET_CLASS (gtk_range_parent_class)->unmap (widget);
1414 static const gchar *
1415 gtk_range_get_slider_detail (GtkRange *range)
1417 const gchar *slider_detail;
1419 if (range->layout->slider_detail_quark)
1420 return g_quark_to_string (range->layout->slider_detail_quark);
1422 slider_detail = GTK_RANGE_GET_CLASS (range)->slider_detail;
1424 if (slider_detail && slider_detail[0] == 'X')
1426 gchar *detail = g_strdup (slider_detail);
1428 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1430 range->layout->slider_detail_quark = g_quark_from_string (detail);
1434 return g_quark_to_string (range->layout->slider_detail_quark);
1437 return slider_detail;
1440 static const gchar *
1441 gtk_range_get_stepper_detail (GtkRange *range)
1443 const gchar *stepper_detail;
1445 if (range->layout->stepper_detail_quark)
1446 return g_quark_to_string (range->layout->stepper_detail_quark);
1448 stepper_detail = GTK_RANGE_GET_CLASS (range)->stepper_detail;
1450 if (stepper_detail && stepper_detail[0] == 'X')
1452 gchar *detail = g_strdup (stepper_detail);
1454 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1456 range->layout->stepper_detail_quark = g_quark_from_string (detail);
1460 return g_quark_to_string (range->layout->stepper_detail_quark);
1463 return stepper_detail;
1467 draw_stepper (GtkRange *range,
1469 GtkArrowType arrow_type,
1471 gboolean prelighted,
1474 GtkStateType state_type;
1475 GtkShadowType shadow_type;
1476 GdkRectangle intersection;
1477 GtkWidget *widget = GTK_WIDGET (range);
1478 gfloat arrow_scaling;
1485 gboolean arrow_sensitive = TRUE;
1487 /* More to get the right clip region than for efficiency */
1488 if (!gdk_rectangle_intersect (area, rect, &intersection))
1491 intersection.x += widget->allocation.x;
1492 intersection.y += widget->allocation.y;
1494 if ((!range->inverted && (arrow_type == GTK_ARROW_DOWN ||
1495 arrow_type == GTK_ARROW_RIGHT)) ||
1496 (range->inverted && (arrow_type == GTK_ARROW_UP ||
1497 arrow_type == GTK_ARROW_LEFT)))
1499 arrow_sensitive = range->layout->upper_sensitive;
1503 arrow_sensitive = range->layout->lower_sensitive;
1506 if (!GTK_WIDGET_IS_SENSITIVE (range) || !arrow_sensitive)
1507 state_type = GTK_STATE_INSENSITIVE;
1509 state_type = GTK_STATE_ACTIVE;
1510 else if (prelighted)
1511 state_type = GTK_STATE_PRELIGHT;
1513 state_type = GTK_STATE_NORMAL;
1515 if (clicked && arrow_sensitive)
1516 shadow_type = GTK_SHADOW_IN;
1518 shadow_type = GTK_SHADOW_OUT;
1520 gtk_paint_box (widget->style,
1522 state_type, shadow_type,
1523 &intersection, widget,
1524 gtk_range_get_stepper_detail (range),
1525 widget->allocation.x + rect->x,
1526 widget->allocation.y + rect->y,
1530 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
1532 arrow_width = rect->width * arrow_scaling;
1533 arrow_height = rect->height * arrow_scaling;
1534 arrow_x = widget->allocation.x + rect->x + (rect->width - arrow_width) / 2;
1535 arrow_y = widget->allocation.y + rect->y + (rect->height - arrow_height) / 2;
1537 if (clicked && arrow_sensitive)
1539 gint arrow_displacement_x;
1540 gint arrow_displacement_y;
1542 gtk_range_get_props (GTK_RANGE (widget),
1543 NULL, NULL, NULL, NULL, NULL, NULL,
1544 &arrow_displacement_x, &arrow_displacement_y);
1546 arrow_x += arrow_displacement_x;
1547 arrow_y += arrow_displacement_y;
1550 gtk_paint_arrow (widget->style,
1552 state_type, shadow_type,
1553 &intersection, widget,
1554 gtk_range_get_stepper_detail (range),
1557 arrow_x, arrow_y, arrow_width, arrow_height);
1561 gtk_range_expose (GtkWidget *widget,
1562 GdkEventExpose *event)
1564 GtkRange *range = GTK_RANGE (widget);
1567 GtkShadowType shadow_type;
1568 GdkRectangle expose_area; /* Relative to widget->allocation */
1570 gint focus_line_width = 0;
1571 gint focus_padding = 0;
1572 gboolean touchscreen;
1574 g_object_get (gtk_widget_get_settings (widget),
1575 "gtk-touchscreen-mode", &touchscreen,
1577 if (GTK_WIDGET_CAN_FOCUS (range))
1578 gtk_widget_style_get (GTK_WIDGET (range),
1579 "focus-line-width", &focus_line_width,
1580 "focus-padding", &focus_padding,
1583 /* we're now exposing, so there's no need to force early repaints */
1584 if (range->layout->repaint_id)
1585 g_source_remove (range->layout->repaint_id);
1586 range->layout->repaint_id = 0;
1588 expose_area = event->area;
1589 expose_area.x -= widget->allocation.x;
1590 expose_area.y -= widget->allocation.y;
1592 gtk_range_calc_marks (range);
1593 gtk_range_calc_layout (range, range->adjustment->value);
1595 sensitive = GTK_WIDGET_IS_SENSITIVE (widget);
1597 /* Just to be confusing, we draw the trough for the whole
1598 * range rectangle, not the trough rectangle (the trough
1599 * rectangle is just for hit detection)
1601 /* The gdk_rectangle_intersect is more to get the right
1602 * clip region (limited to range_rect) than for efficiency
1604 if (gdk_rectangle_intersect (&expose_area, &range->range_rect,
1607 gint x = (widget->allocation.x + range->range_rect.x +
1608 focus_line_width + focus_padding);
1609 gint y = (widget->allocation.y + range->range_rect.y +
1610 focus_line_width + focus_padding);
1611 gint width = (range->range_rect.width -
1612 2 * (focus_line_width + focus_padding));
1613 gint height = (range->range_rect.height -
1614 2 * (focus_line_width + focus_padding));
1615 gboolean trough_side_details;
1616 gboolean trough_under_steppers;
1618 gint stepper_spacing;
1620 area.x += widget->allocation.x;
1621 area.y += widget->allocation.y;
1623 gtk_widget_style_get (GTK_WIDGET (range),
1624 "trough-side-details", &trough_side_details,
1625 "trough-under-steppers", &trough_under_steppers,
1626 "stepper-size", &stepper_size,
1627 "stepper-spacing", &stepper_spacing,
1630 if (stepper_spacing > 0)
1631 trough_under_steppers = FALSE;
1633 if (! trough_under_steppers)
1638 if (range->has_stepper_a)
1639 offset += stepper_size;
1641 if (range->has_stepper_b)
1642 offset += stepper_size;
1646 if (range->has_stepper_c)
1647 shorter += stepper_size;
1649 if (range->has_stepper_d)
1650 shorter += stepper_size;
1652 if (range->has_stepper_a || range->has_stepper_b)
1654 offset += stepper_spacing;
1655 shorter += stepper_spacing;
1658 if (range->has_stepper_c || range->has_stepper_d)
1660 shorter += stepper_spacing;
1663 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1675 if (! trough_side_details)
1677 gtk_paint_box (widget->style,
1679 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1681 &area, GTK_WIDGET(range), "trough",
1687 gint trough_change_pos_x = width;
1688 gint trough_change_pos_y = height;
1690 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1691 trough_change_pos_x = (range->layout->slider.x +
1692 range->layout->slider.width / 2 -
1693 (x - widget->allocation.x));
1695 trough_change_pos_y = (range->layout->slider.y +
1696 range->layout->slider.height / 2 -
1697 (y - widget->allocation.y));
1699 gtk_paint_box (widget->style,
1701 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1703 &area, GTK_WIDGET (range),
1704 should_invert (range) ? "trough-upper" : "trough-lower",
1706 trough_change_pos_x, trough_change_pos_y);
1708 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1709 trough_change_pos_y = 0;
1711 trough_change_pos_x = 0;
1713 gtk_paint_box (widget->style,
1715 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1717 &area, GTK_WIDGET (range),
1718 should_invert (range) ? "trough-lower" : "trough-upper",
1719 x + trough_change_pos_x, y + trough_change_pos_y,
1720 width - trough_change_pos_x,
1721 height - trough_change_pos_y);
1724 if (range->layout->show_fill_level &&
1725 range->adjustment->upper - range->adjustment->page_size -
1726 range->adjustment->lower != 0)
1728 gdouble fill_level = range->layout->fill_level;
1731 gint fill_width = width;
1732 gint fill_height = height;
1735 fill_level = CLAMP (fill_level, range->adjustment->lower,
1736 range->adjustment->upper -
1737 range->adjustment->page_size);
1739 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1741 fill_x = widget->allocation.x + range->layout->trough.x;
1742 fill_width = (range->layout->slider.width +
1743 (fill_level - range->adjustment->lower) /
1744 (range->adjustment->upper -
1745 range->adjustment->lower -
1746 range->adjustment->page_size) *
1747 (range->layout->trough.width -
1748 range->layout->slider.width));
1750 if (should_invert (range))
1751 fill_x += range->layout->trough.width - fill_width;
1755 fill_y = widget->allocation.y + range->layout->trough.y;
1756 fill_height = (range->layout->slider.height +
1757 (fill_level - range->adjustment->lower) /
1758 (range->adjustment->upper -
1759 range->adjustment->lower -
1760 range->adjustment->page_size) *
1761 (range->layout->trough.height -
1762 range->layout->slider.height));
1764 if (should_invert (range))
1765 fill_y += range->layout->trough.height - fill_height;
1768 if (fill_level < range->adjustment->upper - range->adjustment->page_size)
1769 fill_detail = "trough-fill-level-full";
1771 fill_detail = "trough-fill-level";
1773 gtk_paint_box (widget->style,
1775 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1777 &area, GTK_WIDGET (range), fill_detail,
1779 fill_width, fill_height);
1783 GTK_WIDGET_HAS_FOCUS (range))
1784 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
1785 &area, widget, "trough",
1786 widget->allocation.x + range->range_rect.x,
1787 widget->allocation.y + range->range_rect.y,
1788 range->range_rect.width,
1789 range->range_rect.height);
1792 shadow_type = GTK_SHADOW_OUT;
1795 state = GTK_STATE_INSENSITIVE;
1796 else if (!touchscreen && range->layout->mouse_location == MOUSE_SLIDER)
1797 state = GTK_STATE_PRELIGHT;
1799 state = GTK_STATE_NORMAL;
1801 if (range->layout->grab_location == MOUSE_SLIDER)
1803 gboolean activate_slider;
1805 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
1807 if (activate_slider)
1809 state = GTK_STATE_ACTIVE;
1810 shadow_type = GTK_SHADOW_IN;
1814 if (gdk_rectangle_intersect (&expose_area,
1815 &range->layout->slider,
1818 area.x += widget->allocation.x;
1819 area.y += widget->allocation.y;
1821 gtk_paint_slider (widget->style,
1827 gtk_range_get_slider_detail (range),
1828 widget->allocation.x + range->layout->slider.x,
1829 widget->allocation.y + range->layout->slider.y,
1830 range->layout->slider.width,
1831 range->layout->slider.height,
1832 range->orientation);
1835 if (range->has_stepper_a)
1836 draw_stepper (range, &range->layout->stepper_a,
1837 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
1838 range->layout->grab_location == MOUSE_STEPPER_A,
1839 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_A,
1842 if (range->has_stepper_b)
1843 draw_stepper (range, &range->layout->stepper_b,
1844 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
1845 range->layout->grab_location == MOUSE_STEPPER_B,
1846 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_B,
1849 if (range->has_stepper_c)
1850 draw_stepper (range, &range->layout->stepper_c,
1851 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
1852 range->layout->grab_location == MOUSE_STEPPER_C,
1853 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_C,
1856 if (range->has_stepper_d)
1857 draw_stepper (range, &range->layout->stepper_d,
1858 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
1859 range->layout->grab_location == MOUSE_STEPPER_D,
1860 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_D,
1867 range_grab_add (GtkRange *range,
1868 MouseLocation location,
1871 /* we don't actually gtk_grab, since a button is down */
1873 gtk_grab_add (GTK_WIDGET (range));
1875 range->layout->grab_location = location;
1876 range->layout->grab_button = button;
1878 if (gtk_range_update_mouse_location (range))
1879 gtk_widget_queue_draw (GTK_WIDGET (range));
1883 range_grab_remove (GtkRange *range)
1885 MouseLocation location;
1887 gtk_grab_remove (GTK_WIDGET (range));
1889 location = range->layout->grab_location;
1890 range->layout->grab_location = MOUSE_OUTSIDE;
1891 range->layout->grab_button = 0;
1893 if (gtk_range_update_mouse_location (range) ||
1894 location != MOUSE_OUTSIDE)
1895 gtk_widget_queue_draw (GTK_WIDGET (range));
1898 static GtkScrollType
1899 range_get_scroll_for_grab (GtkRange *range)
1903 invert = should_invert (range);
1904 switch (range->layout->grab_location)
1906 /* Backward stepper */
1907 case MOUSE_STEPPER_A:
1908 case MOUSE_STEPPER_C:
1909 switch (range->layout->grab_button)
1912 return invert ? GTK_SCROLL_STEP_FORWARD : GTK_SCROLL_STEP_BACKWARD;
1915 return invert ? GTK_SCROLL_PAGE_FORWARD : GTK_SCROLL_PAGE_BACKWARD;
1918 return invert ? GTK_SCROLL_END : GTK_SCROLL_START;
1923 /* Forward stepper */
1924 case MOUSE_STEPPER_B:
1925 case MOUSE_STEPPER_D:
1926 switch (range->layout->grab_button)
1929 return invert ? GTK_SCROLL_STEP_BACKWARD : GTK_SCROLL_STEP_FORWARD;
1932 return invert ? GTK_SCROLL_PAGE_BACKWARD : GTK_SCROLL_PAGE_FORWARD;
1935 return invert ? GTK_SCROLL_START : GTK_SCROLL_END;
1943 if (range->trough_click_forward)
1944 return GTK_SCROLL_PAGE_FORWARD;
1946 return GTK_SCROLL_PAGE_BACKWARD;
1956 return GTK_SCROLL_NONE;
1960 coord_to_value (GtkRange *range,
1969 gint trough_under_steppers;
1971 if (range->orientation == GTK_ORIENTATION_VERTICAL)
1973 trough_length = range->layout->trough.height;
1974 trough_start = range->layout->trough.y;
1975 slider_length = range->layout->slider.height;
1979 trough_length = range->layout->trough.width;
1980 trough_start = range->layout->trough.x;
1981 slider_length = range->layout->slider.width;
1984 gtk_range_get_props (range, NULL, NULL, NULL, &trough_border, NULL,
1985 &trough_under_steppers, NULL, NULL);
1987 if (! trough_under_steppers)
1989 trough_start += trough_border;
1990 trough_length -= 2 * trough_border;
1993 if (trough_length == slider_length)
1996 frac = (MAX (0, coord - trough_start) /
1997 (gdouble) (trough_length - slider_length));
1999 if (should_invert (range))
2002 value = range->adjustment->lower + frac * (range->adjustment->upper -
2003 range->adjustment->lower -
2004 range->adjustment->page_size);
2010 gtk_range_key_press (GtkWidget *widget,
2013 GtkRange *range = GTK_RANGE (widget);
2015 if (event->keyval == GDK_Escape &&
2016 range->layout->grab_location != MOUSE_OUTSIDE)
2018 stop_scrolling (range);
2020 update_slider_position (range,
2021 range->slide_initial_coordinate,
2022 range->slide_initial_coordinate);
2027 return GTK_WIDGET_CLASS (gtk_range_parent_class)->key_press_event (widget, event);
2031 gtk_range_button_press (GtkWidget *widget,
2032 GdkEventButton *event)
2034 GtkRange *range = GTK_RANGE (widget);
2036 if (!GTK_WIDGET_HAS_FOCUS (widget))
2037 gtk_widget_grab_focus (widget);
2039 /* ignore presses when we're already doing something else. */
2040 if (range->layout->grab_location != MOUSE_OUTSIDE)
2043 range->layout->mouse_x = event->x;
2044 range->layout->mouse_y = event->y;
2045 if (gtk_range_update_mouse_location (range))
2046 gtk_widget_queue_draw (widget);
2048 if (range->layout->mouse_location == MOUSE_TROUGH &&
2051 /* button 1 steps by page increment, as with button 2 on a stepper
2053 GtkScrollType scroll;
2054 gdouble click_value;
2056 click_value = coord_to_value (range,
2057 range->orientation == GTK_ORIENTATION_VERTICAL ?
2058 event->y : event->x);
2060 range->trough_click_forward = click_value > range->adjustment->value;
2061 range_grab_add (range, MOUSE_TROUGH, event->button);
2063 scroll = range_get_scroll_for_grab (range);
2065 gtk_range_add_step_timer (range, scroll);
2069 else if ((range->layout->mouse_location == MOUSE_STEPPER_A ||
2070 range->layout->mouse_location == MOUSE_STEPPER_B ||
2071 range->layout->mouse_location == MOUSE_STEPPER_C ||
2072 range->layout->mouse_location == MOUSE_STEPPER_D) &&
2073 (event->button == 1 || event->button == 2 || event->button == 3))
2075 GdkRectangle *stepper_area;
2076 GtkScrollType scroll;
2078 range_grab_add (range, range->layout->mouse_location, event->button);
2080 stepper_area = get_area (range, range->layout->mouse_location);
2081 gtk_widget_queue_draw_area (widget,
2082 widget->allocation.x + stepper_area->x,
2083 widget->allocation.y + stepper_area->y,
2084 stepper_area->width,
2085 stepper_area->height);
2087 scroll = range_get_scroll_for_grab (range);
2088 if (scroll != GTK_SCROLL_NONE)
2089 gtk_range_add_step_timer (range, scroll);
2093 else if ((range->layout->mouse_location == MOUSE_TROUGH &&
2094 event->button == 2) ||
2095 range->layout->mouse_location == MOUSE_SLIDER)
2097 gboolean need_value_update = FALSE;
2098 gboolean activate_slider;
2100 /* Any button can be used to drag the slider, but you can start
2101 * dragging the slider with a trough click using button 2;
2102 * On button 2 press, we warp the slider to mouse position,
2103 * then begin the slider drag.
2105 if (event->button == 2)
2107 gdouble slider_low_value, slider_high_value, new_value;
2110 coord_to_value (range,
2111 range->orientation == GTK_ORIENTATION_VERTICAL ?
2112 event->y : event->x);
2114 coord_to_value (range,
2115 range->orientation == GTK_ORIENTATION_VERTICAL ?
2116 event->y - range->layout->slider.height :
2117 event->x - range->layout->slider.width);
2119 /* compute new value for warped slider */
2120 new_value = slider_low_value + (slider_high_value - slider_low_value) / 2;
2122 /* recalc slider, so we can set slide_initial_slider_position
2125 range->need_recalc = TRUE;
2126 gtk_range_calc_layout (range, new_value);
2128 /* defer adjustment updates to update_slider_position() in order
2129 * to keep pixel quantisation
2131 need_value_update = TRUE;
2134 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2136 range->slide_initial_slider_position = range->layout->slider.y;
2137 range->slide_initial_coordinate = event->y;
2141 range->slide_initial_slider_position = range->layout->slider.x;
2142 range->slide_initial_coordinate = event->x;
2145 range_grab_add (range, MOUSE_SLIDER, event->button);
2147 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
2149 /* force a redraw, if the active slider is drawn differently to the
2152 if (activate_slider)
2153 gtk_widget_queue_draw (widget);
2155 if (need_value_update)
2156 update_slider_position (range, event->x, event->y);
2164 /* During a slide, move the slider as required given new mouse position */
2166 update_slider_position (GtkRange *range,
2179 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2180 delta = mouse_y - range->slide_initial_coordinate;
2182 delta = mouse_x - range->slide_initial_coordinate;
2184 c = range->slide_initial_slider_position + delta;
2186 new_value = coord_to_value (range, c);
2187 next_value = coord_to_value (range, c + 1);
2188 mark_delta = fabs (next_value - new_value);
2190 for (i = 0; i < range->layout->n_marks; i++)
2192 mark_value = range->layout->marks[i];
2194 if (fabs (range->adjustment->value - mark_value) < 3 * mark_delta)
2196 if (fabs (new_value - mark_value) < (range->slider_end - range->slider_start) * 0.5 * mark_delta)
2198 new_value = mark_value;
2204 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_JUMP, new_value,
2209 stop_scrolling (GtkRange *range)
2211 range_grab_remove (range);
2212 gtk_range_remove_step_timer (range);
2213 /* Flush any pending discontinuous/delayed updates */
2214 gtk_range_update_value (range);
2218 gtk_range_grab_broken (GtkWidget *widget,
2219 GdkEventGrabBroken *event)
2221 GtkRange *range = GTK_RANGE (widget);
2223 if (range->layout->grab_location != MOUSE_OUTSIDE)
2225 if (range->layout->grab_location == MOUSE_SLIDER)
2226 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2228 stop_scrolling (range);
2237 gtk_range_button_release (GtkWidget *widget,
2238 GdkEventButton *event)
2240 GtkRange *range = GTK_RANGE (widget);
2242 if (event->window == range->event_window)
2244 range->layout->mouse_x = event->x;
2245 range->layout->mouse_y = event->y;
2249 gdk_window_get_pointer (range->event_window,
2250 &range->layout->mouse_x,
2251 &range->layout->mouse_y,
2255 if (range->layout->grab_button == event->button)
2257 if (range->layout->grab_location == MOUSE_SLIDER)
2258 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2260 stop_scrolling (range);
2269 * _gtk_range_get_wheel_delta:
2270 * @range: a #GtkRange
2271 * @direction: A #GdkScrollDirection
2273 * Returns a good step value for the mouse wheel.
2275 * Return value: A good step value for the mouse wheel.
2280 _gtk_range_get_wheel_delta (GtkRange *range,
2281 GdkScrollDirection direction)
2283 GtkAdjustment *adj = range->adjustment;
2286 if (GTK_IS_SCROLLBAR (range))
2287 delta = pow (adj->page_size, 2.0 / 3.0);
2289 delta = adj->step_increment * 2;
2291 if (direction == GDK_SCROLL_UP ||
2292 direction == GDK_SCROLL_LEFT)
2295 if (range->inverted)
2302 gtk_range_scroll_event (GtkWidget *widget,
2303 GdkEventScroll *event)
2305 GtkRange *range = GTK_RANGE (widget);
2307 if (GTK_WIDGET_REALIZED (range))
2309 GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
2313 delta = _gtk_range_get_wheel_delta (range, event->direction);
2315 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2316 GTK_SCROLL_JUMP, adj->value + delta,
2319 /* Policy DELAYED makes sense with scroll events,
2320 * but DISCONTINUOUS doesn't, so we update immediately
2323 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
2324 gtk_range_update_value (range);
2331 gtk_range_motion_notify (GtkWidget *widget,
2332 GdkEventMotion *event)
2336 range = GTK_RANGE (widget);
2338 gdk_event_request_motions (event);
2340 range->layout->mouse_x = event->x;
2341 range->layout->mouse_y = event->y;
2343 if (gtk_range_update_mouse_location (range))
2344 gtk_widget_queue_draw (widget);
2346 if (range->layout->grab_location == MOUSE_SLIDER)
2347 update_slider_position (range, event->x, event->y);
2349 /* We handled the event if the mouse was in the range_rect */
2350 return range->layout->mouse_location != MOUSE_OUTSIDE;
2354 gtk_range_enter_notify (GtkWidget *widget,
2355 GdkEventCrossing *event)
2357 GtkRange *range = GTK_RANGE (widget);
2359 range->layout->mouse_x = event->x;
2360 range->layout->mouse_y = event->y;
2362 if (gtk_range_update_mouse_location (range))
2363 gtk_widget_queue_draw (widget);
2369 gtk_range_leave_notify (GtkWidget *widget,
2370 GdkEventCrossing *event)
2372 GtkRange *range = GTK_RANGE (widget);
2374 range->layout->mouse_x = -1;
2375 range->layout->mouse_y = -1;
2377 if (gtk_range_update_mouse_location (range))
2378 gtk_widget_queue_draw (widget);
2384 gtk_range_grab_notify (GtkWidget *widget,
2385 gboolean was_grabbed)
2388 stop_scrolling (GTK_RANGE (widget));
2392 gtk_range_state_changed (GtkWidget *widget,
2393 GtkStateType previous_state)
2395 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2396 stop_scrolling (GTK_RANGE (widget));
2399 #define check_rectangle(rectangle1, rectangle2) \
2401 if (rectangle1.x != rectangle2.x) return TRUE; \
2402 if (rectangle1.y != rectangle2.y) return TRUE; \
2403 if (rectangle1.width != rectangle2.width) return TRUE; \
2404 if (rectangle1.height != rectangle2.height) return TRUE; \
2408 layout_changed (GtkRangeLayout *layout1,
2409 GtkRangeLayout *layout2)
2411 check_rectangle (layout1->slider, layout2->slider);
2412 check_rectangle (layout1->trough, layout2->trough);
2413 check_rectangle (layout1->stepper_a, layout2->stepper_a);
2414 check_rectangle (layout1->stepper_d, layout2->stepper_d);
2415 check_rectangle (layout1->stepper_b, layout2->stepper_b);
2416 check_rectangle (layout1->stepper_c, layout2->stepper_c);
2418 if (layout1->upper_sensitive != layout2->upper_sensitive) return TRUE;
2419 if (layout1->lower_sensitive != layout2->lower_sensitive) return TRUE;
2425 gtk_range_adjustment_changed (GtkAdjustment *adjustment,
2428 GtkRange *range = GTK_RANGE (data);
2429 /* create a copy of the layout */
2430 GtkRangeLayout layout = *range->layout;
2432 range->layout->recalc_marks = TRUE;
2433 range->need_recalc = TRUE;
2434 gtk_range_calc_layout (range, range->adjustment->value);
2436 /* now check whether the layout changed */
2437 if (layout_changed (range->layout, &layout))
2438 gtk_widget_queue_draw (GTK_WIDGET (range));
2440 /* Note that we don't round off to range->round_digits here.
2441 * that's because it's really broken to change a value
2442 * in response to a change signal on that value; round_digits
2443 * is therefore defined to be a filter on what the GtkRange
2444 * can input into the adjustment, not a filter that the GtkRange
2445 * will enforce on the adjustment.
2450 force_repaint (gpointer data)
2452 GtkRange *range = GTK_RANGE (data);
2453 range->layout->repaint_id = 0;
2454 if (GTK_WIDGET_DRAWABLE (range))
2455 gdk_window_process_updates (GTK_WIDGET (range)->window, FALSE);
2460 gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
2463 GtkRange *range = GTK_RANGE (data);
2464 /* create a copy of the layout */
2465 GtkRangeLayout layout = *range->layout;
2467 range->need_recalc = TRUE;
2468 gtk_range_calc_layout (range, range->adjustment->value);
2470 /* now check whether the layout changed */
2471 if (layout_changed (range->layout, &layout))
2473 gtk_widget_queue_draw (GTK_WIDGET (range));
2474 /* setup a timer to ensure the range isn't lagging too much behind the scroll position */
2475 if (!range->layout->repaint_id)
2476 range->layout->repaint_id = gdk_threads_add_timeout_full (GDK_PRIORITY_EVENTS, 181, force_repaint, range, NULL);
2479 /* Note that we don't round off to range->round_digits here.
2480 * that's because it's really broken to change a value
2481 * in response to a change signal on that value; round_digits
2482 * is therefore defined to be a filter on what the GtkRange
2483 * can input into the adjustment, not a filter that the GtkRange
2484 * will enforce on the adjustment.
2487 g_signal_emit (range, signals[VALUE_CHANGED], 0);
2491 gtk_range_style_set (GtkWidget *widget,
2492 GtkStyle *previous_style)
2494 GtkRange *range = GTK_RANGE (widget);
2496 range->need_recalc = TRUE;
2498 GTK_WIDGET_CLASS (gtk_range_parent_class)->style_set (widget, previous_style);
2502 apply_marks (GtkRange *range,
2509 for (i = 0; i < range->layout->n_marks; i++)
2511 mark = range->layout->marks[i];
2512 if ((oldval < mark && mark < *newval) ||
2513 (oldval > mark && mark > *newval))
2522 step_back (GtkRange *range)
2527 newval = range->adjustment->value - range->adjustment->step_increment;
2528 apply_marks (range, range->adjustment->value, &newval);
2529 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2530 GTK_SCROLL_STEP_BACKWARD, newval, &handled);
2534 step_forward (GtkRange *range)
2539 newval = range->adjustment->value + range->adjustment->step_increment;
2540 apply_marks (range, range->adjustment->value, &newval);
2541 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2542 GTK_SCROLL_STEP_FORWARD, newval, &handled);
2547 page_back (GtkRange *range)
2552 newval = range->adjustment->value - range->adjustment->page_increment;
2553 apply_marks (range, range->adjustment->value, &newval);
2554 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2555 GTK_SCROLL_PAGE_BACKWARD, newval, &handled);
2559 page_forward (GtkRange *range)
2564 newval = range->adjustment->value + range->adjustment->page_increment;
2565 apply_marks (range, range->adjustment->value, &newval);
2566 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2567 GTK_SCROLL_PAGE_FORWARD, newval, &handled);
2571 scroll_begin (GtkRange *range)
2574 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2575 GTK_SCROLL_START, range->adjustment->lower,
2580 scroll_end (GtkRange *range)
2585 newval = range->adjustment->upper - range->adjustment->page_size;
2586 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_END, newval,
2591 gtk_range_scroll (GtkRange *range,
2592 GtkScrollType scroll)
2594 gdouble old_value = range->adjustment->value;
2598 case GTK_SCROLL_STEP_LEFT:
2599 if (should_invert (range))
2600 step_forward (range);
2605 case GTK_SCROLL_STEP_UP:
2606 if (should_invert (range))
2607 step_forward (range);
2612 case GTK_SCROLL_STEP_RIGHT:
2613 if (should_invert (range))
2616 step_forward (range);
2619 case GTK_SCROLL_STEP_DOWN:
2620 if (should_invert (range))
2623 step_forward (range);
2626 case GTK_SCROLL_STEP_BACKWARD:
2630 case GTK_SCROLL_STEP_FORWARD:
2631 step_forward (range);
2634 case GTK_SCROLL_PAGE_LEFT:
2635 if (should_invert (range))
2636 page_forward (range);
2641 case GTK_SCROLL_PAGE_UP:
2642 if (should_invert (range))
2643 page_forward (range);
2648 case GTK_SCROLL_PAGE_RIGHT:
2649 if (should_invert (range))
2652 page_forward (range);
2655 case GTK_SCROLL_PAGE_DOWN:
2656 if (should_invert (range))
2659 page_forward (range);
2662 case GTK_SCROLL_PAGE_BACKWARD:
2666 case GTK_SCROLL_PAGE_FORWARD:
2667 page_forward (range);
2670 case GTK_SCROLL_START:
2671 scroll_begin (range);
2674 case GTK_SCROLL_END:
2678 case GTK_SCROLL_JUMP:
2679 /* Used by CList, range doesn't use it. */
2682 case GTK_SCROLL_NONE:
2686 return range->adjustment->value != old_value;
2690 gtk_range_move_slider (GtkRange *range,
2691 GtkScrollType scroll)
2693 gboolean cursor_only;
2695 g_object_get (gtk_widget_get_settings (GTK_WIDGET (range)),
2696 "gtk-keynav-cursor-only", &cursor_only,
2701 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (range));
2703 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
2705 if (scroll == GTK_SCROLL_STEP_UP ||
2706 scroll == GTK_SCROLL_STEP_DOWN)
2709 gtk_widget_child_focus (toplevel,
2710 scroll == GTK_SCROLL_STEP_UP ?
2711 GTK_DIR_UP : GTK_DIR_DOWN);
2717 if (scroll == GTK_SCROLL_STEP_LEFT ||
2718 scroll == GTK_SCROLL_STEP_RIGHT)
2721 gtk_widget_child_focus (toplevel,
2722 scroll == GTK_SCROLL_STEP_LEFT ?
2723 GTK_DIR_LEFT : GTK_DIR_RIGHT);
2729 if (! gtk_range_scroll (range, scroll))
2730 gtk_widget_error_bell (GTK_WIDGET (range));
2732 /* Policy DELAYED makes sense with key events,
2733 * but DISCONTINUOUS doesn't, so we update immediately
2736 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
2737 gtk_range_update_value (range);
2741 gtk_range_get_props (GtkRange *range,
2745 gint *trough_border,
2746 gint *stepper_spacing,
2747 gboolean *trough_under_steppers,
2748 gint *arrow_displacement_x,
2749 gint *arrow_displacement_y)
2751 GtkWidget *widget = GTK_WIDGET (range);
2752 gint tmp_slider_width, tmp_stepper_size, tmp_focus_width, tmp_trough_border;
2753 gint tmp_stepper_spacing, tmp_trough_under_steppers;
2754 gint tmp_arrow_displacement_x, tmp_arrow_displacement_y;
2756 gtk_widget_style_get (widget,
2757 "slider-width", &tmp_slider_width,
2758 "trough-border", &tmp_trough_border,
2759 "stepper-size", &tmp_stepper_size,
2760 "stepper-spacing", &tmp_stepper_spacing,
2761 "trough-under-steppers", &tmp_trough_under_steppers,
2762 "arrow-displacement-x", &tmp_arrow_displacement_x,
2763 "arrow-displacement-y", &tmp_arrow_displacement_y,
2766 if (tmp_stepper_spacing > 0)
2767 tmp_trough_under_steppers = FALSE;
2769 if (GTK_WIDGET_CAN_FOCUS (range))
2771 gint focus_line_width;
2774 gtk_widget_style_get (GTK_WIDGET (range),
2775 "focus-line-width", &focus_line_width,
2776 "focus-padding", &focus_padding,
2779 tmp_focus_width = focus_line_width + focus_padding;
2783 tmp_focus_width = 0;
2787 *slider_width = tmp_slider_width;
2790 *focus_width = tmp_focus_width;
2793 *trough_border = tmp_trough_border;
2796 *stepper_size = tmp_stepper_size;
2798 if (stepper_spacing)
2799 *stepper_spacing = tmp_stepper_spacing;
2801 if (trough_under_steppers)
2802 *trough_under_steppers = tmp_trough_under_steppers;
2804 if (arrow_displacement_x)
2805 *arrow_displacement_x = tmp_arrow_displacement_x;
2807 if (arrow_displacement_y)
2808 *arrow_displacement_y = tmp_arrow_displacement_y;
2811 #define POINT_IN_RECT(xcoord, ycoord, rect) \
2812 ((xcoord) >= (rect).x && \
2813 (xcoord) < ((rect).x + (rect).width) && \
2814 (ycoord) >= (rect).y && \
2815 (ycoord) < ((rect).y + (rect).height))
2817 /* Update mouse location, return TRUE if it changes */
2819 gtk_range_update_mouse_location (GtkRange *range)
2825 widget = GTK_WIDGET (range);
2827 old = range->layout->mouse_location;
2829 x = range->layout->mouse_x;
2830 y = range->layout->mouse_y;
2832 if (range->layout->grab_location != MOUSE_OUTSIDE)
2833 range->layout->mouse_location = range->layout->grab_location;
2834 else if (POINT_IN_RECT (x, y, range->layout->stepper_a))
2835 range->layout->mouse_location = MOUSE_STEPPER_A;
2836 else if (POINT_IN_RECT (x, y, range->layout->stepper_b))
2837 range->layout->mouse_location = MOUSE_STEPPER_B;
2838 else if (POINT_IN_RECT (x, y, range->layout->stepper_c))
2839 range->layout->mouse_location = MOUSE_STEPPER_C;
2840 else if (POINT_IN_RECT (x, y, range->layout->stepper_d))
2841 range->layout->mouse_location = MOUSE_STEPPER_D;
2842 else if (POINT_IN_RECT (x, y, range->layout->slider))
2843 range->layout->mouse_location = MOUSE_SLIDER;
2844 else if (POINT_IN_RECT (x, y, range->layout->trough))
2845 range->layout->mouse_location = MOUSE_TROUGH;
2846 else if (POINT_IN_RECT (x, y, widget->allocation))
2847 range->layout->mouse_location = MOUSE_WIDGET;
2849 range->layout->mouse_location = MOUSE_OUTSIDE;
2851 return old != range->layout->mouse_location;
2854 /* Clamp rect, border inside widget->allocation, such that we prefer
2855 * to take space from border not rect in all directions, and prefer to
2856 * give space to border over rect in one direction.
2859 clamp_dimensions (GtkWidget *widget,
2862 gboolean border_expands_horizontally)
2864 gint extra, shortage;
2866 g_return_if_fail (rect->x == 0);
2867 g_return_if_fail (rect->y == 0);
2868 g_return_if_fail (rect->width >= 0);
2869 g_return_if_fail (rect->height >= 0);
2873 extra = widget->allocation.width - border->left - border->right - rect->width;
2876 if (border_expands_horizontally)
2878 border->left += extra / 2;
2879 border->right += extra / 2 + extra % 2;
2883 rect->width += extra;
2887 /* See if we can fit rect, if not kill the border */
2888 shortage = rect->width - widget->allocation.width;
2891 rect->width = widget->allocation.width;
2892 /* lose the border */
2898 /* See if we can fit rect with borders */
2899 shortage = rect->width + border->left + border->right -
2900 widget->allocation.width;
2903 /* Shrink borders */
2904 border->left -= shortage / 2;
2905 border->right -= shortage / 2 + shortage % 2;
2911 extra = widget->allocation.height - border->top - border->bottom - rect->height;
2914 if (border_expands_horizontally)
2916 /* don't expand border vertically */
2917 rect->height += extra;
2921 border->top += extra / 2;
2922 border->bottom += extra / 2 + extra % 2;
2926 /* See if we can fit rect, if not kill the border */
2927 shortage = rect->height - widget->allocation.height;
2930 rect->height = widget->allocation.height;
2931 /* lose the border */
2937 /* See if we can fit rect with borders */
2938 shortage = rect->height + border->top + border->bottom -
2939 widget->allocation.height;
2942 /* Shrink borders */
2943 border->top -= shortage / 2;
2944 border->bottom -= shortage / 2 + shortage % 2;
2950 gtk_range_calc_request (GtkRange *range,
2955 gint stepper_spacing,
2956 GdkRectangle *range_rect,
2959 gboolean *has_steppers_ab,
2960 gboolean *has_steppers_cd,
2961 gint *slider_length_p)
2973 if (GTK_RANGE_GET_CLASS (range)->get_range_border)
2974 GTK_RANGE_GET_CLASS (range)->get_range_border (range, border);
2979 if (range->has_stepper_a)
2981 if (range->has_stepper_b)
2983 if (range->has_stepper_c)
2985 if (range->has_stepper_d)
2988 n_steppers = n_steppers_ab + n_steppers_cd;
2990 slider_length = range->min_slider_size;
2995 /* We never expand to fill available space in the small dimension
2996 * (i.e. vertical scrollbars are always a fixed width)
2998 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3000 range_rect->width = (focus_width + trough_border) * 2 + slider_width;
3001 range_rect->height = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
3003 if (n_steppers_ab > 0)
3004 range_rect->height += stepper_spacing;
3006 if (n_steppers_cd > 0)
3007 range_rect->height += stepper_spacing;
3011 range_rect->width = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
3012 range_rect->height = (focus_width + trough_border) * 2 + slider_width;
3014 if (n_steppers_ab > 0)
3015 range_rect->width += stepper_spacing;
3017 if (n_steppers_cd > 0)
3018 range_rect->width += stepper_spacing;
3022 *n_steppers_p = n_steppers;
3024 if (has_steppers_ab)
3025 *has_steppers_ab = (n_steppers_ab > 0);
3027 if (has_steppers_cd)
3028 *has_steppers_cd = (n_steppers_cd > 0);
3030 if (slider_length_p)
3031 *slider_length_p = slider_length;
3035 gtk_range_calc_layout (GtkRange *range,
3036 gdouble adjustment_value)
3038 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
3042 gboolean has_steppers_ab;
3043 gboolean has_steppers_cd;
3044 gboolean trough_under_steppers;
3045 GdkRectangle range_rect;
3046 GtkRangeLayout *layout;
3049 if (!range->need_recalc)
3052 /* If we have a too-small allocation, we prefer the steppers over
3053 * the trough/slider, probably the steppers are a more useful
3054 * feature in small spaces.
3056 * Also, we prefer to draw the range itself rather than the border
3057 * areas if there's a conflict, since the borders will be decoration
3058 * not controls. Though this depends on subclasses cooperating by
3059 * not drawing on range->range_rect.
3062 widget = GTK_WIDGET (range);
3063 layout = range->layout;
3065 gtk_range_get_props (range,
3066 &slider_width, &stepper_size,
3067 &focus_width, &trough_border,
3068 &stepper_spacing, &trough_under_steppers,
3071 gtk_range_calc_request (range,
3072 slider_width, stepper_size,
3073 focus_width, trough_border, stepper_spacing,
3074 &range_rect, &border, &n_steppers,
3075 &has_steppers_ab, &has_steppers_cd, &slider_length);
3077 /* We never expand to fill available space in the small dimension
3078 * (i.e. vertical scrollbars are always a fixed width)
3080 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3082 clamp_dimensions (widget, &range_rect, &border, TRUE);
3086 clamp_dimensions (widget, &range_rect, &border, FALSE);
3089 range_rect.x = border.left;
3090 range_rect.y = border.top;
3092 range->range_rect = range_rect;
3094 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3096 gint stepper_width, stepper_height;
3098 /* Steppers are the width of the range, and stepper_size in
3099 * height, or if we don't have enough height, divided equally
3100 * among available space.
3102 stepper_width = range_rect.width - focus_width * 2;
3104 if (trough_under_steppers)
3105 stepper_width -= trough_border * 2;
3107 if (stepper_width < 1)
3108 stepper_width = range_rect.width; /* screw the trough border */
3110 if (n_steppers == 0)
3111 stepper_height = 0; /* avoid divide by n_steppers */
3113 stepper_height = MIN (stepper_size, (range_rect.height / n_steppers));
3117 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3118 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3120 if (range->has_stepper_a)
3122 layout->stepper_a.width = stepper_width;
3123 layout->stepper_a.height = stepper_height;
3127 layout->stepper_a.width = 0;
3128 layout->stepper_a.height = 0;
3133 layout->stepper_b.x = layout->stepper_a.x;
3134 layout->stepper_b.y = layout->stepper_a.y + layout->stepper_a.height;
3136 if (range->has_stepper_b)
3138 layout->stepper_b.width = stepper_width;
3139 layout->stepper_b.height = stepper_height;
3143 layout->stepper_b.width = 0;
3144 layout->stepper_b.height = 0;
3149 if (range->has_stepper_d)
3151 layout->stepper_d.width = stepper_width;
3152 layout->stepper_d.height = stepper_height;
3156 layout->stepper_d.width = 0;
3157 layout->stepper_d.height = 0;
3160 layout->stepper_d.x = layout->stepper_a.x;
3161 layout->stepper_d.y = range_rect.y + range_rect.height - layout->stepper_d.height - focus_width - trough_border * trough_under_steppers;
3165 if (range->has_stepper_c)
3167 layout->stepper_c.width = stepper_width;
3168 layout->stepper_c.height = stepper_height;
3172 layout->stepper_c.width = 0;
3173 layout->stepper_c.height = 0;
3176 layout->stepper_c.x = layout->stepper_a.x;
3177 layout->stepper_c.y = layout->stepper_d.y - layout->stepper_c.height;
3179 /* Now the trough is the remaining space between steppers B and C,
3180 * if any, minus spacing
3182 layout->trough.x = range_rect.x;
3183 layout->trough.y = layout->stepper_b.y + layout->stepper_b.height + stepper_spacing * has_steppers_ab;
3184 layout->trough.width = range_rect.width;
3185 layout->trough.height = layout->stepper_c.y - layout->trough.y - stepper_spacing * has_steppers_cd;
3187 /* Slider fits into the trough, with stepper_spacing on either side,
3188 * and the size/position based on the adjustment or fixed, depending.
3190 layout->slider.x = layout->trough.x + focus_width + trough_border;
3191 layout->slider.width = layout->trough.width - (focus_width + trough_border) * 2;
3193 /* Compute slider position/length */
3195 gint y, bottom, top, height;
3197 top = layout->trough.y;
3198 bottom = layout->trough.y + layout->trough.height;
3200 if (! trough_under_steppers)
3202 top += trough_border;
3203 bottom -= trough_border;
3206 /* slider height is the fraction (page_size /
3207 * total_adjustment_range) times the trough height in pixels
3210 if (range->adjustment->upper - range->adjustment->lower != 0)
3211 height = ((bottom - top) * (range->adjustment->page_size /
3212 (range->adjustment->upper - range->adjustment->lower)));
3214 height = range->min_slider_size;
3216 if (height < range->min_slider_size ||
3217 range->slider_size_fixed)
3218 height = range->min_slider_size;
3220 height = MIN (height, layout->trough.height);
3224 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3225 y += (bottom - top - height) * ((adjustment_value - range->adjustment->lower) /
3226 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3228 y = CLAMP (y, top, bottom);
3230 if (should_invert (range))
3231 y = bottom - (y - top + height);
3233 layout->slider.y = y;
3234 layout->slider.height = height;
3236 /* These are publically exported */
3237 range->slider_start = layout->slider.y;
3238 range->slider_end = layout->slider.y + layout->slider.height;
3243 gint stepper_width, stepper_height;
3245 /* Steppers are the height of the range, and stepper_size in
3246 * width, or if we don't have enough width, divided equally
3247 * among available space.
3249 stepper_height = range_rect.height + focus_width * 2;
3251 if (trough_under_steppers)
3252 stepper_height -= trough_border * 2;
3254 if (stepper_height < 1)
3255 stepper_height = range_rect.height; /* screw the trough border */
3257 if (n_steppers == 0)
3258 stepper_width = 0; /* avoid divide by n_steppers */
3260 stepper_width = MIN (stepper_size, (range_rect.width / n_steppers));
3264 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3265 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3267 if (range->has_stepper_a)
3269 layout->stepper_a.width = stepper_width;
3270 layout->stepper_a.height = stepper_height;
3274 layout->stepper_a.width = 0;
3275 layout->stepper_a.height = 0;
3280 layout->stepper_b.x = layout->stepper_a.x + layout->stepper_a.width;
3281 layout->stepper_b.y = layout->stepper_a.y;
3283 if (range->has_stepper_b)
3285 layout->stepper_b.width = stepper_width;
3286 layout->stepper_b.height = stepper_height;
3290 layout->stepper_b.width = 0;
3291 layout->stepper_b.height = 0;
3296 if (range->has_stepper_d)
3298 layout->stepper_d.width = stepper_width;
3299 layout->stepper_d.height = stepper_height;
3303 layout->stepper_d.width = 0;
3304 layout->stepper_d.height = 0;
3307 layout->stepper_d.x = range_rect.x + range_rect.width - layout->stepper_d.width - focus_width - trough_border * trough_under_steppers;
3308 layout->stepper_d.y = layout->stepper_a.y;
3313 if (range->has_stepper_c)
3315 layout->stepper_c.width = stepper_width;
3316 layout->stepper_c.height = stepper_height;
3320 layout->stepper_c.width = 0;
3321 layout->stepper_c.height = 0;
3324 layout->stepper_c.x = layout->stepper_d.x - layout->stepper_c.width;
3325 layout->stepper_c.y = layout->stepper_a.y;
3327 /* Now the trough is the remaining space between steppers B and C,
3330 layout->trough.x = layout->stepper_b.x + layout->stepper_b.width + stepper_spacing * has_steppers_ab;
3331 layout->trough.y = range_rect.y;
3333 layout->trough.width = layout->stepper_c.x - layout->trough.x - stepper_spacing * has_steppers_cd;
3334 layout->trough.height = range_rect.height;
3336 /* Slider fits into the trough, with stepper_spacing on either side,
3337 * and the size/position based on the adjustment or fixed, depending.
3339 layout->slider.y = layout->trough.y + focus_width + trough_border;
3340 layout->slider.height = layout->trough.height - (focus_width + trough_border) * 2;
3342 /* Compute slider position/length */
3344 gint x, left, right, width;
3346 left = layout->trough.x;
3347 right = layout->trough.x + layout->trough.width;
3349 if (! trough_under_steppers)
3351 left += trough_border;
3352 right -= trough_border;
3355 /* slider width is the fraction (page_size /
3356 * total_adjustment_range) times the trough width in pixels
3359 if (range->adjustment->upper - range->adjustment->lower != 0)
3360 width = ((right - left) * (range->adjustment->page_size /
3361 (range->adjustment->upper - range->adjustment->lower)));
3363 width = range->min_slider_size;
3365 if (width < range->min_slider_size ||
3366 range->slider_size_fixed)
3367 width = range->min_slider_size;
3369 width = MIN (width, layout->trough.width);
3373 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3374 x += (right - left - width) * ((adjustment_value - range->adjustment->lower) /
3375 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3377 x = CLAMP (x, left, right);
3379 if (should_invert (range))
3380 x = right - (x - left + width);
3382 layout->slider.x = x;
3383 layout->slider.width = width;
3385 /* These are publically exported */
3386 range->slider_start = layout->slider.x;
3387 range->slider_end = layout->slider.x + layout->slider.width;
3391 gtk_range_update_mouse_location (range);
3393 switch (range->layout->upper_sensitivity)
3395 case GTK_SENSITIVITY_AUTO:
3396 range->layout->upper_sensitive =
3397 (range->adjustment->value <
3398 (range->adjustment->upper - range->adjustment->page_size));
3401 case GTK_SENSITIVITY_ON:
3402 range->layout->upper_sensitive = TRUE;
3405 case GTK_SENSITIVITY_OFF:
3406 range->layout->upper_sensitive = FALSE;
3410 switch (range->layout->lower_sensitivity)
3412 case GTK_SENSITIVITY_AUTO:
3413 range->layout->lower_sensitive =
3414 (range->adjustment->value > range->adjustment->lower);
3417 case GTK_SENSITIVITY_ON:
3418 range->layout->lower_sensitive = TRUE;
3421 case GTK_SENSITIVITY_OFF:
3422 range->layout->lower_sensitive = FALSE;
3427 static GdkRectangle*
3428 get_area (GtkRange *range,
3429 MouseLocation location)
3433 case MOUSE_STEPPER_A:
3434 return &range->layout->stepper_a;
3435 case MOUSE_STEPPER_B:
3436 return &range->layout->stepper_b;
3437 case MOUSE_STEPPER_C:
3438 return &range->layout->stepper_c;
3439 case MOUSE_STEPPER_D:
3440 return &range->layout->stepper_d;
3442 return &range->layout->trough;
3444 return &range->layout->slider;
3450 g_warning (G_STRLOC": bug");
3455 gtk_range_calc_marks (GtkRange *range)
3459 if (!range->layout->recalc_marks)
3462 range->layout->recalc_marks = FALSE;
3464 for (i = 0; i < range->layout->n_marks; i++)
3466 range->need_recalc = TRUE;
3467 gtk_range_calc_layout (range, range->layout->marks[i]);
3468 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
3469 range->layout->mark_pos[i] = range->layout->slider.x + range->layout->slider.width / 2;
3471 range->layout->mark_pos[i] = range->layout->slider.y + range->layout->slider.height / 2;
3474 range->need_recalc = TRUE;
3478 gtk_range_real_change_value (GtkRange *range,
3479 GtkScrollType scroll,
3482 /* potentially adjust the bounds _before we clamp */
3483 g_signal_emit (range, signals[ADJUST_BOUNDS], 0, value);
3485 if (range->layout->restrict_to_fill_level)
3486 value = MIN (value, MAX (range->adjustment->lower,
3487 range->layout->fill_level));
3489 value = CLAMP (value, range->adjustment->lower,
3490 (range->adjustment->upper - range->adjustment->page_size));
3492 if (range->round_digits >= 0)
3497 i = range->round_digits;
3502 value = floor ((value * power) + 0.5) / power;
3505 if (range->adjustment->value != value)
3507 range->need_recalc = TRUE;
3509 gtk_widget_queue_draw (GTK_WIDGET (range));
3511 switch (range->update_policy)
3513 case GTK_UPDATE_CONTINUOUS:
3514 gtk_adjustment_set_value (range->adjustment, value);
3517 /* Delayed means we update after a period of inactivity */
3518 case GTK_UPDATE_DELAYED:
3519 gtk_range_reset_update_timer (range);
3522 /* Discontinuous means we update on button release */
3523 case GTK_UPDATE_DISCONTINUOUS:
3524 /* don't emit value_changed signal */
3525 range->adjustment->value = value;
3526 range->update_pending = TRUE;
3534 gtk_range_update_value (GtkRange *range)
3536 gtk_range_remove_update_timer (range);
3538 if (range->update_pending)
3540 gtk_adjustment_value_changed (range->adjustment);
3542 range->update_pending = FALSE;
3546 struct _GtkRangeStepTimer
3553 second_timeout (gpointer data)
3557 range = GTK_RANGE (data);
3558 gtk_range_scroll (range, range->timer->step);
3564 initial_timeout (gpointer data)
3567 GtkSettings *settings;
3570 settings = gtk_widget_get_settings (GTK_WIDGET (data));
3571 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3573 range = GTK_RANGE (data);
3574 range->timer->timeout_id = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3582 gtk_range_add_step_timer (GtkRange *range,
3585 GtkSettings *settings;
3588 g_return_if_fail (range->timer == NULL);
3589 g_return_if_fail (step != GTK_SCROLL_NONE);
3591 settings = gtk_widget_get_settings (GTK_WIDGET (range));
3592 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
3594 range->timer = g_new (GtkRangeStepTimer, 1);
3596 range->timer->timeout_id = gdk_threads_add_timeout (timeout,
3599 range->timer->step = step;
3601 gtk_range_scroll (range, range->timer->step);
3605 gtk_range_remove_step_timer (GtkRange *range)
3609 if (range->timer->timeout_id != 0)
3610 g_source_remove (range->timer->timeout_id);
3612 g_free (range->timer);
3614 range->timer = NULL;
3619 update_timeout (gpointer data)
3623 range = GTK_RANGE (data);
3624 gtk_range_update_value (range);
3625 range->update_timeout_id = 0;
3632 gtk_range_reset_update_timer (GtkRange *range)
3634 gtk_range_remove_update_timer (range);
3636 range->update_timeout_id = gdk_threads_add_timeout (UPDATE_DELAY,
3642 gtk_range_remove_update_timer (GtkRange *range)
3644 if (range->update_timeout_id != 0)
3646 g_source_remove (range->update_timeout_id);
3647 range->update_timeout_id = 0;
3652 _gtk_range_set_stop_values (GtkRange *range,
3658 g_free (range->layout->marks);
3659 range->layout->marks = g_new (gdouble, n_values);
3661 g_free (range->layout->mark_pos);
3662 range->layout->mark_pos = g_new (gint, n_values);
3664 range->layout->n_marks = n_values;
3666 for (i = 0; i < n_values; i++)
3667 range->layout->marks[i] = values[i];
3669 range->layout->recalc_marks = TRUE;
3673 _gtk_range_get_stop_positions (GtkRange *range,
3676 gtk_range_calc_marks (range);
3679 *values = g_memdup (range->layout->mark_pos, range->layout->n_marks * sizeof (gint));
3681 return range->layout->n_marks;
3684 #define __GTK_RANGE_C__
3685 #include "gtkaliasdef.c"