Implement wxGetOsVersion() and wxGetOsDescription() with NSProcessInfo.

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.
This commit is contained in:
Tobias Taschner
2015-08-07 15:49:23 +02:00
parent c581188a73
commit 411027d5b4
2 changed files with 46 additions and 1 deletions

View File

@@ -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

View File

@@ -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
//===========================================================================