blob: f8cbf10cdf4beb02b9d6c0dcc5f0f34f9211b140 [file] [log] [blame]
Veronika Irvine32759702001-05-11 13:46:50 +00001package org.eclipse.swt.widgets;
2
3/*
Veronika Irvine6c0e3d72001-06-21 15:16:50 +00004 * (c) Copyright IBM Corp. 2000, 2001.
5 * All Rights Reserved
6 */
7
Veronika Irvine32759702001-05-11 13:46:50 +00008import org.eclipse.swt.internal.motif.*;
9import org.eclipse.swt.*;
10import org.eclipse.swt.events.*;
11import org.eclipse.swt.graphics.*;
12
Jeff Brown9421e6a2001-08-03 04:12:44 +000013/**
14 * Instances of this class are selectable user interface
15 * objects that represent a range of positive, numeric values.
16 * <p>
17 * At any given moment, a given slider will have a
18 * single <em>selection</em> that is considered to be its
19 * value, which is constrained to be within the range of
20 * values the slider represents (that is, between its
21 * <em>minimum</em> and <em>maximum</em> values).
22 * </p><p>
23 * Typically, sliders will be made up of five areas:
24 * <ol>
25 * <li>an arrow button for decrementing the value</li>
26 * <li>a page decrement area for decrementing the value by a larger amount</li>
27 * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
28 * <li>a page increment area for incrementing the value by a larger amount</li>
29 * <li>an arrow button for incrementing the value</li>
30 * </ol>
31 * Based on their style, sliders are either <code>HORIZONTAL</code>
32 * (which have left and right facing buttons for incrementing and
33 * decrementing the value) or <code>VERTICAL</code> (which have
34 * up and down facing buttons for incrementing and decrementing
35 * the value).
36 * </p><p>
37 * On some platforms, the size of the slider's thumb can be
38 * varied relative to the magnitude of the range of values it
39 * represents (that is, relative to the difference between its
40 * maximum and minimum values). Typically, this is used to
41 * indicate some proportional value such as the ratio of the
42 * visible area of a document to the total amount of space that
43 * it would take to display it. SWT supports setting the thumb
44 * size even if the underlying platform does not, but in this
45 * case the appearance of the slider will not change.
46 * </p>
47 * <dl>
48 * <dt><b>Styles:</b></dt>
49 * <dd>HORIZONTAL, VERTICAL</dd>
50 * <dt><b>Events:</b></dt>
51 * <dd>Selection</dd>
52 * </dl>
53 * <p>
54 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
55 *
56 * @see ScrollBar
Veronika Irvine6c0e3d72001-06-21 15:16:50 +000057 */
Carolyn MacLeode40d44c2001-11-30 16:57:14 +000058public class Slider extends Control {
Veronika Irvine32759702001-05-11 13:46:50 +000059/**
Veronika Irvine6c0e3d72001-06-21 15:16:50 +000060 * Constructs a new instance of this class given its parent
61 * and a style value describing its behavior and appearance.
62 * <p>
63 * The style value is either one of the style constants defined in
64 * class <code>SWT</code> which is applicable to instances of this
65 * class, or must be built by <em>bitwise OR</em>'ing together
66 * (that is, using the <code>int</code> "|" operator) two or more
67 * of those <code>SWT</code> style constants. The class description
68 * for all SWT widget classes should include a comment which
69 * describes the style constants which are applicable to the class.
70 * </p>
71 *
72 * @param parent a composite control which will be the parent of the new instance (cannot be null)
73 * @param style the style of control to construct
74 *
75 * @exception IllegalArgumentException <ul>
76 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
77 * </ul>
78 * @exception SWTException <ul>
79 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
80 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
81 * </ul>
82 *
83 * @see SWT
84 * @see Widget#checkSubclass
85 * @see Widget#getStyle
86 */
Veronika Irvine32759702001-05-11 13:46:50 +000087public Slider (Composite parent, int style) {
88 super (parent, checkStyle (style));
89}
Veronika Irvine6c0e3d72001-06-21 15:16:50 +000090/**
91 * Adds the listener to the collection of listeners who will
92 * be notified when the receiver's value changes, by sending
93 * it one of the messages defined in the <code>SelectionListener</code>
94 * interface.
95 * <p>
96 * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
97 * <code>0</code> - for the end of a drag.
98 * <code>SWT.DRAG</code>.
99 * <code>SWT.HOME</code>.
100 * <code>SWT.END</code>.
101 * <code>SWT.ARROW_DOWN</code>.
102 * <code>SWT.ARROW_UP</code>.
103 * <code>SWT.PAGE_DOWN</code>.
104 * <code>SWT.PAGE_UP</code>.
105 * <code>widgetDefaultSelected</code> is not called.
106 * </p>
107 *
108 * @param listener the listener which should be notified
109 *
110 * @exception IllegalArgumentException <ul>
111 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
112 * </ul>
113 * @exception SWTException <ul>
114 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
115 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
116 * </ul>
117 *
118 * @see SelectionListener
119 * @see #removeSelectionListener
120 * @see SelectionEvent
121 */
Veronika Irvine32759702001-05-11 13:46:50 +0000122public void addSelectionListener(SelectionListener listener) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000123 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000124 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
125 TypedListener typedListener = new TypedListener(listener);
126 addListener(SWT.Selection,typedListener);
127 addListener(SWT.DefaultSelection,typedListener);
128}
129static int checkStyle (int style) {
130 return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
131}
Veronika Irvine32759702001-05-11 13:46:50 +0000132public Point computeSize (int wHint, int hHint, boolean changed) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000133 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000134 int border = getBorderWidth ();
135 int width = border * 2, height = border * 2;
136 Display display = getDisplay ();
137 int hScroll = display.scrolledMarginX;
138 int vScroll = display.scrolledMarginY;
139 if ((style & SWT.HORIZONTAL) != 0) {
140 width += hScroll * 10;
141 height += vScroll;
142 } else {
143 width += hScroll;
144 height += vScroll * 10;
145 }
146 if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
147 if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
148 return new Point (width, height);
149}
150void createHandle (int index) {
151 state |= HANDLE;
Steve Northoverd583df22002-01-04 21:28:21 +0000152 Display display = getDisplay ();
Veronika Irvine32759702001-05-11 13:46:50 +0000153 int [] argList = {
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000154 OS.XmNancestorSensitive, 1,
Steve Northoverd583df22002-01-04 21:28:21 +0000155 OS.XmNhighlightThickness, display.textHighlightThickness,
Veronika Irvine32759702001-05-11 13:46:50 +0000156 OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
157 OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
158 };
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000159 int parentHandle = parent.handle;
160 handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
Veronika Irvine32759702001-05-11 13:46:50 +0000161 if (handle == 0) error (SWT.ERROR_NO_HANDLES);
162}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000163/**
164 * Returns the amount that the receiver's value will be
165 * modified by when the up/down (or right/left) arrows
166 * are pressed.
167 *
168 * @return the increment
169 *
170 * @exception SWTException <ul>
171 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
172 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
173 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000174 */
Veronika Irvine32759702001-05-11 13:46:50 +0000175public int getIncrement () {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000176 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000177 int [] argList = {OS.XmNincrement, 0};
178 OS.XtGetValues (handle, argList, argList.length / 2);
179 return argList [1];
180}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000181/**
182 * Returns the maximum value which the receiver will allow.
183 *
184 * @return the maximum
185 *
186 * @exception SWTException <ul>
187 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
188 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
189 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000190 */
Veronika Irvine32759702001-05-11 13:46:50 +0000191public int getMaximum () {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000192 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000193 int [] argList = {OS.XmNmaximum, 0};
194 OS.XtGetValues (handle, argList, argList.length / 2);
195 return argList [1];
196}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000197/**
198 * Returns the minimum value which the receiver will allow.
199 *
200 * @return the minimum
201 *
202 * @exception SWTException <ul>
203 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
204 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
205 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000206 */
Veronika Irvine32759702001-05-11 13:46:50 +0000207public int getMinimum () {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000208 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000209 int [] argList = {OS.XmNminimum, 0};
210 OS.XtGetValues (handle, argList, argList.length / 2);
211 return argList [1];
212}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000213/**
214 * Returns the amount that the receiver's value will be
215 * modified by when the page increment/decrement areas
216 * are selected.
217 *
218 * @return the page increment
219 *
220 * @exception SWTException <ul>
221 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
222 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
223 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000224 */
Veronika Irvine32759702001-05-11 13:46:50 +0000225public int getPageIncrement () {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000226 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000227 int [] argList = {OS.XmNpageIncrement, 0};
228 OS.XtGetValues (handle, argList, argList.length / 2);
229 return argList [1];
230}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000231/**
232 * Returns the single <em>selection</em> that is the receiver's value.
233 *
234 * @return the selection
235 *
236 * @exception SWTException <ul>
237 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
238 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
239 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000240 */
Veronika Irvine32759702001-05-11 13:46:50 +0000241public int getSelection () {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000242 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000243 int [] argList = {OS.XmNvalue, 0};
244 OS.XtGetValues (handle, argList, argList.length / 2);
245 return argList [1];
246}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000247/**
248 * Returns the size of the receiver's thumb relative to the
249 * difference between its maximum and minimum values.
250 *
251 * @return the thumb value
252 *
253 * @exception SWTException <ul>
254 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
255 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
256 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000257 */
Veronika Irvine32759702001-05-11 13:46:50 +0000258public int getThumb () {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000259 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000260 int [] argList = {OS.XmNsliderSize, 0};
261 OS.XtGetValues (handle, argList, argList.length / 2);
262 return argList [1];
263}
264void hookEvents () {
265 super.hookEvents ();
266 int windowProc = getDisplay ().windowProc;
267 OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, SWT.Selection);
268 OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, SWT.Selection);
269 OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, SWT.Selection);
270 OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, SWT.Selection);
271 OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, SWT.Selection);
272 OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, SWT.Selection);
273 OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, SWT.Selection);
274 OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, SWT.Selection);
275}
276int processSelection (int callData) {
277 XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
278 OS.memmove (struct, callData, XmAnyCallbackStruct.sizeof);
279 Event event = new Event ();
280 switch (struct.reason) {
281 case OS.XmCR_DRAG: event.detail = SWT.DRAG; break;
282 /*
283 * Do not set the detail field to SWT.DRAG
284 * to indicate that the dragging has ended.
285 */
286// case OS.XmCR_VALUE_CHANGED: break;
287 case OS.XmCR_TO_TOP: event.detail = SWT.HOME; break;
288 case OS.XmCR_TO_BOTTOM: event.detail = SWT.END; break;
289 case OS.XmCR_DECREMENT: event.detail = SWT.ARROW_UP; break;
290 case OS.XmCR_INCREMENT: event.detail = SWT.ARROW_DOWN; break;
291 case OS.XmCR_PAGE_DECREMENT: event.detail = SWT.PAGE_UP; break;
292 case OS.XmCR_PAGE_INCREMENT: event.detail = SWT.PAGE_DOWN; break;
293 }
294 sendEvent (SWT.Selection, event);
295 return 0;
296}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000297/**
298 * Removes the listener from the collection of listeners who will
299 * be notified when the receiver's value changes.
300 *
301 * @param listener the listener which should no longer be notified
302 *
303 * @exception IllegalArgumentException <ul>
304 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
305 * </ul>
306 * @exception SWTException <ul>
307 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
308 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
309 * </ul>
310 *
311 * @see SelectionListener
312 * @see #addSelectionListener
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000313 */
Veronika Irvine32759702001-05-11 13:46:50 +0000314public void removeSelectionListener(SelectionListener listener) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000315 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000316 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
317 if (eventTable == null) return;
318 eventTable.unhook(SWT.Selection, listener);
319 eventTable.unhook(SWT.DefaultSelection,listener);
320}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000321/**
322 * Sets the amount that the receiver's value will be
323 * modified by when the up/down (or right/left) arrows
324 * are pressed to the argument, which must be at least
325 * one.
326 *
327 * @param value the new increment (must be greater than zero)
328 *
329 * @exception SWTException <ul>
330 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
331 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
332 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000333 */
Veronika Irvine32759702001-05-11 13:46:50 +0000334public void setIncrement (int value) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000335 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000336 if (value < 1) return;
337 int [] argList = {OS.XmNincrement, value};
338 OS.XtSetValues (handle, argList, argList.length / 2);
339}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000340/**
341 * Sets the maximum value which the receiver will allow
342 * to be the argument which must be greater than or
343 * equal to zero.
344 *
345 * @param value the new maximum (must be zero or greater)
346 *
347 * @exception SWTException <ul>
348 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
349 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
350 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000351 */
Veronika Irvine32759702001-05-11 13:46:50 +0000352public void setMaximum (int value) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000353 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000354 if (value < 0) return;
355 int [] argList = {OS.XmNmaximum, value};
356 Display display = getDisplay ();
357 boolean warnings = display.getWarnings ();
358 display.setWarnings (false);
359 OS.XtSetValues (handle, argList, argList.length / 2);
360 display.setWarnings (warnings);
361}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000362/**
363 * Sets the minimum value which the receiver will allow
364 * to be the argument which must be greater than or
365 * equal to zero.
366 *
367 * @param value the new minimum (must be zero or greater)
368 *
369 * @exception SWTException <ul>
370 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
371 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
372 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000373 */
Veronika Irvine32759702001-05-11 13:46:50 +0000374public void setMinimum (int value) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000375 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000376 if (value < 0) return;
377 int [] argList = {
378 OS.XmNminimum, 0,
379 OS.XmNmaximum, 0,
380 OS.XmNsliderSize, 0,
381 };
382 /*
383 * Feature in Motif. For some reason, when minimium
384 * is set to be greater than or equal to maximum, Motif
385 * does not set the minimum. Instead, the value is
386 * changed and the minimum stays the same. This behavior
387 * differs from setting the maximum where the slider size
388 * is always decreased to make room for the new maximum.
389 * The fix is to decrease the slider to make room for
390 * the new minimum.
391 */
392 OS.XtGetValues (handle, argList, argList.length / 2);
393 if (argList [3] - value - argList [5] < 0) {
394 argList [5] = argList [3] - value;
395 }
396 argList [1] = value;
397 Display display = getDisplay ();
398 boolean warnings = display.getWarnings ();
399 display.setWarnings (false);
400 OS.XtSetValues (handle, argList, argList.length / 2);
401 display.setWarnings (warnings);
402}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000403/**
404 * Sets the amount that the receiver's value will be
405 * modified by when the page increment/decrement areas
406 * are selected to the argument, which must be at least
407 * one.
408 *
409 * @return the page increment (must be greater than zero)
410 *
411 * @exception SWTException <ul>
412 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
413 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
414 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000415 */
Veronika Irvine32759702001-05-11 13:46:50 +0000416public void setPageIncrement (int value) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000417 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000418 if (value < 1) return;
419 int [] argList = {OS.XmNpageIncrement, value};
420 OS.XtSetValues (handle, argList, argList.length / 2);
421}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000422/**
423 * Sets the single <em>selection</em> that is the receiver's
424 * value to the argument which must be greater than or equal
425 * to zero.
426 *
427 * @param value the new selection (must be zero or greater)
428 *
429 * @exception SWTException <ul>
430 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
431 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
432 * </ul>
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000433 */
Veronika Irvine32759702001-05-11 13:46:50 +0000434public void setSelection (int value) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000435 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000436 if (value < 0) return;
437 int [] argList = {OS.XmNvalue, value};
438 Display display = getDisplay ();
439 boolean warnings = display.getWarnings ();
440 display.setWarnings (false);
441 OS.XtSetValues (handle, argList, argList.length / 2);
442 display.setWarnings (warnings);
443}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000444/**
445 * Sets the size of the receiver's thumb relative to the
446 * difference between its maximum and minimum values to the
447 * argument which must be at least one.
448 *
449 * @param value the new thumb value (must be at least one)
450 *
451 * @exception SWTException <ul>
452 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
453 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
454 * </ul>
455 *
456 * @see ScrollBar
Veronika Irvine6c0e3d72001-06-21 15:16:50 +0000457 */
Veronika Irvine32759702001-05-11 13:46:50 +0000458public void setThumb (int value) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000459 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000460 if (value < 1) return;
461 int [] argList = {OS.XmNsliderSize, value};
462 Display display = getDisplay ();
463 boolean warnings = display.getWarnings ();
464 display.setWarnings (false);
465 OS.XtSetValues (handle, argList, argList.length / 2);
466 display.setWarnings (warnings);
467}
Jeff Brown9421e6a2001-08-03 04:12:44 +0000468/**
469 * Sets the receiver's selection, minimum value, maximum
470 * value, thumb, increment and page increment all at once.
471 * <p>
472 * Note: This is equivalent to setting the values individually
473 * using the appropriate methods, but may be implemented in a
474 * more efficient fashion on some platforms.
475 * </p>
476 *
477 * @param selection the new selection value
478 * @param minimum the new minimum value
479 * @param maximum the new maximum value
480 * @param thumb the new thumb value
481 * @param increment the new increment value
482 * @param pageIncrement the new pageIncrement value
483 *
484 * @exception SWTException <ul>
485 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
486 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
487 * </ul>
488 */
Veronika Irvine32759702001-05-11 13:46:50 +0000489public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
Jeff Brown9421e6a2001-08-03 04:12:44 +0000490 checkWidget();
Veronika Irvine32759702001-05-11 13:46:50 +0000491 if (selection < 0) return;
492 if (minimum < 0) return;
493 if (maximum < 0) return;
494 if (thumb < 1) return;
495 if (maximum - minimum - thumb < 0) return;
496 if (increment < 1) return;
497 if (pageIncrement < 1) return;
498 int [] argList = {
499 OS.XmNvalue, selection,
500 OS.XmNminimum, minimum,
501 OS.XmNmaximum, maximum,
502 OS.XmNsliderSize, thumb,
503 OS.XmNincrement, increment,
504 OS.XmNpageIncrement, pageIncrement,
505 };
506 Display display = getDisplay ();
507 boolean warnings = display.getWarnings ();
508 display.setWarnings (false);
509 OS.XtSetValues (handle, argList, argList.length / 2);
510 display.setWarnings (warnings);
511}
512}