1 /*******************************************************************************
2 * Copyright (c) 2000, 2012 IBM Corporation and others.
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/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.widgets;
17 import org.eclipse.swt.internal.win32.*;
18 import org.eclipse.swt.*;
19 import org.eclipse.swt.graphics.*;
20 import org.eclipse.swt.events.*;
23 * Instances of this class are selectable user interface
24 * objects that represent a range of positive, numeric values.
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).
32 * Typically, sliders will be made up of five areas:
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>
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).
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.
59 * <dt><b>Styles:</b></dt>
60 * <dd>HORIZONTAL, VERTICAL</dd>
61 * <dt><b>Events:</b></dt>
65 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
67 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
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.
76 public class Slider extends Control {
77 int increment, pageIncrement;
79 static final long ScrollBarProc;
80 static final TCHAR ScrollBarClass = new TCHAR (0, "SCROLLBAR", true);
82 WNDCLASS lpWndClass = new WNDCLASS ();
83 OS.GetClassInfo (0, ScrollBarClass, lpWndClass);
84 ScrollBarProc = lpWndClass.lpfnWndProc;
88 * Constructs a new instance of this class given its parent
89 * and a style value describing its behavior and appearance.
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.
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
103 * @exception IllegalArgumentException <ul>
104 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
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>
111 * @see SWT#HORIZONTAL
113 * @see Widget#checkSubclass
114 * @see Widget#getStyle
116 public Slider (Composite parent, int style) {
117 super (parent, checkStyle (style));
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>
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.
138 * @param listener the listener which should be notified when the user changes the receiver's value
140 * @exception IllegalArgumentException <ul>
141 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
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>
148 * @see SelectionListener
149 * @see #removeSelectionListener
150 * @see SelectionEvent
152 public void addSelectionListener (SelectionListener listener) {
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);
161 long callWindowProc (long hwnd, int msg, long wParam, long lParam) {
162 if (handle == 0) return 0;
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.
172 case OS.WM_LBUTTONDOWN:
173 case OS.WM_LBUTTONDBLCLK:
174 display.runDeferredEvents ();
176 return OS.CallWindowProc (ScrollBarProc, hwnd, msg, wParam, lParam);
179 static int checkStyle (int style) {
180 return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
183 @Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
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);
191 width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
192 height += OS.GetSystemMetrics (OS.SM_CYVSCROLL) * 10;
194 if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
195 if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
196 return new Point (width, height);
200 void createWidget () {
201 super.createWidget ();
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.
210 SCROLLINFO info = new SCROLLINFO ();
211 info.cbSize = SCROLLINFO.sizeof;
212 info.fMask = OS.SIF_ALL;
215 OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
219 int defaultBackground () {
220 return OS.GetSysColor (OS.COLOR_SCROLLBAR);
224 int defaultForeground () {
225 return OS.GetSysColor (OS.COLOR_BTNFACE);
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);
241 public boolean getEnabled () {
243 return (state & DISABLED) == 0;
247 * Returns the amount that the receiver's value will be
248 * modified by when the up/down (or right/left) arrows
251 * @return the increment
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>
258 public int getIncrement () {
264 * Returns the maximum value which the receiver will allow.
266 * @return the maximum
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>
273 public int getMaximum () {
275 SCROLLINFO info = new SCROLLINFO ();
276 info.cbSize = SCROLLINFO.sizeof;
277 info.fMask = OS.SIF_RANGE;
278 OS.GetScrollInfo (handle, OS.SB_CTL, info);
283 * Returns the minimum value which the receiver will allow.
285 * @return the minimum
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>
292 public int getMinimum () {
294 SCROLLINFO info = new SCROLLINFO ();
295 info.cbSize = SCROLLINFO.sizeof;
296 info.fMask = OS.SIF_RANGE;
297 OS.GetScrollInfo (handle, OS.SB_CTL, info);
302 * Returns the amount that the receiver's value will be
303 * modified by when the page increment/decrement areas
306 * @return the page increment
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>
313 public int getPageIncrement () {
315 return pageIncrement;
319 * Returns the 'selection', which is the receiver's value.
321 * @return the selection
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>
328 public int getSelection () {
330 SCROLLINFO info = new SCROLLINFO ();
331 info.cbSize = SCROLLINFO.sizeof;
332 info.fMask = OS.SIF_POS;
333 OS.GetScrollInfo (handle, OS.SB_CTL, info);
338 * Returns the receiver's thumb value.
340 * @return the thumb value
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>
347 public int getThumb () {
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;
358 * Removes the listener from the collection of listeners who will
359 * be notified when the user changes the receiver's value.
361 * @param listener the listener which should no longer be notified
363 * @exception IllegalArgumentException <ul>
364 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
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>
371 * @see SelectionListener
372 * @see #addSelectionListener
374 public void removeSelectionListener (SelectionListener listener) {
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);
383 void setBoundsInPixels (int x, int y, int width, int height, int flags) {
384 super.setBoundsInPixels (x, y, width, height, flags);
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.
391 if (OS.GetFocus () == handle) {
393 OS.SendMessage (handle, OS.WM_SETFOCUS, 0, 0);
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
404 * @param value the new increment (must be greater than zero)
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>
411 public void setIncrement (int value) {
413 if (value < 1) return;
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
423 * @param value the new maximum, which must be greater than the current minimum
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>
430 public void setMaximum (int value) {
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;
439 SetScrollInfo (handle, OS.SB_CTL, info, true);
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
448 * @param value the new minimum
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>
455 public void setMinimum (int value) {
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;
464 SetScrollInfo (handle, OS.SB_CTL, info, true);
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
473 * @param value the page increment (must be greater than zero)
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>
480 public void setPageIncrement (int value) {
482 if (value < 1) return;
483 pageIncrement = value;
486 boolean SetScrollInfo (long hwnd, int flags, SCROLLINFO info, boolean fRedraw) {
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.
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);
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
509 if (OS.GetFocus () == handle) {
511 OS.SendMessage (handle, OS.WM_SETFOCUS, 0, 0);
518 * Sets the 'selection', which is the receiver's
519 * value, to the argument which must be greater than or equal
522 * @param value the new selection (must be zero or greater)
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>
529 public void setSelection (int value) {
531 SCROLLINFO info = new SCROLLINFO ();
532 info.cbSize = SCROLLINFO.sizeof;
533 info.fMask = OS.SIF_POS;
535 SetScrollInfo (handle, OS.SB_CTL, info, true);
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.
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.
547 * @param value the new thumb value, which must be at least one and not
548 * larger than the size of the current range
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>
555 public void setThumb (int value) {
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);
563 if (info.nPage != 0) info.nPage++;
564 SetScrollInfo (handle, OS.SB_CTL, info, true);
568 * Sets the receiver's selection, minimum value, maximum
569 * value, thumb, increment and page increment all at once.
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.
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
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>
588 public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
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;
604 if (info.nPage != 0) info.nPage++;
605 SetScrollInfo (handle, OS.SB_CTL, info, true);
609 int widgetExtStyle () {
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
616 int bits = super.widgetExtStyle ();
617 if ((style & SWT.BORDER) != 0) bits &= ~OS.WS_EX_CLIENTEDGE;
623 int bits = super.widgetStyle () | OS.WS_TABSTOP;
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.
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;
635 TCHAR windowClass () {
636 return ScrollBarClass;
641 return ScrollBarProc;
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;
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
655 * NOTE: This fix is not ideal. It breaks when the bug is fixed
656 * in the operating system.
658 if ((style & SWT.MIRRORED) != 0) {
659 switch ((int)wParam) {
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);
672 LRESULT WM_LBUTTONDBLCLK (long wParam, long lParam) {
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
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;
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.
696 if (OS.GetCapture () == handle) OS.ReleaseCapture ();
697 if (!sendMouseEvent (SWT.MouseUp, 1, handle, OS.WM_LBUTTONUP, wParam, lParam)) {
704 LRESULT WM_LBUTTONDOWN (long wParam, long lParam) {
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
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;
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.
728 if (OS.GetCapture () == handle) OS.ReleaseCapture ();
729 if (!sendMouseEvent (SWT.MouseUp, 1, handle, OS.WM_LBUTTONUP, wParam, lParam)) {
736 LRESULT WM_SETFOCUS (long wParam, long lParam) {
737 if (ignoreFocus) return null;
738 return super.WM_SETFOCUS (wParam, lParam);
742 LRESULT wmScrollChild (long wParam, long lParam) {
744 /* Do nothing when scrolling is ending */
745 int code = OS.LOWORD (wParam);
746 if (code == OS.SB_ENDSCROLL) return null;
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;
756 case OS.SB_THUMBPOSITION:
757 event.detail = SWT.NONE;
758 info.nPos = info.nTrackPos;
760 case OS.SB_THUMBTRACK:
761 event.detail = SWT.DRAG;
762 info.nPos = info.nTrackPos;
765 event.detail = SWT.HOME;
766 info.nPos = info.nMin;
769 event.detail = SWT.END;
770 info.nPos = info.nMax;
773 event.detail = SWT.ARROW_DOWN;
774 info.nPos += increment;
777 event.detail = SWT.ARROW_UP;
778 info.nPos = Math.max (info.nMin, info.nPos - increment);
781 event.detail = SWT.PAGE_DOWN;
782 info.nPos += pageIncrement;
785 event.detail = SWT.PAGE_UP;
786 info.nPos = Math.max (info.nMin, info.nPos - pageIncrement);
789 OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
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.
798 sendSelectionEvent (SWT.Selection, event, true);
799 // the widget could be destroyed at this point