From be228c5a1590694c53d4ec70d7006f2d1a036772 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 17 Feb 2025 11:01:28 +0800 Subject: [PATCH] utils_base.mm: fix --- src/osx/cocoa/utils_base.mm | 63 ++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/src/osx/cocoa/utils_base.mm b/src/osx/cocoa/utils_base.mm index c7c253363d..71ea57b9df 100644 --- a/src/osx/cocoa/utils_base.mm +++ b/src/osx/cocoa/utils_base.mm @@ -24,6 +24,13 @@ #include "wx/osx/private.h" #include "wx/osx/private/available.h" +#if (defined(__APPLE__) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101000) \ + || (defined(__WXOSX_IPHONE__) && defined(__IPHONE_8_0)) + #define wxHAS_NSPROCESSINFO 1 +#endif + +#include + #if wxUSE_SOCKETS // global pointer which lives in the base library, set from the net one (see // sockosx.cpp) and used from the GUI code (see utilsexc_cf.cpp) -- ugly but @@ -36,6 +43,7 @@ wxSocketManager *wxOSXSocketManagerCF = NULL; // our OS version is the same in non GUI and GUI cases wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro) { +#if wxHAS_NSPROCESSINFO NSOperatingSystemVersion osVer = [NSProcessInfo processInfo].operatingSystemVersion; if ( verMaj != NULL ) @@ -46,18 +54,42 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro) if ( verMicro != NULL ) *verMicro = osVer.patchVersion; +#else + SInt32 maj, min, micro; + + Gestalt(gestaltSystemVersionMajor, &maj); + Gestalt(gestaltSystemVersionMinor, &min); + Gestalt(gestaltSystemVersionBugFix, µ); + + if ( verMaj != NULL ) + *verMaj = maj; + if ( verMin != NULL ) + *verMin = min; + + if ( verMicro != NULL ) + *verMicro = micro; +#endif return wxOS_MAC_OSX_DARWIN; } bool wxCheckOsVersion(int majorVsn, int minorVsn, int microVsn) { +#if wxHAS_NSPROCESSINFO NSOperatingSystemVersion osVer; osVer.majorVersion = majorVsn; osVer.minorVersion = minorVsn; osVer.patchVersion = microVsn; return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:osVer] != NO; +#else + int majorCur, minorCur, microCur; + wxGetOsVersion(&majorCur, &minorCur, µCur); + + return majorCur > majorVsn + || (majorCur == majorVsn && minorCur >= minorVsn) + || (majorCur == majorVsn && minorCur == minorVsn && microCur >= microVsn); +#endif } wxString wxGetOsDescription() @@ -77,6 +109,25 @@ wxString wxGetOsDescription() { switch (minorVer) { + case 5: + osName = "Leopard"; + osBrand = "Mac OS X"; + break; + case 6: + osName = "Snow Leopard"; + osBrand = "Mac OS X"; + break; + case 7: + osName = "Lion"; + // 10.7 was the last version where the "Mac" prefix was used + osBrand = "Mac OS X"; + break; + case 8: + osName = "Mountain Lion"; + break; + case 9: + osName = "Mavericks"; + break; case 10: osName = "Yosemite"; break; @@ -223,16 +274,16 @@ bool wxCocoaLaunch(const char* const* argv, pid_t &pid) } NSWorkspace *ws = [NSWorkspace sharedWorkspace]; - - + + NSRunningApplication *app = nil; - + if ( [params count] > 0 ) app = [ws openURLs:params withApplicationAtURL:url options:NSWorkspaceLaunchAsync configuration:[NSDictionary dictionary] error:&error]; - + if ( app == nil ) { app = [ws launchApplicationAtURL:url @@ -252,15 +303,17 @@ bool wxCocoaLaunch(const char* const* argv, pid_t &pid) } } } - + [params release]; if( app != nil ) pid = [app processIdentifier]; else { +#ifdef __WXMAC__ wxString errorDesc = wxCFStringRef::AsString([error localizedDescription]); wxLogDebug( "wxCocoaLaunch failure: error is %s", errorDesc ); +#endif return false; } return true;