X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aa3e374197e99d6362468dd821935050e5074065..8a31648287be0ef976f133de2786b137f1e98340:/src/osx/menu_osx.cpp?ds=inline diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index 54b2d6aa91..ee18135ab7 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -43,7 +43,7 @@ wxMenuImpl::~wxMenuImpl() { } -// the (popup) menu title has this special id +// the (popup) menu title has this special menuid static const int idMenuTitle = -3; // ============================================================================ @@ -111,7 +111,7 @@ void wxMenu::SetNoEventsMode( bool noEvents ) bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) { wxASSERT_MSG( pItem != NULL, wxT("can't append NULL item to the menu") ); - m_peer->InsertOrAppend( pItem, pos ); + GetPeer()->InsertOrAppend( pItem, pos ); if ( pItem->IsSeparator() ) { @@ -210,6 +210,17 @@ wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item) wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) { + if ( m_startRadioGroup != -1 ) + { + // Check if we're removing the item starting the radio group + if ( GetMenuItems().Item(m_startRadioGroup)->GetData() == item ) + { + // Yes, we do, so reset its index as the next item added shouldn't + // count as part of the same radio group anyhow. + m_startRadioGroup = -1; + } + } + /* // we need to find the items position in the child list size_t pos; @@ -228,7 +239,7 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) wxOSXMenuRemoveItem(m_hMenu , pos ); */ - m_peer->Remove( item ); + GetPeer()->Remove( item ); // and from internal data structures return wxMenuBase::DoRemove(item); } @@ -236,7 +247,7 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) void wxMenu::SetTitle(const wxString& label) { m_title = label ; - m_peer->SetTitle( wxStripMenuCodes( label ) ); + GetPeer()->SetTitle( wxStripMenuCodes( label ) ); } bool wxMenu::ProcessCommand(wxCommandEvent & event) @@ -337,8 +348,8 @@ void wxMenu::DoRearrange() bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow ) { - int id = item ? item->GetId() : 0; - wxUpdateUIEvent event(id); + int menuid = item ? item->GetId() : 0; + wxUpdateUIEvent event(menuid); event.SetEventObject( this ); bool processed = false; @@ -368,11 +379,11 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow { // if anything changed, update the changed attribute if (event.GetSetText()) - SetLabel(id, event.GetText()); + SetLabel(menuid, event.GetText()); if (event.GetSetChecked()) - Check(id, event.GetChecked()); + Check(menuid, event.GetChecked()); if (event.GetSetEnabled()) - Enable(id, event.GetEnabled()); + Enable(menuid, event.GetEnabled()); } else { @@ -381,11 +392,11 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow // always reset them ourselves UInt32 cmd = 0; - if ( id == wxApp::s_macExitMenuItemId ) + if ( menuid == wxApp::s_macExitMenuItemId ) { cmd = kHICommandQuit; } - else if (id == wxApp::s_macPreferencesMenuItemId ) + else if (menuid == wxApp::s_macPreferencesMenuItemId ) { cmd = kHICommandPreferences; } @@ -406,18 +417,18 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow bool wxMenu::HandleCommandProcess( wxMenuItem* item, wxWindow* senderWindow ) { - int id = item ? item->GetId() : 0; + int menuid = item ? item->GetId() : 0; bool processed = false; if (item->IsCheckable()) item->Check( !item->IsChecked() ) ; - if ( SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ) + if ( SendEvent( menuid , item->IsCheckable() ? item->IsChecked() : -1 ) ) processed = true ; else { if ( senderWindow != NULL ) { - wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , id); + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , menuid); event.SetEventObject(senderWindow); event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); @@ -436,8 +447,8 @@ bool wxMenu::HandleCommandProcess( wxMenuItem* item, wxWindow* senderWindow ) void wxMenu::HandleMenuItemHighlighted( wxMenuItem* item ) { - int id = item ? item->GetId() : 0; - wxMenuEvent wxevent(wxEVT_MENU_HIGHLIGHT, id, this); + int menuid = item ? item->GetId() : 0; + wxMenuEvent wxevent(wxEVT_MENU_HIGHLIGHT, menuid, this); DoHandleMenuEvent( wxevent ); } @@ -497,6 +508,8 @@ wxMenuBar* wxMenuBar::s_macCommonMenuBar = NULL ; bool wxMenuBar::s_macAutoWindowMenu = true ; WXHMENU wxMenuBar::s_macWindowMenuHandle = NULL ; +const int firstMenuPos = 1; // to account for the 0th application menu on mac + void wxMenuBar::Init() { m_eventHandler = this; @@ -598,13 +611,13 @@ void wxMenuBar::MacInstallMenuBar() // hide items in the apple menu that don't exist in the wx menubar - int id = 0; + int menuid = 0; wxMenuItem* appleItem = NULL; wxMenuItem* wxItem = NULL; - id = wxApp::s_macAboutMenuItemId; - appleItem = m_appleMenu->FindItem(id); - wxItem = FindItem(id); + menuid = wxApp::s_macAboutMenuItemId; + appleItem = m_appleMenu->FindItem(menuid); + wxItem = FindItem(menuid); if ( appleItem != NULL ) { if ( wxItem == NULL ) @@ -613,9 +626,9 @@ void wxMenuBar::MacInstallMenuBar() appleItem->SetItemLabel(wxItem->GetItemLabel()); } - id = wxApp::s_macPreferencesMenuItemId; - appleItem = m_appleMenu->FindItem(id); - wxItem = FindItem(id); + menuid = wxApp::s_macPreferencesMenuItemId; + appleItem = m_appleMenu->FindItem(menuid); + wxItem = FindItem(menuid); if ( appleItem != NULL ) { if ( wxItem == NULL ) @@ -627,26 +640,6 @@ void wxMenuBar::MacInstallMenuBar() #if 0 - MenuBarHandle menubar = NULL ; - - menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ; - - ::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 - InsertMenuItemTextWithCFString( appleMenu, - CFSTR(""), 0, kMenuItemAttrSeparator, 0); - InsertMenuItemTextWithCFString( appleMenu, - CFSTR("About..."), 0, 0, 0); - MacInsertMenu( appleMenu , 0 ) ; - // if we have a mac help menu, clean it up before adding new items MenuHandle helpMenuHandle ; MenuItemIndex firstUserHelpMenuItem ; @@ -826,7 +819,7 @@ void wxMenuBar::EnableTop(size_t pos, bool enable) { wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") ); - m_rootMenu->FindItemByPosition( pos )->Enable(enable); + m_rootMenu->FindItemByPosition(pos+firstMenuPos)->Enable(enable); Refresh(); } @@ -861,8 +854,6 @@ wxString wxMenuBar::GetMenuLabel(size_t pos) const // wxMenuBar construction // --------------------------------------------------------------------------- -const int firstMenuPos = 1; // to account for the 0th application menu on mac - wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) { wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title);