EXPORT(sqInt) primitiveGetMenuItemCommandID(void) { MenuCommand outCommandID; MenuHandle menuHandle; sqInt menuHandleOop; sqInt anInteger; sqInt _return_value; menuHandleOop = interpreterProxy->stackValue(1); anInteger = interpreterProxy->stackIntegerValue(0); if (interpreterProxy->failed()) { return null; } outCommandID = 0; menuHandle = ((MenuHandle) (interpreterProxy->positive64BitValueOf(menuHandleOop))); if (!(ioCheckMenuHandle(menuHandle))) { _return_value = interpreterProxy->success(0); if (interpreterProxy->failed()) { return null; } interpreterProxy->popthenPush(3, _return_value); return null; } GetMenuItemCommandID(menuHandle,anInteger,&outCommandID); _return_value = interpreterProxy->positive64BitIntegerFor(outCommandID); if (interpreterProxy->failed()) { return null; } interpreterProxy->popthenPush(3, _return_value); return null; }
virtual void PopUp( wxWindow *WXUNUSED(win), int x, int y ) { long menuResult = ::PopUpMenuSelect(m_osxMenu, y, x, 0) ; if ( HiWord(menuResult) != 0 ) { MenuCommand macid; GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid ); int id = wxMacCommandToId( macid ); wxMenuItem* item = NULL ; wxMenu* realmenu ; item = m_peer->FindItem( id, &realmenu ) ; if ( item ) { m_peer->HandleCommandProcess(item, NULL ); } } }
// -------------------------------------------------------------------------------------- static Boolean dialogFilter(EventRecord *event, DialogRef *theDialog, DialogItemIndex *itemHit) { /* See the comments for HandleKeyDown in PrefsWindow.c about why we're using virtual key codes instead of character codes. */ Boolean eventHandled = false; char charCode, keyCode; switch (event->what) { case keyDown: // handle key presses not handled by DialogSelect case autoKey: *theDialog = GetDialogFromWindow(FrontNonFloatingWindow()); SetPortDialogPort(*theDialog); charCode = event->message & charCodeMask; keyCode = (event->message & keyCodeMask) >> 8; if ((event->modifiers & cmdKey) != 0) // check to see if any menu commands { // were selected - this isn't necessarily handling the event UInt32 menuChoice; OSErr error; MenuCommand commandID; menuChoice = MenuEvent(event); error = GetMenuItemCommandID(GetMenuRef(HiWord(menuChoice)), LoWord(menuChoice), &commandID); if (error == noErr) { if (commandID == 0) // if the menu item chosen does not have a commandID = (MenuCommand)menuChoice; // command ID HandleMenuChoice(commandID); // (but they all should) } } if ( (keyCode == kEnterKeyCode) || (keyCode == kReturnKeyCode) || (keyCode == kEscapeKeyCode) || ( ((event->modifiers & cmdKey) != 0) && (charCode == '.') ) ) { ControlRef button; unsigned long finalTicks; if ( (keyCode == kEnterKeyCode) || (keyCode == kReturnKeyCode) ) { GetDialogItemAsControl(*theDialog, kStdOkItemIndex, &button); *itemHit = kStdOkItemIndex; } else { GetDialogItemAsControl(*theDialog, kStdCancelItemIndex, &button); *itemHit = kStdCancelItemIndex; } HiliteControl(button, kControlButtonPart); Delay(8, &finalTicks); HiliteControl(button, kControlNoPart); eventHandled = true; } } return eventHandled; }
// -------------------------------------------------------------------------------------- static void handleEvents(EventRecord *event) { WindowRef window; Boolean activate; WindowPartCode partCode; OSErr error; Rect tempRect, newSize; long menuChoice; MenuCommand commandID; RgnHandle grayRegion; switch (event->what) // handle events according to the priority { // determined by the system case activateEvt: window = (WindowRef)event->message; activate = (event->modifiers & activeFlag) != 0; HandleActivate(window, activate); break; case mouseDown: partCode = FindWindow(event->where, &window); switch(partCode) { case inMenuBar: menuChoice = MenuSelect(event->where); error = GetMenuItemCommandID(GetMenuRef(HiWord(menuChoice)), LoWord(menuChoice), &commandID); if (error == noErr) { if (commandID == 0) // if the menu item clicked on does not have commandID = (MenuCommand)menuChoice; // a command ID HandleMenuChoice(commandID); } break; case inSysWindow: if (window != NULL) SystemClick(event, window); break; case inContent: // the following window part codes will only be returned if (window != FrontWindow()) // for the preferences window SelectWindow(window); else HandleContentClick(window, event->where, event->modifiers); break; case inDrag: grayRegion = GetGrayRgn(); DragWindow(window, event->where, &((*grayRegion)->rgnBBox)); break; case inGrow: SetRect(&tempRect, kPrefsWindowPlatinumWidth, kPrefsWindowPlatinumHeight, SHRT_MAX, SHRT_MAX); ResizeWindow(window, event->where, &tempRect, &newSize); AdjustControls(window); break; case inGoAway: ClosePrefsWindow(window); break; } break; case keyDown: case autoKey: // a separate auto key handler would go after disk events if ((event->modifiers & cmdKey) != 0) { UInt32 keyMenuChoice; keyMenuChoice = MenuEvent(event); error = GetMenuItemCommandID(GetMenuRef(HiWord(keyMenuChoice)), LoWord(keyMenuChoice), &commandID); if (error == noErr) { if (commandID == 0) // if the menu item chosen does not have a commandID = (MenuCommand)keyMenuChoice; // command ID HandleMenuChoice(commandID); // (but they all should) } } else { window = FrontNonFloatingWindow(); if (window != NULL) { char keyCode = (event->message & keyCodeMask) >> 8; HandleKeyDown(keyCode, window); } } break; case diskEvt: if (HiWord(event->message) != noErr) { Point where; SetPt(&where, 70, 50); ShowCursor(); DIBadMount(where, event->message); } break; case updateEvt: window = (WindowRef)event->message; SetPortWindowPort(window); BeginUpdate(window); HandleDrawContent(window); EndUpdate(window); break; case kHighLevelEvent: // an OS Event handler would go before high level events AEProcessAppleEvent(event); break; }