?? treeitem.java
字號(hào):
* </ul> */public boolean getGrayed () { checkWidget (); if ((parent.style & SWT.CHECK) == 0) return false; int hwnd = parent.handle; TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE; tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; tvItem.hItem = handle; int result = OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); return (result != 0) && ((tvItem.state >> 12) > 2);}/** * Returns the number of items contained in the receiver * that are direct item children of the receiver. * * @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 hwnd = parent.handle; int hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle); if (hItem == 0) return 0; return parent.getItemCount (hItem);}/** * Returns an array of <code>TreeItem</code>s which are the * direct item children of the receiver. * <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 receiver's 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 hwnd = parent.handle; int hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle); if (hItem == 0) return new TreeItem [0]; return parent.getItems (hItem);}/** * Returns the receiver's parent, which must be a <code>Tree</code>. * * @return the receiver's parent * * @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 Tree getParent () { checkWidget (); return parent;}/** * 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 (); int hwnd = parent.handle; TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM; tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, handle); if (tvItem.hItem == 0) return null; OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); return parent.items [tvItem.lParam];}void redraw () { if (parent.drawCount > 0) return; int hwnd = parent.handle; if (!OS.IsWindowVisible (hwnd)) return; RECT rect = new RECT (); rect.left = handle; if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 1, rect) != 0) { OS.InvalidateRect (hwnd, rect, true); }}void releaseChild () { super.releaseChild (); parent.destroyItem (this);}void releaseHandle () { super.releaseHandle (); handle = 0;}void releaseWidget () { super.releaseWidget (); parent = null;}/** * Sets the receiver's background color to the color specified * by the argument, or to the default system color for the item * if the argument is null. * * @param color the new color (or null) * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument 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> * * @since 2.0 * */public void setBackground (Color color) { checkWidget (); if (color != null && color.isDisposed ()) { SWT.error (SWT.ERROR_INVALID_ARGUMENT); } int pixel = -1; if (color != null) { parent.customDraw = true; pixel = color.handle; } if (background == pixel) return; background = pixel; redraw ();}/** * Sets the checked state of the receiver. * <p> * * @param checked the new checked 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 setChecked (boolean checked) { checkWidget (); if ((parent.style & SWT.CHECK) == 0) return; int hwnd = parent.handle; TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE; tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; tvItem.hItem = handle; OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); int state = tvItem.state >> 12; if (checked) { if ((state & 0x1) != 0) state++; } else { if ((state & 0x1) == 0) --state; } tvItem.state = state << 12; OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);}/** * Sets the expanded state of the receiver. * <p> * * @param expanded the new expanded 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 setExpanded (boolean expanded) { checkWidget (); /* * Feature in Windows. When the user collapses the root * of a subtree that has the focus item, Windows moves * the selection to the root of the subtree and issues * a TVN_SELCHANGED to inform the programmer that the * seletion has changed. When the programmer collapses * the same subtree using TVM_EXPAND, Windows does not * send the selection changed notification. This is not * strictly wrong but is inconsistent. The fix is to notice * that the selection has changed and issue the event. */ int hwnd = parent.handle; int hOldItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); parent.ignoreExpand = true; OS.SendMessage (hwnd, OS.TVM_EXPAND, expanded ? OS.TVE_EXPAND : OS.TVE_COLLAPSE, handle); parent.ignoreExpand = false; int hNewItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); if (hNewItem != hOldItem) { Event event = new Event (); if (hNewItem != 0) { TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM; tvItem.hItem = hNewItem; if (OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem) != 0) { event.item = parent.items [tvItem.lParam]; } parent.hAnchor = hNewItem; } parent.sendEvent (SWT.Selection, event); }}/** * Sets the font that the receiver will use to paint textual information * for this item to the font specified by the argument, or to the default font * for that kind of control if the argument is null. * * @param font the new font (or null) * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument 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> * * @since 3.0 */public void setFont (Font font){ checkWidget (); if (font != null && font.isDisposed ()) { SWT.error (SWT.ERROR_INVALID_ARGUMENT); } int hFont = -1; if (font != null) { parent.customDraw = true; hFont = font.handle; } if (this.font == hFont) return; this.font = hFont; /* * Bug in Windows. When the font is changed for an item, * the bounds for the item are not updated, causing the text * to be clipped. The fix is to reset the text, causing * Windows to compute the new bounds using the new font. */ _setText (text); redraw ();}/** * Sets the receiver's foreground color to the color specified * by the argument, or to the default system color for the item * if the argument is null. * * @param color the new color (or null) * * @since 2.0 * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument 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> * * @since 2.0 * */public void setForeground (Color color) { checkWidget (); if (color != null && color.isDisposed ()) { SWT.error (SWT.ERROR_INVALID_ARGUMENT); } int pixel = -1; if (color != null) { parent.customDraw = true; pixel = color.handle; } if (foreground == pixel) return; foreground = pixel; redraw ();}/** * Sets the grayed state of the receiver. * <p> * * @param grayed the new grayed 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 setGrayed (boolean grayed) { checkWidget (); if ((parent.style & SWT.CHECK) == 0) return; int hwnd = parent.handle; TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE; tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; tvItem.hItem = handle; OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); int state = tvItem.state >> 12; if (grayed) { if (state <= 2) state +=2; } else { if (state > 2) state -=2; } tvItem.state = state << 12; OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);}public void setImage (Image image) { checkWidget (); /* * Feature in Windows. When TVM_SETITEM is used to set * an image for an item, the item redraws. This happens * because there is no easy way to know when a program * has drawn on an image that is already in the control. * However, an image that is an icon cannot be modified. * The fix is to check for the same image when the image * is an icon. */ if (image != null && image.type == SWT.ICON) { if (image.equals (this.image)) return; } super.setImage (image); int hwnd = parent.handle; TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_IMAGE | OS.TVIF_SELECTEDIMAGE; tvItem.iImage = parent.imageIndex (image); tvItem.iSelectedImage = tvItem.iImage; tvItem.hItem = handle; OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);}public void setText (String string) { checkWidget (); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); /* * Feature in Windows. When TVM_SETITEM is used to set * a string for an item that is equal to the string that * is already there, the item redraws. The fix is to * check for this case and do nothing. */ if (string.equals (text)) return; super.setText (string); _setText (string);}}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -