From d41e3a37399e44ff31bfb88c6a480f6b503674c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 17 Nov 2013 18:02:56 +0000 Subject: [PATCH] Don't duplicate code for Apple menu creation. Have just one copy of the code, instead of two. Eliminate differences between the two versions. As a result, applications now properly have preferences and about items even if window-less. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75229 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/menu_osx.cpp | 72 ++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index 2bf5cede9e..8aee6f1cc6 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -588,39 +588,10 @@ wxMenu* emptyMenuBar = NULL; const int firstMenuPos = 1; // to account for the 0th application menu on mac -void wxMenuBar::Init() +static wxMenu *CreateAppleMenu() { - if ( emptyMenuBar == NULL ) - { - emptyMenuBar = new wxMenu(); - - wxMenu* appleMenu = new wxMenu(); - appleMenu->SetAllowRearrange(false); -#if !wxOSX_USE_CARBON - // standard menu items, handled in wxMenu::HandleCommandProcess(), see above: - wxString hideLabel; - hideLabel = wxString::Format(_("Hide %s"), wxTheApp ? wxTheApp->GetAppDisplayName() : _("Application")); - appleMenu->Append( wxID_OSX_HIDE, hideLabel + "\tCtrl+H" ); - appleMenu->Append( wxID_OSX_HIDEOTHERS, _("Hide Others")+"\tAlt+Ctrl+H" ); - appleMenu->Append( wxID_OSX_SHOWALL, _("Show All") ); - appleMenu->AppendSeparator(); - - // Do always add "Quit" item unconditionally however, it can't be disabled. - wxString quitLabel; - quitLabel = wxString::Format(_("Quit %s"), wxTheApp ? wxTheApp->GetAppDisplayName() : _("Application")); - appleMenu->Append( wxApp::s_macExitMenuItemId, quitLabel + "\tCtrl+Q" ); -#endif // !wxOSX_USE_CARBON - - emptyMenuBar->AppendSubMenu(appleMenu, "\x14") ; - } - - m_eventHandler = this; - m_menuBarFrame = NULL; - m_rootMenu = new wxMenu(); - m_rootMenu->Attach(this); - - m_appleMenu = new wxMenu(); - m_appleMenu->SetAllowRearrange(false); + wxMenu *appleMenu = new wxMenu(); + appleMenu->SetAllowRearrange(false); // Create standard items unless the application explicitly disabled this by // setting the corresponding ids to wxID_NONE: although this is not @@ -632,32 +603,49 @@ void wxMenuBar::Init() aboutLabel << ' ' << wxTheApp->GetAppDisplayName(); else aboutLabel << "..."; - m_appleMenu->Append( wxApp::s_macAboutMenuItemId, aboutLabel); - m_appleMenu->AppendSeparator(); + appleMenu->Append( wxApp::s_macAboutMenuItemId, aboutLabel); + appleMenu->AppendSeparator(); } #if !wxOSX_USE_CARBON if ( wxApp::s_macPreferencesMenuItemId != wxID_NONE ) { - m_appleMenu->Append( wxApp::s_macPreferencesMenuItemId, - _("Preferences...") + "\tCtrl+," ); - m_appleMenu->AppendSeparator(); + appleMenu->Append( wxApp::s_macPreferencesMenuItemId, + _("Preferences...") + "\tCtrl+," ); + appleMenu->AppendSeparator(); } // standard menu items, handled in wxMenu::HandleCommandProcess(), see above: 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(); + appleMenu->Append( wxID_OSX_HIDE, hideLabel + "\tCtrl+H" ); + appleMenu->Append( wxID_OSX_HIDEOTHERS, _("Hide Others")+"\tAlt+Ctrl+H" ); + appleMenu->Append( wxID_OSX_SHOWALL, _("Show All") ); + appleMenu->AppendSeparator(); // Do always add "Quit" item unconditionally however, it can't be disabled. wxString quitLabel; quitLabel = wxString::Format(_("Quit %s"), wxTheApp ? wxTheApp->GetAppDisplayName() : _("Application")); - m_appleMenu->Append( wxApp::s_macExitMenuItemId, quitLabel + "\tCtrl+Q" ); + appleMenu->Append( wxApp::s_macExitMenuItemId, quitLabel + "\tCtrl+Q" ); #endif // !wxOSX_USE_CARBON + return appleMenu; +} + +void wxMenuBar::Init() +{ + if ( emptyMenuBar == NULL ) + { + emptyMenuBar = new wxMenu(); + emptyMenuBar->AppendSubMenu(CreateAppleMenu(), "\x14") ; + } + + m_eventHandler = this; + m_menuBarFrame = NULL; + m_rootMenu = new wxMenu(); + m_rootMenu->Attach(this); + + m_appleMenu = CreateAppleMenu(); m_rootMenu->AppendSubMenu(m_appleMenu, "\x14") ; }