X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/09fbcf2a62dcbafaf5b7fc9af39c560480833733..50f12a63130b81796ea531c59af97f0544cf158d:/src/osx/menu_osx.cpp?ds=sidebyside diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index ee18135ab7..cf7dcaa670 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -428,8 +428,8 @@ bool wxMenu::HandleCommandProcess( wxMenuItem* item, wxWindow* senderWindow ) { if ( senderWindow != NULL ) { - wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , menuid); - event.SetEventObject(senderWindow); + wxCommandEvent event(wxEVT_MENU , menuid); + event.SetEventObject(this); event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); if ( senderWindow->HandleWindowEvent(event) ) @@ -452,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) @@ -543,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") ; @@ -611,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 ) @@ -824,6 +828,17 @@ void wxMenuBar::EnableTop(size_t pos, bool 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") ); @@ -873,6 +888,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) return false; m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) ); + menu->SetTitle(title); return true; }