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); if ((style & SWT.VIRTUAL) != 0) { int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0); count = getSelection (hItem, tvItem, guess, 0); } else { 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); if ((style & SWT.VIRTUAL) != 0) { int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0); getSelection (hItem, tvItem, result, 0); } else { 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;
return count;
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 [] {_getItem (tvItem.hItem, 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);	if ((style & SWT.VIRTUAL) != 0) {		int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);		count = getSelection (hItem, tvItem, guess, 0);	} else {		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);	if ((style & SWT.VIRTUAL) != 0) {		int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);		getSelection (hItem, tvItem, result, 0);	} else {		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;}