diff --git a/include/wx/platinfo.h b/include/wx/platinfo.h index 33cd2c58ca..3166f82804 100644 --- a/include/wx/platinfo.h +++ b/include/wx/platinfo.h @@ -190,13 +190,7 @@ public: { return m_osVersionMinor; } // return true if the OS version >= major.minor - bool CheckOSVersion(int major, int minor) const - { - return DoCheckVersion(GetOSMajorVersion(), - GetOSMinorVersion(), - major, - minor); - } + bool CheckOSVersion(int major, int minor) const; int GetToolkitMajorVersion() const { return m_tkVersionMajor; } @@ -300,6 +294,8 @@ protected: return majorCur > major || (majorCur == major && minorCur >= minor); } + bool m_initializedForCurrentPlatform; + void InitForCurrentPlatform(); diff --git a/include/wx/utils.h b/include/wx/utils.h index 3461821b46..e29c131697 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -143,6 +143,9 @@ WXDLLIMPEXP_BASE wxString wxGetOsDescription(); WXDLLIMPEXP_BASE wxOperatingSystemId wxGetOsVersion(int *majorVsn = NULL, int *minorVsn = NULL); +// Check is OS version is at least the specified major and minor version +WXDLLIMPEXP_BASE bool wxCheckOsVersion(int majorVsn, int minorVsn = 0); + // Get platform endianness WXDLLIMPEXP_BASE bool wxIsPlatformLittleEndian(); diff --git a/interface/wx/utils.h b/interface/wx/utils.h index 46418d2b77..0dd2a30d73 100644 --- a/interface/wx/utils.h +++ b/interface/wx/utils.h @@ -879,6 +879,18 @@ wxString wxGetOsDescription(); */ wxOperatingSystemId wxGetOsVersion(int* major = NULL, int* minor = NULL); +/** + Returns @true the version of the operating system on which the program + is running under is the same or later than the given version. + + @since 3.1.0 + + @see wxGetOsVersion(), wxPlatformInfo + + @header{wx/utils.h} +*/ +bool wxCheckOsVersion(int majorVsn, int minorVsn = 0); + /** Returns @true if the operating system the program is running under is 64 bit. The check is performed at run-time and may differ from the value diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp index 268d51273e..41fd0c23db 100644 --- a/src/common/platinfo.cpp +++ b/src/common/platinfo.cpp @@ -135,6 +135,8 @@ wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor, wxEndianness endian, bool usingUniversal) { + m_initializedForCurrentPlatform = false; + m_tkVersionMajor = tkMajor; m_tkVersionMinor = tkMinor; m_port = pid; @@ -166,6 +168,8 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const void wxPlatformInfo::InitForCurrentPlatform() { + m_initializedForCurrentPlatform = true; + // autodetect all informations const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; if ( !traits ) @@ -294,6 +298,19 @@ wxString wxPlatformInfo::GetEndiannessName(wxEndianness end) return wxEndiannessNames[end]; } +bool wxPlatformInfo::CheckOSVersion(int major, int minor) const +{ + // If this instance of wxPlatformInfo has been initialized by InitForCurrentPlatform() + // this check gets forwarded to the wxCheckOsVersion which might do more than a simple + // number check if supported by the platform + if (m_initializedForCurrentPlatform) + return wxCheckOsVersion(major, minor); + else + return DoCheckVersion(GetOSMajorVersion(), + GetOSMinorVersion(), + major, + minor); +} // ---------------------------------------------------------------------------- // wxPlatformInfo - string -> enum conversions diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 93bc29b864..aedbb78841 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -1327,6 +1327,21 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) return s_version.os; } +bool wxCheckOsVersion(int majorVsn, int minorVsn) +{ + OSVERSIONINFOEX osvi = { sizeof(osvi), 0, 0, 0, 0, { 0 }, 0, 0 }; + DWORDLONG const dwlConditionMask = + ::VerSetConditionMask( + ::VerSetConditionMask( + 0, VER_MAJORVERSION, VER_GREATER_EQUAL), + VER_MINORVERSION, VER_GREATER_EQUAL); + + osvi.dwMajorVersion = majorVsn; + osvi.dwMinorVersion = minorVsn; + + return ::VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask) != FALSE; +} + wxWinVersion wxGetWinVersion() { int verMaj, diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index f7e63d2856..cc53be2b0f 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -1150,6 +1150,14 @@ wxString wxGetOsDescription() #endif // !__DARWIN__ +bool wxCheckOsVersion(int majorVsn, int minorVsn) +{ + int majorCur, minorCur; + wxGetOsVersion(&majorCur, &minorCur); + + return majorCur > majorVsn || (majorCur == majorVsn && minorCur >= minorVsn); +} + unsigned long wxGetProcessId() { return (unsigned long)getpid();