?? tree.java
字號:
/* Select/deselect the rest of the items */ TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_STATE; tvItem.stateMask = OS.TVIS_SELECTED; int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC); OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc); for (int i=0; i<this.items.length; i++) { item = this.items [i]; if (item != null) { int index = 0; while (index < length) { if (items [index] == item) break; index++; } tvItem.hItem = item.handle; OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); if ((tvItem.state & OS.TVIS_SELECTED) != 0) { if (index == length) { tvItem.state = 0; OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); } } else { if (index != length) { tvItem.state = OS.TVIS_SELECTED; OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); } } } } OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);}/** * Sets 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. * * @param item the item to be shown * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the item is null</li> * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</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 Tree#getTopItem() * * @since 2.1 */public void setTopItem (TreeItem item) { checkWidget (); if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); int hItem = item.handle; boolean fixScroll = checkScroll (hItem); if (fixScroll) { OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); } OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hItem); if (fixScroll) { OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); }}void showItem (int hItem) { /* * Bug in Windows. When TVM_ENSUREVISIBLE is used to ensure * that an item is visible and the client area of the tree is * smaller that the size of one item, TVM_ENSUREVISIBLE makes * the next item in the tree visible by making it the top item * instead of making the desired item visible. The fix is to * detect the case when the client area is too small and make * the desired visible item be the top item in the tree. */ if (OS.SendMessage (handle, OS.TVM_GETVISIBLECOUNT, 0, 0) == 0) { boolean fixScroll = checkScroll (hItem); if (fixScroll) { OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); } OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hItem); OS.SendMessage (handle, OS.WM_HSCROLL, OS.SB_TOP, 0); if (fixScroll) { OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); } } else { boolean scroll = true; RECT itemRect = new RECT (); itemRect.left = hItem; if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, itemRect) != 0) { forceResize (); RECT rect = new RECT (); OS.GetClientRect (handle, rect); POINT pt = new POINT (); pt.x = itemRect.left; pt.y = itemRect.top; if (OS.PtInRect (rect, pt)) { pt.y = itemRect.bottom; if (OS.PtInRect (rect, pt)) scroll = false; } } if (scroll) { boolean fixScroll = checkScroll (hItem); if (fixScroll) { OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); } OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hItem); if (fixScroll) { OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); } } }}/** * Shows the item. If the item is already showing in the receiver, * this method simply returns. Otherwise, the items are scrolled * and expanded until the item is visible. * * @param item the item to be shown * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the item is null</li> * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</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 Tree#showSelection() */public void showItem (TreeItem item) { checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); if (item.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); showItem (item.handle);}/** * Shows the selection. If the selection is already showing in the receiver, * this method simply returns. Otherwise, the items are scrolled until * the selection is visible. * * @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 Tree#showItem(TreeItem) */public void showSelection () { checkWidget (); int hItem = 0; if ((style & SWT.SINGLE) != 0) { hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); if (hItem == 0) return; 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; } else { TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_STATE; int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC); OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc); int index = 0; while (index <items.length) { TreeItem item = items [index]; if (item != null) { tvItem.hItem = item.handle; OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); if ((tvItem.state & OS.TVIS_SELECTED) != 0) { hItem = tvItem.hItem; break; } } index++; } OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc); } if (hItem != 0) showItem (hItem);}String toolTipText (NMTTDISPINFO hdr) { int hwndToolTip = OS.SendMessage (handle, OS.TVM_GETTOOLTIPS, 0, 0); if (hwndToolTip == hdr.hwndFrom && toolTipText != null) return ""; //$NON-NLS-1$ return super.toolTipText (hdr);}int widgetStyle () { int bits = super.widgetStyle () | OS.TVS_SHOWSELALWAYS; bits |= OS.TVS_LINESATROOT | OS.TVS_HASLINES | OS.TVS_HASBUTTONS; /* * This code is intentionally commented. In future, * FULL_SELECTION may be implemented for trees. */// if ((style & SWT.FULL_SELECTION) != 0) {// bits |= OS.TVS_FULLROWSELECT;// } else {// bits |= OS.TVS_HASLINES | OS.TVS_HASBUTTONS;// }// bits |= OS.TVS_NOTOOLTIPS; return bits;}TCHAR windowClass () { return TreeClass;}int windowProc () { return TreeProc;}LRESULT WM_CHAR (int wParam, int lParam) { LRESULT result = super.WM_CHAR (wParam, lParam); if (result != null) return result; /* * Feature in Windows. The tree control beeps * in WM_CHAR when the search for the item that * matches the key stroke fails. This is the * standard tree behavior but is unexpected when * the key that was typed was ESC, CR or SPACE. * The fix is to avoid calling the tree window * proc in these cases. */ switch (wParam) { case OS.VK_RETURN: /* * Feature in Windows. Windows sends NM_RETURN from WM_KEYDOWN * instead of using WM_CHAR. This means that application code * that expects to consume the key press and therefore avoid the * SWT.DefaultSelection event from WM_CHAR will fail. The fix * is to implement SWT.DefaultSelection in WM_CHAR instead of * using NM_RETURN. */ Event event = new Event (); int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); if (hItem != 0) { TVITEM tvItem = new TVITEM (); tvItem.hItem = hItem; tvItem.mask = OS.TVIF_PARAM; OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); event.item = items [tvItem.lParam]; } postEvent (SWT.DefaultSelection, event); //FALL THROUGH case OS.VK_ESCAPE: case OS.VK_SPACE: return LRESULT.ZERO; } return result;}LRESULT WM_GETOBJECT (int wParam, int lParam) { /* * Ensure that there is an accessible object created for this * control because support for checked item accessibility is * temporarily implemented in the accessibility package. */ if ((style & SWT.CHECK) != 0) { if (accessible == null) accessible = new_Accessible (this); } return super.WM_GETOBJECT (wParam, lParam);}LRESULT WM_KEYDOWN (int wParam, int lParam) { LRESULT result = super.WM_KEYDOWN (wParam, lParam); if (result != null) return result; switch (wParam) { case OS.VK_SPACE: { int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); if (hItem != 0) { hAnchor = hItem; OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hItem); TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_STATE | OS.TVIF_PARAM; tvItem.hItem = hItem; if ((style & SWT.CHECK) != 0) { tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); int state = tvItem.state >> 12; if ((state & 0x1) != 0) { state++; } else { --state; } tvItem.state = state << 12; OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); if (!OS.IsWinCE) { int id = hItem; if (OS.COMCTL32_MAJOR >= 6) { id = OS.SendMessage (handle, OS.TVM_MAPHTREEITEMTOACCID, hItem, 0); } OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, handle, OS.OBJID_CLIENT, id); } } tvItem.stateMask = OS.TVIS_SELECTED; OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); if ((style & SWT.MULTI) != 0 && OS.GetKeyState (OS.VK_CONTROL) < 0) { if ((tvItem.state & OS.TVIS_SELECTED) != 0) { tvItem.state &= ~OS.TVIS_SELECTED; } else { tvItem.state |= OS.TVIS_SELECTED; } } else { tvItem.state |= OS.TVIS_SELECTED; } OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); Event event = new Event (); event.item = items [tvItem.lParam]; postEvent (SWT.Selection, event); if ((style & SWT.CHECK) != 0) { event = new Event (); event.item = items [tvItem.lParam]; event.detail = SWT.CHECK; postEvent (SWT.Selection, event); } return LRESULT.ZERO; } break; } case OS.VK_UP: case OS.VK_DOWN: case OS.VK_PRIOR: case OS.VK_NEXT: case OS.VK_HOME: case OS.VK_END: { if ((style & SWT.SINGLE) != 0) break; if (OS.GetKeyState (OS.VK_SHIFT) < 0) { int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); if (hItem != 0) { if (hAnchor == 0) hAnchor = hItem; ignoreSelect = ignoreDeselect = true; int code = callWindowProc (OS.WM_KEYDOWN, wParam, lParam); ignoreSelect = ignoreDeselect = false; int hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_STATE; tvItem.stateMask = OS.TVIS_SELECTED; int hDeselectItem = hItem; RECT rect1 = new RECT (); rect1.left = hAnchor; OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1); RECT rect2 = rect2 = new RECT (); rect2.left = hDeselectItem; OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2); int flags = rect1.top < rect2.top ? OS.TVGN_PREVIOUSVISIBLE : OS.TVGN_NEXTVISIBLE; while (hDeselectItem != hAnchor) { tvItem.hItem = hDeselectItem; OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); hDeselectItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, flags, hDeselectItem); } int hSelectItem = hAnchor; rect1.left = hNewItem; OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1); rect2.left = hSelectItem; OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2); tvItem.state = OS.TVIS_SELECTED; flags = rect1.top < rect2.top ? OS.TVGN_PREVIOUSVISIBLE : OS.TVGN_NEXTVISIBLE; while (hSelectItem != hNewItem) { tvItem.hItem = hSelectItem; OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); hSelectItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, flags, hSelectItem); } tvItem.hItem = hNewItem; OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); tvItem.mask = OS.TVIF_PARAM; tvItem.hItem = hNewItem; OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); Event event = new Event (); event.item = items [tvItem.lParam]; postEvent (SWT.Selection, event);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -