From 41026f89e070f8c8e358604bb4811319175fe59a Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Sat, 15 Mar 2014 04:56:14 -0700 Subject: [PATCH] MGR: Simplify logic introduced in my commit 0f68132; start replacing deprecated Carbon APIs with Cocoa code. --- clientgui/BOINCGUIApp.cpp | 16 +------ clientgui/mac/BOINCGUIApp.mm | 88 ++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 62 deletions(-) diff --git a/clientgui/BOINCGUIApp.cpp b/clientgui/BOINCGUIApp.cpp index f9d6c3bc9f..21182883f4 100644 --- a/clientgui/BOINCGUIApp.cpp +++ b/clientgui/BOINCGUIApp.cpp @@ -1261,6 +1261,8 @@ int CBOINCGUIApp::SafeMessageBox(const wxString& message, const wxString& captio } +#ifndef __WXMAC__ +// See clientgui/mac/BOINCGUIApp.mm for the Mac versions. /// /// Determines if the current process is visible. /// @@ -1268,11 +1270,6 @@ int CBOINCGUIApp::SafeMessageBox(const wxString& message, const wxString& captio /// true if the current process is visible, otherwise false. /// bool CBOINCGUIApp::IsApplicationVisible() { -#ifdef __WXMAC__ - if (IsProcessVisible(&m_psnCurrentProcess)) { - return true; - } -#endif return false; } @@ -1282,15 +1279,6 @@ bool CBOINCGUIApp::IsApplicationVisible() { /// @param bShow /// true will show the process, false will hide the process. /// -#ifdef __WXMAC__ -void CBOINCGUIApp::ShowApplication(bool bShow) { - if (bShow) { - SetFrontProcess(&m_psnCurrentProcess); - } else { - HideThisApp(); - } -} -#else void CBOINCGUIApp::ShowApplication(bool) { } #endif diff --git a/clientgui/mac/BOINCGUIApp.mm b/clientgui/mac/BOINCGUIApp.mm index 35a7909bc0..1b5a7a2716 100644 --- a/clientgui/mac/BOINCGUIApp.mm +++ b/clientgui/mac/BOINCGUIApp.mm @@ -23,21 +23,6 @@ // Cocoa routines which are part of CBOINCGUIApp - -// Weak linking of objective-C classes is not supported before -// OS 10.6.8 so to be compatible with OS 10.5 we must use the -// objective-C equivalent of dlopen() and dlsym(). -static Class NSRunningApplicationClass = nil; // Requires OS 10.6 -static bool hasOwnsMenuBar = false; // Requires OS 10.7 - - -// HideThisApp() is called from CBOINCGUIApp::ShowApplication(bool) -// and replaces a call of ShowHideProcess() which is deprecated -// under OS 10.9. -void CBOINCGUIApp::HideThisApp() { - [ NSApp hide:NSApp ]; -} - // Override standard wxCocoa wxApp::CallOnInit() to allow Manager // to run properly when launched hidden on login via Login Item. bool CBOINCGUIApp::CallOnInit() { @@ -54,19 +39,6 @@ bool CBOINCGUIApp::CallOnInit() { bool retVal = wxApp::CallOnInit(); - // Determine whether [[NSRunningApplication currentApplication] ownsMenuBar] is available - NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/AppKit.framework"]; - NSError *err = nil; - bool loaded = [bundle loadAndReturnError:&err]; - if (loaded) { - NSRunningApplicationClass = NSClassFromString(@"NSRunningApplication"); - if (NSRunningApplicationClass != nil) { - if ([[NSRunningApplicationClass currentApplication] respondsToSelector:@selector(ownsMenuBar)]) { - hasOwnsMenuBar = true; - } - } - } - [mypool release]; return retVal; } @@ -91,29 +63,49 @@ bool CBOINCGUIApp::CallOnInit() { // void CBOINCGUIApp::CheckPartialActivation() { // This code is not needed and has bad effects on OS 10.5. - // Initializing wasVisible this way avoids the problem - // because we briefly own the menu bar at login on OS 10.5. - static bool wasVisible = ![ NSApp isHidden ]; + // Initializing wasHidden this way avoids the problem + // because we are briefly shown at login on OS 10.5. + static bool wasHidden = [ NSApp isHidden ]; - ProcessSerialNumber frontPSN; - Boolean isSame = false; + if (wasHidden) { + if (m_bAboutDialogIsOpen) return; - if (m_bAboutDialogIsOpen) return; - - if (!wasVisible) { - - if (hasOwnsMenuBar) { // Requires OS 10.7 - isSame = (bool)[[NSRunningApplicationClass - performSelector:NSSelectorFromString(@"currentApplication")] - performSelector:NSSelectorFromString(@"ownsMenuBar")]; - } else { - GetFrontProcess(&frontPSN); // Deprecated in OS 10.9 - SameProcess(&m_psnCurrentProcess, &frontPSN, &isSame); - } - - if (isSame) { + if (! [ NSApp isHidden ]) { + wasHidden = false; ShowInterface(); } - wasVisible = ![ NSApp isHidden ]; + } +} + + +// HideThisApp() is called from CBOINCGUIApp::ShowApplication(bool) +// and replaces a call of ShowHideProcess() which is deprecated +// under OS 10.9. +void CBOINCGUIApp::HideThisApp() { + [ NSApp hide:NSApp ]; +} + + +/// Determines if the current process is visible. +/// +/// @return +/// true if the current process is visible, otherwise false. +/// +bool CBOINCGUIApp::IsApplicationVisible() { + return (! [ NSApp isHidden ]); +} + + +/// +/// Shows or hides the current process. +/// +/// @param bShow +/// true will show the process, false will hide the process. +/// +void CBOINCGUIApp::ShowApplication(bool bShow) { + if (bShow) { + [ NSApp activateIgnoringOtherApps:YES ]; + } else { + [ NSApp hide:NSApp ]; } }