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 range->need_recalc = TRUE;
965 gtk_range_calc_layout (range, range->adjustment->value);
966 gtk_widget_queue_draw (GTK_WIDGET (range));
971 * gtk_range_get_slider_size_fixed:
972 * @range: a #GtkRange
974 * This function is useful mainly for #GtkRange subclasses.
976 * See gtk_range_set_slider_size_fixed().
978 * Return value: whether the range's slider has a fixed size.
983 gtk_range_get_slider_size_fixed (GtkRange *range)
985 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
987 return range->slider_size_fixed;
991 * gtk_range_set_min_slider_size:
992 * @range: a #GtkRange
993 * @min_size: The slider's minimum size
995 * Sets the minimum size of the range's slider.
997 * This function is useful mainly for #GtkRange subclasses.
1002 gtk_range_set_min_slider_size (GtkRange *range,
1005 g_return_if_fail (GTK_IS_RANGE (range));
1006 g_return_if_fail (min_size > 0);
1008 if (min_size != range->min_slider_size)
1010 range->min_slider_size = min_size;
1012 range->need_recalc = TRUE;
1013 gtk_range_calc_layout (range, range->adjustment->value);
1014 gtk_widget_queue_draw (GTK_WIDGET (range));
1019 * gtk_range_get_min_slider_size:
1020 * @range: a #GtkRange
1022 * This function is useful mainly for #GtkRange subclasses.
1024 * See gtk_range_set_min_slider_size().
1026 * Return value: The minimum size of the range's slider.
1031 gtk_range_get_min_slider_size (GtkRange *range)
1033 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1035 return range->min_slider_size;
1039 * gtk_range_get_range_rect:
1040 * @range: a #GtkRange
1041 * @range_rect: return location for the range rectangle
1043 * This function returns the area that contains the range's trough
1044 * and its steppers, in widget->window coordinates.
1046 * This function is useful mainly for #GtkRange subclasses.
1051 gtk_range_get_range_rect (GtkRange *range,
1052 GdkRectangle *range_rect)
1054 g_return_if_fail (GTK_IS_RANGE (range));
1055 g_return_if_fail (range_rect != NULL);
1057 gtk_range_calc_layout (range, range->adjustment->value);
1059 *range_rect = range->range_rect;
1063 * gtk_range_get_slider_range:
1064 * @range: a #GtkRange
1065 * @slider_start: (allow-none): return location for the slider's start, or %NULL
1066 * @slider_end: (allow-none): return location for the slider's end, or %NULL
1068 * This function returns sliders range along the long dimension,
1069 * in widget->window coordinates.
1071 * This function is useful mainly for #GtkRange subclasses.
1076 gtk_range_get_slider_range (GtkRange *range,
1080 g_return_if_fail (GTK_IS_RANGE (range));
1082 gtk_range_calc_layout (range, range->adjustment->value);
1085 *slider_start = range->slider_start;
1088 *slider_end = range->slider_end;
1092 * gtk_range_set_lower_stepper_sensitivity:
1093 * @range: a #GtkRange
1094 * @sensitivity: the lower stepper's sensitivity policy.
1096 * Sets the sensitivity policy for the stepper that points to the
1097 * 'lower' end of the GtkRange's adjustment.
1102 gtk_range_set_lower_stepper_sensitivity (GtkRange *range,
1103 GtkSensitivityType sensitivity)
1105 g_return_if_fail (GTK_IS_RANGE (range));
1107 if (range->layout->lower_sensitivity != sensitivity)
1109 range->layout->lower_sensitivity = sensitivity;
1111 range->need_recalc = TRUE;
1112 gtk_range_calc_layout (range, range->adjustment->value);
1113 gtk_widget_queue_draw (GTK_WIDGET (range));
1115 g_object_notify (G_OBJECT (range), "lower-stepper-sensitivity");
1120 * gtk_range_get_lower_stepper_sensitivity:
1121 * @range: a #GtkRange
1123 * Gets the sensitivity policy for the stepper that points to the
1124 * 'lower' end of the GtkRange's adjustment.
1126 * Return value: The lower stepper's sensitivity policy.
1131 gtk_range_get_lower_stepper_sensitivity (GtkRange *range)
1133 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
1135 return range->layout->lower_sensitivity;
1139 * gtk_range_set_upper_stepper_sensitivity:
1140 * @range: a #GtkRange
1141 * @sensitivity: the upper stepper's sensitivity policy.
1143 * Sets the sensitivity policy for the stepper that points to the
1144 * 'upper' end of the GtkRange's adjustment.
1149 gtk_range_set_upper_stepper_sensitivity (GtkRange *range,
1150 GtkSensitivityType sensitivity)
1152 g_return_if_fail (GTK_IS_RANGE (range));
1154 if (range->layout->upper_sensitivity != sensitivity)
1156 range->layout->upper_sensitivity = sensitivity;
1158 range->need_recalc = TRUE;
1159 gtk_range_calc_layout (range, range->adjustment->value);
1160 gtk_widget_queue_draw (GTK_WIDGET (range));
1162 g_object_notify (G_OBJECT (range), "upper-stepper-sensitivity");
1167 * gtk_range_get_upper_stepper_sensitivity:
1168 * @range: a #GtkRange
1170 * Gets the sensitivity policy for the stepper that points to the
1171 * 'upper' end of the GtkRange's adjustment.
1173 * Return value: The upper stepper's sensitivity policy.
1178 gtk_range_get_upper_stepper_sensitivity (GtkRange *range)
1180 g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
1182 return range->layout->upper_sensitivity;
1186 * gtk_range_set_increments:
1187 * @range: a #GtkRange
1191 * Sets the step and page sizes for the range.
1192 * The step size is used when the user clicks the #GtkScrollbar
1193 * arrows or moves #GtkScale via arrow keys. The page size
1194 * is used for example when moving via Page Up or Page Down keys.
1197 gtk_range_set_increments (GtkRange *range,
1201 g_return_if_fail (GTK_IS_RANGE (range));
1203 range->adjustment->step_increment = step;
1204 range->adjustment->page_increment = page;
1206 gtk_adjustment_changed (range->adjustment);
1210 * gtk_range_set_range:
1211 * @range: a #GtkRange
1212 * @min: minimum range value
1213 * @max: maximum range value
1215 * Sets the allowable values in the #GtkRange, and clamps the range
1216 * value to be between @min and @max. (If the range has a non-zero
1217 * page size, it is clamped between @min and @max - page-size.)
1220 gtk_range_set_range (GtkRange *range,
1226 g_return_if_fail (GTK_IS_RANGE (range));
1227 g_return_if_fail (min < max);
1229 range->adjustment->lower = min;
1230 range->adjustment->upper = max;
1232 value = range->adjustment->value;
1234 if (range->layout->restrict_to_fill_level)
1235 value = MIN (value, MAX (range->adjustment->lower,
1236 range->layout->fill_level));
1238 gtk_adjustment_set_value (range->adjustment, value);
1239 gtk_adjustment_changed (range->adjustment);
1243 * gtk_range_set_value:
1244 * @range: a #GtkRange
1245 * @value: new value of the range
1247 * Sets the current value of the range; if the value is outside the
1248 * minimum or maximum range values, it will be clamped to fit inside
1249 * them. The range emits the #GtkRange::value-changed signal if the
1253 gtk_range_set_value (GtkRange *range,
1256 g_return_if_fail (GTK_IS_RANGE (range));
1258 if (range->layout->restrict_to_fill_level)
1259 value = MIN (value, MAX (range->adjustment->lower,
1260 range->layout->fill_level));
1262 gtk_adjustment_set_value (range->adjustment, value);
1266 * gtk_range_get_value:
1267 * @range: a #GtkRange
1269 * Gets the current value of the range.
1271 * Return value: current value of the range.
1274 gtk_range_get_value (GtkRange *range)
1276 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1278 return range->adjustment->value;
1282 * gtk_range_set_show_fill_level:
1283 * @range: A #GtkRange
1284 * @show_fill_level: Whether a fill level indicator graphics is shown.
1286 * Sets whether a graphical fill level is show on the trough. See
1287 * gtk_range_set_fill_level() for a general description of the fill
1293 gtk_range_set_show_fill_level (GtkRange *range,
1294 gboolean show_fill_level)
1296 g_return_if_fail (GTK_IS_RANGE (range));
1298 show_fill_level = show_fill_level ? TRUE : FALSE;
1300 if (show_fill_level != range->layout->show_fill_level)
1302 range->layout->show_fill_level = show_fill_level;
1303 g_object_notify (G_OBJECT (range), "show-fill-level");
1304 gtk_widget_queue_draw (GTK_WIDGET (range));
1309 * gtk_range_get_show_fill_level:
1310 * @range: A #GtkRange
1312 * Gets whether the range displays the fill level graphically.
1314 * Return value: %TRUE if @range shows the fill level.
1319 gtk_range_get_show_fill_level (GtkRange *range)
1321 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1323 return range->layout->show_fill_level;
1327 * gtk_range_set_restrict_to_fill_level:
1328 * @range: A #GtkRange
1329 * @restrict_to_fill_level: Whether the fill level restricts slider movement.
1331 * Sets whether the slider is restricted to the fill level. See
1332 * gtk_range_set_fill_level() for a general description of the fill
1338 gtk_range_set_restrict_to_fill_level (GtkRange *range,
1339 gboolean restrict_to_fill_level)
1341 g_return_if_fail (GTK_IS_RANGE (range));
1343 restrict_to_fill_level = restrict_to_fill_level ? TRUE : FALSE;
1345 if (restrict_to_fill_level != range->layout->restrict_to_fill_level)
1347 range->layout->restrict_to_fill_level = restrict_to_fill_level;
1348 g_object_notify (G_OBJECT (range), "restrict-to-fill-level");
1350 gtk_range_set_value (range, gtk_range_get_value (range));
1355 * gtk_range_get_restrict_to_fill_level:
1356 * @range: A #GtkRange
1358 * Gets whether the range is restricted to the fill level.
1360 * Return value: %TRUE if @range is restricted to the fill level.
1365 gtk_range_get_restrict_to_fill_level (GtkRange *range)
1367 g_return_val_if_fail (GTK_IS_RANGE (range), FALSE);
1369 return range->layout->restrict_to_fill_level;
1373 * gtk_range_set_fill_level:
1374 * @range: a #GtkRange
1375 * @fill_level: the new position of the fill level indicator
1377 * Set the new position of the fill level indicator.
1379 * The "fill level" is probably best described by its most prominent
1380 * use case, which is an indicator for the amount of pre-buffering in
1381 * a streaming media player. In that use case, the value of the range
1382 * would indicate the current play position, and the fill level would
1383 * be the position up to which the file/stream has been downloaded.
1385 * This amount of prebuffering can be displayed on the range's trough
1386 * and is themeable separately from the trough. To enable fill level
1387 * display, use gtk_range_set_show_fill_level(). The range defaults
1388 * to not showing the fill level.
1390 * Additionally, it's possible to restrict the range's slider position
1391 * to values which are smaller than the fill level. This is controller
1392 * by gtk_range_set_restrict_to_fill_level() and is by default
1398 gtk_range_set_fill_level (GtkRange *range,
1401 g_return_if_fail (GTK_IS_RANGE (range));
1403 if (fill_level != range->layout->fill_level)
1405 range->layout->fill_level = fill_level;
1406 g_object_notify (G_OBJECT (range), "fill-level");
1408 if (range->layout->show_fill_level)
1409 gtk_widget_queue_draw (GTK_WIDGET (range));
1411 if (range->layout->restrict_to_fill_level)
1412 gtk_range_set_value (range, gtk_range_get_value (range));
1417 * gtk_range_get_fill_level:
1418 * @range : A #GtkRange
1420 * Gets the current position of the fill level indicator.
1422 * Return value: The current fill level
1427 gtk_range_get_fill_level (GtkRange *range)
1429 g_return_val_if_fail (GTK_IS_RANGE (range), 0.0);
1431 return range->layout->fill_level;
1435 should_invert (GtkRange *range)
1437 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1439 (range->inverted && !range->flippable) ||
1440 (range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_LTR) ||
1441 (!range->inverted && range->flippable && gtk_widget_get_direction (GTK_WIDGET (range)) == GTK_TEXT_DIR_RTL);
1443 return range->inverted;
1447 gtk_range_destroy (GtkObject *object)
1449 GtkRange *range = GTK_RANGE (object);
1451 gtk_range_remove_step_timer (range);
1452 gtk_range_remove_update_timer (range);
1454 if (range->layout->repaint_id)
1455 g_source_remove (range->layout->repaint_id);
1456 range->layout->repaint_id = 0;
1458 if (range->adjustment)
1460 g_signal_handlers_disconnect_by_func (range->adjustment,
1461 gtk_range_adjustment_changed,
1463 g_signal_handlers_disconnect_by_func (range->adjustment,
1464 gtk_range_adjustment_value_changed,
1466 g_object_unref (range->adjustment);
1467 range->adjustment = NULL;
1470 if (range->layout->n_marks)
1472 g_free (range->layout->marks);
1473 range->layout->marks = NULL;
1474 g_free (range->layout->mark_pos);
1475 range->layout->mark_pos = NULL;
1476 range->layout->n_marks = 0;
1479 GTK_OBJECT_CLASS (gtk_range_parent_class)->destroy (object);
1483 gtk_range_size_request (GtkWidget *widget,
1484 GtkRequisition *requisition)
1487 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
1488 GdkRectangle range_rect;
1491 range = GTK_RANGE (widget);
1493 gtk_range_get_props (range,
1494 &slider_width, &stepper_size,
1495 &focus_width, &trough_border,
1496 &stepper_spacing, NULL,
1499 gtk_range_calc_request (range,
1500 slider_width, stepper_size,
1501 focus_width, trough_border, stepper_spacing,
1502 &range_rect, &border, NULL, NULL, NULL, NULL);
1504 requisition->width = range_rect.width + border.left + border.right;
1505 requisition->height = range_rect.height + border.top + border.bottom;
1509 gtk_range_size_allocate (GtkWidget *widget,
1510 GtkAllocation *allocation)
1514 range = GTK_RANGE (widget);
1516 widget->allocation = *allocation;
1518 range->layout->recalc_marks = TRUE;
1520 range->need_recalc = TRUE;
1521 gtk_range_calc_layout (range, range->adjustment->value);
1523 if (gtk_widget_get_realized (widget))
1524 gdk_window_move_resize (range->event_window,
1525 widget->allocation.x,
1526 widget->allocation.y,
1527 widget->allocation.width,
1528 widget->allocation.height);
1532 gtk_range_realize (GtkWidget *widget)
1535 GdkWindowAttr attributes;
1536 gint attributes_mask;
1538 range = GTK_RANGE (widget);
1540 gtk_range_calc_layout (range, range->adjustment->value);
1542 gtk_widget_set_realized (widget, TRUE);
1544 widget->window = gtk_widget_get_parent_window (widget);
1545 g_object_ref (widget->window);
1547 attributes.window_type = GDK_WINDOW_CHILD;
1548 attributes.x = widget->allocation.x;
1549 attributes.y = widget->allocation.y;
1550 attributes.width = widget->allocation.width;
1551 attributes.height = widget->allocation.height;
1552 attributes.wclass = GDK_INPUT_ONLY;
1553 attributes.event_mask = gtk_widget_get_events (widget);
1554 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1555 GDK_BUTTON_RELEASE_MASK |
1556 GDK_ENTER_NOTIFY_MASK |
1557 GDK_LEAVE_NOTIFY_MASK |
1558 GDK_POINTER_MOTION_MASK |
1559 GDK_POINTER_MOTION_HINT_MASK);
1561 attributes_mask = GDK_WA_X | GDK_WA_Y;
1563 range->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
1564 &attributes, attributes_mask);
1565 gdk_window_set_user_data (range->event_window, range);
1567 widget->style = gtk_style_attach (widget->style, widget->window);
1571 gtk_range_unrealize (GtkWidget *widget)
1573 GtkRange *range = GTK_RANGE (widget);
1575 gtk_range_remove_step_timer (range);
1576 gtk_range_remove_update_timer (range);
1578 gdk_window_set_user_data (range->event_window, NULL);
1579 gdk_window_destroy (range->event_window);
1580 range->event_window = NULL;
1582 GTK_WIDGET_CLASS (gtk_range_parent_class)->unrealize (widget);
1586 gtk_range_map (GtkWidget *widget)
1588 GtkRange *range = GTK_RANGE (widget);
1590 gdk_window_show (range->event_window);
1592 GTK_WIDGET_CLASS (gtk_range_parent_class)->map (widget);
1596 gtk_range_unmap (GtkWidget *widget)
1598 GtkRange *range = GTK_RANGE (widget);
1600 stop_scrolling (range);
1602 gdk_window_hide (range->event_window);
1604 GTK_WIDGET_CLASS (gtk_range_parent_class)->unmap (widget);
1607 static const gchar *
1608 gtk_range_get_slider_detail (GtkRange *range)
1610 const gchar *slider_detail;
1612 if (range->layout->slider_detail_quark)
1613 return g_quark_to_string (range->layout->slider_detail_quark);
1615 slider_detail = GTK_RANGE_GET_CLASS (range)->slider_detail;
1617 if (slider_detail && slider_detail[0] == 'X')
1619 gchar *detail = g_strdup (slider_detail);
1621 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1623 range->layout->slider_detail_quark = g_quark_from_string (detail);
1627 return g_quark_to_string (range->layout->slider_detail_quark);
1630 return slider_detail;
1633 static const gchar *
1634 gtk_range_get_stepper_detail (GtkRange *range,
1637 const gchar *stepper_detail;
1638 gboolean need_orientation;
1639 gboolean need_position;
1641 if (range->layout->stepper_detail_quark[stepper])
1642 return g_quark_to_string (range->layout->stepper_detail_quark[stepper]);
1644 stepper_detail = GTK_RANGE_GET_CLASS (range)->stepper_detail;
1646 need_orientation = stepper_detail && stepper_detail[0] == 'X';
1648 gtk_widget_style_get (GTK_WIDGET (range),
1649 "stepper-position-details", &need_position,
1652 if (need_orientation || need_position)
1655 const gchar *position = NULL;
1662 position = "_start";
1665 if (range->has_stepper_a)
1666 position = "_start_inner";
1668 position = "_start";
1671 if (range->has_stepper_d)
1672 position = "_end_inner";
1680 g_assert_not_reached ();
1684 detail = g_strconcat (stepper_detail, position, NULL);
1686 if (need_orientation)
1687 detail[0] = range->orientation == GTK_ORIENTATION_HORIZONTAL ? 'h' : 'v';
1689 range->layout->stepper_detail_quark[stepper] = g_quark_from_string (detail);
1693 return g_quark_to_string (range->layout->stepper_detail_quark[stepper]);
1696 return stepper_detail;
1700 draw_stepper (GtkRange *range,
1702 GtkArrowType arrow_type,
1704 gboolean prelighted,
1707 GtkStateType state_type;
1708 GtkShadowType shadow_type;
1709 GdkRectangle intersection;
1710 GtkWidget *widget = GTK_WIDGET (range);
1711 gfloat arrow_scaling;
1721 rect = &range->layout->stepper_a;
1724 rect = &range->layout->stepper_b;
1727 rect = &range->layout->stepper_c;
1730 rect = &range->layout->stepper_d;
1733 g_assert_not_reached ();
1736 gboolean arrow_sensitive = TRUE;
1738 /* More to get the right clip region than for efficiency */
1739 if (!gdk_rectangle_intersect (area, rect, &intersection))
1742 intersection.x += widget->allocation.x;
1743 intersection.y += widget->allocation.y;
1745 if ((!range->inverted && (arrow_type == GTK_ARROW_DOWN ||
1746 arrow_type == GTK_ARROW_RIGHT)) ||
1747 (range->inverted && (arrow_type == GTK_ARROW_UP ||
1748 arrow_type == GTK_ARROW_LEFT)))
1750 arrow_sensitive = range->layout->upper_sensitive;
1754 arrow_sensitive = range->layout->lower_sensitive;
1757 if (!gtk_widget_is_sensitive (GTK_WIDGET (range)) || !arrow_sensitive)
1758 state_type = GTK_STATE_INSENSITIVE;
1760 state_type = GTK_STATE_ACTIVE;
1761 else if (prelighted)
1762 state_type = GTK_STATE_PRELIGHT;
1764 state_type = GTK_STATE_NORMAL;
1766 if (clicked && arrow_sensitive)
1767 shadow_type = GTK_SHADOW_IN;
1769 shadow_type = GTK_SHADOW_OUT;
1771 gtk_paint_box (widget->style,
1773 state_type, shadow_type,
1774 &intersection, widget,
1775 gtk_range_get_stepper_detail (range, stepper),
1776 widget->allocation.x + rect->x,
1777 widget->allocation.y + rect->y,
1781 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
1783 arrow_width = rect->width * arrow_scaling;
1784 arrow_height = rect->height * arrow_scaling;
1785 arrow_x = widget->allocation.x + rect->x + (rect->width - arrow_width) / 2;
1786 arrow_y = widget->allocation.y + rect->y + (rect->height - arrow_height) / 2;
1788 if (clicked && arrow_sensitive)
1790 gint arrow_displacement_x;
1791 gint arrow_displacement_y;
1793 gtk_range_get_props (GTK_RANGE (widget),
1794 NULL, NULL, NULL, NULL, NULL, NULL,
1795 &arrow_displacement_x, &arrow_displacement_y);
1797 arrow_x += arrow_displacement_x;
1798 arrow_y += arrow_displacement_y;
1801 gtk_paint_arrow (widget->style,
1803 state_type, shadow_type,
1804 &intersection, widget,
1805 gtk_range_get_stepper_detail (range, stepper),
1808 arrow_x, arrow_y, arrow_width, arrow_height);
1812 gtk_range_expose (GtkWidget *widget,
1813 GdkEventExpose *event)
1815 GtkRange *range = GTK_RANGE (widget);
1818 GtkShadowType shadow_type;
1819 GdkRectangle expose_area; /* Relative to widget->allocation */
1821 gint focus_line_width = 0;
1822 gint focus_padding = 0;
1823 gboolean touchscreen;
1825 g_object_get (gtk_widget_get_settings (widget),
1826 "gtk-touchscreen-mode", &touchscreen,
1828 if (gtk_widget_get_can_focus (GTK_WIDGET (range)))
1829 gtk_widget_style_get (GTK_WIDGET (range),
1830 "focus-line-width", &focus_line_width,
1831 "focus-padding", &focus_padding,
1834 /* we're now exposing, so there's no need to force early repaints */
1835 if (range->layout->repaint_id)
1836 g_source_remove (range->layout->repaint_id);
1837 range->layout->repaint_id = 0;
1839 expose_area = event->area;
1840 expose_area.x -= widget->allocation.x;
1841 expose_area.y -= widget->allocation.y;
1843 gtk_range_calc_marks (range);
1844 gtk_range_calc_layout (range, range->adjustment->value);
1846 sensitive = gtk_widget_is_sensitive (widget);
1848 /* Just to be confusing, we draw the trough for the whole
1849 * range rectangle, not the trough rectangle (the trough
1850 * rectangle is just for hit detection)
1852 /* The gdk_rectangle_intersect is more to get the right
1853 * clip region (limited to range_rect) than for efficiency
1855 if (gdk_rectangle_intersect (&expose_area, &range->range_rect,
1858 gint x = (widget->allocation.x + range->range_rect.x +
1859 focus_line_width + focus_padding);
1860 gint y = (widget->allocation.y + range->range_rect.y +
1861 focus_line_width + focus_padding);
1862 gint width = (range->range_rect.width -
1863 2 * (focus_line_width + focus_padding));
1864 gint height = (range->range_rect.height -
1865 2 * (focus_line_width + focus_padding));
1866 gboolean trough_side_details;
1867 gboolean trough_under_steppers;
1869 gint stepper_spacing;
1871 area.x += widget->allocation.x;
1872 area.y += widget->allocation.y;
1874 gtk_widget_style_get (GTK_WIDGET (range),
1875 "trough-side-details", &trough_side_details,
1876 "trough-under-steppers", &trough_under_steppers,
1877 "stepper-size", &stepper_size,
1878 "stepper-spacing", &stepper_spacing,
1881 if (stepper_spacing > 0)
1882 trough_under_steppers = FALSE;
1884 if (! trough_under_steppers)
1889 if (range->has_stepper_a)
1890 offset += stepper_size;
1892 if (range->has_stepper_b)
1893 offset += stepper_size;
1897 if (range->has_stepper_c)
1898 shorter += stepper_size;
1900 if (range->has_stepper_d)
1901 shorter += stepper_size;
1903 if (range->has_stepper_a || range->has_stepper_b)
1905 offset += stepper_spacing;
1906 shorter += stepper_spacing;
1909 if (range->has_stepper_c || range->has_stepper_d)
1911 shorter += stepper_spacing;
1914 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1926 if (! trough_side_details)
1928 gtk_paint_box (widget->style,
1930 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1932 &area, GTK_WIDGET(range), "trough",
1938 gint trough_change_pos_x = width;
1939 gint trough_change_pos_y = height;
1941 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1942 trough_change_pos_x = (range->layout->slider.x +
1943 range->layout->slider.width / 2 -
1944 (x - widget->allocation.x));
1946 trough_change_pos_y = (range->layout->slider.y +
1947 range->layout->slider.height / 2 -
1948 (y - widget->allocation.y));
1950 gtk_paint_box (widget->style,
1952 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1954 &area, GTK_WIDGET (range),
1955 should_invert (range) ? "trough-upper" : "trough-lower",
1957 trough_change_pos_x, trough_change_pos_y);
1959 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1960 trough_change_pos_y = 0;
1962 trough_change_pos_x = 0;
1964 gtk_paint_box (widget->style,
1966 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1968 &area, GTK_WIDGET (range),
1969 should_invert (range) ? "trough-lower" : "trough-upper",
1970 x + trough_change_pos_x, y + trough_change_pos_y,
1971 width - trough_change_pos_x,
1972 height - trough_change_pos_y);
1975 if (range->layout->show_fill_level &&
1976 range->adjustment->upper - range->adjustment->page_size -
1977 range->adjustment->lower != 0)
1979 gdouble fill_level = range->layout->fill_level;
1982 gint fill_width = width;
1983 gint fill_height = height;
1986 fill_level = CLAMP (fill_level, range->adjustment->lower,
1987 range->adjustment->upper -
1988 range->adjustment->page_size);
1990 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
1992 fill_x = widget->allocation.x + range->layout->trough.x;
1993 fill_width = (range->layout->slider.width +
1994 (fill_level - range->adjustment->lower) /
1995 (range->adjustment->upper -
1996 range->adjustment->lower -
1997 range->adjustment->page_size) *
1998 (range->layout->trough.width -
1999 range->layout->slider.width));
2001 if (should_invert (range))
2002 fill_x += range->layout->trough.width - fill_width;
2006 fill_y = widget->allocation.y + range->layout->trough.y;
2007 fill_height = (range->layout->slider.height +
2008 (fill_level - range->adjustment->lower) /
2009 (range->adjustment->upper -
2010 range->adjustment->lower -
2011 range->adjustment->page_size) *
2012 (range->layout->trough.height -
2013 range->layout->slider.height));
2015 if (should_invert (range))
2016 fill_y += range->layout->trough.height - fill_height;
2019 if (fill_level < range->adjustment->upper - range->adjustment->page_size)
2020 fill_detail = "trough-fill-level-full";
2022 fill_detail = "trough-fill-level";
2024 gtk_paint_box (widget->style,
2026 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
2028 &area, GTK_WIDGET (range), fill_detail,
2030 fill_width, fill_height);
2033 if (sensitive && gtk_widget_has_focus (widget))
2034 gtk_paint_focus (widget->style, widget->window, gtk_widget_get_state (widget),
2035 &area, widget, "trough",
2036 widget->allocation.x + range->range_rect.x,
2037 widget->allocation.y + range->range_rect.y,
2038 range->range_rect.width,
2039 range->range_rect.height);
2042 shadow_type = GTK_SHADOW_OUT;
2045 state = GTK_STATE_INSENSITIVE;
2046 else if (!touchscreen && range->layout->mouse_location == MOUSE_SLIDER)
2047 state = GTK_STATE_PRELIGHT;
2049 state = GTK_STATE_NORMAL;
2051 if (range->layout->grab_location == MOUSE_SLIDER)
2053 gboolean activate_slider;
2055 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
2057 if (activate_slider)
2059 state = GTK_STATE_ACTIVE;
2060 shadow_type = GTK_SHADOW_IN;
2064 if (gdk_rectangle_intersect (&expose_area,
2065 &range->layout->slider,
2068 area.x += widget->allocation.x;
2069 area.y += widget->allocation.y;
2071 gtk_paint_slider (widget->style,
2077 gtk_range_get_slider_detail (range),
2078 widget->allocation.x + range->layout->slider.x,
2079 widget->allocation.y + range->layout->slider.y,
2080 range->layout->slider.width,
2081 range->layout->slider.height,
2082 range->orientation);
2085 if (range->has_stepper_a)
2086 draw_stepper (range, STEPPER_A,
2087 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
2088 range->layout->grab_location == MOUSE_STEPPER_A,
2089 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_A,
2092 if (range->has_stepper_b)
2093 draw_stepper (range, STEPPER_B,
2094 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
2095 range->layout->grab_location == MOUSE_STEPPER_B,
2096 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_B,
2099 if (range->has_stepper_c)
2100 draw_stepper (range, STEPPER_C,
2101 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_UP : GTK_ARROW_LEFT,
2102 range->layout->grab_location == MOUSE_STEPPER_C,
2103 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_C,
2106 if (range->has_stepper_d)
2107 draw_stepper (range, STEPPER_D,
2108 range->orientation == GTK_ORIENTATION_VERTICAL ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
2109 range->layout->grab_location == MOUSE_STEPPER_D,
2110 !touchscreen && range->layout->mouse_location == MOUSE_STEPPER_D,
2117 range_grab_add (GtkRange *range,
2119 MouseLocation location,
2122 GtkRangeLayout *layout = range->layout;
2124 if (device == layout->grab_device)
2127 if (layout->grab_device != NULL)
2129 g_warning ("GtkRange already had a grab device, releasing device grab");
2130 gtk_device_grab_remove (GTK_WIDGET (range), layout->grab_device);
2133 /* we don't actually gdk_grab, since a button is down */
2134 gtk_device_grab_add (GTK_WIDGET (range), device, TRUE);
2136 range->layout->grab_location = location;
2137 range->layout->grab_button = button;
2138 range->layout->grab_device = device;
2140 if (gtk_range_update_mouse_location (range))
2141 gtk_widget_queue_draw (GTK_WIDGET (range));
2145 range_grab_remove (GtkRange *range)
2147 GtkRangeLayout *layout = range->layout;
2148 MouseLocation location;
2150 if (layout->grab_device)
2152 gtk_device_grab_remove (GTK_WIDGET (range),
2153 layout->grab_device);
2154 layout->grab_device = NULL;
2157 location = range->layout->grab_location;
2158 range->layout->grab_location = MOUSE_OUTSIDE;
2159 range->layout->grab_button = 0;
2161 if (gtk_range_update_mouse_location (range) ||
2162 location != MOUSE_OUTSIDE)
2163 gtk_widget_queue_draw (GTK_WIDGET (range));
2166 static GtkScrollType
2167 range_get_scroll_for_grab (GtkRange *range)
2171 invert = should_invert (range);
2172 switch (range->layout->grab_location)
2174 /* Backward stepper */
2175 case MOUSE_STEPPER_A:
2176 case MOUSE_STEPPER_C:
2177 switch (range->layout->grab_button)
2180 return invert ? GTK_SCROLL_STEP_FORWARD : GTK_SCROLL_STEP_BACKWARD;
2183 return invert ? GTK_SCROLL_PAGE_FORWARD : GTK_SCROLL_PAGE_BACKWARD;
2186 return invert ? GTK_SCROLL_END : GTK_SCROLL_START;
2191 /* Forward stepper */
2192 case MOUSE_STEPPER_B:
2193 case MOUSE_STEPPER_D:
2194 switch (range->layout->grab_button)
2197 return invert ? GTK_SCROLL_STEP_BACKWARD : GTK_SCROLL_STEP_FORWARD;
2200 return invert ? GTK_SCROLL_PAGE_BACKWARD : GTK_SCROLL_PAGE_FORWARD;
2203 return invert ? GTK_SCROLL_START : GTK_SCROLL_END;
2211 if (range->trough_click_forward)
2212 return GTK_SCROLL_PAGE_FORWARD;
2214 return GTK_SCROLL_PAGE_BACKWARD;
2224 return GTK_SCROLL_NONE;
2228 coord_to_value (GtkRange *range,
2237 gint trough_under_steppers;
2239 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2241 trough_length = range->layout->trough.height;
2242 trough_start = range->layout->trough.y;
2243 slider_length = range->layout->slider.height;
2247 trough_length = range->layout->trough.width;
2248 trough_start = range->layout->trough.x;
2249 slider_length = range->layout->slider.width;
2252 gtk_range_get_props (range, NULL, NULL, NULL, &trough_border, NULL,
2253 &trough_under_steppers, NULL, NULL);
2255 if (! trough_under_steppers)
2257 trough_start += trough_border;
2258 trough_length -= 2 * trough_border;
2261 if (trough_length == slider_length)
2264 frac = (MAX (0, coord - trough_start) /
2265 (gdouble) (trough_length - slider_length));
2267 if (should_invert (range))
2270 value = range->adjustment->lower + frac * (range->adjustment->upper -
2271 range->adjustment->lower -
2272 range->adjustment->page_size);
2278 gtk_range_key_press (GtkWidget *widget,
2282 GtkRange *range = GTK_RANGE (widget);
2283 GtkRangeLayout *layout = range->layout;
2285 device = gdk_event_get_device ((GdkEvent *) event);
2286 device = gdk_device_get_associated_device (device);
2288 if (device == layout->grab_device &&
2289 event->keyval == GDK_Escape &&
2290 range->layout->grab_location != MOUSE_OUTSIDE)
2292 stop_scrolling (range);
2294 update_slider_position (range,
2295 range->slide_initial_coordinate,
2296 range->slide_initial_coordinate);
2301 return GTK_WIDGET_CLASS (gtk_range_parent_class)->key_press_event (widget, event);
2305 gtk_range_button_press (GtkWidget *widget,
2306 GdkEventButton *event)
2308 GtkRange *range = GTK_RANGE (widget);
2311 if (!gtk_widget_has_focus (widget))
2312 gtk_widget_grab_focus (widget);
2314 /* ignore presses when we're already doing something else. */
2315 if (range->layout->grab_location != MOUSE_OUTSIDE)
2318 device = gdk_event_get_device ((GdkEvent *) event);
2319 range->layout->mouse_x = event->x;
2320 range->layout->mouse_y = event->y;
2322 if (gtk_range_update_mouse_location (range))
2323 gtk_widget_queue_draw (widget);
2325 if (range->layout->mouse_location == MOUSE_TROUGH &&
2328 /* button 1 steps by page increment, as with button 2 on a stepper
2330 GtkScrollType scroll;
2331 gdouble click_value;
2333 click_value = coord_to_value (range,
2334 range->orientation == GTK_ORIENTATION_VERTICAL ?
2335 event->y : event->x);
2337 range->trough_click_forward = click_value > range->adjustment->value;
2338 range_grab_add (range, device, MOUSE_TROUGH, event->button);
2340 scroll = range_get_scroll_for_grab (range);
2342 gtk_range_add_step_timer (range, scroll);
2346 else if ((range->layout->mouse_location == MOUSE_STEPPER_A ||
2347 range->layout->mouse_location == MOUSE_STEPPER_B ||
2348 range->layout->mouse_location == MOUSE_STEPPER_C ||
2349 range->layout->mouse_location == MOUSE_STEPPER_D) &&
2350 (event->button == 1 || event->button == 2 || event->button == 3))
2352 GdkRectangle *stepper_area;
2353 GtkScrollType scroll;
2355 range_grab_add (range, device, range->layout->mouse_location, event->button);
2357 stepper_area = get_area (range, range->layout->mouse_location);
2358 gtk_widget_queue_draw_area (widget,
2359 widget->allocation.x + stepper_area->x,
2360 widget->allocation.y + stepper_area->y,
2361 stepper_area->width,
2362 stepper_area->height);
2364 scroll = range_get_scroll_for_grab (range);
2365 if (scroll != GTK_SCROLL_NONE)
2366 gtk_range_add_step_timer (range, scroll);
2370 else if ((range->layout->mouse_location == MOUSE_TROUGH &&
2371 event->button == 2) ||
2372 range->layout->mouse_location == MOUSE_SLIDER)
2374 gboolean need_value_update = FALSE;
2375 gboolean activate_slider;
2377 /* Any button can be used to drag the slider, but you can start
2378 * dragging the slider with a trough click using button 2;
2379 * On button 2 press, we warp the slider to mouse position,
2380 * then begin the slider drag.
2382 if (event->button == 2)
2384 gdouble slider_low_value, slider_high_value, new_value;
2387 coord_to_value (range,
2388 range->orientation == GTK_ORIENTATION_VERTICAL ?
2389 event->y : event->x);
2391 coord_to_value (range,
2392 range->orientation == GTK_ORIENTATION_VERTICAL ?
2393 event->y - range->layout->slider.height :
2394 event->x - range->layout->slider.width);
2396 /* compute new value for warped slider */
2397 new_value = slider_low_value + (slider_high_value - slider_low_value) / 2;
2399 /* recalc slider, so we can set slide_initial_slider_position
2402 range->need_recalc = TRUE;
2403 gtk_range_calc_layout (range, new_value);
2405 /* defer adjustment updates to update_slider_position() in order
2406 * to keep pixel quantisation
2408 need_value_update = TRUE;
2411 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2413 range->slide_initial_slider_position = range->layout->slider.y;
2414 range->slide_initial_coordinate = event->y;
2418 range->slide_initial_slider_position = range->layout->slider.x;
2419 range->slide_initial_coordinate = event->x;
2422 range_grab_add (range, device, MOUSE_SLIDER, event->button);
2424 gtk_widget_style_get (widget, "activate-slider", &activate_slider, NULL);
2426 /* force a redraw, if the active slider is drawn differently to the
2429 if (activate_slider)
2430 gtk_widget_queue_draw (widget);
2432 if (need_value_update)
2433 update_slider_position (range, event->x, event->y);
2441 /* During a slide, move the slider as required given new mouse position */
2443 update_slider_position (GtkRange *range,
2456 if (range->orientation == GTK_ORIENTATION_VERTICAL)
2457 delta = mouse_y - range->slide_initial_coordinate;
2459 delta = mouse_x - range->slide_initial_coordinate;
2461 c = range->slide_initial_slider_position + delta;
2463 new_value = coord_to_value (range, c);
2464 next_value = coord_to_value (range, c + 1);
2465 mark_delta = fabs (next_value - new_value);
2467 for (i = 0; i < range->layout->n_marks; i++)
2469 mark_value = range->layout->marks[i];
2471 if (fabs (range->adjustment->value - mark_value) < 3 * mark_delta)
2473 if (fabs (new_value - mark_value) < (range->slider_end - range->slider_start) * 0.5 * mark_delta)
2475 new_value = mark_value;
2481 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_JUMP, new_value,
2486 stop_scrolling (GtkRange *range)
2488 range_grab_remove (range);
2489 gtk_range_remove_step_timer (range);
2490 /* Flush any pending discontinuous/delayed updates */
2491 gtk_range_update_value (range);
2495 gtk_range_grab_broken (GtkWidget *widget,
2496 GdkEventGrabBroken *event)
2498 GtkRange *range = GTK_RANGE (widget);
2501 device = gdk_event_get_device ((GdkEvent *) event);
2503 if (device == range->layout->grab_device &&
2504 range->layout->grab_location != MOUSE_OUTSIDE)
2506 if (range->layout->grab_location == MOUSE_SLIDER)
2507 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2509 stop_scrolling (range);
2518 gtk_range_button_release (GtkWidget *widget,
2519 GdkEventButton *event)
2521 GtkRange *range = GTK_RANGE (widget);
2524 if (event->window == range->event_window)
2526 range->layout->mouse_x = event->x;
2527 range->layout->mouse_y = event->y;
2531 gdk_window_get_device_position (range->event_window,
2533 &range->layout->mouse_x,
2534 &range->layout->mouse_y,
2538 device = gdk_event_get_device ((GdkEvent *) event);
2540 if (range->layout->grab_device == device &&
2541 range->layout->grab_button == event->button)
2543 if (range->layout->grab_location == MOUSE_SLIDER)
2544 update_slider_position (range, range->layout->mouse_x, range->layout->mouse_y);
2546 stop_scrolling (range);
2555 * _gtk_range_get_wheel_delta:
2556 * @range: a #GtkRange
2557 * @direction: A #GdkScrollDirection
2559 * Returns a good step value for the mouse wheel.
2561 * Return value: A good step value for the mouse wheel.
2566 _gtk_range_get_wheel_delta (GtkRange *range,
2567 GdkScrollDirection direction)
2569 GtkAdjustment *adj = range->adjustment;
2572 if (GTK_IS_SCROLLBAR (range))
2573 delta = pow (adj->page_size, 2.0 / 3.0);
2575 delta = adj->step_increment * 2;
2577 if (direction == GDK_SCROLL_UP ||
2578 direction == GDK_SCROLL_LEFT)
2581 if (range->inverted)
2588 gtk_range_scroll_event (GtkWidget *widget,
2589 GdkEventScroll *event)
2591 GtkRange *range = GTK_RANGE (widget);
2593 if (gtk_widget_get_realized (widget))
2595 GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
2599 delta = _gtk_range_get_wheel_delta (range, event->direction);
2601 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2602 GTK_SCROLL_JUMP, adj->value + delta,
2605 /* Policy DELAYED makes sense with scroll events,
2606 * but DISCONTINUOUS doesn't, so we update immediately
2609 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
2610 gtk_range_update_value (range);
2617 gtk_range_motion_notify (GtkWidget *widget,
2618 GdkEventMotion *event)
2622 range = GTK_RANGE (widget);
2624 gdk_event_request_motions (event);
2626 range->layout->mouse_x = event->x;
2627 range->layout->mouse_y = event->y;
2629 if (gtk_range_update_mouse_location (range))
2630 gtk_widget_queue_draw (widget);
2632 if (range->layout->grab_location == MOUSE_SLIDER)
2633 update_slider_position (range, event->x, event->y);
2635 /* We handled the event if the mouse was in the range_rect */
2636 return range->layout->mouse_location != MOUSE_OUTSIDE;
2640 gtk_range_enter_notify (GtkWidget *widget,
2641 GdkEventCrossing *event)
2643 GtkRange *range = GTK_RANGE (widget);
2645 range->layout->mouse_x = event->x;
2646 range->layout->mouse_y = event->y;
2648 if (gtk_range_update_mouse_location (range))
2649 gtk_widget_queue_draw (widget);
2655 gtk_range_leave_notify (GtkWidget *widget,
2656 GdkEventCrossing *event)
2658 GtkRange *range = GTK_RANGE (widget);
2660 range->layout->mouse_x = -1;
2661 range->layout->mouse_y = -1;
2663 if (gtk_range_update_mouse_location (range))
2664 gtk_widget_queue_draw (widget);
2670 gtk_range_grab_notify (GtkWidget *widget,
2671 gboolean was_grabbed)
2673 GtkRangeLayout *layout = GTK_RANGE (widget)->layout;
2675 if (layout->grab_device &&
2676 gtk_widget_device_is_shadowed (widget, layout->grab_device))
2677 stop_scrolling (GTK_RANGE (widget));
2681 gtk_range_state_changed (GtkWidget *widget,
2682 GtkStateType previous_state)
2684 if (!gtk_widget_is_sensitive (widget))
2685 stop_scrolling (GTK_RANGE (widget));
2688 #define check_rectangle(rectangle1, rectangle2) \
2690 if (rectangle1.x != rectangle2.x) return TRUE; \
2691 if (rectangle1.y != rectangle2.y) return TRUE; \
2692 if (rectangle1.width != rectangle2.width) return TRUE; \
2693 if (rectangle1.height != rectangle2.height) return TRUE; \
2697 layout_changed (GtkRangeLayout *layout1,
2698 GtkRangeLayout *layout2)
2700 check_rectangle (layout1->slider, layout2->slider);
2701 check_rectangle (layout1->trough, layout2->trough);
2702 check_rectangle (layout1->stepper_a, layout2->stepper_a);
2703 check_rectangle (layout1->stepper_d, layout2->stepper_d);
2704 check_rectangle (layout1->stepper_b, layout2->stepper_b);
2705 check_rectangle (layout1->stepper_c, layout2->stepper_c);
2707 if (layout1->upper_sensitive != layout2->upper_sensitive) return TRUE;
2708 if (layout1->lower_sensitive != layout2->lower_sensitive) return TRUE;
2714 gtk_range_adjustment_changed (GtkAdjustment *adjustment,
2717 GtkRange *range = GTK_RANGE (data);
2718 /* create a copy of the layout */
2719 GtkRangeLayout layout = *range->layout;
2721 range->layout->recalc_marks = TRUE;
2722 range->need_recalc = TRUE;
2723 gtk_range_calc_layout (range, range->adjustment->value);
2725 /* now check whether the layout changed */
2726 if (layout_changed (range->layout, &layout))
2727 gtk_widget_queue_draw (GTK_WIDGET (range));
2729 /* Note that we don't round off to range->round_digits here.
2730 * that's because it's really broken to change a value
2731 * in response to a change signal on that value; round_digits
2732 * is therefore defined to be a filter on what the GtkRange
2733 * can input into the adjustment, not a filter that the GtkRange
2734 * will enforce on the adjustment.
2739 force_repaint (gpointer data)
2741 GtkRange *range = GTK_RANGE (data);
2743 range->layout->repaint_id = 0;
2744 if (gtk_widget_is_drawable (GTK_WIDGET (range)))
2745 gdk_window_process_updates (GTK_WIDGET (range)->window, FALSE);
2751 gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
2754 GtkRange *range = GTK_RANGE (data);
2755 /* create a copy of the layout */
2756 GtkRangeLayout layout = *range->layout;
2758 range->need_recalc = TRUE;
2759 gtk_range_calc_layout (range, range->adjustment->value);
2761 /* now check whether the layout changed */
2762 if (layout_changed (range->layout, &layout) ||
2763 (GTK_IS_SCALE (range) && gtk_scale_get_draw_value (GTK_SCALE (range))))
2765 gtk_widget_queue_draw (GTK_WIDGET (range));
2766 /* setup a timer to ensure the range isn't lagging too much behind the scroll position */
2767 if (!range->layout->repaint_id)
2768 range->layout->repaint_id = gdk_threads_add_timeout_full (GDK_PRIORITY_EVENTS, 181, force_repaint, range, NULL);
2771 /* Note that we don't round off to range->round_digits here.
2772 * that's because it's really broken to change a value
2773 * in response to a change signal on that value; round_digits
2774 * is therefore defined to be a filter on what the GtkRange
2775 * can input into the adjustment, not a filter that the GtkRange
2776 * will enforce on the adjustment.
2779 g_signal_emit (range, signals[VALUE_CHANGED], 0);
2783 gtk_range_style_set (GtkWidget *widget,
2784 GtkStyle *previous_style)
2786 GtkRange *range = GTK_RANGE (widget);
2788 range->need_recalc = TRUE;
2790 GTK_WIDGET_CLASS (gtk_range_parent_class)->style_set (widget, previous_style);
2794 apply_marks (GtkRange *range,
2801 for (i = 0; i < range->layout->n_marks; i++)
2803 mark = range->layout->marks[i];
2804 if ((oldval < mark && mark < *newval) ||
2805 (oldval > mark && mark > *newval))
2814 step_back (GtkRange *range)
2819 newval = range->adjustment->value - range->adjustment->step_increment;
2820 apply_marks (range, range->adjustment->value, &newval);
2821 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2822 GTK_SCROLL_STEP_BACKWARD, newval, &handled);
2826 step_forward (GtkRange *range)
2831 newval = range->adjustment->value + range->adjustment->step_increment;
2832 apply_marks (range, range->adjustment->value, &newval);
2833 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2834 GTK_SCROLL_STEP_FORWARD, newval, &handled);
2839 page_back (GtkRange *range)
2844 newval = range->adjustment->value - range->adjustment->page_increment;
2845 apply_marks (range, range->adjustment->value, &newval);
2846 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2847 GTK_SCROLL_PAGE_BACKWARD, newval, &handled);
2851 page_forward (GtkRange *range)
2856 newval = range->adjustment->value + range->adjustment->page_increment;
2857 apply_marks (range, range->adjustment->value, &newval);
2858 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2859 GTK_SCROLL_PAGE_FORWARD, newval, &handled);
2863 scroll_begin (GtkRange *range)
2866 g_signal_emit (range, signals[CHANGE_VALUE], 0,
2867 GTK_SCROLL_START, range->adjustment->lower,
2872 scroll_end (GtkRange *range)
2877 newval = range->adjustment->upper - range->adjustment->page_size;
2878 g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_END, newval,
2883 gtk_range_scroll (GtkRange *range,
2884 GtkScrollType scroll)
2886 gdouble old_value = range->adjustment->value;
2890 case GTK_SCROLL_STEP_LEFT:
2891 if (should_invert (range))
2892 step_forward (range);
2897 case GTK_SCROLL_STEP_UP:
2898 if (should_invert (range))
2899 step_forward (range);
2904 case GTK_SCROLL_STEP_RIGHT:
2905 if (should_invert (range))
2908 step_forward (range);
2911 case GTK_SCROLL_STEP_DOWN:
2912 if (should_invert (range))
2915 step_forward (range);
2918 case GTK_SCROLL_STEP_BACKWARD:
2922 case GTK_SCROLL_STEP_FORWARD:
2923 step_forward (range);
2926 case GTK_SCROLL_PAGE_LEFT:
2927 if (should_invert (range))
2928 page_forward (range);
2933 case GTK_SCROLL_PAGE_UP:
2934 if (should_invert (range))
2935 page_forward (range);
2940 case GTK_SCROLL_PAGE_RIGHT:
2941 if (should_invert (range))
2944 page_forward (range);
2947 case GTK_SCROLL_PAGE_DOWN:
2948 if (should_invert (range))
2951 page_forward (range);
2954 case GTK_SCROLL_PAGE_BACKWARD:
2958 case GTK_SCROLL_PAGE_FORWARD:
2959 page_forward (range);
2962 case GTK_SCROLL_START:
2963 scroll_begin (range);
2966 case GTK_SCROLL_END:
2970 case GTK_SCROLL_JUMP:
2971 /* Used by CList, range doesn't use it. */
2974 case GTK_SCROLL_NONE:
2978 return range->adjustment->value != old_value;
2982 gtk_range_move_slider (GtkRange *range,
2983 GtkScrollType scroll)
2985 gboolean cursor_only;
2987 g_object_get (gtk_widget_get_settings (GTK_WIDGET (range)),
2988 "gtk-keynav-cursor-only", &cursor_only,
2993 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (range));
2995 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
2997 if (scroll == GTK_SCROLL_STEP_UP ||
2998 scroll == GTK_SCROLL_STEP_DOWN)
3001 gtk_widget_child_focus (toplevel,
3002 scroll == GTK_SCROLL_STEP_UP ?
3003 GTK_DIR_UP : GTK_DIR_DOWN);
3009 if (scroll == GTK_SCROLL_STEP_LEFT ||
3010 scroll == GTK_SCROLL_STEP_RIGHT)
3013 gtk_widget_child_focus (toplevel,
3014 scroll == GTK_SCROLL_STEP_LEFT ?
3015 GTK_DIR_LEFT : GTK_DIR_RIGHT);
3021 if (! gtk_range_scroll (range, scroll))
3022 gtk_widget_error_bell (GTK_WIDGET (range));
3024 /* Policy DELAYED makes sense with key events,
3025 * but DISCONTINUOUS doesn't, so we update immediately
3028 if (range->update_policy == GTK_UPDATE_DISCONTINUOUS)
3029 gtk_range_update_value (range);
3033 gtk_range_get_props (GtkRange *range,
3037 gint *trough_border,
3038 gint *stepper_spacing,
3039 gboolean *trough_under_steppers,
3040 gint *arrow_displacement_x,
3041 gint *arrow_displacement_y)
3043 GtkWidget *widget = GTK_WIDGET (range);
3044 gint tmp_slider_width, tmp_stepper_size, tmp_focus_width, tmp_trough_border;
3045 gint tmp_stepper_spacing, tmp_trough_under_steppers;
3046 gint tmp_arrow_displacement_x, tmp_arrow_displacement_y;
3048 gtk_widget_style_get (widget,
3049 "slider-width", &tmp_slider_width,
3050 "trough-border", &tmp_trough_border,
3051 "stepper-size", &tmp_stepper_size,
3052 "stepper-spacing", &tmp_stepper_spacing,
3053 "trough-under-steppers", &tmp_trough_under_steppers,
3054 "arrow-displacement-x", &tmp_arrow_displacement_x,
3055 "arrow-displacement-y", &tmp_arrow_displacement_y,
3058 if (tmp_stepper_spacing > 0)
3059 tmp_trough_under_steppers = FALSE;
3061 if (gtk_widget_get_can_focus (GTK_WIDGET (range)))
3063 gint focus_line_width;
3066 gtk_widget_style_get (GTK_WIDGET (range),
3067 "focus-line-width", &focus_line_width,
3068 "focus-padding", &focus_padding,
3071 tmp_focus_width = focus_line_width + focus_padding;
3075 tmp_focus_width = 0;
3079 *slider_width = tmp_slider_width;
3082 *focus_width = tmp_focus_width;
3085 *trough_border = tmp_trough_border;
3088 *stepper_size = tmp_stepper_size;
3090 if (stepper_spacing)
3091 *stepper_spacing = tmp_stepper_spacing;
3093 if (trough_under_steppers)
3094 *trough_under_steppers = tmp_trough_under_steppers;
3096 if (arrow_displacement_x)
3097 *arrow_displacement_x = tmp_arrow_displacement_x;
3099 if (arrow_displacement_y)
3100 *arrow_displacement_y = tmp_arrow_displacement_y;
3103 #define POINT_IN_RECT(xcoord, ycoord, rect) \
3104 ((xcoord) >= (rect).x && \
3105 (xcoord) < ((rect).x + (rect).width) && \
3106 (ycoord) >= (rect).y && \
3107 (ycoord) < ((rect).y + (rect).height))
3109 /* Update mouse location, return TRUE if it changes */
3111 gtk_range_update_mouse_location (GtkRange *range)
3117 widget = GTK_WIDGET (range);
3119 old = range->layout->mouse_location;
3121 x = range->layout->mouse_x;
3122 y = range->layout->mouse_y;
3124 if (range->layout->grab_location != MOUSE_OUTSIDE)
3125 range->layout->mouse_location = range->layout->grab_location;
3126 else if (POINT_IN_RECT (x, y, range->layout->stepper_a))
3127 range->layout->mouse_location = MOUSE_STEPPER_A;
3128 else if (POINT_IN_RECT (x, y, range->layout->stepper_b))
3129 range->layout->mouse_location = MOUSE_STEPPER_B;
3130 else if (POINT_IN_RECT (x, y, range->layout->stepper_c))
3131 range->layout->mouse_location = MOUSE_STEPPER_C;
3132 else if (POINT_IN_RECT (x, y, range->layout->stepper_d))
3133 range->layout->mouse_location = MOUSE_STEPPER_D;
3134 else if (POINT_IN_RECT (x, y, range->layout->slider))
3135 range->layout->mouse_location = MOUSE_SLIDER;
3136 else if (POINT_IN_RECT (x, y, range->layout->trough))
3137 range->layout->mouse_location = MOUSE_TROUGH;
3138 else if (POINT_IN_RECT (x, y, widget->allocation))
3139 range->layout->mouse_location = MOUSE_WIDGET;
3141 range->layout->mouse_location = MOUSE_OUTSIDE;
3143 return old != range->layout->mouse_location;
3146 /* Clamp rect, border inside widget->allocation, such that we prefer
3147 * to take space from border not rect in all directions, and prefer to
3148 * give space to border over rect in one direction.
3151 clamp_dimensions (GtkWidget *widget,
3154 gboolean border_expands_horizontally)
3156 gint extra, shortage;
3158 g_return_if_fail (rect->x == 0);
3159 g_return_if_fail (rect->y == 0);
3160 g_return_if_fail (rect->width >= 0);
3161 g_return_if_fail (rect->height >= 0);
3165 extra = widget->allocation.width - border->left - border->right - rect->width;
3168 if (border_expands_horizontally)
3170 border->left += extra / 2;
3171 border->right += extra / 2 + extra % 2;
3175 rect->width += extra;
3179 /* See if we can fit rect, if not kill the border */
3180 shortage = rect->width - widget->allocation.width;
3183 rect->width = widget->allocation.width;
3184 /* lose the border */
3190 /* See if we can fit rect with borders */
3191 shortage = rect->width + border->left + border->right -
3192 widget->allocation.width;
3195 /* Shrink borders */
3196 border->left -= shortage / 2;
3197 border->right -= shortage / 2 + shortage % 2;
3203 extra = widget->allocation.height - border->top - border->bottom - rect->height;
3206 if (border_expands_horizontally)
3208 /* don't expand border vertically */
3209 rect->height += extra;
3213 border->top += extra / 2;
3214 border->bottom += extra / 2 + extra % 2;
3218 /* See if we can fit rect, if not kill the border */
3219 shortage = rect->height - widget->allocation.height;
3222 rect->height = widget->allocation.height;
3223 /* lose the border */
3229 /* See if we can fit rect with borders */
3230 shortage = rect->height + border->top + border->bottom -
3231 widget->allocation.height;
3234 /* Shrink borders */
3235 border->top -= shortage / 2;
3236 border->bottom -= shortage / 2 + shortage % 2;
3242 gtk_range_calc_request (GtkRange *range,
3247 gint stepper_spacing,
3248 GdkRectangle *range_rect,
3251 gboolean *has_steppers_ab,
3252 gboolean *has_steppers_cd,
3253 gint *slider_length_p)
3265 if (GTK_RANGE_GET_CLASS (range)->get_range_border)
3266 GTK_RANGE_GET_CLASS (range)->get_range_border (range, border);
3271 if (range->has_stepper_a)
3273 if (range->has_stepper_b)
3275 if (range->has_stepper_c)
3277 if (range->has_stepper_d)
3280 n_steppers = n_steppers_ab + n_steppers_cd;
3282 slider_length = range->min_slider_size;
3287 /* We never expand to fill available space in the small dimension
3288 * (i.e. vertical scrollbars are always a fixed width)
3290 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3292 range_rect->width = (focus_width + trough_border) * 2 + slider_width;
3293 range_rect->height = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
3295 if (n_steppers_ab > 0)
3296 range_rect->height += stepper_spacing;
3298 if (n_steppers_cd > 0)
3299 range_rect->height += stepper_spacing;
3303 range_rect->width = stepper_size * n_steppers + (focus_width + trough_border) * 2 + slider_length;
3304 range_rect->height = (focus_width + trough_border) * 2 + slider_width;
3306 if (n_steppers_ab > 0)
3307 range_rect->width += stepper_spacing;
3309 if (n_steppers_cd > 0)
3310 range_rect->width += stepper_spacing;
3314 *n_steppers_p = n_steppers;
3316 if (has_steppers_ab)
3317 *has_steppers_ab = (n_steppers_ab > 0);
3319 if (has_steppers_cd)
3320 *has_steppers_cd = (n_steppers_cd > 0);
3322 if (slider_length_p)
3323 *slider_length_p = slider_length;
3327 gtk_range_calc_layout (GtkRange *range,
3328 gdouble adjustment_value)
3330 gint slider_width, stepper_size, focus_width, trough_border, stepper_spacing;
3334 gboolean has_steppers_ab;
3335 gboolean has_steppers_cd;
3336 gboolean trough_under_steppers;
3337 GdkRectangle range_rect;
3338 GtkRangeLayout *layout;
3341 if (!range->need_recalc)
3344 /* If we have a too-small allocation, we prefer the steppers over
3345 * the trough/slider, probably the steppers are a more useful
3346 * feature in small spaces.
3348 * Also, we prefer to draw the range itself rather than the border
3349 * areas if there's a conflict, since the borders will be decoration
3350 * not controls. Though this depends on subclasses cooperating by
3351 * not drawing on range->range_rect.
3354 widget = GTK_WIDGET (range);
3355 layout = range->layout;
3357 gtk_range_get_props (range,
3358 &slider_width, &stepper_size,
3359 &focus_width, &trough_border,
3360 &stepper_spacing, &trough_under_steppers,
3363 gtk_range_calc_request (range,
3364 slider_width, stepper_size,
3365 focus_width, trough_border, stepper_spacing,
3366 &range_rect, &border, &n_steppers,
3367 &has_steppers_ab, &has_steppers_cd, &slider_length);
3369 /* We never expand to fill available space in the small dimension
3370 * (i.e. vertical scrollbars are always a fixed width)
3372 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3374 clamp_dimensions (widget, &range_rect, &border, TRUE);
3378 clamp_dimensions (widget, &range_rect, &border, FALSE);
3381 range_rect.x = border.left;
3382 range_rect.y = border.top;
3384 range->range_rect = range_rect;
3386 if (range->orientation == GTK_ORIENTATION_VERTICAL)
3388 gint stepper_width, stepper_height;
3390 /* Steppers are the width of the range, and stepper_size in
3391 * height, or if we don't have enough height, divided equally
3392 * among available space.
3394 stepper_width = range_rect.width - focus_width * 2;
3396 if (trough_under_steppers)
3397 stepper_width -= trough_border * 2;
3399 if (stepper_width < 1)
3400 stepper_width = range_rect.width; /* screw the trough border */
3402 if (n_steppers == 0)
3403 stepper_height = 0; /* avoid divide by n_steppers */
3405 stepper_height = MIN (stepper_size, (range_rect.height / n_steppers));
3409 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3410 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3412 if (range->has_stepper_a)
3414 layout->stepper_a.width = stepper_width;
3415 layout->stepper_a.height = stepper_height;
3419 layout->stepper_a.width = 0;
3420 layout->stepper_a.height = 0;
3425 layout->stepper_b.x = layout->stepper_a.x;
3426 layout->stepper_b.y = layout->stepper_a.y + layout->stepper_a.height;
3428 if (range->has_stepper_b)
3430 layout->stepper_b.width = stepper_width;
3431 layout->stepper_b.height = stepper_height;
3435 layout->stepper_b.width = 0;
3436 layout->stepper_b.height = 0;
3441 if (range->has_stepper_d)
3443 layout->stepper_d.width = stepper_width;
3444 layout->stepper_d.height = stepper_height;
3448 layout->stepper_d.width = 0;
3449 layout->stepper_d.height = 0;
3452 layout->stepper_d.x = layout->stepper_a.x;
3453 layout->stepper_d.y = range_rect.y + range_rect.height - layout->stepper_d.height - focus_width - trough_border * trough_under_steppers;
3457 if (range->has_stepper_c)
3459 layout->stepper_c.width = stepper_width;
3460 layout->stepper_c.height = stepper_height;
3464 layout->stepper_c.width = 0;
3465 layout->stepper_c.height = 0;
3468 layout->stepper_c.x = layout->stepper_a.x;
3469 layout->stepper_c.y = layout->stepper_d.y - layout->stepper_c.height;
3471 /* Now the trough is the remaining space between steppers B and C,
3472 * if any, minus spacing
3474 layout->trough.x = range_rect.x;
3475 layout->trough.y = layout->stepper_b.y + layout->stepper_b.height + stepper_spacing * has_steppers_ab;
3476 layout->trough.width = range_rect.width;
3477 layout->trough.height = layout->stepper_c.y - layout->trough.y - stepper_spacing * has_steppers_cd;
3479 /* Slider fits into the trough, with stepper_spacing on either side,
3480 * and the size/position based on the adjustment or fixed, depending.
3482 layout->slider.x = layout->trough.x + focus_width + trough_border;
3483 layout->slider.width = layout->trough.width - (focus_width + trough_border) * 2;
3485 /* Compute slider position/length */
3487 gint y, bottom, top, height;
3489 top = layout->trough.y;
3490 bottom = layout->trough.y + layout->trough.height;
3492 if (! trough_under_steppers)
3494 top += trough_border;
3495 bottom -= trough_border;
3498 /* slider height is the fraction (page_size /
3499 * total_adjustment_range) times the trough height in pixels
3502 if (range->adjustment->upper - range->adjustment->lower != 0)
3503 height = ((bottom - top) * (range->adjustment->page_size /
3504 (range->adjustment->upper - range->adjustment->lower)));
3506 height = range->min_slider_size;
3508 if (height < range->min_slider_size ||
3509 range->slider_size_fixed)
3510 height = range->min_slider_size;
3512 height = MIN (height, layout->trough.height);
3516 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3517 y += (bottom - top - height) * ((adjustment_value - range->adjustment->lower) /
3518 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3520 y = CLAMP (y, top, bottom);
3522 if (should_invert (range))
3523 y = bottom - (y - top + height);
3525 layout->slider.y = y;
3526 layout->slider.height = height;
3528 /* These are publically exported */
3529 range->slider_start = layout->slider.y;
3530 range->slider_end = layout->slider.y + layout->slider.height;
3535 gint stepper_width, stepper_height;
3537 /* Steppers are the height of the range, and stepper_size in
3538 * width, or if we don't have enough width, divided equally
3539 * among available space.
3541 stepper_height = range_rect.height + focus_width * 2;
3543 if (trough_under_steppers)
3544 stepper_height -= trough_border * 2;
3546 if (stepper_height < 1)
3547 stepper_height = range_rect.height; /* screw the trough border */
3549 if (n_steppers == 0)
3550 stepper_width = 0; /* avoid divide by n_steppers */
3552 stepper_width = MIN (stepper_size, (range_rect.width / n_steppers));
3556 layout->stepper_a.x = range_rect.x + focus_width + trough_border * trough_under_steppers;
3557 layout->stepper_a.y = range_rect.y + focus_width + trough_border * trough_under_steppers;
3559 if (range->has_stepper_a)
3561 layout->stepper_a.width = stepper_width;
3562 layout->stepper_a.height = stepper_height;
3566 layout->stepper_a.width = 0;
3567 layout->stepper_a.height = 0;
3572 layout->stepper_b.x = layout->stepper_a.x + layout->stepper_a.width;
3573 layout->stepper_b.y = layout->stepper_a.y;
3575 if (range->has_stepper_b)
3577 layout->stepper_b.width = stepper_width;
3578 layout->stepper_b.height = stepper_height;
3582 layout->stepper_b.width = 0;
3583 layout->stepper_b.height = 0;
3588 if (range->has_stepper_d)
3590 layout->stepper_d.width = stepper_width;
3591 layout->stepper_d.height = stepper_height;
3595 layout->stepper_d.width = 0;
3596 layout->stepper_d.height = 0;
3599 layout->stepper_d.x = range_rect.x + range_rect.width - layout->stepper_d.width - focus_width - trough_border * trough_under_steppers;
3600 layout->stepper_d.y = layout->stepper_a.y;
3605 if (range->has_stepper_c)
3607 layout->stepper_c.width = stepper_width;
3608 layout->stepper_c.height = stepper_height;
3612 layout->stepper_c.width = 0;
3613 layout->stepper_c.height = 0;
3616 layout->stepper_c.x = layout->stepper_d.x - layout->stepper_c.width;
3617 layout->stepper_c.y = layout->stepper_a.y;
3619 /* Now the trough is the remaining space between steppers B and C,
3622 layout->trough.x = layout->stepper_b.x + layout->stepper_b.width + stepper_spacing * has_steppers_ab;
3623 layout->trough.y = range_rect.y;
3625 layout->trough.width = layout->stepper_c.x - layout->trough.x - stepper_spacing * has_steppers_cd;
3626 layout->trough.height = range_rect.height;
3628 /* Slider fits into the trough, with stepper_spacing on either side,
3629 * and the size/position based on the adjustment or fixed, depending.
3631 layout->slider.y = layout->trough.y + focus_width + trough_border;
3632 layout->slider.height = layout->trough.height - (focus_width + trough_border) * 2;
3634 /* Compute slider position/length */
3636 gint x, left, right, width;
3638 left = layout->trough.x;
3639 right = layout->trough.x + layout->trough.width;
3641 if (! trough_under_steppers)
3643 left += trough_border;
3644 right -= trough_border;
3647 /* slider width is the fraction (page_size /
3648 * total_adjustment_range) times the trough width in pixels
3651 if (range->adjustment->upper - range->adjustment->lower != 0)
3652 width = ((right - left) * (range->adjustment->page_size /
3653 (range->adjustment->upper - range->adjustment->lower)));
3655 width = range->min_slider_size;
3657 if (width < range->min_slider_size ||
3658 range->slider_size_fixed)
3659 width = range->min_slider_size;
3661 width = MIN (width, layout->trough.width);
3665 if (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size != 0)
3666 x += (right - left - width) * ((adjustment_value - range->adjustment->lower) /
3667 (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size));
3669 x = CLAMP (x, left, right);
3671 if (should_invert (range))
3672 x = right - (x - left + width);
3674 layout->slider.x = x;
3675 layout->slider.width = width;
3677 /* These are publically exported */
3678 range->slider_start = layout->slider.x;
3679 range->slider_end = layout->slider.x + layout->slider.width;
3683 gtk_range_update_mouse_location (range);
3685 switch (range->layout->upper_sensitivity)
3687 case GTK_SENSITIVITY_AUTO:
3688 range->layout->upper_sensitive =
3689 (range->adjustment->value <
3690 (range->adjustment->upper - range->adjustment->page_size));
3693 case GTK_SENSITIVITY_ON:
3694 range->layout->upper_sensitive = TRUE;
3697 case GTK_SENSITIVITY_OFF:
3698 range->layout->upper_sensitive = FALSE;
3702 switch (range->layout->lower_sensitivity)
3704 case GTK_SENSITIVITY_AUTO:
3705 range->layout->lower_sensitive =
3706 (range->adjustment->value > range->adjustment->lower);
3709 case GTK_SENSITIVITY_ON:
3710 range->layout->lower_sensitive = TRUE;
3713 case GTK_SENSITIVITY_OFF:
3714 range->layout->lower_sensitive = FALSE;
3719 static GdkRectangle*
3720 get_area (GtkRange *range,
3721 MouseLocation location)
3725 case MOUSE_STEPPER_A:
3726 return &range->layout->stepper_a;
3727 case MOUSE_STEPPER_B:
3728 return &range->layout->stepper_b;
3729 case MOUSE_STEPPER_C:
3730 return &range->layout->stepper_c;
3731 case MOUSE_STEPPER_D:
3732 return &range->layout->stepper_d;
3734 return &range->layout->trough;
3736 return &range->layout->slider;
3742 g_warning (G_STRLOC": bug");
3747 gtk_range_calc_marks (GtkRange *range)
3751 if (!range->layout->recalc_marks)
3754 range->layout->recalc_marks = FALSE;
3756 for (i = 0; i < range->layout->n_marks; i++)
3758 range->need_recalc = TRUE;
3759 gtk_range_calc_layout (range, range->layout->marks[i]);
3760 if (range->orientation == GTK_ORIENTATION_HORIZONTAL)
3761 range->layout->mark_pos[i] = range->layout->slider.x + range->layout->slider.width / 2;
3763 range->layout->mark_pos[i] = range->layout->slider.y + range->layout->slider.height / 2;
3766 range->need_recalc = TRUE;
3770 gtk_range_real_change_value (GtkRange *range,
3771 GtkScrollType scroll,
3774 /* potentially adjust the bounds _before_ we clamp */
3775 g_signal_emit (range, signals[ADJUST_BOUNDS], 0, value);
3777 if (range->layout->restrict_to_fill_level)
3778 value = MIN (value, MAX (range->adjustment->lower,
3779 range->layout->fill_level));
3781 value = CLAMP (value, range->adjustment->lower,
3782 (range->adjustment->upper - range->adjustment->page_size));
3784 if (range->round_digits >= 0)
3789 i = range->round_digits;
3794 value = floor ((value * power) + 0.5) / power;
3797 if (range->adjustment->value != value)
3799 range->need_recalc = TRUE;
3801 gtk_widget_queue_draw (GTK_WIDGET (range));
3803 switch (range->update_policy)
3805 case GTK_UPDATE_CONTINUOUS:
3806 gtk_adjustment_set_value (range->adjustment, value);
3809 /* Delayed means we update after a period of inactivity */
3810 case GTK_UPDATE_DELAYED:
3811 gtk_range_reset_update_timer (range);
3814 /* Discontinuous means we update on button release */
3815 case GTK_UPDATE_DISCONTINUOUS:
3816 /* don't emit value_changed signal */
3817 range->adjustment->value = value;
3818 range->update_pending = TRUE;
3826 gtk_range_update_value (GtkRange *range)
3828 gtk_range_remove_update_timer (range);
3830 if (range->update_pending)
3832 gtk_adjustment_value_changed (range->adjustment);
3834 range->update_pending = FALSE;
3838 struct _GtkRangeStepTimer
3845 second_timeout (gpointer data)
3849 range = GTK_RANGE (data);
3850 gtk_range_scroll (range, range->timer->step);
3856 initial_timeout (gpointer data)
3859 GtkSettings *settings;
3862 settings = gtk_widget_get_settings (GTK_WIDGET (data));
3863 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
3865 range = GTK_RANGE (data);
3866 range->timer->timeout_id = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
3874 gtk_range_add_step_timer (GtkRange *range,
3877 GtkSettings *settings;
3880 g_return_if_fail (range->timer == NULL);
3881 g_return_if_fail (step != GTK_SCROLL_NONE);
3883 settings = gtk_widget_get_settings (GTK_WIDGET (range));
3884 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
3886 range->timer = g_new (GtkRangeStepTimer, 1);
3888 range->timer->timeout_id = gdk_threads_add_timeout (timeout,
3891 range->timer->step = step;
3893 gtk_range_scroll (range, range->timer->step);
3897 gtk_range_remove_step_timer (GtkRange *range)
3901 if (range->timer->timeout_id != 0)
3902 g_source_remove (range->timer->timeout_id);
3904 g_free (range->timer);
3906 range->timer = NULL;
3911 update_timeout (gpointer data)
3915 range = GTK_RANGE (data);
3916 gtk_range_update_value (range);
3917 range->update_timeout_id = 0;
3924 gtk_range_reset_update_timer (GtkRange *range)
3926 gtk_range_remove_update_timer (range);
3928 range->update_timeout_id = gdk_threads_add_timeout (UPDATE_DELAY,
3934 gtk_range_remove_update_timer (GtkRange *range)
3936 if (range->update_timeout_id != 0)
3938 g_source_remove (range->update_timeout_id);
3939 range->update_timeout_id = 0;
3944 _gtk_range_set_stop_values (GtkRange *range,
3950 g_free (range->layout->marks);
3951 range->layout->marks = g_new (gdouble, n_values);
3953 g_free (range->layout->mark_pos);
3954 range->layout->mark_pos = g_new (gint, n_values);
3956 range->layout->n_marks = n_values;
3958 for (i = 0; i < n_values; i++)
3959 range->layout->marks[i] = values[i];
3961 range->layout->recalc_marks = TRUE;
3965 _gtk_range_get_stop_positions (GtkRange *range,
3968 gtk_range_calc_marks (range);
3971 *values = g_memdup (range->layout->mark_pos, range->layout->n_marks * sizeof (gint));
3973 return range->layout->n_marks;