X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c1ec7ee8a12c3a5004859139dd031dfdd66f7292..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/osx/menu_osx.cpp diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index ea54053308..aca50de2cd 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -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) @@ -418,7 +429,7 @@ bool wxMenu::HandleCommandProcess( wxMenuItem* item, wxWindow* senderWindow ) if ( senderWindow != NULL ) { wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , menuid); - event.SetEventObject(senderWindow); + event.SetEventObject(this); event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); if ( senderWindow->HandleWindowEvent(event) ) @@ -441,16 +452,25 @@ void wxMenu::HandleMenuItemHighlighted( wxMenuItem* item ) DoHandleMenuEvent( wxevent ); } -void wxMenu::HandleMenuOpened() +void wxMenu::DoHandleMenuOpenedOrClosed(wxEventType evtType) { - wxMenuEvent wxevent(wxEVT_MENU_OPEN, 0, this); + // Popup menu being currently shown or NULL, defined in wincmn.cpp. + extern wxMenu *wxCurrentPopupMenu; + + // Set the id to allow wxMenuEvent::IsPopup() to work correctly. + int menuid = this == wxCurrentPopupMenu ? wxID_ANY : 0; + wxMenuEvent wxevent(evtType, menuid, this); DoHandleMenuEvent( wxevent ); } +void wxMenu::HandleMenuOpened() +{ + DoHandleMenuOpenedOrClosed(wxEVT_MENU_OPEN); +} + void wxMenu::HandleMenuClosed() { - wxMenuEvent wxevent(wxEVT_MENU_CLOSE, 0, this); - DoHandleMenuEvent( wxevent ); + DoHandleMenuOpenedOrClosed(wxEVT_MENU_CLOSE); } bool wxMenu::DoHandleMenuEvent(wxEvent& wxevent) @@ -497,6 +517,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; @@ -530,21 +552,17 @@ void wxMenuBar::Init() } // standard menu items, handled in wxMenu::HandleCommandProcess(), see above: - wxString hideLabel(_("Hide")); - if ( wxTheApp ) - hideLabel << ' ' << wxTheApp->GetAppDisplayName(); - hideLabel << "\tCtrl+H"; - m_appleMenu->Append( wxID_OSX_HIDE, hideLabel ); + wxString hideLabel; + hideLabel = wxString::Format(_("Hide %s"), wxTheApp ? wxTheApp->GetAppDisplayName() : _("Application")); + m_appleMenu->Append( wxID_OSX_HIDE, hideLabel + "\tCtrl+H" ); m_appleMenu->Append( wxID_OSX_HIDEOTHERS, _("Hide Others")+"\tAlt+Ctrl+H" ); m_appleMenu->Append( wxID_OSX_SHOWALL, _("Show All") ); m_appleMenu->AppendSeparator(); // Do always add "Quit" item unconditionally however, it can't be disabled. - wxString quitLabel(_("Quit")); - if ( wxTheApp ) - quitLabel << ' ' << wxTheApp->GetAppDisplayName(); - quitLabel << "\tCtrl+Q"; - m_appleMenu->Append( wxApp::s_macExitMenuItemId, quitLabel ); + wxString quitLabel; + quitLabel = wxString::Format(_("Quit %s"), wxTheApp ? wxTheApp->GetAppDisplayName() : _("Application")); + m_appleMenu->Append( wxApp::s_macExitMenuItemId, quitLabel + "\tCtrl+Q" ); #endif // !wxOSX_USE_CARBON m_rootMenu->AppendSubMenu(m_appleMenu, "\x14") ; @@ -598,11 +616,10 @@ void wxMenuBar::MacInstallMenuBar() // 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; + int menuid = wxApp::s_macAboutMenuItemId; appleItem = m_appleMenu->FindItem(menuid); wxItem = FindItem(menuid); if ( appleItem != NULL ) @@ -806,11 +823,22 @@ 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(); } +bool wxMenuBar::IsEnabledTop(size_t pos) const +{ + wxCHECK_MSG( IsAttached(), true, + wxT("doesn't work with unattached menubars") ); + + wxMenuItem* const item = m_rootMenu->FindItemByPosition(pos+firstMenuPos); + wxCHECK_MSG( item, false, wxT("invalid menu index") ); + + return item->IsEnabled(); +} + bool wxMenuBar::Enable(bool enable) { wxCHECK_MSG( IsAttached(), false, wxT("doesn't work with unattached menubars") ); @@ -841,8 +869,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);