⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scrollbar.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	* 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 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 selection 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 selection) {	checkWidget();	SCROLLINFO info = new SCROLLINFO ();	info.cbSize = SCROLLINFO.sizeof;	int hwnd = hwndScrollBar (), type = scrollBarType ();	info.fMask = OS.SIF_POS;	info.nPos = selection;	OS.SetScrollInfo (hwnd, type, 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;	int hwnd = hwndScrollBar (), type = scrollBarType ();	info.fMask = OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;	OS.GetScrollInfo (hwnd, type, info);	info.nPage = value;	if (info.nPage != 0) info.nPage++;	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,	* 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 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++;	int hwnd = hwndScrollBar (), type = scrollBarType ();	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,	* 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);		}	}}/** * Marks the receiver as visible if the argument is <code>true</code>, * and marks it invisible otherwise.  * <p> * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, marking * it visible may not actually cause it to be displayed. * </p> * * @param visible the new 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 void setVisible (boolean visible) {	checkWidget();	boolean isVisible = (state & HIDDEN) == 0;	if (isVisible == visible) return;		/*	* On Windows CE, use SIF_DISABLENOSCROLL to show and	* hide the scroll bar when the page size is equal to	* the range.	*/	if (OS.IsWinCE) {		SCROLLINFO info = new SCROLLINFO ();		info.cbSize = SCROLLINFO.sizeof;		int hwnd = hwndScrollBar (), type = scrollBarType ();		info.fMask = OS.SIF_RANGE | OS.SIF_PAGE;		if (visible) info.fMask |= OS.SIF_DISABLENOSCROLL;		OS.GetScrollInfo (hwnd, type, info);		if (info.nPage == info.nMax - info.nMin + 1) {			/*			* Bug in Windows.  When the only changed flag to			* SetScrollInfo () is OS.SIF_DISABLENOSCROLL, 			* Windows does not update the scroll bar state.			* The fix is to increase and then decrease the			* maximum, causing Windows to honour the flag.			*/  			int max = info.nMax;			info.nMax++;			OS.SetScrollInfo (hwnd, type, info, false);			info.nMax = max;			OS.SetScrollInfo (hwnd, type, info, true);		} else {        	/*        	* This line is intentionally commented.  Currently        	* always show scrollbar as being enabled and visible.        	*///			if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED);		}		return;	}		/*	* Set the state bits before calling ShowScrollBar ()	* because hiding and showing the scroll bar can cause	* WM_SIZE messages when the client area is resized.	* Setting the state before the call means that code	* that runs during WM_SIZE that queries the visibility	* of the scroll bar will get the correct value.	*/	state = visible ? state & ~HIDDEN : state | HIDDEN;	int hwnd = hwndScrollBar (), type = scrollBarType ();	if (OS.ShowScrollBar (hwnd, type, visible)) {		/*		* Bug in Windows.  For some reason, when the widget		* is a standard scroll bar, and SetScrollInfo () is		* called with SIF_RANGE or SIF_PAGE while the widget		* is not visible, the widget is incorrectly disabled		* even though the values for SIF_RANGE and SIF_PAGE,		* when set for a visible scroll bar would not disable		* the scroll bar.  The fix is to enable the scroll bar		* when not disabled by the application and the current		* scroll bar ranges would cause the scroll bar to be		* enabled had they been set when the scroll bar was		* visible.		*/		if ((state & DISABLED) == 0) {			SCROLLINFO info = new SCROLLINFO ();			info.cbSize = SCROLLINFO.sizeof;			info.fMask = OS.SIF_RANGE | OS.SIF_PAGE;			OS.GetScrollInfo (hwnd, type, info);			if (info.nMax - info.nMin - info.nPage >= 0) {				OS.EnableScrollBar (hwnd, type, OS.ESB_ENABLE_BOTH);			}		}		sendEvent (visible ? SWT.Show : SWT.Hide);		// widget could be disposed at this point	}}LRESULT wmScrollChild (int wParam, int lParam) {	/* Do nothing when scrolling is ending */	int code = wParam & 0xFFFF;	if (code == OS.SB_ENDSCROLL) return null;	/*	* Send the event because WM_HSCROLL and	* WM_VSCROLL are sent from a modal message	* loop in Windows that is active when the	* user is scrolling.	*/	Event event = new Event ();	switch (code) {		/*		* This line is intentionally commented.  Do not set the detail		* field to DRAG to indicate that the dragging has ended when the		* scroll bar is finally positioned in SB_THUMBPOSITION.		*///		case OS.SB_THUMBPOSITION:	break;		case OS.SB_THUMBTRACK:		event.detail = SWT.DRAG;  break;		case OS.SB_TOP: 			event.detail = SWT.HOME;  break;		case OS.SB_BOTTOM:			event.detail = SWT.END;  break;		case OS.SB_LINEDOWN:		event.detail = SWT.ARROW_DOWN;  break;		case OS.SB_LINEUP: 		event.detail = SWT.ARROW_UP;  break;		case OS.SB_PAGEDOWN:		event.detail = SWT.PAGE_DOWN;  break;		case OS.SB_PAGEUP:			event.detail = SWT.PAGE_UP;  break;	}	sendEvent (SWT.Selection, event);	// the widget could be destroyed at this point	return null;}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -