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
This commit is contained in:
Václav Slavík
2013-11-17 18:02:56 +00:00
parent c6de30bf70
commit d41e3a3739

View File

@@ -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") ;
}