1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 IBM Corporation and others.
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
10  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module org.eclipse.swt.widgets.Slider;
14 
15 import java.lang.all;
16 
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.TypedListener;
20 import org.eclipse.swt.widgets.Event;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.internal.gtk.OS;
23 import org.eclipse.swt.graphics.Point;
24 import org.eclipse.swt.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
56  * it would take to display it. SWT supports setting the thumb
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
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">SWT Example: ControlExample</a>
75  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
76  */
77 public class Slider : Control {
78 
79     alias Control.computeSize computeSize;
80 
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
88  * class <code>SWT</code> which is applicable to instances of this
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
91  * of those <code>SWT</code> style constants. The class description
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>
102  * @exception SWTException <ul>
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  *
107  * @see SWT#HORIZONTAL
108  * @see SWT#VERTICAL
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:
123  * <code>SWT.NONE</code> - for the end of a drag.
124  * <code>SWT.DRAG</code>.
125  * <code>SWT.HOME</code>.
126  * <code>SWT.END</code>.
127  * <code>SWT.ARROW_DOWN</code>.
128  * <code>SWT.ARROW_UP</code>.
129  * <code>SWT.PAGE_DOWN</code>.
130  * <code>SWT.PAGE_UP</code>.
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>
139  * @exception SWTException <ul>
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 ();
150     if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
151     TypedListener typedListener = new TypedListener (listener);
152     addListener (SWT.Selection,typedListener);
153     addListener (SWT.DefaultSelection,typedListener);
154 }
155 
156 static int checkStyle (int style) {
157     return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
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);
163     if (fixedHandle is null) error (SWT.ERROR_NO_HANDLES);
164     OS.gtk_fixed_set_has_window (fixedHandle, true);
165     auto hAdjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10);
166     if (hAdjustment is null) error (SWT.ERROR_NO_HANDLES);
167     if ((style & SWT.HORIZONTAL) !is 0) {
168         handle = cast(GtkWidget*)OS.gtk_hscrollbar_new (hAdjustment);
169     } else {
170         handle = cast(GtkWidget*)OS.gtk_vscrollbar_new (hAdjustment);
171     }
172     if (handle is null) error (SWT.ERROR_NO_HANDLES);
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 & SWT.VERTICAL) !is 0) {
182         OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
183     }
184     OS.gtk_container_add (fixedHandle, handle);
185 }
186 
187 override int 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 gtk_change_value (GtkWidget* widget, int scroll, double value1, void* user_data) {
196     detail = scroll;
197     return 0;
198 }
199 
200 override int gtk_value_changed (int adjustment) {
201     Event event = new Event ();
202     dragSent = detail is OS.GTK_SCROLL_JUMP;
203     switch (detail) {
204         case OS.GTK_SCROLL_NONE:            event.detail = SWT.NONE; break;
205         case OS.GTK_SCROLL_JUMP:            event.detail = SWT.DRAG; break;
206         case OS.GTK_SCROLL_START:           event.detail = SWT.HOME; break;
207         case OS.GTK_SCROLL_END:             event.detail = SWT.END; break;
208         case OS.GTK_SCROLL_PAGE_DOWN:
209         case OS.GTK_SCROLL_PAGE_RIGHT:
210         case OS.GTK_SCROLL_PAGE_FORWARD:    event.detail = SWT.PAGE_DOWN; break;
211         case OS.GTK_SCROLL_PAGE_UP:
212         case OS.GTK_SCROLL_PAGE_LEFT:
213         case OS.GTK_SCROLL_PAGE_BACKWARD:   event.detail = SWT.PAGE_UP; break;
214         case OS.GTK_SCROLL_STEP_DOWN:
215         case OS.GTK_SCROLL_STEP_RIGHT:
216         case OS.GTK_SCROLL_STEP_FORWARD:    event.detail = SWT.ARROW_DOWN; break;
217         case OS.GTK_SCROLL_STEP_UP:
218         case OS.GTK_SCROLL_STEP_LEFT:
219         case OS.GTK_SCROLL_STEP_BACKWARD:   event.detail = SWT.ARROW_UP; break;
220         default:
221     }
222     if (!dragSent) detail = OS.GTK_SCROLL_NONE;
223     postEvent (SWT.Selection, event);
224     return 0;
225 }
226 
227 override int gtk_event_after (GtkWidget* widget, GdkEvent* gdkEvent) {
228     GdkEventButton* gdkEventButton = null;
229     switch (gdkEvent.type) {
230         case OS.GDK_BUTTON_RELEASE: {
231             gdkEventButton = cast(GdkEventButton*)gdkEvent;
232             if (gdkEventButton.button is 1 && detail is SWT.DRAG) {
233                 if (!dragSent) {
234                     Event event = new Event ();
235                     event.detail = SWT.DRAG;
236                     postEvent (SWT.Selection, event);
237                 }
238                 postEvent (SWT.Selection);
239             }
240             detail = OS.GTK_SCROLL_NONE;
241             dragSent = false;
242             break;
243         default:
244         }
245     }
246     return super.gtk_event_after (widget, gdkEvent);
247 }
248 
249 override void hookEvents () {
250     super.hookEvents ();
251     if (OS.GTK_VERSION >= OS.buildVERSION (2, 6, 0)) {
252         OS.g_signal_connect_closure (handle, OS.change_value.ptr, display.closures [CHANGE_VALUE], false);
253     }
254     OS.g_signal_connect_closure (handle, OS.value_changed.ptr, display.closures [VALUE_CHANGED], false);
255 }
256 
257 override void register () {
258     super.register ();
259     auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
260     display.addWidget (cast(GtkWidget*)hAdjustment, this);
261 }
262 
263 override void deregister () {
264     super.deregister ();
265     auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
266     display.removeWidget (cast(GtkWidget*)hAdjustment);
267 }
268 
269 override public Point computeSize (int wHint, int hHint, bool changed) {
270     checkWidget();
271     if (wHint !is SWT.DEFAULT && wHint < 0) wHint = 0;
272     if (hHint !is SWT.DEFAULT && hHint < 0) hHint = 0;
273     Point size = computeNativeSize(handle, wHint, hHint, changed);
274     if ((style & SWT.HORIZONTAL) !is 0) {
275         if (wHint is SWT.DEFAULT) size.x = 2 * size.x;
276     } else {
277         if (hHint is SWT.DEFAULT) size.y = 2 * size.y;
278     }
279     return size;
280 }
281 
282 /**
283  * Returns the amount that the receiver's value will be
284  * modified by when the up/down (or right/left) arrows
285  * are pressed.
286  *
287  * @return the increment
288  *
289  * @exception SWTException <ul>
290  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
291  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
292  * </ul>
293  */
294 public int getIncrement () {
295     checkWidget ();
296     auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
297     return cast(int) hAdjustment.step_increment;
298 }
299 
300 /**
301  * Returns the maximum value which the receiver will allow.
302  *
303  * @return the maximum
304  *
305  * @exception SWTException <ul>
306  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
307  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
308  * </ul>
309  */
310 public int getMaximum () {
311     checkWidget ();
312     auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
313     return cast(int) hAdjustment.upper;
314 }
315 
316 /**
317  * Returns the minimum value which the receiver will allow.
318  *
319  * @return the minimum
320  *
321  * @exception SWTException <ul>
322  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
323  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
324  * </ul>
325  */
326 public int getMinimum () {
327     checkWidget ();
328     auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
329     return cast(int) hAdjustment.lower;
330 }
331 
332 /**
333  * Returns the amount that the receiver's value will be
334  * modified by when the page increment/decrement areas
335  * are selected.
336  *
337  * @return the page increment
338  *
339  * @exception SWTException <ul>
340  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
341  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
342  * </ul>
343  */
344 public int getPageIncrement () {
345     checkWidget ();
346     auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
347     return cast(int) hAdjustment.page_increment;
348 }
349 
350 /**
351  * Returns the 'selection', which is the receiver's value.
352  *
353  * @return the selection
354  *
355  * @exception SWTException <ul>
356  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
357  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
358  * </ul>
359  */
360 public int getSelection () {
361     checkWidget ();
362     auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
363     return cast(int) hAdjustment.value;
364 }
365 
366 /**
367  * Returns the size of the receiver's thumb relative to the
368  * difference between its maximum and minimum values.
369  *
370  * @return the thumb value
371  *
372  * @exception SWTException <ul>
373  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
374  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
375  * </ul>
376  */
377 public int getThumb () {
378     checkWidget ();
379     auto hAdjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
380     return cast(int) hAdjustment.page_size;
381 }
382 
383 /**
384  * Removes the listener from the collection of listeners who will
385  * be notified when the user changes the receiver's value.
386  *
387  * @param listener the listener which should no longer be notified
388  *
389  * @exception IllegalArgumentException <ul>
390  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
391  * </ul>
392  * @exception SWTException <ul>
393  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
394  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
395  * </ul>
396  *
397  * @see SelectionListener
398  * @see #addSelectionListener
399  */
400 public void removeSelectionListener (SelectionListener listener) {
401     checkWidget();
402     if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
403     if (eventTable is null) return;
404     eventTable.unhook (SWT.Selection, listener);
405     eventTable.unhook (SWT.DefaultSelection,listener);
406 }
407 
408 /**
409  * Sets the amount that the receiver's value will be
410  * modified by when the up/down (or right/left) arrows
411  * are pressed to the argument, which must be at least
412  * one.
413  *
414  * @param value the new increment (must be greater than zero)
415  *
416  * @exception SWTException <ul>
417  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
418  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
419  * </ul>
420  */
421 public void setIncrement (int value) {
422     checkWidget ();
423     if (value < 1) return;
424     OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
425     OS.gtk_range_set_increments (cast(GtkRange*)handle, value, getPageIncrement ());
426     OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
427 }
428 
429 /**
430  * Sets the maximum. If this value is negative or less than or
431  * equal to the minimum, the value is ignored. If necessary, first
432  * the thumb and then the selection are adjusted to fit within the
433  * new range.
434  *
435  * @param value the new maximum, which must be greater than the current minimum
436  *
437  * @exception SWTException <ul>
438  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
439  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
440  * </ul>
441  */
442 public void setMaximum (int value) {
443     checkWidget ();
444     auto adjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
445     int minimum = cast(int) adjustment.lower;
446     if (value <= minimum) return;
447     adjustment.upper = value;
448     adjustment.page_size = Math.min (cast(int)adjustment.page_size, value - minimum);
449     adjustment.value = Math.min (cast(int)adjustment.value, cast(int)(value - adjustment.page_size));
450     OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
451     OS.gtk_adjustment_changed (adjustment);
452     OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
453 }
454 
455 /**
456  * Sets the minimum value. If this value is negative or greater
457  * than or equal to the maximum, the value is ignored. If necessary,
458  * first the thumb and then the selection are adjusted to fit within
459  * the new range.
460  *
461  * @param value the new minimum
462  *
463  * @exception SWTException <ul>
464  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
465  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
466  * </ul>
467  */
468 public void setMinimum (int value) {
469     checkWidget ();
470     if (value < 0) return;
471     auto adjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
472     int maximum = cast(int) adjustment.upper;
473     if (value >= maximum) return;
474     adjustment.lower = value;
475     adjustment.page_size = Math.min (cast(int)adjustment.page_size, maximum - value);
476     adjustment.value = Math.max (cast(int)adjustment.value, value);
477     OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
478     OS.gtk_adjustment_changed (adjustment);
479     OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
480 }
481 
482 override void setOrientation () {
483     super.setOrientation ();
484     if ((style & SWT.RIGHT_TO_LEFT) !is 0) {
485         if ((style & SWT.HORIZONTAL) !is 0) {
486             OS.gtk_range_set_inverted (cast(GtkRange*)handle, true);
487         }
488     }
489 }
490 
491 /**
492  * Sets the amount that the receiver's value will be
493  * modified by when the page increment/decrement areas
494  * are selected to the argument, which must be at least
495  * one.
496  *
497  * @param value the page increment (must be greater than zero)
498  *
499  * @exception SWTException <ul>
500  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
501  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
502  * </ul>
503  */
504 public void setPageIncrement (int value) {
505     checkWidget ();
506     if (value < 1) return;
507     OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
508     OS.gtk_range_set_increments (cast(GtkRange*)handle, getIncrement (), value);
509     OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
510 }
511 
512 /**
513  * Sets the 'selection', which is the receiver's
514  * value, to the argument which must be greater than or equal
515  * to zero.
516  *
517  * @param value the new selection (must be zero or greater)
518  *
519  * @exception SWTException <ul>
520  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
521  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
522  * </ul>
523  */
524 public void setSelection (int value) {
525     checkWidget ();
526     OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
527     OS.gtk_range_set_value (cast(GtkRange*)handle, value);
528     OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
529 }
530 
531 /**
532  * Sets the size of the receiver's thumb relative to the
533  * difference between its maximum and minimum values.  This new
534  * value will be ignored if it is less than one, and will be
535  * clamped if it exceeds the receiver's current range.
536  *
537  * @param value the new thumb value, which must be at least one and not
538  * larger than the size of the current range
539  *
540  * @exception SWTException <ul>
541  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
542  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
543  * </ul>
544  */
545 public void setThumb (int value) {
546     checkWidget ();
547     if (value < 1) return;
548     auto adjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
549     value = cast(int) Math.min (value, cast(int)(adjustment.upper - adjustment.lower));
550     adjustment.page_size = cast(double) value;
551     adjustment.value = Math.min (cast(int)adjustment.value, cast(int)(adjustment.upper - value));
552     OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
553     OS.gtk_adjustment_changed (adjustment);
554     OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
555 }
556 
557 /**
558  * Sets the receiver's selection, minimum value, maximum
559  * value, thumb, increment and page increment all at once.
560  * <p>
561  * Note: This is similar to setting the values individually
562  * using the appropriate methods, but may be implemented in a
563  * more efficient fashion on some platforms.
564  * </p>
565  *
566  * @param selection the new selection value
567  * @param minimum the new minimum value
568  * @param maximum the new maximum value
569  * @param thumb the new thumb value
570  * @param increment the new increment value
571  * @param pageIncrement the new pageIncrement value
572  *
573  * @exception SWTException <ul>
574  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
575  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
576  * </ul>
577  */
578 public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
579     checkWidget ();
580     if (minimum < 0) return;
581     if (maximum < 0) return;
582     if (thumb < 1) return;
583     if (increment < 1) return;
584     if (pageIncrement < 1) return;
585     thumb = Math.min (thumb, maximum - minimum);
586     auto adjustment = OS.gtk_range_get_adjustment (cast(GtkRange*)handle);
587     adjustment.value = Math.min (Math.max (selection, minimum), maximum - thumb);
588     adjustment.lower = cast(double) minimum;
589     adjustment.upper = cast(double) maximum;
590     adjustment.page_size = cast(double) thumb;
591     adjustment.step_increment = cast(double) increment;
592     adjustment.page_increment = cast(double) pageIncrement;
593     OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
594     OS.gtk_adjustment_changed (adjustment);
595     OS.gtk_adjustment_value_changed (adjustment);
596     OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udVALUE_CHANGED);
597 }
598 
599 }