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

📄 tabfolder.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 * @return the index of the item * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the string 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> */public int indexOf (TabItem item) {	checkWidget ();	if (item == null) error (SWT.ERROR_NULL_ARGUMENT);	int count = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);	for (int i=0; i<count; i++) {		if (items [i] == item) return i;	}	return -1;}Point minimumSize (int wHint, int hHint, boolean flushCache) {	Control [] children = _getChildren ();	int width = 0, height = 0;	for (int i=0; i<children.length; i++) {		Control child = children [i];		int index = 0;			int count = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);		while (index < count) {			if (items [index].control == child) break;			index++;		}		if (index == count) {			Rectangle rect = child.getBounds ();			width = Math.max (width, rect.x + rect.width);			height = Math.max (height, rect.y + rect.height);		} else {			Point size = child.computeSize (wHint, hHint, flushCache);			width = Math.max (width, size.x);			height = Math.max (height, size.y);		}	}	return new Point (width, height);}boolean mnemonicHit (char key) {	for (int i=0; i<items.length; i++) {		TabItem item = items [i];		if (item != null) {			char ch = findMnemonic (item.getText ());			if (Character.toUpperCase (key) == Character.toUpperCase (ch)) {						if (setFocus ()) {					setSelection (i, true);					return true;				}			}		}	}	return false;}boolean mnemonicMatch (char key) {	for (int i=0; i<items.length; i++) {		TabItem item = items [i];		if (item != null) {			char ch = findMnemonic (item.getText ());			if (Character.toUpperCase (key) == Character.toUpperCase (ch)) {						return true;			}		}	}	return false;}void releaseWidget () {	int count = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);	for (int i=0; i<count; i++) {		TabItem item = items [i];		if (!item.isDisposed ()) item.releaseResources ();	}	items = null;	if (imageList != null) {		OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0);		display.releaseImageList (imageList);	}	imageList = null;	super.releaseWidget ();}void removeControl (Control control) {	super.removeControl (control);	int count = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);	for (int i=0; i<count; i++) {		TabItem item = items [i];		if (item.control == control) item.setControl (null);	}}/** * Removes the listener from the collection of listeners who will * be notified when the receiver's selection 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);	}/** * Sets the receiver's selection to be the given array of items. * The current selected is first cleared, then the new items are * selected. * * @param items the array of items * * @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 (TabItem [] items) {	checkWidget ();	if (items == null) error (SWT.ERROR_NULL_ARGUMENT);	if (items.length == 0) {		setSelection (-1, false);	} else {		for (int i=items.length-1; i>=0; --i) {			int index = indexOf (items [i]);			if (index != -1) setSelection (index, false);		}	}}/** * Selects the item at the given zero-relative index in the receiver.  * If the item at the index was already selected, it remains selected. * The current selection is first cleared, then the new items are * selected. Indices that are out of range are ignored. * * @param index the index of the item to select * * @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 index) {	checkWidget ();	int count = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);	if (!(0 <= index && index < count)) return;	setSelection (index, false);}void setSelection (int index, boolean notify) {	int oldIndex = OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);	if (oldIndex != -1) {		TabItem item = items [oldIndex];		Control control = item.control;		if (control != null && !control.isDisposed ()) {			control.setVisible (false);		}	}	OS.SendMessage (handle, OS.TCM_SETCURSEL, index, 0);	int newIndex = OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);	if (newIndex != -1) {		TabItem item = items [newIndex];		Control control = item.control;		if (control != null && !control.isDisposed ()) {			control.setBounds (getClientArea ());			control.setVisible (true);		}		if (notify) {			Event event = new Event ();			event.item = item;			sendEvent (SWT.Selection, event);		}	}}String toolTipText (NMTTDISPINFO hdr) {	if ((hdr.uFlags & OS.TTF_IDISHWND) != 0) {		return null;	}	int index = hdr.idFrom;	int hwndToolTip = OS.SendMessage (handle, OS.TCM_GETTOOLTIPS, 0, 0);	if (hwndToolTip == hdr.hwndFrom) {		if (toolTipText != null) return "";		if (0 <= index && index < items.length) {			TabItem item = items [index];			if (item != null) return item.toolTipText;		}	}	return super.toolTipText (hdr);}boolean traversePage (boolean next) {	int count = getItemCount ();	if (count == 0) return false;	int index = getSelectionIndex ();	if (index == -1) {		index = 0;	} else {		int offset = (next) ? 1 : -1;		index = (index + offset + count) % count;	}	setSelection (index, true);	return index == getSelectionIndex ();}int widgetStyle () {	/*	* Bug in Windows.  Under certain circumstances,	* when TCM_SETITEM is used to change the text	* in a tab item, the tab folder draws on top	* of the client area.  The fix is ensure that	* this cannot happen by setting WS_CLIPCHILDREN.	*/	int bits = super.widgetStyle () | OS.WS_CLIPCHILDREN;	if ((style & SWT.NO_FOCUS) != 0) bits |= OS.TCS_FOCUSNEVER;	if ((style & SWT.BOTTOM) != 0) bits |= OS.TCS_BOTTOM;	return bits | OS.TCS_TABS | OS.TCS_TOOLTIPS;}TCHAR windowClass () {	return TabFolderClass;}int windowProc () {	return TabFolderProc;}LRESULT WM_GETDLGCODE (int wParam, int lParam) {	LRESULT result = super.WM_GETDLGCODE (wParam, lParam);	/*	* Return DLGC_BUTTON so that mnemonics will be	* processed without needing to press the ALT key	* when the widget has focus.	*/	if (result != null) return result;	return new LRESULT (OS.DLGC_BUTTON);}LRESULT WM_NCHITTEST (int wParam, int lParam) {	LRESULT result = super.WM_NCHITTEST (wParam, lParam);	if (result != null) return result;	/*	* Feature in Windows.  The tab control implements	* WM_NCHITTEST to return HTCLIENT when the cursor	* is inside the tab buttons.  This causes mouse	* events like WM_MOUSEMOVE to be delivered to the	* parent.  Also, tool tips for the tab control are	* never invoked because tool tips rely on mouse	* events to be delivered to the window that wants	* to display the tool tip.  The fix is to call the	* default window proc that returns HTCLIENT when	* the mouse is in the client area.		*/	int hittest = OS.DefWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);	return new LRESULT (hittest);}LRESULT WM_NOTIFY (int wParam, int lParam) {	/*	* Feature in Windows.  When the tab folder window	* proc processes WM_NOTIFY, it forwards this	* message to its parent.  This is done so that	* children of this control that send this message 	* type to their parent will notify not only	* this control but also the parent of this control,	* which is typically the application window and	* the window that is looking for the message.	* If the control did not forward the message, 	* applications would have to subclass the control 	* window to see the message. Because the control	* window is subclassed by SWT, the message	* is delivered twice, once by SWT and once when	* the message is forwarded by the window proc.	* The fix is to avoid calling the window proc 	* for this control.	*/	LRESULT result = super.WM_NOTIFY (wParam, lParam);	if (result != null) return result;	return LRESULT.ZERO;}LRESULT WM_PARENTNOTIFY (int wParam, int lParam) {	LRESULT result = super.WM_PARENTNOTIFY (wParam, lParam);	if (result != null) return result;	/*	* Feature in Windows.  Windows does not explicitly set the orientation of	* the buddy control.  Instead, the orientation is inherited when WS_EX_LAYOUTRTL	* is specified for the tab folder.  This means that when both WS_EX_LAYOUTRTL	* and WS_EX_NOINHERITLAYOUT are specified for the tab folder, the buddy control	* will not be oriented correctly.  The fix is to explicitly set the orientation	* for the buddy control.	* 	* NOTE: WS_EX_LAYOUTRTL is not supported on Windows NT.	*/	if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR)	< (4 << 16 | 10)) return result;	if ((style & SWT.RIGHT_TO_LEFT) != 0) {		int code = wParam & 0xFFFF;		switch (code) {			case OS.WM_CREATE: {				int id = (wParam >> 16), hwnd = lParam;				if (id == ID_UPDOWN) {					int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);					OS.SetWindowLong (hwnd, OS.GWL_EXSTYLE,	bits | OS.WS_EX_LAYOUTRTL);				}				break;			}		}	}	return result;}LRESULT WM_SIZE (int wParam, int lParam) {	LRESULT result = super.WM_SIZE (wParam, lParam);	/*	* It is possible (but unlikely), that application	* code could have disposed the widget in the resize	* event.  If this happens, end the processing of the	* Windows message by returning the result of the	* WM_SIZE message.	*/	if (isDisposed ()) return result;	int index = OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);	if (index != -1) {		TabItem item = items [index];		Control control = item.control;		if (control != null && !control.isDisposed ()) {			control.setBounds (getClientArea ());		}	}	return result;}LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) {	LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);	if (result != null) return result;	if (!OS.IsWindowVisible (handle)) return result;	WINDOWPOS lpwp = new WINDOWPOS ();	OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);	if ((lpwp.flags & (OS.SWP_NOSIZE | OS.SWP_NOREDRAW)) != 0) {		return result;	}	int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);	if ((bits & OS.TCS_MULTILINE) != 0) {		OS.InvalidateRect (handle, null, true);		return result;	}	RECT rect = new RECT ();	OS.SetRect (rect, 0, 0, lpwp.cx, lpwp.cy);	OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, rect);	int newWidth = rect.right - rect.left;	int newHeight = rect.bottom - rect.top;	OS.GetClientRect (handle, rect);	int oldWidth = rect.right - rect.left;	int oldHeight = rect.bottom - rect.top;	if (newWidth == oldWidth && newHeight == oldHeight) {		return result;	}	RECT inset = new RECT ();	OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, inset);	int marginX = -inset.right, marginY = -inset.bottom;	if (newWidth != oldWidth) {		int left = oldWidth;		if (newWidth < oldWidth) left = newWidth;		OS.SetRect (rect, left - marginX, 0, newWidth, newHeight);		OS.InvalidateRect (handle, rect, true);	}	if (newHeight != oldHeight) {		int bottom = oldHeight;		if (newHeight < oldHeight) bottom = newHeight;		if (newWidth < oldWidth) oldWidth -= marginX;		OS.SetRect (rect, 0, bottom - marginY, oldWidth, newHeight);		OS.InvalidateRect (handle, rect, true);	}	return result;}LRESULT wmNotifyChild (int wParam, int lParam) {	NMHDR hdr = new NMHDR ();	OS.MoveMemory (hdr, lParam, NMHDR.sizeof);	int code = hdr.code;	switch (code) {		case OS.TCN_SELCHANGE: 		case OS.TCN_SELCHANGING:			TabItem item = null;			int index = OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);			if (index != -1) item = items [index];			if (item != null) {				Control control = item.control;				if (control != null && !control.isDisposed ()) {					if (code == OS.TCN_SELCHANGE) {						control.setBounds (getClientArea ());					}					control.setVisible (code == OS.TCN_SELCHANGE);				}			}			if (code == OS.TCN_SELCHANGE) {				Event event = new Event ();				event.item = item;				postEvent (SWT.Selection, event);			}	}	return super.wmNotifyChild (wParam, lParam);}}

⌨️ 快捷键说明

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