Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 1 | package org.eclipse.swt.widgets;
|
| 2 |
|
| 3 | /*
|
Veronika Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 4 | * (c) Copyright IBM Corp. 2000, 2001.
|
| 5 | * All Rights Reserved
|
| 6 | */
|
| 7 |
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 8 | import org.eclipse.swt.internal.motif.*;
|
| 9 | import org.eclipse.swt.*;
|
| 10 | import org.eclipse.swt.events.*;
|
| 11 | import org.eclipse.swt.graphics.*;
|
| 12 |
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 13 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 57 | */
|
Carolyn MacLeod | e40d44c | 2001-11-30 16:57:14 +0000 | [diff] [blame] | 58 | public class Slider extends Control {
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 59 | /**
|
Veronika Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 60 | * 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 Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 87 | public Slider (Composite parent, int style) {
|
| 88 | super (parent, checkStyle (style));
|
| 89 | }
|
Veronika Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 90 | /**
|
| 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 Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 122 | public void addSelectionListener(SelectionListener listener) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 123 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 124 | 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 | }
|
| 129 | static int checkStyle (int style) {
|
| 130 | return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
|
| 131 | }
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 132 | public Point computeSize (int wHint, int hHint, boolean changed) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 133 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 134 | 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 | }
|
| 150 | void createHandle (int index) {
|
| 151 | state |= HANDLE;
|
Steve Northover | d583df2 | 2002-01-04 21:28:21 +0000 | [diff] [blame] | 152 | Display display = getDisplay ();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 153 | int [] argList = {
|
Veronika Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 154 | OS.XmNancestorSensitive, 1,
|
Steve Northover | d583df2 | 2002-01-04 21:28:21 +0000 | [diff] [blame] | 155 | OS.XmNhighlightThickness, display.textHighlightThickness,
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 156 | OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
|
| 157 | OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
|
| 158 | };
|
Veronika Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 159 | int parentHandle = parent.handle;
|
| 160 | handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 161 | if (handle == 0) error (SWT.ERROR_NO_HANDLES);
|
| 162 | }
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 163 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 174 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 175 | public int getIncrement () {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 176 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 177 | int [] argList = {OS.XmNincrement, 0};
|
| 178 | OS.XtGetValues (handle, argList, argList.length / 2);
|
| 179 | return argList [1];
|
| 180 | }
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 181 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 190 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 191 | public int getMaximum () {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 192 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 193 | int [] argList = {OS.XmNmaximum, 0};
|
| 194 | OS.XtGetValues (handle, argList, argList.length / 2);
|
| 195 | return argList [1];
|
| 196 | }
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 197 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 206 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 207 | public int getMinimum () {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 208 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 209 | int [] argList = {OS.XmNminimum, 0};
|
| 210 | OS.XtGetValues (handle, argList, argList.length / 2);
|
| 211 | return argList [1];
|
| 212 | }
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 213 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 224 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 225 | public int getPageIncrement () {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 226 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 227 | int [] argList = {OS.XmNpageIncrement, 0};
|
| 228 | OS.XtGetValues (handle, argList, argList.length / 2);
|
| 229 | return argList [1];
|
| 230 | }
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 231 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 240 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 241 | public int getSelection () {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 242 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 243 | int [] argList = {OS.XmNvalue, 0};
|
| 244 | OS.XtGetValues (handle, argList, argList.length / 2);
|
| 245 | return argList [1];
|
| 246 | }
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 247 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 257 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 258 | public int getThumb () {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 259 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 260 | int [] argList = {OS.XmNsliderSize, 0};
|
| 261 | OS.XtGetValues (handle, argList, argList.length / 2);
|
| 262 | return argList [1];
|
| 263 | }
|
| 264 | void 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 | }
|
| 276 | int 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 Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 297 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 313 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 314 | public void removeSelectionListener(SelectionListener listener) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 315 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 316 | 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 Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 321 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 333 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 334 | public void setIncrement (int value) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 335 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 336 | if (value < 1) return;
|
| 337 | int [] argList = {OS.XmNincrement, value};
|
| 338 | OS.XtSetValues (handle, argList, argList.length / 2);
|
| 339 | }
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 340 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 351 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 352 | public void setMaximum (int value) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 353 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 354 | 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 Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 362 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 373 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 374 | public void setMinimum (int value) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 375 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 376 | 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 Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 403 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 415 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 416 | public void setPageIncrement (int value) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 417 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 418 | if (value < 1) return;
|
| 419 | int [] argList = {OS.XmNpageIncrement, value};
|
| 420 | OS.XtSetValues (handle, argList, argList.length / 2);
|
| 421 | }
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 422 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 433 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 434 | public void setSelection (int value) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 435 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 436 | 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 Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 444 | /**
|
| 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 Irvine | 6c0e3d7 | 2001-06-21 15:16:50 +0000 | [diff] [blame] | 457 | */
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 458 | public void setThumb (int value) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 459 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 460 | 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 Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 468 | /**
|
| 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 Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 489 | public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
|
Jeff Brown | 9421e6a | 2001-08-03 04:12:44 +0000 | [diff] [blame] | 490 | checkWidget();
|
Veronika Irvine | 3275970 | 2001-05-11 13:46:50 +0000 | [diff] [blame] | 491 | 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 | }
|