From c46d050368659ba3afff87b8c0127ce2e77860b5 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 30 Nov 2010 09:59:11 +0000 Subject: [PATCH] adding standard menu items for cocoa, adding translation macro to menulabels, fixes #12732 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66300 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 7 +++++++ include/wx/osx/core/private.h | 4 +++- src/osx/cocoa/menuitem.mm | 30 +++++++++++++++++++++++++++++- src/osx/menu_osx.cpp | 26 +++++++++++++++++++++++--- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index f6ca2542d2..cd23f91020 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -2117,6 +2117,13 @@ enum wxStandardID wxID_MDI_WINDOW_NEXT, wxID_MDI_WINDOW_LAST = wxID_MDI_WINDOW_NEXT, + /* OS X system menu ids */ + wxID_OSX_MENU_FIRST = 5250, + wxID_OSX_HIDE = wxID_OSX_MENU_FIRST, + wxID_OSX_HIDEOTHERS, + wxID_OSX_SHOWALL, + wxID_OSX_MENU_LAST = wxID_OSX_SHOWALL, + /* IDs used by generic file dialog (13 consecutive starting from this value) */ wxID_FILEDLGG = 5900, diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 0e0ff542ae..ba2d659c20 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -149,7 +149,9 @@ public : const wxString& strHelp, wxItemKind kind, wxMenu *pSubMenu ); - + + // handle OS specific menu items if they weren't handled during normal processing + virtual bool DoDefault() {} ; protected : wxMenuItem* m_peer; diff --git a/src/osx/cocoa/menuitem.mm b/src/osx/cocoa/menuitem.mm index 60b54eae14..c253f75672 100644 --- a/src/osx/cocoa/menuitem.mm +++ b/src/osx/cocoa/menuitem.mm @@ -35,7 +35,10 @@ wxUnusedVar(sender); if ( impl ) { - impl->GetWXPeer()->GetMenu()->HandleCommandProcess(impl->GetWXPeer()); + wxMenuItem* menuitem = impl->GetWXPeer(); + if ( menuitem->GetMenu()->HandleCommandProcess(menuitem) == false ) + { + } } } @@ -212,6 +215,8 @@ public : wxMacCocoaMenuItemSetAccelerator( m_osxMenuItem, entry ); } + + bool DoDefault(); void * GetHMenuItem() { return m_osxMenuItem; } @@ -226,6 +231,29 @@ wxMenuItemCocoaImpl::~wxMenuItemCocoaImpl() [m_osxMenuItem release]; } +bool wxMenuItemCocoaImpl::DoDefault() +{ + bool handled=false; + int menuid = m_peer->GetId(); + + NSApplication *theNSApplication = [NSApplication sharedApplication]; + if (menuid == wxID_OSX_HIDE) + { + [theNSApplication hide:nil]; + handled=true; + } + else if (menuid == wxID_OSX_HIDEOTHERS) + { + [theNSApplication hideOtherApplications:nil]; + handled=true; + } + else if (menuid == wxID_OSX_SHOWALL) + { + [theNSApplication unhideAllApplications:nil]; + handled=true; + } + return handled; +} wxMenuItemImpl* wxMenuItemImpl::Create( wxMenuItem* peer, wxMenu *pParentMenu, int WXUNUSED(id), diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index c10dba486e..9c0d904ae8 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -440,6 +440,12 @@ bool wxMenu::HandleCommandProcess( wxMenuItem* item, wxWindow* senderWindow ) processed = true ; } } + + if(!processed && item) + { + processed = item->GetPeer()->DoDefault(); + } + return processed; } @@ -521,7 +527,7 @@ void wxMenuBar::Init() // recommended, sometimes these items really don't make sense. if ( wxApp::s_macAboutMenuItemId != wxID_NONE ) { - wxString aboutLabel("About"); + wxString aboutLabel(_("About")); if ( wxTheApp ) aboutLabel << ' ' << wxTheApp->GetAppDisplayName(); else @@ -534,12 +540,26 @@ void wxMenuBar::Init() if ( wxApp::s_macPreferencesMenuItemId != wxID_NONE ) { m_appleMenu->Append( wxApp::s_macPreferencesMenuItemId, - "Preferences...\tCtrl+," ); + _("Preferences...") + "\tCtrl+," ); m_appleMenu->AppendSeparator(); } + // 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 ); + 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. - m_appleMenu->Append( wxApp::s_macExitMenuItemId, "Quit\tCtrl+Q" ); + wxString quitLabel(_("Quit")); + if ( wxTheApp ) + quitLabel << ' ' << wxTheApp->GetAppDisplayName(); + quitLabel << "\tCtrl+Q"; + m_appleMenu->Append( wxApp::s_macExitMenuItemId, quitLabel ); #endif // !wxOSX_USE_CARBON m_rootMenu->AppendSubMenu(m_appleMenu, "\x14") ; -- 2.45.2