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

📄 tree.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	releaseItem (item, tvItem);	OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem);	if (fixRedraw) {		OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);		OS.ValidateRect (handle, null);		/*		* If the item that was deleted was the last child of a tree item that		* is visible, redraw the parent item to force the +/- to be updated.		*/		if (OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent) == 0) {			RECT rect = new RECT ();			rect.left = hParent;			if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) != 0) {				OS.InvalidateRect (handle, rect, true);			}		}	}	int count = OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);	if (count == 0) {		if (imageList != null) {			OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0);			display.releaseImageList (imageList);		}		imageList = null;		customDraw = false;		items = new TreeItem [4];		}}int getBackgroundPixel () {	if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOW);	int pixel = OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0);	if (pixel == -1) return OS.GetSysColor (OS.COLOR_WINDOW);	return pixel;}int getForegroundPixel () {	if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOWTEXT);	int pixel = OS.SendMessage (handle, OS.TVM_GETTEXTCOLOR, 0, 0);	if (pixel == -1) return OS.GetSysColor (OS.COLOR_WINDOWTEXT);	return pixel;}/** * Returns the item at the given point in the receiver * or null if no such item exists. The point is in the * coordinate system of the receiver. * * @param point the point used to locate the item * @return the item at the given point * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the point 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 TreeItem getItem (Point point) {	checkWidget ();	if (point == null) error (SWT.ERROR_NULL_ARGUMENT);	TVHITTESTINFO lpht = new TVHITTESTINFO ();	lpht.x = point.x;	lpht.y = point.y;	OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);	if (lpht.hItem != 0 && (lpht.flags & OS.TVHT_ONITEM) != 0) {		TVITEM tvItem = new TVITEM ();		tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;		tvItem.hItem = lpht.hItem;		OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);		return items [tvItem.lParam];		}	return null;}/** * Returns the number of items contained in the receiver * that are direct item children of the receiver.  The * number that is returned is the number of roots in the * tree. * * @return the number 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 int getItemCount () {	checkWidget ();	int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);	if (hItem == 0) return 0;	return getItemCount (hItem);}int getItemCount (int hItem) {	int count = 0;	while (hItem != 0) {		hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);		count++;	}	return count;}/** * Returns the height of the area which would be used to * display <em>one</em> of the items in the tree. * * @return the height of one item * * @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 getItemHeight () {	checkWidget ();	return OS.SendMessage (handle, OS.TVM_GETITEMHEIGHT, 0, 0);}/** * Returns the items contained in the receiver * that are direct item children of the receiver.  These * are the roots of the tree. * <p> * Note: This is not the actual structure used by the receiver * to maintain its list of items, so modifying the array will * not affect the receiver.  * </p> * * @return the 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 TreeItem [] getItems () {	checkWidget ();	int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);	if (hItem == 0) return new TreeItem [0];	return getItems (hItem);}TreeItem [] getItems (int hTreeItem) {	int count = 0, hItem = hTreeItem;	while (hItem != 0) {		hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);		count++;	}	int index = 0;	TreeItem [] result = new TreeItem [count];	TVITEM tvItem = new TVITEM ();	tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;	tvItem.hItem = hTreeItem;	/*	* Feature in Windows.  In some cases an expand or collapse message	* can occurs from within TVM_DELETEITEM.  When this happens, the item	* being destroyed has been removed from the list of items but has not	* been deleted from the tree.  The fix is to check for null items and	* remove them from the list.	*/	while (tvItem.hItem != 0) {		OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);		TreeItem item = items [tvItem.lParam];		if (item != null) result [index++] = item;		tvItem.hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, tvItem.hItem);	}	if (index != count) {		TreeItem [] newResult = new TreeItem [index];		System.arraycopy (result, 0, newResult, 0, index);		result = newResult;	}	return result;}/** * Returns the receiver's parent item, which must be a * <code>TreeItem</code> or null when the receiver is a * root. * * @return the receiver's parent item * * @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 TreeItem getParentItem () {	checkWidget ();	return null;}/** * Returns an array of <code>TreeItem</code>s that are currently * selected in the receiver. An empty array indicates that no * items are selected. * <p> * Note: This is not the actual structure used by the receiver * to maintain its selection, so modifying the array will * not affect the receiver.  * </p> * @return an array representing the selection * * @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 TreeItem [] getSelection () {	checkWidget ();	if ((style & SWT.SINGLE) != 0) {		int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);		if (hItem == 0) return new TreeItem [0];		TVITEM tvItem = new TVITEM ();		tvItem.mask = OS.TVIF_PARAM | OS.TVIF_STATE;		tvItem.hItem = hItem;		OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);		if ((tvItem.state & OS.TVIS_SELECTED) == 0) return new TreeItem [0];		return new TreeItem [] {items [tvItem.lParam]};	}	int count = 0;	TreeItem [] guess = new TreeItem [8];	TVITEM tvItem = new TVITEM ();	tvItem.mask = OS.TVIF_PARAM | OS.TVIF_STATE;	int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);	OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);	for (int i=0; i<items.length; i++) {		TreeItem item = items [i];		if (item != null) {			tvItem.hItem = item.handle;			OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);			if ((tvItem.state & OS.TVIS_SELECTED) != 0) {				if (count < guess.length) guess [count] = item;				count++;			}		}	}	OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);	if (count == 0) return new TreeItem [0];	if (count == guess.length) return guess;	TreeItem [] result = new TreeItem [count];	if (count < guess.length) {		System.arraycopy (guess, 0, result, 0, count);		return result;	}	OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);	int index = 0;	for (int i=0; i<items.length; i++) {		TreeItem item = items [i];		if (item != null) {			tvItem.hItem = item.handle;			OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);			if ((tvItem.state & OS.TVIS_SELECTED) != 0) {				result [index++] = item;			}		}	}	OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);	return result;}/** * Returns the number of selected items contained in the receiver. * * @return the number of selected 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 int getSelectionCount () {	checkWidget ();	if ((style & SWT.SINGLE) != 0) {		int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);		if (hItem == 0) return 0;		TVITEM tvItem = new TVITEM ();		tvItem.mask = OS.TVIF_STATE;		tvItem.hItem = hItem;		OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);		if ((tvItem.state & OS.TVIS_SELECTED) == 0) return 0;		return 1;	}	int count = 0;	TVITEM tvItem = new TVITEM ();	tvItem.mask = OS.TVIF_STATE;	int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);	OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);	for (int i=0; i<items.length; i++) {		TreeItem item = items [i];		if (item != null) {			tvItem.hItem = item.handle;			OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);			if ((tvItem.state & OS.TVIS_SELECTED) != 0) count++;		}	}	OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);	return count;}/** * Returns the item which is currently at the top of the receiver. * This item can change when items are expanded, collapsed, scrolled * or new items are added or removed. * * @return the item at the top of the receiver  *  * @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> *  * @since 2.1 */public TreeItem getTopItem () {	checkWidget ();	int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);	if (hItem == 0) return null;	TVITEM tvItem = new TVITEM ();	tvItem.mask = OS.TVIF_PARAM;	tvItem.hItem = hItem;	if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) == 0) return null;	return items [tvItem.lParam];}int imageIndex (Image image) {	if (image == null) return OS.I_IMAGENONE;	if (imageList == null) {		int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);		if (hOldList != 0) OS.ImageList_Destroy (hOldList);		Rectangle bounds = image.getBounds ();		imageList = display.getImageList (new Point (bounds.width, bounds.height));		int index = imageList.indexOf (image);		if (index == -1) index = imageList.add (image);		int hImageList = imageList.getHandle ();		OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, hImageList);		return index;	}	int index = imageList.indexOf (image);	if (index != -1) return index;	return imageList.add (image);}boolean releaseItem (TreeItem item, TVITEM tvItem) {	int hItem = item.handle;	if (hItem == hAnchor) hAnchor = 0;	if (item.isDisposed ()) return false;	tvItem.hItem = hItem;	OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);	items [tvItem.lParam] = null;	return true;}void releaseItems (TreeItem [] nodes, TVITEM tvItem) {	for (int i=0; i<nodes.length; i++) {		TreeItem item = nodes [i];		TreeItem [] sons = item.getItems ();		if (sons.length != 0) {			releaseItems (sons, tvItem);		}		if (releaseItem (item, tvItem)) {			item.releaseResources ();		}	}}void releaseWidget () {	for (int i=0; i<items.length; i++) {		TreeItem item = items [i];		if (item != null && !item.isDisposed ()) {			item.releaseResources ();		}	}	/*	* Feature in Windows.  For some reason, when	* TVM_GETIMAGELIST or TVM_SETIMAGELIST is sent,	* the tree issues NM_CUSTOMDRAW messages.  This	* behavior is unwanted when the tree is being	* disposed.  The fix is to ingore NM_CUSTOMDRAW	* messages by usnig the custom draw flag.

⌨️ 快捷键说明

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