File: | ctk/ctkrange.c |
Warning: | line 3108, column 21 2nd function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* CTK - The GIMP Toolkit | |||
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald | |||
3 | * Copyright (C) 2001 Red Hat, Inc. | |||
4 | * | |||
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. | |||
9 | * | |||
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. | |||
14 | * | |||
15 | * You should have received a copy of the GNU Lesser General Public | |||
16 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
17 | */ | |||
18 | ||||
19 | /* | |||
20 | * Modified by the CTK+ Team and others 1997-2004. See the AUTHORS | |||
21 | * file for a list of people on the CTK+ Team. See the ChangeLog | |||
22 | * files for a list of changes. These files are distributed with | |||
23 | * CTK+ at ftp://ftp.ctk.org/pub/ctk/. | |||
24 | */ | |||
25 | ||||
26 | #include "config.h" | |||
27 | ||||
28 | #include <stdio.h> | |||
29 | #include <math.h> | |||
30 | ||||
31 | #include "ctkrange.h" | |||
32 | #include "ctkrangeprivate.h" | |||
33 | ||||
34 | #include "ctkadjustmentprivate.h" | |||
35 | #include "ctkboxgadgetprivate.h" | |||
36 | #include "ctkbuiltiniconprivate.h" | |||
37 | #include "ctkcsscustomgadgetprivate.h" | |||
38 | #include "ctkcolorscaleprivate.h" | |||
39 | #include "ctkintl.h" | |||
40 | #include "ctkgesturelongpressprivate.h" | |||
41 | #include "ctkmain.h" | |||
42 | #include "ctkmarshalers.h" | |||
43 | #include "ctkorientableprivate.h" | |||
44 | #include "ctkprivate.h" | |||
45 | #include "ctkscale.h" | |||
46 | #include "ctkscrollbar.h" | |||
47 | #include "ctktypebuiltins.h" | |||
48 | #include "ctkwindow.h" | |||
49 | #include "ctkwidgetprivate.h" | |||
50 | #include "a11y/ctkrangeaccessible.h" | |||
51 | #include "ctkcssstylepropertyprivate.h" | |||
52 | ||||
53 | /** | |||
54 | * SECTION:ctkrange | |||
55 | * @Short_description: Base class for widgets which visualize an adjustment | |||
56 | * @Title: CtkRange | |||
57 | * | |||
58 | * #CtkRange is the common base class for widgets which visualize an | |||
59 | * adjustment, e.g #CtkScale or #CtkScrollbar. | |||
60 | * | |||
61 | * Apart from signals for monitoring the parameters of the adjustment, | |||
62 | * #CtkRange provides properties and methods for influencing the sensitivity | |||
63 | * of the “steppers”. It also provides properties and methods for setting a | |||
64 | * “fill level” on range widgets. See ctk_range_set_fill_level(). | |||
65 | */ | |||
66 | ||||
67 | ||||
68 | #define TIMEOUT_INITIAL500 500 | |||
69 | #define TIMEOUT_REPEAT250 250 | |||
70 | #define AUTOSCROLL_FACTOR20 20 | |||
71 | #define SCROLL_EDGE_SIZE15 15 | |||
72 | #define MARK_SNAP_LENGTH12 12 | |||
73 | ||||
74 | typedef struct _CtkRangeStepTimer CtkRangeStepTimer; | |||
75 | ||||
76 | struct _CtkRangePrivate | |||
77 | { | |||
78 | CtkCssGadget *mouse_location; | |||
79 | /* last mouse coords we got, or G_MININT if mouse is outside the range */ | |||
80 | gint mouse_x; | |||
81 | gint mouse_y; | |||
82 | CtkCssGadget *grab_location; /* "grabbed" mouse location, NULL for no grab */ | |||
83 | ||||
84 | CtkRangeStepTimer *timer; | |||
85 | ||||
86 | CtkAdjustment *adjustment; | |||
87 | CtkSensitivityType lower_sensitivity; | |||
88 | CtkSensitivityType upper_sensitivity; | |||
89 | ||||
90 | CdkWindow *event_window; | |||
91 | ||||
92 | /* Steppers are: < > ---- < > | |||
93 | * a b c d | |||
94 | */ | |||
95 | CtkCssGadget *gadget; | |||
96 | CtkCssGadget *contents_gadget; | |||
97 | CtkCssGadget *stepper_a_gadget; | |||
98 | CtkCssGadget *stepper_b_gadget; | |||
99 | CtkCssGadget *stepper_c_gadget; | |||
100 | CtkCssGadget *stepper_d_gadget; | |||
101 | CtkCssGadget *trough_gadget; | |||
102 | CtkCssGadget *fill_gadget; | |||
103 | CtkCssGadget *highlight_gadget; | |||
104 | CtkCssGadget *slider_gadget; | |||
105 | ||||
106 | CtkOrientation orientation; | |||
107 | ||||
108 | gdouble fill_level; | |||
109 | gdouble *marks; | |||
110 | ||||
111 | gint *mark_pos; | |||
112 | gint min_slider_size; | |||
113 | gint n_marks; | |||
114 | gint round_digits; /* Round off value to this many digits, -1 for no rounding */ | |||
115 | gint slide_initial_slider_position; | |||
116 | gint slide_initial_coordinate_delta; | |||
117 | ||||
118 | guint flippable : 1; | |||
119 | guint inverted : 1; | |||
120 | guint slider_size_fixed : 1; | |||
121 | guint slider_use_min_size : 1; | |||
122 | guint trough_click_forward : 1; /* trough click was on the forward side of slider */ | |||
123 | ||||
124 | /* Stepper sensitivity */ | |||
125 | guint lower_sensitive : 1; | |||
126 | guint upper_sensitive : 1; | |||
127 | ||||
128 | /* The range has an origin, should be drawn differently. Used by CtkScale */ | |||
129 | guint has_origin : 1; | |||
130 | ||||
131 | /* Whether we're doing fine adjustment */ | |||
132 | guint zoom : 1; | |||
133 | ||||
134 | /* Fill level */ | |||
135 | guint show_fill_level : 1; | |||
136 | guint restrict_to_fill_level : 1; | |||
137 | ||||
138 | /* Whether dragging is ongoing */ | |||
139 | guint in_drag : 1; | |||
140 | ||||
141 | CtkGesture *long_press_gesture; | |||
142 | CtkGesture *multipress_gesture; | |||
143 | CtkGesture *drag_gesture; | |||
144 | ||||
145 | CtkScrollType autoscroll_mode; | |||
146 | guint autoscroll_id; | |||
147 | }; | |||
148 | ||||
149 | ||||
150 | enum { | |||
151 | PROP_0, | |||
152 | PROP_ADJUSTMENT, | |||
153 | PROP_INVERTED, | |||
154 | PROP_LOWER_STEPPER_SENSITIVITY, | |||
155 | PROP_UPPER_STEPPER_SENSITIVITY, | |||
156 | PROP_SHOW_FILL_LEVEL, | |||
157 | PROP_RESTRICT_TO_FILL_LEVEL, | |||
158 | PROP_FILL_LEVEL, | |||
159 | PROP_ROUND_DIGITS, | |||
160 | PROP_ORIENTATION, | |||
161 | LAST_PROP = PROP_ORIENTATION | |||
162 | }; | |||
163 | ||||
164 | enum { | |||
165 | VALUE_CHANGED, | |||
166 | ADJUST_BOUNDS, | |||
167 | MOVE_SLIDER, | |||
168 | CHANGE_VALUE, | |||
169 | LAST_SIGNAL | |||
170 | }; | |||
171 | ||||
172 | static void ctk_range_set_property (GObject *object, | |||
173 | guint prop_id, | |||
174 | const GValue *value, | |||
175 | GParamSpec *pspec); | |||
176 | static void ctk_range_get_property (GObject *object, | |||
177 | guint prop_id, | |||
178 | GValue *value, | |||
179 | GParamSpec *pspec); | |||
180 | static void ctk_range_finalize (GObject *object); | |||
181 | static void ctk_range_destroy (CtkWidget *widget); | |||
182 | static void ctk_range_get_preferred_width | |||
183 | (CtkWidget *widget, | |||
184 | gint *minimum, | |||
185 | gint *natural); | |||
186 | static void ctk_range_get_preferred_height | |||
187 | (CtkWidget *widget, | |||
188 | gint *minimum, | |||
189 | gint *natural); | |||
190 | static void ctk_range_size_allocate (CtkWidget *widget, | |||
191 | CtkAllocation *allocation); | |||
192 | static void ctk_range_realize (CtkWidget *widget); | |||
193 | static void ctk_range_unrealize (CtkWidget *widget); | |||
194 | static void ctk_range_map (CtkWidget *widget); | |||
195 | static void ctk_range_unmap (CtkWidget *widget); | |||
196 | static gboolean ctk_range_draw (CtkWidget *widget, | |||
197 | cairo_t *cr); | |||
198 | ||||
199 | static void ctk_range_multipress_gesture_pressed (CtkGestureMultiPress *gesture, | |||
200 | guint n_press, | |||
201 | gdouble x, | |||
202 | gdouble y, | |||
203 | CtkRange *range); | |||
204 | static void ctk_range_multipress_gesture_released (CtkGestureMultiPress *gesture, | |||
205 | guint n_press, | |||
206 | gdouble x, | |||
207 | gdouble y, | |||
208 | CtkRange *range); | |||
209 | static void ctk_range_drag_gesture_begin (CtkGestureDrag *gesture, | |||
210 | gdouble offset_x, | |||
211 | gdouble offset_y, | |||
212 | CtkRange *range); | |||
213 | static void ctk_range_drag_gesture_update (CtkGestureDrag *gesture, | |||
214 | gdouble offset_x, | |||
215 | gdouble offset_y, | |||
216 | CtkRange *range); | |||
217 | static void ctk_range_long_press_gesture_pressed (CtkGestureLongPress *gesture, | |||
218 | gdouble x, | |||
219 | gdouble y, | |||
220 | CtkRange *range); | |||
221 | ||||
222 | ||||
223 | static gboolean ctk_range_scroll_event (CtkWidget *widget, | |||
224 | CdkEventScroll *event); | |||
225 | static gboolean ctk_range_event (CtkWidget *widget, | |||
226 | CdkEvent *event); | |||
227 | static void update_slider_position (CtkRange *range, | |||
228 | gint mouse_x, | |||
229 | gint mouse_y); | |||
230 | static void stop_scrolling (CtkRange *range); | |||
231 | static void add_autoscroll (CtkRange *range); | |||
232 | static void remove_autoscroll (CtkRange *range); | |||
233 | ||||
234 | /* Range methods */ | |||
235 | ||||
236 | static void ctk_range_move_slider (CtkRange *range, | |||
237 | CtkScrollType scroll); | |||
238 | ||||
239 | /* Internals */ | |||
240 | static void ctk_range_compute_slider_position (CtkRange *range, | |||
241 | gdouble adjustment_value, | |||
242 | CdkRectangle *slider_rect); | |||
243 | static gboolean ctk_range_scroll (CtkRange *range, | |||
244 | CtkScrollType scroll); | |||
245 | static void ctk_range_update_mouse_location (CtkRange *range); | |||
246 | static void ctk_range_calc_slider (CtkRange *range); | |||
247 | static void ctk_range_calc_stepper_sensitivity (CtkRange *range); | |||
248 | static void ctk_range_calc_marks (CtkRange *range); | |||
249 | static void ctk_range_adjustment_value_changed (CtkAdjustment *adjustment, | |||
250 | gpointer data); | |||
251 | static void ctk_range_adjustment_changed (CtkAdjustment *adjustment, | |||
252 | gpointer data); | |||
253 | static void ctk_range_add_step_timer (CtkRange *range, | |||
254 | CtkScrollType step); | |||
255 | static void ctk_range_remove_step_timer (CtkRange *range); | |||
256 | static gboolean ctk_range_real_change_value (CtkRange *range, | |||
257 | CtkScrollType scroll, | |||
258 | gdouble value); | |||
259 | static gboolean ctk_range_key_press (CtkWidget *range, | |||
260 | CdkEventKey *event); | |||
261 | static void ctk_range_state_flags_changed (CtkWidget *widget, | |||
262 | CtkStateFlags previous_state); | |||
263 | static void ctk_range_direction_changed (CtkWidget *widget, | |||
264 | CtkTextDirection previous_direction); | |||
265 | static void ctk_range_measure_trough (CtkCssGadget *gadget, | |||
266 | CtkOrientation orientation, | |||
267 | gint for_size, | |||
268 | gint *minimum, | |||
269 | gint *natural, | |||
270 | gint *minimum_baseline, | |||
271 | gint *natural_baseline, | |||
272 | gpointer user_data); | |||
273 | static void ctk_range_allocate_trough (CtkCssGadget *gadget, | |||
274 | const CtkAllocation *allocation, | |||
275 | int baseline, | |||
276 | CtkAllocation *out_clip, | |||
277 | gpointer data); | |||
278 | static gboolean ctk_range_render_trough (CtkCssGadget *gadget, | |||
279 | cairo_t *cr, | |||
280 | int x, | |||
281 | int y, | |||
282 | int width, | |||
283 | int height, | |||
284 | gpointer user_data); | |||
285 | static void ctk_range_measure (CtkCssGadget *gadget, | |||
286 | CtkOrientation orientation, | |||
287 | gint for_size, | |||
288 | gint *minimum, | |||
289 | gint *natural, | |||
290 | gint *minimum_baseline, | |||
291 | gint *natural_baseline, | |||
292 | gpointer user_data); | |||
293 | static void ctk_range_allocate (CtkCssGadget *gadget, | |||
294 | const CtkAllocation *allocation, | |||
295 | int baseline, | |||
296 | CtkAllocation *out_clip, | |||
297 | gpointer data); | |||
298 | static gboolean ctk_range_render (CtkCssGadget *gadget, | |||
299 | cairo_t *cr, | |||
300 | int x, | |||
301 | int y, | |||
302 | int width, | |||
303 | int height, | |||
304 | gpointer user_data); | |||
305 | ||||
306 | G_DEFINE_ABSTRACT_TYPE_WITH_CODE (CtkRange, ctk_range, CTK_TYPE_WIDGET,static void ctk_range_init (CtkRange *self); static void ctk_range_class_init (CtkRangeClass *klass); static GType ctk_range_get_type_once (void); static gpointer ctk_range_parent_class = ((void*)0); static gint CtkRange_private_offset; static void ctk_range_class_intern_init (gpointer klass) { ctk_range_parent_class = g_type_class_peek_parent (klass); if (CtkRange_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkRange_private_offset); ctk_range_class_init ( (CtkRangeClass*) klass); } __attribute__ ((__unused__)) static inline gpointer ctk_range_get_instance_private (CtkRange *self ) { return (((gpointer) ((guint8*) (self) + (glong) (CtkRange_private_offset )))); } GType ctk_range_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); (void ) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*) 0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_range_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_range_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((ctk_widget_get_type ()), g_intern_static_string ("CtkRange"), sizeof (CtkRangeClass ), (GClassInitFunc)(void (*)(void)) ctk_range_class_intern_init , sizeof (CtkRange), (GInstanceInitFunc)(void (*)(void)) ctk_range_init , (GTypeFlags) G_TYPE_FLAG_ABSTRACT); { {{ CtkRange_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkRangePrivate )); } { const GInterfaceInfo g_implement_interface_info = { ( GInterfaceInitFunc)(void (*)(void)) ((void*)0), ((void*)0), ( (void*)0) }; g_type_add_interface_static (g_define_type_id, ( ctk_orientable_get_type ()), &g_implement_interface_info) ; };} } return g_define_type_id; } | |||
307 | G_ADD_PRIVATE (CtkRange)static void ctk_range_init (CtkRange *self); static void ctk_range_class_init (CtkRangeClass *klass); static GType ctk_range_get_type_once (void); static gpointer ctk_range_parent_class = ((void*)0); static gint CtkRange_private_offset; static void ctk_range_class_intern_init (gpointer klass) { ctk_range_parent_class = g_type_class_peek_parent (klass); if (CtkRange_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkRange_private_offset); ctk_range_class_init ( (CtkRangeClass*) klass); } __attribute__ ((__unused__)) static inline gpointer ctk_range_get_instance_private (CtkRange *self ) { return (((gpointer) ((guint8*) (self) + (glong) (CtkRange_private_offset )))); } GType ctk_range_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); (void ) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*) 0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_range_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_range_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((ctk_widget_get_type ()), g_intern_static_string ("CtkRange"), sizeof (CtkRangeClass ), (GClassInitFunc)(void (*)(void)) ctk_range_class_intern_init , sizeof (CtkRange), (GInstanceInitFunc)(void (*)(void)) ctk_range_init , (GTypeFlags) G_TYPE_FLAG_ABSTRACT); { {{ CtkRange_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkRangePrivate )); } { const GInterfaceInfo g_implement_interface_info = { ( GInterfaceInitFunc)(void (*)(void)) ((void*)0), ((void*)0), ( (void*)0) }; g_type_add_interface_static (g_define_type_id, ( ctk_orientable_get_type ()), &g_implement_interface_info) ; };} } return g_define_type_id; } | |||
308 | G_IMPLEMENT_INTERFACE (CTK_TYPE_ORIENTABLE,static void ctk_range_init (CtkRange *self); static void ctk_range_class_init (CtkRangeClass *klass); static GType ctk_range_get_type_once (void); static gpointer ctk_range_parent_class = ((void*)0); static gint CtkRange_private_offset; static void ctk_range_class_intern_init (gpointer klass) { ctk_range_parent_class = g_type_class_peek_parent (klass); if (CtkRange_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkRange_private_offset); ctk_range_class_init ( (CtkRangeClass*) klass); } __attribute__ ((__unused__)) static inline gpointer ctk_range_get_instance_private (CtkRange *self ) { return (((gpointer) ((guint8*) (self) + (glong) (CtkRange_private_offset )))); } GType ctk_range_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); (void ) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*) 0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_range_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_range_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((ctk_widget_get_type ()), g_intern_static_string ("CtkRange"), sizeof (CtkRangeClass ), (GClassInitFunc)(void (*)(void)) ctk_range_class_intern_init , sizeof (CtkRange), (GInstanceInitFunc)(void (*)(void)) ctk_range_init , (GTypeFlags) G_TYPE_FLAG_ABSTRACT); { {{ CtkRange_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkRangePrivate )); } { const GInterfaceInfo g_implement_interface_info = { ( GInterfaceInitFunc)(void (*)(void)) ((void*)0), ((void*)0), ( (void*)0) }; g_type_add_interface_static (g_define_type_id, ( ctk_orientable_get_type ()), &g_implement_interface_info) ; };} } return g_define_type_id; } | |||
309 | NULL))static void ctk_range_init (CtkRange *self); static void ctk_range_class_init (CtkRangeClass *klass); static GType ctk_range_get_type_once (void); static gpointer ctk_range_parent_class = ((void*)0); static gint CtkRange_private_offset; static void ctk_range_class_intern_init (gpointer klass) { ctk_range_parent_class = g_type_class_peek_parent (klass); if (CtkRange_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkRange_private_offset); ctk_range_class_init ( (CtkRangeClass*) klass); } __attribute__ ((__unused__)) static inline gpointer ctk_range_get_instance_private (CtkRange *self ) { return (((gpointer) ((guint8*) (self) + (glong) (CtkRange_private_offset )))); } GType ctk_range_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); (void ) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*) 0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_range_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_range_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((ctk_widget_get_type ()), g_intern_static_string ("CtkRange"), sizeof (CtkRangeClass ), (GClassInitFunc)(void (*)(void)) ctk_range_class_intern_init , sizeof (CtkRange), (GInstanceInitFunc)(void (*)(void)) ctk_range_init , (GTypeFlags) G_TYPE_FLAG_ABSTRACT); { {{ CtkRange_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkRangePrivate )); } { const GInterfaceInfo g_implement_interface_info = { ( GInterfaceInitFunc)(void (*)(void)) ((void*)0), ((void*)0), ( (void*)0) }; g_type_add_interface_static (g_define_type_id, ( ctk_orientable_get_type ()), &g_implement_interface_info) ; };} } return g_define_type_id; } | |||
310 | ||||
311 | static guint signals[LAST_SIGNAL]; | |||
312 | static GParamSpec *properties[LAST_PROP]; | |||
313 | ||||
314 | static void | |||
315 | ctk_range_class_init (CtkRangeClass *class) | |||
316 | { | |||
317 | GObjectClass *gobject_class; | |||
318 | CtkWidgetClass *widget_class; | |||
319 | ||||
320 | gobject_class = G_OBJECT_CLASS (class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((class)), (((GType) ((20) << (2)))))))); | |||
321 | widget_class = (CtkWidgetClass*) class; | |||
322 | ||||
323 | gobject_class->set_property = ctk_range_set_property; | |||
324 | gobject_class->get_property = ctk_range_get_property; | |||
325 | gobject_class->finalize = ctk_range_finalize; | |||
326 | ||||
327 | widget_class->destroy = ctk_range_destroy; | |||
328 | widget_class->get_preferred_width = ctk_range_get_preferred_width; | |||
329 | widget_class->get_preferred_height = ctk_range_get_preferred_height; | |||
330 | widget_class->size_allocate = ctk_range_size_allocate; | |||
331 | widget_class->realize = ctk_range_realize; | |||
332 | widget_class->unrealize = ctk_range_unrealize; | |||
333 | widget_class->map = ctk_range_map; | |||
334 | widget_class->unmap = ctk_range_unmap; | |||
335 | widget_class->draw = ctk_range_draw; | |||
336 | widget_class->event = ctk_range_event; | |||
337 | widget_class->scroll_event = ctk_range_scroll_event; | |||
338 | widget_class->key_press_event = ctk_range_key_press; | |||
339 | widget_class->state_flags_changed = ctk_range_state_flags_changed; | |||
340 | widget_class->direction_changed = ctk_range_direction_changed; | |||
341 | ||||
342 | class->move_slider = ctk_range_move_slider; | |||
343 | class->change_value = ctk_range_real_change_value; | |||
344 | ||||
345 | /** | |||
346 | * CtkRange::value-changed: | |||
347 | * @range: the #CtkRange that received the signal | |||
348 | * | |||
349 | * Emitted when the range value changes. | |||
350 | */ | |||
351 | signals[VALUE_CHANGED] = | |||
352 | g_signal_new (I_("value-changed")g_intern_static_string ("value-changed"), | |||
353 | G_TYPE_FROM_CLASS (gobject_class)(((GTypeClass*) (gobject_class))->g_type), | |||
354 | G_SIGNAL_RUN_LAST, | |||
355 | G_STRUCT_OFFSET (CtkRangeClass, value_changed)((glong) __builtin_offsetof(CtkRangeClass, value_changed)), | |||
356 | NULL((void*)0), NULL((void*)0), | |||
357 | NULL((void*)0), | |||
358 | G_TYPE_NONE((GType) ((1) << (2))), 0); | |||
359 | ||||
360 | /** | |||
361 | * CtkRange::adjust-bounds: | |||
362 | * @range: the #CtkRange that received the signal | |||
363 | * @value: the value before we clamp | |||
364 | * | |||
365 | * Emitted before clamping a value, to give the application a | |||
366 | * chance to adjust the bounds. | |||
367 | */ | |||
368 | signals[ADJUST_BOUNDS] = | |||
369 | g_signal_new (I_("adjust-bounds")g_intern_static_string ("adjust-bounds"), | |||
370 | G_TYPE_FROM_CLASS (gobject_class)(((GTypeClass*) (gobject_class))->g_type), | |||
371 | G_SIGNAL_RUN_LAST, | |||
372 | G_STRUCT_OFFSET (CtkRangeClass, adjust_bounds)((glong) __builtin_offsetof(CtkRangeClass, adjust_bounds)), | |||
373 | NULL((void*)0), NULL((void*)0), | |||
374 | NULL((void*)0), | |||
375 | G_TYPE_NONE((GType) ((1) << (2))), 1, | |||
376 | G_TYPE_DOUBLE((GType) ((15) << (2)))); | |||
377 | ||||
378 | /** | |||
379 | * CtkRange::move-slider: | |||
380 | * @range: the #CtkRange that received the signal | |||
381 | * @step: how to move the slider | |||
382 | * | |||
383 | * Virtual function that moves the slider. Used for keybindings. | |||
384 | */ | |||
385 | signals[MOVE_SLIDER] = | |||
386 | g_signal_new (I_("move-slider")g_intern_static_string ("move-slider"), | |||
387 | G_TYPE_FROM_CLASS (gobject_class)(((GTypeClass*) (gobject_class))->g_type), | |||
388 | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, | |||
389 | G_STRUCT_OFFSET (CtkRangeClass, move_slider)((glong) __builtin_offsetof(CtkRangeClass, move_slider)), | |||
390 | NULL((void*)0), NULL((void*)0), | |||
391 | NULL((void*)0), | |||
392 | G_TYPE_NONE((GType) ((1) << (2))), 1, | |||
393 | CTK_TYPE_SCROLL_TYPE(ctk_scroll_type_get_type ())); | |||
394 | ||||
395 | /** | |||
396 | * CtkRange::change-value: | |||
397 | * @range: the #CtkRange that received the signal | |||
398 | * @scroll: the type of scroll action that was performed | |||
399 | * @value: the new value resulting from the scroll action | |||
400 | * | |||
401 | * The #CtkRange::change-value signal is emitted when a scroll action is | |||
402 | * performed on a range. It allows an application to determine the | |||
403 | * type of scroll event that occurred and the resultant new value. | |||
404 | * The application can handle the event itself and return %TRUE to | |||
405 | * prevent further processing. Or, by returning %FALSE, it can pass | |||
406 | * the event to other handlers until the default CTK+ handler is | |||
407 | * reached. | |||
408 | * | |||
409 | * The value parameter is unrounded. An application that overrides | |||
410 | * the CtkRange::change-value signal is responsible for clamping the | |||
411 | * value to the desired number of decimal digits; the default CTK+ | |||
412 | * handler clamps the value based on #CtkRange:round-digits. | |||
413 | * | |||
414 | * Returns: %TRUE to prevent other handlers from being invoked for | |||
415 | * the signal, %FALSE to propagate the signal further | |||
416 | * | |||
417 | * Since: 2.6 | |||
418 | */ | |||
419 | signals[CHANGE_VALUE] = | |||
420 | g_signal_new (I_("change-value")g_intern_static_string ("change-value"), | |||
421 | G_TYPE_FROM_CLASS (gobject_class)(((GTypeClass*) (gobject_class))->g_type), | |||
422 | G_SIGNAL_RUN_LAST, | |||
423 | G_STRUCT_OFFSET (CtkRangeClass, change_value)((glong) __builtin_offsetof(CtkRangeClass, change_value)), | |||
424 | _ctk_boolean_handled_accumulator, NULL((void*)0), | |||
425 | _ctk_marshal_BOOLEAN__ENUM_DOUBLE, | |||
426 | G_TYPE_BOOLEAN((GType) ((5) << (2))), 2, | |||
427 | CTK_TYPE_SCROLL_TYPE(ctk_scroll_type_get_type ()), | |||
428 | G_TYPE_DOUBLE((GType) ((15) << (2)))); | |||
429 | ||||
430 | g_object_class_override_property (gobject_class, PROP_ORIENTATION, "orientation"); | |||
431 | ||||
432 | properties[PROP_ADJUSTMENT] = | |||
433 | g_param_spec_object ("adjustment", | |||
434 | P_("Adjustment")g_dgettext("ctk30" "-properties","Adjustment"), | |||
435 | P_("The CtkAdjustment that contains the current value of this range object")g_dgettext("ctk30" "-properties","The CtkAdjustment that contains the current value of this range object" ), | |||
436 | CTK_TYPE_ADJUSTMENT(ctk_adjustment_get_type ()), | |||
437 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_CONSTRUCT); | |||
438 | ||||
439 | properties[PROP_INVERTED] = | |||
440 | g_param_spec_boolean ("inverted", | |||
441 | P_("Inverted")g_dgettext("ctk30" "-properties","Inverted"), | |||
442 | P_("Invert direction slider moves to increase range value")g_dgettext("ctk30" "-properties","Invert direction slider moves to increase range value" ), | |||
443 | FALSE(0), | |||
444 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_EXPLICIT_NOTIFY); | |||
445 | ||||
446 | properties[PROP_LOWER_STEPPER_SENSITIVITY] = | |||
447 | g_param_spec_enum ("lower-stepper-sensitivity", | |||
448 | P_("Lower stepper sensitivity")g_dgettext("ctk30" "-properties","Lower stepper sensitivity"), | |||
449 | P_("The sensitivity policy for the stepper that points to the adjustment's lower side")g_dgettext("ctk30" "-properties","The sensitivity policy for the stepper that points to the adjustment's lower side" ), | |||
450 | CTK_TYPE_SENSITIVITY_TYPE(ctk_sensitivity_type_get_type ()), | |||
451 | CTK_SENSITIVITY_AUTO, | |||
452 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_DEPRECATED); | |||
453 | ||||
454 | properties[PROP_UPPER_STEPPER_SENSITIVITY] = | |||
455 | g_param_spec_enum ("upper-stepper-sensitivity", | |||
456 | P_("Upper stepper sensitivity")g_dgettext("ctk30" "-properties","Upper stepper sensitivity"), | |||
457 | P_("The sensitivity policy for the stepper that points to the adjustment's upper side")g_dgettext("ctk30" "-properties","The sensitivity policy for the stepper that points to the adjustment's upper side" ), | |||
458 | CTK_TYPE_SENSITIVITY_TYPE(ctk_sensitivity_type_get_type ()), | |||
459 | CTK_SENSITIVITY_AUTO, | |||
460 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_DEPRECATED); | |||
461 | ||||
462 | /** | |||
463 | * CtkRange:show-fill-level: | |||
464 | * | |||
465 | * The show-fill-level property controls whether fill level indicator | |||
466 | * graphics are displayed on the trough. See | |||
467 | * ctk_range_set_show_fill_level(). | |||
468 | * | |||
469 | * Since: 2.12 | |||
470 | **/ | |||
471 | properties[PROP_SHOW_FILL_LEVEL] = | |||
472 | g_param_spec_boolean ("show-fill-level", | |||
473 | P_("Show Fill Level")g_dgettext("ctk30" "-properties","Show Fill Level"), | |||
474 | P_("Whether to display a fill level indicator graphics on trough.")g_dgettext("ctk30" "-properties","Whether to display a fill level indicator graphics on trough." ), | |||
475 | FALSE(0), | |||
476 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_EXPLICIT_NOTIFY); | |||
477 | ||||
478 | /** | |||
479 | * CtkRange:restrict-to-fill-level: | |||
480 | * | |||
481 | * The restrict-to-fill-level property controls whether slider | |||
482 | * movement is restricted to an upper boundary set by the | |||
483 | * fill level. See ctk_range_set_restrict_to_fill_level(). | |||
484 | * | |||
485 | * Since: 2.12 | |||
486 | **/ | |||
487 | properties[PROP_RESTRICT_TO_FILL_LEVEL] = | |||
488 | g_param_spec_boolean ("restrict-to-fill-level", | |||
489 | P_("Restrict to Fill Level")g_dgettext("ctk30" "-properties","Restrict to Fill Level"), | |||
490 | P_("Whether to restrict the upper boundary to the fill level.")g_dgettext("ctk30" "-properties","Whether to restrict the upper boundary to the fill level." ), | |||
491 | TRUE(!(0)), | |||
492 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_EXPLICIT_NOTIFY); | |||
493 | ||||
494 | /** | |||
495 | * CtkRange:fill-level: | |||
496 | * | |||
497 | * The fill level (e.g. prebuffering of a network stream). | |||
498 | * See ctk_range_set_fill_level(). | |||
499 | * | |||
500 | * Since: 2.12 | |||
501 | **/ | |||
502 | properties[PROP_FILL_LEVEL] = | |||
503 | g_param_spec_double ("fill-level", | |||
504 | P_("Fill Level")g_dgettext("ctk30" "-properties","Fill Level"), | |||
505 | P_("The fill level.")g_dgettext("ctk30" "-properties","The fill level."), | |||
506 | -G_MAXDOUBLE1.7976931348623157e+308, G_MAXDOUBLE1.7976931348623157e+308, | |||
507 | G_MAXDOUBLE1.7976931348623157e+308, | |||
508 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_EXPLICIT_NOTIFY); | |||
509 | ||||
510 | /** | |||
511 | * CtkRange:round-digits: | |||
512 | * | |||
513 | * The number of digits to round the value to when | |||
514 | * it changes, or -1. See #CtkRange::change-value. | |||
515 | * | |||
516 | * Since: 2.24 | |||
517 | */ | |||
518 | properties[PROP_ROUND_DIGITS] = | |||
519 | g_param_spec_int ("round-digits", | |||
520 | P_("Round Digits")g_dgettext("ctk30" "-properties","Round Digits"), | |||
521 | P_("The number of digits to round the value to.")g_dgettext("ctk30" "-properties","The number of digits to round the value to." ), | |||
522 | -1, G_MAXINT2147483647, | |||
523 | -1, | |||
524 | CTK_PARAM_READWRITEG_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_EXPLICIT_NOTIFY); | |||
525 | ||||
526 | g_object_class_install_properties (gobject_class, LAST_PROP, properties); | |||
527 | ||||
528 | /** | |||
529 | * CtkRange:slider-width: | |||
530 | * | |||
531 | * Width of scrollbar or scale thumb. | |||
532 | * | |||
533 | * Deprecated: 3.20: Use the min-height/min-width CSS properties on the | |||
534 | * slider element. The value of this style property is ignored. | |||
535 | */ | |||
536 | ctk_widget_class_install_style_property (widget_class, | |||
537 | g_param_spec_int ("slider-width", | |||
538 | P_("Slider Width")g_dgettext("ctk30" "-properties","Slider Width"), | |||
539 | P_("Width of scrollbar or scale thumb")g_dgettext("ctk30" "-properties","Width of scrollbar or scale thumb" ), | |||
540 | 0, | |||
541 | G_MAXINT2147483647, | |||
542 | 14, | |||
543 | CTK_PARAM_READABLEG_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_DEPRECATED)); | |||
544 | /** | |||
545 | * CtkRange:trough-border: | |||
546 | * | |||
547 | * Spacing between thumb/steppers and outer trough bevel. | |||
548 | * | |||
549 | * Deprecated: 3.20: Use the margin/padding CSS properties on the trough and | |||
550 | * stepper elements. The value of this style property is ignored. | |||
551 | */ | |||
552 | ctk_widget_class_install_style_property (widget_class, | |||
553 | g_param_spec_int ("trough-border", | |||
554 | P_("Trough Border")g_dgettext("ctk30" "-properties","Trough Border"), | |||
555 | P_("Spacing between thumb/steppers and outer trough bevel")g_dgettext("ctk30" "-properties","Spacing between thumb/steppers and outer trough bevel" ), | |||
556 | 0, | |||
557 | G_MAXINT2147483647, | |||
558 | 1, | |||
559 | CTK_PARAM_READABLEG_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_DEPRECATED)); | |||
560 | /** | |||
561 | * CtkRange:stepper-size: | |||
562 | * | |||
563 | * Length of step buttons at ends. | |||
564 | * | |||
565 | * Deprecated: 3.20: Use the min-height/min-width CSS properties on the | |||
566 | * stepper elements. The value of this style property is ignored. | |||
567 | */ | |||
568 | ctk_widget_class_install_style_property (widget_class, | |||
569 | g_param_spec_int ("stepper-size", | |||
570 | P_("Stepper Size")g_dgettext("ctk30" "-properties","Stepper Size"), | |||
571 | P_("Length of step buttons at ends")g_dgettext("ctk30" "-properties","Length of step buttons at ends" ), | |||
572 | 0, | |||
573 | G_MAXINT2147483647, | |||
574 | 14, | |||
575 | CTK_PARAM_READABLEG_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_DEPRECATED)); | |||
576 | /** | |||
577 | * CtkRange:stepper-spacing: | |||
578 | * | |||
579 | * The spacing between the stepper buttons and thumb. Note that | |||
580 | * stepper-spacing won't have any effect if there are no steppers. | |||
581 | * | |||
582 | * Deprecated: 3.20: Use the margin CSS property on the stepper elements. | |||
583 | * The value of this style property is ignored. | |||
584 | */ | |||
585 | ctk_widget_class_install_style_property (widget_class, | |||
586 | g_param_spec_int ("stepper-spacing", | |||
587 | P_("Stepper Spacing")g_dgettext("ctk30" "-properties","Stepper Spacing"), | |||
588 | P_("Spacing between step buttons and thumb")g_dgettext("ctk30" "-properties","Spacing between step buttons and thumb" ), | |||
589 | 0, | |||
590 | G_MAXINT2147483647, | |||
591 | 0, | |||
592 | CTK_PARAM_READABLEG_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_DEPRECATED)); | |||
593 | ||||
594 | /** | |||
595 | * CtkRange:arrow-displacement-x: | |||
596 | * | |||
597 | * How far in the x direction to move the arrow when the button is depressed. | |||
598 | * | |||
599 | * Deprecated: 3.20: The value of this style property is ignored. | |||
600 | */ | |||
601 | ctk_widget_class_install_style_property (widget_class, | |||
602 | g_param_spec_int ("arrow-displacement-x", | |||
603 | P_("Arrow X Displacement")g_dgettext("ctk30" "-properties","Arrow X Displacement"), | |||
604 | P_("How far in the x direction to move the arrow when the button is depressed")g_dgettext("ctk30" "-properties","How far in the x direction to move the arrow when the button is depressed" ), | |||
605 | G_MININT(-2147483647 -1), | |||
606 | G_MAXINT2147483647, | |||
607 | 0, | |||
608 | CTK_PARAM_READABLEG_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_DEPRECATED)); | |||
609 | ||||
610 | /** | |||
611 | * CtkRange:arrow-displacement-y: | |||
612 | * | |||
613 | * How far in the y direction to move the arrow when the button is depressed. | |||
614 | * | |||
615 | * Deprecated: 3.20: The value of this style property is ignored. | |||
616 | */ | |||
617 | ctk_widget_class_install_style_property (widget_class, | |||
618 | g_param_spec_int ("arrow-displacement-y", | |||
619 | P_("Arrow Y Displacement")g_dgettext("ctk30" "-properties","Arrow Y Displacement"), | |||
620 | P_("How far in the y direction to move the arrow when the button is depressed")g_dgettext("ctk30" "-properties","How far in the y direction to move the arrow when the button is depressed" ), | |||
621 | G_MININT(-2147483647 -1), | |||
622 | G_MAXINT2147483647, | |||
623 | 0, | |||
624 | CTK_PARAM_READABLEG_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_DEPRECATED)); | |||
625 | ||||
626 | /** | |||
627 | * CtkRange:trough-under-steppers: | |||
628 | * | |||
629 | * Whether to draw the trough across the full length of the range or | |||
630 | * to exclude the steppers and their spacing. | |||
631 | * | |||
632 | * Since: 2.10 | |||
633 | * | |||
634 | * Deprecated: 3.20: The value of this style property is ignored, and the | |||
635 | * widget will behave as if it was set to %TRUE. | |||
636 | */ | |||
637 | ctk_widget_class_install_style_property (widget_class, | |||
638 | g_param_spec_boolean ("trough-under-steppers", | |||
639 | P_("Trough Under Steppers")g_dgettext("ctk30" "-properties","Trough Under Steppers"), | |||
640 | P_("Whether to draw trough for full length of range or exclude the steppers and spacing")g_dgettext("ctk30" "-properties","Whether to draw trough for full length of range or exclude the steppers and spacing" ), | |||
641 | TRUE(!(0)), | |||
642 | CTK_PARAM_READABLEG_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_DEPRECATED)); | |||
643 | ||||
644 | /** | |||
645 | * CtkRange:arrow-scaling: | |||
646 | * | |||
647 | * The arrow size proportion relative to the scroll button size. | |||
648 | * | |||
649 | * Since: 2.14 | |||
650 | * | |||
651 | * Deprecated: 3.20: Use min-width/min-height on the "button" node instead. | |||
652 | * The value of this style property is ignored. | |||
653 | */ | |||
654 | ctk_widget_class_install_style_property (widget_class, | |||
655 | g_param_spec_float ("arrow-scaling", | |||
656 | P_("Arrow scaling")g_dgettext("ctk30" "-properties","Arrow scaling"), | |||
657 | P_("Arrow scaling with regard to scroll button size")g_dgettext("ctk30" "-properties","Arrow scaling with regard to scroll button size" ), | |||
658 | 0.0, 1.0, 0.5, | |||
659 | CTK_PARAM_READABLEG_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB|G_PARAM_DEPRECATED)); | |||
660 | ||||
661 | ctk_widget_class_set_accessible_type (widget_class, CTK_TYPE_RANGE_ACCESSIBLE(ctk_range_accessible_get_type ())); | |||
662 | } | |||
663 | ||||
664 | static void | |||
665 | ctk_range_sync_orientation (CtkRange *range) | |||
666 | { | |||
667 | CtkRangePrivate *priv = range->priv; | |||
668 | CtkOrientation orientation; | |||
669 | ||||
670 | orientation = ctk_orientable_get_orientation (CTK_ORIENTABLE (range)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_orientable_get_type ()))))))); | |||
671 | _ctk_orientable_set_style_classes (CTK_ORIENTABLE (range)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_orientable_get_type ()))))))); | |||
672 | ctk_box_gadget_set_orientation (CTK_BOX_GADGET (priv->contents_gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (priv->contents_gadget), ((ctk_box_gadget_get_type ())) )))), orientation); | |||
673 | } | |||
674 | ||||
675 | static void | |||
676 | ctk_range_set_property (GObject *object, | |||
677 | guint prop_id, | |||
678 | const GValue *value, | |||
679 | GParamSpec *pspec) | |||
680 | { | |||
681 | CtkRange *range = CTK_RANGE (object)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_range_get_type ())))))); | |||
682 | CtkRangePrivate *priv = range->priv; | |||
683 | ||||
684 | switch (prop_id) | |||
685 | { | |||
686 | case PROP_ORIENTATION: | |||
687 | if (priv->orientation != g_value_get_enum (value)) | |||
688 | { | |||
689 | priv->orientation = g_value_get_enum (value); | |||
690 | ctk_range_sync_orientation (range); | |||
691 | ctk_widget_queue_resize (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
692 | g_object_notify_by_pspec (object, pspec); | |||
693 | } | |||
694 | break; | |||
695 | case PROP_ADJUSTMENT: | |||
696 | ctk_range_set_adjustment (range, g_value_get_object (value)); | |||
697 | break; | |||
698 | case PROP_INVERTED: | |||
699 | ctk_range_set_inverted (range, g_value_get_boolean (value)); | |||
700 | break; | |||
701 | case PROP_LOWER_STEPPER_SENSITIVITY: | |||
702 | ctk_range_set_lower_stepper_sensitivity (range, g_value_get_enum (value)); | |||
703 | break; | |||
704 | case PROP_UPPER_STEPPER_SENSITIVITY: | |||
705 | ctk_range_set_upper_stepper_sensitivity (range, g_value_get_enum (value)); | |||
706 | break; | |||
707 | case PROP_SHOW_FILL_LEVEL: | |||
708 | ctk_range_set_show_fill_level (range, g_value_get_boolean (value)); | |||
709 | break; | |||
710 | case PROP_RESTRICT_TO_FILL_LEVEL: | |||
711 | ctk_range_set_restrict_to_fill_level (range, g_value_get_boolean (value)); | |||
712 | break; | |||
713 | case PROP_FILL_LEVEL: | |||
714 | ctk_range_set_fill_level (range, g_value_get_double (value)); | |||
715 | break; | |||
716 | case PROP_ROUND_DIGITS: | |||
717 | ctk_range_set_round_digits (range, g_value_get_int (value)); | |||
718 | break; | |||
719 | default: | |||
720 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "ctkrange.c", 720, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); | |||
721 | break; | |||
722 | } | |||
723 | } | |||
724 | ||||
725 | static void | |||
726 | ctk_range_get_property (GObject *object, | |||
727 | guint prop_id, | |||
728 | GValue *value, | |||
729 | GParamSpec *pspec) | |||
730 | { | |||
731 | CtkRange *range = CTK_RANGE (object)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_range_get_type ())))))); | |||
732 | CtkRangePrivate *priv = range->priv; | |||
733 | ||||
734 | switch (prop_id) | |||
735 | { | |||
736 | case PROP_ORIENTATION: | |||
737 | g_value_set_enum (value, priv->orientation); | |||
738 | break; | |||
739 | case PROP_ADJUSTMENT: | |||
740 | g_value_set_object (value, priv->adjustment); | |||
741 | break; | |||
742 | case PROP_INVERTED: | |||
743 | g_value_set_boolean (value, priv->inverted); | |||
744 | break; | |||
745 | case PROP_LOWER_STEPPER_SENSITIVITY: | |||
746 | g_value_set_enum (value, ctk_range_get_lower_stepper_sensitivity (range)); | |||
747 | break; | |||
748 | case PROP_UPPER_STEPPER_SENSITIVITY: | |||
749 | g_value_set_enum (value, ctk_range_get_upper_stepper_sensitivity (range)); | |||
750 | break; | |||
751 | case PROP_SHOW_FILL_LEVEL: | |||
752 | g_value_set_boolean (value, ctk_range_get_show_fill_level (range)); | |||
753 | break; | |||
754 | case PROP_RESTRICT_TO_FILL_LEVEL: | |||
755 | g_value_set_boolean (value, ctk_range_get_restrict_to_fill_level (range)); | |||
756 | break; | |||
757 | case PROP_FILL_LEVEL: | |||
758 | g_value_set_double (value, ctk_range_get_fill_level (range)); | |||
759 | break; | |||
760 | case PROP_ROUND_DIGITS: | |||
761 | g_value_set_int (value, ctk_range_get_round_digits (range)); | |||
762 | break; | |||
763 | default: | |||
764 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "ctkrange.c", 764, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); | |||
765 | break; | |||
766 | } | |||
767 | } | |||
768 | ||||
769 | static void | |||
770 | ctk_range_init (CtkRange *range) | |||
771 | { | |||
772 | CtkRangePrivate *priv; | |||
773 | CtkCssNode *widget_node; | |||
774 | ||||
775 | range->priv = ctk_range_get_instance_private (range); | |||
776 | priv = range->priv; | |||
777 | ||||
778 | ctk_widget_set_has_window (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), FALSE(0)); | |||
779 | ||||
780 | priv->orientation = CTK_ORIENTATION_HORIZONTAL; | |||
781 | priv->adjustment = NULL((void*)0); | |||
782 | priv->inverted = FALSE(0); | |||
783 | priv->flippable = FALSE(0); | |||
784 | priv->min_slider_size = 1; | |||
785 | priv->round_digits = -1; | |||
786 | priv->mouse_x = G_MININT(-2147483647 -1); | |||
787 | priv->mouse_y = G_MININT(-2147483647 -1); | |||
788 | priv->lower_sensitivity = CTK_SENSITIVITY_AUTO; | |||
789 | priv->upper_sensitivity = CTK_SENSITIVITY_AUTO; | |||
790 | priv->lower_sensitive = TRUE(!(0)); | |||
791 | priv->upper_sensitive = TRUE(!(0)); | |||
792 | priv->has_origin = FALSE(0); | |||
793 | priv->show_fill_level = FALSE(0); | |||
794 | priv->restrict_to_fill_level = TRUE(!(0)); | |||
795 | priv->fill_level = G_MAXDOUBLE1.7976931348623157e+308; | |||
796 | priv->timer = NULL((void*)0); | |||
797 | ||||
798 | _ctk_orientable_set_style_classes (CTK_ORIENTABLE (range)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_orientable_get_type ()))))))); | |||
799 | ||||
800 | widget_node = ctk_widget_get_css_node (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
801 | priv->gadget = ctk_css_custom_gadget_new_for_node (widget_node, | |||
802 | CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), | |||
803 | ctk_range_measure, | |||
804 | ctk_range_allocate, | |||
805 | ctk_range_render, | |||
806 | NULL((void*)0), NULL((void*)0)); | |||
807 | priv->contents_gadget = ctk_box_gadget_new ("contents", | |||
808 | CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), | |||
809 | priv->gadget, NULL((void*)0)); | |||
810 | priv->trough_gadget = ctk_css_custom_gadget_new ("trough", | |||
811 | CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), | |||
812 | NULL((void*)0), NULL((void*)0), | |||
813 | ctk_range_measure_trough, | |||
814 | ctk_range_allocate_trough, | |||
815 | ctk_range_render_trough, | |||
816 | NULL((void*)0), NULL((void*)0)); | |||
817 | ctk_css_gadget_set_state (priv->trough_gadget, | |||
818 | ctk_css_node_get_state (widget_node)); | |||
819 | ctk_box_gadget_insert_gadget (CTK_BOX_GADGET (priv->contents_gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (priv->contents_gadget), ((ctk_box_gadget_get_type ())) )))), -1, priv->trough_gadget, | |||
820 | TRUE(!(0)), CTK_ALIGN_CENTER); | |||
821 | ||||
822 | priv->slider_gadget = ctk_builtin_icon_new ("slider", | |||
823 | CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), | |||
824 | priv->trough_gadget, NULL((void*)0)); | |||
825 | ctk_css_gadget_set_state (priv->slider_gadget, | |||
826 | ctk_css_node_get_state (widget_node)); | |||
827 | ||||
828 | /* Note: Order is important here. | |||
829 | * The ::drag-begin handler relies on the state set up by the | |||
830 | * multipress ::pressed handler. Gestures are handling events | |||
831 | * in the oppposite order in which they are added to their | |||
832 | * widget. | |||
833 | */ | |||
834 | priv->drag_gesture = ctk_gesture_drag_new (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
835 | ctk_gesture_single_set_button (CTK_GESTURE_SINGLE (priv->drag_gesture)((((CtkGestureSingle*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((priv->drag_gesture)), ((ctk_gesture_single_get_type ())))))), 0); | |||
836 | g_signal_connect (priv->drag_gesture, "drag-begin",g_signal_connect_data ((priv->drag_gesture), ("drag-begin" ), (((GCallback) (ctk_range_drag_gesture_begin))), (range), ( (void*)0), (GConnectFlags) 0) | |||
837 | G_CALLBACK (ctk_range_drag_gesture_begin), range)g_signal_connect_data ((priv->drag_gesture), ("drag-begin" ), (((GCallback) (ctk_range_drag_gesture_begin))), (range), ( (void*)0), (GConnectFlags) 0); | |||
838 | g_signal_connect (priv->drag_gesture, "drag-update",g_signal_connect_data ((priv->drag_gesture), ("drag-update" ), (((GCallback) (ctk_range_drag_gesture_update))), (range), ( (void*)0), (GConnectFlags) 0) | |||
839 | G_CALLBACK (ctk_range_drag_gesture_update), range)g_signal_connect_data ((priv->drag_gesture), ("drag-update" ), (((GCallback) (ctk_range_drag_gesture_update))), (range), ( (void*)0), (GConnectFlags) 0); | |||
840 | ||||
841 | priv->multipress_gesture = ctk_gesture_multi_press_new (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
842 | ctk_gesture_single_set_button (CTK_GESTURE_SINGLE (priv->multipress_gesture)((((CtkGestureSingle*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((priv->multipress_gesture)), ((ctk_gesture_single_get_type ())))))), 0); | |||
843 | ctk_gesture_group (priv->drag_gesture, priv->multipress_gesture); | |||
844 | g_signal_connect (priv->multipress_gesture, "pressed",g_signal_connect_data ((priv->multipress_gesture), ("pressed" ), (((GCallback) (ctk_range_multipress_gesture_pressed))), (range ), ((void*)0), (GConnectFlags) 0) | |||
845 | G_CALLBACK (ctk_range_multipress_gesture_pressed), range)g_signal_connect_data ((priv->multipress_gesture), ("pressed" ), (((GCallback) (ctk_range_multipress_gesture_pressed))), (range ), ((void*)0), (GConnectFlags) 0); | |||
846 | g_signal_connect (priv->multipress_gesture, "released",g_signal_connect_data ((priv->multipress_gesture), ("released" ), (((GCallback) (ctk_range_multipress_gesture_released))), ( range), ((void*)0), (GConnectFlags) 0) | |||
847 | G_CALLBACK (ctk_range_multipress_gesture_released), range)g_signal_connect_data ((priv->multipress_gesture), ("released" ), (((GCallback) (ctk_range_multipress_gesture_released))), ( range), ((void*)0), (GConnectFlags) 0); | |||
848 | ||||
849 | priv->long_press_gesture = ctk_gesture_long_press_new (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
850 | g_object_set (priv->long_press_gesture, "delay-factor", 2.0, NULL((void*)0)); | |||
851 | ctk_gesture_group (priv->drag_gesture, priv->long_press_gesture); | |||
852 | g_signal_connect (priv->long_press_gesture, "pressed",g_signal_connect_data ((priv->long_press_gesture), ("pressed" ), (((GCallback) (ctk_range_long_press_gesture_pressed))), (range ), ((void*)0), (GConnectFlags) 0) | |||
853 | G_CALLBACK (ctk_range_long_press_gesture_pressed), range)g_signal_connect_data ((priv->long_press_gesture), ("pressed" ), (((GCallback) (ctk_range_long_press_gesture_pressed))), (range ), ((void*)0), (GConnectFlags) 0); | |||
854 | } | |||
855 | ||||
856 | /** | |||
857 | * ctk_range_get_adjustment: | |||
858 | * @range: a #CtkRange | |||
859 | * | |||
860 | * Get the #CtkAdjustment which is the “model” object for #CtkRange. | |||
861 | * See ctk_range_set_adjustment() for details. | |||
862 | * The return value does not have a reference added, so should not | |||
863 | * be unreferenced. | |||
864 | * | |||
865 | * Returns: (transfer none): a #CtkAdjustment | |||
866 | **/ | |||
867 | CtkAdjustment* | |||
868 | ctk_range_get_adjustment (CtkRange *range) | |||
869 | { | |||
870 | CtkRangePrivate *priv; | |||
871 | ||||
872 | g_return_val_if_fail (CTK_IS_RANGE (range), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return (((void*)0)); } } while ( 0); | |||
873 | ||||
874 | priv = range->priv; | |||
875 | ||||
876 | if (!priv->adjustment) | |||
877 | ctk_range_set_adjustment (range, NULL((void*)0)); | |||
878 | ||||
879 | return priv->adjustment; | |||
880 | } | |||
881 | ||||
882 | /** | |||
883 | * ctk_range_set_adjustment: | |||
884 | * @range: a #CtkRange | |||
885 | * @adjustment: a #CtkAdjustment | |||
886 | * | |||
887 | * Sets the adjustment to be used as the “model” object for this range | |||
888 | * widget. The adjustment indicates the current range value, the | |||
889 | * minimum and maximum range values, the step/page increments used | |||
890 | * for keybindings and scrolling, and the page size. The page size | |||
891 | * is normally 0 for #CtkScale and nonzero for #CtkScrollbar, and | |||
892 | * indicates the size of the visible area of the widget being scrolled. | |||
893 | * The page size affects the size of the scrollbar slider. | |||
894 | **/ | |||
895 | void | |||
896 | ctk_range_set_adjustment (CtkRange *range, | |||
897 | CtkAdjustment *adjustment) | |||
898 | { | |||
899 | CtkRangePrivate *priv; | |||
900 | ||||
901 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
902 | ||||
903 | priv = range->priv; | |||
904 | ||||
905 | if (!adjustment) | |||
906 | adjustment = ctk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | |||
907 | else | |||
908 | g_return_if_fail (CTK_IS_ADJUSTMENT (adjustment))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((adjustment)); GType __t = ((ctk_adjustment_get_type ())) ; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning ("Ctk", ((const char *) (__func__)), "CTK_IS_ADJUSTMENT (adjustment)"); return; } } while (0); | |||
909 | ||||
910 | if (priv->adjustment != adjustment) | |||
911 | { | |||
912 | if (priv->adjustment) | |||
913 | { | |||
914 | g_signal_handlers_disconnect_by_func (priv->adjustment,g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_changed), (range)) | |||
915 | ctk_range_adjustment_changed,g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_changed), (range)) | |||
916 | range)g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_changed), (range)); | |||
917 | g_signal_handlers_disconnect_by_func (priv->adjustment,g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_value_changed), (range )) | |||
918 | ctk_range_adjustment_value_changed,g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_value_changed), (range )) | |||
919 | range)g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_value_changed), (range )); | |||
920 | g_object_unref (priv->adjustment); | |||
921 | } | |||
922 | ||||
923 | priv->adjustment = adjustment; | |||
924 | g_object_ref_sink (adjustment)((__typeof__ (adjustment)) (g_object_ref_sink) (adjustment)); | |||
925 | ||||
926 | g_signal_connect (adjustment, "changed",g_signal_connect_data ((adjustment), ("changed"), (((GCallback ) (ctk_range_adjustment_changed))), (range), ((void*)0), (GConnectFlags ) 0) | |||
927 | G_CALLBACK (ctk_range_adjustment_changed),g_signal_connect_data ((adjustment), ("changed"), (((GCallback ) (ctk_range_adjustment_changed))), (range), ((void*)0), (GConnectFlags ) 0) | |||
928 | range)g_signal_connect_data ((adjustment), ("changed"), (((GCallback ) (ctk_range_adjustment_changed))), (range), ((void*)0), (GConnectFlags ) 0); | |||
929 | g_signal_connect (adjustment, "value-changed",g_signal_connect_data ((adjustment), ("value-changed"), (((GCallback ) (ctk_range_adjustment_value_changed))), (range), ((void*)0) , (GConnectFlags) 0) | |||
930 | G_CALLBACK (ctk_range_adjustment_value_changed),g_signal_connect_data ((adjustment), ("value-changed"), (((GCallback ) (ctk_range_adjustment_value_changed))), (range), ((void*)0) , (GConnectFlags) 0) | |||
931 | range)g_signal_connect_data ((adjustment), ("value-changed"), (((GCallback ) (ctk_range_adjustment_value_changed))), (range), ((void*)0) , (GConnectFlags) 0); | |||
932 | ||||
933 | ctk_range_adjustment_changed (adjustment, range); | |||
934 | g_object_notify_by_pspec (G_OBJECT (range)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), (((GType) ((20) << (2)))))))), properties[PROP_ADJUSTMENT]); | |||
935 | } | |||
936 | } | |||
937 | ||||
938 | static gboolean | |||
939 | should_invert (CtkRange *range) | |||
940 | { | |||
941 | CtkRangePrivate *priv = range->priv; | |||
942 | ||||
943 | if (priv->orientation == CTK_ORIENTATION_HORIZONTAL) | |||
944 | return | |||
945 | (priv->inverted && !priv->flippable) || | |||
946 | (priv->inverted && priv->flippable && ctk_widget_get_direction (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))) == CTK_TEXT_DIR_LTR) || | |||
947 | (!priv->inverted && priv->flippable && ctk_widget_get_direction (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))) == CTK_TEXT_DIR_RTL); | |||
948 | else | |||
949 | return priv->inverted; | |||
950 | } | |||
951 | ||||
952 | static gboolean | |||
953 | should_invert_move (CtkRange *range, | |||
954 | CtkOrientation move_orientation) | |||
955 | { | |||
956 | CtkRangePrivate *priv = range->priv; | |||
957 | ||||
958 | /* If the move is parallel to the range, use general check for inversion */ | |||
959 | if (move_orientation == priv->orientation) | |||
960 | return should_invert (range); | |||
961 | ||||
962 | /* H scale/V move: Always invert, so down/up always dec/increase the value */ | |||
963 | if (priv->orientation == CTK_ORIENTATION_HORIZONTAL && CTK_IS_SCALE (range)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (range)); GType __t = ((ctk_scale_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
964 | return TRUE(!(0)); | |||
965 | ||||
966 | /* V range/H move: Left/right always dec/increase the value */ | |||
967 | return FALSE(0); | |||
968 | } | |||
969 | ||||
970 | static void | |||
971 | update_highlight_position (CtkRange *range) | |||
972 | { | |||
973 | CtkRangePrivate *priv = range->priv; | |||
974 | ||||
975 | if (!priv->highlight_gadget) | |||
976 | return; | |||
977 | ||||
978 | if (should_invert (range)) | |||
979 | { | |||
980 | ctk_css_gadget_remove_class (priv->highlight_gadget, CTK_STYLE_CLASS_TOP"top"); | |||
981 | ctk_css_gadget_add_class (priv->highlight_gadget, CTK_STYLE_CLASS_BOTTOM"bottom"); | |||
982 | } | |||
983 | else | |||
984 | { | |||
985 | ctk_css_gadget_remove_class (priv->highlight_gadget, CTK_STYLE_CLASS_BOTTOM"bottom"); | |||
986 | ctk_css_gadget_add_class (priv->highlight_gadget, CTK_STYLE_CLASS_TOP"top"); | |||
987 | } | |||
988 | } | |||
989 | ||||
990 | static void | |||
991 | update_fill_position (CtkRange *range) | |||
992 | { | |||
993 | CtkRangePrivate *priv = range->priv; | |||
994 | ||||
995 | if (!priv->fill_gadget) | |||
996 | return; | |||
997 | ||||
998 | if (should_invert (range)) | |||
999 | { | |||
1000 | ctk_css_gadget_remove_class (priv->fill_gadget, CTK_STYLE_CLASS_TOP"top"); | |||
1001 | ctk_css_gadget_add_class (priv->fill_gadget, CTK_STYLE_CLASS_BOTTOM"bottom"); | |||
1002 | } | |||
1003 | else | |||
1004 | { | |||
1005 | ctk_css_gadget_remove_class (priv->fill_gadget, CTK_STYLE_CLASS_BOTTOM"bottom"); | |||
1006 | ctk_css_gadget_add_class (priv->fill_gadget, CTK_STYLE_CLASS_TOP"top"); | |||
1007 | } | |||
1008 | } | |||
1009 | ||||
1010 | static void | |||
1011 | update_stepper_state (CtkRange *range, | |||
1012 | CtkCssGadget *gadget) | |||
1013 | { | |||
1014 | CtkRangePrivate *priv = range->priv; | |||
1015 | CtkStateFlags state; | |||
1016 | gboolean arrow_sensitive; | |||
1017 | ||||
1018 | state = ctk_widget_get_state_flags (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
1019 | ||||
1020 | if ((!priv->inverted && | |||
1021 | (gadget == priv->stepper_a_gadget || gadget == priv->stepper_c_gadget)) || | |||
1022 | (priv->inverted && | |||
1023 | (gadget == priv->stepper_b_gadget || gadget == priv->stepper_d_gadget))) | |||
1024 | arrow_sensitive = priv->lower_sensitive; | |||
1025 | else | |||
1026 | arrow_sensitive = priv->upper_sensitive; | |||
1027 | ||||
1028 | state &= ~(CTK_STATE_FLAG_ACTIVE | CTK_STATE_FLAG_PRELIGHT); | |||
1029 | ||||
1030 | if ((state & CTK_STATE_FLAG_INSENSITIVE) || !arrow_sensitive) | |||
1031 | { | |||
1032 | state |= CTK_STATE_FLAG_INSENSITIVE; | |||
1033 | } | |||
1034 | else | |||
1035 | { | |||
1036 | if (priv->grab_location == gadget) | |||
1037 | state |= CTK_STATE_FLAG_ACTIVE; | |||
1038 | if (priv->mouse_location == gadget) | |||
1039 | state |= CTK_STATE_FLAG_PRELIGHT; | |||
1040 | } | |||
1041 | ||||
1042 | ctk_css_gadget_set_state (gadget, state); | |||
1043 | } | |||
1044 | ||||
1045 | static void | |||
1046 | update_steppers_state (CtkRange *range) | |||
1047 | { | |||
1048 | CtkRangePrivate *priv = range->priv; | |||
1049 | ||||
1050 | if (priv->stepper_a_gadget) | |||
1051 | update_stepper_state (range, priv->stepper_a_gadget); | |||
1052 | if (priv->stepper_b_gadget) | |||
1053 | update_stepper_state (range, priv->stepper_b_gadget); | |||
1054 | if (priv->stepper_c_gadget) | |||
1055 | update_stepper_state (range, priv->stepper_c_gadget); | |||
1056 | if (priv->stepper_d_gadget) | |||
1057 | update_stepper_state (range, priv->stepper_d_gadget); | |||
1058 | } | |||
1059 | ||||
1060 | /** | |||
1061 | * ctk_range_set_inverted: | |||
1062 | * @range: a #CtkRange | |||
1063 | * @setting: %TRUE to invert the range | |||
1064 | * | |||
1065 | * Ranges normally move from lower to higher values as the | |||
1066 | * slider moves from top to bottom or left to right. Inverted | |||
1067 | * ranges have higher values at the top or on the right rather than | |||
1068 | * on the bottom or left. | |||
1069 | **/ | |||
1070 | void | |||
1071 | ctk_range_set_inverted (CtkRange *range, | |||
1072 | gboolean setting) | |||
1073 | { | |||
1074 | CtkRangePrivate *priv; | |||
1075 | ||||
1076 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1077 | ||||
1078 | priv = range->priv; | |||
1079 | ||||
1080 | setting = setting != FALSE(0); | |||
1081 | ||||
1082 | if (setting != priv->inverted) | |||
1083 | { | |||
1084 | priv->inverted = setting; | |||
1085 | ||||
1086 | update_steppers_state (range); | |||
1087 | update_fill_position (range); | |||
1088 | update_highlight_position (range); | |||
1089 | ||||
1090 | ctk_widget_queue_resize (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
1091 | ||||
1092 | g_object_notify_by_pspec (G_OBJECT (range)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), (((GType) ((20) << (2)))))))), properties[PROP_INVERTED]); | |||
1093 | } | |||
1094 | } | |||
1095 | ||||
1096 | /** | |||
1097 | * ctk_range_get_inverted: | |||
1098 | * @range: a #CtkRange | |||
1099 | * | |||
1100 | * Gets the value set by ctk_range_set_inverted(). | |||
1101 | * | |||
1102 | * Returns: %TRUE if the range is inverted | |||
1103 | **/ | |||
1104 | gboolean | |||
1105 | ctk_range_get_inverted (CtkRange *range) | |||
1106 | { | |||
1107 | g_return_val_if_fail (CTK_IS_RANGE (range), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return ((0)); } } while (0); | |||
1108 | ||||
1109 | return range->priv->inverted; | |||
1110 | } | |||
1111 | ||||
1112 | /** | |||
1113 | * ctk_range_set_flippable: | |||
1114 | * @range: a #CtkRange | |||
1115 | * @flippable: %TRUE to make the range flippable | |||
1116 | * | |||
1117 | * If a range is flippable, it will switch its direction if it is | |||
1118 | * horizontal and its direction is %CTK_TEXT_DIR_RTL. | |||
1119 | * | |||
1120 | * See ctk_widget_get_direction(). | |||
1121 | * | |||
1122 | * Since: 2.18 | |||
1123 | **/ | |||
1124 | void | |||
1125 | ctk_range_set_flippable (CtkRange *range, | |||
1126 | gboolean flippable) | |||
1127 | { | |||
1128 | CtkRangePrivate *priv; | |||
1129 | ||||
1130 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1131 | ||||
1132 | priv = range->priv; | |||
1133 | ||||
1134 | flippable = flippable ? TRUE(!(0)) : FALSE(0); | |||
1135 | ||||
1136 | if (flippable != priv->flippable) | |||
1137 | { | |||
1138 | priv->flippable = flippable; | |||
1139 | update_fill_position (range); | |||
1140 | update_highlight_position (range); | |||
1141 | ||||
1142 | ctk_widget_queue_allocate (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
1143 | } | |||
1144 | } | |||
1145 | ||||
1146 | /** | |||
1147 | * ctk_range_get_flippable: | |||
1148 | * @range: a #CtkRange | |||
1149 | * | |||
1150 | * Gets the value set by ctk_range_set_flippable(). | |||
1151 | * | |||
1152 | * Returns: %TRUE if the range is flippable | |||
1153 | * | |||
1154 | * Since: 2.18 | |||
1155 | **/ | |||
1156 | gboolean | |||
1157 | ctk_range_get_flippable (CtkRange *range) | |||
1158 | { | |||
1159 | g_return_val_if_fail (CTK_IS_RANGE (range), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return ((0)); } } while (0); | |||
1160 | ||||
1161 | return range->priv->flippable; | |||
1162 | } | |||
1163 | ||||
1164 | void | |||
1165 | ctk_range_set_slider_use_min_size (CtkRange *range, | |||
1166 | gboolean use_min_size) | |||
1167 | { | |||
1168 | CtkRangePrivate *priv = range->priv; | |||
1169 | ||||
1170 | if (use_min_size != priv->slider_use_min_size) | |||
1171 | { | |||
1172 | priv->slider_use_min_size = use_min_size; | |||
1173 | ctk_css_gadget_queue_resize (priv->slider_gadget); | |||
1174 | } | |||
1175 | } | |||
1176 | ||||
1177 | /** | |||
1178 | * ctk_range_set_slider_size_fixed: | |||
1179 | * @range: a #CtkRange | |||
1180 | * @size_fixed: %TRUE to make the slider size constant | |||
1181 | * | |||
1182 | * Sets whether the range’s slider has a fixed size, or a size that | |||
1183 | * depends on its adjustment’s page size. | |||
1184 | * | |||
1185 | * This function is useful mainly for #CtkRange subclasses. | |||
1186 | * | |||
1187 | * Since: 2.20 | |||
1188 | **/ | |||
1189 | void | |||
1190 | ctk_range_set_slider_size_fixed (CtkRange *range, | |||
1191 | gboolean size_fixed) | |||
1192 | { | |||
1193 | CtkRangePrivate *priv; | |||
1194 | ||||
1195 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1196 | ||||
1197 | priv = range->priv; | |||
1198 | ||||
1199 | if (size_fixed != priv->slider_size_fixed) | |||
1200 | { | |||
1201 | priv->slider_size_fixed = size_fixed ? TRUE(!(0)) : FALSE(0); | |||
1202 | ||||
1203 | if (priv->adjustment && ctk_widget_get_mapped (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))))) | |||
1204 | ctk_css_gadget_queue_allocate (priv->slider_gadget); | |||
1205 | } | |||
1206 | } | |||
1207 | ||||
1208 | /** | |||
1209 | * ctk_range_get_slider_size_fixed: | |||
1210 | * @range: a #CtkRange | |||
1211 | * | |||
1212 | * This function is useful mainly for #CtkRange subclasses. | |||
1213 | * | |||
1214 | * See ctk_range_set_slider_size_fixed(). | |||
1215 | * | |||
1216 | * Returns: whether the range’s slider has a fixed size. | |||
1217 | * | |||
1218 | * Since: 2.20 | |||
1219 | **/ | |||
1220 | gboolean | |||
1221 | ctk_range_get_slider_size_fixed (CtkRange *range) | |||
1222 | { | |||
1223 | g_return_val_if_fail (CTK_IS_RANGE (range), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return ((0)); } } while (0); | |||
1224 | ||||
1225 | return range->priv->slider_size_fixed; | |||
1226 | } | |||
1227 | ||||
1228 | /** | |||
1229 | * ctk_range_set_min_slider_size: | |||
1230 | * @range: a #CtkRange | |||
1231 | * @min_size: The slider’s minimum size | |||
1232 | * | |||
1233 | * Sets the minimum size of the range’s slider. | |||
1234 | * | |||
1235 | * This function is useful mainly for #CtkRange subclasses. | |||
1236 | * | |||
1237 | * Since: 2.20 | |||
1238 | * | |||
1239 | * Deprecated: 3.20: Use the min-height/min-width CSS properties on the slider | |||
1240 | * node. | |||
1241 | **/ | |||
1242 | void | |||
1243 | ctk_range_set_min_slider_size (CtkRange *range, | |||
1244 | gint min_size) | |||
1245 | { | |||
1246 | CtkRangePrivate *priv; | |||
1247 | ||||
1248 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1249 | g_return_if_fail (min_size > 0)do { if ((min_size > 0)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "min_size > 0"); return ; } } while (0); | |||
1250 | ||||
1251 | priv = range->priv; | |||
1252 | ||||
1253 | if (min_size != priv->min_slider_size) | |||
1254 | { | |||
1255 | priv->min_slider_size = min_size; | |||
1256 | ||||
1257 | ctk_widget_queue_resize (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
1258 | } | |||
1259 | } | |||
1260 | ||||
1261 | /** | |||
1262 | * ctk_range_get_min_slider_size: | |||
1263 | * @range: a #CtkRange | |||
1264 | * | |||
1265 | * This function is useful mainly for #CtkRange subclasses. | |||
1266 | * | |||
1267 | * See ctk_range_set_min_slider_size(). | |||
1268 | * | |||
1269 | * Returns: The minimum size of the range’s slider. | |||
1270 | * | |||
1271 | * Since: 2.20 | |||
1272 | * | |||
1273 | * Deprecated: 3.20: Use the min-height/min-width CSS properties on the slider | |||
1274 | * node. | |||
1275 | **/ | |||
1276 | gint | |||
1277 | ctk_range_get_min_slider_size (CtkRange *range) | |||
1278 | { | |||
1279 | g_return_val_if_fail (CTK_IS_RANGE (range), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return ((0)); } } while (0); | |||
1280 | ||||
1281 | return range->priv->min_slider_size; | |||
1282 | } | |||
1283 | ||||
1284 | static void | |||
1285 | measure_one_gadget (CtkCssGadget *gadget, | |||
1286 | int *width_out, | |||
1287 | int *height_out) | |||
1288 | { | |||
1289 | ctk_css_gadget_get_preferred_size (gadget, | |||
1290 | CTK_ORIENTATION_HORIZONTAL, -1, | |||
1291 | width_out, NULL((void*)0), | |||
1292 | NULL((void*)0), NULL((void*)0)); | |||
1293 | ctk_css_gadget_get_preferred_size (gadget, | |||
1294 | CTK_ORIENTATION_VERTICAL, -1, | |||
1295 | height_out, NULL((void*)0), | |||
1296 | NULL((void*)0), NULL((void*)0)); | |||
1297 | } | |||
1298 | ||||
1299 | /** | |||
1300 | * ctk_range_get_range_rect: | |||
1301 | * @range: a #CtkRange | |||
1302 | * @range_rect: (out): return location for the range rectangle | |||
1303 | * | |||
1304 | * This function returns the area that contains the range’s trough | |||
1305 | * and its steppers, in widget->window coordinates. | |||
1306 | * | |||
1307 | * This function is useful mainly for #CtkRange subclasses. | |||
1308 | * | |||
1309 | * Since: 2.20 | |||
1310 | **/ | |||
1311 | void | |||
1312 | ctk_range_get_range_rect (CtkRange *range, | |||
1313 | CdkRectangle *range_rect) | |||
1314 | { | |||
1315 | CtkRangePrivate *priv; | |||
1316 | ||||
1317 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1318 | g_return_if_fail (range_rect != NULL)do { if ((range_rect != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "range_rect != NULL"); return ; } } while (0); | |||
1319 | ||||
1320 | priv = range->priv; | |||
1321 | ||||
1322 | ctk_css_gadget_get_margin_box (priv->contents_gadget, range_rect); | |||
1323 | } | |||
1324 | ||||
1325 | /** | |||
1326 | * ctk_range_get_slider_range: | |||
1327 | * @range: a #CtkRange | |||
1328 | * @slider_start: (out) (allow-none): return location for the slider's | |||
1329 | * start, or %NULL | |||
1330 | * @slider_end: (out) (allow-none): return location for the slider's | |||
1331 | * end, or %NULL | |||
1332 | * | |||
1333 | * This function returns sliders range along the long dimension, | |||
1334 | * in widget->window coordinates. | |||
1335 | * | |||
1336 | * This function is useful mainly for #CtkRange subclasses. | |||
1337 | * | |||
1338 | * Since: 2.20 | |||
1339 | **/ | |||
1340 | void | |||
1341 | ctk_range_get_slider_range (CtkRange *range, | |||
1342 | gint *slider_start, | |||
1343 | gint *slider_end) | |||
1344 | { | |||
1345 | CtkRangePrivate *priv; | |||
1346 | CtkAllocation slider_alloc; | |||
1347 | ||||
1348 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1349 | ||||
1350 | priv = range->priv; | |||
1351 | ||||
1352 | ctk_css_gadget_get_margin_box (priv->slider_gadget, &slider_alloc); | |||
1353 | ||||
1354 | if (priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
1355 | { | |||
1356 | if (slider_start) | |||
1357 | *slider_start = slider_alloc.y; | |||
1358 | if (slider_end) | |||
1359 | *slider_end = slider_alloc.y + slider_alloc.height; | |||
1360 | } | |||
1361 | else | |||
1362 | { | |||
1363 | if (slider_start) | |||
1364 | *slider_start = slider_alloc.x; | |||
1365 | if (slider_end) | |||
1366 | *slider_end = slider_alloc.x + slider_alloc.width; | |||
1367 | } | |||
1368 | } | |||
1369 | ||||
1370 | /** | |||
1371 | * ctk_range_set_lower_stepper_sensitivity: | |||
1372 | * @range: a #CtkRange | |||
1373 | * @sensitivity: the lower stepper’s sensitivity policy. | |||
1374 | * | |||
1375 | * Sets the sensitivity policy for the stepper that points to the | |||
1376 | * 'lower' end of the CtkRange’s adjustment. | |||
1377 | * | |||
1378 | * Since: 2.10 | |||
1379 | **/ | |||
1380 | void | |||
1381 | ctk_range_set_lower_stepper_sensitivity (CtkRange *range, | |||
1382 | CtkSensitivityType sensitivity) | |||
1383 | { | |||
1384 | CtkRangePrivate *priv; | |||
1385 | ||||
1386 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1387 | ||||
1388 | priv = range->priv; | |||
1389 | ||||
1390 | if (priv->lower_sensitivity != sensitivity) | |||
1391 | { | |||
1392 | priv->lower_sensitivity = sensitivity; | |||
1393 | ||||
1394 | ctk_range_calc_stepper_sensitivity (range); | |||
1395 | ||||
1396 | g_object_notify_by_pspec (G_OBJECT (range)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), (((GType) ((20) << (2)))))))), properties[PROP_LOWER_STEPPER_SENSITIVITY]); | |||
1397 | } | |||
1398 | } | |||
1399 | ||||
1400 | /** | |||
1401 | * ctk_range_get_lower_stepper_sensitivity: | |||
1402 | * @range: a #CtkRange | |||
1403 | * | |||
1404 | * Gets the sensitivity policy for the stepper that points to the | |||
1405 | * 'lower' end of the CtkRange’s adjustment. | |||
1406 | * | |||
1407 | * Returns: The lower stepper’s sensitivity policy. | |||
1408 | * | |||
1409 | * Since: 2.10 | |||
1410 | **/ | |||
1411 | CtkSensitivityType | |||
1412 | ctk_range_get_lower_stepper_sensitivity (CtkRange *range) | |||
1413 | { | |||
1414 | g_return_val_if_fail (CTK_IS_RANGE (range), CTK_SENSITIVITY_AUTO)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return (CTK_SENSITIVITY_AUTO); } } while (0); | |||
1415 | ||||
1416 | return range->priv->lower_sensitivity; | |||
1417 | } | |||
1418 | ||||
1419 | /** | |||
1420 | * ctk_range_set_upper_stepper_sensitivity: | |||
1421 | * @range: a #CtkRange | |||
1422 | * @sensitivity: the upper stepper’s sensitivity policy. | |||
1423 | * | |||
1424 | * Sets the sensitivity policy for the stepper that points to the | |||
1425 | * 'upper' end of the CtkRange’s adjustment. | |||
1426 | * | |||
1427 | * Since: 2.10 | |||
1428 | **/ | |||
1429 | void | |||
1430 | ctk_range_set_upper_stepper_sensitivity (CtkRange *range, | |||
1431 | CtkSensitivityType sensitivity) | |||
1432 | { | |||
1433 | CtkRangePrivate *priv; | |||
1434 | ||||
1435 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1436 | ||||
1437 | priv = range->priv; | |||
1438 | ||||
1439 | if (priv->upper_sensitivity != sensitivity) | |||
1440 | { | |||
1441 | priv->upper_sensitivity = sensitivity; | |||
1442 | ||||
1443 | ctk_range_calc_stepper_sensitivity (range); | |||
1444 | ||||
1445 | g_object_notify_by_pspec (G_OBJECT (range)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), (((GType) ((20) << (2)))))))), properties[PROP_UPPER_STEPPER_SENSITIVITY]); | |||
1446 | } | |||
1447 | } | |||
1448 | ||||
1449 | /** | |||
1450 | * ctk_range_get_upper_stepper_sensitivity: | |||
1451 | * @range: a #CtkRange | |||
1452 | * | |||
1453 | * Gets the sensitivity policy for the stepper that points to the | |||
1454 | * 'upper' end of the CtkRange’s adjustment. | |||
1455 | * | |||
1456 | * Returns: The upper stepper’s sensitivity policy. | |||
1457 | * | |||
1458 | * Since: 2.10 | |||
1459 | **/ | |||
1460 | CtkSensitivityType | |||
1461 | ctk_range_get_upper_stepper_sensitivity (CtkRange *range) | |||
1462 | { | |||
1463 | g_return_val_if_fail (CTK_IS_RANGE (range), CTK_SENSITIVITY_AUTO)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return (CTK_SENSITIVITY_AUTO); } } while (0); | |||
1464 | ||||
1465 | return range->priv->upper_sensitivity; | |||
1466 | } | |||
1467 | ||||
1468 | /** | |||
1469 | * ctk_range_set_increments: | |||
1470 | * @range: a #CtkRange | |||
1471 | * @step: step size | |||
1472 | * @page: page size | |||
1473 | * | |||
1474 | * Sets the step and page sizes for the range. | |||
1475 | * The step size is used when the user clicks the #CtkScrollbar | |||
1476 | * arrows or moves #CtkScale via arrow keys. The page size | |||
1477 | * is used for example when moving via Page Up or Page Down keys. | |||
1478 | **/ | |||
1479 | void | |||
1480 | ctk_range_set_increments (CtkRange *range, | |||
1481 | gdouble step, | |||
1482 | gdouble page) | |||
1483 | { | |||
1484 | CtkAdjustment *adjustment; | |||
1485 | ||||
1486 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1487 | ||||
1488 | adjustment = range->priv->adjustment; | |||
1489 | ||||
1490 | ctk_adjustment_configure (adjustment, | |||
1491 | ctk_adjustment_get_value (adjustment), | |||
1492 | ctk_adjustment_get_lower (adjustment), | |||
1493 | ctk_adjustment_get_upper (adjustment), | |||
1494 | step, | |||
1495 | page, | |||
1496 | ctk_adjustment_get_page_size (adjustment)); | |||
1497 | } | |||
1498 | ||||
1499 | /** | |||
1500 | * ctk_range_set_range: | |||
1501 | * @range: a #CtkRange | |||
1502 | * @min: minimum range value | |||
1503 | * @max: maximum range value | |||
1504 | * | |||
1505 | * Sets the allowable values in the #CtkRange, and clamps the range | |||
1506 | * value to be between @min and @max. (If the range has a non-zero | |||
1507 | * page size, it is clamped between @min and @max - page-size.) | |||
1508 | **/ | |||
1509 | void | |||
1510 | ctk_range_set_range (CtkRange *range, | |||
1511 | gdouble min, | |||
1512 | gdouble max) | |||
1513 | { | |||
1514 | CtkRangePrivate *priv; | |||
1515 | CtkAdjustment *adjustment; | |||
1516 | gdouble value; | |||
1517 | ||||
1518 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1519 | g_return_if_fail (min <= max)do { if ((min <= max)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "min <= max"); return ; } } while (0); | |||
1520 | ||||
1521 | priv = range->priv; | |||
1522 | adjustment = priv->adjustment; | |||
1523 | ||||
1524 | value = ctk_adjustment_get_value (adjustment); | |||
1525 | if (priv->restrict_to_fill_level) | |||
1526 | value = MIN (value, MAX (ctk_adjustment_get_lower (adjustment),(((value) < ((((ctk_adjustment_get_lower (adjustment)) > (priv->fill_level)) ? (ctk_adjustment_get_lower (adjustment )) : (priv->fill_level)))) ? (value) : ((((ctk_adjustment_get_lower (adjustment)) > (priv->fill_level)) ? (ctk_adjustment_get_lower (adjustment)) : (priv->fill_level)))) | |||
1527 | priv->fill_level))(((value) < ((((ctk_adjustment_get_lower (adjustment)) > (priv->fill_level)) ? (ctk_adjustment_get_lower (adjustment )) : (priv->fill_level)))) ? (value) : ((((ctk_adjustment_get_lower (adjustment)) > (priv->fill_level)) ? (ctk_adjustment_get_lower (adjustment)) : (priv->fill_level)))); | |||
1528 | ||||
1529 | ctk_adjustment_configure (adjustment, | |||
1530 | value, | |||
1531 | min, | |||
1532 | max, | |||
1533 | ctk_adjustment_get_step_increment (adjustment), | |||
1534 | ctk_adjustment_get_page_increment (adjustment), | |||
1535 | ctk_adjustment_get_page_size (adjustment)); | |||
1536 | } | |||
1537 | ||||
1538 | /** | |||
1539 | * ctk_range_set_value: | |||
1540 | * @range: a #CtkRange | |||
1541 | * @value: new value of the range | |||
1542 | * | |||
1543 | * Sets the current value of the range; if the value is outside the | |||
1544 | * minimum or maximum range values, it will be clamped to fit inside | |||
1545 | * them. The range emits the #CtkRange::value-changed signal if the | |||
1546 | * value changes. | |||
1547 | **/ | |||
1548 | void | |||
1549 | ctk_range_set_value (CtkRange *range, | |||
1550 | gdouble value) | |||
1551 | { | |||
1552 | CtkRangePrivate *priv; | |||
1553 | ||||
1554 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1555 | ||||
1556 | priv = range->priv; | |||
1557 | ||||
1558 | if (priv->restrict_to_fill_level) | |||
1559 | value = MIN (value, MAX (ctk_adjustment_get_lower (priv->adjustment),(((value) < ((((ctk_adjustment_get_lower (priv->adjustment )) > (priv->fill_level)) ? (ctk_adjustment_get_lower (priv ->adjustment)) : (priv->fill_level)))) ? (value) : (((( ctk_adjustment_get_lower (priv->adjustment)) > (priv-> fill_level)) ? (ctk_adjustment_get_lower (priv->adjustment )) : (priv->fill_level)))) | |||
1560 | priv->fill_level))(((value) < ((((ctk_adjustment_get_lower (priv->adjustment )) > (priv->fill_level)) ? (ctk_adjustment_get_lower (priv ->adjustment)) : (priv->fill_level)))) ? (value) : (((( ctk_adjustment_get_lower (priv->adjustment)) > (priv-> fill_level)) ? (ctk_adjustment_get_lower (priv->adjustment )) : (priv->fill_level)))); | |||
1561 | ||||
1562 | ctk_adjustment_set_value (priv->adjustment, value); | |||
1563 | } | |||
1564 | ||||
1565 | /** | |||
1566 | * ctk_range_get_value: | |||
1567 | * @range: a #CtkRange | |||
1568 | * | |||
1569 | * Gets the current value of the range. | |||
1570 | * | |||
1571 | * Returns: current value of the range. | |||
1572 | **/ | |||
1573 | gdouble | |||
1574 | ctk_range_get_value (CtkRange *range) | |||
1575 | { | |||
1576 | g_return_val_if_fail (CTK_IS_RANGE (range), 0.0)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return (0.0); } } while (0); | |||
1577 | ||||
1578 | return ctk_adjustment_get_value (range->priv->adjustment); | |||
1579 | } | |||
1580 | ||||
1581 | /** | |||
1582 | * ctk_range_set_show_fill_level: | |||
1583 | * @range: A #CtkRange | |||
1584 | * @show_fill_level: Whether a fill level indicator graphics is shown. | |||
1585 | * | |||
1586 | * Sets whether a graphical fill level is show on the trough. See | |||
1587 | * ctk_range_set_fill_level() for a general description of the fill | |||
1588 | * level concept. | |||
1589 | * | |||
1590 | * Since: 2.12 | |||
1591 | **/ | |||
1592 | void | |||
1593 | ctk_range_set_show_fill_level (CtkRange *range, | |||
1594 | gboolean show_fill_level) | |||
1595 | { | |||
1596 | CtkRangePrivate *priv; | |||
1597 | ||||
1598 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1599 | ||||
1600 | priv = range->priv; | |||
1601 | ||||
1602 | show_fill_level = show_fill_level ? TRUE(!(0)) : FALSE(0); | |||
1603 | ||||
1604 | if (show_fill_level == priv->show_fill_level) | |||
1605 | return; | |||
1606 | ||||
1607 | priv->show_fill_level = show_fill_level; | |||
1608 | ||||
1609 | if (show_fill_level) | |||
1610 | { | |||
1611 | priv->fill_gadget = ctk_css_custom_gadget_new ("fill", | |||
1612 | CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), | |||
1613 | priv->trough_gadget, NULL((void*)0), | |||
1614 | NULL((void*)0), NULL((void*)0), NULL((void*)0), | |||
1615 | NULL((void*)0), NULL((void*)0)); | |||
1616 | ctk_css_gadget_set_state (priv->fill_gadget, | |||
1617 | ctk_css_node_get_state (ctk_css_gadget_get_node (priv->trough_gadget))); | |||
1618 | ||||
1619 | update_fill_position (range); | |||
1620 | } | |||
1621 | else | |||
1622 | { | |||
1623 | ctk_css_node_set_parent (ctk_css_gadget_get_node (priv->fill_gadget), NULL((void*)0)); | |||
1624 | g_clear_object (&priv->fill_gadget)do { _Static_assert (sizeof *((&priv->fill_gadget)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->fill_gadget))) _pp = ((&priv->fill_gadget )); __typeof__ (*((&priv->fill_gadget))) _ptr = *_pp; * _pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while ( 0); | |||
1625 | } | |||
1626 | ||||
1627 | g_object_notify_by_pspec (G_OBJECT (range)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), (((GType) ((20) << (2)))))))), properties[PROP_SHOW_FILL_LEVEL]); | |||
1628 | ctk_widget_queue_allocate (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
1629 | } | |||
1630 | ||||
1631 | /** | |||
1632 | * ctk_range_get_show_fill_level: | |||
1633 | * @range: A #CtkRange | |||
1634 | * | |||
1635 | * Gets whether the range displays the fill level graphically. | |||
1636 | * | |||
1637 | * Returns: %TRUE if @range shows the fill level. | |||
1638 | * | |||
1639 | * Since: 2.12 | |||
1640 | **/ | |||
1641 | gboolean | |||
1642 | ctk_range_get_show_fill_level (CtkRange *range) | |||
1643 | { | |||
1644 | g_return_val_if_fail (CTK_IS_RANGE (range), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return ((0)); } } while (0); | |||
1645 | ||||
1646 | return range->priv->show_fill_level; | |||
1647 | } | |||
1648 | ||||
1649 | /** | |||
1650 | * ctk_range_set_restrict_to_fill_level: | |||
1651 | * @range: A #CtkRange | |||
1652 | * @restrict_to_fill_level: Whether the fill level restricts slider movement. | |||
1653 | * | |||
1654 | * Sets whether the slider is restricted to the fill level. See | |||
1655 | * ctk_range_set_fill_level() for a general description of the fill | |||
1656 | * level concept. | |||
1657 | * | |||
1658 | * Since: 2.12 | |||
1659 | **/ | |||
1660 | void | |||
1661 | ctk_range_set_restrict_to_fill_level (CtkRange *range, | |||
1662 | gboolean restrict_to_fill_level) | |||
1663 | { | |||
1664 | CtkRangePrivate *priv; | |||
1665 | ||||
1666 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1667 | ||||
1668 | priv = range->priv; | |||
1669 | ||||
1670 | restrict_to_fill_level = restrict_to_fill_level ? TRUE(!(0)) : FALSE(0); | |||
1671 | ||||
1672 | if (restrict_to_fill_level != priv->restrict_to_fill_level) | |||
1673 | { | |||
1674 | priv->restrict_to_fill_level = restrict_to_fill_level; | |||
1675 | g_object_notify_by_pspec (G_OBJECT (range)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), (((GType) ((20) << (2)))))))), properties[PROP_RESTRICT_TO_FILL_LEVEL]); | |||
1676 | ||||
1677 | ctk_range_set_value (range, ctk_range_get_value (range)); | |||
1678 | } | |||
1679 | } | |||
1680 | ||||
1681 | /** | |||
1682 | * ctk_range_get_restrict_to_fill_level: | |||
1683 | * @range: A #CtkRange | |||
1684 | * | |||
1685 | * Gets whether the range is restricted to the fill level. | |||
1686 | * | |||
1687 | * Returns: %TRUE if @range is restricted to the fill level. | |||
1688 | * | |||
1689 | * Since: 2.12 | |||
1690 | **/ | |||
1691 | gboolean | |||
1692 | ctk_range_get_restrict_to_fill_level (CtkRange *range) | |||
1693 | { | |||
1694 | g_return_val_if_fail (CTK_IS_RANGE (range), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return ((0)); } } while (0); | |||
1695 | ||||
1696 | return range->priv->restrict_to_fill_level; | |||
1697 | } | |||
1698 | ||||
1699 | /** | |||
1700 | * ctk_range_set_fill_level: | |||
1701 | * @range: a #CtkRange | |||
1702 | * @fill_level: the new position of the fill level indicator | |||
1703 | * | |||
1704 | * Set the new position of the fill level indicator. | |||
1705 | * | |||
1706 | * The “fill level” is probably best described by its most prominent | |||
1707 | * use case, which is an indicator for the amount of pre-buffering in | |||
1708 | * a streaming media player. In that use case, the value of the range | |||
1709 | * would indicate the current play position, and the fill level would | |||
1710 | * be the position up to which the file/stream has been downloaded. | |||
1711 | * | |||
1712 | * This amount of prebuffering can be displayed on the range’s trough | |||
1713 | * and is themeable separately from the trough. To enable fill level | |||
1714 | * display, use ctk_range_set_show_fill_level(). The range defaults | |||
1715 | * to not showing the fill level. | |||
1716 | * | |||
1717 | * Additionally, it’s possible to restrict the range’s slider position | |||
1718 | * to values which are smaller than the fill level. This is controller | |||
1719 | * by ctk_range_set_restrict_to_fill_level() and is by default | |||
1720 | * enabled. | |||
1721 | * | |||
1722 | * Since: 2.12 | |||
1723 | **/ | |||
1724 | void | |||
1725 | ctk_range_set_fill_level (CtkRange *range, | |||
1726 | gdouble fill_level) | |||
1727 | { | |||
1728 | CtkRangePrivate *priv; | |||
1729 | ||||
1730 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
1731 | ||||
1732 | priv = range->priv; | |||
1733 | ||||
1734 | if (fill_level != priv->fill_level) | |||
1735 | { | |||
1736 | priv->fill_level = fill_level; | |||
1737 | g_object_notify_by_pspec (G_OBJECT (range)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), (((GType) ((20) << (2)))))))), properties[PROP_FILL_LEVEL]); | |||
1738 | ||||
1739 | if (priv->show_fill_level) | |||
1740 | ctk_widget_queue_allocate (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
1741 | ||||
1742 | if (priv->restrict_to_fill_level) | |||
1743 | ctk_range_set_value (range, ctk_range_get_value (range)); | |||
1744 | } | |||
1745 | } | |||
1746 | ||||
1747 | /** | |||
1748 | * ctk_range_get_fill_level: | |||
1749 | * @range: A #CtkRange | |||
1750 | * | |||
1751 | * Gets the current position of the fill level indicator. | |||
1752 | * | |||
1753 | * Returns: The current fill level | |||
1754 | * | |||
1755 | * Since: 2.12 | |||
1756 | **/ | |||
1757 | gdouble | |||
1758 | ctk_range_get_fill_level (CtkRange *range) | |||
1759 | { | |||
1760 | g_return_val_if_fail (CTK_IS_RANGE (range), 0.0)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return (0.0); } } while (0); | |||
1761 | ||||
1762 | return range->priv->fill_level; | |||
1763 | } | |||
1764 | ||||
1765 | static void | |||
1766 | ctk_range_destroy (CtkWidget *widget) | |||
1767 | { | |||
1768 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
1769 | CtkRangePrivate *priv = range->priv; | |||
1770 | ||||
1771 | ctk_range_remove_step_timer (range); | |||
1772 | ||||
1773 | if (priv->adjustment) | |||
1774 | { | |||
1775 | g_signal_handlers_disconnect_by_func (priv->adjustment,g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_changed), (range)) | |||
1776 | ctk_range_adjustment_changed,g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_changed), (range)) | |||
1777 | range)g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_changed), (range)); | |||
1778 | g_signal_handlers_disconnect_by_func (priv->adjustment,g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_value_changed), (range )) | |||
1779 | ctk_range_adjustment_value_changed,g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_value_changed), (range )) | |||
1780 | range)g_signal_handlers_disconnect_matched ((priv->adjustment), ( GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA) , 0, 0, ((void*)0), (ctk_range_adjustment_value_changed), (range )); | |||
1781 | g_object_unref (priv->adjustment); | |||
1782 | priv->adjustment = NULL((void*)0); | |||
1783 | } | |||
1784 | ||||
1785 | if (priv->n_marks) | |||
1786 | { | |||
1787 | g_free (priv->marks); | |||
1788 | priv->marks = NULL((void*)0); | |||
1789 | g_free (priv->mark_pos); | |||
1790 | priv->mark_pos = NULL((void*)0); | |||
1791 | priv->n_marks = 0; | |||
1792 | } | |||
1793 | ||||
1794 | CTK_WIDGET_CLASS (ctk_range_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_range_parent_class)), ((ctk_widget_get_type ()))))))->destroy (widget); | |||
1795 | } | |||
1796 | ||||
1797 | static void | |||
1798 | ctk_range_finalize (GObject *object) | |||
1799 | { | |||
1800 | CtkRange *range = CTK_RANGE (object)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_range_get_type ())))))); | |||
1801 | CtkRangePrivate *priv = range->priv; | |||
1802 | ||||
1803 | g_clear_object (&priv->drag_gesture)do { _Static_assert (sizeof *((&priv->drag_gesture)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->drag_gesture))) _pp = ((&priv->drag_gesture )); __typeof__ (*((&priv->drag_gesture))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1804 | g_clear_object (&priv->multipress_gesture)do { _Static_assert (sizeof *((&priv->multipress_gesture )) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->multipress_gesture))) _pp = ((&priv-> multipress_gesture)); __typeof__ (*((&priv->multipress_gesture ))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref ) (_ptr); } while (0); | |||
1805 | g_clear_object (&priv->long_press_gesture)do { _Static_assert (sizeof *((&priv->long_press_gesture )) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->long_press_gesture))) _pp = ((&priv-> long_press_gesture)); __typeof__ (*((&priv->long_press_gesture ))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref ) (_ptr); } while (0); | |||
1806 | ||||
1807 | g_clear_object (&priv->gadget)do { _Static_assert (sizeof *((&priv->gadget)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ ((( &priv->gadget))) _pp = ((&priv->gadget)); __typeof__ (*((&priv->gadget))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1808 | g_clear_object (&priv->contents_gadget)do { _Static_assert (sizeof *((&priv->contents_gadget) ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->contents_gadget))) _pp = ((&priv->contents_gadget )); __typeof__ (*((&priv->contents_gadget))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1809 | g_clear_object (&priv->trough_gadget)do { _Static_assert (sizeof *((&priv->trough_gadget)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->trough_gadget))) _pp = ((&priv->trough_gadget )); __typeof__ (*((&priv->trough_gadget))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1810 | g_clear_object (&priv->fill_gadget)do { _Static_assert (sizeof *((&priv->fill_gadget)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->fill_gadget))) _pp = ((&priv->fill_gadget )); __typeof__ (*((&priv->fill_gadget))) _ptr = *_pp; * _pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while ( 0); | |||
1811 | g_clear_object (&priv->highlight_gadget)do { _Static_assert (sizeof *((&priv->highlight_gadget )) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->highlight_gadget))) _pp = ((&priv->highlight_gadget )); __typeof__ (*((&priv->highlight_gadget))) _ptr = * _pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1812 | g_clear_object (&priv->slider_gadget)do { _Static_assert (sizeof *((&priv->slider_gadget)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->slider_gadget))) _pp = ((&priv->slider_gadget )); __typeof__ (*((&priv->slider_gadget))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1813 | g_clear_object (&priv->stepper_a_gadget)do { _Static_assert (sizeof *((&priv->stepper_a_gadget )) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->stepper_a_gadget))) _pp = ((&priv->stepper_a_gadget )); __typeof__ (*((&priv->stepper_a_gadget))) _ptr = * _pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1814 | g_clear_object (&priv->stepper_b_gadget)do { _Static_assert (sizeof *((&priv->stepper_b_gadget )) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->stepper_b_gadget))) _pp = ((&priv->stepper_b_gadget )); __typeof__ (*((&priv->stepper_b_gadget))) _ptr = * _pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1815 | g_clear_object (&priv->stepper_c_gadget)do { _Static_assert (sizeof *((&priv->stepper_c_gadget )) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->stepper_c_gadget))) _pp = ((&priv->stepper_c_gadget )); __typeof__ (*((&priv->stepper_c_gadget))) _ptr = * _pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1816 | g_clear_object (&priv->stepper_d_gadget)do { _Static_assert (sizeof *((&priv->stepper_d_gadget )) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->stepper_d_gadget))) _pp = ((&priv->stepper_d_gadget )); __typeof__ (*((&priv->stepper_d_gadget))) _ptr = * _pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
1817 | ||||
1818 | G_OBJECT_CLASS (ctk_range_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_range_parent_class)), (((GType) ((20) << (2))) )))))->finalize (object); | |||
1819 | } | |||
1820 | ||||
1821 | static void | |||
1822 | ctk_range_measure_trough (CtkCssGadget *gadget, | |||
1823 | CtkOrientation orientation, | |||
1824 | gint for_size, | |||
1825 | gint *minimum, | |||
1826 | gint *natural, | |||
1827 | gint *minimum_baseline G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1828 | gint *natural_baseline G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1829 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
1830 | { | |||
1831 | CtkWidget *widget = ctk_css_gadget_get_owner (gadget); | |||
1832 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
1833 | CtkRangePrivate *priv = range->priv; | |||
1834 | gint min, nat; | |||
1835 | ||||
1836 | ctk_css_gadget_get_preferred_size (priv->slider_gadget, | |||
1837 | orientation, -1, | |||
1838 | minimum, natural, | |||
1839 | NULL((void*)0), NULL((void*)0)); | |||
1840 | ||||
1841 | if (priv->fill_gadget) | |||
1842 | { | |||
1843 | ctk_css_gadget_get_preferred_size (priv->fill_gadget, | |||
1844 | orientation, for_size, | |||
1845 | &min, &nat, | |||
1846 | NULL((void*)0), NULL((void*)0)); | |||
1847 | *minimum = MAX (*minimum, min)(((*minimum) > (min)) ? (*minimum) : (min)); | |||
1848 | *natural = MAX (*natural, nat)(((*natural) > (nat)) ? (*natural) : (nat)); | |||
1849 | } | |||
1850 | ||||
1851 | if (priv->highlight_gadget) | |||
1852 | { | |||
1853 | ctk_css_gadget_get_preferred_size (priv->highlight_gadget, | |||
1854 | orientation, for_size, | |||
1855 | &min, &nat, | |||
1856 | NULL((void*)0), NULL((void*)0)); | |||
1857 | *minimum = MAX (*minimum, min)(((*minimum) > (min)) ? (*minimum) : (min)); | |||
1858 | *natural = MAX (*natural, nat)(((*natural) > (nat)) ? (*natural) : (nat)); | |||
1859 | } | |||
1860 | } | |||
1861 | ||||
1862 | static void | |||
1863 | ctk_range_measure (CtkCssGadget *gadget, | |||
1864 | CtkOrientation orientation, | |||
1865 | gint for_size G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1866 | gint *minimum, | |||
1867 | gint *natural, | |||
1868 | gint *minimum_baseline G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1869 | gint *natural_baseline G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1870 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
1871 | { | |||
1872 | CtkWidget *widget = ctk_css_gadget_get_owner (gadget); | |||
1873 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
1874 | CtkRangePrivate *priv = range->priv; | |||
1875 | CtkBorder border = { 0 }; | |||
1876 | ||||
1877 | /* Measure the main box */ | |||
1878 | ctk_css_gadget_get_preferred_size (priv->contents_gadget, | |||
1879 | orientation, | |||
1880 | -1, | |||
1881 | minimum, natural, | |||
1882 | NULL((void*)0), NULL((void*)0)); | |||
1883 | ||||
1884 | if (CTK_RANGE_GET_CLASS (range)((((CtkRangeClass*) (((GTypeInstance*) ((range)))->g_class ))))->get_range_border) | |||
1885 | CTK_RANGE_GET_CLASS (range)((((CtkRangeClass*) (((GTypeInstance*) ((range)))->g_class ))))->get_range_border (range, &border); | |||
1886 | ||||
1887 | /* Add the border */ | |||
1888 | if (orientation == CTK_ORIENTATION_HORIZONTAL) | |||
1889 | { | |||
1890 | *minimum += border.left + border.right; | |||
1891 | *natural += border.left + border.right; | |||
1892 | } | |||
1893 | else | |||
1894 | { | |||
1895 | *minimum += border.top + border.bottom; | |||
1896 | *natural += border.top + border.bottom; | |||
1897 | } | |||
1898 | } | |||
1899 | ||||
1900 | static void | |||
1901 | ctk_range_size_request (CtkWidget *widget, | |||
1902 | CtkOrientation orientation, | |||
1903 | gint *minimum, | |||
1904 | gint *natural) | |||
1905 | { | |||
1906 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
1907 | CtkRangePrivate *priv = range->priv; | |||
1908 | ||||
1909 | ctk_css_gadget_get_preferred_size (priv->gadget, orientation, -1, | |||
1910 | minimum, natural, | |||
1911 | NULL((void*)0), NULL((void*)0)); | |||
1912 | ||||
1913 | if (CTK_RANGE_GET_CLASS (range)((((CtkRangeClass*) (((GTypeInstance*) ((range)))->g_class ))))->get_range_size_request) | |||
1914 | { | |||
1915 | gint min, nat; | |||
1916 | ||||
1917 | CTK_RANGE_GET_CLASS (range)((((CtkRangeClass*) (((GTypeInstance*) ((range)))->g_class ))))->get_range_size_request (range, orientation, | |||
1918 | &min, &nat); | |||
1919 | ||||
1920 | *minimum = MAX (*minimum, min)(((*minimum) > (min)) ? (*minimum) : (min)); | |||
1921 | *natural = MAX (*natural, nat)(((*natural) > (nat)) ? (*natural) : (nat)); | |||
1922 | } | |||
1923 | } | |||
1924 | ||||
1925 | static void | |||
1926 | ctk_range_get_preferred_width (CtkWidget *widget, | |||
1927 | gint *minimum, | |||
1928 | gint *natural) | |||
1929 | { | |||
1930 | ctk_range_size_request (widget, CTK_ORIENTATION_HORIZONTAL, | |||
1931 | minimum, natural); | |||
1932 | } | |||
1933 | ||||
1934 | static void | |||
1935 | ctk_range_get_preferred_height (CtkWidget *widget, | |||
1936 | gint *minimum, | |||
1937 | gint *natural) | |||
1938 | { | |||
1939 | ctk_range_size_request (widget, CTK_ORIENTATION_VERTICAL, | |||
1940 | minimum, natural); | |||
1941 | } | |||
1942 | ||||
1943 | static void | |||
1944 | ctk_range_allocate_trough (CtkCssGadget *gadget, | |||
1945 | const CtkAllocation *allocation, | |||
1946 | int baseline, | |||
1947 | CtkAllocation *out_clip, | |||
1948 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
1949 | { | |||
1950 | CtkWidget *widget = ctk_css_gadget_get_owner (gadget); | |||
1951 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
1952 | CtkRangePrivate *priv = range->priv; | |||
1953 | CtkAllocation slider_alloc, widget_alloc; | |||
1954 | ||||
1955 | /* Slider */ | |||
1956 | ctk_range_calc_marks (range); | |||
1957 | ctk_range_calc_stepper_sensitivity (range); | |||
1958 | ||||
1959 | ctk_widget_get_allocation (widget, &widget_alloc); | |||
1960 | ctk_range_compute_slider_position (range, | |||
1961 | ctk_adjustment_get_value (priv->adjustment), | |||
1962 | &slider_alloc); | |||
1963 | slider_alloc.x += widget_alloc.x; | |||
1964 | slider_alloc.y += widget_alloc.y; | |||
1965 | ||||
1966 | ctk_css_gadget_allocate (priv->slider_gadget, | |||
1967 | &slider_alloc, | |||
1968 | ctk_widget_get_allocated_baseline (widget), | |||
1969 | out_clip); | |||
1970 | ||||
1971 | if (priv->show_fill_level && | |||
1972 | ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment) - | |||
1973 | ctk_adjustment_get_lower (priv->adjustment) != 0) | |||
1974 | { | |||
1975 | gdouble level, fill; | |||
1976 | CtkAllocation fill_alloc, fill_clip; | |||
1977 | ||||
1978 | fill_alloc = *allocation; | |||
1979 | ||||
1980 | level = CLAMP (priv->fill_level,(((priv->fill_level) > (ctk_adjustment_get_upper (priv-> adjustment) - ctk_adjustment_get_page_size (priv->adjustment ))) ? (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment)) : (((priv->fill_level) < (ctk_adjustment_get_lower (priv->adjustment))) ? (ctk_adjustment_get_lower (priv-> adjustment)) : (priv->fill_level))) | |||
1981 | ctk_adjustment_get_lower (priv->adjustment),(((priv->fill_level) > (ctk_adjustment_get_upper (priv-> adjustment) - ctk_adjustment_get_page_size (priv->adjustment ))) ? (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment)) : (((priv->fill_level) < (ctk_adjustment_get_lower (priv->adjustment))) ? (ctk_adjustment_get_lower (priv-> adjustment)) : (priv->fill_level))) | |||
1982 | ctk_adjustment_get_upper (priv->adjustment) -(((priv->fill_level) > (ctk_adjustment_get_upper (priv-> adjustment) - ctk_adjustment_get_page_size (priv->adjustment ))) ? (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment)) : (((priv->fill_level) < (ctk_adjustment_get_lower (priv->adjustment))) ? (ctk_adjustment_get_lower (priv-> adjustment)) : (priv->fill_level))) | |||
1983 | ctk_adjustment_get_page_size (priv->adjustment))(((priv->fill_level) > (ctk_adjustment_get_upper (priv-> adjustment) - ctk_adjustment_get_page_size (priv->adjustment ))) ? (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment)) : (((priv->fill_level) < (ctk_adjustment_get_lower (priv->adjustment))) ? (ctk_adjustment_get_lower (priv-> adjustment)) : (priv->fill_level))); | |||
1984 | ||||
1985 | fill = (level - ctk_adjustment_get_lower (priv->adjustment)) / | |||
1986 | (ctk_adjustment_get_upper (priv->adjustment) - | |||
1987 | ctk_adjustment_get_lower (priv->adjustment) - | |||
1988 | ctk_adjustment_get_page_size (priv->adjustment)); | |||
1989 | ||||
1990 | if (priv->orientation == CTK_ORIENTATION_HORIZONTAL) | |||
1991 | { | |||
1992 | fill_alloc.width *= fill; | |||
1993 | ||||
1994 | if (should_invert (range)) | |||
1995 | fill_alloc.x += allocation->width - fill_alloc.width; | |||
1996 | } | |||
1997 | else | |||
1998 | { | |||
1999 | fill_alloc.height *= fill; | |||
2000 | ||||
2001 | if (should_invert (range)) | |||
2002 | fill_alloc.y += allocation->height - fill_alloc.height; | |||
2003 | } | |||
2004 | ||||
2005 | ctk_css_gadget_allocate (priv->fill_gadget, | |||
2006 | &fill_alloc, | |||
2007 | baseline, | |||
2008 | &fill_clip); | |||
2009 | cdk_rectangle_union (out_clip, &fill_clip, out_clip); | |||
2010 | } | |||
2011 | ||||
2012 | if (priv->has_origin) | |||
2013 | { | |||
2014 | CtkAllocation highlight_alloc, highlight_clip; | |||
2015 | int min, nat; | |||
2016 | ||||
2017 | ctk_css_gadget_get_preferred_size (priv->highlight_gadget, | |||
2018 | priv->orientation, -1, | |||
2019 | &min, &nat, | |||
2020 | NULL((void*)0), NULL((void*)0)); | |||
2021 | ||||
2022 | highlight_alloc = *allocation; | |||
2023 | ||||
2024 | if (priv->orientation == CTK_ORIENTATION_HORIZONTAL) | |||
2025 | { | |||
2026 | int x = slider_alloc.x + slider_alloc.width / 2; | |||
2027 | ||||
2028 | if (!should_invert (range)) | |||
2029 | { | |||
2030 | highlight_alloc.x = allocation->x; | |||
2031 | highlight_alloc.width = MAX (x - allocation->x, min)(((x - allocation->x) > (min)) ? (x - allocation->x) : (min)); | |||
2032 | } | |||
2033 | else | |||
2034 | { | |||
2035 | highlight_alloc.width = MAX (allocation->x + allocation->width - x, min)(((allocation->x + allocation->width - x) > (min)) ? (allocation->x + allocation->width - x) : (min)); | |||
2036 | highlight_alloc.x = allocation->x + allocation->width - highlight_alloc.width; | |||
2037 | } | |||
2038 | } | |||
2039 | else | |||
2040 | { | |||
2041 | int y = slider_alloc.y + slider_alloc.height / 2; | |||
2042 | ||||
2043 | if (!should_invert (range)) | |||
2044 | { | |||
2045 | highlight_alloc.y = allocation->y; | |||
2046 | highlight_alloc.height = MAX (y - allocation->y, min)(((y - allocation->y) > (min)) ? (y - allocation->y) : (min)); | |||
2047 | } | |||
2048 | else | |||
2049 | { | |||
2050 | highlight_alloc.height = MAX (allocation->y + allocation->height - y, min)(((allocation->y + allocation->height - y) > (min)) ? (allocation->y + allocation->height - y) : (min)); | |||
2051 | highlight_alloc.y = allocation->y + allocation->height - highlight_alloc.height; | |||
2052 | } | |||
2053 | } | |||
2054 | ||||
2055 | ctk_css_gadget_allocate (priv->highlight_gadget, | |||
2056 | &highlight_alloc, | |||
2057 | baseline, | |||
2058 | &highlight_clip); | |||
2059 | cdk_rectangle_union (out_clip, &highlight_clip, out_clip); | |||
2060 | } | |||
2061 | } | |||
2062 | ||||
2063 | /* Clamp dimensions and border inside allocation, such that we prefer | |||
2064 | * to take space from border not dimensions in all directions, and prefer to | |||
2065 | * give space to border over dimensions in one direction. | |||
2066 | */ | |||
2067 | static void | |||
2068 | clamp_dimensions (const CtkAllocation *allocation, | |||
2069 | int *width, | |||
2070 | int *height, | |||
2071 | CtkBorder *border, | |||
2072 | gboolean border_expands_horizontally) | |||
2073 | { | |||
2074 | gint extra, shortage; | |||
2075 | ||||
2076 | /* Width */ | |||
2077 | extra = allocation->width - border->left - border->right - *width; | |||
2078 | if (extra > 0) | |||
2079 | { | |||
2080 | if (border_expands_horizontally) | |||
2081 | { | |||
2082 | border->left += extra / 2; | |||
2083 | border->right += extra / 2 + extra % 2; | |||
2084 | } | |||
2085 | else | |||
2086 | { | |||
2087 | *width += extra; | |||
2088 | } | |||
2089 | } | |||
2090 | ||||
2091 | /* See if we can fit rect, if not kill the border */ | |||
2092 | shortage = *width - allocation->width; | |||
2093 | if (shortage > 0) | |||
2094 | { | |||
2095 | *width = allocation->width; | |||
2096 | /* lose the border */ | |||
2097 | border->left = 0; | |||
2098 | border->right = 0; | |||
2099 | } | |||
2100 | else | |||
2101 | { | |||
2102 | /* See if we can fit rect with borders */ | |||
2103 | shortage = *width + border->left + border->right - allocation->width; | |||
2104 | if (shortage > 0) | |||
2105 | { | |||
2106 | /* Shrink borders */ | |||
2107 | border->left -= shortage / 2; | |||
2108 | border->right -= shortage / 2 + shortage % 2; | |||
2109 | } | |||
2110 | } | |||
2111 | ||||
2112 | /* Height */ | |||
2113 | extra = allocation->height - border->top - border->bottom - *height; | |||
2114 | if (extra > 0) | |||
2115 | { | |||
2116 | if (border_expands_horizontally) | |||
2117 | { | |||
2118 | /* don't expand border vertically */ | |||
2119 | *height += extra; | |||
2120 | } | |||
2121 | else | |||
2122 | { | |||
2123 | border->top += extra / 2; | |||
2124 | border->bottom += extra / 2 + extra % 2; | |||
2125 | } | |||
2126 | } | |||
2127 | ||||
2128 | /* See if we can fit rect, if not kill the border */ | |||
2129 | shortage = *height - allocation->height; | |||
2130 | if (shortage > 0) | |||
2131 | { | |||
2132 | *height = allocation->height; | |||
2133 | /* lose the border */ | |||
2134 | border->top = 0; | |||
2135 | border->bottom = 0; | |||
2136 | } | |||
2137 | else | |||
2138 | { | |||
2139 | /* See if we can fit rect with borders */ | |||
2140 | shortage = *height + border->top + border->bottom - allocation->height; | |||
2141 | if (shortage > 0) | |||
2142 | { | |||
2143 | /* Shrink borders */ | |||
2144 | border->top -= shortage / 2; | |||
2145 | border->bottom -= shortage / 2 + shortage % 2; | |||
2146 | } | |||
2147 | } | |||
2148 | } | |||
2149 | ||||
2150 | static void | |||
2151 | ctk_range_allocate (CtkCssGadget *gadget, | |||
2152 | const CtkAllocation *allocation, | |||
2153 | int baseline, | |||
2154 | CtkAllocation *out_clip, | |||
2155 | gpointer data G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
2156 | { | |||
2157 | CtkWidget *widget = ctk_css_gadget_get_owner (gadget); | |||
2158 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2159 | CtkRangePrivate *priv = range->priv; | |||
2160 | CtkBorder border = { 0 }; | |||
2161 | CtkAllocation box_alloc; | |||
2162 | int box_min_width, box_min_height; | |||
2163 | ||||
2164 | if (CTK_RANGE_GET_CLASS (range)((((CtkRangeClass*) (((GTypeInstance*) ((range)))->g_class ))))->get_range_border) | |||
2165 | CTK_RANGE_GET_CLASS (range)((((CtkRangeClass*) (((GTypeInstance*) ((range)))->g_class ))))->get_range_border (range, &border); | |||
2166 | ||||
2167 | measure_one_gadget (priv->contents_gadget, &box_min_width, &box_min_height); | |||
2168 | ||||
2169 | if (priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
2170 | clamp_dimensions (allocation, &box_min_width, &box_min_height, &border, TRUE(!(0))); | |||
2171 | else | |||
2172 | clamp_dimensions (allocation, &box_min_width, &box_min_height, &border, FALSE(0)); | |||
2173 | ||||
2174 | box_alloc.x = border.left + allocation->x; | |||
2175 | box_alloc.y = border.top + allocation->y; | |||
2176 | box_alloc.width = box_min_width; | |||
2177 | box_alloc.height = box_min_height; | |||
2178 | ||||
2179 | ctk_css_gadget_allocate (priv->contents_gadget, | |||
2180 | &box_alloc, | |||
2181 | baseline, | |||
2182 | out_clip); | |||
2183 | ||||
2184 | /* TODO: we should compute a proper clip from get_range_border(), | |||
2185 | * but this will at least give us outset shadows. | |||
2186 | */ | |||
2187 | cdk_rectangle_union (out_clip, allocation, out_clip); | |||
2188 | } | |||
2189 | ||||
2190 | static void | |||
2191 | ctk_range_size_allocate (CtkWidget *widget, | |||
2192 | CtkAllocation *allocation) | |||
2193 | { | |||
2194 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2195 | CtkRangePrivate *priv = range->priv; | |||
2196 | CtkAllocation clip; | |||
2197 | ||||
2198 | ctk_widget_set_allocation (widget, allocation); | |||
2199 | ||||
2200 | if (ctk_widget_get_realized (widget)) | |||
2201 | cdk_window_move_resize (priv->event_window, | |||
2202 | allocation->x, allocation->y, | |||
2203 | allocation->width, allocation->height); | |||
2204 | ||||
2205 | ctk_css_gadget_allocate (priv->gadget, | |||
2206 | allocation, | |||
2207 | ctk_widget_get_allocated_baseline (widget), | |||
2208 | &clip); | |||
2209 | ctk_widget_set_clip (widget, &clip); | |||
2210 | } | |||
2211 | ||||
2212 | static void | |||
2213 | ctk_range_realize (CtkWidget *widget) | |||
2214 | { | |||
2215 | CtkAllocation allocation; | |||
2216 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2217 | CtkRangePrivate *priv = range->priv; | |||
2218 | CdkWindow *window; | |||
2219 | CdkWindowAttr attributes; | |||
2220 | gint attributes_mask; | |||
2221 | ||||
2222 | ctk_widget_set_realized (widget, TRUE(!(0))); | |||
2223 | ||||
2224 | window = ctk_widget_get_parent_window (widget); | |||
2225 | ctk_widget_set_window (widget, window); | |||
2226 | g_object_ref (window)((__typeof__ (window)) (g_object_ref) (window)); | |||
2227 | ||||
2228 | ctk_widget_get_allocation (widget, &allocation); | |||
2229 | ||||
2230 | attributes.window_type = CDK_WINDOW_CHILD; | |||
2231 | attributes.x = allocation.x; | |||
2232 | attributes.y = allocation.y; | |||
2233 | attributes.width = allocation.width; | |||
2234 | attributes.height = allocation.height; | |||
2235 | attributes.wclass = CDK_INPUT_ONLY; | |||
2236 | attributes.event_mask = ctk_widget_get_events (widget); | |||
2237 | attributes.event_mask |= CDK_BUTTON_PRESS_MASK | | |||
2238 | CDK_BUTTON_RELEASE_MASK | | |||
2239 | CDK_SCROLL_MASK | | |||
2240 | CDK_SMOOTH_SCROLL_MASK | | |||
2241 | CDK_ENTER_NOTIFY_MASK | | |||
2242 | CDK_LEAVE_NOTIFY_MASK | | |||
2243 | CDK_POINTER_MOTION_MASK; | |||
2244 | ||||
2245 | attributes_mask = CDK_WA_X | CDK_WA_Y; | |||
2246 | ||||
2247 | priv->event_window = cdk_window_new (ctk_widget_get_parent_window (widget), | |||
2248 | &attributes, attributes_mask); | |||
2249 | ctk_widget_register_window (widget, priv->event_window); | |||
2250 | } | |||
2251 | ||||
2252 | static void | |||
2253 | ctk_range_unrealize (CtkWidget *widget) | |||
2254 | { | |||
2255 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2256 | CtkRangePrivate *priv = range->priv; | |||
2257 | ||||
2258 | ctk_range_remove_step_timer (range); | |||
2259 | ||||
2260 | ctk_widget_unregister_window (widget, priv->event_window); | |||
2261 | cdk_window_destroy (priv->event_window); | |||
2262 | priv->event_window = NULL((void*)0); | |||
2263 | ||||
2264 | CTK_WIDGET_CLASS (ctk_range_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_range_parent_class)), ((ctk_widget_get_type ()))))))->unrealize (widget); | |||
2265 | } | |||
2266 | ||||
2267 | static void | |||
2268 | ctk_range_map (CtkWidget *widget) | |||
2269 | { | |||
2270 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2271 | CtkRangePrivate *priv = range->priv; | |||
2272 | ||||
2273 | cdk_window_show (priv->event_window); | |||
2274 | ||||
2275 | CTK_WIDGET_CLASS (ctk_range_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_range_parent_class)), ((ctk_widget_get_type ()))))))->map (widget); | |||
2276 | } | |||
2277 | ||||
2278 | static void | |||
2279 | ctk_range_unmap (CtkWidget *widget) | |||
2280 | { | |||
2281 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2282 | CtkRangePrivate *priv = range->priv; | |||
2283 | ||||
2284 | stop_scrolling (range); | |||
2285 | ||||
2286 | cdk_window_hide (priv->event_window); | |||
2287 | ||||
2288 | CTK_WIDGET_CLASS (ctk_range_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_range_parent_class)), ((ctk_widget_get_type ()))))))->unmap (widget); | |||
2289 | } | |||
2290 | ||||
2291 | static void | |||
2292 | update_slider_state (CtkRange *range) | |||
2293 | { | |||
2294 | CtkRangePrivate *priv = range->priv; | |||
2295 | CtkStateFlags state; | |||
2296 | ||||
2297 | state = ctk_widget_get_state_flags (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
2298 | ||||
2299 | state &= ~(CTK_STATE_FLAG_PRELIGHT | CTK_STATE_FLAG_ACTIVE); | |||
2300 | ||||
2301 | if (priv->mouse_location == priv->slider_gadget && | |||
2302 | !(state & CTK_STATE_FLAG_INSENSITIVE)) | |||
2303 | state |= CTK_STATE_FLAG_PRELIGHT; | |||
2304 | ||||
2305 | if (priv->grab_location == priv->slider_gadget) | |||
2306 | state |= CTK_STATE_FLAG_ACTIVE; | |||
2307 | ||||
2308 | ctk_css_gadget_set_state (priv->slider_gadget, state); | |||
2309 | } | |||
2310 | ||||
2311 | static void | |||
2312 | update_trough_state (CtkRange *range) | |||
2313 | { | |||
2314 | CtkRangePrivate *priv = range->priv; | |||
2315 | CtkStateFlags state; | |||
2316 | ||||
2317 | state = ctk_widget_get_state_flags (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
2318 | ||||
2319 | state &= ~(CTK_STATE_FLAG_PRELIGHT | CTK_STATE_FLAG_ACTIVE); | |||
2320 | ||||
2321 | ctk_css_gadget_set_state (priv->contents_gadget, state); | |||
2322 | ||||
2323 | if (priv->mouse_location == priv->trough_gadget && | |||
2324 | !(state & CTK_STATE_FLAG_INSENSITIVE)) | |||
2325 | state |= CTK_STATE_FLAG_PRELIGHT; | |||
2326 | ||||
2327 | if (priv->grab_location == priv->trough_gadget) | |||
2328 | state |= CTK_STATE_FLAG_ACTIVE; | |||
2329 | ||||
2330 | ctk_css_gadget_set_state (priv->trough_gadget, state); | |||
2331 | if (priv->highlight_gadget) | |||
2332 | ctk_css_gadget_set_state (priv->highlight_gadget, state); | |||
2333 | if (priv->fill_gadget) | |||
2334 | ctk_css_gadget_set_state (priv->fill_gadget, state); | |||
2335 | } | |||
2336 | ||||
2337 | static void | |||
2338 | ctk_range_direction_changed (CtkWidget *widget, | |||
2339 | CtkTextDirection previous_direction) | |||
2340 | { | |||
2341 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2342 | ||||
2343 | update_fill_position (range); | |||
2344 | update_highlight_position (range); | |||
2345 | ||||
2346 | CTK_WIDGET_CLASS (ctk_range_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_range_parent_class)), ((ctk_widget_get_type ()))))))->direction_changed (widget, previous_direction); | |||
2347 | } | |||
2348 | ||||
2349 | static void | |||
2350 | ctk_range_state_flags_changed (CtkWidget *widget, | |||
2351 | CtkStateFlags previous_state) | |||
2352 | { | |||
2353 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2354 | ||||
2355 | update_trough_state (range); | |||
2356 | update_slider_state (range); | |||
2357 | update_steppers_state (range); | |||
2358 | ||||
2359 | CTK_WIDGET_CLASS (ctk_range_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_range_parent_class)), ((ctk_widget_get_type ()))))))->state_flags_changed (widget, previous_state); | |||
2360 | } | |||
2361 | ||||
2362 | static gboolean | |||
2363 | ctk_range_render_trough (CtkCssGadget *gadget, | |||
2364 | cairo_t *cr, | |||
2365 | int x, | |||
2366 | int y, | |||
2367 | int width, | |||
2368 | int height, | |||
2369 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
2370 | { | |||
2371 | CtkWidget *widget = ctk_css_gadget_get_owner (gadget); | |||
2372 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2373 | CtkRangePrivate *priv = range->priv; | |||
2374 | ||||
2375 | /* HACK: CtkColorScale wants to draw its own trough | |||
2376 | * so we let it... | |||
2377 | */ | |||
2378 | if (CTK_IS_COLOR_SCALE (widget)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (widget)); GType __t = ((ctk_color_scale_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
2379 | ctk_color_scale_draw_trough (CTK_COLOR_SCALE (widget)((((CtkColorScale*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_color_scale_get_type ())))))), cr, x, y, width, height); | |||
2380 | ||||
2381 | if (priv->show_fill_level && | |||
2382 | ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment) - | |||
2383 | ctk_adjustment_get_lower (priv->adjustment) != 0) | |||
2384 | ctk_css_gadget_draw (priv->fill_gadget, cr); | |||
2385 | ||||
2386 | if (priv->has_origin) | |||
2387 | ctk_css_gadget_draw (priv->highlight_gadget, cr); | |||
2388 | ||||
2389 | return ctk_widget_has_visible_focus (widget); | |||
2390 | } | |||
2391 | ||||
2392 | static gboolean | |||
2393 | ctk_range_render (CtkCssGadget *gadget, | |||
2394 | cairo_t *cr, | |||
2395 | int x G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2396 | int y G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2397 | int width G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2398 | int height G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2399 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
2400 | { | |||
2401 | CtkWidget *widget = ctk_css_gadget_get_owner (gadget); | |||
2402 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2403 | CtkRangePrivate *priv = range->priv; | |||
2404 | ||||
2405 | ctk_css_gadget_draw (priv->contents_gadget, cr); | |||
2406 | ||||
2407 | /* Draw the slider last, so that e.g. the focus ring stays below it */ | |||
2408 | ctk_css_gadget_draw (priv->slider_gadget, cr); | |||
2409 | ||||
2410 | return FALSE(0); | |||
2411 | } | |||
2412 | ||||
2413 | static gboolean | |||
2414 | ctk_range_draw (CtkWidget *widget, | |||
2415 | cairo_t *cr) | |||
2416 | { | |||
2417 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2418 | CtkRangePrivate *priv = range->priv; | |||
2419 | ||||
2420 | ctk_css_gadget_draw (priv->gadget, cr); | |||
2421 | ||||
2422 | return CDK_EVENT_PROPAGATE((0)); | |||
2423 | } | |||
2424 | ||||
2425 | static void | |||
2426 | range_grab_add (CtkRange *range, | |||
2427 | CtkCssGadget *location) | |||
2428 | { | |||
2429 | CtkRangePrivate *priv = range->priv; | |||
2430 | CtkStyleContext *context; | |||
2431 | ||||
2432 | context = ctk_widget_get_style_context (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
2433 | ||||
2434 | /* Don't perform any CDK/CTK+ grab here. Since a button | |||
2435 | * is down, there's an ongoing implicit grab on | |||
2436 | * priv->event_window, which pretty much guarantees this | |||
2437 | * is the only widget receiving the pointer events. | |||
2438 | */ | |||
2439 | priv->grab_location = location; | |||
2440 | ctk_css_gadget_queue_allocate (location); | |||
2441 | ||||
2442 | update_trough_state (range); | |||
2443 | update_slider_state (range); | |||
2444 | update_steppers_state (range); | |||
2445 | ||||
2446 | ctk_style_context_add_class (context, "dragging"); | |||
2447 | ||||
2448 | ctk_grab_add (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
2449 | } | |||
2450 | ||||
2451 | static void | |||
2452 | update_zoom_state (CtkRange *range, | |||
2453 | gboolean enabled) | |||
2454 | { | |||
2455 | CtkStyleContext *context; | |||
2456 | ||||
2457 | context = ctk_widget_get_style_context (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
2458 | ||||
2459 | if (enabled) | |||
2460 | ctk_style_context_add_class (context, "fine-tune"); | |||
2461 | else | |||
2462 | ctk_style_context_remove_class (context, "fine-tune"); | |||
2463 | ||||
2464 | range->priv->zoom = enabled; | |||
2465 | } | |||
2466 | ||||
2467 | static void | |||
2468 | range_grab_remove (CtkRange *range) | |||
2469 | { | |||
2470 | CtkRangePrivate *priv = range->priv; | |||
2471 | CtkStyleContext *context; | |||
2472 | ||||
2473 | if (!priv->grab_location) | |||
2474 | return; | |||
2475 | ||||
2476 | ctk_grab_remove (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
2477 | context = ctk_widget_get_style_context (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
2478 | ||||
2479 | ctk_css_gadget_queue_allocate (priv->grab_location); | |||
2480 | priv->grab_location = NULL((void*)0); | |||
2481 | ||||
2482 | ctk_range_update_mouse_location (range); | |||
2483 | ||||
2484 | update_slider_state (range); | |||
2485 | update_steppers_state (range); | |||
2486 | update_zoom_state (range, FALSE(0)); | |||
2487 | ||||
2488 | ctk_style_context_remove_class (context, "dragging"); | |||
2489 | } | |||
2490 | ||||
2491 | static CtkScrollType | |||
2492 | range_get_scroll_for_grab (CtkRange *range) | |||
2493 | { | |||
2494 | CtkRangePrivate *priv = range->priv; | |||
2495 | guint grab_button; | |||
2496 | gboolean invert; | |||
2497 | ||||
2498 | invert = should_invert (range); | |||
2499 | grab_button = ctk_gesture_single_get_current_button (CTK_GESTURE_SINGLE (range->priv->multipress_gesture)((((CtkGestureSingle*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((range->priv->multipress_gesture)), (( ctk_gesture_single_get_type ()))))))); | |||
2500 | ||||
2501 | if (!priv->grab_location) | |||
2502 | return CTK_SCROLL_NONE; | |||
2503 | ||||
2504 | /* Backward stepper */ | |||
2505 | if (priv->grab_location == priv->stepper_a_gadget || | |||
2506 | priv->grab_location == priv->stepper_c_gadget) | |||
2507 | { | |||
2508 | switch (grab_button) | |||
2509 | { | |||
2510 | case CDK_BUTTON_PRIMARY(1): | |||
2511 | return invert ? CTK_SCROLL_STEP_FORWARD : CTK_SCROLL_STEP_BACKWARD; | |||
2512 | break; | |||
2513 | case CDK_BUTTON_SECONDARY(3): | |||
2514 | return invert ? CTK_SCROLL_PAGE_FORWARD : CTK_SCROLL_PAGE_BACKWARD; | |||
2515 | break; | |||
2516 | case CDK_BUTTON_MIDDLE(2): | |||
2517 | return invert ? CTK_SCROLL_END : CTK_SCROLL_START; | |||
2518 | break; | |||
2519 | default: | |||
2520 | return CTK_SCROLL_NONE; | |||
2521 | } | |||
2522 | } | |||
2523 | ||||
2524 | /* Forward stepper */ | |||
2525 | if (priv->grab_location == priv->stepper_b_gadget || | |||
2526 | priv->grab_location == priv->stepper_d_gadget) | |||
2527 | { | |||
2528 | switch (grab_button) | |||
2529 | { | |||
2530 | case CDK_BUTTON_PRIMARY(1): | |||
2531 | return invert ? CTK_SCROLL_STEP_BACKWARD : CTK_SCROLL_STEP_FORWARD; | |||
2532 | break; | |||
2533 | case CDK_BUTTON_SECONDARY(3): | |||
2534 | return invert ? CTK_SCROLL_PAGE_BACKWARD : CTK_SCROLL_PAGE_FORWARD; | |||
2535 | break; | |||
2536 | case CDK_BUTTON_MIDDLE(2): | |||
2537 | return invert ? CTK_SCROLL_START : CTK_SCROLL_END; | |||
2538 | break; | |||
2539 | default: | |||
2540 | return CTK_SCROLL_NONE; | |||
2541 | } | |||
2542 | } | |||
2543 | ||||
2544 | /* In the trough */ | |||
2545 | if (priv->grab_location == priv->trough_gadget) | |||
2546 | { | |||
2547 | if (priv->trough_click_forward) | |||
2548 | return CTK_SCROLL_PAGE_FORWARD; | |||
2549 | else | |||
2550 | return CTK_SCROLL_PAGE_BACKWARD; | |||
2551 | } | |||
2552 | ||||
2553 | return CTK_SCROLL_NONE; | |||
2554 | } | |||
2555 | ||||
2556 | static gdouble | |||
2557 | coord_to_value (CtkRange *range, | |||
2558 | gdouble coord) | |||
2559 | { | |||
2560 | CtkRangePrivate *priv = range->priv; | |||
2561 | gdouble frac; | |||
2562 | gdouble value; | |||
2563 | gint trough_length; | |||
2564 | gint trough_start; | |||
2565 | gint slider_length; | |||
2566 | CtkAllocation slider_alloc, trough_alloc; | |||
2567 | ||||
2568 | ctk_css_gadget_get_margin_box (priv->slider_gadget, &slider_alloc); | |||
2569 | ctk_css_gadget_get_content_box (priv->trough_gadget, &trough_alloc); | |||
2570 | ||||
2571 | if (priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
2572 | { | |||
2573 | trough_length = trough_alloc.height; | |||
2574 | trough_start = trough_alloc.y; | |||
2575 | slider_length = slider_alloc.height; | |||
2576 | } | |||
2577 | else | |||
2578 | { | |||
2579 | trough_length = trough_alloc.width; | |||
2580 | trough_start = trough_alloc.x; | |||
2581 | slider_length = slider_alloc.width; | |||
2582 | } | |||
2583 | ||||
2584 | if (trough_length == slider_length) | |||
2585 | frac = 1.0; | |||
2586 | else | |||
2587 | frac = (MAX (0, coord - trough_start)(((0) > (coord - trough_start)) ? (0) : (coord - trough_start )) / | |||
2588 | (gdouble) (trough_length - slider_length)); | |||
2589 | ||||
2590 | if (should_invert (range)) | |||
2591 | frac = 1.0 - frac; | |||
2592 | ||||
2593 | value = ctk_adjustment_get_lower (priv->adjustment) + frac * (ctk_adjustment_get_upper (priv->adjustment) - | |||
2594 | ctk_adjustment_get_lower (priv->adjustment) - | |||
2595 | ctk_adjustment_get_page_size (priv->adjustment)); | |||
2596 | return value; | |||
2597 | } | |||
2598 | ||||
2599 | static gboolean | |||
2600 | ctk_range_key_press (CtkWidget *widget, | |||
2601 | CdkEventKey *event) | |||
2602 | { | |||
2603 | CdkDevice *device; | |||
2604 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
2605 | CtkRangePrivate *priv = range->priv; | |||
2606 | ||||
2607 | device = cdk_event_get_device ((CdkEvent *) event); | |||
2608 | device = cdk_device_get_associated_device (device); | |||
2609 | ||||
2610 | if (ctk_gesture_is_active (priv->drag_gesture) && | |||
2611 | device == ctk_gesture_get_device (priv->drag_gesture) && | |||
2612 | event->keyval == CDK_KEY_Escape0xff1b && | |||
2613 | priv->grab_location != NULL((void*)0)) | |||
2614 | { | |||
2615 | stop_scrolling (range); | |||
2616 | ||||
2617 | return CDK_EVENT_STOP((!(0))); | |||
2618 | } | |||
2619 | else if (priv->in_drag && | |||
2620 | (event->keyval == CDK_KEY_Shift_L0xffe1 || | |||
2621 | event->keyval == CDK_KEY_Shift_R0xffe2)) | |||
2622 | { | |||
2623 | CtkAllocation slider_alloc; | |||
2624 | ||||
2625 | ctk_css_gadget_get_margin_box (priv->slider_gadget, &slider_alloc); | |||
2626 | ||||
2627 | if (priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
2628 | priv->slide_initial_slider_position = slider_alloc.y; | |||
2629 | else | |||
2630 | priv->slide_initial_slider_position = slider_alloc.x; | |||
2631 | update_zoom_state (range, !priv->zoom); | |||
2632 | ||||
2633 | return CDK_EVENT_STOP((!(0))); | |||
2634 | } | |||
2635 | ||||
2636 | return CTK_WIDGET_CLASS (ctk_range_parent_class)((((CtkWidgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_range_parent_class)), ((ctk_widget_get_type ()))))))->key_press_event (widget, event); | |||
2637 | } | |||
2638 | ||||
2639 | static void | |||
2640 | update_initial_slider_position (CtkRange *range, | |||
2641 | gdouble x, | |||
2642 | gdouble y, | |||
2643 | CtkAllocation *slider_alloc) | |||
2644 | { | |||
2645 | CtkRangePrivate *priv = range->priv; | |||
2646 | ||||
2647 | if (priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
2648 | { | |||
2649 | priv->slide_initial_slider_position = MAX (0, slider_alloc->y)(((0) > (slider_alloc->y)) ? (0) : (slider_alloc->y) ); | |||
2650 | priv->slide_initial_coordinate_delta = y - priv->slide_initial_slider_position; | |||
2651 | } | |||
2652 | else | |||
2653 | { | |||
2654 | priv->slide_initial_slider_position = MAX (0, slider_alloc->x)(((0) > (slider_alloc->x)) ? (0) : (slider_alloc->x) ); | |||
2655 | priv->slide_initial_coordinate_delta = x - priv->slide_initial_slider_position; | |||
2656 | } | |||
2657 | } | |||
2658 | ||||
2659 | static void | |||
2660 | ctk_range_long_press_gesture_pressed (CtkGestureLongPress *gesture G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2661 | gdouble x, | |||
2662 | gdouble y, | |||
2663 | CtkRange *range) | |||
2664 | { | |||
2665 | CtkRangePrivate *priv = range->priv; | |||
2666 | ||||
2667 | ctk_range_update_mouse_location (range); | |||
2668 | ||||
2669 | if (priv->mouse_location == priv->slider_gadget && !priv->zoom) | |||
2670 | { | |||
2671 | CtkAllocation slider_alloc; | |||
2672 | ||||
2673 | ctk_css_gadget_get_margin_box (priv->slider_gadget, &slider_alloc); | |||
2674 | update_initial_slider_position (range, x, y, &slider_alloc); | |||
2675 | update_zoom_state (range, TRUE(!(0))); | |||
2676 | } | |||
2677 | } | |||
2678 | ||||
2679 | static void | |||
2680 | ctk_range_multipress_gesture_pressed (CtkGestureMultiPress *gesture, | |||
2681 | guint n_press G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2682 | gdouble x, | |||
2683 | gdouble y, | |||
2684 | CtkRange *range) | |||
2685 | { | |||
2686 | CtkWidget *widget = CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))); | |||
2687 | CtkRangePrivate *priv = range->priv; | |||
2688 | CdkDevice *source_device; | |||
2689 | CdkEventSequence *sequence; | |||
2690 | const CdkEvent *event; | |||
2691 | CdkInputSource source; | |||
2692 | gboolean primary_warps; | |||
2693 | gboolean shift_pressed; | |||
2694 | guint button; | |||
2695 | CdkModifierType state_mask; | |||
2696 | CtkAllocation slider_alloc; | |||
2697 | ||||
2698 | if (!ctk_widget_has_focus (widget)) | |||
2699 | ctk_widget_grab_focus (widget); | |||
2700 | ||||
2701 | sequence = ctk_gesture_single_get_current_sequence (CTK_GESTURE_SINGLE (gesture)((((CtkGestureSingle*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((gesture)), ((ctk_gesture_single_get_type () ))))))); | |||
2702 | button = ctk_gesture_single_get_current_button (CTK_GESTURE_SINGLE (gesture)((((CtkGestureSingle*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((gesture)), ((ctk_gesture_single_get_type () ))))))); | |||
2703 | event = ctk_gesture_get_last_event (CTK_GESTURE (gesture)((((CtkGesture*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((gesture)), ((ctk_gesture_get_type ())))))), sequence); | |||
2704 | cdk_event_get_state (event, &state_mask); | |||
2705 | shift_pressed = (state_mask & CDK_SHIFT_MASK) != 0; | |||
2706 | ||||
2707 | source_device = cdk_event_get_source_device ((CdkEvent *) event); | |||
2708 | source = cdk_device_get_source (source_device); | |||
2709 | ||||
2710 | priv->mouse_x = x; | |||
2711 | priv->mouse_y = y; | |||
2712 | ||||
2713 | ctk_range_update_mouse_location (range); | |||
2714 | ctk_css_gadget_get_margin_box (priv->slider_gadget, &slider_alloc); | |||
2715 | ||||
2716 | g_object_get (ctk_widget_get_settings (widget), | |||
2717 | "ctk-primary-button-warps-slider", &primary_warps, | |||
2718 | NULL((void*)0)); | |||
2719 | ||||
2720 | if (priv->mouse_location == priv->slider_gadget && | |||
2721 | cdk_event_triggers_context_menu (event)) | |||
2722 | { | |||
2723 | gboolean handled; | |||
2724 | ||||
2725 | ctk_gesture_set_state (priv->multipress_gesture, CTK_EVENT_SEQUENCE_CLAIMED); | |||
2726 | g_signal_emit_by_name (widget, "popup-menu", &handled); | |||
2727 | return; | |||
2728 | } | |||
2729 | ||||
2730 | if (priv->mouse_location == priv->slider_gadget) | |||
2731 | { | |||
2732 | /* Shift-click in the slider = fine adjustment */ | |||
2733 | if (shift_pressed) | |||
2734 | update_zoom_state (range, TRUE(!(0))); | |||
2735 | ||||
2736 | update_initial_slider_position (range, x, y, &slider_alloc); | |||
2737 | range_grab_add (range, priv->slider_gadget); | |||
2738 | ||||
2739 | ctk_widget_queue_draw (widget); | |||
2740 | } | |||
2741 | else if (priv->mouse_location == priv->stepper_a_gadget || | |||
2742 | priv->mouse_location == priv->stepper_b_gadget || | |||
2743 | priv->mouse_location == priv->stepper_c_gadget || | |||
2744 | priv->mouse_location == priv->stepper_d_gadget) | |||
2745 | { | |||
2746 | CtkScrollType scroll; | |||
2747 | ||||
2748 | range_grab_add (range, priv->mouse_location); | |||
2749 | ||||
2750 | scroll = range_get_scroll_for_grab (range); | |||
2751 | if (scroll == CTK_SCROLL_START || scroll == CTK_SCROLL_END) | |||
2752 | ctk_range_scroll (range, scroll); | |||
2753 | else if (scroll != CTK_SCROLL_NONE) | |||
2754 | { | |||
2755 | remove_autoscroll (range); | |||
2756 | range->priv->autoscroll_mode = scroll; | |||
2757 | add_autoscroll (range); | |||
2758 | } | |||
2759 | } | |||
2760 | else if (priv->mouse_location == priv->trough_gadget && | |||
2761 | (source == CDK_SOURCE_TOUCHSCREEN || | |||
2762 | (primary_warps && !shift_pressed && button == CDK_BUTTON_PRIMARY(1)) || | |||
2763 | (!primary_warps && shift_pressed && button == CDK_BUTTON_PRIMARY(1)) || | |||
2764 | (!primary_warps && button == CDK_BUTTON_MIDDLE(2)))) | |||
2765 | { | |||
2766 | /* warp to location */ | |||
2767 | CdkRectangle slider; | |||
2768 | gdouble slider_low_value, slider_high_value, new_value; | |||
2769 | ||||
2770 | slider_high_value = | |||
2771 | coord_to_value (range, | |||
2772 | priv->orientation == CTK_ORIENTATION_VERTICAL ? | |||
2773 | y : x); | |||
2774 | slider_low_value = | |||
2775 | coord_to_value (range, | |||
2776 | priv->orientation == CTK_ORIENTATION_VERTICAL ? | |||
2777 | y - slider_alloc.height : | |||
2778 | x - slider_alloc.width); | |||
2779 | ||||
2780 | /* compute new value for warped slider */ | |||
2781 | new_value = (slider_low_value + slider_high_value) / 2; | |||
2782 | ||||
2783 | ctk_range_compute_slider_position (range, new_value, &slider); | |||
2784 | update_initial_slider_position (range, x, y, &slider); | |||
2785 | ||||
2786 | range_grab_add (range, priv->slider_gadget); | |||
2787 | ||||
2788 | ctk_widget_queue_draw (widget); | |||
2789 | ||||
2790 | update_slider_position (range, x, y); | |||
2791 | } | |||
2792 | else if (priv->mouse_location == priv->trough_gadget && | |||
2793 | ((primary_warps && shift_pressed && button == CDK_BUTTON_PRIMARY(1)) || | |||
2794 | (!primary_warps && !shift_pressed && button == CDK_BUTTON_PRIMARY(1)) || | |||
2795 | (primary_warps && button == CDK_BUTTON_MIDDLE(2)))) | |||
2796 | { | |||
2797 | /* jump by pages */ | |||
2798 | CtkScrollType scroll; | |||
2799 | gdouble click_value; | |||
2800 | ||||
2801 | click_value = coord_to_value (range, | |||
2802 | priv->orientation == CTK_ORIENTATION_VERTICAL ? | |||
2803 | y : x); | |||
2804 | ||||
2805 | priv->trough_click_forward = click_value > ctk_adjustment_get_value (priv->adjustment); | |||
2806 | range_grab_add (range, priv->trough_gadget); | |||
2807 | ||||
2808 | scroll = range_get_scroll_for_grab (range); | |||
2809 | ctk_range_add_step_timer (range, scroll); | |||
2810 | } | |||
2811 | else if (priv->mouse_location == priv->trough_gadget && | |||
2812 | button == CDK_BUTTON_SECONDARY(3)) | |||
2813 | { | |||
2814 | /* autoscroll */ | |||
2815 | gdouble click_value; | |||
2816 | ||||
2817 | click_value = coord_to_value (range, | |||
2818 | priv->orientation == CTK_ORIENTATION_VERTICAL ? | |||
2819 | y : x); | |||
2820 | ||||
2821 | priv->trough_click_forward = click_value > ctk_adjustment_get_value (priv->adjustment); | |||
2822 | range_grab_add (range, priv->trough_gadget); | |||
2823 | ||||
2824 | remove_autoscroll (range); | |||
2825 | range->priv->autoscroll_mode = priv->trough_click_forward ? CTK_SCROLL_END : CTK_SCROLL_START; | |||
2826 | add_autoscroll (range); | |||
2827 | } | |||
2828 | ||||
2829 | if (priv->grab_location == priv->slider_gadget); | |||
2830 | /* leave it to ::drag-begin to claim the sequence */ | |||
2831 | else if (priv->grab_location != NULL((void*)0)) | |||
2832 | ctk_gesture_set_state (priv->multipress_gesture, CTK_EVENT_SEQUENCE_CLAIMED); | |||
2833 | } | |||
2834 | ||||
2835 | static void | |||
2836 | ctk_range_multipress_gesture_released (CtkGestureMultiPress *gesture G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2837 | guint n_press G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2838 | gdouble x, | |||
2839 | gdouble y, | |||
2840 | CtkRange *range) | |||
2841 | { | |||
2842 | CtkRangePrivate *priv = range->priv; | |||
2843 | ||||
2844 | priv->mouse_x = x; | |||
2845 | priv->mouse_y = y; | |||
2846 | range->priv->in_drag = FALSE(0); | |||
2847 | stop_scrolling (range); | |||
2848 | } | |||
2849 | ||||
2850 | /* During a slide, move the slider as required given new mouse position */ | |||
2851 | static void | |||
2852 | update_slider_position (CtkRange *range, | |||
2853 | gint mouse_x, | |||
2854 | gint mouse_y) | |||
2855 | { | |||
2856 | CtkRangePrivate *priv = range->priv; | |||
2857 | gdouble delta; | |||
2858 | gdouble c; | |||
2859 | gdouble new_value; | |||
2860 | gboolean handled; | |||
2861 | gdouble next_value; | |||
2862 | gdouble mark_value; | |||
2863 | gdouble mark_delta; | |||
2864 | gdouble zoom; | |||
2865 | gint i; | |||
2866 | ||||
2867 | if (priv->zoom) | |||
2868 | { | |||
2869 | CtkAllocation trough_alloc; | |||
2870 | ||||
2871 | ctk_css_gadget_get_margin_box (priv->trough_gadget, &trough_alloc); | |||
2872 | ||||
2873 | zoom = MIN(1.0, (priv->orientation == CTK_ORIENTATION_VERTICAL ?(((1.0) < ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc.height : trough_alloc.width) / (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) ? ( 1.0) : ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc .height : trough_alloc.width) / (ctk_adjustment_get_upper (priv ->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) | |||
2874 | trough_alloc.height : trough_alloc.width) /(((1.0) < ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc.height : trough_alloc.width) / (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) ? ( 1.0) : ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc .height : trough_alloc.width) / (ctk_adjustment_get_upper (priv ->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) | |||
2875 | (ctk_adjustment_get_upper (priv->adjustment) -(((1.0) < ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc.height : trough_alloc.width) / (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) ? ( 1.0) : ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc .height : trough_alloc.width) / (ctk_adjustment_get_upper (priv ->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) | |||
2876 | ctk_adjustment_get_lower (priv->adjustment) -(((1.0) < ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc.height : trough_alloc.width) / (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) ? ( 1.0) : ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc .height : trough_alloc.width) / (ctk_adjustment_get_upper (priv ->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) | |||
2877 | ctk_adjustment_get_page_size (priv->adjustment)))(((1.0) < ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc.height : trough_alloc.width) / (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) ? ( 1.0) : ((priv->orientation == CTK_ORIENTATION_VERTICAL ? trough_alloc .height : trough_alloc.width) / (ctk_adjustment_get_upper (priv ->adjustment) - ctk_adjustment_get_lower (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))); | |||
2878 | /* the above is ineffective for scales, so just set a zoom factor */ | |||
2879 | if (zoom == 1.0) | |||
2880 | zoom = 0.25; | |||
2881 | } | |||
2882 | else | |||
2883 | zoom = 1.0; | |||
2884 | ||||
2885 | /* recalculate the initial position from the current position */ | |||
2886 | if (priv->slide_initial_slider_position == -1) | |||
2887 | { | |||
2888 | CtkAllocation slider_alloc; | |||
2889 | ||||
2890 | ctk_css_gadget_get_margin_box (priv->slider_gadget, &slider_alloc); | |||
2891 | ||||
2892 | if (priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
2893 | priv->slide_initial_slider_position = (zoom * (mouse_y - priv->slide_initial_coordinate_delta) - slider_alloc.y) / (zoom - 1.0); | |||
2894 | else | |||
2895 | priv->slide_initial_slider_position = (zoom * (mouse_x - priv->slide_initial_coordinate_delta) - slider_alloc.x) / (zoom - 1.0); | |||
2896 | } | |||
2897 | ||||
2898 | if (priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
2899 | delta = mouse_y - (priv->slide_initial_coordinate_delta + priv->slide_initial_slider_position); | |||
2900 | else | |||
2901 | delta = mouse_x - (priv->slide_initial_coordinate_delta + priv->slide_initial_slider_position); | |||
2902 | ||||
2903 | c = priv->slide_initial_slider_position + zoom * delta; | |||
2904 | ||||
2905 | new_value = coord_to_value (range, c); | |||
2906 | next_value = coord_to_value (range, c + 1); | |||
2907 | mark_delta = fabs (next_value - new_value); | |||
2908 | ||||
2909 | for (i = 0; i < priv->n_marks; i++) | |||
2910 | { | |||
2911 | mark_value = priv->marks[i]; | |||
2912 | ||||
2913 | if (fabs (ctk_adjustment_get_value (priv->adjustment) - mark_value) < 3 * mark_delta) | |||
2914 | { | |||
2915 | if (fabs (new_value - mark_value) < MARK_SNAP_LENGTH12 * mark_delta) | |||
2916 | { | |||
2917 | new_value = mark_value; | |||
2918 | break; | |||
2919 | } | |||
2920 | } | |||
2921 | } | |||
2922 | ||||
2923 | g_signal_emit (range, signals[CHANGE_VALUE], 0, CTK_SCROLL_JUMP, new_value, &handled); | |||
2924 | } | |||
2925 | ||||
2926 | static void | |||
2927 | remove_autoscroll (CtkRange *range) | |||
2928 | { | |||
2929 | if (range->priv->autoscroll_id) | |||
2930 | { | |||
2931 | ctk_widget_remove_tick_callback (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), | |||
2932 | range->priv->autoscroll_id); | |||
2933 | range->priv->autoscroll_id = 0; | |||
2934 | } | |||
2935 | ||||
2936 | /* unset initial position so it can be calculated */ | |||
2937 | range->priv->slide_initial_slider_position = -1; | |||
2938 | ||||
2939 | range->priv->autoscroll_mode = CTK_SCROLL_NONE; | |||
2940 | } | |||
2941 | ||||
2942 | static gboolean | |||
2943 | autoscroll_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2944 | CdkFrameClock *frame_clock G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
2945 | gpointer data) | |||
2946 | { | |||
2947 | CtkRange *range = CTK_RANGE (data)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_range_get_type ())))))); | |||
2948 | CtkRangePrivate *priv = range->priv; | |||
2949 | CtkAdjustment *adj = priv->adjustment; | |||
2950 | gdouble increment; | |||
2951 | gdouble value; | |||
2952 | gboolean handled; | |||
2953 | gdouble step, page; | |||
2954 | ||||
2955 | step = ctk_adjustment_get_step_increment (adj); | |||
2956 | page = ctk_adjustment_get_page_increment (adj); | |||
2957 | ||||
2958 | switch (priv->autoscroll_mode) | |||
2959 | { | |||
2960 | case CTK_SCROLL_STEP_FORWARD: | |||
2961 | increment = step / AUTOSCROLL_FACTOR20; | |||
2962 | break; | |||
2963 | case CTK_SCROLL_PAGE_FORWARD: | |||
2964 | increment = page / AUTOSCROLL_FACTOR20; | |||
2965 | break; | |||
2966 | case CTK_SCROLL_STEP_BACKWARD: | |||
2967 | increment = - step / AUTOSCROLL_FACTOR20; | |||
2968 | break; | |||
2969 | case CTK_SCROLL_PAGE_BACKWARD: | |||
2970 | increment = - page / AUTOSCROLL_FACTOR20; | |||
2971 | break; | |||
2972 | case CTK_SCROLL_START: | |||
2973 | case CTK_SCROLL_END: | |||
2974 | { | |||
2975 | gdouble x, y; | |||
2976 | gdouble distance, t; | |||
2977 | ||||
2978 | /* Vary scrolling speed from slow (ie step) to fast (2 * page), | |||
2979 | * based on the distance of the pointer from the widget. We start | |||
2980 | * speeding up if the pointer moves at least 20 pixels away, and | |||
2981 | * we reach maximum speed when it is 220 pixels away. | |||
2982 | */ | |||
2983 | if (!ctk_gesture_drag_get_offset (CTK_GESTURE_DRAG (priv->drag_gesture)((((CtkGestureDrag*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((priv->drag_gesture)), ((ctk_gesture_drag_get_type ()) ))))), &x, &y)) | |||
2984 | { | |||
2985 | x = 0.0; | |||
2986 | y = 0.0; | |||
2987 | } | |||
2988 | if (ctk_orientable_get_orientation (CTK_ORIENTABLE (range)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_orientable_get_type ()))))))) == CTK_ORIENTATION_HORIZONTAL) | |||
2989 | distance = fabs (y); | |||
2990 | else | |||
2991 | distance = fabs (x); | |||
2992 | distance = CLAMP (distance - 20, 0.0, 200)(((distance - 20) > (200)) ? (200) : (((distance - 20) < (0.0)) ? (0.0) : (distance - 20))); | |||
2993 | t = distance / 100.0; | |||
2994 | step = (1 - t) * step + t * page; | |||
2995 | if (priv->autoscroll_mode == CTK_SCROLL_END) | |||
2996 | increment = step / AUTOSCROLL_FACTOR20; | |||
2997 | else | |||
2998 | increment = - step / AUTOSCROLL_FACTOR20; | |||
2999 | } | |||
3000 | break; | |||
3001 | default: | |||
3002 | g_assert_not_reached ()do { g_assertion_message_expr ("Ctk", "ctkrange.c", 3002, ((const char*) (__func__)), ((void*)0)); } while (0); | |||
3003 | break; | |||
3004 | } | |||
3005 | ||||
3006 | value = ctk_adjustment_get_value (adj); | |||
3007 | value += increment; | |||
3008 | ||||
3009 | g_signal_emit (range, signals[CHANGE_VALUE], 0, CTK_SCROLL_JUMP, value, &handled); | |||
3010 | ||||
3011 | return G_SOURCE_CONTINUE(!(0)); | |||
3012 | } | |||
3013 | ||||
3014 | static void | |||
3015 | add_autoscroll (CtkRange *range) | |||
3016 | { | |||
3017 | CtkRangePrivate *priv = range->priv; | |||
3018 | ||||
3019 | if (priv->autoscroll_id != 0 || | |||
3020 | priv->autoscroll_mode == CTK_SCROLL_NONE) | |||
3021 | return; | |||
3022 | ||||
3023 | priv->autoscroll_id = ctk_widget_add_tick_callback (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), | |||
3024 | autoscroll_cb, range, NULL((void*)0)); | |||
3025 | } | |||
3026 | ||||
3027 | static void | |||
3028 | stop_scrolling (CtkRange *range) | |||
3029 | { | |||
3030 | range_grab_remove (range); | |||
3031 | ctk_range_remove_step_timer (range); | |||
3032 | remove_autoscroll (range); | |||
3033 | } | |||
3034 | ||||
3035 | /** | |||
3036 | * _ctk_range_get_wheel_delta: | |||
3037 | * @range: a #CtkRange | |||
3038 | * @event: A #CdkEventScroll | |||
3039 | * | |||
3040 | * Returns a good step value for the mouse wheel. | |||
3041 | * | |||
3042 | * Returns: A good step value for the mouse wheel. | |||
3043 | * | |||
3044 | * Since: 2.4 | |||
3045 | **/ | |||
3046 | gdouble | |||
3047 | _ctk_range_get_wheel_delta (CtkRange *range, | |||
3048 | CdkEventScroll *event) | |||
3049 | { | |||
3050 | CtkRangePrivate *priv = range->priv; | |||
3051 | CtkAdjustment *adjustment = priv->adjustment; | |||
3052 | gdouble dx, dy; | |||
3053 | gdouble delta = 0; | |||
3054 | gdouble page_size; | |||
3055 | gdouble page_increment; | |||
3056 | gdouble scroll_unit; | |||
3057 | CdkScrollDirection direction; | |||
3058 | CtkOrientation move_orientation; | |||
3059 | ||||
3060 | page_size = ctk_adjustment_get_page_size (adjustment); | |||
3061 | page_increment = ctk_adjustment_get_page_increment (adjustment); | |||
3062 | ||||
3063 | if (CTK_IS_SCROLLBAR (range)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (range)); GType __t = ((ctk_scrollbar_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
3064 | { | |||
3065 | gdouble pow_unit = pow (page_size, 2.0 / 3.0); | |||
3066 | ||||
3067 | /* for very small page sizes of < 1.0, the effect of pow() is | |||
3068 | * the opposite of what's intended and the scroll steps become | |||
3069 | * unusably large, make sure we never get a scroll_unit larger | |||
3070 | * than page_size / 2.0, which used to be the default before the | |||
3071 | * pow() magic was introduced. | |||
3072 | */ | |||
3073 | scroll_unit = MIN (pow_unit, page_size / 2.0)(((pow_unit) < (page_size / 2.0)) ? (pow_unit) : (page_size / 2.0)); | |||
3074 | } | |||
3075 | else | |||
3076 | scroll_unit = page_increment; | |||
3077 | ||||
3078 | if (cdk_event_get_scroll_deltas ((CdkEvent *) event, &dx, &dy)) | |||
3079 | { | |||
3080 | #ifdef CDK_WINDOWING_QUARTZ | |||
3081 | scroll_unit = 1; | |||
3082 | #endif | |||
3083 | ||||
3084 | if (priv->orientation == CTK_ORIENTATION_HORIZONTAL && dx != 0) | |||
3085 | { | |||
3086 | move_orientation = CTK_ORIENTATION_HORIZONTAL; | |||
3087 | delta = dx * scroll_unit; | |||
3088 | } | |||
3089 | else | |||
3090 | { | |||
3091 | move_orientation = CTK_ORIENTATION_VERTICAL; | |||
3092 | delta = dy * scroll_unit; | |||
3093 | } | |||
3094 | } | |||
3095 | else if (cdk_event_get_scroll_direction ((CdkEvent *) event, &direction)) | |||
3096 | { | |||
3097 | if (direction == CDK_SCROLL_LEFT || direction == CDK_SCROLL_RIGHT) | |||
3098 | move_orientation = CTK_ORIENTATION_HORIZONTAL; | |||
3099 | else | |||
3100 | move_orientation = CTK_ORIENTATION_VERTICAL; | |||
3101 | ||||
3102 | if (direction == CDK_SCROLL_LEFT || direction == CDK_SCROLL_UP) | |||
3103 | delta = - scroll_unit; | |||
3104 | else | |||
3105 | delta = scroll_unit; | |||
3106 | } | |||
3107 | ||||
3108 | if (delta != 0 && should_invert_move (range, move_orientation)) | |||
| ||||
3109 | delta = - delta; | |||
3110 | ||||
3111 | return delta; | |||
3112 | } | |||
3113 | ||||
3114 | static gboolean | |||
3115 | ctk_range_scroll_event (CtkWidget *widget, | |||
3116 | CdkEventScroll *event) | |||
3117 | { | |||
3118 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
3119 | CtkRangePrivate *priv = range->priv; | |||
3120 | double delta = _ctk_range_get_wheel_delta (range, event); | |||
| ||||
3121 | gboolean handled; | |||
3122 | ||||
3123 | g_signal_emit (range, signals[CHANGE_VALUE], 0, | |||
3124 | CTK_SCROLL_JUMP, ctk_adjustment_get_value (priv->adjustment) + delta, | |||
3125 | &handled); | |||
3126 | ||||
3127 | return CDK_EVENT_STOP((!(0))); | |||
3128 | } | |||
3129 | ||||
3130 | static void | |||
3131 | update_autoscroll_mode (CtkRange *range) | |||
3132 | { | |||
3133 | CtkScrollType mode = CTK_SCROLL_NONE; | |||
3134 | ||||
3135 | if (range->priv->zoom) | |||
3136 | { | |||
3137 | CtkAllocation allocation; | |||
3138 | gint size, pos; | |||
3139 | ||||
3140 | ctk_widget_get_allocation (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), &allocation); | |||
3141 | ||||
3142 | if (range->priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
3143 | { | |||
3144 | size = allocation.height; | |||
3145 | pos = range->priv->mouse_y; | |||
3146 | } | |||
3147 | else | |||
3148 | { | |||
3149 | size = allocation.width; | |||
3150 | pos = range->priv->mouse_x; | |||
3151 | } | |||
3152 | ||||
3153 | if (pos < SCROLL_EDGE_SIZE15) | |||
3154 | mode = range->priv->inverted ? CTK_SCROLL_STEP_FORWARD : CTK_SCROLL_STEP_BACKWARD; | |||
3155 | else if (pos > (size - SCROLL_EDGE_SIZE15)) | |||
3156 | mode = range->priv->inverted ? CTK_SCROLL_STEP_BACKWARD : CTK_SCROLL_STEP_FORWARD; | |||
3157 | } | |||
3158 | ||||
3159 | if (mode != range->priv->autoscroll_mode) | |||
3160 | { | |||
3161 | remove_autoscroll (range); | |||
3162 | range->priv->autoscroll_mode = mode; | |||
3163 | add_autoscroll (range); | |||
3164 | } | |||
3165 | } | |||
3166 | ||||
3167 | static void | |||
3168 | ctk_range_drag_gesture_update (CtkGestureDrag *gesture, | |||
3169 | gdouble offset_x, | |||
3170 | gdouble offset_y, | |||
3171 | CtkRange *range) | |||
3172 | { | |||
3173 | CtkRangePrivate *priv = range->priv; | |||
3174 | gdouble start_x, start_y; | |||
3175 | ||||
3176 | if (priv->grab_location == priv->slider_gadget) | |||
3177 | { | |||
3178 | ctk_gesture_drag_get_start_point (gesture, &start_x, &start_y); | |||
3179 | priv->mouse_x = start_x + offset_x; | |||
3180 | priv->mouse_y = start_y + offset_y; | |||
3181 | priv->in_drag = TRUE(!(0)); | |||
3182 | update_autoscroll_mode (range); | |||
3183 | ||||
3184 | if (priv->autoscroll_mode == CTK_SCROLL_NONE) | |||
3185 | update_slider_position (range, priv->mouse_x, priv->mouse_y); | |||
3186 | } | |||
3187 | } | |||
3188 | ||||
3189 | static void | |||
3190 | ctk_range_drag_gesture_begin (CtkGestureDrag *gesture G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3191 | gdouble offset_x G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3192 | gdouble offset_y G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3193 | CtkRange *range) | |||
3194 | { | |||
3195 | CtkRangePrivate *priv = range->priv; | |||
3196 | ||||
3197 | if (priv->grab_location == priv->slider_gadget) | |||
3198 | ctk_gesture_set_state (priv->drag_gesture, CTK_EVENT_SEQUENCE_CLAIMED); | |||
3199 | } | |||
3200 | ||||
3201 | static gboolean | |||
3202 | ctk_range_event (CtkWidget *widget, | |||
3203 | CdkEvent *event) | |||
3204 | { | |||
3205 | CtkRange *range = CTK_RANGE (widget)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_range_get_type ())))))); | |||
3206 | CtkRangePrivate *priv = range->priv; | |||
3207 | gdouble x, y; | |||
3208 | ||||
3209 | if (event->type == CDK_LEAVE_NOTIFY) | |||
3210 | { | |||
3211 | priv->mouse_x = G_MININT(-2147483647 -1); | |||
3212 | priv->mouse_y = G_MININT(-2147483647 -1); | |||
3213 | } | |||
3214 | else if (cdk_event_get_coords (event, &x, &y)) | |||
3215 | { | |||
3216 | priv->mouse_x = x; | |||
3217 | priv->mouse_y = y; | |||
3218 | } | |||
3219 | ||||
3220 | ctk_range_update_mouse_location (range); | |||
3221 | ||||
3222 | return CDK_EVENT_PROPAGATE((0)); | |||
3223 | } | |||
3224 | ||||
3225 | static void | |||
3226 | ctk_range_adjustment_changed (CtkAdjustment *adjustment G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3227 | gpointer data) | |||
3228 | { | |||
3229 | CtkRange *range = CTK_RANGE (data)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_range_get_type ())))))); | |||
3230 | ||||
3231 | ctk_range_calc_slider (range); | |||
3232 | ctk_range_calc_stepper_sensitivity (range); | |||
3233 | ||||
3234 | /* Note that we don't round off to priv->round_digits here. | |||
3235 | * that's because it's really broken to change a value | |||
3236 | * in response to a change signal on that value; round_digits | |||
3237 | * is therefore defined to be a filter on what the CtkRange | |||
3238 | * can input into the adjustment, not a filter that the CtkRange | |||
3239 | * will enforce on the adjustment. | |||
3240 | */ | |||
3241 | } | |||
3242 | ||||
3243 | static void | |||
3244 | ctk_range_adjustment_value_changed (CtkAdjustment *adjustment G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3245 | gpointer data) | |||
3246 | { | |||
3247 | CtkRange *range = CTK_RANGE (data)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_range_get_type ())))))); | |||
3248 | ||||
3249 | ctk_range_calc_slider (range); | |||
3250 | ctk_range_calc_stepper_sensitivity (range); | |||
3251 | ||||
3252 | /* now check whether the layout changed */ | |||
3253 | if (CTK_IS_SCALE (range)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (range)); GType __t = ((ctk_scale_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))) && ctk_scale_get_draw_value (CTK_SCALE (range)((((CtkScale*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_scale_get_type ())))))))) | |||
3254 | { | |||
3255 | ctk_widget_queue_draw (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
3256 | } | |||
3257 | ||||
3258 | /* Note that we don't round off to priv->round_digits here. | |||
3259 | * that's because it's really broken to change a value | |||
3260 | * in response to a change signal on that value; round_digits | |||
3261 | * is therefore defined to be a filter on what the CtkRange | |||
3262 | * can input into the adjustment, not a filter that the CtkRange | |||
3263 | * will enforce on the adjustment. | |||
3264 | */ | |||
3265 | ||||
3266 | g_signal_emit (range, signals[VALUE_CHANGED], 0); | |||
3267 | } | |||
3268 | ||||
3269 | static void | |||
3270 | apply_marks (CtkRange *range, | |||
3271 | gdouble oldval, | |||
3272 | gdouble *newval) | |||
3273 | { | |||
3274 | CtkRangePrivate *priv = range->priv; | |||
3275 | gint i; | |||
3276 | gdouble mark; | |||
3277 | ||||
3278 | for (i = 0; i < priv->n_marks; i++) | |||
3279 | { | |||
3280 | mark = priv->marks[i]; | |||
3281 | if ((oldval < mark && mark < *newval) || | |||
3282 | (oldval > mark && mark > *newval)) | |||
3283 | { | |||
3284 | *newval = mark; | |||
3285 | return; | |||
3286 | } | |||
3287 | } | |||
3288 | } | |||
3289 | ||||
3290 | static void | |||
3291 | step_back (CtkRange *range) | |||
3292 | { | |||
3293 | CtkRangePrivate *priv = range->priv; | |||
3294 | gdouble newval; | |||
3295 | gboolean handled; | |||
3296 | ||||
3297 | newval = ctk_adjustment_get_value (priv->adjustment) - ctk_adjustment_get_step_increment (priv->adjustment); | |||
3298 | apply_marks (range, ctk_adjustment_get_value (priv->adjustment), &newval); | |||
3299 | g_signal_emit (range, signals[CHANGE_VALUE], 0, | |||
3300 | CTK_SCROLL_STEP_BACKWARD, newval, &handled); | |||
3301 | } | |||
3302 | ||||
3303 | static void | |||
3304 | step_forward (CtkRange *range) | |||
3305 | { | |||
3306 | CtkRangePrivate *priv = range->priv; | |||
3307 | gdouble newval; | |||
3308 | gboolean handled; | |||
3309 | ||||
3310 | newval = ctk_adjustment_get_value (priv->adjustment) + ctk_adjustment_get_step_increment (priv->adjustment); | |||
3311 | apply_marks (range, ctk_adjustment_get_value (priv->adjustment), &newval); | |||
3312 | g_signal_emit (range, signals[CHANGE_VALUE], 0, | |||
3313 | CTK_SCROLL_STEP_FORWARD, newval, &handled); | |||
3314 | } | |||
3315 | ||||
3316 | ||||
3317 | static void | |||
3318 | page_back (CtkRange *range) | |||
3319 | { | |||
3320 | CtkRangePrivate *priv = range->priv; | |||
3321 | gdouble newval; | |||
3322 | gboolean handled; | |||
3323 | ||||
3324 | newval = ctk_adjustment_get_value (priv->adjustment) - ctk_adjustment_get_page_increment (priv->adjustment); | |||
3325 | apply_marks (range, ctk_adjustment_get_value (priv->adjustment), &newval); | |||
3326 | g_signal_emit (range, signals[CHANGE_VALUE], 0, | |||
3327 | CTK_SCROLL_PAGE_BACKWARD, newval, &handled); | |||
3328 | } | |||
3329 | ||||
3330 | static void | |||
3331 | page_forward (CtkRange *range) | |||
3332 | { | |||
3333 | CtkRangePrivate *priv = range->priv; | |||
3334 | gdouble newval; | |||
3335 | gboolean handled; | |||
3336 | ||||
3337 | newval = ctk_adjustment_get_value (priv->adjustment) + ctk_adjustment_get_page_increment (priv->adjustment); | |||
3338 | apply_marks (range, ctk_adjustment_get_value (priv->adjustment), &newval); | |||
3339 | g_signal_emit (range, signals[CHANGE_VALUE], 0, | |||
3340 | CTK_SCROLL_PAGE_FORWARD, newval, &handled); | |||
3341 | } | |||
3342 | ||||
3343 | static void | |||
3344 | scroll_begin (CtkRange *range) | |||
3345 | { | |||
3346 | CtkRangePrivate *priv = range->priv; | |||
3347 | gboolean handled; | |||
3348 | ||||
3349 | g_signal_emit (range, signals[CHANGE_VALUE], 0, | |||
3350 | CTK_SCROLL_START, ctk_adjustment_get_lower (priv->adjustment), | |||
3351 | &handled); | |||
3352 | } | |||
3353 | ||||
3354 | static void | |||
3355 | scroll_end (CtkRange *range) | |||
3356 | { | |||
3357 | CtkRangePrivate *priv = range->priv; | |||
3358 | gdouble newval; | |||
3359 | gboolean handled; | |||
3360 | ||||
3361 | newval = ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment); | |||
3362 | g_signal_emit (range, signals[CHANGE_VALUE], 0, CTK_SCROLL_END, newval, | |||
3363 | &handled); | |||
3364 | } | |||
3365 | ||||
3366 | static gboolean | |||
3367 | ctk_range_scroll (CtkRange *range, | |||
3368 | CtkScrollType scroll) | |||
3369 | { | |||
3370 | CtkRangePrivate *priv = range->priv; | |||
3371 | gdouble old_value = ctk_adjustment_get_value (priv->adjustment); | |||
3372 | ||||
3373 | switch (scroll) | |||
3374 | { | |||
3375 | case CTK_SCROLL_STEP_LEFT: | |||
3376 | if (should_invert (range)) | |||
3377 | step_forward (range); | |||
3378 | else | |||
3379 | step_back (range); | |||
3380 | break; | |||
3381 | ||||
3382 | case CTK_SCROLL_STEP_UP: | |||
3383 | if (should_invert (range)) | |||
3384 | step_forward (range); | |||
3385 | else | |||
3386 | step_back (range); | |||
3387 | break; | |||
3388 | ||||
3389 | case CTK_SCROLL_STEP_RIGHT: | |||
3390 | if (should_invert (range)) | |||
3391 | step_back (range); | |||
3392 | else | |||
3393 | step_forward (range); | |||
3394 | break; | |||
3395 | ||||
3396 | case CTK_SCROLL_STEP_DOWN: | |||
3397 | if (should_invert (range)) | |||
3398 | step_back (range); | |||
3399 | else | |||
3400 | step_forward (range); | |||
3401 | break; | |||
3402 | ||||
3403 | case CTK_SCROLL_STEP_BACKWARD: | |||
3404 | step_back (range); | |||
3405 | break; | |||
3406 | ||||
3407 | case CTK_SCROLL_STEP_FORWARD: | |||
3408 | step_forward (range); | |||
3409 | break; | |||
3410 | ||||
3411 | case CTK_SCROLL_PAGE_LEFT: | |||
3412 | if (should_invert (range)) | |||
3413 | page_forward (range); | |||
3414 | else | |||
3415 | page_back (range); | |||
3416 | break; | |||
3417 | ||||
3418 | case CTK_SCROLL_PAGE_UP: | |||
3419 | if (should_invert (range)) | |||
3420 | page_forward (range); | |||
3421 | else | |||
3422 | page_back (range); | |||
3423 | break; | |||
3424 | ||||
3425 | case CTK_SCROLL_PAGE_RIGHT: | |||
3426 | if (should_invert (range)) | |||
3427 | page_back (range); | |||
3428 | else | |||
3429 | page_forward (range); | |||
3430 | break; | |||
3431 | ||||
3432 | case CTK_SCROLL_PAGE_DOWN: | |||
3433 | if (should_invert (range)) | |||
3434 | page_back (range); | |||
3435 | else | |||
3436 | page_forward (range); | |||
3437 | break; | |||
3438 | ||||
3439 | case CTK_SCROLL_PAGE_BACKWARD: | |||
3440 | page_back (range); | |||
3441 | break; | |||
3442 | ||||
3443 | case CTK_SCROLL_PAGE_FORWARD: | |||
3444 | page_forward (range); | |||
3445 | break; | |||
3446 | ||||
3447 | case CTK_SCROLL_START: | |||
3448 | scroll_begin (range); | |||
3449 | break; | |||
3450 | ||||
3451 | case CTK_SCROLL_END: | |||
3452 | scroll_end (range); | |||
3453 | break; | |||
3454 | ||||
3455 | case CTK_SCROLL_JUMP: | |||
3456 | /* Used by CList, range doesn't use it. */ | |||
3457 | break; | |||
3458 | ||||
3459 | case CTK_SCROLL_NONE: | |||
3460 | break; | |||
3461 | } | |||
3462 | ||||
3463 | return ctk_adjustment_get_value (priv->adjustment) != old_value; | |||
3464 | } | |||
3465 | ||||
3466 | static void | |||
3467 | ctk_range_move_slider (CtkRange *range, | |||
3468 | CtkScrollType scroll) | |||
3469 | { | |||
3470 | if (! ctk_range_scroll (range, scroll)) | |||
3471 | ctk_widget_error_bell (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
3472 | } | |||
3473 | ||||
3474 | static gboolean | |||
3475 | rectangle_contains_point (CdkRectangle *rect, | |||
3476 | gint x, | |||
3477 | gint y) | |||
3478 | { | |||
3479 | return (x >= rect->x) && (x < rect->x + rect->width) && | |||
3480 | (y >= rect->y) && (y < rect->y + rect->height); | |||
3481 | } | |||
3482 | ||||
3483 | /* Update mouse location, return TRUE if it changes */ | |||
3484 | static void | |||
3485 | ctk_range_update_mouse_location (CtkRange *range) | |||
3486 | { | |||
3487 | CtkRangePrivate *priv = range->priv; | |||
3488 | gint x, y; | |||
3489 | CtkCssGadget *old_location; | |||
3490 | CtkWidget *widget = CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))); | |||
3491 | CdkRectangle trough_alloc, slider_alloc, slider_trace; | |||
3492 | ||||
3493 | old_location = priv->mouse_location; | |||
3494 | ||||
3495 | x = priv->mouse_x; | |||
3496 | y = priv->mouse_y; | |||
3497 | ||||
3498 | ctk_css_gadget_get_border_box (priv->trough_gadget, &trough_alloc); | |||
3499 | ctk_css_gadget_get_border_box (priv->slider_gadget, &slider_alloc); | |||
3500 | cdk_rectangle_union (&slider_alloc, &trough_alloc, &slider_trace); | |||
3501 | ||||
3502 | if (priv->grab_location != NULL((void*)0)) | |||
3503 | priv->mouse_location = priv->grab_location; | |||
3504 | else if (priv->stepper_a_gadget && | |||
3505 | ctk_css_gadget_border_box_contains_point (priv->stepper_a_gadget, x, y)) | |||
3506 | priv->mouse_location = priv->stepper_a_gadget; | |||
3507 | else if (priv->stepper_b_gadget && | |||
3508 | ctk_css_gadget_border_box_contains_point (priv->stepper_b_gadget, x, y)) | |||
3509 | priv->mouse_location = priv->stepper_b_gadget; | |||
3510 | else if (priv->stepper_c_gadget && | |||
3511 | ctk_css_gadget_border_box_contains_point (priv->stepper_c_gadget, x, y)) | |||
3512 | priv->mouse_location = priv->stepper_c_gadget; | |||
3513 | else if (priv->stepper_d_gadget && | |||
3514 | ctk_css_gadget_border_box_contains_point (priv->stepper_d_gadget, x, y)) | |||
3515 | priv->mouse_location = priv->stepper_d_gadget; | |||
3516 | else if (ctk_css_gadget_border_box_contains_point (priv->slider_gadget, x, y)) | |||
3517 | priv->mouse_location = priv->slider_gadget; | |||
3518 | else if (rectangle_contains_point (&slider_trace, x, y)) | |||
3519 | priv->mouse_location = priv->trough_gadget; | |||
3520 | else if (ctk_css_gadget_margin_box_contains_point (priv->gadget, x, y)) | |||
3521 | priv->mouse_location = priv->gadget; | |||
3522 | else | |||
3523 | priv->mouse_location = NULL((void*)0); | |||
3524 | ||||
3525 | if (old_location != priv->mouse_location) | |||
3526 | { | |||
3527 | if (old_location != NULL((void*)0)) | |||
3528 | ctk_css_gadget_queue_allocate (old_location); | |||
3529 | ||||
3530 | if (priv->mouse_location != NULL((void*)0)) | |||
3531 | { | |||
3532 | ctk_widget_set_state_flags (widget, CTK_STATE_FLAG_PRELIGHT, FALSE(0)); | |||
3533 | ctk_css_gadget_queue_allocate (priv->mouse_location); | |||
3534 | } | |||
3535 | else | |||
3536 | { | |||
3537 | ctk_widget_unset_state_flags (widget, CTK_STATE_FLAG_PRELIGHT); | |||
3538 | } | |||
3539 | ||||
3540 | update_trough_state (range); | |||
3541 | update_slider_state (range); | |||
3542 | update_steppers_state (range); | |||
3543 | } | |||
3544 | } | |||
3545 | ||||
3546 | static void | |||
3547 | ctk_range_compute_slider_position (CtkRange *range, | |||
3548 | gdouble adjustment_value, | |||
3549 | CdkRectangle *slider_rect) | |||
3550 | { | |||
3551 | CtkRangePrivate *priv = range->priv; | |||
3552 | CtkAllocation trough_content_alloc; | |||
3553 | int slider_width, slider_height, min_slider_size; | |||
3554 | ||||
3555 | measure_one_gadget (priv->slider_gadget, &slider_width, &slider_height); | |||
3556 | ctk_css_gadget_get_content_box (priv->trough_gadget, &trough_content_alloc); | |||
3557 | ||||
3558 | min_slider_size = priv->min_slider_size; | |||
3559 | ||||
3560 | if (priv->orientation == CTK_ORIENTATION_VERTICAL) | |||
3561 | { | |||
3562 | gint y, bottom, top, height; | |||
3563 | ||||
3564 | /* Slider fits into the trough, with stepper_spacing on either side, | |||
3565 | * and the size/position based on the adjustment or fixed, depending. | |||
3566 | */ | |||
3567 | slider_rect->x = trough_content_alloc.x + (int) floor ((trough_content_alloc.width - slider_width) / 2); | |||
3568 | slider_rect->width = slider_width; | |||
3569 | ||||
3570 | if (priv->slider_use_min_size) | |||
3571 | min_slider_size = slider_height; | |||
3572 | ||||
3573 | /* Compute slider position/length */ | |||
3574 | top = trough_content_alloc.y; | |||
3575 | bottom = top + trough_content_alloc.height; | |||
3576 | ||||
3577 | /* Scale slider half extends over the trough edge */ | |||
3578 | if (CTK_IS_SCALE (range)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (range)); GType __t = ((ctk_scale_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
3579 | { | |||
3580 | top -= min_slider_size / 2; | |||
3581 | bottom += min_slider_size / 2; | |||
3582 | } | |||
3583 | ||||
3584 | /* slider height is the fraction (page_size / | |||
3585 | * total_adjustment_range) times the trough height in pixels | |||
3586 | */ | |||
3587 | ||||
3588 | if (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment) != 0) | |||
3589 | height = ((bottom - top) * (ctk_adjustment_get_page_size (priv->adjustment) / | |||
3590 | (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment)))); | |||
3591 | else | |||
3592 | height = min_slider_size; | |||
3593 | ||||
3594 | if (height < min_slider_size || | |||
3595 | priv->slider_size_fixed) | |||
3596 | height = min_slider_size; | |||
3597 | ||||
3598 | height = MIN (height, trough_content_alloc.height)(((height) < (trough_content_alloc.height)) ? (height) : ( trough_content_alloc.height)); | |||
3599 | ||||
3600 | y = top; | |||
3601 | ||||
3602 | if (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment) != 0) | |||
3603 | y += (bottom - top - height) * ((adjustment_value - ctk_adjustment_get_lower (priv->adjustment)) / | |||
3604 | (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment))); | |||
3605 | ||||
3606 | y = CLAMP (y, top, bottom)(((y) > (bottom)) ? (bottom) : (((y) < (top)) ? (top) : (y))); | |||
3607 | ||||
3608 | if (should_invert (range)) | |||
3609 | y = bottom - (y - top + height); | |||
3610 | ||||
3611 | slider_rect->y = y; | |||
3612 | slider_rect->height = height; | |||
3613 | } | |||
3614 | else | |||
3615 | { | |||
3616 | gint x, left, right, width; | |||
3617 | ||||
3618 | /* Slider fits into the trough, with stepper_spacing on either side, | |||
3619 | * and the size/position based on the adjustment or fixed, depending. | |||
3620 | */ | |||
3621 | slider_rect->y = trough_content_alloc.y + (int) floor ((trough_content_alloc.height - slider_height) / 2); | |||
3622 | slider_rect->height = slider_height; | |||
3623 | ||||
3624 | if (priv->slider_use_min_size) | |||
3625 | min_slider_size = slider_width; | |||
3626 | ||||
3627 | /* Compute slider position/length */ | |||
3628 | left = trough_content_alloc.x; | |||
3629 | right = left + trough_content_alloc.width; | |||
3630 | ||||
3631 | /* Scale slider half extends over the trough edge */ | |||
3632 | if (CTK_IS_SCALE (range)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (range)); GType __t = ((ctk_scale_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
3633 | { | |||
3634 | left -= min_slider_size / 2; | |||
3635 | right += min_slider_size / 2; | |||
3636 | } | |||
3637 | ||||
3638 | /* slider width is the fraction (page_size / | |||
3639 | * total_adjustment_range) times the trough width in pixels | |||
3640 | */ | |||
3641 | ||||
3642 | if (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment) != 0) | |||
3643 | width = ((right - left) * (ctk_adjustment_get_page_size (priv->adjustment) / | |||
3644 | (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment)))); | |||
3645 | else | |||
3646 | width = min_slider_size; | |||
3647 | ||||
3648 | if (width < min_slider_size || | |||
3649 | priv->slider_size_fixed) | |||
3650 | width = min_slider_size; | |||
3651 | ||||
3652 | width = MIN (width, trough_content_alloc.width)(((width) < (trough_content_alloc.width)) ? (width) : (trough_content_alloc .width)); | |||
3653 | ||||
3654 | x = left; | |||
3655 | ||||
3656 | if (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment) != 0) | |||
3657 | x += (right - left - width) * ((adjustment_value - ctk_adjustment_get_lower (priv->adjustment)) / | |||
3658 | (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_lower (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment))); | |||
3659 | ||||
3660 | x = CLAMP (x, left, right)(((x) > (right)) ? (right) : (((x) < (left)) ? (left) : (x))); | |||
3661 | ||||
3662 | if (should_invert (range)) | |||
3663 | x = right - (x - left + width); | |||
3664 | ||||
3665 | slider_rect->x = x; | |||
3666 | slider_rect->width = width; | |||
3667 | } | |||
3668 | } | |||
3669 | ||||
3670 | static void | |||
3671 | ctk_range_calc_slider (CtkRange *range) | |||
3672 | { | |||
3673 | CtkRangePrivate *priv = range->priv; | |||
3674 | gboolean visible; | |||
3675 | ||||
3676 | if (CTK_IS_SCALE (range)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (range)); GType __t = ((ctk_scale_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))) && | |||
3677 | ctk_adjustment_get_upper (priv->adjustment) == ctk_adjustment_get_lower (priv->adjustment)) | |||
3678 | visible = FALSE(0); | |||
3679 | else | |||
3680 | visible = TRUE(!(0)); | |||
3681 | ||||
3682 | ctk_css_gadget_set_visible (priv->slider_gadget, visible); | |||
3683 | ||||
3684 | ctk_css_gadget_queue_resize (priv->slider_gadget); | |||
3685 | ||||
3686 | if (priv->has_origin) | |||
3687 | ctk_css_gadget_queue_allocate (priv->trough_gadget); | |||
3688 | ||||
3689 | ctk_range_update_mouse_location (range); | |||
3690 | } | |||
3691 | ||||
3692 | static void | |||
3693 | ctk_range_calc_stepper_sensitivity (CtkRange *range) | |||
3694 | { | |||
3695 | CtkRangePrivate *priv = range->priv; | |||
3696 | gboolean was_upper_sensitive, was_lower_sensitive; | |||
3697 | ||||
3698 | was_upper_sensitive = priv->upper_sensitive; | |||
3699 | switch (priv->upper_sensitivity) | |||
3700 | { | |||
3701 | case CTK_SENSITIVITY_AUTO: | |||
3702 | priv->upper_sensitive = | |||
3703 | (ctk_adjustment_get_value (priv->adjustment) < | |||
3704 | (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment))); | |||
3705 | break; | |||
3706 | ||||
3707 | case CTK_SENSITIVITY_ON: | |||
3708 | priv->upper_sensitive = TRUE(!(0)); | |||
3709 | break; | |||
3710 | ||||
3711 | case CTK_SENSITIVITY_OFF: | |||
3712 | priv->upper_sensitive = FALSE(0); | |||
3713 | break; | |||
3714 | } | |||
3715 | ||||
3716 | was_lower_sensitive = priv->lower_sensitive; | |||
3717 | switch (priv->lower_sensitivity) | |||
3718 | { | |||
3719 | case CTK_SENSITIVITY_AUTO: | |||
3720 | priv->lower_sensitive = | |||
3721 | (ctk_adjustment_get_value (priv->adjustment) > ctk_adjustment_get_lower (priv->adjustment)); | |||
3722 | break; | |||
3723 | ||||
3724 | case CTK_SENSITIVITY_ON: | |||
3725 | priv->lower_sensitive = TRUE(!(0)); | |||
3726 | break; | |||
3727 | ||||
3728 | case CTK_SENSITIVITY_OFF: | |||
3729 | priv->lower_sensitive = FALSE(0); | |||
3730 | break; | |||
3731 | } | |||
3732 | ||||
3733 | /* Too many side effects can influence which stepper reacts to wat condition. | |||
3734 | * So we just invalidate them all. | |||
3735 | */ | |||
3736 | if (was_upper_sensitive != priv->upper_sensitive || | |||
3737 | was_lower_sensitive != priv->lower_sensitive) | |||
3738 | { | |||
3739 | update_steppers_state (range); | |||
3740 | ||||
3741 | if (priv->stepper_a_gadget) | |||
3742 | ctk_css_gadget_queue_allocate (priv->stepper_a_gadget); | |||
3743 | if (priv->stepper_b_gadget) | |||
3744 | ctk_css_gadget_queue_allocate (priv->stepper_b_gadget); | |||
3745 | if (priv->stepper_c_gadget) | |||
3746 | ctk_css_gadget_queue_allocate (priv->stepper_c_gadget); | |||
3747 | if (priv->stepper_d_gadget) | |||
3748 | ctk_css_gadget_queue_allocate (priv->stepper_d_gadget); | |||
3749 | } | |||
3750 | } | |||
3751 | ||||
3752 | static void | |||
3753 | ctk_range_calc_marks (CtkRange *range) | |||
3754 | { | |||
3755 | CtkRangePrivate *priv = range->priv; | |||
3756 | CdkRectangle slider; | |||
3757 | gint i; | |||
3758 | ||||
3759 | for (i = 0; i < priv->n_marks; i++) | |||
3760 | { | |||
3761 | ctk_range_compute_slider_position (range, priv->marks[i], &slider); | |||
3762 | ||||
3763 | if (priv->orientation == CTK_ORIENTATION_HORIZONTAL) | |||
3764 | priv->mark_pos[i] = slider.x + slider.width / 2; | |||
3765 | else | |||
3766 | priv->mark_pos[i] = slider.y + slider.height / 2; | |||
3767 | } | |||
3768 | } | |||
3769 | ||||
3770 | static gboolean | |||
3771 | ctk_range_real_change_value (CtkRange *range, | |||
3772 | CtkScrollType scroll G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3773 | gdouble value) | |||
3774 | { | |||
3775 | CtkRangePrivate *priv = range->priv; | |||
3776 | ||||
3777 | /* potentially adjust the bounds _before_ we clamp */ | |||
3778 | g_signal_emit (range, signals[ADJUST_BOUNDS], 0, value); | |||
3779 | ||||
3780 | if (priv->restrict_to_fill_level) | |||
3781 | value = MIN (value, MAX (ctk_adjustment_get_lower (priv->adjustment),(((value) < ((((ctk_adjustment_get_lower (priv->adjustment )) > (priv->fill_level)) ? (ctk_adjustment_get_lower (priv ->adjustment)) : (priv->fill_level)))) ? (value) : (((( ctk_adjustment_get_lower (priv->adjustment)) > (priv-> fill_level)) ? (ctk_adjustment_get_lower (priv->adjustment )) : (priv->fill_level)))) | |||
3782 | priv->fill_level))(((value) < ((((ctk_adjustment_get_lower (priv->adjustment )) > (priv->fill_level)) ? (ctk_adjustment_get_lower (priv ->adjustment)) : (priv->fill_level)))) ? (value) : (((( ctk_adjustment_get_lower (priv->adjustment)) > (priv-> fill_level)) ? (ctk_adjustment_get_lower (priv->adjustment )) : (priv->fill_level)))); | |||
3783 | ||||
3784 | value = CLAMP (value, ctk_adjustment_get_lower (priv->adjustment),(((value) > ((ctk_adjustment_get_upper (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) ? ( (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment))) : (((value) < (ctk_adjustment_get_lower (priv->adjustment))) ? (ctk_adjustment_get_lower (priv-> adjustment)) : (value))) | |||
3785 | (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment)))(((value) > ((ctk_adjustment_get_upper (priv->adjustment ) - ctk_adjustment_get_page_size (priv->adjustment)))) ? ( (ctk_adjustment_get_upper (priv->adjustment) - ctk_adjustment_get_page_size (priv->adjustment))) : (((value) < (ctk_adjustment_get_lower (priv->adjustment))) ? (ctk_adjustment_get_lower (priv-> adjustment)) : (value))); | |||
3786 | ||||
3787 | if (priv->round_digits >= 0) | |||
3788 | { | |||
3789 | gdouble power; | |||
3790 | gint i; | |||
3791 | ||||
3792 | i = priv->round_digits; | |||
3793 | power = 1; | |||
3794 | while (i--) | |||
3795 | power *= 10; | |||
3796 | ||||
3797 | value = floor ((value * power) + 0.5) / power; | |||
3798 | } | |||
3799 | ||||
3800 | if (priv->in_drag || priv->autoscroll_id) | |||
3801 | ctk_adjustment_set_value (priv->adjustment, value); | |||
3802 | else | |||
3803 | ctk_adjustment_animate_to_value (priv->adjustment, value); | |||
3804 | ||||
3805 | return FALSE(0); | |||
3806 | } | |||
3807 | ||||
3808 | struct _CtkRangeStepTimer | |||
3809 | { | |||
3810 | guint timeout_id; | |||
3811 | CtkScrollType step; | |||
3812 | }; | |||
3813 | ||||
3814 | static gboolean | |||
3815 | second_timeout (gpointer data) | |||
3816 | { | |||
3817 | CtkRange *range = CTK_RANGE (data)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_range_get_type ())))))); | |||
3818 | CtkRangePrivate *priv = range->priv; | |||
3819 | ||||
3820 | ctk_range_scroll (range, priv->timer->step); | |||
3821 | ||||
3822 | return G_SOURCE_CONTINUE(!(0)); | |||
3823 | } | |||
3824 | ||||
3825 | static gboolean | |||
3826 | initial_timeout (gpointer data) | |||
3827 | { | |||
3828 | CtkRange *range = CTK_RANGE (data)((((CtkRange*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_range_get_type ())))))); | |||
3829 | CtkRangePrivate *priv = range->priv; | |||
3830 | ||||
3831 | priv->timer->timeout_id = cdk_threads_add_timeout (TIMEOUT_REPEAT250, | |||
3832 | second_timeout, | |||
3833 | range); | |||
3834 | g_source_set_name_by_id (priv->timer->timeout_id, "[ctk+] second_timeout"); | |||
3835 | return G_SOURCE_REMOVE(0); | |||
3836 | } | |||
3837 | ||||
3838 | static void | |||
3839 | ctk_range_add_step_timer (CtkRange *range, | |||
3840 | CtkScrollType step) | |||
3841 | { | |||
3842 | CtkRangePrivate *priv = range->priv; | |||
3843 | ||||
3844 | g_return_if_fail (priv->timer == NULL)do { if ((priv->timer == ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "priv->timer == NULL" ); return; } } while (0); | |||
3845 | g_return_if_fail (step != CTK_SCROLL_NONE)do { if ((step != CTK_SCROLL_NONE)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "step != CTK_SCROLL_NONE" ); return; } } while (0); | |||
3846 | ||||
3847 | priv->timer = g_new (CtkRangeStepTimer, 1)((CtkRangeStepTimer *) g_malloc_n ((1), sizeof (CtkRangeStepTimer ))); | |||
3848 | ||||
3849 | priv->timer->timeout_id = cdk_threads_add_timeout (TIMEOUT_INITIAL500, | |||
3850 | initial_timeout, | |||
3851 | range); | |||
3852 | g_source_set_name_by_id (priv->timer->timeout_id, "[ctk+] initial_timeout"); | |||
3853 | priv->timer->step = step; | |||
3854 | ||||
3855 | ctk_range_scroll (range, priv->timer->step); | |||
3856 | } | |||
3857 | ||||
3858 | static void | |||
3859 | ctk_range_remove_step_timer (CtkRange *range) | |||
3860 | { | |||
3861 | CtkRangePrivate *priv = range->priv; | |||
3862 | ||||
3863 | if (priv->timer) | |||
3864 | { | |||
3865 | if (priv->timer->timeout_id != 0) | |||
3866 | g_source_remove (priv->timer->timeout_id); | |||
3867 | ||||
3868 | g_free (priv->timer); | |||
3869 | ||||
3870 | priv->timer = NULL((void*)0); | |||
3871 | } | |||
3872 | } | |||
3873 | ||||
3874 | void | |||
3875 | _ctk_range_set_has_origin (CtkRange *range, | |||
3876 | gboolean has_origin) | |||
3877 | { | |||
3878 | CtkRangePrivate *priv = range->priv; | |||
3879 | ||||
3880 | range->priv->has_origin = has_origin; | |||
3881 | ||||
3882 | if (has_origin) | |||
3883 | { | |||
3884 | priv->highlight_gadget = ctk_css_custom_gadget_new ("highlight", | |||
3885 | CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))), | |||
3886 | priv->trough_gadget, NULL((void*)0), | |||
3887 | NULL((void*)0), NULL((void*)0), NULL((void*)0), | |||
3888 | NULL((void*)0), NULL((void*)0)); | |||
3889 | ctk_css_gadget_set_state (priv->highlight_gadget, | |||
3890 | ctk_css_node_get_state (ctk_css_gadget_get_node (priv->trough_gadget))); | |||
3891 | ||||
3892 | update_highlight_position (range); | |||
3893 | } | |||
3894 | else | |||
3895 | { | |||
3896 | ctk_css_node_set_parent (ctk_css_gadget_get_node (priv->highlight_gadget), NULL((void*)0)); | |||
3897 | g_clear_object (&priv->highlight_gadget)do { _Static_assert (sizeof *((&priv->highlight_gadget )) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&priv->highlight_gadget))) _pp = ((&priv->highlight_gadget )); __typeof__ (*((&priv->highlight_gadget))) _ptr = * _pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
3898 | } | |||
3899 | } | |||
3900 | ||||
3901 | gboolean | |||
3902 | _ctk_range_get_has_origin (CtkRange *range) | |||
3903 | { | |||
3904 | return range->priv->has_origin; | |||
3905 | } | |||
3906 | ||||
3907 | void | |||
3908 | _ctk_range_set_stop_values (CtkRange *range, | |||
3909 | gdouble *values, | |||
3910 | gint n_values) | |||
3911 | { | |||
3912 | CtkRangePrivate *priv = range->priv; | |||
3913 | gint i; | |||
3914 | ||||
3915 | g_free (priv->marks); | |||
3916 | priv->marks = g_new (gdouble, n_values)((gdouble *) g_malloc_n ((n_values), sizeof (gdouble))); | |||
3917 | ||||
3918 | g_free (priv->mark_pos); | |||
3919 | priv->mark_pos = g_new (gint, n_values)((gint *) g_malloc_n ((n_values), sizeof (gint))); | |||
3920 | ||||
3921 | priv->n_marks = n_values; | |||
3922 | ||||
3923 | for (i = 0; i < n_values; i++) | |||
3924 | priv->marks[i] = values[i]; | |||
3925 | ||||
3926 | ctk_range_calc_marks (range); | |||
3927 | } | |||
3928 | ||||
3929 | gint | |||
3930 | _ctk_range_get_stop_positions (CtkRange *range, | |||
3931 | gint **values) | |||
3932 | { | |||
3933 | CtkRangePrivate *priv = range->priv; | |||
3934 | ||||
3935 | ctk_range_calc_marks (range); | |||
3936 | ||||
3937 | if (values) | |||
3938 | *values = g_memdup2 (priv->mark_pos, priv->n_marks * sizeof (gint)); | |||
3939 | ||||
3940 | return priv->n_marks; | |||
3941 | } | |||
3942 | ||||
3943 | /** | |||
3944 | * ctk_range_set_round_digits: | |||
3945 | * @range: a #CtkRange | |||
3946 | * @round_digits: the precision in digits, or -1 | |||
3947 | * | |||
3948 | * Sets the number of digits to round the value to when | |||
3949 | * it changes. See #CtkRange::change-value. | |||
3950 | * | |||
3951 | * Since: 2.24 | |||
3952 | */ | |||
3953 | void | |||
3954 | ctk_range_set_round_digits (CtkRange *range, | |||
3955 | gint round_digits) | |||
3956 | { | |||
3957 | g_return_if_fail (CTK_IS_RANGE (range))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return; } } while (0); | |||
3958 | g_return_if_fail (round_digits >= -1)do { if ((round_digits >= -1)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "round_digits >= -1") ; return; } } while (0); | |||
3959 | ||||
3960 | if (range->priv->round_digits != round_digits) | |||
3961 | { | |||
3962 | range->priv->round_digits = round_digits; | |||
3963 | g_object_notify_by_pspec (G_OBJECT (range)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), (((GType) ((20) << (2)))))))), properties[PROP_ROUND_DIGITS]); | |||
3964 | } | |||
3965 | } | |||
3966 | ||||
3967 | /** | |||
3968 | * ctk_range_get_round_digits: | |||
3969 | * @range: a #CtkRange | |||
3970 | * | |||
3971 | * Gets the number of digits to round the value to when | |||
3972 | * it changes. See #CtkRange::change-value. | |||
3973 | * | |||
3974 | * Returns: the number of digits to round to | |||
3975 | * | |||
3976 | * Since: 2.24 | |||
3977 | */ | |||
3978 | gint | |||
3979 | ctk_range_get_round_digits (CtkRange *range) | |||
3980 | { | |||
3981 | g_return_val_if_fail (CTK_IS_RANGE (range), -1)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((range)); GType __t = ((ctk_range_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_RANGE (range)"); return (-1); } } while (0); | |||
3982 | ||||
3983 | return range->priv->round_digits; | |||
3984 | } | |||
3985 | ||||
3986 | static void | |||
3987 | sync_stepper_gadget (CtkRange *range, | |||
3988 | gboolean should_have_stepper, | |||
3989 | CtkCssGadget **gadget_ptr, | |||
3990 | const gchar *class, | |||
3991 | CtkCssImageBuiltinType image_type, | |||
3992 | CtkCssGadget *prev_sibling) | |||
3993 | { | |||
3994 | CtkWidget *widget; | |||
3995 | CtkCssGadget *gadget; | |||
3996 | CtkCssNode *widget_node; | |||
3997 | gboolean has_stepper; | |||
3998 | CtkRangePrivate *priv = range->priv; | |||
3999 | ||||
4000 | has_stepper = (*gadget_ptr != NULL((void*)0)); | |||
4001 | if (has_stepper == should_have_stepper) | |||
4002 | return; | |||
4003 | ||||
4004 | if (!should_have_stepper) | |||
4005 | { | |||
4006 | if (*gadget_ptr != NULL((void*)0)) | |||
4007 | { | |||
4008 | if (*gadget_ptr == priv->grab_location) | |||
4009 | stop_scrolling (range); | |||
4010 | if (*gadget_ptr == priv->mouse_location) | |||
4011 | priv->mouse_location = NULL((void*)0); | |||
4012 | ctk_css_node_set_parent (ctk_css_gadget_get_node (*gadget_ptr), NULL((void*)0)); | |||
4013 | ctk_box_gadget_remove_gadget (CTK_BOX_GADGET (priv->contents_gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (priv->contents_gadget), ((ctk_box_gadget_get_type ())) )))), *gadget_ptr); | |||
4014 | } | |||
4015 | g_clear_object (gadget_ptr)do { _Static_assert (sizeof *((gadget_ptr)) == sizeof (gpointer ), "Expression evaluates to false"); __typeof__ (((gadget_ptr ))) _pp = ((gadget_ptr)); __typeof__ (*((gadget_ptr))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
4016 | return; | |||
4017 | } | |||
4018 | ||||
4019 | widget = CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ())))))); | |||
4020 | widget_node = ctk_widget_get_css_node (widget); | |||
4021 | gadget = ctk_builtin_icon_new ("button", | |||
4022 | widget, | |||
4023 | NULL((void*)0), NULL((void*)0)); | |||
4024 | ctk_builtin_icon_set_image (CTK_BUILTIN_ICON (gadget)((((CtkBuiltinIcon*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_builtin_icon_get_type ())))))), image_type); | |||
4025 | ctk_css_gadget_add_class (gadget, class); | |||
4026 | ctk_css_gadget_set_state (gadget, ctk_css_node_get_state (widget_node)); | |||
4027 | ||||
4028 | ctk_box_gadget_insert_gadget_after (CTK_BOX_GADGET (priv->contents_gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (priv->contents_gadget), ((ctk_box_gadget_get_type ())) )))), prev_sibling, | |||
4029 | gadget, FALSE(0), CTK_ALIGN_FILL); | |||
4030 | *gadget_ptr = gadget; | |||
4031 | } | |||
4032 | ||||
4033 | void | |||
4034 | _ctk_range_set_steppers (CtkRange *range, | |||
4035 | gboolean has_a, | |||
4036 | gboolean has_b, | |||
4037 | gboolean has_c, | |||
4038 | gboolean has_d) | |||
4039 | { | |||
4040 | CtkRangePrivate *priv = range->priv; | |||
4041 | ||||
4042 | sync_stepper_gadget (range, | |||
4043 | has_a, &priv->stepper_a_gadget, | |||
4044 | "up", | |||
4045 | priv->orientation == CTK_ORIENTATION_VERTICAL ? | |||
4046 | CTK_CSS_IMAGE_BUILTIN_ARROW_UP : CTK_CSS_IMAGE_BUILTIN_ARROW_LEFT, | |||
4047 | NULL((void*)0)); | |||
4048 | ||||
4049 | sync_stepper_gadget (range, | |||
4050 | has_b, &priv->stepper_b_gadget, | |||
4051 | "down", | |||
4052 | priv->orientation == CTK_ORIENTATION_VERTICAL ? | |||
4053 | CTK_CSS_IMAGE_BUILTIN_ARROW_DOWN : CTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT, | |||
4054 | priv->stepper_a_gadget); | |||
4055 | ||||
4056 | sync_stepper_gadget (range, | |||
4057 | has_c, &priv->stepper_c_gadget, | |||
4058 | "up", | |||
4059 | priv->orientation == CTK_ORIENTATION_VERTICAL ? | |||
4060 | CTK_CSS_IMAGE_BUILTIN_ARROW_UP : CTK_CSS_IMAGE_BUILTIN_ARROW_LEFT, | |||
4061 | priv->trough_gadget); | |||
4062 | ||||
4063 | sync_stepper_gadget (range, | |||
4064 | has_d, &priv->stepper_d_gadget, | |||
4065 | "down", | |||
4066 | priv->orientation == CTK_ORIENTATION_VERTICAL ? | |||
4067 | CTK_CSS_IMAGE_BUILTIN_ARROW_DOWN : CTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT, | |||
4068 | priv->stepper_c_gadget ? priv->stepper_c_gadget : priv->trough_gadget); | |||
4069 | ||||
4070 | ctk_widget_queue_resize (CTK_WIDGET (range)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((range)), ((ctk_widget_get_type ()))))))); | |||
4071 | } | |||
4072 | ||||
4073 | CtkCssGadget * | |||
4074 | ctk_range_get_slider_gadget (CtkRange *range) | |||
4075 | { | |||
4076 | return range->priv->slider_gadget; | |||
4077 | } | |||
4078 | ||||
4079 | CtkCssGadget * | |||
4080 | ctk_range_get_gadget (CtkRange *range) | |||
4081 | { | |||
4082 | return range->priv->gadget; | |||
4083 | } |