EXPORT(sqInt) primitiveGetMenuID(void) { MenuID menuID; MenuHandle menuHandle; sqInt menuHandleOop; sqInt _return_value; menuHandleOop = interpreterProxy->stackValue(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(2, _return_value); return null; } menuID = GetMenuID(menuHandle); _return_value = interpreterProxy->integerObjectOf(menuID); if (interpreterProxy->failed()) { return null; } interpreterProxy->popthenPush(2, _return_value); return null; }
int TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) { HICommand command; int menuContext; OSStatus status; switch (eventPtr->eKind) { case kEventCommandProcess: case kEventCommandUpdateStatus: break; default: return 0; break; } status = GetEventParameter(eventPtr->eventRef, kEventParamDirectObject, typeHICommand, NULL, sizeof(command), NULL, &command); if (status == noErr && (command.attributes & kHICommandFromMenu)) { if (eventPtr->eKind == kEventCommandProcess) { status = GetEventParameter(eventPtr->eventRef, kEventParamMenuContext, typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext); if (status == noErr && (menuContext & kMenuContextMenuBar) && (menuContext & kMenuContextMenuBarTracking)) { TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef), command.menu.menuItemIndex, GetCurrentEventKeyModifiers() & optionKey); return 1; } } else { Tcl_CmdInfo dummy; if (command.commandID == kHICommandPreferences && eventPtr->interp) { if (Tcl_GetCommandInfo(eventPtr->interp, "::tk::mac::ShowPreferences", &dummy)) { if (!IsMenuItemEnabled(command.menu.menuRef, command.menu.menuItemIndex)) { EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } } else { if (IsMenuItemEnabled(command.menu.menuRef, command.menu.menuItemIndex)) { DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } } return 1; } } } return 0; }
void TkpDestroyMenuButton( TkMenuButton *mbPtr) { MacMenuButton * macMbPtr = (MacMenuButton *)mbPtr; if (macMbPtr->userPane) { DisposeControl(macMbPtr->userPane); macMbPtr->userPane = NULL; } if (macMbPtr->menuRef) { short menuID; menuID = GetMenuID(macMbPtr->menuRef); TkMacOSXFreeMenuID(menuID); DisposeMenu(macMbPtr->menuRef); macMbPtr->menuRef = NULL; } }
// -------------------------------------------------------------------------------------- OSStatus handleCommand(HICommand command) { OSStatus result = eventNotHandledErr; switch (command.commandID) { /* Note that we're not handling the Quit HI Command here. Instead we let the default handler process it which sends us a Quit Application Apple Event, which we are "required" to handle anyways. Similarly we are letting the default handler process the Close HI Command which sends a close window Carbon Event to the appropriate window. */ case kHICommandAbout: SysBeep(30); result = noErr; break; case kCommandPrWin: OpenPrefsWindow(); result = noErr; break; case kCommandPrDlg: OpenPrefsDialog(); result = noErr; break; default: // there isn't a recognized command ID; see if it's a menu item we know if ((command.attributes & kHICommandFromMenu) != 0) { MenuID menuID; menuID = GetMenuID(command.menu.menuRef); switch (menuID) { // all of our menu items have commands but if they didn't we } // would further switch on command.menu.menuItemIndex } } return result; }
static void winproc(void *a) { MenuItemIndex index; winRect.left = 30; winRect.top = 60; winRect.bottom = (devRect.size.height * 0.75) + winRect.top; winRect.right = (devRect.size.width * 0.75) + winRect.left; ClearMenuBar(); InitCursor(); CreateStandardWindowMenu(0, &windMenu); InsertMenu(windMenu, 0); CreateNewMenu(1004, 0, &viewMenu); SetMenuTitleWithCFString(viewMenu, CFSTR("View")); AppendMenuItemTextWithCFString(viewMenu, CFSTR("Toggle Full Screen"), 0, kFullScreenCmd, &index); SetMenuItemCommandKey(viewMenu, index, FALSE, 'F'); InsertMenu(viewMenu, GetMenuID(windMenu)); DrawMenuBar(); uint32_t windowAttrs = 0 | kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowResizableAttribute | kWindowStandardHandlerAttribute | kWindowFullZoomAttribute ; CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow); SetWindowTitleWithCFString(theWindow, CFSTR("Acme SAC")); if(PasteboardCreate(kPasteboardClipboard, &appleclip) != noErr) sysfatal("pasteboard create failed"); const EventTypeSpec app_events[] = { { kEventClassApplication, kEventAppQuit } }; const EventTypeSpec commands[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassCommand, kEventCommandProcess } }; const EventTypeSpec events[] = { { kEventClassTextInput, kEventTextInputUpdateActiveInputArea }, { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, { kEventClassTextInput, kEventTextInputOffsetToPos }, { kEventClassTextInput, kEventTextInputPosToOffset }, { kEventClassTextInput, kEventTextInputShowHideBottomWindow }, { kEventClassTextInput, kEventTextInputGetSelectedText }, { kEventClassTextInput, kEventTextInputUnicodeText }, { kEventClassTextInput, kEventTextInputFilterText }, { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyModifiersChanged }, { kEventClassKeyboard, kEventRawKeyRepeat }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseDragged }, { kEventClassMouse, kEventMouseWheelMoved }, }; InstallApplicationEventHandler ( NewEventHandlerUPP (ApplicationQuitEventHandler), GetEventTypeCount(app_events), app_events, NULL, NULL); InstallApplicationEventHandler ( NewEventHandlerUPP (MainWindowEventHandler), GetEventTypeCount(events), events, NULL, NULL); InstallWindowEventHandler ( theWindow, NewEventHandlerUPP (MainWindowCommandHandler), GetEventTypeCount(commands), commands, theWindow, NULL); ShowWindow(theWindow); ShowMenuBar(); window_resized(); Rectangle rect = { { 0, 0 }, { bounds.size.width, bounds.size.height } }; wmtrack(0, rect.max.x, rect.max.y, 0); SelectWindow(theWindow); // Run the event loop readybit = 1; Wakeup(&rend); RunApplicationEventLoop(); }