static void NativeMenuItem_setText (GuiObject me) { int acc = my motiff.pushButton.acceleratorChar, modifiers = my motiff.pushButton.acceleratorModifiers; #if win static MelderString title = { 0 }; if (acc == 0) { MelderString_copy (& title, _GuiWin_expandAmpersands (my name)); } else { static const wchar_t *keyStrings [256] = { 0, L"<-", L"->", L"Up", L"Down", L"PAUSE", L"Del", L"Ins", L"Backspace", L"Tab", L"LineFeed", L"Home", L"End", L"Enter", L"PageUp", L"PageDown", L"Esc", L"F1", L"F2", L"F3", L"F4", L"F5", L"F6", L"F7", L"F8", L"F9", L"F10", L"F11", L"F12", 0, 0, 0, L"Space", L"!", L"\"", L"#", L"$", L"%", L"&", L"\'", L"(", L")", L"*", L"+", L",", L"-", L".", L"/", L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9", L":", L";", L"<", L"=", L">", L"?", L"@", L"A", L"B", L"C", L"D", L"E", L"F", L"G", L"H", L"I", L"J", L"K", L"L", L"M", L"N", L"O", L"P", L"Q", L"R", L"S", L"T", L"U", L"V", L"W", L"X", L"Y", L"Z", L"[", L"\\", L"]", L"^", L"_", L"`", L"a", L"b", L"c", L"d", L"e", L"f", L"g", L"h", L"i", L"j", L"k", L"l", L"m", L"n", L"o", L"p", L"q", L"r", L"s", L"t", L"u", L"v", L"w", L"x", L"y", L"z", L"{", L"|", L"}", L"~", L"Del", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"[", L"]", L",", L"?", L".", L"\\", L";", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"-", L"`", L"=", L"\'", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const wchar_t *keyString = keyStrings [acc] ? keyStrings [acc] : L"???"; MelderString_empty (& title); MelderString_append (& title, _GuiWin_expandAmpersands (my name), L"\t", modifiers & _motif_COMMAND_MASK ? L"Ctrl-" : NULL, modifiers & _motif_OPTION_MASK ? L"Alt-" : NULL, modifiers & _motif_SHIFT_MASK ? L"Shift-" : NULL, keyString); } ModifyMenu (my nat.entry.handle, my nat.entry.id, MF_BYCOMMAND | MF_STRING, my nat.entry.id, title.string); #elif mac static int theGlyphs [1+31] = { 0, kMenuLeftArrowDashedGlyph, kMenuRightArrowDashedGlyph, kMenuUpArrowDashedGlyph, kMenuDownwardArrowDashedGlyph, 0, kMenuDeleteRightGlyph, 0, kMenuDeleteLeftGlyph, kMenuTabRightGlyph, 0, 0, 0, kMenuReturnGlyph, kMenuPageUpGlyph, kMenuPageDownGlyph, kMenuEscapeGlyph, kMenuF1Glyph, kMenuF2Glyph, kMenuF3Glyph, kMenuF4Glyph, kMenuF5Glyph, kMenuF6Glyph, kMenuF7Glyph, kMenuF8Glyph, kMenuF9Glyph, kMenuF10Glyph, kMenuF11Glyph, kMenuF12Glyph, 0, 0, 0 }; SetMenuItemTextWithCFString (my nat.entry.handle, my nat.entry.item, (CFStringRef) Melder_peekWcsToCfstring (my name)); if (acc > 32) { SetItemCmd (my nat.entry.handle, my nat.entry.item, acc); } else { Melder_assert (acc > 0 && acc < 32); SetItemCmd (my nat.entry.handle, my nat.entry.item, ' '); /* Funny that this should be needed. */ SetMenuItemKeyGlyph (my nat.entry.handle, my nat.entry.item, theGlyphs [acc]); } SetMenuItemModifiers (my nat.entry.handle, my nat.entry.item, ( modifiers & _motif_OPTION_MASK ? kMenuOptionModifier : 0 ) + ( modifiers & _motif_SHIFT_MASK ? kMenuShiftModifier : 0 ) + ( modifiers & _motif_COMMAND_MASK ? 0 : kMenuNoCommandModifier )); #endif }
static void NativeMenuItem_setText (GuiObject me) { int acc = my motiff.pushButton.acceleratorChar, modifiers = my motiff.pushButton.acceleratorModifiers; #if win static MelderString title { 0 }; if (acc == 0) { MelderString_copy (& title, _GuiWin_expandAmpersands (my name)); } else { static const char32 *keyStrings [256] = { 0, U"<-", U"->", U"Up", U"Down", U"PAUSE", U"Del", U"Ins", U"Backspace", U"Tab", U"LineFeed", U"Home", U"End", U"Enter", U"PageUp", U"PageDown", U"Esc", U"F1", U"F2", U"F3", U"F4", U"F5", U"F6", U"F7", U"F8", U"F9", U"F10", U"F11", U"F12", 0, 0, 0, U"Space", U"!", U"\"", U"#", U"$", U"%", U"&", U"\'", U"(", U")", U"*", U"+", U",", U"-", U".", U"/", U"0", U"1", U"2", U"3", U"4", U"5", U"6", U"7", U"8", U"9", U":", U";", U"<", U"=", U">", U"?", U"@", U"A", U"B", U"C", U"D", U"E", U"F", U"G", U"H", U"I", U"J", U"K", U"L", U"M", U"N", U"O", U"P", U"Q", U"R", U"S", U"T", U"U", U"V", U"W", U"X", U"Y", U"Z", U"[", U"\\", U"]", U"^", U"_", U"`", U"a", U"b", U"c", U"d", U"e", U"f", U"g", U"h", U"i", U"j", U"k", U"l", U"m", U"n", U"o", U"p", U"q", U"r", U"s", U"t", U"u", U"v", U"w", U"x", U"y", U"z", U"{", U"|", U"}", U"~", U"Del", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, U"[", U"]", U",", U"?", U".", U"\\", U";", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, U"-", U"`", U"=", U"\'", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const char32 *keyString = keyStrings [acc] ? keyStrings [acc] : U"???"; MelderString_copy (& title, _GuiWin_expandAmpersands (my name), U"\t", modifiers & _motif_COMMAND_MASK ? U"Ctrl-" : nullptr, modifiers & _motif_OPTION_MASK ? U"Alt-" : nullptr, modifiers & _motif_SHIFT_MASK ? U"Shift-" : nullptr, keyString); } ModifyMenu (my nat.entry.handle, my nat.entry.id, MF_BYCOMMAND | MF_STRING, my nat.entry.id, Melder_peek32toW (title.string)); #elif mac static int theGlyphs [1+31] = { 0, kMenuLeftArrowDashedGlyph, kMenuRightArrowDashedGlyph, kMenuUpArrowDashedGlyph, kMenuDownwardArrowDashedGlyph, 0, kMenuDeleteRightGlyph, 0, kMenuDeleteLeftGlyph, kMenuTabRightGlyph, 0, 0, 0, kMenuReturnGlyph, kMenuPageUpGlyph, kMenuPageDownGlyph, kMenuEscapeGlyph, kMenuF1Glyph, kMenuF2Glyph, kMenuF3Glyph, kMenuF4Glyph, kMenuF5Glyph, kMenuF6Glyph, kMenuF7Glyph, kMenuF8Glyph, kMenuF9Glyph, kMenuF10Glyph, kMenuF11Glyph, kMenuF12Glyph, 0, 0, 0 }; SetMenuItemTextWithCFString (my nat.entry.handle, my nat.entry.item, (CFStringRef) Melder_peek32toCfstring (my name)); if (acc > 32) { SetItemCmd (my nat.entry.handle, my nat.entry.item, acc); } else { Melder_assert (acc > 0 && acc < 32); SetItemCmd (my nat.entry.handle, my nat.entry.item, ' '); /* Funny that this should be needed. */ SetMenuItemKeyGlyph (my nat.entry.handle, my nat.entry.item, theGlyphs [acc]); } SetMenuItemModifiers (my nat.entry.handle, my nat.entry.item, ( modifiers & _motif_OPTION_MASK ? kMenuOptionModifier : 0 ) + ( modifiers & _motif_SHIFT_MASK ? kMenuShiftModifier : 0 ) + ( modifiers & _motif_COMMAND_MASK ? 0 : kMenuNoCommandModifier )); #endif }
EXPORT(sqInt) primitiveSetItemCmd(void) { CharParameter aCharacter; MenuHandle menuHandle; sqInt menuHandleOop; sqInt anInteger; sqInt anIntegerCmdChar; sqInt _return_value; menuHandleOop = interpreterProxy->stackValue(2); anInteger = interpreterProxy->stackIntegerValue(1); anIntegerCmdChar = interpreterProxy->stackIntegerValue(0); if (interpreterProxy->failed()) { return null; } menuHandle = ((MenuHandle) (interpreterProxy->positive64BitValueOf(menuHandleOop))); if (!(ioCheckMenuHandle(menuHandle))) { _return_value = interpreterProxy->success(0); if (interpreterProxy->failed()) { return null; } interpreterProxy->popthenPush(4, _return_value); return null; } aCharacter = anIntegerCmdChar; SetItemCmd(menuHandle,anInteger,aCharacter); return null; }
static void MenuBarInit(void) { Handle hdl; MenuHandle hmenu; hdl = GetNewMBar(IDM_MAINMENU); if (hdl == NULL) { ExitToShell(); } SetMenuBar(hdl); hmenu = GetMenuHandle(IDM_APPLE); if (hmenu) { AppendResMenu(hmenu, 'DRVR'); } #if !defined(SUPPORT_SCSI) hmenu = GetMenuHandle(IDM_HARDDISK); if (hmenu) { DeleteMenuItem(hmenu, 7); DeleteMenuItem(hmenu, 6); DeleteMenuItem(hmenu, 5); DeleteMenuItem(hmenu, 4); DeleteMenuItem(hmenu, 3); } #endif if (!np2oscfg.I286SAVE) { hmenu = GetMenuHandle(IDM_OTHER); if (hmenu) { DeleteMenuItem(hmenu, 9); } } InsertMenu(GetMenu(IDM_SASI1), -1); InsertMenu(GetMenu(IDM_SASI2), -1); #if defined(SUPPORT_SCSI) InsertMenu(GetMenu(IDM_SCSI0), -1); InsertMenu(GetMenu(IDM_SCSI1), -1); InsertMenu(GetMenu(IDM_SCSI2), -1); InsertMenu(GetMenu(IDM_SCSI3), -1); #endif InsertMenu(GetMenu(IDM_KEYBOARD), -1); InsertMenu(GetMenu(IDM_SOUND), -1); InsertMenu(GetMenu(IDM_MEMORY), -1); #if TARGET_API_MAC_CARBON hmenu = GetMenuHandle(IDM_FDD2); SetItemCmd(hmenu, LoWord(IDM_FDD2OPEN), 'D'); SetMenuItemModifiers(hmenu, LoWord(IDM_FDD2OPEN), kMenuShiftModifier); SetItemCmd(hmenu, LoWord(IDM_FDD2EJECT), 'E'); SetMenuItemModifiers(hmenu, LoWord(IDM_FDD2EJECT), kMenuShiftModifier); hmenu = GetMenuHandle(IDM_SASI2); SetItemCmd(hmenu, LoWord(IDM_SASI2OPEN), 'O'); SetMenuItemModifiers(hmenu, LoWord(IDM_SASI2OPEN), kMenuShiftModifier); #else EnableItem(GetMenuHandle(IDM_DEVICE), LoWord(IDM_MOUSE)); EnableItem(GetMenuHandle(IDM_KEYBOARD), LoWord(IDM_F12MOUSE)); #endif if (!(np2cfg.fddequip & 1)) { DeleteMenu(IDM_FDD1); } if (!(np2cfg.fddequip & 2)) { DeleteMenu(IDM_FDD2); } if (!(np2cfg.fddequip & 4)) { DeleteMenu(IDM_FDD3); } if (!(np2cfg.fddequip & 8)) { DeleteMenu(IDM_FDD4); } #if defined(SUPPORT_STATSAVE) if (!np2oscfg.statsave) { #endif DeleteMenu(IDM_STATSAVE); #if defined(SUPPORT_STATSAVE) } #endif DrawMenuBar(); }
void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry ) { if ( !entry ) { SetMenuItemCommandKey(menu, item, false, 0); return ; } UInt8 modifiers = 0 ; SInt16 key = entry->GetKeyCode() ; if ( key ) { bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL); if (entry->GetFlags() & wxACCEL_ALT) modifiers |= kMenuOptionModifier ; if (entry->GetFlags() & wxACCEL_SHIFT) modifiers |= kMenuShiftModifier ; SInt16 glyph = 0 ; SInt16 macKey = key ; if ( key >= WXK_F1 && key <= WXK_F15 ) { if ( !explicitCommandKey ) modifiers |= kMenuNoCommandModifier ; // for some reasons this must be 0 right now // everything else leads to just the first function key item // to be selected. Thanks to Ryan Wilcox for finding out. macKey = 0 ; glyph = kMenuF1Glyph + ( key - WXK_F1 ) ; if ( key >= WXK_F13 ) glyph += 12 ; } else { switch ( key ) { case WXK_BACK : macKey = kBackspaceCharCode ; glyph = kMenuDeleteLeftGlyph ; break ; case WXK_TAB : macKey = kTabCharCode ; glyph = kMenuTabRightGlyph ; break ; case kEnterCharCode : macKey = kEnterCharCode ; glyph = kMenuEnterGlyph ; break ; case WXK_RETURN : macKey = kReturnCharCode ; glyph = kMenuReturnGlyph ; break ; case WXK_ESCAPE : macKey = kEscapeCharCode ; glyph = kMenuEscapeGlyph ; break ; case WXK_SPACE : macKey = ' ' ; glyph = kMenuSpaceGlyph ; break ; case WXK_DELETE : macKey = kDeleteCharCode ; glyph = kMenuDeleteRightGlyph ; break ; case WXK_CLEAR : macKey = kClearCharCode ; glyph = kMenuClearGlyph ; break ; case WXK_PAGEUP : macKey = kPageUpCharCode ; glyph = kMenuPageUpGlyph ; break ; case WXK_PAGEDOWN : macKey = kPageDownCharCode ; glyph = kMenuPageDownGlyph ; break ; case WXK_LEFT : macKey = kLeftArrowCharCode ; glyph = kMenuLeftArrowGlyph ; break ; case WXK_UP : macKey = kUpArrowCharCode ; glyph = kMenuUpArrowGlyph ; break ; case WXK_RIGHT : macKey = kRightArrowCharCode ; glyph = kMenuRightArrowGlyph ; break ; case WXK_DOWN : macKey = kDownArrowCharCode ; glyph = kMenuDownArrowGlyph ; break ; case WXK_HOME : macKey = kHomeCharCode ; glyph = kMenuNorthwestArrowGlyph ; break ; case WXK_END : macKey = kEndCharCode ; glyph = kMenuSoutheastArrowGlyph ; break ; default : macKey = toupper( key ) ; break ; } // we now allow non command key shortcuts // remove in case this gives problems if ( !explicitCommandKey ) modifiers |= kMenuNoCommandModifier ; } // 1d and 1e have special meaning to SetItemCmd, so // do not use for these character codes. if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT) SetItemCmd( menu, item , macKey ); SetMenuItemModifiers( menu, item , modifiers ) ; if ( glyph ) SetMenuItemKeyGlyph( menu, item , glyph ) ; } }
// create the Shell menu in Terminal static void AddShellItems( MenuRef menu ) { MenuItemIndex item; AppendMenuItemTextWithCFString( menu, CFSTR("New"), 0, 0, &item ); SetItemCmd( menu, item, 'N' ); AppendMenuItemTextWithCFString( menu, CFSTR("Open..."), 0, 0, &item ); SetItemCmd( menu, item, 'O' ); AppendMenuItemTextWithCFString( menu, CFSTR("Library"), kMenuItemAttrDisabled, 0, &item ); SetMenuItemHierarchicalID( menu, item, 201 ); AppendMenuItemTextWithCFString( menu, NULL, kMenuItemAttrSeparator, 0, NULL ); AppendMenuItemTextWithCFString( menu, CFSTR("Save"), 0, 0, &item ); SetItemCmd( menu, item, 'S' ); AppendMenuItemTextWithCFString( menu, CFSTR("Save As..."), 0, 0, &item ); SetItemCmd( menu, item, 'S' ); SetMenuItemModifiers( menu, item, kMenuShiftModifier ); AppendMenuItemTextWithCFString( menu, CFSTR("Save Text As..."), 0, 0, &item ); SetItemCmd( menu, item, 'S' ); SetMenuItemModifiers( menu, item, kMenuOptionModifier ); AppendMenuItemTextWithCFString( menu, CFSTR("Save Selected Text As..."), 0, 0, &item ); SetItemCmd( menu, item, 'S' ); SetMenuItemModifiers( menu, item, kMenuShiftModifier | kMenuOptionModifier ); AppendMenuItemTextWithCFString( menu, NULL, kMenuItemAttrSeparator, 0, NULL ); AppendMenuItemTextWithCFString( menu, CFSTR("Run Command..."), 0, 0, &item ); SetItemCmd( menu, item, 'N' ); SetMenuItemModifiers( menu, item, kMenuShiftModifier ); AppendMenuItemTextWithCFString( menu, CFSTR("Set Title..."), 0, 0, &item ); SetItemCmd( menu, item, 'T' ); SetMenuItemModifiers( menu, item, kMenuShiftModifier ); AppendMenuItemTextWithCFString( menu, CFSTR("Inspector..."), 0, 0, &item ); SetItemCmd( menu, item, 'I' ); AppendMenuItemTextWithCFString( menu, NULL, kMenuItemAttrSeparator, 0, NULL ); AppendMenuItemTextWithCFString( menu, CFSTR("Page Setup..."), 0, 0, &item ); SetItemCmd( menu, item, 'P' ); SetMenuItemModifiers( menu, item, kMenuShiftModifier ); AppendMenuItemTextWithCFString( menu, CFSTR("Print..."), 0, 0, &item ); SetItemCmd( menu, item, 'P' ); }
extern pascal OSStatus InsertSystemSubMenu(MenuRef rootMenu, MenuRef parentMenu, UInt16 itemInParent, MenuRef childMenu) // See comment in interface part. { long oldA4; OSStatus err; SubSysMenuEntry newEntry; SInt16 newIDForChildMenu; oldA4 = SetUpA4(); assert(ValidateSystemMenuRef(rootMenu )); assert(ValidateSystemMenuRef(parentMenu)); assert(ValidateSystemMenuRef(childMenu )); assert(gMenuSelectState = kMenuSelectStatePre); // Validate parameters err = noErr; if ((rootMenu == NULL) || (parentMenu == NULL) || (childMenu == NULL)) { err = paramErr; } if (err == noErr && ((itemInParent == 0) || (itemInParent > CountMenuItems(parentMenu)))) { err = paramErr; } // Make sure rootMenu references a current system menu. // If it does, record the index of the root menu for // later use by HandleMenuSelect. Also fill out the rest // of the fields of the sub-menu entry. if (err == noErr) { newEntry.rootMenuIndex = FindRootMenuByRef(rootMenu); newEntry.parentMenu = parentMenu; newEntry.itemInParent = itemInParent; newEntry.childMenu = childMenu; if (newEntry.rootMenuIndex == kRootMenuNotFound) { err = paramErr; } } // Add newEntry to the sub-menu list, creating the sub-menu list if necessary. if (err == noErr) { if (gSubSysMenus == NULL) { gSubSysMenus = (SubSysMenuHandle) NewHandleSys(0); err = MemError(); } } if (err == noErr) { err = PtrAndHand(&newEntry, (Handle) gSubSysMenus, sizeof(newEntry)); } // Finally, insert the menu with a unique ID into the menu bar, // and set the parent item to reference its ID. if (err == noErr) { newIDForChildMenu = FindUniqueSubMenuID(); (**childMenu).menuID = newIDForChildMenu; InsertMenu(childMenu, hierMenu); SetItemCmd(parentMenu, itemInParent, hMenuCmd); SetItemMark(parentMenu, itemInParent, newIDForChildMenu); // I added this after testing revealed that adding a sub-menu didn't // force the menu size to be recalculated, so the item text of the // hierarchical item in the sub-menu was being truncated. This // only appears to happen on Mac OS 8.5, but the fix is sufficiently // benign to be employed on all systems. CalcMenuSize(parentMenu); } (void) SetA4(oldA4); return err; }