Mercurial > projects > dwt-linux
annotate dwt/widgets/Slider.d @ 322:96b14a31d9b3
Added missing dwthelper.utils imports. (catched by llvmdc)
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 06 Oct 2008 21:02:12 +0200 |
parents | c0d810de7093 |
children |
rev | line source |
---|---|
72 | 1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
62 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
72 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
62 | 12 *******************************************************************************/ |
13 module dwt.widgets.Slider; | |
14 | |
322
96b14a31d9b3
Added missing dwthelper.utils imports. (catched by llvmdc)
Frank Benoit <benoit@tionex.de>
parents:
259
diff
changeset
|
15 import dwt.dwthelper.utils; |
62 | 16 |
17 import dwt.widgets.Control; | |
18 import dwt.widgets.Composite; | |
19 import dwt.widgets.TypedListener; | |
20 import dwt.widgets.Event; | |
71 | 21 import dwt.DWT; |
62 | 22 import dwt.internal.gtk.OS; |
23 import dwt.graphics.Point; | |
24 import dwt.events.SelectionListener; | |
25 | |
26 /** | |
27 * Instances of this class are selectable user interface | |
28 * objects that represent a range of positive, numeric values. | |
29 * <p> | |
30 * At any given moment, a given slider will have a | |
31 * single 'selection' that is considered to be its | |
32 * value, which is constrained to be within the range of | |
33 * values the slider represents (that is, between its | |
34 * <em>minimum</em> and <em>maximum</em> values). | |
35 * </p><p> | |
36 * Typically, sliders will be made up of five areas: | |
37 * <ol> | |
38 * <li>an arrow button for decrementing the value</li> | |
39 * <li>a page decrement area for decrementing the value by a larger amount</li> | |
40 * <li>a <em>thumb</em> for modifying the value by mouse dragging</li> | |
41 * <li>a page increment area for incrementing the value by a larger amount</li> | |
42 * <li>an arrow button for incrementing the value</li> | |
43 * </ol> | |
44 * Based on their style, sliders are either <code>HORIZONTAL</code> | |
45 * (which have a left facing button for decrementing the value and a | |
46 * right facing button for incrementing it) or <code>VERTICAL</code> | |
47 * (which have an upward facing button for decrementing the value | |
48 * and a downward facing buttons for incrementing it). | |
49 * </p><p> | |
50 * On some platforms, the size of the slider's thumb can be | |
51 * varied relative to the magnitude of the range of values it | |
52 * represents (that is, relative to the difference between its | |
53 * maximum and minimum values). Typically, this is used to | |
54 * indicate some proportional value such as the ratio of the | |
55 * visible area of a document to the total amount of space that | |
71 | 56 * it would take to display it. DWT supports setting the thumb |
62 | 57 * size even if the underlying platform does not, but in this |
58 * case the appearance of the slider will not change. | |
59 * </p> | |
60 * <dl> | |
61 * <dt><b>Styles:</b></dt> | |
62 * <dd>HORIZONTAL, VERTICAL</dd> | |
63 * <dt><b>Events:</b></dt> | |
64 * <dd>Selection</dd> | |
65 * </dl> | |
66 * <p> | |
67 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. | |
68 * </p><p> | |
69 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
70 * </p> | |
71 * | |
72 * @see ScrollBar | |
259 | 73 * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a> |
74 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | |
75 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
62 | 76 */ |
77 public class Slider : Control { | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
78 |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
79 alias Control.computeSize computeSize; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
80 |
62 | 81 int detail; |
82 bool dragSent; | |
83 /** | |
84 * Constructs a new instance of this class given its parent | |
85 * and a style value describing its behavior and appearance. | |
86 * <p> | |
87 * The style value is either one of the style constants defined in | |
71 | 88 * class <code>DWT</code> which is applicable to instances of this |
62 | 89 * class, or must be built by <em>bitwise OR</em>'ing together |
90 * (that is, using the <code>int</code> "|" operator) two or more | |
71 | 91 * of those <code>DWT</code> style constants. The class description |
62 | 92 * lists the style constants that are applicable to the class. |
93 * Style bits are also inherited from superclasses. | |
94 * </p> | |
95 * | |
96 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
97 * @param style the style of control to construct | |
98 * | |
99 * @exception IllegalArgumentException <ul> | |
100 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
101 * </ul> | |
71 | 102 * @exception DWTException <ul> |
62 | 103 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
104 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
105 * </ul> | |
106 * | |
71 | 107 * @see DWT#HORIZONTAL |
108 * @see DWT#VERTICAL | |
62 | 109 * @see Widget#checkSubclass |
110 * @see Widget#getStyle | |
111 */ | |
112 public this (Composite parent, int style) { | |
113 super (parent, checkStyle (style)); | |
114 } | |
115 | |
116 /** | |
117 * Adds the listener to the collection of listeners who will | |
118 * be notified when the user changes the receiver's value, by sending | |
119 * it one of the messages defined in the <code>SelectionListener</code> | |
120 * interface. | |
121 * <p> | |
122 * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values: | |
71 | 123 * <code>DWT.NONE</code> - for the end of a drag. |
124 * <code>DWT.DRAG</code>. | |
125 * <code>DWT.HOME</code>. | |
126 * <code>DWT.END</code>. | |
127 * <code>DWT.ARROW_DOWN</code>. | |
128 * <code>DWT.ARROW_UP</code>. | |
129 * <code>DWT.PAGE_DOWN</code>. | |
130 * <code>DWT.PAGE_UP</code>. | |
62 | 131 * <code>widgetDefaultSelected</code> is not called. |
132 * </p> | |
133 * | |
134 * @param listener the listener which should be notified when the user changes the receiver's value | |
135 * | |
136 * @exception IllegalArgumentException <ul> | |
137 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
138 * </ul> | |
71 | 139 * @exception DWTException <ul> |
62 | 140 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
141 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
142 * </ul> | |
143 * | |
144 * @see SelectionListener | |
145 * @see #removeSelectionListener | |
146 * @see SelectionEvent | |
147 */ | |
148 public void addSelectionListener (SelectionListener listener) { | |
149 checkWidget (); | |
71 | 150 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); |
62 | 151 TypedListener typedListener = new TypedListener (listener); |
71 | 152 addListener (DWT.Selection,typedListener); |
153 addListener (DWT.DefaultSelection,typedListener); | |
62 | 154 } |
155 | |
156 static int checkStyle (int style) { | |
71 | 157 return checkBits (style, DWT.HORIZONTAL, DWT.VERTICAL, 0, 0, 0, 0); |
62 | 158 } |
159 | |
160 override void createHandle (int index) { | |
161 state |= HANDLE; | |
162 fixedHandle = cast(GtkWidget*)OS.g_object_new (display.gtk_fixed_get_type (), null); | |
71 | 163 if (fixedHandle is null) error (DWT.ERROR_NO_HANDLES); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
164 OS.gtk_fixed_set_has_window (fixedHandle, true); |
62 | 165 auto hAdjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10); |
71 | 166 if (hAdjustment is null) error (DWT.ERROR_NO_HANDLES); |
167 if ((style & DWT.HORIZONTAL) !is 0) { | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
168 handle = cast(GtkWidget*)OS.gtk_hscrollbar_new (hAdjustment); |
62 | 169 } else { |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
170 handle = cast(GtkWidget*)OS.gtk_vscrollbar_new (hAdjustment); |
62 | 171 } |
71 | 172 if (handle is null) error (DWT.ERROR_NO_HANDLES); |
240 | 173 /* |
174 * Bug in GTK. In GTK 2.10, the buttons on either end of | |
175 * a horizontal slider are created taller then the slider bar | |
176 * when the GTK_CAN_FOCUS flag is set. The fix is not to set | |
177 * the flag for horizontal bars in all versions of 2.10. Note | |
178 * that a bug has been logged with GTK about this issue. | |
179 * (http://bugzilla.gnome.org/show_bug.cgi?id=475909) | |
180 */ | |
181 if (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0) || (style & DWT.VERTICAL) !is 0) { | |
182 OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
183 } | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
184 OS.gtk_container_add (fixedHandle, handle); |
62 | 185 } |
186 | |
187 override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) { | |
188 auto result = super.gtk_button_press_event (widget, event); | |
189 if (result !is 0) return result; | |
190 detail = OS.GTK_SCROLL_NONE; | |
191 dragSent = false; | |
192 return result; | |
193 } | |
194 | |
195 override int /*long*/ gtk_change_value (GtkWidget* widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) { | |
196 detail = cast(int)/*64*/scroll; | |
197 return 0; | |
198 } | |
199 | |
200 override int /*long*/ gtk_value_changed (int /*long*/ adjustment) { | |
201 Event event = new Event (); | |
202 dragSent = detail is OS.GTK_SCROLL_JUMP; | |
203 switch (detail) { | |
71 | 204 case OS.GTK_SCROLL_NONE: event.detail = DWT.NONE; break; |
205 case OS.GTK_SCROLL_JUMP: event.detail = DWT.DRAG; break; | |
206 case OS.GTK_SCROLL_START: event.detail = DWT.HOME; break; | |
207 case OS.GTK_SCROLL_END: event.detail = DWT.END; break; | |
62 | 208 case OS.GTK_SCROLL_PAGE_DOWN: |
209 case OS.GTK_SCROLL_PAGE_RIGHT: | |
71 | 210 case OS.GTK_SCROLL_PAGE_FORWARD: event.detail = DWT.PAGE_DOWN; break; |
62 | 211 case OS.GTK_SCROLL_PAGE_UP: |
212 case OS.GTK_SCROLL_PAGE_LEFT: | |
71 | 213 case OS.GTK_SCROLL_PAGE_BACKWARD: event.detail = DWT.PAGE_UP; break; |
62 | 214 case OS.GTK_SCROLL_STEP_DOWN: |
215 case OS.GTK_SCROLL_STEP_RIGHT: | |
71 | 216 case OS.GTK_SCROLL_STEP_FORWARD: event.detail = DWT.ARROW_DOWN; break; |
62 | 217 case OS.GTK_SCROLL_STEP_UP: |
218 case OS.GTK_SCROLL_STEP_LEFT: | |
71 | 219 case OS.GTK_SCROLL_STEP_BACKWARD: event.detail = DWT.ARROW_UP; break; |
62 | 220 default: |
221 } | |
222 if (!dragSent) detail = OS.GTK_SCROLL_NONE; | |
71 | 223 postEvent (DWT.Selection, event); |
62 | 224 return 0; |
225 } | |
226 | |
227 override int /*long*/ gtk_event_after (GtkWidget* widget, GdkEvent* gdkEvent) { | |
228 switch (gdkEvent.type) { | |
229 case OS.GDK_BUTTON_RELEASE: { | |
230 GdkEventButton* gdkEventButton = cast(GdkEventButton*)gdkEvent; | |
71 | 231 if (gdkEventButton.button is 1 && detail is DWT.DRAG) { |
62 | 232 if (!dragSent) { |
233 Event event = new Event (); | |
71 | 234 event.detail = DWT.DRAG; |
235 postEvent (DWT.Selection, event); | |
62 | 236 } |
71 | 237 postEvent (DWT.Selection); |
62 | 238 } |
239 detail = OS.GTK_SCROLL_NONE; | |
240 dragSent = false; | |
241 break; | |
242 default: | |
243 } | |
244 } | |
245 return super.gtk_event_after (widget, gdkEvent); | |
246 } | |
247 | |
248 override void hookEvents () { | |
249 super.hookEvents (); | |
250 if (OS.GTK_VERSION >= OS.buildVERSION (2, 6, 0)) { | |
251 OS.g_signal_connect_closure (handle, OS.change_value.ptr, display.closures [CHANGE_VALUE], false); | |
252 } | |
253 OS.g_signal_connect_closure (handle, OS.value_changed.ptr, display.closures [VALUE_CHANGED], false); | |
254 } | |
255 | |
256 override void register () { | |
257 super.register (); | |
258 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
259 display.addWidget (cast(GtkWidget*)hAdjustment, this); | |
260 } | |
261 | |
262 override void deregister () { | |
263 super.deregister (); | |
264 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
265 display.removeWidget (cast(GtkWidget*)hAdjustment); | |
266 } | |
267 | |
268 override public Point computeSize (int wHint, int hHint, bool changed) { | |
269 checkWidget(); | |
71 | 270 if (wHint !is DWT.DEFAULT && wHint < 0) wHint = 0; |
271 if (hHint !is DWT.DEFAULT && hHint < 0) hHint = 0; | |
62 | 272 Point size = computeNativeSize(handle, wHint, hHint, changed); |
71 | 273 if ((style & DWT.HORIZONTAL) !is 0) { |
274 if (wHint is DWT.DEFAULT) size.x = 2 * size.x; | |
62 | 275 } else { |
71 | 276 if (hHint is DWT.DEFAULT) size.y = 2 * size.y; |
62 | 277 } |
278 return size; | |
279 } | |
280 | |
281 /** | |
282 * Returns the amount that the receiver's value will be | |
283 * modified by when the up/down (or right/left) arrows | |
284 * are pressed. | |
285 * | |
286 * @return the increment | |
287 * | |
71 | 288 * @exception DWTException <ul> |
62 | 289 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
290 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
291 * </ul> | |
292 */ | |
293 public int getIncrement () { | |
294 checkWidget (); | |
295 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
296 return cast(int) hAdjustment.step_increment; | |
297 } | |
298 | |
299 /** | |
300 * Returns the maximum value which the receiver will allow. | |
301 * | |
302 * @return the maximum | |
303 * | |
71 | 304 * @exception DWTException <ul> |
62 | 305 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
306 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
307 * </ul> | |
308 */ | |
309 public int getMaximum () { | |
310 checkWidget (); | |
311 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
312 return cast(int) hAdjustment.upper; | |
313 } | |
314 | |
315 /** | |
316 * Returns the minimum value which the receiver will allow. | |
317 * | |
318 * @return the minimum | |
319 * | |
71 | 320 * @exception DWTException <ul> |
62 | 321 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
322 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
323 * </ul> | |
324 */ | |
325 public int getMinimum () { | |
326 checkWidget (); | |
327 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
328 return cast(int) hAdjustment.lower; | |
329 } | |
330 | |
331 /** | |
332 * Returns the amount that the receiver's value will be | |
333 * modified by when the page increment/decrement areas | |
334 * are selected. | |
335 * | |
336 * @return the page increment | |
337 * | |
71 | 338 * @exception DWTException <ul> |
62 | 339 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
340 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
341 * </ul> | |
342 */ | |
343 public int getPageIncrement () { | |
344 checkWidget (); | |
345 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
346 return cast(int) hAdjustment.page_increment; | |
347 } | |
348 | |
349 /** | |
350 * Returns the 'selection', which is the receiver's value. | |
351 * | |
352 * @return the selection | |
353 * | |
71 | 354 * @exception DWTException <ul> |
62 | 355 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
356 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
357 * </ul> | |
358 */ | |
359 public int getSelection () { | |
360 checkWidget (); | |
361 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
362 return cast(int) hAdjustment.value; | |
363 } | |
364 | |
365 /** | |
366 * Returns the size of the receiver's thumb relative to the | |
367 * difference between its maximum and minimum values. | |
368 * | |
369 * @return the thumb value | |
370 * | |
71 | 371 * @exception DWTException <ul> |
62 | 372 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
373 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
374 * </ul> | |
375 */ | |
376 public int getThumb () { | |
377 checkWidget (); | |
378 auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
379 return cast(int) hAdjustment.page_size; | |
380 } | |
381 | |
382 /** | |
383 * Removes the listener from the collection of listeners who will | |
384 * be notified when the user changes the receiver's value. | |
385 * | |
386 * @param listener the listener which should no longer be notified | |
387 * | |
388 * @exception IllegalArgumentException <ul> | |
389 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
390 * </ul> | |
71 | 391 * @exception DWTException <ul> |
62 | 392 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
393 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
394 * </ul> | |
395 * | |
396 * @see SelectionListener | |
397 * @see #addSelectionListener | |
398 */ | |
399 public void removeSelectionListener (SelectionListener listener) { | |
400 checkWidget(); | |
71 | 401 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); |
62 | 402 if (eventTable is null) return; |
71 | 403 eventTable.unhook (DWT.Selection, listener); |
404 eventTable.unhook (DWT.DefaultSelection,listener); | |
62 | 405 } |
406 | |
407 /** | |
408 * Sets the amount that the receiver's value will be | |
409 * modified by when the up/down (or right/left) arrows | |
410 * are pressed to the argument, which must be at least | |
411 * one. | |
412 * | |
413 * @param value the new increment (must be greater than zero) | |
414 * | |
71 | 415 * @exception DWTException <ul> |
62 | 416 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
417 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
418 * </ul> | |
419 */ | |
420 public void setIncrement (int value) { | |
421 checkWidget (); | |
422 if (value < 1) return; | |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
423 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 424 OS.gtk_range_set_increments (cast(GtkRange*)handle, value, getPageIncrement ()); |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
425 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 426 } |
427 | |
428 /** | |
429 * Sets the maximum. If this value is negative or less than or | |
430 * equal to the minimum, the value is ignored. If necessary, first | |
431 * the thumb and then the selection are adjusted to fit within the | |
432 * new range. | |
433 * | |
434 * @param value the new maximum, which must be greater than the current minimum | |
435 * | |
71 | 436 * @exception DWTException <ul> |
62 | 437 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
438 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
439 * </ul> | |
440 */ | |
441 public void setMaximum (int value) { | |
442 checkWidget (); | |
443 auto adjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
444 int minimum = cast(int) adjustment.lower; | |
445 if (value <= minimum) return; | |
446 adjustment.upper = value; | |
447 adjustment.page_size = Math.min (cast(int)adjustment.page_size, value - minimum); | |
448 adjustment.value = Math.min (cast(int)adjustment.value, cast(int)(value - adjustment.page_size)); | |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
449 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 450 OS.gtk_adjustment_changed (adjustment); |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
451 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 452 } |
453 | |
454 /** | |
455 * Sets the minimum value. If this value is negative or greater | |
456 * than or equal to the maximum, the value is ignored. If necessary, | |
457 * first the thumb and then the selection are adjusted to fit within | |
458 * the new range. | |
459 * | |
460 * @param value the new minimum | |
461 * | |
71 | 462 * @exception DWTException <ul> |
62 | 463 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
464 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
465 * </ul> | |
466 */ | |
467 public void setMinimum (int value) { | |
468 checkWidget (); | |
469 if (value < 0) return; | |
470 auto adjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
471 int maximum = cast(int) adjustment.upper; | |
472 if (value >= maximum) return; | |
473 adjustment.lower = value; | |
474 adjustment.page_size = Math.min (cast(int)adjustment.page_size, maximum - value); | |
475 adjustment.value = Math.max (cast(int)adjustment.value, value); | |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
476 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 477 OS.gtk_adjustment_changed (adjustment); |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
478 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 479 } |
480 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
481 override void setOrientation () { |
62 | 482 super.setOrientation (); |
71 | 483 if ((style & DWT.RIGHT_TO_LEFT) !is 0) { |
484 if ((style & DWT.HORIZONTAL) !is 0) { | |
62 | 485 OS.gtk_range_set_inverted (cast(GtkRange*)handle, true); |
486 } | |
487 } | |
488 } | |
489 | |
490 /** | |
491 * Sets the amount that the receiver's value will be | |
492 * modified by when the page increment/decrement areas | |
493 * are selected to the argument, which must be at least | |
494 * one. | |
495 * | |
496 * @param value the page increment (must be greater than zero) | |
497 * | |
71 | 498 * @exception DWTException <ul> |
62 | 499 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
500 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
501 * </ul> | |
502 */ | |
503 public void setPageIncrement (int value) { | |
504 checkWidget (); | |
505 if (value < 1) return; | |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
506 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 507 OS.gtk_range_set_increments (cast(GtkRange*)handle, getIncrement (), value); |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
508 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 509 } |
510 | |
511 /** | |
512 * Sets the 'selection', which is the receiver's | |
513 * value, to the argument which must be greater than or equal | |
514 * to zero. | |
515 * | |
516 * @param value the new selection (must be zero or greater) | |
517 * | |
71 | 518 * @exception DWTException <ul> |
62 | 519 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
520 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
521 * </ul> | |
522 */ | |
523 public void setSelection (int value) { | |
524 checkWidget (); | |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
525 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 526 OS.gtk_range_set_value (cast(GtkRange*)handle, value); |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
527 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 528 } |
529 | |
530 /** | |
531 * Sets the size of the receiver's thumb relative to the | |
532 * difference between its maximum and minimum values. This new | |
533 * value will be ignored if it is less than one, and will be | |
534 * clamped if it exceeds the receiver's current range. | |
535 * | |
536 * @param value the new thumb value, which must be at least one and not | |
537 * larger than the size of the current range | |
538 * | |
71 | 539 * @exception DWTException <ul> |
62 | 540 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
541 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
542 * </ul> | |
543 */ | |
544 public void setThumb (int value) { | |
545 checkWidget (); | |
546 if (value < 1) return; | |
547 auto adjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
548 value = cast(int) Math.min (value, cast(int)(adjustment.upper - adjustment.lower)); | |
549 adjustment.page_size = cast(double) value; | |
550 adjustment.value = Math.min (cast(int)adjustment.value, cast(int)(adjustment.upper - value)); | |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
551 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 552 OS.gtk_adjustment_changed (adjustment); |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
553 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 554 } |
555 | |
556 /** | |
557 * Sets the receiver's selection, minimum value, maximum | |
558 * value, thumb, increment and page increment all at once. | |
559 * <p> | |
560 * Note: This is similar to setting the values individually | |
561 * using the appropriate methods, but may be implemented in a | |
562 * more efficient fashion on some platforms. | |
563 * </p> | |
564 * | |
565 * @param selection the new selection value | |
566 * @param minimum the new minimum value | |
567 * @param maximum the new maximum value | |
568 * @param thumb the new thumb value | |
569 * @param increment the new increment value | |
570 * @param pageIncrement the new pageIncrement value | |
571 * | |
71 | 572 * @exception DWTException <ul> |
62 | 573 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
574 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
575 * </ul> | |
576 */ | |
577 public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) { | |
578 checkWidget (); | |
579 if (minimum < 0) return; | |
580 if (maximum < 0) return; | |
581 if (thumb < 1) return; | |
582 if (increment < 1) return; | |
583 if (pageIncrement < 1) return; | |
584 thumb = Math.min (thumb, maximum - minimum); | |
585 auto adjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle); | |
586 adjustment.value = Math.min (Math.max (selection, minimum), maximum - thumb); | |
587 adjustment.lower = cast(double) minimum; | |
588 adjustment.upper = cast(double) maximum; | |
589 adjustment.page_size = cast(double) thumb; | |
590 adjustment.step_increment = cast(double) increment; | |
591 adjustment.page_increment = cast(double) pageIncrement; | |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
592 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 593 OS.gtk_adjustment_changed (adjustment); |
594 OS.gtk_adjustment_value_changed (adjustment); | |
66
bb2217c09e61
Fixed signal blocking/unblocking:
Frank Benoit <benoit@tionex.de>
parents:
62
diff
changeset
|
595 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED); |
62 | 596 } |
597 | |
598 } |