From 411027d5b4a2d4398aabc756f71fec0bf1fa77b0 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Fri, 7 Aug 2015 15:49:23 +0200 Subject: [PATCH] Implement wxGetOsVersion() and wxGetOsDescription() with NSProcessInfo. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NSProcessInfo is the recommended way to determine OS X OS version, but the operatingSystemVersion property is only available in OS X 10.10+. Because of that a fallback to Gestalt() is implemented. The NSProcessInfo.operatingSystemVersionString in the form “Version 10.10.4 (Build 14E46)" now used by wxGetOsDescription() should be more useful to the user than the carbon implementations darwin version. --- src/osx/cocoa/utils.mm | 41 ++++++++++++++++++++++++++++++++++ src/osx/core/utilsexc_base.cpp | 6 ++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/osx/cocoa/utils.mm b/src/osx/cocoa/utils.mm index 4f81cc473e..8e20c9dd3c 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -618,4 +618,45 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const #endif // wxUSE_GUI +// our OS version is the same in non GUI and GUI cases +wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn) +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 + if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) + { + NSOperatingSystemVersion osVer = [NSProcessInfo processInfo].operatingSystemVersion; + + if ( majorVsn != NULL ) + *majorVsn = osVer.majorVersion; + + if ( minorVsn != NULL ) + *minorVsn = osVer.minorVersion; + } + else +#endif + { + // On OS X versions prior to 10.10 NSProcessInfo does not provide the OS version + SInt32 maj, min; + Gestalt(gestaltSystemVersionMajor, &maj); + Gestalt(gestaltSystemVersionMinor, &min); + + if ( majorVsn != NULL ) + *majorVsn = maj; + + if ( minorVsn != NULL ) + *minorVsn = min; + } + + return wxOS_MAC_OSX_DARWIN; +} + +wxString wxGetOsDescription() +{ + NSString* osDesc = [NSProcessInfo processInfo].operatingSystemVersionString; + wxCFStringRef cf(wxCFRetain(osDesc)); + + return wxString::Format(wxT("Mac OS X %s"), + cf.AsString()); +} + #endif // wxOSX_USE_COCOA diff --git a/src/osx/core/utilsexc_base.cpp b/src/osx/core/utilsexc_base.cpp index c33b88a235..3f325b3683 100644 --- a/src/osx/core/utilsexc_base.cpp +++ b/src/osx/core/utilsexc_base.cpp @@ -53,7 +53,7 @@ extern WXDLLIMPEXP_BASE wxSocketManager *wxOSXSocketManagerCF; wxSocketManager *wxOSXSocketManagerCF = NULL; #endif // wxUSE_SOCKETS -#if ( !wxUSE_GUI && !wxOSX_USE_IPHONE ) || wxOSX_USE_COCOA_OR_CARBON +#if ( !wxUSE_GUI && !wxOSX_USE_IPHONE ) || wxOSX_USE_CARBON // our OS version is the same in non GUI and GUI cases wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn) @@ -85,6 +85,10 @@ wxString wxGetOsDescription() wxString::FromAscii(name.machine).c_str()); } +#endif // wxOSX_USE_CARBON + +#if ( !wxUSE_GUI && !wxOSX_USE_IPHONE ) || wxOSX_USE_COCOA_OR_CARBON + //=========================================================================== // IMPLEMENTATION //===========================================================================