EXPORT(sqInt) primitiveGetIndMenuWithCommandID(void) { MenuCommand commandID; MenuHandle menuHandle; MenuItemIndex outIndex; MenuHandle applicationMenu; sqInt menuHandleOop; sqInt aCommandID; sqInt _return_value; menuHandleOop = interpreterProxy->stackValue(1); aCommandID = interpreterProxy->stackValue(0); if (interpreterProxy->failed()) { return null; } menuHandle = ((MenuHandle) (interpreterProxy->positive64BitValueOf(menuHandleOop))); commandID = ((MenuCommand) (interpreterProxy->positive64BitValueOf(aCommandID))); if (!(ioCheckMenuHandle(menuHandle))) { _return_value = interpreterProxy->success(0); if (interpreterProxy->failed()) { return null; } interpreterProxy->popthenPush(3, _return_value); return null; } #if TARGET_API_MAC_CARBON GetIndMenuItemWithCommandID(menuHandle, kHICommandHide, 1, &applicationMenu, &outIndex); #endif ; _return_value = interpreterProxy->positive64BitIntegerFor(((long) applicationMenu)); if (interpreterProxy->failed()) { return null; } interpreterProxy->popthenPush(3, _return_value); return null; }
S32 PopupMenu::insertSubMenu(S32 pos, const char *title, PopupMenu *submenu) { for(S32 i = 0;i < mSubmenus->size();i++) { if(submenu == (*mSubmenus)[i]) { Con::errorf("PopupMenu::insertSubMenu - Attempting to add submenu twice"); return -1; } } CFStringRef cftitle = CFStringCreateWithCString(NULL,title,kCFStringEncodingUTF8); InsertMenuItemTextWithCFString(mData->mMenu, cftitle, pos, 0, kHICommandTorque + 1); CFRelease( cftitle ); // ensure that we have the correct index for the new menu item MenuRef outref; MenuItemIndex item; GetIndMenuItemWithCommandID(mData->mMenu, kHICommandTorque+1, 1, &outref, &item); SetMenuItemCommandID(mData->mMenu, item, 0); S32 tag = PlatformPopupMenuData::getTag(); SetMenuItemRefCon( mData->mMenu, item, tag); // store a pointer to the PopupMenu this item represents. See PopupMenu::removeItem() SetMenuItemProperty(mData->mMenu, item, 'GG2d', 'subm', sizeof(PopupMenu*), submenu); SetMenuItemHierarchicalMenu( mData->mMenu, item, submenu->mData->mMenu); mSubmenus->addObject(submenu); return tag; }
bool AquaGui::createMenu() { MenuRef rApplicationMenu; MenuItemIndex outIndex[1]; /* Enable 'Prefereces...' */ EnableMenuCommand(NULL, kHICommandPreferences); GetIndMenuItemWithCommandID(NULL, kHICommandPreferences, 1, &rApplicationMenu, outIndex); /* Enable 'About' */ InsertMenuItemTextWithCFString(rApplicationMenu, CFSTR("About gnash"), (short) 0, 0, kHICommandAbout); return true; }
void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter) { wxMenuItemList::compatibility_iterator node; wxMenuItem *item; wxMenu *subMenu = NULL ; bool newItems = false; for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; if (subMenu) { wxInsertMenuItemsInMenu(subMenu, (MenuRef)subMenu->GetHMenu(), 0); } if ( item->IsSeparator() ) { if ( wm && newItems) InsertMenuItemTextWithCFString( wm, CFSTR(""), insertAfter, kMenuItemAttrSeparator, 0); newItems = false; } else { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; MenuItemIndex winListPos = (MenuItemIndex)-1; OSStatus err = GetIndMenuItemWithCommandID(wm, wxIdToMacCommand ( item->GetId() ), 1, NULL, &winListPos); if ( wm && err == menuItemNotFoundErr ) { // NB: the only way to determine whether or not we should add // a separator is to know if we've added menu items to the menu // before the separator. newItems = true; UMAInsertMenuItem(wm, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), insertAfter, entry); SetMenuItemCommandID( wm , insertAfter+1 , wxIdToMacCommand ( item->GetId() ) ) ; SetMenuItemRefCon( wm , insertAfter+1 , (URefCon) item ) ; } delete entry ; } } }
void ige_mac_menu_set_quit_menu_item (GtkMenuItem *menu_item) { MenuRef appmenu; MenuItemIndex index; g_return_if_fail (GTK_IS_MENU_ITEM (menu_item)); setup_menu_event_handler (); if (GetIndMenuItemWithCommandID (NULL, kHICommandQuit, 1, &appmenu, &index) == noErr) { SetMenuItemCommandID (appmenu, index, 0); SetMenuItemProperty (appmenu, index, IGE_QUARTZ_MENU_CREATOR, IGE_QUARTZ_ITEM_WIDGET, sizeof (menu_item), &menu_item); gtk_widget_hide (GTK_WIDGET (menu_item)); } }
S32 PopupMenu::insertItem(S32 pos, const char *title, const char* accel) { MenuItemIndex item; CFStringRef cftitle; MenuItemAttributes attr = 0; bool needRelease = false; if(title && *title) { cftitle = CFStringCreateWithCString(NULL,title,kCFStringEncodingUTF8); needRelease = true; } else { cftitle = CFSTR("-"); attr = kMenuItemAttrSeparator; } InsertMenuItemTextWithCFString(mData->mMenu, cftitle, pos, attr, kHICommandTorque + 1); if( needRelease ) CFRelease( cftitle ); // ensure that we have the correct index for the new menu item MenuRef outref; GetIndMenuItemWithCommandID(mData->mMenu, kHICommandTorque+1, 1, &outref, &item); SetMenuItemCommandID(mData->mMenu, item, kHICommandTorque); // save a ref to the PopupMenu that owns this item. PopupMenu* thisMenu = this; SetMenuItemProperty(mData->mMenu, item, 'GG2d', 'ownr', sizeof(PopupMenu*), &thisMenu); // construct the accelerator keys _assignCommandKeys(accel, mData->mMenu, item); S32 tag = PlatformPopupMenuData::getTag(); SetMenuItemRefCon(mData->mMenu, item, tag); return tag; }
void wxMenuBar::MacInstallMenuBar() { if ( s_macInstalledMenuBar == this ) return ; m_rootMenu->GetPeer()->MakeRoot(); // hide items in the apple menu that don't exist in the wx menubar int menuid = 0; wxMenuItem* appleItem = NULL; wxMenuItem* wxItem = NULL; menuid = wxApp::s_macAboutMenuItemId; appleItem = m_appleMenu->FindItem(menuid); wxItem = FindItem(menuid); if ( appleItem != NULL ) { if ( wxItem == NULL ) appleItem->GetPeer()->Hide(); else appleItem->SetItemLabel(wxItem->GetItemLabel()); } menuid = wxApp::s_macPreferencesMenuItemId; appleItem = m_appleMenu->FindItem(menuid); wxItem = FindItem(menuid); if ( appleItem != NULL ) { if ( wxItem == NULL ) appleItem->GetPeer()->Hide(); else appleItem->SetItemLabel(wxItem->GetItemLabel()); } #if 0 // if we have a mac help menu, clean it up before adding new items MenuHandle helpMenuHandle ; MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenuDontCreate( &helpMenuHandle , &firstUserHelpMenuItem) == noErr ) { for ( int i = CountMenuItems( helpMenuHandle ) ; i >= firstUserHelpMenuItem ; --i ) DeleteMenuItem( helpMenuHandle , i ) ; } else { helpMenuHandle = NULL ; } if ( wxApp::s_macPreferencesMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ; if ( item == NULL || !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandPreferences ) ; else EnableMenuCommand( NULL , kHICommandPreferences ) ; } // Unlike preferences which may or may not exist, the Quit item should be always // enabled unless it is added by the application and then disabled, otherwise // a program would be required to add an item with wxID_EXIT in order to get the // Quit menu item to be enabled, which seems a bit burdensome. if ( wxApp::s_macExitMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macExitMenuItemId , NULL ) ; if ( item != NULL && !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandQuit ) ; else EnableMenuCommand( NULL , kHICommandQuit ) ; } wxString strippedHelpMenuTitle = wxStripMenuCodes( wxApp::s_macHelpMenuTitleName ) ; wxString strippedTranslatedHelpMenuTitle = wxStripMenuCodes( wxString( _("&Help") ) ) ; wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst(); for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext()) { wxMenuItemList::compatibility_iterator node; wxMenuItem *item; wxMenu* menu = menuIter->GetData() , *subMenu = NULL ; wxString strippedMenuTitle = wxStripMenuCodes(m_titles[i]); if ( strippedMenuTitle == wxT("?") || strippedMenuTitle == strippedHelpMenuTitle || strippedMenuTitle == strippedTranslatedHelpMenuTitle ) { for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; if (subMenu) { UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding() ); MenuItemIndex position = CountMenuItems(mh); ::SetMenuItemHierarchicalMenu(mh, position, MAC_WXHMENU(subMenu->GetHMenu())); } else { if ( item->GetId() != wxApp::s_macAboutMenuItemId ) { // we have found a user help menu and an item other than the about item, // so we can create the mac help menu now, if we haven't created it yet if ( helpMenuHandle == NULL ) { if ( UMAGetHelpMenu( &helpMenuHandle , &firstUserHelpMenuItem) != noErr ) { helpMenuHandle = NULL ; break ; } } } if ( item->IsSeparator() ) { if ( helpMenuHandle ) AppendMenuItemTextWithCFString( helpMenuHandle, CFSTR(""), kMenuItemAttrSeparator, 0,NULL); } else { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { // this will be taken care of below } else { if ( helpMenuHandle ) { UMAAppendMenuItem(helpMenuHandle, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), entry); SetMenuItemCommandID( helpMenuHandle , CountMenuItems(helpMenuHandle) , wxIdToMacCommand ( item->GetId() ) ) ; SetMenuItemRefCon( helpMenuHandle , CountMenuItems(helpMenuHandle) , (URefCon) item ) ; } } delete entry ; } } } } else if ( ( m_titles[i] == wxT("Window") || m_titles[i] == wxT("&Window") ) && GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) { CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; } MenuRef wm = (MenuRef)MacGetWindowMenuHMenu(); if ( wm == NULL ) break; // get the insertion point in the standard menu MenuItemIndex winListStart; GetIndMenuItemWithCommandID(wm, kHICommandWindowListSeparator, 1, NULL, &winListStart); // add a separator so that the standard items and the custom items // aren't mixed together, but only if this is the first run OSStatus err = GetIndMenuItemWithCommandID(wm, 'WXWM', 1, NULL, NULL); if ( err == menuItemNotFoundErr ) { InsertMenuItemTextWithCFString( wm, CFSTR(""), winListStart-1, kMenuItemAttrSeparator, 'WXWM'); } wxInsertMenuItemsInMenu(menu, wm, winListStart); } else { UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], GetFont().GetEncoding() ) ; menu->MacBeforeDisplay(false) ; ::InsertMenu(MAC_WXHMENU(GetMenu(i)->GetHMenu()), 0); } } // take care of the about menu item wherever it is { wxMenu* aboutMenu ; wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; if ( aboutMenuItem ) { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( aboutMenuItem->GetItemLabel() ) ; UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetItemLabel() ) , wxFont::GetDefaultEncoding() ); UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; delete entry; } } if ( GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ; } ::DrawMenuBar() ; #endif s_macInstalledMenuBar = this; }
//----------------------------------------------------------------------------- // wxDockEventHandler // // This is the global Mac/Carbon event handler for the dock. // We need this for two reasons: // 1) To handle wxTaskBarIcon menu events (see below for why) // 2) To handle events from the dock when it requests a menu //----------------------------------------------------------------------------- pascal OSStatus wxDockEventHandler(EventHandlerCallRef WXUNUSED(inHandlerCallRef), EventRef inEvent, void *pData) { // Get the parameters we want from the event wxDockTaskBarIcon* pTB = (wxDockTaskBarIcon*) pData; const UInt32 eventClass = GetEventClass(inEvent); const UInt32 eventKind = GetEventKind(inEvent); OSStatus err = eventNotHandledErr; // Handle wxTaskBar menu events (note that this is a global event handler // so it will actually get called by all commands/menus) if ((eventClass == kEventClassCommand) && (eventKind == kEventCommandProcess || eventKind == kEventCommandUpdateStatus )) { // if we have no taskbar menu quickly pass it back to wxApp if (pTB->m_pMenu != NULL) { // This is the real reason why we need this. Normally menus // get handled in wxMacAppEventHandler // However, in the case of a taskbar menu call // command.menu.menuRef IS NULL! // Which causes the wxApp handler just to skip it. // get the HICommand from the event HICommand command; if (GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL,sizeof(HICommand), NULL, &command ) == noErr) { // Obtain the REAL menuRef and the menuItemIndex in the real menuRef // // NOTE: menuRef is generally used here for submenus, as // GetMenuItemRefCon could give an incorrect wxMenuItem if we pass // just the top level wxTaskBar menu MenuItemIndex menuItemIndex; MenuRef menuRef; MenuRef taskbarMenuRef = MAC_WXHMENU(pTB->m_pMenu->GetHMenu()); // the next command is only successful if it was a command from the taskbar menu // otherwise we pass it on if (GetIndMenuItemWithCommandID(taskbarMenuRef,command.commandID, 1, &menuRef, &menuItemIndex ) == noErr) { wxMenu* itemMenu = wxFindMenuFromMacMenu( menuRef ) ; int id = wxMacCommandToId( command.commandID ) ; wxMenuItem *item = NULL; if (id != 0) // get the wxMenuItem reference from the MenuRef GetMenuItemRefCon( menuRef, menuItemIndex, (URefCon*) &item ); if (item && itemMenu ) { if ( eventKind == kEventCommandProcess ) { if ( itemMenu->HandleCommandProcess( item ) ) err = noErr; } else if ( eventKind == kEventCommandUpdateStatus ) { if ( itemMenu->HandleCommandUpdateStatus( item ) ) err = noErr; } } } } } //end if noErr on getting HICommand from event } else if ((eventClass == kEventClassApplication) && (eventKind == kEventAppGetDockTileMenu )) { // process the right click events // NB: This may result in double or even triple-creation of the menus // We need to do this for 2.4 compat, however wxTaskBarIconEvent downevt(wxEVT_TASKBAR_RIGHT_DOWN, NULL); pTB->m_parent->ProcessEvent(downevt); wxTaskBarIconEvent upevt(wxEVT_TASKBAR_RIGHT_UP, NULL); pTB->m_parent->ProcessEvent(upevt); // create popup menu wxMenu* menu = pTB->DoCreatePopupMenu(); if (menu != NULL) { // note to self - a MenuRef *is* a MenuHandle MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu()); // When SetEventParameter is called it will decrement // the reference count of the menu - we need to make // sure it stays around in the wxMenu class here CFRetain(hMenu); // set the actual dock menu err = SetEventParameter( inEvent, kEventParamMenuRef, typeMenuRef, sizeof(MenuRef), &hMenu ); verify_noerr( err ); } } return err; }
void ige_mac_menu_add_app_menu_item (IgeMacMenuGroup *group, GtkMenuItem *menu_item, const gchar *label) { MenuRef appmenu; GList *list; gint index = 0; g_return_if_fail (group != NULL); g_return_if_fail (GTK_IS_MENU_ITEM (menu_item)); setup_menu_event_handler (); if (GetIndMenuItemWithCommandID (NULL, kHICommandHide, 1, &appmenu, NULL) != noErr) { g_warning ("%s: retrieving app menu failed", G_STRFUNC); return; } for (list = app_menu_groups; list; list = g_list_next (list)) { IgeMacMenuGroup *list_group = list->data; index += g_list_length (list_group->items); /* adjust index for the separator between groups, but not * before the first group */ if (list_group->items && list->prev) index++; if (group == list_group) { CFStringRef cfstr; /* add a separator before adding the first item, but not * for the first group */ if (!group->items && list->prev) { InsertMenuItemTextWithCFString (appmenu, NULL, index, kMenuItemAttrSeparator, 0); index++; } if (!label) label = get_menu_label_text (GTK_WIDGET (menu_item), NULL); cfstr = CFStringCreateWithCString (NULL, label, kCFStringEncodingUTF8); InsertMenuItemTextWithCFString (appmenu, cfstr, index, 0, 0); SetMenuItemProperty (appmenu, index + 1, IGE_QUARTZ_MENU_CREATOR, IGE_QUARTZ_ITEM_WIDGET, sizeof (menu_item), &menu_item); CFRelease (cfstr); gtk_widget_hide (GTK_WIDGET (menu_item)); group->items = g_list_append (group->items, menu_item); return; } } if (!list) g_warning ("%s: app menu group %p does not exist", G_STRFUNC, group); }
pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void* pData) { wxTaskBarIcon*& pTB = (wxTaskBarIcon*&) pData; const UInt32 eventClass = GetEventClass(inEvent); const UInt32 eventKind = GetEventKind(inEvent); if (eventClass == kEventClassCommand && eventKind == kEventCommandProcess) { //TODO: This is a complete copy of //static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) if (! pTB->GetCurrentMenu() ) { return eventNotHandledErr; } MenuRef hMenu = MAC_WXHMENU(pTB->GetCurrentMenu()->GetHMenu()); OSStatus result = eventNotHandledErr ; HICommand command ; OSErr err; err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command); wxASSERT(err == noErr); MenuItemIndex menuItemIndex; err = GetIndMenuItemWithCommandID(hMenu, command.commandID, 1, NULL, &menuItemIndex); wxASSERT(err == noErr); MenuCommand id = command.commandID ; wxMenuItem* item = NULL; // for items we don't really control if ( id == kHICommandPreferences ) { id = wxApp::s_macPreferencesMenuItemId ; wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; if ( mbar ) { wxMenu* menu = NULL ; item = mbar->FindItem( id , &menu ) ; } } else if (id != 0) GetMenuItemRefCon( hMenu , menuItemIndex , (UInt32*) &item ) ; if ( item ) { if (item->IsCheckable()) { item->Check( !item->IsChecked() ) ; } item->GetMenu()->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; result = noErr ; } return result ; } wxASSERT(eventClass == kEventClassApplication && eventKind == kEventAppGetDockTileMenu); //process the right click events wxTaskBarIconEvent downevt(wxEVT_TASKBAR_RIGHT_DOWN,NULL); pTB->ProcessEvent(downevt); wxTaskBarIconEvent upevt(wxEVT_TASKBAR_RIGHT_UP,NULL); pTB->ProcessEvent(upevt); //create popup menu wxMenu* menu = pTB->DoCreatePopupMenu(); OSStatus err = noErr; if(menu) { //note to self - a MenuRef IS A MenuHandle MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu()); //When we call SetEventParameter it will decrement //the reference count of the menu - we need to make //sure it stays around in the wxMenu class here RetainMenu(hMenu); //set the actual dock menu err = SetEventParameter((EventRef) inEvent, kEventParamMenuRef, typeMenuRef, sizeof(MenuRef), &hMenu); wxASSERT(err == 0); return err; } else return eventNotHandledErr; }
//----------------------------------------------------------------------------- // wxDockEventHandler // // This is the global Mac/Carbon event handler for the dock. // We need this for two reasons: // 1) To handle wxTaskBarIcon menu events (see below for why) // 2) To handle events from the dock when it requests a menu //----------------------------------------------------------------------------- pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *pData ) { // Get the parameters we want from the event wxDockTaskBarIcon* pTB = (wxDockTaskBarIcon*) pData; const UInt32 eventClass = GetEventClass(inEvent); const UInt32 eventKind = GetEventKind(inEvent); // Handle wxTaskBar menu events (note that this is a global event handler // so it will actually get called by all commands/menus) if ((eventClass == kEventClassCommand) && (eventKind == kEventCommandProcess)) { // if we have no taskbar menu quickly pass it back to wxApp if (pTB->m_pMenu == NULL) return eventNotHandledErr; // This is the real reason why we need this. Normally menus // get handled in wxMacAppEventHandler // // pascal OSStatus wxMacAppEventHandler(EventHandlerCallRef handler, // EventRef event, void *data) // // However, in the case of a taskbar menu call // command.menu.menuRef IS NULL! // Which causes the wxApp handler just to skip it. MenuRef taskbarMenuRef = MAC_WXHMENU(pTB->m_pMenu->GetHMenu()); OSStatus err; // get the HICommand from the event HICommand command; err = GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command ); if (err == noErr) { // Obtain the REAL menuRef and the menuItemIndex in the real menuRef // // NOTE: menuRef is generally used here for submenus, as // GetMenuItemRefCon could give an incorrect wxMenuItem if we pass // just the top level wxTaskBar menu MenuItemIndex menuItemIndex; MenuRef menuRef; err = GetIndMenuItemWithCommandID( taskbarMenuRef, command.commandID, 1, &menuRef, &menuItemIndex ); if (err == noErr) { MenuCommand id = command.commandID; wxMenuItem *item = NULL; if (id != 0) // get the wxMenuItem reference from the MenuRef GetMenuItemRefCon( menuRef, menuItemIndex, (URefCon*) &item ); if (item) { // Handle items that are checkable // FIXME: Doesn't work (at least on 10.2)! if (item->IsCheckable()) item->Check( !item->IsChecked() ); // send the wxEvent to the wxMenu item->GetMenu()->SendEvent( id, item->IsCheckable() ? item->IsChecked() : -1 ); // successfully handled the event err = noErr; } } } //end if noErr on getting HICommand from event // return whether we handled the event or not return err; } // We better have a kEventClassApplication/kEventAppGetDockTileMenu combo here, // otherwise something is truly funky wxASSERT(eventClass == kEventClassApplication && eventKind == kEventAppGetDockTileMenu); // process the right click events // NB: This may result in double or even triple-creation of the menus // We need to do this for 2.4 compat, however wxTaskBarIconEvent downevt(wxEVT_TASKBAR_RIGHT_DOWN, NULL); pTB->m_parent->ProcessEvent(downevt); wxTaskBarIconEvent upevt(wxEVT_TASKBAR_RIGHT_UP, NULL); pTB->m_parent->ProcessEvent(upevt); // create popup menu wxMenu* menu = pTB->DoCreatePopupMenu(); OSStatus err = eventNotHandledErr; if (menu != NULL) { // note to self - a MenuRef *is* a MenuHandle MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu()); // When SetEventParameter is called it will decrement // the reference count of the menu - we need to make // sure it stays around in the wxMenu class here CFRetain(hMenu); // set the actual dock menu err = SetEventParameter( inEvent, kEventParamMenuRef, typeMenuRef, sizeof(MenuRef), &hMenu ); verify_noerr( err ); } return err; }
void wxMenuBar::MacInstallMenuBar() { if ( s_macInstalledMenuBar == this ) return ; MenuBarHandle menubar = NULL ; #if TARGET_API_MAC_OSX menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ; #else menubar = NewHandleClear( 12 ) ; (*menubar)[3] = 0x0a ; #endif ::SetMenuBar( menubar ) ; DisposeMenuBar( menubar ) ; MenuHandle appleMenu = NULL ; verify_noerr( CreateNewMenu( kwxMacAppleMenuId , 0 , &appleMenu ) ) ; verify_noerr( SetMenuTitleWithCFString( appleMenu , CFSTR( "\x14" ) ) ); // Add About/Preferences separator only on OS X // KH/RN: Separator is always present on 10.3 but not on 10.2 // However, the change from 10.2 to 10.3 suggests it is preferred #if TARGET_API_MAC_OSX InsertMenuItemTextWithCFString( appleMenu, CFSTR(""), 0, kMenuItemAttrSeparator, 0); #endif InsertMenuItemTextWithCFString( appleMenu, CFSTR("About..."), 0, 0, 0); MacInsertMenu( appleMenu , 0 ) ; // clean-up the help menu before adding new items static MenuHandle mh = NULL ; if ( mh != NULL ) { MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr ) { for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i ) DeleteMenuItem( mh , i ) ; } else { mh = NULL ; } } #if TARGET_CARBON if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ; if ( item == NULL || !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandPreferences ) ; else EnableMenuCommand( NULL , kHICommandPreferences ) ; } // Unlike preferences which may or may not exist, the Quit item should be always // enabled unless it is added by the application and then disabled, otherwise // a program would be required to add an item with wxID_EXIT in order to get the // Quit menu item to be enabled, which seems a bit burdensome. if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macExitMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macExitMenuItemId , NULL ) ; if ( item != NULL && !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandQuit ) ; else EnableMenuCommand( NULL , kHICommandQuit ) ; } #endif wxString strippedHelpMenuTitle = wxStripMenuCodes( wxApp::s_macHelpMenuTitleName ) ; wxString strippedTranslatedHelpMenuTitle = wxStripMenuCodes( wxString( _("&Help") ) ) ; wxString strippedWindowMenuTitle = wxStripMenuCodes( wxString(wxT("&Window")) /* wxApp::s_macWindowMenuTitleName */ ) ; wxString strippedTranslatedWindowMenuTitle = wxStripMenuCodes( wxString( _("&Window") ) ) ; wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst(); for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext()) { wxMenuItemList::compatibility_iterator node; wxMenuItem *item; wxMenu* menu = menuIter->GetData() , *subMenu = NULL ; wxString strippedMenuTitle = wxStripMenuCodes(m_titles[i]); if ( strippedMenuTitle == wxT("?") || strippedMenuTitle == strippedHelpMenuTitle || strippedMenuTitle == strippedTranslatedHelpMenuTitle ) { for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; if (subMenu) { UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding() ); MenuItemIndex position = CountMenuItems(mh); ::SetMenuItemHierarchicalMenu(mh, position, MAC_WXHMENU(subMenu->GetHMenu())); } else { if ( item->GetId() != wxApp::s_macAboutMenuItemId ) { if ( mh == NULL ) { MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr ) { mh = NULL ; break ; } } } if ( item->IsSeparator() ) { if ( mh ) AppendMenuItemTextWithCFString( mh, CFSTR(""), kMenuItemAttrSeparator, 0,NULL); } else { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetText() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { // this will be taken care of below } else { if ( mh ) { UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding(), entry); MenuItemIndex position = CountMenuItems(mh); SetMenuItemCommandID( mh , position, wxIdToMacCommand ( item->GetId() ) ); SetMenuItemRefCon( mh , position, (URefCon) item ); item->DoUpdateItemBitmap( mh, position ); } } delete entry ; } } } } else if ( (strippedMenuTitle == wxT("Window") || strippedMenuTitle == strippedWindowMenuTitle || strippedMenuTitle == strippedTranslatedWindowMenuTitle ) && GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) { CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; } MenuRef wm = (MenuRef)MacGetWindowMenuHMenu(); if ( wm == NULL ) break; // get the insertion point in the standard menu MenuItemIndex winListStart; GetIndMenuItemWithCommandID(wm, kHICommandWindowListSeparator, 1, NULL, &winListStart); // add a separator so that the standard items and the custom items // aren't mixed together, but only if this is the first run OSStatus err = GetIndMenuItemWithCommandID(wm, 'WXWM', 1, NULL, NULL); if ( err == menuItemNotFoundErr ) { InsertMenuItemTextWithCFString( wm, CFSTR(""), winListStart-1, kMenuItemAttrSeparator, 'WXWM'); } wxInsertMenuItemsInMenu(menu, wm, winListStart); } else { UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], GetFont().GetEncoding() ) ; menu->MacBeforeDisplay(false) ; ::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0); } } // take care of the about menu item wherever it is { wxMenu* aboutMenu ; wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; if ( aboutMenuItem ) { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( aboutMenuItem->GetText() ) ; UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetText() ) , wxFont::GetDefaultEncoding() ); UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; delete entry; } } if ( GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ; } ::DrawMenuBar() ; s_macInstalledMenuBar = this; }