?? slider.java
字號:
if ((state & DISABLED) != 0) { if (OS.IsWinCE) { OS.EnableWindow (handle, false); } else { OS.EnableScrollBar (handle, OS.SB_CTL, OS.ESB_DISABLE_BOTH); } } /* * Bug in Windows. If the thumb is resized when it has focus, * the flashing cursor that is used to show that the scroll bar has * focus is not moved. The fix is to post a fake WM_SETFOCUS to * get the scroll bar to recompute the size of the flashing cursor. */ if (OS.GetFocus () == handle) { OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0); }}/** * Sets the minimum value. If this value is negative or greater * than or equal to the maximum, the value is ignored. If necessary, * first the thumb and then the selection are adjusted to fit within * the new range. * * @param value the new minimum * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setMinimum (int value) { checkWidget (); if (value < 0) return; SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; OS.GetScrollInfo (handle, OS.SB_CTL, info); if (info.nMax - value - info.nPage < 1) return; info.nMin = value; OS.SetScrollInfo (handle, OS.SB_CTL, info, true); /* * Feature in Windows. Using SIF_DISABLENOSCROLL, * SetScrollInfo () can change enabled and disabled * state of the scroll bar causing a scroll bar that * was disabled by the application to become enabled. * The fix is to disable the scroll bar (again) when * the application has disabled the scroll bar. */ if ((state & DISABLED) != 0) { if (OS.IsWinCE) { OS.EnableWindow (handle, false); } else { OS.EnableScrollBar (handle, OS.SB_CTL, OS.ESB_DISABLE_BOTH); } } /* * Bug in Windows. If the thumb is resized when it has focus, * the flashing cursor that is used to show that the scroll bar has * focus is not moved. The fix is to post a fake WM_SETFOCUS to * get the scroll bar to recompute the size of the flashing cursor. */ if (OS.GetFocus () == handle) { OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0); }}/** * Sets the amount that the receiver's value will be * modified by when the page increment/decrement areas * are selected to the argument, which must be at least * one. * * @param value the page increment (must be greater than zero) * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setPageIncrement (int value) { checkWidget (); if (value < 1) return; pageIncrement = value;}/** * Sets the single <em>selection</em> that is the receiver's * value to the argument which must be greater than or equal * to zero. * * @param value the new selection (must be zero or greater) * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setSelection (int value) { checkWidget (); SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; info.nPos = value; OS.SetScrollInfo (handle, OS.SB_CTL, info, true);}/** * Sets the size of the receiver's thumb relative to the * difference between its maximum and minimum values. This new * value will be ignored if it is less than one, and will be * clamped if it exceeds the receiver's current range. * * @param value the new thumb value, which must be at least one and not * larger than the size of the current range * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setThumb (int value) { checkWidget (); /* Position the thumb */ if (value < 1) return; SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; OS.GetScrollInfo (handle, OS.SB_CTL, info); info.nPage = value; if (info.nPage != 0) info.nPage++; OS.SetScrollInfo (handle, OS.SB_CTL, info, true); /* * Feature in Windows. Using SIF_DISABLENOSCROLL, * SetScrollInfo () can change enabled and disabled * state of the scroll bar causing a scroll bar that * was disabled by the application to become enabled. * The fix is to disable the scroll bar (again) when * the application has disabled the scroll bar. */ if ((state & DISABLED) != 0) { if (OS.IsWinCE) { OS.EnableWindow (handle, false); } else { OS.EnableScrollBar (handle, OS.SB_CTL, OS.ESB_DISABLE_BOTH); } } /* * Bug in Windows. If the thumb is resized when it has focus, * the flashing cursor that is used to show that the scroll bar has * focus is not moved. The fix is to post a fake WM_SETFOCUS to * get the scroll bar to recompute the size of the flashing cursor. */ if (OS.GetFocus () == handle) { OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0); }}/** * Sets the receiver's selection, minimum value, maximum * value, thumb, increment and page increment all at once. * <p> * Note: This is equivalent to setting the values individually * using the appropriate methods, but may be implemented in a * more efficient fashion on some platforms. * </p> * * @param selection the new selection value * @param minimum the new minimum value * @param maximum the new maximum value * @param thumb the new thumb value * @param increment the new increment value * @param pageIncrement the new pageIncrement value * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) { checkWidget (); if (minimum < 0) return; if (maximum < 0) return; if (thumb < 1) return; if (increment < 1) return; if (pageIncrement < 1) return; this.increment = increment; this.pageIncrement = pageIncrement; SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS | OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; info.nPos = selection; info.nMin = minimum; info.nMax = maximum; info.nPage = thumb; if (info.nPage != 0) info.nPage++; OS.SetScrollInfo (handle, OS.SB_CTL, info, true); /* * Feature in Windows. Using SIF_DISABLENOSCROLL, * SetScrollInfo () can change enabled and disabled * state of the scroll bar causing a scroll bar that * was disabled by the application to become enabled. * The fix is to disable the scroll bar (again) when * the application has disabled the scroll bar. */ if ((state & DISABLED) != 0) { if (OS.IsWinCE) { OS.EnableWindow (handle, false); } else { OS.EnableScrollBar (handle, OS.SB_CTL, OS.ESB_DISABLE_BOTH); } } /* * Bug in Windows. If the thumb is resized when it has focus, * the flashing cursor that is used to show that the scroll bar has * focus is not moved. The fix is to post a fake WM_SETFOCUS to * get the scroll bar to recompute the size of the flashing cursor. */ if (OS.GetFocus () == handle) { OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0); }}int widgetExtStyle () { /* * Bug in Windows. If a scroll bar control is given a border, * dragging the scroll bar thumb eats away parts of the border * while the thumb is dragged. The fix is to clear border for * all scroll bars. */ int bits = super.widgetExtStyle (); if ((style & SWT.BORDER) != 0) bits &= ~OS.WS_EX_CLIENTEDGE; return bits;}int widgetStyle () { int bits = super.widgetStyle () | OS.WS_TABSTOP; /* * Bug in Windows. If a scroll bar control is given a border, * dragging the scroll bar thumb eats away parts of the border * while the thumb is dragged. The fix is to clear WS_BORDER. */ if ((style & SWT.BORDER) != 0) bits &= ~OS.WS_BORDER; if ((style & SWT.HORIZONTAL) != 0) return bits | OS.SBS_HORZ; return bits | OS.SBS_VERT;}TCHAR windowClass () { return ScrollBarClass;}int windowProc () { return ScrollBarProc;}LRESULT WM_KEYDOWN (int wParam, int lParam) { LRESULT result = super.WM_KEYDOWN (wParam, lParam); if (result != null) return result; if ((style & SWT.VERTICAL) != 0) return result; /* * Bug in Windows. When a horizontal scroll bar is mirrored, * the native control does not correctly swap the arrow keys. * The fix is to swap them before calling the scroll bar window * proc. * * NOTE: This fix is not ideal. It breaks when the bug is fixed * in the operating system. */ if ((style & SWT.MIRRORED) != 0) { switch (wParam) { case OS.VK_LEFT: case OS.VK_RIGHT: { int key = wParam == OS.VK_LEFT ? OS.VK_RIGHT : OS.VK_LEFT; int code = callWindowProc (OS.WM_KEYDOWN, key, lParam); return new LRESULT (code); } } } return result;} LRESULT WM_LBUTTONDBLCLK (int wParam, int lParam) { /* * Feature in Windows. For some reason, capturing * the mouse after processing WM_LBUTTONDBLCLK for the * widget interferes with the normal mouse processing * for the widget. The fix is to avoid the automatic * mouse capture. */ /* * Feature in Windows. Windows uses the WS_TABSTOP * style for the scroll bar to decide that focus * should be set during WM_LBUTTONDBLCLK. This is * not the desired behavior. The fix is to clear * and restore WS_TABSTOP so that Windows will not * assign focus. */ int hwndCapture = OS.GetCapture (); int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE); int newBits = oldBits & ~OS.WS_TABSTOP; OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); LRESULT result = super.WM_LBUTTONDBLCLK (wParam, lParam); OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits); if (OS.GetCapture () != hwndCapture) OS.SetCapture (hwndCapture); /* * Feature in Windows. Windows runs a modal message loop * when the user drags a scroll bar that terminates when * it sees an WM_LBUTTONUP. Unfortunately the WM_LBUTTONUP * is consumed. The fix is to send a fake mouse up. */ sendMouseEvent (SWT.MouseUp, 1, OS.WM_LBUTTONUP, wParam, lParam); return result;}LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { /* * Feature in Windows. For some reason, capturing * the mouse after processing WM_LBUTTONDOWN for the * widget interferes with the normal mouse processing * for the widget. The fix is to avoid the automatic * mouse capture. */ /* * Feature in Windows. Windows uses the WS_TABSTOP * style for the scroll bar to decide that focus * should be set during WM_LBUTTONDOWN. This is * not the desired behavior. The fix is to clear * and restore WS_TABSTOP so that Windows will not * assign focus. */ int hwndCapture = OS.GetCapture (); int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE); int newBits = oldBits & ~OS.WS_TABSTOP; OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam); OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits); if (OS.GetCapture () != hwndCapture) OS.SetCapture (hwndCapture); /* * Feature in Windows. Windows runs a modal message loop * when the user drags a scroll bar that terminates when * it sees an WM_LBUTTONUP. Unfortunately the WM_LBUTTONUP * is consumed. The fix is to send a fake mouse up. */ sendMouseEvent (SWT.MouseUp, 1, OS.WM_LBUTTONUP, wParam, lParam); return result;}LRESULT wmScrollChild (int wParam, int lParam) { /* Do nothing when scrolling is ending */ int code = wParam & 0xFFFF; if (code == OS.SB_ENDSCROLL) return null; /* Move the thumb */ Event event = new Event (); SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_TRACKPOS | OS.SIF_POS | OS.SIF_RANGE; OS.GetScrollInfo (handle, OS.SB_CTL, info); info.fMask = OS.SIF_POS; switch (code) { case OS.SB_THUMBPOSITION: /* * Do not set the detail field to DRAG to * indicate that the dragging has ended. */ info.nPos = info.nTrackPos; break; case OS.SB_THUMBTRACK: event.detail = SWT.DRAG; info.nPos = info.nTrackPos; break; case OS.SB_TOP: event.detail = SWT.HOME; info.nPos = info.nMin; break; case OS.SB_BOTTOM: event.detail = SWT.END; info.nPos = info.nMax; break; case OS.SB_LINEDOWN: event.detail = SWT.ARROW_DOWN; info.nPos += increment; break; case OS.SB_LINEUP: event.detail = SWT.ARROW_UP; info.nPos = Math.max (info.nMin, info.nPos - increment); break; case OS.SB_PAGEDOWN: event.detail = SWT.PAGE_DOWN; info.nPos += pageIncrement; break; case OS.SB_PAGEUP: event.detail = SWT.PAGE_UP; info.nPos = Math.max (info.nMin, info.nPos - pageIncrement); break; } OS.SetScrollInfo (handle, OS.SB_CTL, info, true); /* * Feature in Windows. Windows runs a modal message * loop when the user drags a scroll bar. This means * that selection event must be sent because WM_HSCROLL * and WM_VSCROLL are sent from the modal message loop * so that they are delivered during inside the loop. */ sendEvent (SWT.Selection, event); // the widget could be destroyed at this point return null;}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -