]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/widgets/Slider.java
Remove invalid SHA-256-Digests
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / widgets / Slider.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2012 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.widgets;
15
16
17 import org.eclipse.swt.internal.win32.*;
18 import org.eclipse.swt.*;
19 import org.eclipse.swt.graphics.*;
20 import org.eclipse.swt.events.*;
21
22 /**
23  * Instances of this class are selectable user interface
24  * objects that represent a range of positive, numeric values.
25  * <p>
26  * At any given moment, a given slider will have a
27  * single 'selection' that is considered to be its
28  * value, which is constrained to be within the range of
29  * values the slider represents (that is, between its
30  * <em>minimum</em> and <em>maximum</em> values).
31  * </p><p>
32  * Typically, sliders will be made up of five areas:
33  * </p>
34  * <ol>
35  * <li>an arrow button for decrementing the value</li>
36  * <li>a page decrement area for decrementing the value by a larger amount</li>
37  * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
38  * <li>a page increment area for incrementing the value by a larger amount</li>
39  * <li>an arrow button for incrementing the value</li>
40  * </ol>
41  * <p>
42  * Based on their style, sliders are either <code>HORIZONTAL</code>
43  * (which have a left facing button for decrementing the value and a
44  * right facing button for incrementing it) or <code>VERTICAL</code>
45  * (which have an upward facing button for decrementing the value
46  * and a downward facing buttons for incrementing it).
47  * </p><p>
48  * On some platforms, the size of the slider's thumb can be
49  * varied relative to the magnitude of the range of values it
50  * represents (that is, relative to the difference between its
51  * maximum and minimum values). Typically, this is used to
52  * indicate some proportional value such as the ratio of the
53  * visible area of a document to the total amount of space that
54  * it would take to display it. SWT supports setting the thumb
55  * size even if the underlying platform does not, but in this
56  * case the appearance of the slider will not change.
57  * </p>
58  * <dl>
59  * <dt><b>Styles:</b></dt>
60  * <dd>HORIZONTAL, VERTICAL</dd>
61  * <dt><b>Events:</b></dt>
62  * <dd>Selection</dd>
63  * </dl>
64  * <p>
65  * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
66  * </p><p>
67  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
68  * </p>
69  *
70  * @see ScrollBar
71  * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
72  * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
73  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
74  * @noextend This class is not intended to be subclassed by clients.
75  */
76 public class Slider extends Control {
77         int increment, pageIncrement;
78         boolean ignoreFocus;
79         static final long ScrollBarProc;
80         static final TCHAR ScrollBarClass = new TCHAR (0, "SCROLLBAR", true);
81         static {
82                 WNDCLASS lpWndClass = new WNDCLASS ();
83                 OS.GetClassInfo (0, ScrollBarClass, lpWndClass);
84                 ScrollBarProc = lpWndClass.lpfnWndProc;
85         }
86
87 /**
88  * Constructs a new instance of this class given its parent
89  * and a style value describing its behavior and appearance.
90  * <p>
91  * The style value is either one of the style constants defined in
92  * class <code>SWT</code> which is applicable to instances of this
93  * class, or must be built by <em>bitwise OR</em>'ing together
94  * (that is, using the <code>int</code> "|" operator) two or more
95  * of those <code>SWT</code> style constants. The class description
96  * lists the style constants that are applicable to the class.
97  * Style bits are also inherited from superclasses.
98  * </p>
99  *
100  * @param parent a composite control which will be the parent of the new instance (cannot be null)
101  * @param style the style of control to construct
102  *
103  * @exception IllegalArgumentException <ul>
104  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
105  * </ul>
106  * @exception SWTException <ul>
107  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
108  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
109  * </ul>
110  *
111  * @see SWT#HORIZONTAL
112  * @see SWT#VERTICAL
113  * @see Widget#checkSubclass
114  * @see Widget#getStyle
115  */
116 public Slider (Composite parent, int style) {
117         super (parent, checkStyle (style));
118 }
119
120 /**
121  * Adds the listener to the collection of listeners who will
122  * be notified when the user changes the receiver's value, by sending
123  * it one of the messages defined in the <code>SelectionListener</code>
124  * interface.
125  * <p>
126  * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
127  * <code>SWT.NONE</code> - for the end of a drag.
128  * <code>SWT.DRAG</code>.
129  * <code>SWT.HOME</code>.
130  * <code>SWT.END</code>.
131  * <code>SWT.ARROW_DOWN</code>.
132  * <code>SWT.ARROW_UP</code>.
133  * <code>SWT.PAGE_DOWN</code>.
134  * <code>SWT.PAGE_UP</code>.
135  * <code>widgetDefaultSelected</code> is not called.
136  * </p>
137  *
138  * @param listener the listener which should be notified when the user changes the receiver's value
139  *
140  * @exception IllegalArgumentException <ul>
141  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
142  * </ul>
143  * @exception SWTException <ul>
144  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
145  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
146  * </ul>
147  *
148  * @see SelectionListener
149  * @see #removeSelectionListener
150  * @see SelectionEvent
151  */
152 public void addSelectionListener (SelectionListener listener) {
153         checkWidget ();
154         if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
155         TypedListener typedListener = new TypedListener(listener);
156         addListener (SWT.Selection,typedListener);
157         addListener (SWT.DefaultSelection,typedListener);
158 }
159
160 @Override
161 long callWindowProc (long hwnd, int msg, long wParam, long lParam) {
162         if (handle == 0) return 0;
163         /*
164         * Feature in Windows.  Windows runs a modal message
165         * loop when the user drags a scroll bar.  This means
166         * that mouse down events won't get delivered until
167         * after the loop finishes.  The fix is to run any
168         * deferred messages, including mouse down messages
169         * before calling the scroll bar window proc.
170         */
171         switch (msg) {
172                 case OS.WM_LBUTTONDOWN:
173                 case OS.WM_LBUTTONDBLCLK:
174                         display.runDeferredEvents ();
175         }
176         return OS.CallWindowProc (ScrollBarProc, hwnd, msg, wParam, lParam);
177 }
178
179 static int checkStyle (int style) {
180         return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
181 }
182
183 @Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
184         checkWidget ();
185         int border = getBorderWidthInPixels ();
186         int width = border * 2, height = border * 2;
187         if ((style & SWT.HORIZONTAL) != 0) {
188                 width += OS.GetSystemMetrics (OS.SM_CXHSCROLL) * 10;
189                 height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
190         } else {
191                 width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
192                 height += OS.GetSystemMetrics (OS.SM_CYVSCROLL) * 10;
193         }
194         if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
195         if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
196         return new Point (width, height);
197 }
198
199 @Override
200 void createWidget () {
201         super.createWidget ();
202         increment = 1;
203         pageIncrement = 10;
204         /*
205         * Set the initial values of the maximum
206         * to 100 and the thumb to 10.  Note that
207         * info.nPage needs to be 11 in order to
208         * get a thumb that is 10.
209         */
210         SCROLLINFO info = new SCROLLINFO ();
211         info.cbSize = SCROLLINFO.sizeof;
212         info.fMask = OS.SIF_ALL;
213         info.nMax = 100;
214         info.nPage = 11;
215         OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
216 }
217
218 @Override
219 int defaultBackground () {
220         return OS.GetSysColor (OS.COLOR_SCROLLBAR);
221 }
222
223 @Override
224 int defaultForeground () {
225         return OS.GetSysColor (OS.COLOR_BTNFACE);
226 }
227
228 @Override
229 void enableWidget (boolean enabled) {
230         super.enableWidget (enabled);
231         int flags = enabled ? OS.ESB_ENABLE_BOTH : OS.ESB_DISABLE_BOTH;
232         OS.EnableScrollBar (handle, OS.SB_CTL, flags);
233         if (enabled) {
234                 state &= ~DISABLED;
235         } else {
236                 state |= DISABLED;
237         }
238 }
239
240 @Override
241 public boolean getEnabled () {
242         checkWidget ();
243         return (state & DISABLED) == 0;
244 }
245
246 /**
247  * Returns the amount that the receiver's value will be
248  * modified by when the up/down (or right/left) arrows
249  * are pressed.
250  *
251  * @return the increment
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>
257  */
258 public int getIncrement () {
259         checkWidget ();
260         return increment;
261 }
262
263 /**
264  * Returns the maximum value which the receiver will allow.
265  *
266  * @return the maximum
267  *
268  * @exception SWTException <ul>
269  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
270  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
271  * </ul>
272  */
273 public int getMaximum () {
274         checkWidget ();
275         SCROLLINFO info = new SCROLLINFO ();
276         info.cbSize = SCROLLINFO.sizeof;
277         info.fMask = OS.SIF_RANGE;
278         OS.GetScrollInfo (handle, OS.SB_CTL, info);
279         return info.nMax;
280 }
281
282 /**
283  * Returns the minimum value which the receiver will allow.
284  *
285  * @return the minimum
286  *
287  * @exception SWTException <ul>
288  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
289  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
290  * </ul>
291  */
292 public int getMinimum () {
293         checkWidget ();
294         SCROLLINFO info = new SCROLLINFO ();
295         info.cbSize = SCROLLINFO.sizeof;
296         info.fMask = OS.SIF_RANGE;
297         OS.GetScrollInfo (handle, OS.SB_CTL, info);
298         return info.nMin;
299 }
300
301 /**
302  * Returns the amount that the receiver's value will be
303  * modified by when the page increment/decrement areas
304  * are selected.
305  *
306  * @return the page increment
307  *
308  * @exception SWTException <ul>
309  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
310  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
311  * </ul>
312  */
313 public int getPageIncrement () {
314         checkWidget ();
315         return pageIncrement;
316 }
317
318 /**
319  * Returns the 'selection', which is the receiver's value.
320  *
321  * @return the selection
322  *
323  * @exception SWTException <ul>
324  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
325  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
326  * </ul>
327  */
328 public int getSelection () {
329         checkWidget ();
330         SCROLLINFO info = new SCROLLINFO ();
331         info.cbSize = SCROLLINFO.sizeof;
332         info.fMask = OS.SIF_POS;
333         OS.GetScrollInfo (handle, OS.SB_CTL, info);
334         return info.nPos;
335 }
336
337 /**
338  * Returns the receiver's thumb value.
339  *
340  * @return the thumb value
341  *
342  * @exception SWTException <ul>
343  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
344  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
345  * </ul>
346  */
347 public int getThumb () {
348         checkWidget ();
349         SCROLLINFO info = new SCROLLINFO ();
350         info.cbSize = SCROLLINFO.sizeof;
351         info.fMask = OS.SIF_PAGE;
352         OS.GetScrollInfo (handle, OS.SB_CTL, info);
353         if (info.nPage != 0) --info.nPage;
354         return info.nPage;
355 }
356
357 /**
358  * Removes the listener from the collection of listeners who will
359  * be notified when the user changes the receiver's value.
360  *
361  * @param listener the listener which should no longer be notified
362  *
363  * @exception IllegalArgumentException <ul>
364  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
365  * </ul>
366  * @exception SWTException <ul>
367  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
368  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
369  * </ul>
370  *
371  * @see SelectionListener
372  * @see #addSelectionListener
373  */
374 public void removeSelectionListener (SelectionListener listener) {
375         checkWidget ();
376         if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
377         if (eventTable == null) return;
378         eventTable.unhook (SWT.Selection, listener);
379         eventTable.unhook (SWT.DefaultSelection,listener);
380 }
381
382 @Override
383 void setBoundsInPixels (int x, int y, int width, int height, int flags) {
384         super.setBoundsInPixels (x, y, width, height, flags);
385         /*
386         * Bug in Windows.  If the scroll bar is resized when it has focus,
387         * the flashing cursor that is used to show that the scroll bar has
388         * focus is not moved.  The fix is to send a fake WM_SETFOCUS to
389         * get the scroll bar to recompute the size of the flashing cursor.
390         */
391         if (OS.GetFocus () == handle) {
392                 ignoreFocus = true;
393                 OS.SendMessage (handle, OS.WM_SETFOCUS, 0, 0);
394                 ignoreFocus = false;
395         }
396 }
397
398 /**
399  * Sets the amount that the receiver's value will be
400  * modified by when the up/down (or right/left) arrows
401  * are pressed to the argument, which must be at least
402  * one.
403  *
404  * @param value the new increment (must be greater than zero)
405  *
406  * @exception SWTException <ul>
407  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
408  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
409  * </ul>
410  */
411 public void setIncrement (int value) {
412         checkWidget ();
413         if (value < 1) return;
414         increment = value;
415 }
416
417 /**
418  * Sets the maximum. If this value is negative or less than or
419  * equal to the minimum, the value is ignored. If necessary, first
420  * the thumb and then the selection are adjusted to fit within the
421  * new range.
422  *
423  * @param value the new maximum, which must be greater than the current minimum
424  *
425  * @exception SWTException <ul>
426  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
427  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
428  * </ul>
429  */
430 public void setMaximum (int value) {
431         checkWidget ();
432         if (value < 0) return;
433         SCROLLINFO info = new SCROLLINFO ();
434         info.cbSize = SCROLLINFO.sizeof;
435         info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
436         OS.GetScrollInfo (handle, OS.SB_CTL, info);
437         if (value - info.nMin - info.nPage < 1) return;
438         info.nMax = value;
439         SetScrollInfo (handle, OS.SB_CTL, info, true);
440 }
441
442 /**
443  * Sets the minimum value. If this value is negative or greater
444  * than or equal to the maximum, the value is ignored. If necessary,
445  * first the thumb and then the selection are adjusted to fit within
446  * the new range.
447  *
448  * @param value the new minimum
449  *
450  * @exception SWTException <ul>
451  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
452  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
453  * </ul>
454  */
455 public void setMinimum (int value) {
456         checkWidget ();
457         if (value < 0) return;
458         SCROLLINFO info = new SCROLLINFO ();
459         info.cbSize = SCROLLINFO.sizeof;
460         info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
461         OS.GetScrollInfo (handle, OS.SB_CTL, info);
462         if (info.nMax - value - info.nPage < 1) return;
463         info.nMin = value;
464         SetScrollInfo (handle, OS.SB_CTL, info, true);
465 }
466
467 /**
468  * Sets the amount that the receiver's value will be
469  * modified by when the page increment/decrement areas
470  * are selected to the argument, which must be at least
471  * one.
472  *
473  * @param value the page increment (must be greater than zero)
474  *
475  * @exception SWTException <ul>
476  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
477  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
478  * </ul>
479  */
480 public void setPageIncrement (int value) {
481         checkWidget ();
482         if (value < 1) return;
483         pageIncrement = value;
484 }
485
486 boolean SetScrollInfo (long hwnd, int flags, SCROLLINFO info, boolean fRedraw) {
487         /*
488         * Feature in Windows.  Using SIF_DISABLENOSCROLL,
489         * SetScrollInfo () can change enabled and disabled
490         * state of the scroll bar causing a scroll bar that
491         * was disabled by the application to become enabled.
492         * The fix is to disable the scroll bar (again) when
493         * the application has disabled the scroll bar.
494         */
495         if ((state & DISABLED) != 0) fRedraw = false;
496         boolean result = OS.SetScrollInfo (hwnd, flags, info, fRedraw);
497         if ((state & DISABLED) != 0) {
498                 OS.EnableWindow (handle, false);
499                 OS.EnableScrollBar (handle, OS.SB_CTL, OS.ESB_DISABLE_BOTH);
500         }
501
502         /*
503         * Bug in Windows.  If the thumb is resized when it has focus,
504         * the flashing cursor that is used to show that the scroll bar
505         * has focus is not moved.  The fix is to send a fake WM_SETFOCUS
506         * to get the scroll bar to recompute the size of the flashing
507         * cursor.
508         */
509         if (OS.GetFocus () == handle) {
510                 ignoreFocus = true;
511                 OS.SendMessage (handle, OS.WM_SETFOCUS, 0, 0);
512                 ignoreFocus = false;
513         }
514         return result;
515 }
516
517 /**
518  * Sets the 'selection', which is the receiver's
519  * value, to the argument which must be greater than or equal
520  * to zero.
521  *
522  * @param value the new selection (must be zero or greater)
523  *
524  * @exception SWTException <ul>
525  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
526  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
527  * </ul>
528  */
529 public void setSelection (int value) {
530         checkWidget ();
531         SCROLLINFO info = new SCROLLINFO ();
532         info.cbSize = SCROLLINFO.sizeof;
533         info.fMask = OS.SIF_POS;
534         info.nPos = value;
535         SetScrollInfo (handle, OS.SB_CTL, info, true);
536 }
537
538 /**
539  * Sets the thumb value. The thumb value should be used to represent
540  * the size of the visual portion of the current range. This value is
541  * usually the same as the page increment value.
542  * <p>
543  * This new value will be ignored if it is less than one, and will be
544  * clamped if it exceeds the receiver's current range.
545  * </p>
546  *
547  * @param value the new thumb value, which must be at least one and not
548  * larger than the size of the current range
549  *
550  * @exception SWTException <ul>
551  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
552  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
553  * </ul>
554  */
555 public void setThumb (int value) {
556         checkWidget ();
557         if (value < 1) return;
558         SCROLLINFO info = new SCROLLINFO ();
559         info.cbSize = SCROLLINFO.sizeof;
560         info.fMask = OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
561         OS.GetScrollInfo (handle, OS.SB_CTL, info);
562         info.nPage = value;
563         if (info.nPage != 0) info.nPage++;
564         SetScrollInfo (handle, OS.SB_CTL, info, true);
565 }
566
567 /**
568  * Sets the receiver's selection, minimum value, maximum
569  * value, thumb, increment and page increment all at once.
570  * <p>
571  * Note: This is similar to setting the values individually
572  * using the appropriate methods, but may be implemented in a
573  * more efficient fashion on some platforms.
574  * </p>
575  *
576  * @param selection the new selection value
577  * @param minimum the new minimum value
578  * @param maximum the new maximum value
579  * @param thumb the new thumb value
580  * @param increment the new increment value
581  * @param pageIncrement the new pageIncrement value
582  *
583  * @exception SWTException <ul>
584  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
585  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
586  * </ul>
587  */
588 public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
589         checkWidget ();
590         if (minimum < 0) return;
591         if (maximum < 0) return;
592         if (thumb < 1) return;
593         if (increment < 1) return;
594         if (pageIncrement < 1) return;
595         this.increment = increment;
596         this.pageIncrement = pageIncrement;
597         SCROLLINFO info = new SCROLLINFO ();
598         info.cbSize = SCROLLINFO.sizeof;
599         info.fMask = OS.SIF_POS | OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
600         info.nPos = selection;
601         info.nMin = minimum;
602         info.nMax = maximum;
603         info.nPage = thumb;
604         if (info.nPage != 0) info.nPage++;
605         SetScrollInfo (handle, OS.SB_CTL, info, true);
606 }
607
608 @Override
609 int widgetExtStyle () {
610         /*
611         * Bug in Windows.  If a scroll bar control is given a border,
612         * dragging the scroll bar thumb eats away parts of the border
613         * while the thumb is dragged.  The fix is to clear border for
614         * all scroll bars.
615         */
616         int bits = super.widgetExtStyle ();
617         if ((style & SWT.BORDER) != 0) bits &= ~OS.WS_EX_CLIENTEDGE;
618         return bits;
619 }
620
621 @Override
622 int widgetStyle () {
623         int bits = super.widgetStyle () | OS.WS_TABSTOP;
624         /*
625         * Bug in Windows.  If a scroll bar control is given a border,
626         * dragging the scroll bar thumb eats away parts of the border
627         * while the thumb is dragged.  The fix is to clear WS_BORDER.
628         */
629         if ((style & SWT.BORDER) != 0) bits &= ~OS.WS_BORDER;
630         if ((style & SWT.HORIZONTAL) != 0) return bits | OS.SBS_HORZ;
631         return bits | OS.SBS_VERT;
632 }
633
634 @Override
635 TCHAR windowClass () {
636         return ScrollBarClass;
637 }
638
639 @Override
640 long windowProc () {
641         return ScrollBarProc;
642 }
643
644 @Override
645 LRESULT WM_KEYDOWN (long wParam, long lParam) {
646         LRESULT result = super.WM_KEYDOWN (wParam, lParam);
647         if (result != null) return result;
648         if ((style & SWT.VERTICAL) != 0) return result;
649         /*
650         * Bug in Windows.  When a horizontal scroll bar is mirrored,
651         * the native control does not correctly swap the arrow keys.
652         * The fix is to swap them before calling the scroll bar window
653         * proc.
654         *
655         * NOTE: This fix is not ideal.  It breaks when the bug is fixed
656         * in the operating system.
657         */
658         if ((style & SWT.MIRRORED) != 0) {
659                 switch ((int)wParam) {
660                         case OS.VK_LEFT:
661                         case OS.VK_RIGHT: {
662                                 int key = wParam == OS.VK_LEFT ? OS.VK_RIGHT : OS.VK_LEFT;
663                                 long code = callWindowProc (handle, OS.WM_KEYDOWN, key, lParam);
664                                 return new LRESULT (code);
665                         }
666                 }
667         }
668         return result;
669 }
670
671 @Override
672 LRESULT WM_LBUTTONDBLCLK (long wParam, long lParam) {
673         /*
674         * Feature in Windows.  Windows uses the WS_TABSTOP
675         * style for the scroll bar to decide that focus
676         * should be set during WM_LBUTTONDBLCLK.  This is
677         * not the desired behavior.  The fix is to clear
678         * and restore WS_TABSTOP so that Windows will not
679         * assign focus.
680         */
681         int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
682         int newBits = oldBits & ~OS.WS_TABSTOP;
683         OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
684         LRESULT result = super.WM_LBUTTONDBLCLK (wParam, lParam);
685         if (isDisposed ()) return LRESULT.ZERO;
686         OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
687         if (result == LRESULT.ZERO) return result;
688
689         /*
690         * Feature in Windows.  Windows runs a modal message loop
691         * when the user drags a scroll bar that terminates when
692         * it sees an WM_LBUTTONUP.  Unfortunately the WM_LBUTTONUP
693         * is consumed.  The fix is to send a fake mouse up and
694         * release the automatic capture.
695         */
696         if (OS.GetCapture () == handle) OS.ReleaseCapture ();
697         if (!sendMouseEvent (SWT.MouseUp, 1, handle, OS.WM_LBUTTONUP, wParam, lParam)) {
698                 return LRESULT.ZERO;
699         }
700         return result;
701 }
702
703 @Override
704 LRESULT WM_LBUTTONDOWN (long wParam, long lParam) {
705         /*
706         * Feature in Windows.  Windows uses the WS_TABSTOP
707         * style for the scroll bar to decide that focus
708         * should be set during WM_LBUTTONDOWN.  This is
709         * not the desired behavior.  The fix is to clear
710         * and restore WS_TABSTOP so that Windows will not
711         * assign focus.
712         */
713         int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
714         int newBits = oldBits & ~OS.WS_TABSTOP;
715         OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
716         LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
717         if (isDisposed ()) return LRESULT.ZERO;
718         OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
719         if (result == LRESULT.ZERO) return result;
720
721         /*
722         * Feature in Windows.  Windows runs a modal message loop
723         * when the user drags a scroll bar that terminates when
724         * it sees an WM_LBUTTONUP.  Unfortunately the WM_LBUTTONUP
725         * is consumed.  The fix is to send a fake mouse up and
726         * release the automatic capture.
727         */
728         if (OS.GetCapture () == handle) OS.ReleaseCapture ();
729         if (!sendMouseEvent (SWT.MouseUp, 1, handle, OS.WM_LBUTTONUP, wParam, lParam)) {
730                 return LRESULT.ONE;
731         }
732         return result;
733 }
734
735 @Override
736 LRESULT WM_SETFOCUS (long wParam, long lParam) {
737         if (ignoreFocus) return null;
738         return super.WM_SETFOCUS (wParam, lParam);
739 }
740
741 @Override
742 LRESULT wmScrollChild (long wParam, long lParam) {
743
744         /* Do nothing when scrolling is ending */
745         int code = OS.LOWORD (wParam);
746         if (code == OS.SB_ENDSCROLL) return null;
747
748         /* Move the thumb */
749         Event event = new Event ();
750         SCROLLINFO info = new SCROLLINFO ();
751         info.cbSize = SCROLLINFO.sizeof;
752         info.fMask = OS.SIF_TRACKPOS | OS.SIF_POS | OS.SIF_RANGE;
753         OS.GetScrollInfo (handle, OS.SB_CTL, info);
754         info.fMask = OS.SIF_POS;
755         switch (code) {
756                 case OS.SB_THUMBPOSITION:
757                         event.detail = SWT.NONE;
758                         info.nPos = info.nTrackPos;
759                         break;
760                 case OS.SB_THUMBTRACK:
761                         event.detail = SWT.DRAG;
762                         info.nPos = info.nTrackPos;
763                         break;
764                 case OS.SB_TOP:
765                         event.detail = SWT.HOME;
766                         info.nPos = info.nMin;
767                         break;
768                 case OS.SB_BOTTOM:
769                         event.detail = SWT.END;
770                         info.nPos = info.nMax;
771                         break;
772                 case OS.SB_LINEDOWN:
773                         event.detail = SWT.ARROW_DOWN;
774                         info.nPos += increment;
775                         break;
776                 case OS.SB_LINEUP:
777                         event.detail = SWT.ARROW_UP;
778                         info.nPos = Math.max (info.nMin, info.nPos - increment);
779                         break;
780                 case OS.SB_PAGEDOWN:
781                         event.detail = SWT.PAGE_DOWN;
782                         info.nPos += pageIncrement;
783                         break;
784                 case OS.SB_PAGEUP:
785                         event.detail = SWT.PAGE_UP;
786                         info.nPos = Math.max (info.nMin, info.nPos - pageIncrement);
787                         break;
788         }
789         OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
790
791         /*
792         * Feature in Windows.  Windows runs a modal message
793         * loop when the user drags a scroll bar.  This means
794         * that selection event must be sent because WM_HSCROLL
795         * and WM_VSCROLL are sent from the modal message loop
796         * so that they are delivered during inside the loop.
797         */
798         sendSelectionEvent (SWT.Selection, event, true);
799         // the widget could be destroyed at this point
800         return null;
801 }
802
803 }