?? menu.java
字號:
info.fMask = OS.MIIM_DATA; info.dwItemData = item.id; success = OS.SetMenuItemInfo (handle, index, true, info); } } else { /* * Bug in Windows. For some reason, when InsertMenuItem() * is used to insert an item without text, it is not possible * to use SetMenuItemInfo() to set the text at a later time. * The fix is to insert the item with some text. * * Feature in Windows. When an empty string is used instead * of a space and InsertMenuItem() is used to set a submenu * before setting text to a non-empty string, the menu item * becomes unexpectedly disabled. The fix is to insert a * space. */ int hHeap = OS.GetProcessHeap (); TCHAR buffer = new TCHAR (0, " ", true); int byteCount = buffer.length () * TCHAR.sizeof; int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); OS.MoveMemory (pszText, buffer, byteCount); MENUITEMINFO info = new MENUITEMINFO (); info.cbSize = MENUITEMINFO.sizeof; info.fMask = OS.MIIM_ID | OS.MIIM_TYPE | OS.MIIM_DATA; info.wID = info.dwItemData = item.id; info.fType = item.widgetStyle (); info.dwTypeData = pszText; success = OS.InsertMenuItem (handle, index, true, info); if (pszText != 0) OS.HeapFree (hHeap, 0, pszText); } } if (!success) { display.removeMenuItem (item); error (SWT.ERROR_ITEM_NOT_ADDED); } redraw ();} void createWidget () { /* * Bug in IBM JVM 1.3.1. For some reason, when the following code is called * from this method, the JVM issues this error: * * JVM Exception 0x2 (subcode 0x0) occurred in thread "main" (TID:0x9F19D8) * * In addition, on Windows XP, a dialog appears with following error message, * indicating that the problem may be in the JIT: * * AppName: java.exe AppVer: 0.0.0.0 ModName: jitc.dll * ModVer: 0.0.0.0 Offset: 000b6912 * The fix is to move the code to the caller of this method. */// checkOrientation (parent); createHandle (); parent.addMenu (this);}/** Currently not used.*/int defaultBackground () { return OS.GetSysColor (OS.COLOR_MENU);}/** Currently not used.*/int defaultForeground () { return OS.GetSysColor (OS.COLOR_MENUTEXT);}void destroyAccelerators () { parent.destroyAccelerators ();}void destroyItem (MenuItem item) { if (OS.IsWinCE) { if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) { if (OS.IsSP) { redraw(); return; } int index = OS.SendMessage (hwndCB, OS.TB_COMMANDTOINDEX, item.id, 0); if (OS.SendMessage (hwndCB, OS.TB_DELETEBUTTON, index, 0) == 0) { error (SWT.ERROR_ITEM_NOT_REMOVED); } int count = OS.SendMessage (hwndCB, OS.TB_BUTTONCOUNT, 0, 0); if (count == 0) { if (imageList != null) { OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, 0); display.releaseImageList (imageList); imageList = null; } } } else { int index = 0; MENUITEMINFO info = new MENUITEMINFO (); info.cbSize = MENUITEMINFO.sizeof; info.fMask = OS.MIIM_DATA; while (OS.GetMenuItemInfo (handle, index, true, info)) { if (info.dwItemData == item.id) break; index++; } if (info.dwItemData != item.id) { error (SWT.ERROR_ITEM_NOT_REMOVED); } if (!OS.RemoveMenu (handle, index, OS.MF_BYPOSITION)) { error (SWT.ERROR_ITEM_NOT_REMOVED); } } } else { if (!OS.RemoveMenu (handle, item.id, OS.MF_BYCOMMAND)) { error (SWT.ERROR_ITEM_NOT_REMOVED); } } redraw ();}void destroyWidget () { int hMenu = handle, hCB = hwndCB; releaseHandle (); if (OS.IsWinCE && hCB != 0) { OS.CommandBar_Destroy (hCB); } else { if (hMenu != 0) OS.DestroyMenu (hMenu); }}void fixMenus (Decorations newParent) { MenuItem [] items = getItems (); for (int i=0; i<items.length; i++) { items [i].fixMenus (newParent); } parent.removeMenu (this); newParent.addMenu (this); this.parent = newParent;}/** * Returns the default menu item or null if none has * been previously set. * * @return the default menu item. * * </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 MenuItem getDefaultItem () { checkWidget (); if (OS.IsWinCE) return null; int id = OS.GetMenuDefaultItem (handle, OS.MF_BYCOMMAND, OS.GMDI_USEDISABLED); if (id == -1) return null; MENUITEMINFO info = new MENUITEMINFO (); info.cbSize = MENUITEMINFO.sizeof; info.fMask = OS.MIIM_ID; if (OS.GetMenuItemInfo (handle, id, false, info)) { return display.getMenuItem (info.wID); } return null;}/** * Returns <code>true</code> if the receiver is enabled, and * <code>false</code> otherwise. A disabled control is typically * not selectable from the user interface and draws with an * inactive or "grayed" look. * * @return the receiver's enabled 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> * * @see #isEnabled */public boolean getEnabled () { checkWidget (); return (state & DISABLED) == 0;}/** * Returns the item at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * * @param index the index of the item to return * @return the item at the given index * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</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 MenuItem getItem (int index) { checkWidget (); int id = 0; if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) { if (OS.IsPPC) { TBBUTTON lpButton = new TBBUTTON (); int result = OS.SendMessage (hwndCB, OS.TB_GETBUTTON, index, lpButton); if (result == 0) error (SWT.ERROR_CANNOT_GET_ITEM); id = lpButton.idCommand; } if (OS.IsSP) { if (!(0 <= index && index <= 1)) error (SWT.ERROR_CANNOT_GET_ITEM); id = index == 0 ? id0 : id1; } } else { MENUITEMINFO info = new MENUITEMINFO (); info.cbSize = MENUITEMINFO.sizeof; info.fMask = OS.MIIM_DATA; if (!OS.GetMenuItemInfo (handle, index, true, info)) { } id = info.dwItemData; } return display.getMenuItem (id);}/** * Returns the number of items contained in 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 (); return GetMenuItemCount (handle);}/** * Returns an array of <code>MenuItem</code>s which are the items * in 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 items in 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> */public MenuItem [] getItems () { checkWidget (); if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) { if (OS.IsSP) { MenuItem [] result = new MenuItem [2]; result[0] = display.getMenuItem (id0); result[1] = display.getMenuItem (id1); return result; } int count = OS.SendMessage (hwndCB, OS.TB_BUTTONCOUNT, 0, 0); TBBUTTON lpButton = new TBBUTTON (); MenuItem [] result = new MenuItem [count]; for (int i=0; i<count; i++) { OS.SendMessage (hwndCB, OS.TB_GETBUTTON, i, lpButton); result [i] = display.getMenuItem (lpButton.idCommand); } return result; } int index = 0; int length = OS.IsWinCE ? 4 : OS.GetMenuItemCount (handle); MenuItem [] items = new MenuItem [length]; MENUITEMINFO info = new MENUITEMINFO (); info.cbSize = MENUITEMINFO.sizeof; info.fMask = OS.MIIM_DATA; while (OS.GetMenuItemInfo (handle, index, true, info)) { if (index == items.length) { MenuItem [] newItems = new MenuItem [index + 4]; System.arraycopy (items, 0, newItems, 0, index); items = newItems; } items [index++] = display.getMenuItem (info.dwItemData); } if (index == items.length) return items; MenuItem [] result = new MenuItem [index]; System.arraycopy (items, 0, result, 0, index); return result;}int GetMenuItemCount (int handle) { checkWidget (); if (OS.IsWinCE) { if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) { return OS.IsSP ? 2 : OS.SendMessage (hwndCB, OS.TB_BUTTONCOUNT, 0, 0); } int count = 0; MENUITEMINFO info = new MENUITEMINFO (); info.cbSize = MENUITEMINFO.sizeof; while (OS.GetMenuItemInfo (handle, count, true, info)) count++; return count; } return OS.GetMenuItemCount (handle);}String getNameText () { String result = ""; MenuItem [] items = getItems (); int length = items.length; if (length > 0) { for (int i=0; i<length-1; i++) { result = result + items [i].getNameText() + ", "; } result = result + items [length-1].getNameText (); } return result;}/** * Returns the receiver's parent, which must be a <code>Decorations</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 Decorations getParent () { checkWidget (); return parent;}/** * Returns the receiver's parent item, which must be a * <code>MenuItem</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 MenuItem getParentItem () { checkWidget (); return cascade;}/** * Returns the receiver's parent item, which must be a * <code>Menu</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 Menu getParentMenu () { checkWidget (); if (cascade != null) return cascade.parent; return null;}/** * Returns the receiver's shell. For all controls other than * shells, this simply returns the control's nearest ancestor * shell. Shells return themselves, even if they are children * of other shells. * * @return the receiver's shell * * @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 #getParent */public Shell getShell () { checkWidget (); return parent.getShell ();}/** * Returns a point describing the receiver's size. The * x coordinate of the result is the width of the receiver. * The y coordinate of the result is the height of the * receiver. * * @return the receiver's size * * @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*/ Point getSize () { checkWidget (); if (OS.IsWinCE) return new Point (0, 0); if ((style & SWT.BAR) != 0) { MENUBARINFO info = new MENUBARINFO (); info.cbSize = MENUBARINFO.sizeof; int hwndParent = parent.handle; if (OS.GetMenuBarInfo (hwndParent, OS.OBJID_MENU, 0, info)) { int width = info.right - info.left; int height = info.bottom - info.top; return new Point (width, height); } } else { int count = GetMenuItemCount (handle); if (count != 0) { RECT rect1 = new RECT (); int hwndParent = parent.handle; if (OS.GetMenuItemRect (hwndParent, handle, 0, rect1)) { RECT rect2 = new RECT (); if (OS.GetMenuItemRect (hwndParent, handle, count - 1, rect2)) { int width = (rect2.right - rect2.left) + 4; int height = (rect2.bottom - rect1.top) + 4; return new Point (width, height); } } } } return new Point (0, 0);}/** * Returns <code>true</code> if the receiver is visible, and * <code>false</code> otherwise. * <p>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -