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"
39 #include "gtkscrollbar.h"
40 #include "gtkprivate.h"
45 * @Short_description: Base class for widgets which visualize an adjustment
48 * #GtkRange is the common base class for widgets which visualize an
49 * adjustment, e.g #GtkScale or #GtkScrollbar.
51 * Apart from signals for monitoring the parameters of the adjustment,
52 * #GtkRange provides properties and methods for influencing the sensitivity
53 * of the "steppers". It also provides properties and methods for setting a
54 * "fill level" on range widgets. See gtk_range_set_fill_level().
58 #define SCROLL_DELAY_FACTOR 5 /* Scroll repeat multiplier */
59 #define UPDATE_DELAY 300 /* Delay for queued update */
67 PROP_LOWER_STEPPER_SENSITIVITY,
68 PROP_UPPER_STEPPER_SENSITIVITY,
70 PROP_RESTRICT_TO_FILL_LEVEL,
90 MOUSE_WIDGET /* inside widget but not in any of the above GUI elements */
100 #define GTK_RANGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RANGE, GtkRangeLayout))
102 struct _GtkRangeLayout
104 /* These are in widget->window coordinates */
105 GdkRectangle stepper_a;
106 GdkRectangle stepper_b;
107 GdkRectangle stepper_c;
108 GdkRectangle stepper_d;
109 /* The trough rectangle is the area the thumb can slide in, not the
115 /* Layout-related state */
117 MouseLocation mouse_location;
118 /* last mouse coords we got, or -1 if mouse is outside the range */
122 /* "grabbed" mouse location, OUTSIDE for no grab */
123 MouseLocation grab_location;
124 guint grab_button : 8; /* 0 if none */
126 /* Stepper sensitivity */
127 guint lower_sensitive : 1;
128 guint upper_sensitive : 1;
131 guint show_fill_level : 1;
132 guint restrict_to_fill_level : 1;
134 GtkSensitivityType lower_sensitivity;
135 GtkSensitivityType upper_sensitivity;
140 GQuark slider_detail_quark;
141 GQuark stepper_detail_quark[4];
146 gboolean recalc_marks;
148 GdkDevice *grab_device;
152 static void gtk_range_set_property (GObject *object,
156 static void gtk_range_get_property (GObject *object,
160 static void gtk_range_destroy (GtkObject *object);
161 static void gtk_range_size_request (GtkWidget *widget,
162 GtkRequisition *requisition);
163 static void gtk_range_size_allocate (GtkWidget *widget,
164 GtkAllocation *allocation);
165 static void gtk_range_realize (GtkWidget *widget);
166 static void gtk_range_unrealize (GtkWidget *widget);
167 static void gtk_range_map (GtkWidget *widget);
168 static void gtk_range_unmap (GtkWidget *widget);
169 static gboolean gtk_range_expose (GtkWidget *widget,
170 GdkEventExpose *event);
171 static gboolean gtk_range_button_press (GtkWidget *widget,
172 GdkEventButton *event);
173 static gboolean gtk_range_button_release (GtkWidget *widget,
174 GdkEventButton *event);
175 static gboolean gtk_range_motion_notify (GtkWidget *widget,
176 GdkEventMotion *event);
177 static gboolean gtk_range_enter_notify (GtkWidget *widget,
178 GdkEventCrossing *event);
179 static gboolean gtk_range_leave_notify (GtkWidget *widget,
180 GdkEventCrossing *event);
181 static gboolean gtk_range_grab_broken (GtkWidget *widget,
182 GdkEventGrabBroken *event);
183 static void gtk_range_grab_notify (GtkWidget *widget,
184 gboolean was_grabbed);
185 static void gtk_range_state_changed (GtkWidget *widget,
186 GtkStateType previous_state);
187 static gboolean gtk_range_scroll_event (GtkWidget *widget,
188 GdkEventScroll *event);
189 static void gtk_range_style_set (GtkWidget *widget,
190 GtkStyle *previous_style);
191 static void update_slider_position (GtkRange *range,
194 static void stop_scrolling (GtkRange *range);
198 static void gtk_range_move_slider (GtkRange *range,
199 GtkScrollType scroll);
202 static gboolean gtk_range_scroll (GtkRange *range,
203 GtkScrollType scroll);
204 static gboolean gtk_range_update_mouse_location (GtkRange *range);
205 static void gtk_range_calc_layout (GtkRange *range,
206 gdouble adjustment_value);
207 static void gtk_range_calc_marks (GtkRange *range);
208 static void gtk_range_get_props (GtkRange *range,
213 gint *stepper_spacing,
214 gboolean *trough_under_steppers,
215 gint *arrow_displacement_x,
216 gint *arrow_displacement_y);
217 static void gtk_range_calc_request (GtkRange *range,
222 gint stepper_spacing,
223 GdkRectangle *range_rect,
226 gboolean *has_steppers_ab,
227 gboolean *has_steppers_cd,
228 gint *slider_length_p);
229 static void gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
231 static void gtk_range_adjustment_changed (GtkAdjustment *adjustment,
233 static void gtk_range_add_step_timer (GtkRange *range,
235 static void gtk_range_remove_step_timer (GtkRange *range);
236 static void gtk_range_reset_update_timer (GtkRange *range);
237 static void gtk_range_remove_update_timer (GtkRange *range);
238 static GdkRectangle* get_area (GtkRange *range,
239 MouseLocation location);
240 static gboolean gtk_range_real_change_value (GtkRange *range,
241 GtkScrollType scroll,
243 static void gtk_range_update_value (GtkRange *range);
244 static gboolean gtk_range_key_press (GtkWidget *range,
248 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkRange, gtk_range, GTK_TYPE_WIDGET,
249 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
252 static guint signals[LAST_SIGNAL];
256 gtk_range_class_init (GtkRangeClass *class)
258 GObjectClass *gobject_class;
259 GtkObjectClass *object_class;
260 GtkWidgetClass *widget_class;
262 gobject_class = G_OBJECT_CLASS (class);
263 object_class = (GtkObjectClass*) class;
264 widget_class = (GtkWidgetClass*) class;
266 gobject_class->set_property = gtk_range_set_property;
267 gobject_class->get_property = gtk_range_get_property;
269 object_class->destroy = gtk_range_destroy;
271 widget_class->size_request = gtk_range_size_request;
272 widget_class->size_allocate = gtk_range_size_allocate;
273 widget_class->realize = gtk_range_realize;
274 widget_class->unrealize = gtk_range_unrealize;
275 widget_class->map = gtk_range_map;
276 widget_class->unmap = gtk_range_unmap;
277 widget_class->expose_event = gtk_range_expose;
278 widget_class->button_press_event = gtk_range_button_press;
279 widget_class->button_release_event = gtk_range_button_release;
280 widget_class->motion_notify_event = gtk_range_motion_notify;
281 widget_class->scroll_event = gtk_range_scroll_event;
282 widget_class->enter_notify_event = gtk_range_enter_notify;
283 widget_class->leave_notify_event = gtk_range_leave_notify;
284 widget_class->grab_broken_event = gtk_range_grab_broken;
285 widget_class->grab_notify = gtk_range_grab_notify;
286 widget_class->state_changed = gtk_range_state_changed;
287 widget_class->style_set = gtk_range_style_set;
288 widget_class->key_press_event = gtk_range_key_press;
290 class->move_slider = gtk_range_move_slider;
291 class->change_value = gtk_range_real_change_value;
293 class->slider_detail = "slider";
294 class->stepper_detail = "stepper";
297 * GtkRange::value-changed:
298 * @range: the #GtkRange that received the signal
300 * Emitted when the range value changes.
302 signals[VALUE_CHANGED] =
303 g_signal_new (I_("value-changed"),
304 G_TYPE_FROM_CLASS (gobject_class),
306 G_STRUCT_OFFSET (GtkRangeClass, value_changed),
308 _gtk_marshal_VOID__VOID,
312 * GtkRange::adjust-bounds:
313 * @range: the #GtkRange that received the signal
314 * @value: the value before we clamp
316 * Emitted before clamping a value, to give the application a
317 * chance to adjust the bounds.
319 signals[ADJUST_BOUNDS] =
320 g_signal_new (I_("adjust-bounds"),
321 G_TYPE_FROM_CLASS (gobject_class),
323 G_STRUCT_OFFSET (GtkRangeClass, adjust_bounds),
325 _gtk_marshal_VOID__DOUBLE,
330 * GtkRange::move-slider:
331 * @range: the #GtkRange that received the signal
332 * @step: how to move the slider
334 * Virtual function that moves the slider. Used for keybindings.
336 signals[MOVE_SLIDER] =
337 g_signal_new (I_("move-slider"),
338 G_TYPE_FROM_CLASS (gobject_class),
339 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
340 G_STRUCT_OFFSET (GtkRangeClass, move_slider),
342 _gtk_marshal_VOID__ENUM,
344 GTK_TYPE_SCROLL_TYPE);
347 * GtkRange::change-value:
348 * @range: the #GtkRange that received the signal
349 * @scroll: the type of scroll action that was performed
350 * @value: the new value resulting from the scroll action
351 * @returns: %TRUE to prevent other handlers from being invoked for the
352 * signal, %FALSE to propagate the signal further
354 * The ::change-value signal is emitted when a scroll action is
355 * performed on a range. It allows an application to determine the
356 * type of scroll event that occurred and the resultant new value.
357 * The application can handle the event itself and return %TRUE to
358 * prevent further processing. Or, by returning %FALSE, it can pass
359 * the event to other handlers until the default GTK+ handler is
362 * The value parameter is unrounded. An application that overrides
363 * the ::change-value signal is responsible for clamping the value to
364 * the desired number of decimal digits; the default GTK+ handler
365 * clamps the value based on @range->round_digits.
367 * It is not possible to use delayed update policies in an overridden
368 * ::change-value handler.
372 signals[CHANGE_VALUE] =
373 g_signal_new (I_("change-value"),
374 G_TYPE_FROM_CLASS (gobject_class),
376 G_STRUCT_OFFSET (GtkRangeClass, change_value),
377 _gtk_boolean_handled_accumulator, NULL,
378 _gtk_marshal_BOOLEAN__ENUM_DOUBLE,
380 GTK_TYPE_SCROLL_TYPE,
383 g_object_class_override_property (gobject_class,
387 g_object_class_install_property (gobject_class,
389 g_param_spec_enum ("update-policy",
391 P_("How the range should be updated on the screen"),
392 GTK_TYPE_UPDATE_TYPE,
393 GTK_UPDATE_CONTINUOUS,
394 GTK_PARAM_READWRITE));
396 g_object_class_install_property (gobject_class,
398 g_param_spec_object ("adjustment",
400 P_("The GtkAdjustment that contains the current value of this range object"),
402 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
404 g_object_class_install_property (gobject_class,
406 g_param_spec_boolean ("inverted",
408 P_("Invert direction slider moves to increase range value"),
410 GTK_PARAM_READWRITE));
412 g_object_class_install_property (gobject_class,
413 PROP_LOWER_STEPPER_SENSITIVITY,
414 g_param_spec_enum ("lower-stepper-sensitivity",
415 P_("Lower stepper sensitivity"),
416 P_("The sensitivity policy for the stepper that points to the adjustment's lower side"),
417 GTK_TYPE_SENSITIVITY_TYPE,
418 GTK_SENSITIVITY_AUTO,
419 GTK_PARAM_READWRITE));
421 g_object_class_install_property (gobject_class,
422 PROP_UPPER_STEPPER_SENSITIVITY,
423 g_param_spec_enum ("upper-stepper-sensitivity",
424 P_("Upper stepper sensitivity"),
425 P_("The sensitivity policy for the stepper that points to the adjustment's upper side"),
426 GTK_TYPE_SENSITIVITY_TYPE,
427 GTK_SENSITIVITY_AUTO,
428 GTK_PARAM_READWRITE));
431 * GtkRange:show-fill-level:
433 * The show-fill-level property controls whether fill level indicator
434 * graphics are displayed on the trough. See
435 * gtk_range_set_show_fill_level().
439 g_object_class_install_property (gobject_class,
440 PROP_SHOW_FILL_LEVEL,
441 g_param_spec_boolean ("show-fill-level",
442 P_("Show Fill Level"),
443 P_("Whether to display a fill level indicator graphics on trough."),
445 GTK_PARAM_READWRITE));
448 * GtkRange:restrict-to-fill-level:
450 * The restrict-to-fill-level property controls whether slider
451 * movement is restricted to an upper boundary set by the
452 * fill level. See gtk_range_set_restrict_to_fill_level().
456 g_object_class_install_property (gobject_class,
457 PROP_RESTRICT_TO_FILL_LEVEL,
458 g_param_spec_boolean ("restrict-to-fill-level",
459 P_("Restrict to Fill Level"),
460 P_("Whether to restrict the upper boundary to the fill level."),
462 GTK_PARAM_READWRITE));
465 * GtkRange:fill-level:
467 * The fill level (e.g. prebuffering of a network stream).
468 * See gtk_range_set_fill_level().
472 g_object_class_install_property (gobject_class,
474 g_param_spec_double ("fill-level",
476 P_("The fill level."),
480 GTK_PARAM_READWRITE));
482 gtk_widget_class_install_style_property (widget_class,
483 g_param_spec_int ("slider-width",
485 P_("Width of scrollbar or scale thumb"),
489 GTK_PARAM_READABLE));
490 gtk_widget_class_install_style_property (widget_class,
491 g_param_spec_int ("trough-border",
493 P_("Spacing between thumb/steppers and outer trough bevel"),
497 GTK_PARAM_READABLE));
498 gtk_widget_class_install_style_property (widget_class,
499 g_param_spec_int ("stepper-size",
501 P_("Length of step buttons at ends"),
505 GTK_PARAM_READABLE));
507 * GtkRange:stepper-spacing:
509 * The spacing between the stepper buttons and thumb. Note that
510 * setting this value to anything > 0 will automatically set the
511 * trough-under-steppers style property to %TRUE as well. Also,
512 * stepper-spacing won't have any effect if there are no steppers.
514 gtk_widget_class_install_style_property (widget_class,
515 g_param_spec_int ("stepper-spacing",
516 P_("Stepper Spacing"),
517 P_("Spacing between step buttons and thumb"),
521 GTK_PARAM_READABLE));
522 gtk_widget_class_install_style_property (widget_class,
523 g_param_spec_int ("arrow-displacement-x",
524 P_("Arrow X Displacement"),
525 P_("How far in the x direction to move the arrow when the button is depressed"),
529 GTK_PARAM_READABLE));
530 gtk_widget_class_install_style_property (widget_class,
531 g_param_spec_int ("arrow-displacement-y",
532 P_("Arrow Y Displacement"),
533 P_("How far in the y direction to move the arrow when the button is depressed"),
537 GTK_PARAM_READABLE));
539 gtk_widget_class_install_style_property (widget_class,
540 g_param_spec_boolean ("activate-slider",
541 P_("Draw slider ACTIVE during drag"),
542 P_("With this option set to TRUE, sliders will be drawn ACTIVE and with shadow IN while they are dragged"),
544 GTK_PARAM_READABLE));
547 * GtkRange:trough-side-details:
549 * When %TRUE, the parts of the trough on the two sides of the
550 * slider are drawn with different details.
554 gtk_widget_class_install_style_property (widget_class,
555 g_param_spec_boolean ("trough-side-details",
556 P_("Trough Side Details"),
557 P_("When TRUE, the parts of the trough on the two sides of the slider are drawn with different details"),
559 GTK_PARAM_READABLE));
562 * GtkRange:trough-under-steppers:
564 * Whether to draw the trough across the full length of the range or
565 * to exclude the steppers and their spacing. Note that setting the
566 * #GtkRange:stepper-spacing style property to any value > 0 will
567 * automatically enable trough-under-steppers too.
571 gtk_widget_class_install_style_property (widget_class,
572 g_param_spec_boolean ("trough-under-steppers",
573 P_("Trough Under Steppers"),
574 P_("Whether to draw trough for full length of range or exclude the steppers and spacing"),
576 GTK_PARAM_READABLE));
579 * GtkRange:arrow-scaling:
581 * The arrow size proportion relative to the scroll button size.
585 gtk_widget_class_install_style_property (widget_class,
586 g_param_spec_float ("arrow-scaling",
588 P_("Arrow scaling with regard to scroll button size"),
590 GTK_PARAM_READABLE));
593 * GtkRange:stepper-position-details:
595 * When %TRUE, the detail string for rendering the steppers will be
596 * suffixed with information about the stepper position.
600 gtk_widget_class_install_style_property (widget_class,
601 g_param_spec_boolean ("stepper-position-details",
602 P_("Stepper Position Details"),
603 P_("When TRUE, the detail string for rendering the steppers is suffixed with position information"),
605 GTK_PARAM_READABLE));
607 g_type_class_add_private (class, sizeof (GtkRangeLayout));
611 gtk_range_set_property (GObject *object,
616 GtkRange *range = GTK_RANGE (object);
620 case PROP_ORIENTATION:
621 range->orientation = g_value_get_enum (value);
623 range->layout->slider_detail_quark = 0;
624 range->layout->stepper_detail_quark[0] = 0;
625 range->layout->stepper_detail_quark[1] = 0;
626 range->layout->stepper_detail_quark[2] = 0;
627 range->layout->stepper_detail_quark[3] = 0;
629 gtk_widget_queue_resize (GTK_WIDGET (range));
631 case PROP_UPDATE_POLICY:
632 gtk_range_set_update_policy (range, g_value_get_enum (value));
634 case PROP_ADJUSTMENT:
635 gtk_range_set_adjustment (range, g_value_get_object (value));
638 gtk_range_set_inverted (range, g_value_get_boolean (value));
640 case PROP_LOWER_STEPPER_SENSITIVITY:
641 gtk_range_set_lower_stepper_sensitivity (range, g_value_get_enum (value));
643 case PROP_UPPER_STEPPER_SENSITIVITY:
644 gtk_range_set_upper_stepper_sensitivity (range, g_value_get_enum (value));
646 case PROP_SHOW_FILL_LEVEL:
647 gtk_range_set_show_fill_level (range, g_value_get_boolean (value));
649 case PROP_RESTRICT_TO_FILL_LEVEL:
650 gtk_range_set_restrict_to_fill_level (range, g_value_get_boolean (value));
652 case PROP_FILL_LEVEL:
653 gtk_range_set_fill_level (range, g_value_get_double (value));
656 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
662 gtk_range_get_property (GObject *object,
667 GtkRange *range = GTK_RANGE (object);
671 case PROP_ORIENTATION:
672 g_value_set_enum (value, range->orientation);
674 case PROP_UPDATE_POLICY:
675 g_value_set_enum (value, range->update_policy);
677 case PROP_ADJUSTMENT:
678 g_value_set_object (value, range->adjustment);
681 g_value_set_boolean (value, range->inverted);
683 case PROP_LOWER_STEPPER_SENSITIVITY:
684 g_value_set_enum (value, gtk_range_get_lower_stepper_sensitivity (range));
686 case PROP_UPPER_STEPPER_SENSITIVITY:
687 g_value_set_enum (value, gtk_range_get_upper_stepper_sensitivity (range));
689 case PROP_SHOW_FILL_LEVEL:
690 g_value_set_boolean (value, gtk_range_get_show_fill_level (range));
692 case PROP_RESTRICT_TO_FILL_LEVEL:
693 g_value_set_boolean (value, gtk_range_get_restrict_to_fill_level (range));
695 case PROP_FILL_LEVEL:
696 g_value_set_double (value, gtk_range_get_fill_level (range));
699 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
705 gtk_range_init (GtkRange *range)
707 gtk_widget_set_has_window (GTK_WIDGET (range), FALSE);
709 range->orientation = GTK_ORIENTATION_HORIZONTAL;
710 range->adjustment = NULL;
711 range->update_policy = GTK_UPDATE_CONTINUOUS;
712 range->inverted = FALSE;
713 range->flippable = FALSE;
714 range->min_slider_size = 1;
715 range->has_stepper_a = FALSE;
716 range->has_stepper_b = FALSE;
717 range->has_stepper_c = FALSE;
718 range->has_stepper_d = FALSE;
719 range->need_recalc = TRUE;
720 range->round_digits = -1;
721 range->layout = GTK_RANGE_GET_PRIVATE (range);
722 range->layout->mouse_location = MOUSE_OUTSIDE;
723 range->layout->mouse_x = -1;
724 range->layout->mouse_y = -1;
725 range->layout->grab_location = MOUSE_OUTSIDE;
726 range->layout->grab_button = 0;
727 range->layout->lower_sensitivity = GTK_SENSITIVITY_AUTO;
728 range->layout->upper_sensitivity = GTK_SENSITIVITY_AUTO;
729 range->layout->lower_sensitive = TRUE;
730 range->layout->upper_sensitive = TRUE;
731 range->layout->show_fill_level = FALSE;
732 range->layout->restrict_to_fill_level = TRUE;
733 range->layout->fill_level = G_MAXDOUBLE;
738 * gtk_range_get_adjustment:
739 * @range: a #GtkRange
741 * Get the #GtkAdjustment which is the "model" object for #GtkRange.
742 * See gtk_range_set_adjustment() for details.
743 * The return value does not have a reference added, so should not
746 * Return value: a #GtkAdjustment
749 gtk_range_get_adjustment (GtkRange *range)
751 g_return_val_if_fail (GTK_IS_RANGE (range), NULL);
753 if (!range->adjustment)
754 gtk_range_set_adjustment (range, NULL);
756 return range->adjustment;
760 * gtk_range_set_update_policy:
761 * @range: a #GtkRange
762 * @policy: update policy
764 * Sets the update policy for the range. #GTK_UPDATE_CONTINUOUS means that
765 * anytime the range slider is moved, the range value will change and the
766 * value_changed signal will be emitted. #GTK_UPDATE_DELAYED means that
767 * the value will be updated after a brief timeout where no slider motion
768 * occurs, so updates are spaced by a short time rather than
769 * continuous. #GTK_UPDATE_DISCONTINUOUS means that the value will only
770 * be updated when the user releases the button and ends the slider
774 gtk_range_set_update_policy (GtkRange *range,
775 GtkUpdateType policy)
777 g_return_if_fail (GTK_IS_RANGE (range));
779 if (range->update_policy != policy)
781 range->update_policy = policy;
782 g_object_notify (G_OBJECT (range), "update-policy");
787 * gtk_range_get_update_policy:
788 * @range: a #GtkRange
790 * Gets the update policy of @range. See gtk_range_set_update_policy().
792 * Return value: the current update policy
795 gtk_range_get_update_policy (GtkRange *range)
797 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_UPDATE_CONTINUOUS);
799 return range->update_policy;
803 * gtk_range_set_adjustment:
804 * @range: a #GtkRange
805 * @adjustment: a #GtkAdjustment
807 * Sets the adjustment to be used as the "model" object for this range
808 * widget. The adjustment indicates the current range value, the
809 * minimum and maximum range values, the step/page increments used
810 * for keybindings and scrolling, and the page size. The page size
811 * is normally 0 for #GtkScale and nonzero for #GtkScrollbar, and
812 * indicates the size of the visible area of the widget being scrolled.
813 * The page size affects the size of the scrollbar slider.
816 gtk_range_set_adjustment (GtkRange *range,
817 GtkAdjustment *adjustment)
819 g_return_if_fail (GTK_IS_RANGE (range));
822 adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
824 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
826 if (range->adjustment != adjustment)
828 if (range->adjustment)
830 g_signal_handlers_disconnect_by_func (range->adjustment,
831 gtk_range_adjustment_changed,
833 g_signal_handlers_disconnect_by_func (range->adjustment,
834 gtk_range_adjustment_value_changed,
836 g_object_unref (range->adjustment);
839 range->adjustment = adjustment;
840 g_object_ref_sink (adjustment);
842 g_signal_connect (adjustment, "changed",
843 G_CALLBACK (gtk_range_adjustment_changed),
845 g_signal_connect (adjustment, "value-changed",
846 G_CALLBACK (gtk_range_adjustment_value_changed),
849 gtk_range_adjustment_changed (adjustment, range);
850 g_object_notify (G_OBJECT (range), "adjustment");
855 * gtk_range_set_inverted:
856 * @range: a #GtkRange
857 * @setting: %TRUE to invert the range
859 * Ranges normally move from lower to higher values as the
860 * slider moves from top to bottom or left to right. Inverted
861 * ranges have higher values at the top or on the right rather than
862 * on the bottom or left.
865 gtk_range_set_inverted (GtkRange *range,
868 g_return_if_fail (GTK_IS_RANGE (range));
870 setting = setting != FALSE;
872 if (setting != range->inverted)
874 range->inverted = setting;
875 g_object_notify (G_OBJECT (range), "inverted");
876 gtk_widget_queue_resize (GTK_WIDGET (range));
881 * gtk_range_get_inverted:
882 * @range: a #GtkRange
884 * Gets the value set by gtk_range_set_inverted().
886 * Return value: %TRUE if the range is inverted
889 gtk_range_get_inverted (GtkRange *range)
891 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
893 return range->inverted;
897 * gtk_range_set_flippable:
898 * @range: a #GtkRange
899 * @flippable: %TRUE to make the range flippable
901 * If a range is flippable, it will switch its direction if it is
902 * horizontal and its direction is %GTK_TEXT_DIR_RTL.
904 * See gtk_widget_get_direction().
909 gtk_range_set_flippable (GtkRange *range,
912 g_return_if_fail (GTK_IS_RANGE (range));
914 flippable = flippable ? TRUE : FALSE;
916 if (flippable != range->flippable)
918 range->flippable = flippable;
920 gtk_widget_queue_draw (GTK_WIDGET (range));
925 * gtk_range_get_flippable:
926 * @range: a #GtkRange
928 * Gets the value set by gtk_range_set_flippable().
930 * Return value: %TRUE if the range is flippable
935 gtk_range_get_flippable (GtkRange *range)
937 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
939 return range->flippable;
943 * gtk_range_set_slider_size_fixed:
944 * @range: a #GtkRange
945 * @size_fixed: %TRUE to make the slider size constant
947 * Sets whether the range's slider has a fixed size, or a size that
948 * depends on it's adjustment's page size.
950 * This function is useful mainly for #GtkRange subclasses.
955 gtk_range_set_slider_size_fixed (GtkRange *range,
958 g_return_if_fail (GTK_IS_RANGE (range));
960 if (size_fixed != range->slider_size_fixed)
962 range->slider_size_fixed = size_fixed ? TRUE : FALSE;
964 if (range->adjustment && gtk_widget_get_mapped (GTK_WIDGET (range)))
966 range->need_recalc = TRUE;
967 gtk_range_calc_layout (range, gtk_adjustment_get_value (range->adjustment));
968 gtk_widget_queue_draw (GTK_WIDGET (range));
974 * gtk_range_get_slider_size_fixed:
975 * @range: a #GtkRange
977 * This function is useful mainly for #GtkRange subclasses.
979 * See gtk_range_set_slider_size_fixed().
981 * Return value: whether the range's slider has a fixed size.
986 gtk_range_get_slider_size_fixed (GtkRange *range)
988 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
990 return range->slider_size_fixed;
994 * gtk_range_set_min_slider_size:
995 * @range: a #GtkRange
996 * @min_size: The slider's minimum size
998 * Sets the minimum size of the range's slider.
1000 * This function is useful mainly for #GtkRange subclasses.
1005 gtk_range_set_min_slider_size (GtkRange *range,
1008 g_return_if_fail (GTK_IS_RANGE (range));
1009 g_return_if_fail (min_size > 0);
1011 if (min_size != range->min_slider_size)
1013 range->min_slider_size = min_size;
1015 range->need_recalc = TRUE;
1016 gtk_range_calc_layout (range, range->adjustment->value);
1017 gtk_widget_queue_draw (GTK_WIDGET (range));
1022 * gtk_range_get_min_slider_size:
1023 * @range: a #GtkRange
1025 * This function is useful mainly for #GtkRange subclasses.
1027 * See gtk_range_set_min_slider_size().
1029 * Return value: The minimum size of the range's slider.
1034 gtk_range_get_min_slider_size (GtkRange *range)
1036 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1038 return range->min_slider_size;
1042 * gtk_range_get_range_rect:
1043 * @range: a #GtkRange
1044 * @range_rect: return location for the range rectangle
1046 * This function returns the area that contains the range's trough
1047 * and its steppers, in widget->window coordinates.
1049 * This function is useful mainly for #GtkRange subclasses.
1054 gtk_range_get_range_rect (GtkRange *range,
1055 GdkRectangle *range_rect)
1057 g_return_if_fail (GTK_IS_RANGE (range));
1058 g_return_if_fail (range_rect != NULL);
1060 gtk_range_calc_layout (range, range->adjustment->value);
1062 *range_rect = range->range_rect;
1066 * gtk_range_get_slider_range:
1067 * @range: a #GtkRange
1068 * @slider_start: (allow-none): return location for the slider's start, or %NULL
1069 * @slider_end: (allow-none): return location for the slider's end, or %NULL
1071 * This function returns sliders range along the long dimension,
1072 * in widget->window coordinates.
1074 * This function is useful mainly for #GtkRange subclasses.
1079 gtk_range_get_slider_range (GtkRange *range,
1083 g_return_if_fail (GTK_IS_RANGE (range));
1085 gtk_range_calc_layout (range, range->adjustment->value);
1088 *slider_start = range->slider_start;
1091 *slider_end = range->slider_end;
1095 * gtk_range_set_lower_stepper_sensitivity:
1096 * @range: a #GtkRange
1097 * @sensitivity: the lower stepper's sensitivity policy.
1099 * Sets the sensitivity policy for the stepper that points to the
1100 * 'lower' end of the GtkRange's adjustment.
1105 gtk_range_set_lower_stepper_sensitivity (GtkRange *range,
1106 GtkSensitivityType sensitivity)
1108 g_return_if_fail (GTK_IS_RANGE (range));
1110 if (range->layout->lower_sensitivity != sensitivity)
1112 range->layout->lower_sensitivity = sensitivity;
1114 range->need_recalc = TRUE;
1115 gtk_range_calc_layout (range, range->adjustment->value);
1116 gtk_widget_queue_draw (GTK_WIDGET (range));
1118 g_object_notify (G_OBJECT (range), "lower-stepper-sensitivity");
1123 * gtk_range_get_lower_stepper_sensitivity:
1124 * @range: a #GtkRange
1126 * Gets the sensitivity policy for the stepper that points to the
1127 * 'lower' end of the GtkRange's adjustment.
1129 * Return value: The lower stepper's sensitivity policy.
1134 gtk_range_get_lower_stepper_sensitivity (GtkRange *range)
1136 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
1138 return range->layout->lower_sensitivity;
1142 * gtk_range_set_upper_stepper_sensitivity:
1143 * @range: a #GtkRange
1144 * @sensitivity: the upper stepper's sensitivity policy.
1146 * Sets the sensitivity policy for the stepper that points to the
1147 * 'upper' end of the GtkRange's adjustment.
1152 gtk_range_set_upper_stepper_sensitivity (GtkRange *range,
1153 GtkSensitivityType sensitivity)
1155 g_return_if_fail (GTK_IS_RANGE (range));
1157 if (range->layout->upper_sensitivity != sensitivity)
1159 range->layout->upper_sensitivity = sensitivity;
1161 range->need_recalc = TRUE;
1162 gtk_range_calc_layout (range, range->adjustment->value);
1163 gtk_widget_queue_draw (GTK_WIDGET (range));
1165 g_object_notify (G_OBJECT (range), "upper-stepper-sensitivity");
1170 * gtk_range_get_upper_stepper_sensitivity:
1171 * @range: a #GtkRange
1173 * Gets the sensitivity policy for the stepper that points to the
1174 * 'upper' end of the GtkRange's adjustment.
1176 * Return value: The upper stepper's sensitivity policy.
1181 gtk_range_get_upper_stepper_sensitivity (GtkRange *range)
1183 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
1185 return range->layout->upper_sensitivity;
1189 * gtk_range_set_increments:
1190 * @range: a #GtkRange
1194 * Sets the step and page sizes for the range.
1195 * The step size is used when the user clicks the #GtkScrollbar
1196 * arrows or moves #GtkScale via arrow keys. The page size
1197 * is used for example when moving via Page Up or Page Down keys.
1200 gtk_range_set_increments (GtkRange *range,
1204 g_return_if_fail (GTK_IS_RANGE (range));
1206 range->adjustment->step_increment = step;
1207 range->adjustment->page_increment = page;
1209 gtk_adjustment_changed (range->adjustment);
1213 * gtk_range_set_range:
1214 * @range: a #GtkRange
1215 * @min: minimum range value
1216 * @max: maximum range value
1218 * Sets the allowable values in the #GtkRange, and clamps the range
1219 * value to be between @min and @max. (If the range has a non-zero
1220 * page size, it is clamped between @min and @max - page-size.)
1223 gtk_range_set_range (GtkRange *range,
1229 g_return_if_fail (GTK_IS_RANGE (range));
1230 g_return_if_fail (min < max);
1232 range->adjustment->lower = min;
1233 range->adjustment->upper = max;
1235 value = range->adjustment->value;
1237 if (range->layout->restrict_to_fill_level)
1238 value = MIN (value, MAX (range->adjustment->lower,
1239 range->layout->fill_level));
1241 gtk_adjustment_set_value (range->adjustment, value);
1242 gtk_adjustment_changed (range->adjustment);
1246 * gtk_range_set_value:
1247 * @range: a #GtkRange
1248 * @value: new value of the range
1250 * Sets the current value of the range; if the value is outside the
1251 * minimum or maximum range values, it will be clamped to fit inside
1252 * them. The range emits the #GtkRange::value-changed signal if the
1256 gtk_range_set_value (GtkRange *range,
1259 g_return_if_fail (GTK_IS_RANGE (range));
1261 if (range->layout->restrict_to_fill_level)
1262 value = MIN (value, MAX (range->adjustment->lower,
1263 range->layout->fill_level));
1265 gtk_adjustment_set_value (range->adjustment, value);
1269 * gtk_range_get_value:
1270 * @range: a #GtkRange
1272 * Gets the current value of the range.
1274 * Return value: current value of the range.
1277 gtk_range_get_value (GtkRange *range)
1279 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1281 return range->adjustment->value;
1285 * gtk_range_set_show_fill_level:
1286 * @range: A #GtkRange
1287 * @show_fill_level: Whether a fill level indicator graphics is shown.
1289 * Sets whether a graphical fill level is show on the trough. See
1290 * gtk_range_set_fill_level() for a general description of the fill
1296 gtk_range_set_show_fill_level (GtkRange *range,
1297 gboolean show_fill_level)
1299 g_return_if_fail (GTK_IS_RANGE (range));
1301 show_fill_level = show_fill_level ? TRUE : FALSE;
1303 if (show_fill_level != range->layout->show_fill_level)
1305 range->layout->show_fill_level = show_fill_level;
1306 g_object_notify (G_OBJECT (range), "show-fill-level");
1307 gtk_widget_queue_draw (GTK_WIDGET (range));
1312 * gtk_range_get_show_fill_level:
1313 * @range: A #GtkRange
1315 * Gets whether the range displays the fill level graphically.
1317 * Return value: %TRUE if @range shows the fill level.
1322 gtk_range_get_show_fill_level (GtkRange *range)
1324 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1326 return range->layout->show_fill_level;
1330 * gtk_range_set_restrict_to_fill_level:
1331 * @range: A #GtkRange
1332 * @restrict_to_fill_level: Whether the fill level restricts slider movement.
1334 * Sets whether the slider is restricted to the fill level. See
1335 * gtk_range_set_fill_level() for a general description of the fill
1341 gtk_range_set_restrict_to_fill_level (GtkRange *range,
1342 gboolean restrict_to_fill_level)
1344 g_return_if_fail (GTK_IS_RANGE (range));
1346 restrict_to_fill_level = restrict_to_fill_level ? TRUE : FALSE;
1348 if (restrict_to_fill_level != range->layout->restrict_to_fill_level)
1350 range->layout->restrict_to_fill_level = restrict_to_fill_level;
1351 g_object_notify (G_OBJECT (range), "restrict-to-fill-level");
1353 gtk_range_set_value (range, gtk_range_get_value (range));
1358 * gtk_range_get_restrict_to_fill_level:
1359 * @range: A #GtkRange
1361 * Gets whether the range is restricted to the fill level.
1363 * Return value: %TRUE if @range is restricted to the fill level.
1368 gtk_range_get_restrict_to_fill_level (GtkRange *range)
1370 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1372 return range->layout->restrict_to_fill_level;
1376 * gtk_range_set_fill_level:
1377 * @range: a #GtkRange
1378 * @fill_level: the new position of the fill level indicator
1380 * Set the new position of the fill level indicator.
1382 * The "fill level" is probably best described by its most prominent
1383 * use case, which is an indicator for the amount of pre-buffering in
1384 * a streaming media player. In that use case, the value of the range
1385 * would indicate the current play position, and the fill level would
1386 * be the position up to which the file/stream has been downloaded.
1388 * This amount of prebuffering can be displayed on the range's trough
1389 * and is themeable separately from the trough. To enable fill level
1390 * display, use gtk_range_set_show_fill_level(). The range defaults
1391 * to not showing the fill level.
1393 * Additionally, it's possible to restrict the range's slider position
1394 * to values which are smaller than the fill level. This is controller
1395 * by gtk_range_set_restrict_to_fill_level() and is by default
1401 gtk_range_set_fill_level (GtkRange *range,
1404 g_return_if_fail (GTK_IS_RANGE (range));
1406 if (fill_level != range->layout->fill_level)
1408 range->layout->fill_level = fill_level;
1409 g_object_notify (G_OBJECT (range), "fill-level");
1411 if (range->layout->show_fill_level)
1412 gtk_widget_queue_draw (GTK_WIDGET (range));
1414 if (range->layout->restrict_to_fill_level)
1415 gtk_range_set_value (range, gtk_range_get_value (range));
1420 * gtk_range_get_fill_level:
1421 * @range : A #GtkRange
1423 * Gets the current position of the fill level indicator.
1425 * Return value: The current fill level
1430 gtk_range_get_fill_level (GtkRange *range)
1432 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1434 return range->layout->fill_level;
1438 should_invert (GtkRange *range)
1440 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1442 (range->inverted && !range->flippable) ||
1443 (range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_LTR) ||
1444 (!range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_RTL);
1446 return range->inverted;
1450 gtk_range_destroy (GtkObject *object)
1452 GtkRange *range = GTK_RANGE (object);
1454 gtk_range_remove_step_timer (range);
1455 gtk_range_remove_update_timer (range);
1457 if (range->layout->repaint_id)
1458 g_source_remove (range->layout->repaint_id);
1459 range->layout->repaint_id = 0;
1461 if (range->adjustment)
1463 g_signal_handlers_disconnect_by_func (range->adjustment,
1464 gtk_range_adjustment_changed,
1466 g_signal_handlers_disconnect_by_func (range->adjustment,
1467 gtk_range_adjustment_value_changed,
1469 g_object_unref (range->adjustment);
1470 range->adjustment = NULL;
1473 if (range->layout->n_marks)
1475 g_free (range->layout->marks);
1476 range->layout->marks = NULL;
1477 g_free (range->layout->mark_pos);
1478 range->layout->mark_pos = NULL;
1479 range->layout->n_marks = 0;
1482 GTK_OBJECT_CLASS (gtk_range_parent_class)->destroy (object);
1486 gtk_range_size_request (GtkWidget *widget,
1487 GtkRequisition *requisition)
1490 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
1491 GdkRectangle range_rect;
1494 range = GTK_RANGE (widget);
1496 gtk_range_get_props (range,
1497 &slider_width, &stepper_size,
1498 &focus_width, &trough_border,
1499 &stepper_spacing, NULL,
1502 gtk_range_calc_request (range,
1503 slider_width, stepper_size,
1504 focus_width, trough_border, stepper_spacing,
1505 &range_rect, &border, NULL, NULL, NULL, NULL);
1507 requisition->width = range_rect.width + border.left + border.right;
1508 requisition->height = range_rect.height + border.top + border.bottom;
1512 gtk_range_size_allocate (GtkWidget *widget,
1513 GtkAllocation *allocation)
1517 range = GTK_RANGE (widget);
1519 gtk_widget_set_allocation (widget, allocation);
1521 range->layout->recalc_marks = TRUE;
1523 range->need_recalc = TRUE;
1524 gtk_range_calc_layout (range, range->adjustment->value);
1526 if (gtk_widget_get_realized (widget))
1527 gdk_window_move_resize (range->event_window,
1528 allocation->x, allocation->y,
1529 allocation->width, allocation->height);
1533 gtk_range_realize (GtkWidget *widget)
1535 GtkAllocation allocation;
1538 GdkWindowAttr attributes;
1539 gint attributes_mask;
1541 range = GTK_RANGE (widget);
1543 gtk_range_calc_layout (range, range->adjustment->value);
1545 gtk_widget_set_realized (widget, TRUE);
1547 window = gtk_widget_get_parent_window (widget);
1548 gtk_widget_set_window (widget, window);
1549 g_object_ref (window);
1551 gtk_widget_get_allocation (widget, &allocation);
1553 attributes.window_type = GDK_WINDOW_CHILD;
1554 attributes.x = allocation.x;
1555 attributes.y = allocation.y;
1556 attributes.width = allocation.width;
1557 attributes.height = allocation.height;
1558 attributes.wclass = GDK_INPUT_ONLY;
1559 attributes.event_mask = gtk_widget_get_events (widget);
1560 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1561 GDK_BUTTON_RELEASE_MASK |
1562 GDK_ENTER_NOTIFY_MASK |
1563 GDK_LEAVE_NOTIFY_MASK |
1564 GDK_POINTER_MOTION_MASK |
1565 GDK_POINTER_MOTION_HINT_MASK);
1567 attributes_mask = GDK_WA_X | GDK_WA_Y;
1569 range->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1570 &attributes, attributes_mask);
1571 gdk_window_set_user_data (range->event_window, range);
1573 gtk_widget_style_attach (widget);
1577 gtk_range_unrealize (GtkWidget *widget)
1579 GtkRange *range = GTK_RANGE (widget);
1581 gtk_range_remove_step_timer (range);
1582 gtk_range_remove_update_timer (range);
1584 gdk_window_set_user_data (range->event_window, NULL);
1585 gdk_window_destroy (range->event_window);
1586 range->event_window = NULL;
1588 GTK_WIDGET_CLASS (gtk_range_parent_class)->unrealize (widget);
1592 gtk_range_map (GtkWidget *widget)
1594 GtkRange *range = GTK_RANGE (widget);
1596 gdk_window_show (range->event_window);
1598 GTK_WIDGET_CLASS (gtk_range_parent_class)->map (widget);
1602 gtk_range_unmap (GtkWidget *widget)
1604 GtkRange *range = GTK_RANGE (widget);
1606 stop_scrolling (range);
1608 gdk_window_hide (range->event_window);
1610 GTK_WIDGET_CLASS (gtk_range_parent_class)->unmap (widget);
1613 static const gchar *
1614 gtk_range_get_slider_detail (GtkRange *range)
1616 const gchar *slider_detail;
1618 if (range->layout->slider_detail_quark)
1619 return g_quark_to_string (range->layout->slider_detail_quark);
1621 slider_detail = GTK_RANGE_GET_CLASS (range)->slider_detail;
1623 if (slider_detail && slider_detail[0] == 'X')
1625 gchar *detail = g_strdup (slider_detail);
1627 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1629 range->layout->slider_detail_quark = g_quark_from_string (detail);
1633 return g_quark_to_string (range->layout->slider_detail_quark);
1636 return slider_detail;
1639 static const gchar *
1640 gtk_range_get_stepper_detail (GtkRange *range,
1643 const gchar *stepper_detail;
1644 gboolean need_orientation;
1645 gboolean need_position;
1647 if (range->layout->stepper_detail_quark[stepper])
1648 return g_quark_to_string (range->layout->stepper_detail_quark[stepper]);
1650 stepper_detail = GTK_RANGE_GET_CLASS (range)->stepper_detail;
1652 need_orientation = stepper_detail && stepper_detail[0] == 'X';
1654 gtk_widget_style_get (GTK_WIDGET (range),
1655 "stepper-position-details", &need_position,
1658 if (need_orientation || need_position)
1661 const gchar *position = NULL;
1668 position = "_start";
1671 if (range->has_stepper_a)
1672 position = "_start_inner";
1674 position = "_start";
1677 if (range->has_stepper_d)
1678 position = "_end_inner";
1686 g_assert_not_reached ();
1690 detail = g_strconcat (stepper_detail, position, NULL);
1692 if (need_orientation)
1693 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1695 range->layout->stepper_detail_quark[stepper] = g_quark_from_string (detail);
1699 return g_quark_to_string (range->layout->stepper_detail_quark[stepper]);
1702 return stepper_detail;
1706 draw_stepper (GtkRange *range,
1708 GtkArrowType arrow_type,
1710 gboolean prelighted,
1713 GtkAllocation allocation;
1714 GtkStateType state_type;
1715 GtkShadowType shadow_type;
1717 GtkWidget *widget = GTK_WIDGET (range);
1718 GdkRectangle intersection;
1720 gfloat arrow_scaling;
1730 rect = &range->layout->stepper_a;
1733 rect = &range->layout->stepper_b;
1736 rect = &range->layout->stepper_c;
1739 rect = &range->layout->stepper_d;
1742 g_assert_not_reached ();
1745 gboolean arrow_sensitive = TRUE;
1747 /* More to get the right clip region than for efficiency */
1748 if (!gdk_rectangle_intersect (area, rect, &intersection))
1751 gtk_widget_get_allocation (widget, &allocation);
1753 intersection.x += allocation.x;
1754 intersection.y += allocation.y;
1756 if ((!range->inverted && (arrow_type == GTK_ARROW_DOWN ||
1757 arrow_type == GTK_ARROW_RIGHT)) ||
1758 (range->inverted && (arrow_type == GTK_ARROW_UP ||
1759 arrow_type == GTK_ARROW_LEFT)))
1761 arrow_sensitive = range->layout->upper_sensitive;
1765 arrow_sensitive = range->layout->lower_sensitive;
1768 if (!gtk_widget_is_sensitive (GTK_WIDGET (range)) || !arrow_sensitive)
1769 state_type = GTK_STATE_INSENSITIVE;
1771 state_type = GTK_STATE_ACTIVE;
1772 else if (prelighted)
1773 state_type = GTK_STATE_PRELIGHT;
1775 state_type = GTK_STATE_NORMAL;
1777 if (clicked && arrow_sensitive)
1778 shadow_type = GTK_SHADOW_IN;
1780 shadow_type = GTK_SHADOW_OUT;
1782 style = gtk_widget_get_style (widget);
1783 window = gtk_widget_get_window (widget);
1785 gtk_paint_box (style, window,
1786 state_type, shadow_type,
1787 &intersection, widget,
1788 gtk_range_get_stepper_detail (range, stepper),
1789 allocation.x + rect->x,
1790 allocation.y + rect->y,
1794 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
1796 arrow_width = rect->width * arrow_scaling;
1797 arrow_height = rect->height * arrow_scaling;
1798 arrow_x = allocation.x + rect->x + (rect->width - arrow_width) / 2;
1799 arrow_y = allocation.y + rect->y + (rect->height - arrow_height) / 2;
1801 if (clicked && arrow_sensitive)
1803 gint arrow_displacement_x;
1804 gint arrow_displacement_y;
1806 gtk_range_get_props (GTK_RANGE (widget),
1807 NULL, NULL, NULL, NULL, NULL, NULL,
1808 &arrow_displacement_x, &arrow_displacement_y);
1810 arrow_x += arrow_displacement_x;
1811 arrow_y += arrow_displacement_y;
1814 gtk_paint_arrow (style, window,
1815 state_type, shadow_type,
1816 &intersection, widget,
1817 gtk_range_get_stepper_detail (range, stepper),
1820 arrow_x, arrow_y, arrow_width, arrow_height);
1824 gtk_range_expose (GtkWidget *widget,
1825 GdkEventExpose *event)
1827 GtkAllocation allocation;
1828 GtkRange *range = GTK_RANGE (widget);
1831 GtkShadowType shadow_type;
1833 GdkRectangle expose_area; /* Relative to widget->allocation */
1836 gint focus_line_width = 0;
1837 gint focus_padding = 0;
1838 gboolean touchscreen;
1840 g_object_get (gtk_widget_get_settings (widget),
1841 "gtk-touchscreen-mode", &touchscreen,
1844 style = gtk_widget_get_style (widget);
1845 if (gtk_widget_get_can_focus (GTK_WIDGET (range)))
1846 gtk_widget_style_get (GTK_WIDGET (range),
1847 "focus-line-width", &focus_line_width,
1848 "focus-padding", &focus_padding,
1851 window = gtk_widget_get_window (widget);
1853 /* we're now exposing, so there's no need to force early repaints */
1854 if (range->layout->repaint_id)
1855 g_source_remove (range->layout->repaint_id);
1856 range->layout->repaint_id = 0;
1858 gtk_widget_get_allocation (widget, &allocation);
1860 expose_area = event->area;
1861 expose_area.x -= allocation.x;
1862 expose_area.y -= allocation.y;
1864 gtk_range_calc_marks (range);
1865 gtk_range_calc_layout (range, range->adjustment->value);
1867 sensitive = gtk_widget_is_sensitive (widget);
1869 /* Just to be confusing, we draw the trough for the whole
1870 * range rectangle, not the trough rectangle (the trough
1871 * rectangle is just for hit detection)
1873 /* The gdk_rectangle_intersect is more to get the right
1874 * clip region (limited to range_rect) than for efficiency
1876 if (gdk_rectangle_intersect (&expose_area, &range->range_rect,
1879 gint x = (allocation.x + range->range_rect.x +
1880 focus_line_width + focus_padding);
1881 gint y = (allocation.y + range->range_rect.y +
1882 focus_line_width + focus_padding);
1883 gint width = (range->range_rect.width -
1884 2 * (focus_line_width + focus_padding));
1885 gint height = (range->range_rect.height -
1886 2 * (focus_line_width + focus_padding));
1887 gboolean trough_side_details;
1888 gboolean trough_under_steppers;
1890 gint stepper_spacing;
1892 area.x += allocation.x;
1893 area.y += allocation.y;
1895 gtk_widget_style_get (GTK_WIDGET (range),
1896 "trough-side-details", &trough_side_details,
1897 "trough-under-steppers", &trough_under_steppers,
1898 "stepper-size", &stepper_size,
1899 "stepper-spacing", &stepper_spacing,
1902 if (stepper_spacing > 0)
1903 trough_under_steppers = FALSE;
1905 if (! trough_under_steppers)
1910 if (range->has_stepper_a)
1911 offset += stepper_size;
1913 if (range->has_stepper_b)
1914 offset += stepper_size;
1918 if (range->has_stepper_c)
1919 shorter += stepper_size;
1921 if (range->has_stepper_d)
1922 shorter += stepper_size;
1924 if (range->has_stepper_a || range->has_stepper_b)
1926 offset += stepper_spacing;
1927 shorter += stepper_spacing;
1930 if (range->has_stepper_c || range->has_stepper_d)
1932 shorter += stepper_spacing;
1935 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1947 if (! trough_side_details)
1949 gtk_paint_box (style, window,
1950 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1952 &area, GTK_WIDGET(range), "trough",
1958 gint trough_change_pos_x = width;
1959 gint trough_change_pos_y = height;
1961 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1962 trough_change_pos_x = (range->layout->slider.x +
1963 range->layout->slider.width / 2 -
1964 (x - allocation.x));
1966 trough_change_pos_y = (range->layout->slider.y +
1967 range->layout->slider.height / 2 -
1968 (y - allocation.y));
1970 gtk_paint_box (style, window,
1971 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1973 &area, GTK_WIDGET (range),
1974 should_invert (range) ? "trough-upper" : "trough-lower",
1976 trough_change_pos_x, trough_change_pos_y);
1978 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1979 trough_change_pos_y = 0;
1981 trough_change_pos_x = 0;
1983 gtk_paint_box (style, window,
1984 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1986 &area, GTK_WIDGET (range),
1987 should_invert (range) ? "trough-lower" : "trough-upper",
1988 x + trough_change_pos_x, y + trough_change_pos_y,
1989 width - trough_change_pos_x,
1990 height - trough_change_pos_y);
1993 if (range->layout->show_fill_level &&
1994 range->adjustment->upper - range->adjustment->page_size -
1995 range->adjustment->lower != 0)
1997 gdouble fill_level = range->layout->fill_level;
2000 gint fill_width = width;
2001 gint fill_height = height;
2004 fill_level = CLAMP (fill_level, range->adjustment->lower,
2005 range->adjustment->upper -
2006 range->adjustment->page_size);
2008 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
2010 fill_x = allocation.x + range->layout->trough.x;
2011 fill_width = (range->layout->slider.width +
2012 (fill_level - range->adjustment->lower) /
2013 (range->adjustment->upper -
2014 range->adjustment->lower -
2015 range->adjustment->page_size) *
2016 (range->layout->trough.width -
2017 range->layout->slider.width));
2019 if (should_invert (range))
2020 fill_x += range->layout->trough.width - fill_width;
2024 fill_y = allocation.y + range->layout->trough.y;
2025 fill_height = (range->layout->slider.height +
2026 (fill_level - range->adjustment->lower) /
2027 (range->adjustment->upper -
2028 range->adjustment->lower -
2029 range->adjustment->page_size) *
2030 (range->layout->trough.height -
2031 range->layout->slider.height));
2033 if (should_invert (range))
2034 fill_y += range->layout->trough.height - fill_height;
2037 if (fill_level < range->adjustment->upper - range->adjustment->page_size)
2038 fill_detail = "trough-fill-level-full";
2040 fill_detail = "trough-fill-level";
2042 gtk_paint_box (style, window,
2043 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
2045 &area, GTK_WIDGET (range), fill_detail,
2047 fill_width, fill_height);
2050 if (sensitive && gtk_widget_has_focus (widget))
2051 gtk_paint_focus (style, window,
2052 gtk_widget_get_state (widget),
2053 &area, widget, "trough",
2054 allocation.x + range->range_rect.x,
2055 allocation.y + range->range_rect.y,
2056 range->range_rect.width,
2057 range->range_rect.height);
2060 shadow_type = GTK_SHADOW_OUT;
2063 state = GTK_STATE_INSENSITIVE;
2064 else if (!touchscreen && range->layout->mouse_location == MOUSE_SLIDER)
2065 state = GTK_STATE_PRELIGHT;
2067 state = GTK_STATE_NORMAL;
2069 if (range->layout->grab_location == MOUSE_SLIDER)
2071 gboolean activate_slider;
2073 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
2075 if (activate_slider)
2077 state = GTK_STATE_ACTIVE;
2078 shadow_type = GTK_SHADOW_IN;
2082 if (gdk_rectangle_intersect (&expose_area,
2083 &range->layout->slider,
2086 area.x += allocation.x;
2087 area.y += allocation.y;
2089 gtk_paint_slider (style,
2095 gtk_range_get_slider_detail (range),
2096 allocation.x + range->layout->slider.x,
2097 allocation.y + range->layout->slider.y,
2098 range->layout->slider.width,
2099 range->layout->slider.height,
2100 range->orientation);
2103 if (range->has_stepper_a)
2104 draw_stepper (range, STEPPER_A,
2105 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
2106 range->layout->grab_location == MOUSE_STEPPER_A,
2107 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_A,
2110 if (range->has_stepper_b)
2111 draw_stepper (range, STEPPER_B,
2112 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
2113 range->layout->grab_location == MOUSE_STEPPER_B,
2114 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_B,
2117 if (range->has_stepper_c)
2118 draw_stepper (range, STEPPER_C,
2119 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
2120 range->layout->grab_location == MOUSE_STEPPER_C,
2121 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_C,
2124 if (range->has_stepper_d)
2125 draw_stepper (range, STEPPER_D,
2126 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
2127 range->layout->grab_location == MOUSE_STEPPER_D,
2128 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_D,
2135 range_grab_add (GtkRange *range,
2137 MouseLocation location,
2140 GtkRangeLayout *layout = range->layout;
2142 if (device == layout->grab_device)
2145 if (layout->grab_device != NULL)
2147 g_warning ("GtkRange already had a grab device, releasing device grab");
2148 gtk_device_grab_remove (GTK_WIDGET (range), layout->grab_device);
2151 /* we don't actually gdk_grab, since a button is down */
2152 gtk_device_grab_add (GTK_WIDGET (range), device, TRUE);
2154 range->layout->grab_location = location;
2155 range->layout->grab_button = button;
2156 range->layout->grab_device = device;
2158 if (gtk_range_update_mouse_location (range))
2159 gtk_widget_queue_draw (GTK_WIDGET (range));
2163 range_grab_remove (GtkRange *range)
2165 GtkRangeLayout *layout = range->layout;
2166 MouseLocation location;
2168 if (layout->grab_device)
2170 gtk_device_grab_remove (GTK_WIDGET (range),
2171 layout->grab_device);
2172 layout->grab_device = NULL;
2175 location = range->layout->grab_location;
2176 range->layout->grab_location = MOUSE_OUTSIDE;
2177 range->layout->grab_button = 0;
2179 if (gtk_range_update_mouse_location (range) ||
2180 location != MOUSE_OUTSIDE)
2181 gtk_widget_queue_draw (GTK_WIDGET (range));
2184 static GtkScrollType
2185 range_get_scroll_for_grab (GtkRange *range)
2189 invert = should_invert (range);
2190 switch (range->layout->grab_location)
2192 /* Backward stepper */
2193 case MOUSE_STEPPER_A:
2194 case MOUSE_STEPPER_C:
2195 switch (range->layout->grab_button)
2198 return invert ? GTK_SCROLL_STEP_FORWARD : GTK_SCROLL_STEP_BACKWARD;
2201 return invert ? GTK_SCROLL_PAGE_FORWARD : GTK_SCROLL_PAGE_BACKWARD;
2204 return invert ? GTK_SCROLL_END : GTK_SCROLL_START;
2209 /* Forward stepper */
2210 case MOUSE_STEPPER_B:
2211 case MOUSE_STEPPER_D:
2212 switch (range->layout->grab_button)
2215 return invert ? GTK_SCROLL_STEP_BACKWARD : GTK_SCROLL_STEP_FORWARD;
2218 return invert ? GTK_SCROLL_PAGE_BACKWARD : GTK_SCROLL_PAGE_FORWARD;
2221 return invert ? GTK_SCROLL_START : GTK_SCROLL_END;
2229 if (range->trough_click_forward)
2230 return GTK_SCROLL_PAGE_FORWARD;
2232 return GTK_SCROLL_PAGE_BACKWARD;
2242 return GTK_SCROLL_NONE;
2246 coord_to_value (GtkRange *range,
2255 gint trough_under_steppers;
2257 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2259 trough_length = range->layout->trough.height;
2260 trough_start = range->layout->trough.y;
2261 slider_length = range->layout->slider.height;
2265 trough_length = range->layout->trough.width;
2266 trough_start = range->layout->trough.x;
2267 slider_length = range->layout->slider.width;
2270 gtk_range_get_props (range, NULL, NULL, NULL, &trough_border, NULL,
2271 &trough_under_steppers, NULL, NULL);
2273 if (! trough_under_steppers)
2275 trough_start += trough_border;
2276 trough_length -= 2 * trough_border;
2279 if (trough_length == slider_length)
2282 frac = (MAX (0, coord - trough_start) /
2283 (gdouble) (trough_length - slider_length));
2285 if (should_invert (range))
2288 value = range->adjustment->lower + frac * (range->adjustment->upper -
2289 range->adjustment->lower -
2290 range->adjustment->page_size);
2296 gtk_range_key_press (GtkWidget *widget,
2300 GtkRange *range = GTK_RANGE (widget);
2301 GtkRangeLayout *layout = range->layout;
2303 device = gdk_event_get_device ((GdkEvent *) event);
2304 device = gdk_device_get_associated_device (device);
2306 if (device == layout->grab_device &&
2307 event->keyval == GDK_Escape &&
2308 range->layout->grab_location != MOUSE_OUTSIDE)
2310 stop_scrolling (range);
2312 update_slider_position (range,
2313 range->slide_initial_coordinate,
2314 range->slide_initial_coordinate);
2319 return GTK_WIDGET_CLASS (gtk_range_parent_class)->key_press_event (widget, event);
2323 gtk_range_button_press (GtkWidget *widget,
2324 GdkEventButton *event)
2326 GtkRange *range = GTK_RANGE (widget);
2329 if (!gtk_widget_has_focus (widget))
2330 gtk_widget_grab_focus (widget);
2332 /* ignore presses when we're already doing something else. */
2333 if (range->layout->grab_location != MOUSE_OUTSIDE)
2336 device = gdk_event_get_device ((GdkEvent *) event);
2337 range->layout->mouse_x = event->x;
2338 range->layout->mouse_y = event->y;
2340 if (gtk_range_update_mouse_location (range))
2341 gtk_widget_queue_draw (widget);
2343 if (range->layout->mouse_location == MOUSE_TROUGH &&
2346 /* button 1 steps by page increment, as with button 2 on a stepper
2348 GtkScrollType scroll;
2349 gdouble click_value;
2351 click_value = coord_to_value (range,
2352 range->orientation == GTK_ORIENTATION_VERTICAL ?
2353 event->y : event->x);
2355 range->trough_click_forward = click_value > range->adjustment->value;
2356 range_grab_add (range, device, MOUSE_TROUGH, event->button);
2358 scroll = range_get_scroll_for_grab (range);
2360 gtk_range_add_step_timer (range, scroll);
2364 else if ((range->layout->mouse_location == MOUSE_STEPPER_A ||
2365 range->layout->mouse_location == MOUSE_STEPPER_B ||
2366 range->layout->mouse_location == MOUSE_STEPPER_C ||
2367 range->layout->mouse_location == MOUSE_STEPPER_D) &&
2368 (event->button == 1 || event->button == 2 || event->button == 3))
2370 GtkAllocation allocation;
2371 GdkRectangle *stepper_area;
2372 GtkScrollType scroll;
2374 range_grab_add (range, device, range->layout->mouse_location, event->button);
2376 stepper_area = get_area (range, range->layout->mouse_location);
2377 gtk_widget_get_allocation (widget, &allocation);
2378 gtk_widget_queue_draw_area (widget,
2379 allocation.x + stepper_area->x,
2380 allocation.y + stepper_area->y,
2381 stepper_area->width,
2382 stepper_area->height);
2384 scroll = range_get_scroll_for_grab (range);
2385 if (scroll != GTK_SCROLL_NONE)
2386 gtk_range_add_step_timer (range, scroll);
2390 else if ((range->layout->mouse_location == MOUSE_TROUGH &&
2391 event->button == 2) ||
2392 range->layout->mouse_location == MOUSE_SLIDER)
2394 gboolean need_value_update = FALSE;
2395 gboolean activate_slider;
2397 /* Any button can be used to drag the slider, but you can start
2398 * dragging the slider with a trough click using button 2;
2399 * On button 2 press, we warp the slider to mouse position,
2400 * then begin the slider drag.
2402 if (event->button == 2)
2404 gdouble slider_low_value, slider_high_value, new_value;
2407 coord_to_value (range,
2408 range->orientation == GTK_ORIENTATION_VERTICAL ?
2409 event->y : event->x);
2411 coord_to_value (range,
2412 range->orientation == GTK_ORIENTATION_VERTICAL ?
2413 event->y - range->layout->slider.height :
2414 event->x - range->layout->slider.width);
2416 /* compute new value for warped slider */
2417 new_value = slider_low_value + (slider_high_value - slider_low_value) / 2;
2419 /* recalc slider, so we can set slide_initial_slider_position
2422 range->need_recalc = TRUE;
2423 gtk_range_calc_layout (range, new_value);
2425 /* defer adjustment updates to update_slider_position() in order
2426 * to keep pixel quantisation
2428 need_value_update = TRUE;
2431 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2433 range->slide_initial_slider_position = range->layout->slider.y;
2434 range->slide_initial_coordinate = event->y;
2438 range->slide_initial_slider_position = range->layout->slider.x;
2439 range->slide_initial_coordinate = event->x;
2442 range_grab_add (range, device, MOUSE_SLIDER, event->button);
2444 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
2446 /* force a redraw, if the active slider is drawn differently to the
2449 if (activate_slider)
2450 gtk_widget_queue_draw (widget);
2452 if (need_value_update)
2453 update_slider_position (range, event->x, event->y);
2461 /* During a slide, move the slider as required given new mouse position */
2463 update_slider_position (GtkRange *range,
2476 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2477 delta = mouse_y - range->slide_initial_coordinate;
2479 delta = mouse_x - range->slide_initial_coordinate;
2481 c = range->slide_initial_slider_position + delta;
2483 new_value = coord_to_value (range, c);
2484 next_value = coord_to_value (range, c + 1);
2485 mark_delta = fabs (next_value - new_value);
2487 for (i = 0; i < range->layout->n_marks; i++)
2489 mark_value = range->layout->marks[i];
2491 if (fabs (range->adjustment->value - mark_value) < 3 * mark_delta)
2493 if (fabs (new_value - mark_value) < (range->slider_end - range->slider_start) * 0.5 * mark_delta)
2495 new_value = mark_value;
2501 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_JUMP, new_value,
2506 stop_scrolling (GtkRange *range)
2508 range_grab_remove (range);
2509 gtk_range_remove_step_timer (range);
2510 /* Flush any pending discontinuous/delayed updates */
2511 gtk_range_update_value (range);
2515 gtk_range_grab_broken (GtkWidget *widget,
2516 GdkEventGrabBroken *event)
2518 GtkRange *range = GTK_RANGE (widget);
2521 device = gdk_event_get_device ((GdkEvent *) event);
2523 if (device == range->layout->grab_device &&
2524 range->layout->grab_location != MOUSE_OUTSIDE)
2526 if (range->layout->grab_location == MOUSE_SLIDER)
2527 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2529 stop_scrolling (range);
2538 gtk_range_button_release (GtkWidget *widget,
2539 GdkEventButton *event)
2541 GtkRange *range = GTK_RANGE (widget);
2544 if (event->window == range->event_window)
2546 range->layout->mouse_x = event->x;
2547 range->layout->mouse_y = event->y;
2551 gdk_window_get_device_position (range->event_window,
2553 &range->layout->mouse_x,
2554 &range->layout->mouse_y,
2558 device = gdk_event_get_device ((GdkEvent *) event);
2560 if (range->layout->grab_device == device &&
2561 range->layout->grab_button == event->button)
2563 if (range->layout->grab_location == MOUSE_SLIDER)
2564 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2566 stop_scrolling (range);
2575 * _gtk_range_get_wheel_delta:
2576 * @range: a #GtkRange
2577 * @direction: A #GdkScrollDirection
2579 * Returns a good step value for the mouse wheel.
2581 * Return value: A good step value for the mouse wheel.
2586 _gtk_range_get_wheel_delta (GtkRange *range,
2587 GdkScrollDirection direction)
2589 GtkAdjustment *adj = range->adjustment;
2592 if (GTK_IS_SCROLLBAR (range))
2593 delta = pow (adj->page_size, 2.0 / 3.0);
2595 delta = adj->step_increment * 2;
2597 if (direction == GDK_SCROLL_UP ||
2598 direction == GDK_SCROLL_LEFT)
2601 if (range->inverted)
2608 gtk_range_scroll_event (GtkWidget *widget,
2609 GdkEventScroll *event)
2611 GtkRange *range = GTK_RANGE (widget);
2613 if (gtk_widget_get_realized (widget))
2615 GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
2619 delta = _gtk_range_get_wheel_delta (range, event->direction);
2621 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2622 GTK_SCROLL_JUMP, adj->value + delta,
2625 /* Policy DELAYED makes sense with scroll events,
2626 * but DISCONTINUOUS doesn't, so we update immediately
2629 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
2630 gtk_range_update_value (range);
2637 gtk_range_motion_notify (GtkWidget *widget,
2638 GdkEventMotion *event)
2642 range = GTK_RANGE (widget);
2644 gdk_event_request_motions (event);
2646 range->layout->mouse_x = event->x;
2647 range->layout->mouse_y = event->y;
2649 if (gtk_range_update_mouse_location (range))
2650 gtk_widget_queue_draw (widget);
2652 if (range->layout->grab_location == MOUSE_SLIDER)
2653 update_slider_position (range, event->x, event->y);
2655 /* We handled the event if the mouse was in the range_rect */
2656 return range->layout->mouse_location != MOUSE_OUTSIDE;
2660 gtk_range_enter_notify (GtkWidget *widget,
2661 GdkEventCrossing *event)
2663 GtkRange *range = GTK_RANGE (widget);
2665 range->layout->mouse_x = event->x;
2666 range->layout->mouse_y = event->y;
2668 if (gtk_range_update_mouse_location (range))
2669 gtk_widget_queue_draw (widget);
2675 gtk_range_leave_notify (GtkWidget *widget,
2676 GdkEventCrossing *event)
2678 GtkRange *range = GTK_RANGE (widget);
2680 range->layout->mouse_x = -1;
2681 range->layout->mouse_y = -1;
2683 if (gtk_range_update_mouse_location (range))
2684 gtk_widget_queue_draw (widget);
2690 gtk_range_grab_notify (GtkWidget *widget,
2691 gboolean was_grabbed)
2693 GtkRangeLayout *layout = GTK_RANGE (widget)->layout;
2695 if (layout->grab_device &&
2696 gtk_widget_device_is_shadowed (widget, layout->grab_device))
2697 stop_scrolling (GTK_RANGE (widget));
2701 gtk_range_state_changed (GtkWidget *widget,
2702 GtkStateType previous_state)
2704 if (!gtk_widget_is_sensitive (widget))
2705 stop_scrolling (GTK_RANGE (widget));
2708 #define check_rectangle(rectangle1, rectangle2) \
2710 if (rectangle1.x != rectangle2.x) return TRUE; \
2711 if (rectangle1.y != rectangle2.y) return TRUE; \
2712 if (rectangle1.width != rectangle2.width) return TRUE; \
2713 if (rectangle1.height != rectangle2.height) return TRUE; \
2717 layout_changed (GtkRangeLayout *layout1,
2718 GtkRangeLayout *layout2)
2720 check_rectangle (layout1->slider, layout2->slider);
2721 check_rectangle (layout1->trough, layout2->trough);
2722 check_rectangle (layout1->stepper_a, layout2->stepper_a);
2723 check_rectangle (layout1->stepper_d, layout2->stepper_d);
2724 check_rectangle (layout1->stepper_b, layout2->stepper_b);
2725 check_rectangle (layout1->stepper_c, layout2->stepper_c);
2727 if (layout1->upper_sensitive != layout2->upper_sensitive) return TRUE;
2728 if (layout1->lower_sensitive != layout2->lower_sensitive) return TRUE;
2734 gtk_range_adjustment_changed (GtkAdjustment *adjustment,
2737 GtkRange *range = GTK_RANGE (data);
2738 /* create a copy of the layout */
2739 GtkRangeLayout layout = *range->layout;
2741 range->layout->recalc_marks = TRUE;
2742 range->need_recalc = TRUE;
2743 gtk_range_calc_layout (range, range->adjustment->value);
2745 /* now check whether the layout changed */
2746 if (layout_changed (range->layout, &layout))
2747 gtk_widget_queue_draw (GTK_WIDGET (range));
2749 /* Note that we don't round off to range->round_digits here.
2750 * that's because it's really broken to change a value
2751 * in response to a change signal on that value; round_digits
2752 * is therefore defined to be a filter on what the GtkRange
2753 * can input into the adjustment, not a filter that the GtkRange
2754 * will enforce on the adjustment.
2759 force_repaint (gpointer data)
2761 GtkRange *range = GTK_RANGE (data);
2762 GtkWidget *widget = GTK_WIDGET (range);
2764 range->layout->repaint_id = 0;
2765 if (gtk_widget_is_drawable (widget))
2766 gdk_window_process_updates (gtk_widget_get_window (widget), FALSE);
2772 gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
2775 GtkRange *range = GTK_RANGE (data);
2776 /* create a copy of the layout */
2777 GtkRangeLayout layout = *range->layout;
2779 range->need_recalc = TRUE;
2780 gtk_range_calc_layout (range, range->adjustment->value);
2782 /* now check whether the layout changed */
2783 if (layout_changed (range->layout, &layout) ||
2784 (GTK_IS_SCALE (range) && gtk_scale_get_draw_value (GTK_SCALE (range))))
2786 gtk_widget_queue_draw (GTK_WIDGET (range));
2787 /* setup a timer to ensure the range isn't lagging too much behind the scroll position */
2788 if (!range->layout->repaint_id)
2789 range->layout->repaint_id = gdk_threads_add_timeout_full (GDK_PRIORITY_EVENTS, 181, force_repaint, range, NULL);
2792 /* Note that we don't round off to range->round_digits here.
2793 * that's because it's really broken to change a value
2794 * in response to a change signal on that value; round_digits
2795 * is therefore defined to be a filter on what the GtkRange
2796 * can input into the adjustment, not a filter that the GtkRange
2797 * will enforce on the adjustment.
2800 g_signal_emit (range, signals[VALUE_CHANGED], 0);
2804 gtk_range_style_set (GtkWidget *widget,
2805 GtkStyle *previous_style)
2807 GtkRange *range = GTK_RANGE (widget);
2809 range->need_recalc = TRUE;
2811 GTK_WIDGET_CLASS (gtk_range_parent_class)->style_set (widget, previous_style);
2815 apply_marks (GtkRange *range,
2822 for (i = 0; i < range->layout->n_marks; i++)
2824 mark = range->layout->marks[i];
2825 if ((oldval < mark && mark < *newval) ||
2826 (oldval > mark && mark > *newval))
2835 step_back (GtkRange *range)
2840 newval = range->adjustment->value - range->adjustment->step_increment;
2841 apply_marks (range, range->adjustment->value, &newval);
2842 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2843 GTK_SCROLL_STEP_BACKWARD, newval, &handled);
2847 step_forward (GtkRange *range)
2852 newval = range->adjustment->value + range->adjustment->step_increment;
2853 apply_marks (range, range->adjustment->value, &newval);
2854 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2855 GTK_SCROLL_STEP_FORWARD, newval, &handled);
2860 page_back (GtkRange *range)
2865 newval = range->adjustment->value - range->adjustment->page_increment;
2866 apply_marks (range, range->adjustment->value, &newval);
2867 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2868 GTK_SCROLL_PAGE_BACKWARD, newval, &handled);
2872 page_forward (GtkRange *range)
2877 newval = range->adjustment->value + range->adjustment->page_increment;
2878 apply_marks (range, range->adjustment->value, &newval);
2879 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2880 GTK_SCROLL_PAGE_FORWARD, newval, &handled);
2884 scroll_begin (GtkRange *range)
2887 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2888 GTK_SCROLL_START, range->adjustment->lower,
2893 scroll_end (GtkRange *range)
2898 newval = range->adjustment->upper - range->adjustment->page_size;
2899 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_END, newval,
2904 gtk_range_scroll (GtkRange *range,
2905 GtkScrollType scroll)
2907 gdouble old_value = range->adjustment->value;
2911 case GTK_SCROLL_STEP_LEFT:
2912 if (should_invert (range))
2913 step_forward (range);
2918 case GTK_SCROLL_STEP_UP:
2919 if (should_invert (range))
2920 step_forward (range);
2925 case GTK_SCROLL_STEP_RIGHT:
2926 if (should_invert (range))
2929 step_forward (range);
2932 case GTK_SCROLL_STEP_DOWN:
2933 if (should_invert (range))
2936 step_forward (range);
2939 case GTK_SCROLL_STEP_BACKWARD:
2943 case GTK_SCROLL_STEP_FORWARD:
2944 step_forward (range);
2947 case GTK_SCROLL_PAGE_LEFT:
2948 if (should_invert (range))
2949 page_forward (range);
2954 case GTK_SCROLL_PAGE_UP:
2955 if (should_invert (range))
2956 page_forward (range);
2961 case GTK_SCROLL_PAGE_RIGHT:
2962 if (should_invert (range))
2965 page_forward (range);
2968 case GTK_SCROLL_PAGE_DOWN:
2969 if (should_invert (range))
2972 page_forward (range);
2975 case GTK_SCROLL_PAGE_BACKWARD:
2979 case GTK_SCROLL_PAGE_FORWARD:
2980 page_forward (range);
2983 case GTK_SCROLL_START:
2984 scroll_begin (range);
2987 case GTK_SCROLL_END:
2991 case GTK_SCROLL_JUMP:
2992 /* Used by CList, range doesn't use it. */
2995 case GTK_SCROLL_NONE:
2999 return range->adjustment->value != old_value;
3003 gtk_range_move_slider (GtkRange *range,
3004 GtkScrollType scroll)
3006 gboolean cursor_only;
3008 g_object_get (gtk_widget_get_settings (GTK_WIDGET (range)),
3009 "gtk-keynav-cursor-only", &cursor_only,
3014 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (range));
3016 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
3018 if (scroll == GTK_SCROLL_STEP_UP ||
3019 scroll == GTK_SCROLL_STEP_DOWN)
3022 gtk_widget_child_focus (toplevel,
3023 scroll == GTK_SCROLL_STEP_UP ?
3024 GTK_DIR_UP : GTK_DIR_DOWN);
3030 if (scroll == GTK_SCROLL_STEP_LEFT ||
3031 scroll == GTK_SCROLL_STEP_RIGHT)
3034 gtk_widget_child_focus (toplevel,
3035 scroll == GTK_SCROLL_STEP_LEFT ?
3036 GTK_DIR_LEFT : GTK_DIR_RIGHT);
3042 if (! gtk_range_scroll (range, scroll))
3043 gtk_widget_error_bell (GTK_WIDGET (range));
3045 /* Policy DELAYED makes sense with key events,
3046 * but DISCONTINUOUS doesn't, so we update immediately
3049 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
3050 gtk_range_update_value (range);
3054 gtk_range_get_props (GtkRange *range,
3058 gint *trough_border,
3059 gint *stepper_spacing,
3060 gboolean *trough_under_steppers,
3061 gint *arrow_displacement_x,
3062 gint *arrow_displacement_y)
3064 GtkWidget *widget = GTK_WIDGET (range);
3065 gint tmp_slider_width, tmp_stepper_size, tmp_focus_width, tmp_trough_border;
3066 gint tmp_stepper_spacing, tmp_trough_under_steppers;
3067 gint tmp_arrow_displacement_x, tmp_arrow_displacement_y;
3069 gtk_widget_style_get (widget,
3070 "slider-width", &tmp_slider_width,
3071 "trough-border", &tmp_trough_border,
3072 "stepper-size", &tmp_stepper_size,
3073 "stepper-spacing", &tmp_stepper_spacing,
3074 "trough-under-steppers", &tmp_trough_under_steppers,
3075 "arrow-displacement-x", &tmp_arrow_displacement_x,
3076 "arrow-displacement-y", &tmp_arrow_displacement_y,
3079 if (tmp_stepper_spacing > 0)
3080 tmp_trough_under_steppers = FALSE;
3082 if (gtk_widget_get_can_focus (GTK_WIDGET (range)))
3084 gint focus_line_width;
3087 gtk_widget_style_get (GTK_WIDGET (range),
3088 "focus-line-width", &focus_line_width,
3089 "focus-padding", &focus_padding,
3092 tmp_focus_width = focus_line_width + focus_padding;
3096 tmp_focus_width = 0;
3100 *slider_width = tmp_slider_width;
3103 *focus_width = tmp_focus_width;
3106 *trough_border = tmp_trough_border;
3109 *stepper_size = tmp_stepper_size;
3111 if (stepper_spacing)
3112 *stepper_spacing = tmp_stepper_spacing;
3114 if (trough_under_steppers)
3115 *trough_under_steppers = tmp_trough_under_steppers;
3117 if (arrow_displacement_x)
3118 *arrow_displacement_x = tmp_arrow_displacement_x;
3120 if (arrow_displacement_y)
3121 *arrow_displacement_y = tmp_arrow_displacement_y;
3124 #define POINT_IN_RECT(xcoord, ycoord, rect) \
3125 ((xcoord) >= (rect).x && \
3126 (xcoord) < ((rect).x + (rect).width) && \
3127 (ycoord) >= (rect).y && \
3128 (ycoord) < ((rect).y + (rect).height))
3130 /* Update mouse location, return TRUE if it changes */
3132 gtk_range_update_mouse_location (GtkRange *range)
3134 GtkAllocation allocation;
3139 widget = GTK_WIDGET (range);
3141 old = range->layout->mouse_location;
3143 x = range->layout->mouse_x;
3144 y = range->layout->mouse_y;
3146 gtk_widget_get_allocation (widget, &allocation);
3148 if (range->layout->grab_location != MOUSE_OUTSIDE)
3149 range->layout->mouse_location = range->layout->grab_location;
3150 else if (POINT_IN_RECT (x, y, range->layout->stepper_a))
3151 range->layout->mouse_location = MOUSE_STEPPER_A;
3152 else if (POINT_IN_RECT (x, y, range->layout->stepper_b))
3153 range->layout->mouse_location = MOUSE_STEPPER_B;
3154 else if (POINT_IN_RECT (x, y, range->layout->stepper_c))
3155 range->layout->mouse_location = MOUSE_STEPPER_C;
3156 else if (POINT_IN_RECT (x, y, range->layout->stepper_d))
3157 range->layout->mouse_location = MOUSE_STEPPER_D;
3158 else if (POINT_IN_RECT (x, y, range->layout->slider))
3159 range->layout->mouse_location = MOUSE_SLIDER;
3160 else if (POINT_IN_RECT (x, y, range->layout->trough))
3161 range->layout->mouse_location = MOUSE_TROUGH;
3162 else if (POINT_IN_RECT (x, y, allocation))
3163 range->layout->mouse_location = MOUSE_WIDGET;
3165 range->layout->mouse_location = MOUSE_OUTSIDE;
3167 return old != range->layout->mouse_location;
3170 /* Clamp rect, border inside widget->allocation, such that we prefer
3171 * to take space from border not rect in all directions, and prefer to
3172 * give space to border over rect in one direction.
3175 clamp_dimensions (GtkWidget *widget,
3178 gboolean border_expands_horizontally)
3180 GtkAllocation allocation;
3181 gint extra, shortage;
3183 g_return_if_fail (rect->x == 0);
3184 g_return_if_fail (rect->y == 0);
3185 g_return_if_fail (rect->width >= 0);
3186 g_return_if_fail (rect->height >= 0);
3188 gtk_widget_get_allocation (widget, &allocation);
3192 extra = allocation.width - border->left - border->right - rect->width;
3195 if (border_expands_horizontally)
3197 border->left += extra / 2;
3198 border->right += extra / 2 + extra % 2;
3202 rect->width += extra;
3206 /* See if we can fit rect, if not kill the border */
3207 shortage = rect->width - allocation.width;
3210 rect->width = allocation.width;
3211 /* lose the border */
3217 /* See if we can fit rect with borders */
3218 shortage = rect->width + border->left + border->right - allocation.width;
3221 /* Shrink borders */
3222 border->left -= shortage / 2;
3223 border->right -= shortage / 2 + shortage % 2;
3229 extra = allocation.height - border->top - border->bottom - rect->height;
3232 if (border_expands_horizontally)
3234 /* don't expand border vertically */
3235 rect->height += extra;
3239 border->top += extra / 2;
3240 border->bottom += extra / 2 + extra % 2;
3244 /* See if we can fit rect, if not kill the border */
3245 shortage = rect->height - allocation.height;
3248 rect->height = allocation.height;
3249 /* lose the border */
3255 /* See if we can fit rect with borders */
3256 shortage = rect->height + border->top + border->bottom - allocation.height;
3259 /* Shrink borders */
3260 border->top -= shortage / 2;
3261 border->bottom -= shortage / 2 + shortage % 2;
3267 gtk_range_calc_request (GtkRange *range,
3272 gint stepper_spacing,
3273 GdkRectangle *range_rect,
3276 gboolean *has_steppers_ab,
3277 gboolean *has_steppers_cd,
3278 gint *slider_length_p)
3290 if (GTK_RANGE_GET_CLASS (range)->get_range_border)
3291 GTK_RANGE_GET_CLASS (range)->get_range_border (range, border);
3296 if (range->has_stepper_a)
3298 if (range->has_stepper_b)
3300 if (range->has_stepper_c)
3302 if (range->has_stepper_d)
3305 n_steppers = n_steppers_ab + n_steppers_cd;
3307 slider_length = range->min_slider_size;
3312 /* We never expand to fill available space in the small dimension
3313 * (i.e. vertical scrollbars are always a fixed width)
3315 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3317 range_rect->width = (focus_width + trough_border) * 2 + slider_width;
3318 range_rect->height = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
3320 if (n_steppers_ab > 0)
3321 range_rect->height += stepper_spacing;
3323 if (n_steppers_cd > 0)
3324 range_rect->height += stepper_spacing;
3328 range_rect->width = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
3329 range_rect->height = (focus_width + trough_border) * 2 + slider_width;
3331 if (n_steppers_ab > 0)
3332 range_rect->width += stepper_spacing;
3334 if (n_steppers_cd > 0)
3335 range_rect->width += stepper_spacing;
3339 *n_steppers_p = n_steppers;
3341 if (has_steppers_ab)
3342 *has_steppers_ab = (n_steppers_ab > 0);
3344 if (has_steppers_cd)
3345 *has_steppers_cd = (n_steppers_cd > 0);
3347 if (slider_length_p)
3348 *slider_length_p = slider_length;
3352 gtk_range_calc_layout (GtkRange *range,
3353 gdouble adjustment_value)
3355 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
3359 gboolean has_steppers_ab;
3360 gboolean has_steppers_cd;
3361 gboolean trough_under_steppers;
3362 GdkRectangle range_rect;
3363 GtkRangeLayout *layout;
3366 if (!range->need_recalc)
3369 /* If we have a too-small allocation, we prefer the steppers over
3370 * the trough/slider, probably the steppers are a more useful
3371 * feature in small spaces.
3373 * Also, we prefer to draw the range itself rather than the border
3374 * areas if there's a conflict, since the borders will be decoration
3375 * not controls. Though this depends on subclasses cooperating by
3376 * not drawing on range->range_rect.
3379 widget = GTK_WIDGET (range);
3380 layout = range->layout;
3382 gtk_range_get_props (range,
3383 &slider_width, &stepper_size,
3384 &focus_width, &trough_border,
3385 &stepper_spacing, &trough_under_steppers,
3388 gtk_range_calc_request (range,
3389 slider_width, stepper_size,
3390 focus_width, trough_border, stepper_spacing,
3391 &range_rect, &border, &n_steppers,
3392 &has_steppers_ab, &has_steppers_cd, &slider_length);
3394 /* We never expand to fill available space in the small dimension
3395 * (i.e. vertical scrollbars are always a fixed width)
3397 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3399 clamp_dimensions (widget, &range_rect, &border, TRUE);
3403 clamp_dimensions (widget, &range_rect, &border, FALSE);
3406 range_rect.x = border.left;
3407 range_rect.y = border.top;
3409 range->range_rect = range_rect;
3411 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3413 gint stepper_width, stepper_height;
3415 /* Steppers are the width of the range, and stepper_size in
3416 * height, or if we don't have enough height, divided equally
3417 * among available space.
3419 stepper_width = range_rect.width - focus_width * 2;
3421 if (trough_under_steppers)
3422 stepper_width -= trough_border * 2;
3424 if (stepper_width < 1)
3425 stepper_width = range_rect.width; /* screw the trough border */
3427 if (n_steppers == 0)
3428 stepper_height = 0; /* avoid divide by n_steppers */
3430 stepper_height = MIN (stepper_size, (range_rect.height / n_steppers));
3434 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3435 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3437 if (range->has_stepper_a)
3439 layout->stepper_a.width = stepper_width;
3440 layout->stepper_a.height = stepper_height;
3444 layout->stepper_a.width = 0;
3445 layout->stepper_a.height = 0;
3450 layout->stepper_b.x = layout->stepper_a.x;
3451 layout->stepper_b.y = layout->stepper_a.y + layout->stepper_a.height;
3453 if (range->has_stepper_b)
3455 layout->stepper_b.width = stepper_width;
3456 layout->stepper_b.height = stepper_height;
3460 layout->stepper_b.width = 0;
3461 layout->stepper_b.height = 0;
3466 if (range->has_stepper_d)
3468 layout->stepper_d.width = stepper_width;
3469 layout->stepper_d.height = stepper_height;
3473 layout->stepper_d.width = 0;
3474 layout->stepper_d.height = 0;
3477 layout->stepper_d.x = layout->stepper_a.x;
3478 layout->stepper_d.y = range_rect.y + range_rect.height - layout->stepper_d.height - focus_width - trough_border * trough_under_steppers;
3482 if (range->has_stepper_c)
3484 layout->stepper_c.width = stepper_width;
3485 layout->stepper_c.height = stepper_height;
3489 layout->stepper_c.width = 0;
3490 layout->stepper_c.height = 0;
3493 layout->stepper_c.x = layout->stepper_a.x;
3494 layout->stepper_c.y = layout->stepper_d.y - layout->stepper_c.height;
3496 /* Now the trough is the remaining space between steppers B and C,
3497 * if any, minus spacing
3499 layout->trough.x = range_rect.x;
3500 layout->trough.y = layout->stepper_b.y + layout->stepper_b.height + stepper_spacing * has_steppers_ab;
3501 layout->trough.width = range_rect.width;
3502 layout->trough.height = layout->stepper_c.y - layout->trough.y - stepper_spacing * has_steppers_cd;
3504 /* Slider fits into the trough, with stepper_spacing on either side,
3505 * and the size/position based on the adjustment or fixed, depending.
3507 layout->slider.x = layout->trough.x + focus_width + trough_border;
3508 layout->slider.width = layout->trough.width - (focus_width + trough_border) * 2;
3510 /* Compute slider position/length */
3512 gint y, bottom, top, height;
3514 top = layout->trough.y;
3515 bottom = layout->trough.y + layout->trough.height;
3517 if (! trough_under_steppers)
3519 top += trough_border;
3520 bottom -= trough_border;
3523 /* slider height is the fraction (page_size /
3524 * total_adjustment_range) times the trough height in pixels
3527 if (range->adjustment->upper - range->adjustment->lower != 0)
3528 height = ((bottom - top) * (range->adjustment->page_size /
3529 (range->adjustment->upper - range->adjustment->lower)));
3531 height = range->min_slider_size;
3533 if (height < range->min_slider_size ||
3534 range->slider_size_fixed)
3535 height = range->min_slider_size;
3537 height = MIN (height, layout->trough.height);
3541 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3542 y += (bottom - top - height) * ((adjustment_value - range->adjustment->lower) /
3543 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3545 y = CLAMP (y, top, bottom);
3547 if (should_invert (range))
3548 y = bottom - (y - top + height);
3550 layout->slider.y = y;
3551 layout->slider.height = height;
3553 /* These are publically exported */
3554 range->slider_start = layout->slider.y;
3555 range->slider_end = layout->slider.y + layout->slider.height;
3560 gint stepper_width, stepper_height;
3562 /* Steppers are the height of the range, and stepper_size in
3563 * width, or if we don't have enough width, divided equally
3564 * among available space.
3566 stepper_height = range_rect.height + focus_width * 2;
3568 if (trough_under_steppers)
3569 stepper_height -= trough_border * 2;
3571 if (stepper_height < 1)
3572 stepper_height = range_rect.height; /* screw the trough border */
3574 if (n_steppers == 0)
3575 stepper_width = 0; /* avoid divide by n_steppers */
3577 stepper_width = MIN (stepper_size, (range_rect.width / n_steppers));
3581 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3582 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3584 if (range->has_stepper_a)
3586 layout->stepper_a.width = stepper_width;
3587 layout->stepper_a.height = stepper_height;
3591 layout->stepper_a.width = 0;
3592 layout->stepper_a.height = 0;
3597 layout->stepper_b.x = layout->stepper_a.x + layout->stepper_a.width;
3598 layout->stepper_b.y = layout->stepper_a.y;
3600 if (range->has_stepper_b)
3602 layout->stepper_b.width = stepper_width;
3603 layout->stepper_b.height = stepper_height;
3607 layout->stepper_b.width = 0;
3608 layout->stepper_b.height = 0;
3613 if (range->has_stepper_d)
3615 layout->stepper_d.width = stepper_width;
3616 layout->stepper_d.height = stepper_height;
3620 layout->stepper_d.width = 0;
3621 layout->stepper_d.height = 0;
3624 layout->stepper_d.x = range_rect.x + range_rect.width - layout->stepper_d.width - focus_width - trough_border * trough_under_steppers;
3625 layout->stepper_d.y = layout->stepper_a.y;
3630 if (range->has_stepper_c)
3632 layout->stepper_c.width = stepper_width;
3633 layout->stepper_c.height = stepper_height;
3637 layout->stepper_c.width = 0;
3638 layout->stepper_c.height = 0;
3641 layout->stepper_c.x = layout->stepper_d.x - layout->stepper_c.width;
3642 layout->stepper_c.y = layout->stepper_a.y;
3644 /* Now the trough is the remaining space between steppers B and C,
3647 layout->trough.x = layout->stepper_b.x + layout->stepper_b.width + stepper_spacing * has_steppers_ab;
3648 layout->trough.y = range_rect.y;
3650 layout->trough.width = layout->stepper_c.x - layout->trough.x - stepper_spacing * has_steppers_cd;
3651 layout->trough.height = range_rect.height;
3653 /* Slider fits into the trough, with stepper_spacing on either side,
3654 * and the size/position based on the adjustment or fixed, depending.
3656 layout->slider.y = layout->trough.y + focus_width + trough_border;
3657 layout->slider.height = layout->trough.height - (focus_width + trough_border) * 2;
3659 /* Compute slider position/length */
3661 gint x, left, right, width;
3663 left = layout->trough.x;
3664 right = layout->trough.x + layout->trough.width;
3666 if (! trough_under_steppers)
3668 left += trough_border;
3669 right -= trough_border;
3672 /* slider width is the fraction (page_size /
3673 * total_adjustment_range) times the trough width in pixels
3676 if (range->adjustment->upper - range->adjustment->lower != 0)
3677 width = ((right - left) * (range->adjustment->page_size /
3678 (range->adjustment->upper - range->adjustment->lower)));
3680 width = range->min_slider_size;
3682 if (width < range->min_slider_size ||
3683 range->slider_size_fixed)
3684 width = range->min_slider_size;
3686 width = MIN (width, layout->trough.width);
3690 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3691 x += (right - left - width) * ((adjustment_value - range->adjustment->lower) /
3692 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3694 x = CLAMP (x, left, right);
3696 if (should_invert (range))
3697 x = right - (x - left + width);
3699 layout->slider.x = x;
3700 layout->slider.width = width;
3702 /* These are publically exported */
3703 range->slider_start = layout->slider.x;
3704 range->slider_end = layout->slider.x + layout->slider.width;
3708 gtk_range_update_mouse_location (range);
3710 switch (range->layout->upper_sensitivity)
3712 case GTK_SENSITIVITY_AUTO:
3713 range->layout->upper_sensitive =
3714 (range->adjustment->value <
3715 (range->adjustment->upper - range->adjustment->page_size));
3718 case GTK_SENSITIVITY_ON:
3719 range->layout->upper_sensitive = TRUE;
3722 case GTK_SENSITIVITY_OFF:
3723 range->layout->upper_sensitive = FALSE;
3727 switch (range->layout->lower_sensitivity)
3729 case GTK_SENSITIVITY_AUTO:
3730 range->layout->lower_sensitive =
3731 (range->adjustment->value > range->adjustment->lower);
3734 case GTK_SENSITIVITY_ON:
3735 range->layout->lower_sensitive = TRUE;
3738 case GTK_SENSITIVITY_OFF:
3739 range->layout->lower_sensitive = FALSE;
3744 static GdkRectangle*
3745 get_area (GtkRange *range,
3746 MouseLocation location)
3750 case MOUSE_STEPPER_A:
3751 return &range->layout->stepper_a;
3752 case MOUSE_STEPPER_B:
3753 return &range->layout->stepper_b;
3754 case MOUSE_STEPPER_C:
3755 return &range->layout->stepper_c;
3756 case MOUSE_STEPPER_D:
3757 return &range->layout->stepper_d;
3759 return &range->layout->trough;
3761 return &range->layout->slider;
3767 g_warning (G_STRLOC": bug");
3772 gtk_range_calc_marks (GtkRange *range)
3776 if (!range->layout->recalc_marks)
3779 range->layout->recalc_marks = FALSE;
3781 for (i = 0; i < range->layout->n_marks; i++)
3783 range->need_recalc = TRUE;
3784 gtk_range_calc_layout (range, range->layout->marks[i]);
3785 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
3786 range->layout->mark_pos[i] = range->layout->slider.x + range->layout->slider.width / 2;
3788 range->layout->mark_pos[i] = range->layout->slider.y + range->layout->slider.height / 2;
3791 range->need_recalc = TRUE;
3795 gtk_range_real_change_value (GtkRange *range,
3796 GtkScrollType scroll,
3799 /* potentially adjust the bounds _before_ we clamp */
3800 g_signal_emit (range, signals[ADJUST_BOUNDS], 0, value);
3802 if (range->layout->restrict_to_fill_level)
3803 value = MIN (value, MAX (range->adjustment->lower,
3804 range->layout->fill_level));
3806 value = CLAMP (value, range->adjustment->lower,
3807 (range->adjustment->upper - range->adjustment->page_size));
3809 if (range->round_digits >= 0)
3814 i = range->round_digits;
3819 value = floor ((value * power) + 0.5) / power;
3822 if (range->adjustment->value != value)
3824 range->need_recalc = TRUE;
3826 gtk_widget_queue_draw (GTK_WIDGET (range));
3828 switch (range->update_policy)
3830 case GTK_UPDATE_CONTINUOUS:
3831 gtk_adjustment_set_value (range->adjustment, value);
3834 /* Delayed means we update after a period of inactivity */
3835 case GTK_UPDATE_DELAYED:
3836 gtk_range_reset_update_timer (range);
3839 /* Discontinuous means we update on button release */
3840 case GTK_UPDATE_DISCONTINUOUS:
3841 /* don't emit value_changed signal */
3842 range->adjustment->value = value;
3843 range->update_pending = TRUE;
3851 gtk_range_update_value (GtkRange *range)
3853 gtk_range_remove_update_timer (range);
3855 if (range->update_pending)
3857 gtk_adjustment_value_changed (range->adjustment);
3859 range->update_pending = FALSE;
3863 struct _GtkRangeStepTimer
3870 second_timeout (gpointer data)
3874 range = GTK_RANGE (data);
3875 gtk_range_scroll (range, range->timer->step);
3881 initial_timeout (gpointer data)
3884 GtkSettings *settings;
3887 settings = gtk_widget_get_settings (GTK_WIDGET (data));
3888 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3890 range = GTK_RANGE (data);
3891 range->timer->timeout_id = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3899 gtk_range_add_step_timer (GtkRange *range,
3902 GtkSettings *settings;
3905 g_return_if_fail (range->timer == NULL);
3906 g_return_if_fail (step != GTK_SCROLL_NONE);
3908 settings = gtk_widget_get_settings (GTK_WIDGET (range));
3909 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
3911 range->timer = g_new (GtkRangeStepTimer, 1);
3913 range->timer->timeout_id = gdk_threads_add_timeout (timeout,
3916 range->timer->step = step;
3918 gtk_range_scroll (range, range->timer->step);
3922 gtk_range_remove_step_timer (GtkRange *range)
3926 if (range->timer->timeout_id != 0)
3927 g_source_remove (range->timer->timeout_id);
3929 g_free (range->timer);
3931 range->timer = NULL;
3936 update_timeout (gpointer data)
3940 range = GTK_RANGE (data);
3941 gtk_range_update_value (range);
3942 range->update_timeout_id = 0;
3949 gtk_range_reset_update_timer (GtkRange *range)
3951 gtk_range_remove_update_timer (range);
3953 range->update_timeout_id = gdk_threads_add_timeout (UPDATE_DELAY,
3959 gtk_range_remove_update_timer (GtkRange *range)
3961 if (range->update_timeout_id != 0)
3963 g_source_remove (range->update_timeout_id);
3964 range->update_timeout_id = 0;
3969 _gtk_range_set_stop_values (GtkRange *range,
3975 g_free (range->layout->marks);
3976 range->layout->marks = g_new (gdouble, n_values);
3978 g_free (range->layout->mark_pos);
3979 range->layout->mark_pos = g_new (gint, n_values);
3981 range->layout->n_marks = n_values;
3983 for (i = 0; i < n_values; i++)
3984 range->layout->marks[i] = values[i];
3986 range->layout->recalc_marks = TRUE;
3990 _gtk_range_get_stop_positions (GtkRange *range,
3993 gtk_range_calc_marks (range);
3996 *values = g_memdup (range->layout->mark_pos, range->layout->n_marks * sizeof (gint));
3998 return range->layout->n_marks;
4002 _gtk_range_set_round_digits (GtkRange *range,
4005 range->round_digits = round_digits;