?? scrollbar.java
字號:
*/public int getSelection () { checkWidget(); SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; int hwnd = hwndScrollBar (); int type = scrollBarType (); OS.GetScrollInfo (hwnd, type, info); return info.nPos;}/** * Returns a point describing the receiver's size. The * x coordinate of the result is the width of the receiver. * The y coordinate of the result is the height of the * receiver. * * @return the receiver's size * * @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 Point getSize () { checkWidget(); parent.forceResize (); RECT rect = new RECT (); OS.GetClientRect (parent.handle, rect); int width, height; if ((style & SWT.HORIZONTAL) != 0) { width = rect.right - rect.left; height = OS.GetSystemMetrics (OS.SM_CYHSCROLL); } else { width = OS.GetSystemMetrics (OS.SM_CXVSCROLL); height = rect.bottom - rect.top; } return new Point (width, height);}/** * Answers the size of the receiver's thumb relative to the * difference between its maximum and minimum values. * * @return the thumb 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> * * @see ScrollBar */public int getThumb () { checkWidget(); SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_PAGE; int hwnd = hwndScrollBar (); int type = scrollBarType (); OS.GetScrollInfo (hwnd, type, info); if (info.nPage != 0) --info.nPage; return info.nPage;}/** * Returns <code>true</code> if the receiver is visible, and * <code>false</code> otherwise. * <p> * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, this method * may still indicate that it is considered visible even though * it may not actually be showing. * </p> * * @return the receiver's visibility state * * @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 boolean getVisible () { checkWidget(); return (state & HIDDEN) == 0;}int hwndScrollBar () { return parent.handle;}/** * Returns <code>true</code> if the receiver is enabled and all * of the receiver's ancestors are enabled, and <code>false</code> * otherwise. A disabled control is typically not selectable from the * user interface and draws with an inactive or "grayed" look. * * @return the receiver's enabled state * * @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> * * @see #getEnabled */public boolean isEnabled () { checkWidget(); return getEnabled () && parent.isEnabled ();}/** * Returns <code>true</code> if the receiver is visible and all * of the receiver's ancestors are visible and <code>false</code> * otherwise. * * @return the receiver's visibility state * * @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> * * @see #getVisible */public boolean isVisible () { checkWidget(); return getVisible () && parent.isVisible ();}void releaseChild () { super.releaseChild (); if (parent.horizontalBar == this) parent.horizontalBar = null; if (parent.verticalBar == this) parent.verticalBar = null;}void releaseWidget () { super.releaseWidget (); parent = null;}/** * Removes the listener from the collection of listeners who will * be notified when the receiver's value changes. * * @param listener the listener which should no longer be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @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> * * @see SelectionListener * @see #addSelectionListener */public void removeSelectionListener (SelectionListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Selection, listener); eventTable.unhook (SWT.DefaultSelection,listener); }int scrollBarType () { if ((style & SWT.VERTICAL) != 0) return OS.SB_VERT; /* * This line is intentionally commented. There should * only ever be HORIZONTAL and VERTICAL scroll bars. * The commented code reminds us that this is the case * and that the default style is HORIZONTAL. */ // if ((style & SWT.HORIZONTAL) != 0) return OS.SB_HORZ; return OS.SB_HORZ;}/** * Enables the receiver if the argument is <code>true</code>, * and disables it otherwise. A disabled control is typically * not selectable from the user interface and draws with an * inactive or "grayed" look. * * @param enabled the new enabled state * * @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 setEnabled (boolean enabled) { checkWidget(); /* * This line is intentionally commented. Currently * always show scrollbar as being enabled and visible. */// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED); if (!OS.IsWinCE) { int hwnd = hwndScrollBar (), type = scrollBarType (); int flags = enabled ? OS.ESB_ENABLE_BOTH : OS.ESB_DISABLE_BOTH; OS.EnableScrollBar (hwnd, type, flags); state &= ~DISABLED; if (!enabled) state |= DISABLED; }}/** * Sets the amount that the receiver's value will be * modified by when the up/down (or right/left) arrows * are pressed to the argument, which must be at least * one. * * @param value the new 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 setIncrement (int value) { checkWidget(); if (value < 1) return; increment = value;}/** * Sets the maximum. If this value is negative or less than or * equal to the minimum, 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 maximum * * @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 setMaximum (int value) { checkWidget(); if (value < 0) return; SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; int hwnd = hwndScrollBar (), type = scrollBarType (); info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; OS.GetScrollInfo (hwnd, type, info); if (value - info.nMin - info.nPage < 1) return; info.nMax = value; OS.SetScrollInfo (hwnd, type, info, (state & DISABLED) == 0); /* * Bug in Windows. For some reason, when the widget * is a standard scroll bar, and SetScrollInfo () is * called with SIF_RANGE or SIF_PAGE, the widget is * incorrectly made visible so that the next time the * widget is resized (or another scroll bar operation * is performed), the scroll bar draws. The fix is * to hide the scroll bar (again) when already hidden. */ if ((state & HIDDEN) != 0) { /* * This line is intentionally commented. Currently * always show scrollbar as being enabled and visible. */// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED); if (!OS.IsWinCE) { OS.ShowScrollBar (hwnd, type, false); } } /* * 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) { /* * This line is intentionally commented. Currently * always show scrollbar as being enabled and visible. */// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED); if (!OS.IsWinCE) { OS.EnableScrollBar (hwnd, type, OS.ESB_DISABLE_BOTH); } }}/** * 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; int hwnd = hwndScrollBar (), type = scrollBarType (); info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL; OS.GetScrollInfo (hwnd, type, info); if (info.nMax - value - info.nPage < 1) return; info.nMin = value; OS.SetScrollInfo (hwnd, type, info, true); /* * Bug in Windows. For some reason, when the widget * is a standard scroll bar, and SetScrollInfo () is * called with SIF_RANGE or SIF_PAGE, the widget is * incorrectly made visible so that the next time the * widget is resized (or another scroll bar operation * is performed), the scroll bar draws. The fix is * to hide the scroll bar (again) when already hidden. */ if ((state & HIDDEN) != 0) { /* * This line is intentionally commented. Currently * always show scrollbar as being enabled and visible. */// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED); if (!OS.IsWinCE) { OS.ShowScrollBar (hwnd, type, false); } } /* * Feature in Windows. Using SIF_DISABLENOSCROLL,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -