void setOrientation(int orientation) { long /*int*/ hMenu = parent.handle; MENUITEMINFO info = new MENUITEMINFO(); info.cbSize = MENUITEMINFO.sizeof; info.fMask = OS.MIIM_FTYPE; info.fType = widgetStyle(); OS.SetMenuItemInfo(hMenu, id, false, info); if (menu != null) menu._setOrientation(orientation); }
/** * Sets the receiver's text. The string may include the mnemonic character and accelerator text. * * <p>Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. * When the user presses a key sequence that matches the mnemonic, a selection event occurs. On * most platforms, the mnemonic appears underlined but may be emphasised in a platform specific * manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, * causing a single '&' to be displayed. * * <p>Accelerator text is indicated by the '\t' character. On platforms that support accelerator * text, the text that follows the '\t' character is displayed to the user, typically indicating * the key stroke that will cause the item to become selected. On most platforms, the accelerator * text appears right aligned in the menu. Setting the accelerator text does not install the * accelerator key sequence. The accelerator key sequence is installed using #setAccelerator. * * @param string the new text * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the text is null * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> * * @see #setAccelerator */ public void setText(String string) { checkWidget(); if (string == null) error(SWT.ERROR_NULL_ARGUMENT); if ((style & SWT.SEPARATOR) != 0) return; if (text.equals(string)) return; super.setText(string); long /*int*/ hHeap = OS.GetProcessHeap(); long /*int*/ pszText = 0; boolean success = false; if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) { /* * Bug in WinCE PPC. Tool items on the menubar don't resize * correctly when the character '&' is used (even when it * is a sequence '&&'). The fix is to remove all '&' from * the string. */ if (string.indexOf('&') != -1) { int length = string.length(); char[] text = new char[length]; string.getChars(0, length, text, 0); int i = 0, j = 0; for (i = 0; i < length; i++) { if (text[i] != '&') text[j++] = text[i]; } if (j < i) string = new String(text, 0, j); } /* Use the character encoding for the default locale */ TCHAR buffer = new TCHAR(0, string, true); int byteCount = buffer.length() * TCHAR.sizeof; pszText = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount); OS.MoveMemory(pszText, buffer, byteCount); long /*int*/ hwndCB = parent.hwndCB; TBBUTTONINFO info2 = new TBBUTTONINFO(); info2.cbSize = TBBUTTONINFO.sizeof; info2.dwMask = OS.TBIF_TEXT; info2.pszText = pszText; success = OS.SendMessage(hwndCB, OS.TB_SETBUTTONINFO, id, info2) != 0; } else { MENUITEMINFO info = new MENUITEMINFO(); info.cbSize = MENUITEMINFO.sizeof; long /*int*/ hMenu = parent.handle; /* Use the character encoding for the default locale */ TCHAR buffer = new TCHAR(0, string, true); int byteCount = buffer.length() * TCHAR.sizeof; pszText = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount); OS.MoveMemory(pszText, buffer, byteCount); /* * Bug in Windows 2000. For some reason, when MIIM_TYPE is set * on a menu item that also has MIIM_BITMAP, the MIIM_TYPE clears * the MIIM_BITMAP style. The fix is to use MIIM_STRING. */ if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) { info.fMask = OS.MIIM_STRING; } else { info.fMask = OS.MIIM_TYPE; info.fType = widgetStyle(); } info.dwTypeData = pszText; success = OS.SetMenuItemInfo(hMenu, id, false, info); } if (pszText != 0) OS.HeapFree(hHeap, 0, pszText); if (!success) { int error = OS.GetLastError(); SWT.error( SWT.ERROR_CANNOT_SET_TEXT, null, " [GetLastError=0x" + Integer.toHexString(error) + "]"); // $NON-NLS-1$ $NON-NLS-2$ } parent.redraw(); }