From 388e82e70c5314d8d804bafa7b627e47e00264a6 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Thu, 6 Aug 2015 09:44:20 +0200 Subject: [PATCH 01/11] Remove MSW code targeted at versions prior to WinXP. In 3.1 WinXP is required so remove checks and code for prior versions. --- src/common/filefn.cpp | 9 --------- src/common/filename.cpp | 7 ------- src/msw/pen.cpp | 13 ------------ src/msw/toplevel.cpp | 10 +-------- src/msw/utils.cpp | 45 +++++++++++++++++++---------------------- src/msw/utilsexc.cpp | 3 +-- src/msw/window.cpp | 19 +++-------------- 7 files changed, 26 insertions(+), 80 deletions(-) diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 18cd9ef682..3027b4f575 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -1679,15 +1679,6 @@ static bool wxCheckWin32Permission(const wxString& path, DWORD access) return false; } - if ( wxGetOsVersion() == wxOS_WINDOWS_9X ) - { - // FAT directories always allow all access, even if they have the - // readonly flag set, and FAT files can only be read-only - return (dwAttr & FILE_ATTRIBUTE_DIRECTORY) || - (access != GENERIC_WRITE || - !(dwAttr & FILE_ATTRIBUTE_READONLY)); - } - HANDLE h = ::CreateFile ( path.t_str(), diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 0d6ed2f169..70f131f45b 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -2606,13 +2606,6 @@ bool wxFileName::SetTimes(const wxDateTime *dtAccess, int flags; if ( IsDir() ) { - if ( wxGetOsVersion() == wxOS_WINDOWS_9X ) - { - wxLogError(_("Setting directory access times is not supported " - "under this OS version")); - return false; - } - path = GetPath(); flags = FILE_FLAG_BACKUP_SEMANTICS; } diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index a41e4ddf83..843cc88c26 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -300,19 +300,6 @@ bool wxPenRefData::Alloc() const COLORREF col = m_colour.GetPixel(); #ifdef wxHAVE_EXT_CREATE_PEN - // Only NT can display dashed or dotted lines with width > 1 - static const int os = wxGetOsVersion(); - if ( os != wxOS_WINDOWS_NT && - (m_style == wxPENSTYLE_DOT || - m_style == wxPENSTYLE_LONG_DASH || - m_style == wxPENSTYLE_SHORT_DASH || - m_style == wxPENSTYLE_DOT_DASH || - m_style == wxPENSTYLE_USER_DASH) && - m_width > 1 ) - { - m_width = 1; - } - // check if it's a standard kind of pen which can be created with just // CreatePen() if ( m_join == wxJOIN_ROUND && diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index f275bb5c10..02f28bb566 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -1341,15 +1341,7 @@ bool wxTopLevelWindowMSW::SetTransparent(wxByte alpha) bool wxTopLevelWindowMSW::CanSetTransparent() { - // The API is available on win2k and above - - static int os_type = -1; - static int ver_major = -1; - - if (os_type == -1) - os_type = ::wxGetOsVersion(&ver_major); - - return (os_type == wxOS_WINDOWS_NT && ver_major >= 5); + return true; } void wxTopLevelWindowMSW::DoFreeze() diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 974534be61..93bc29b864 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -891,36 +891,33 @@ bool wxShutdown(int WXUNUSED_IN_WINCE(flags)) #else bool bOK = true; - if ( wxGetOsVersion(NULL, NULL) == wxOS_WINDOWS_NT ) // if is NT or 2K + // Get a token for this process. + HANDLE hToken; + bOK = ::OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, + &hToken) != 0; + if ( bOK ) { - // Get a token for this process. - HANDLE hToken; - bOK = ::OpenProcessToken(GetCurrentProcess(), - TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, - &hToken) != 0; + TOKEN_PRIVILEGES tkp; + + // Get the LUID for the shutdown privilege. + bOK = ::LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, + &tkp.Privileges[0].Luid) != 0; + if ( bOK ) { - TOKEN_PRIVILEGES tkp; + tkp.PrivilegeCount = 1; // one privilege to set + tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - // Get the LUID for the shutdown privilege. - bOK = ::LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, - &tkp.Privileges[0].Luid) != 0; + // Get the shutdown privilege for this process. + ::AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, + (PTOKEN_PRIVILEGES)NULL, 0); - if ( bOK ) - { - tkp.PrivilegeCount = 1; // one privilege to set - tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - - // Get the shutdown privilege for this process. - ::AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, - (PTOKEN_PRIVILEGES)NULL, 0); - - // Cannot test the return value of AdjustTokenPrivileges. - bOK = ::GetLastError() == ERROR_SUCCESS; - } - - ::CloseHandle(hToken); + // Cannot test the return value of AdjustTokenPrivileges. + bOK = ::GetLastError() == ERROR_SUCCESS; } + + ::CloseHandle(hToken); } if ( bOK ) diff --git a/src/msw/utilsexc.cpp b/src/msw/utilsexc.cpp index a0fbc92115..dedc3f547a 100644 --- a/src/msw/utilsexc.cpp +++ b/src/msw/utilsexc.cpp @@ -761,8 +761,7 @@ long wxExecute(const wxString& cmd, int flags, wxProcess *handler, DWORD dwFlags = CREATE_SUSPENDED; #ifndef __WXWINCE__ - if ( (flags & wxEXEC_MAKE_GROUP_LEADER) && - (wxGetOsVersion() == wxOS_WINDOWS_NT) ) + if ( (flags & wxEXEC_MAKE_GROUP_LEADER) ) dwFlags |= CREATE_NEW_PROCESS_GROUP; dwFlags |= CREATE_DEFAULT_ERROR_MODE ; diff --git a/src/msw/window.cpp b/src/msw/window.cpp index a29b0b75bd..4ceb1b076c 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -917,22 +917,9 @@ void wxWindowMSW::WarpPointer(int x, int y) void wxWindowMSW::MSWUpdateUIState(int action, int state) { - // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good - // to use it on older systems -- and could possibly do some harm - static int s_needToUpdate = -1; - if ( s_needToUpdate == -1 ) - { - int verMaj, verMin; - s_needToUpdate = wxGetOsVersion(&verMaj, &verMin) == wxOS_WINDOWS_NT && - verMaj >= 5; - } - - if ( s_needToUpdate ) - { - // we send WM_CHANGEUISTATE so if nothing needs changing then the system - // won't send WM_UPDATEUISTATE - ::SendMessage(GetHwnd(), WM_CHANGEUISTATE, MAKEWPARAM(action, state), 0); - } + // we send WM_CHANGEUISTATE so if nothing needs changing then the system + // won't send WM_UPDATEUISTATE + ::SendMessage(GetHwnd(), WM_CHANGEUISTATE, MAKEWPARAM(action, state), 0); } // --------------------------------------------------------------------------- From e9c04133d24ba9614941ae1683c1070b7bbaa5c9 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Thu, 6 Aug 2015 09:50:47 +0200 Subject: [PATCH 02/11] Remove code targeted at MacOS versions prior to OS X. --- src/generic/treectlg.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index aee711a689..5f5f451529 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -996,12 +996,6 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, const wxString& name ) { #ifdef __WXMAC__ - int major, minor; - wxGetOsVersion(&major, &minor); - - if (major < 10) - style |= wxTR_ROW_LINES; - if (style & wxTR_HAS_BUTTONS) style |= wxTR_NO_LINES; #endif // __WXMAC__ From 93324ebe62c98d61f341b264bf3541b7ee5913c8 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Thu, 6 Aug 2015 10:10:26 +0200 Subject: [PATCH 03/11] Update utils.h documentation with more current OS versions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some OS versions mentioned were a little bit outdated and the paragraph about wxGetHostName on Windows simply didn’t match the implementation any more. --- interface/wx/utils.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/interface/wx/utils.h b/interface/wx/utils.h index bce6a30dcf..46418d2b77 100644 --- a/interface/wx/utils.h +++ b/interface/wx/utils.h @@ -733,10 +733,6 @@ wxString wxGetHomeDir(); note that the returned name is @e not fully qualified, i.e. it does not include the domain name. - Under Windows or NT, this function first looks in the environment variable - SYSTEM_NAME; if this is not found, the entry @b HostName in the wxWidgets - section of the WIN.INI file is tried. - @return The hostname if successful or an empty string otherwise. @see wxGetFullHostName() @@ -835,7 +831,7 @@ bool wxGetUserName(char* buf, int sz); /** Returns the string containing the description of the current platform in a user-readable form. For example, this function may return strings like - "Windows NT Version 4.0" or "Linux 2.2.2 i386". + "Windows 10 (build 10240), 64-bit edition" or "Linux 4.1.4 i386". @see wxGetOsVersion() @@ -851,16 +847,21 @@ wxString wxGetOsDescription(); For Unix-like systems (@c wxOS_UNIX) the major and minor version integers will contain the kernel major and minor version numbers (as returned by the - 'uname -r' command); e.g. "2" and "6" if the machine is using kernel 2.6.19. + 'uname -r' command); e.g. "4" and "1" if the machine is using kernel 4.1.4. For Mac OS X systems (@c wxOS_MAC) the major and minor version integers are the - natural version numbers associated with the OS; e.g. "10" and "6" if the machine - is using Mac OS X Snow Leopard. + natural version numbers associated with the OS; e.g. "10" and "11" if the machine + is using Mac OS X El Capitan. For Windows-like systems (@c wxOS_WINDOWS) the major and minor version integers will contain the following values: @beginTable @row3col{Windows OS name, Major version, Minor version} + @row3col{Windows 10, 10, 0} + @row3col{Windows 8.1, 6, 3} + @row3col{Windows Server 2012 R2, 6, 3} + @row3col{Windows 8, 6, 2} + @row3col{Windows Server 2012, 6, 2} @row3col{Windows 7, 6, 1} @row3col{Windows Server 2008 R2, 6, 1} @row3col{Windows Server 2008, 6, 0} @@ -868,7 +869,6 @@ wxString wxGetOsDescription(); @row3col{Windows Server 2003 R2, 5, 2} @row3col{Windows Server 2003, 5, 2} @row3col{Windows XP, 5, 1} - @row3col{Windows 2000, 5, 0} @endDefList See the MSDN for more info about the values above. From d8e291c27af9dd2c467c38a6a8911ea2a4e09c28 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Thu, 6 Aug 2015 10:16:50 +0200 Subject: [PATCH 04/11] Remove unused and outdated code in OS X wxGetOsVersion. --- src/osx/core/utilsexc_base.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/osx/core/utilsexc_base.cpp b/src/osx/core/utilsexc_base.cpp index 22b9f43302..c33b88a235 100644 --- a/src/osx/core/utilsexc_base.cpp +++ b/src/osx/core/utilsexc_base.cpp @@ -70,16 +70,6 @@ wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn) if ( minorVsn != NULL ) *minorVsn = min; -#if 0 - SInt32 theSystem; - Gestalt(gestaltSystemVersion, &theSystem); - - if ( majorVsn != NULL ) - *majorVsn = (theSystem >> 8); - - if ( minorVsn != NULL ) - *minorVsn = (theSystem & 0xFF); -#endif return wxOS_MAC_OSX_DARWIN; } From 2b3633b3c040b277740cd1c8d4fdb998ebf900a0 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Thu, 6 Aug 2015 11:32:38 +0200 Subject: [PATCH 05/11] Add wxCheckOsVersion() to implement platform based OS version checks. Windows implements VerifyVersionInfo api since Win2k. Starting with Windows 8.1 GetVersionEx is deprecated and may not return the expected version number if the application does not contain the correct compatibility information in its manifest. VerifyVersionInfo works independent of manifest in the executable (and is the recommend way to check). Existing code may already use wxPlatformInfo::CheckOSVersion() so the method forwards the call to wxCheckOsVersion if initialized for the current system. --- include/wx/platinfo.h | 10 +++------- include/wx/utils.h | 3 +++ interface/wx/utils.h | 12 ++++++++++++ src/common/platinfo.cpp | 17 +++++++++++++++++ src/msw/utils.cpp | 15 +++++++++++++++ src/unix/utilsunx.cpp | 8 ++++++++ 6 files changed, 58 insertions(+), 7 deletions(-) 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(); From c581188a73bea9d591e9cefd179d9ee0c059e933 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Thu, 6 Aug 2015 11:46:46 +0200 Subject: [PATCH 06/11] Remove unused code in cocoa file dialog implementation. The removed function was used for OS X versions prior to 10.7 and was not used any more. --- src/osx/cocoa/filedlg.mm | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/osx/cocoa/filedlg.mm b/src/osx/cocoa/filedlg.mm index bdfa9c9be0..9e439b9ab8 100644 --- a/src/osx/cocoa/filedlg.mm +++ b/src/osx/cocoa/filedlg.mm @@ -52,32 +52,6 @@ // then the delegate method - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename will have to // be implemented -namespace -{ - -bool HasAppKit_10_6() -{ - // Even if we require 10.6, we might be loaded by an application that - // was linked against 10.5. setAllowedFileTypes will still be ignored - // in this case. From NSSavePanel.h: - // NSOpenPanel: On versions less than 10.6, this property is ignored. - // For applications that link against 10.6 and higher, this property will - // determine which files should be enabled in the open panel. - int32_t version = NSVersionOfLinkTimeLibrary("AppKit"); - if (version == -1) - { - // If we're loaded by an application that doesn't link against AppKit, - // use the runtime version instead. This check will not work for the - // case above. - version = NSVersionOfRunTimeLibrary("AppKit"); - } - - // Notice that this still works correctly even if version is -1. - return version >= 0x40e2400 /* version of 10.6 AppKit */; -} - -} // anonymous namespace - @interface wxOpenPanelDelegate : NSObject wxOSX_10_6_AND_LATER() { wxFileDialog* _dialog; From 411027d5b4a2d4398aabc756f71fec0bf1fa77b0 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Fri, 7 Aug 2015 15:49:23 +0200 Subject: [PATCH 07/11] 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 //=========================================================================== From 3250bae3a2c3c2c270d79c63306d8053c2e862d4 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Fri, 7 Aug 2015 15:49:52 +0200 Subject: [PATCH 08/11] Implement wxCheckOsVersion() with NSProccessInfo on OS X. Since OS X 10.10 NSProcessInfo has a method isOperatingSystemAtLeastVersion: which should be used compare the OS version if necessary. --- src/osx/cocoa/utils.mm | 22 ++++++++++++++++++++++ src/unix/utilsunx.cpp | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/osx/cocoa/utils.mm b/src/osx/cocoa/utils.mm index 8e20c9dd3c..7faa2bc61b 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -650,6 +650,28 @@ wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn) return wxOS_MAC_OSX_DARWIN; } +bool wxCheckOsVersion(int majorVsn, int minorVsn) +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 + if ([NSProcessInfo instancesRespondToSelector:@selector(isOperatingSystemAtLeastVersion:)]) + { + NSOperatingSystemVersion osVer; + osVer.majorVersion = majorVsn; + osVer.minorVersion = minorVsn; + osVer.patchVersion = 0; + + return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:osVer] != NO; + } + else +#endif + { + int majorCur, minorCur; + wxGetOsVersion(&majorCur, &minorCur); + + return majorCur > majorVsn || (majorCur == majorVsn && minorCur >= minorVsn); + } +} + wxString wxGetOsDescription() { NSString* osDesc = [NSProcessInfo processInfo].operatingSystemVersionString; diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index cc53be2b0f..2a403b1a4d 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -1148,8 +1148,6 @@ wxString wxGetOsDescription() return wxGetCommandOutput(wxT("uname -s -r -m")); } -#endif // !__DARWIN__ - bool wxCheckOsVersion(int majorVsn, int minorVsn) { int majorCur, minorCur; @@ -1158,6 +1156,8 @@ bool wxCheckOsVersion(int majorVsn, int minorVsn) return majorCur > majorVsn || (majorCur == majorVsn && minorCur >= minorVsn); } +#endif // !__DARWIN__ + unsigned long wxGetProcessId() { return (unsigned long)getpid(); From 3f63ad5c61d0b42c7e004799010fe5545fe5bfe3 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Fri, 7 Aug 2015 16:02:24 +0200 Subject: [PATCH 09/11] Add constants for OS X 10.10. --- include/wx/platform.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/wx/platform.h b/include/wx/platform.h index c398f119d3..03c695bc90 100644 --- a/include/wx/platform.h +++ b/include/wx/platform.h @@ -35,6 +35,9 @@ # ifndef MAC_OS_X_VERSION_10_9 # define MAC_OS_X_VERSION_10_9 1090 # endif +# ifndef MAC_OS_X_VERSION_10_10 +# define MAC_OS_X_VERSION_10_10 101000 +# endif # include "wx/osx/config_xcode.h" # ifndef __WXOSX__ # define __WXOSX__ 1 @@ -534,6 +537,9 @@ # ifndef MAC_OS_X_VERSION_10_9 # define MAC_OS_X_VERSION_10_9 1090 # endif +# ifndef MAC_OS_X_VERSION_10_10 +# define MAC_OS_X_VERSION_10_10 101000 +# endif # else # error "only mach-o configurations are supported" # endif From 8bd14648cd3c66dd38dd83617eb7aac4f0afa02e Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Fri, 7 Aug 2015 16:25:28 +0200 Subject: [PATCH 10/11] Remove Cocoa code and precompiler defines targeting OS X versions prior to OS X 10.7. --- include/wx/osx/cocoa/dataview.h | 4 +-- include/wx/osx/cocoa/private.h | 8 +++--- include/wx/osx/core/private.h | 11 -------- src/osx/carbon/colordlgosx.mm | 2 +- src/osx/carbon/utilscocoa.mm | 7 +---- src/osx/cocoa/combobox.mm | 2 +- src/osx/cocoa/filedlg.mm | 2 +- src/osx/cocoa/listbox.mm | 4 +-- src/osx/cocoa/menu.mm | 2 +- src/osx/cocoa/nonownedwnd.mm | 49 ++++++++------------------------- src/osx/cocoa/notebook.mm | 2 +- src/osx/cocoa/textctrl.mm | 2 +- src/osx/cocoa/toolbar.mm | 2 +- src/osx/cocoa/utils.mm | 2 +- src/osx/cocoa/window.mm | 11 ++------ 15 files changed, 30 insertions(+), 80 deletions(-) diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 540b66a56c..65fc99c2b3 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -249,7 +249,7 @@ private: // owned by the set. Furthermore, children of the last parent are stored // in a linear list. // -@interface wxCocoaOutlineDataSource : NSObject wxOSX_10_6_AND_LATER() +@interface wxCocoaOutlineDataSource : NSObject { // descriptors specifying the sorting (currently the array only holds one // object only) @@ -395,7 +395,7 @@ private: // wxCocoaOutlineView // ============================================================================ -@interface wxCocoaOutlineView : NSOutlineView wxOSX_10_6_AND_LATER() +@interface wxCocoaOutlineView : NSOutlineView { @private // column and row of the cell being edited or -1 if none diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 83cd34d41e..cc929ae6bf 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -336,7 +336,7 @@ public: - (void) setTextField:(NSTextField*) field; @end - @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER() + @interface wxNSTextField : NSTextField { wxNSTextFieldEditor* fieldEditor; } @@ -346,14 +346,14 @@ public: @end - @interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER() + @interface wxNSSecureTextField : NSSecureTextField { } @end - @interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER() + @interface wxNSTextView : NSTextView { } @@ -432,7 +432,7 @@ public: #ifdef __LP64__ WXEXPORT #endif // 64 bit builds - @interface wxNSAppController : NSObject wxOSX_10_6_AND_LATER() + @interface wxNSAppController : NSObject { } diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index c52a8e5af2..9b1c371562 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -20,17 +20,6 @@ #include "wx/osx/core/cfstring.h" #include "wx/osx/core/cfdataref.h" -// Define helper macros allowing to insert small snippets of code to be -// compiled for high enough OS X version only: this shouldn't be abused for -// anything big but it's handy for e.g. specifying OS X 10.6-only protocols in -// the Objective C classes declarations when they're not supported under the -// previous versions -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 - #define wxOSX_10_6_AND_LATER(x) x -#else - #define wxOSX_10_6_AND_LATER(x) -#endif - // platform specific Clang analyzer support #ifndef NS_RETURNS_RETAINED # if WX_HAS_CLANG_FEATURE(attribute_ns_returns_retained) diff --git a/src/osx/carbon/colordlgosx.mm b/src/osx/carbon/colordlgosx.mm index a818dde360..a22a2cc44b 100644 --- a/src/osx/carbon/colordlgosx.mm +++ b/src/osx/carbon/colordlgosx.mm @@ -41,7 +41,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog); // wxCPWCDelegate - Window Closed delegate // --------------------------------------------------------------------------- -@interface wxCPWCDelegate : NSObject wxOSX_10_6_AND_LATER() +@interface wxCPWCDelegate : NSObject { bool m_bIsClosed; } diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 60c03445e0..489aeaba56 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -494,12 +494,7 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns double wxOSXGetMainScreenContentScaleFactor() { -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) - if ( [ [NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)] ) - return [[NSScreen mainScreen] backingScaleFactor]; - else -#endif - return 1.0; + return [[NSScreen mainScreen] backingScaleFactor]; } CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scaleptr ) diff --git a/src/osx/cocoa/combobox.mm b/src/osx/cocoa/combobox.mm index fbaec3fb74..0a4acd1190 100644 --- a/src/osx/cocoa/combobox.mm +++ b/src/osx/cocoa/combobox.mm @@ -24,7 +24,7 @@ // work in progress -@interface wxNSTableDataSource : NSObject wxOSX_10_6_AND_LATER() +@interface wxNSTableDataSource : NSObject { wxNSComboBoxControl* impl; } diff --git a/src/osx/cocoa/filedlg.mm b/src/osx/cocoa/filedlg.mm index 9e439b9ab8..540358f757 100644 --- a/src/osx/cocoa/filedlg.mm +++ b/src/osx/cocoa/filedlg.mm @@ -52,7 +52,7 @@ // then the delegate method - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename will have to // be implemented -@interface wxOpenPanelDelegate : NSObject wxOSX_10_6_AND_LATER() +@interface wxOpenPanelDelegate : NSObject { wxFileDialog* _dialog; } diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index 0eb49dd569..7966d70223 100644 --- a/src/osx/cocoa/listbox.mm +++ b/src/osx/cocoa/listbox.mm @@ -30,7 +30,7 @@ class wxListWidgetCocoaImpl; -@interface wxNSTableDataSource : NSObject wxOSX_10_6_AND_LATER() +@interface wxNSTableDataSource : NSObject { wxListWidgetCocoaImpl* impl; } @@ -50,7 +50,7 @@ class wxListWidgetCocoaImpl; @end -@interface wxNSTableView : NSTableView wxOSX_10_6_AND_LATER() +@interface wxNSTableView : NSTableView { } diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm index 562efe75d4..eb52113acc 100644 --- a/src/osx/cocoa/menu.mm +++ b/src/osx/cocoa/menu.mm @@ -58,7 +58,7 @@ // and under 10.4, we are not getting a 'close' event however... #define wxOSX_USE_NEEDSUPDATE_HOOK 1 -@interface wxNSMenuController : NSObject wxOSX_10_6_AND_LATER() +@interface wxNSMenuController : NSObject { } diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index a13efdabbf..97186983b1 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -91,19 +91,11 @@ bool shouldHandleSelector(SEL selector) } - -#define wxHAS_FULL_SCREEN_API (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) - -#if wxHAS_FULL_SCREEN_API - static bool IsUsingFullScreenApi(WXWindow macWindow) { - return [macWindow respondsToSelector:@selector(toggleFullScreen:)] - && ([macWindow collectionBehavior] & NSWindowCollectionBehaviorFullScreenPrimary); + return ([macWindow collectionBehavior] & NSWindowCollectionBehaviorFullScreenPrimary); } -#endif - // // wx category for NSWindow (our own and wrapped instances) // @@ -313,7 +305,7 @@ static NSResponder* s_formerFirstResponder = NULL; // controller // -@interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER() +@interface wxNonOwnedWindowController : NSObject { } @@ -326,9 +318,7 @@ static NSResponder* s_formerFirstResponder = NULL; - (void)windowDidDeminiaturize:(NSNotification *)notification; - (BOOL)windowShouldClose:(id)window; - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame; -#if wxHAS_FULL_SCREEN_API - (void)windowWillEnterFullScreen:(NSNotification *)notification; -#endif @end @@ -585,8 +575,6 @@ extern int wxOSXGetIdFromSelector(SEL action ); return true; } -#if wxHAS_FULL_SCREEN_API - // work around OS X bug, on a secondary monitor an already fully sized window // (eg maximized) will not be correctly put to full screen size and keeps a 22px // title band at the top free, therefore we force the correct content size @@ -607,8 +595,6 @@ extern int wxOSXGetIdFromSelector(SEL action ); } } -#endif - @end wxIMPLEMENT_DYNAMIC_CLASS(wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl); @@ -1000,44 +986,32 @@ typedef struct bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const { -#if wxHAS_FULL_SCREEN_API if ( IsUsingFullScreenApi(m_macWindow) ) { return [m_macWindow styleMask] & NSFullScreenWindowMask; } -#endif return m_macFullScreenData != NULL ; } bool wxNonOwnedWindowCocoaImpl::EnableFullScreenView(bool enable) { -#if wxHAS_FULL_SCREEN_API - if ( [ m_macWindow respondsToSelector:@selector(setCollectionBehavior:) ] ) + NSUInteger collectionBehavior = [m_macWindow collectionBehavior]; + if (enable) { - NSUInteger collectionBehavior = [m_macWindow collectionBehavior]; - if (enable) - { - collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; - } - else - { - collectionBehavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; - } - [m_macWindow setCollectionBehavior: collectionBehavior]; - - return true; + collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; } -#else - wxUnusedVar(enable); -#endif + else + { + collectionBehavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; + } + [m_macWindow setCollectionBehavior: collectionBehavior]; - return false; + return true; } bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style)) { -#if wxHAS_FULL_SCREEN_API if ( IsUsingFullScreenApi(m_macWindow) ) { if ( show != IsFullScreen() ) @@ -1047,7 +1021,6 @@ bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style)) return true; } -#endif if ( show ) { diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm index 33b773b117..ead8978b54 100644 --- a/src/osx/cocoa/notebook.mm +++ b/src/osx/cocoa/notebook.mm @@ -29,7 +29,7 @@ // controller // -@interface wxTabViewController : NSObject wxOSX_10_6_AND_LATER() +@interface wxTabViewController : NSObject { } diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 22fc4e7681..cb12954e4b 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -827,7 +827,7 @@ wxNSTextFieldControl::wxNSTextFieldControl(wxWindow *wxPeer, void wxNSTextFieldControl::Init(WXWidget w) { - NSTextField wxOSX_10_6_AND_LATER() *tf = (NSTextField wxOSX_10_6_AND_LATER()*) w; + NSTextField *tf = (NSTextField *) w; m_textField = tf; [m_textField setDelegate: tf]; m_selStart = m_selEnd = 0; diff --git a/src/osx/cocoa/toolbar.mm b/src/osx/cocoa/toolbar.mm index 243b0c4d42..e5f918dbad 100644 --- a/src/osx/cocoa/toolbar.mm +++ b/src/osx/cocoa/toolbar.mm @@ -301,7 +301,7 @@ private: @end -@interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER() +@interface wxNSToolbarDelegate : NSObject { bool m_isSelectable; } diff --git a/src/osx/cocoa/utils.mm b/src/osx/cocoa/utils.mm index 7faa2bc61b..d3418d9433 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -412,7 +412,7 @@ bool wxApp::DoInitGui() } appcontroller = OSXCreateAppController(); - [[NSApplication sharedApplication] setDelegate:(id wxOSX_10_6_AND_LATER())appcontroller]; + [[NSApplication sharedApplication] setDelegate:(id )appcontroller]; [NSColor setIgnoresAlpha:NO]; // calling finishLaunching so early before running the loop seems to trigger some 'MenuManager compatibility' which leads diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 91e02ed9e5..e2ead70efe 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -1755,9 +1755,7 @@ void wxOSXCocoaClassAddWXMethods(Class c) wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" ) wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" ) -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 wxOSX_CLASS_ADD_METHOD(c, @selector(magnifyWithEvent:), (IMP)wxOSX_mouseEvent, "v@:@") -#endif wxOSX_CLASS_ADD_METHOD(c, @selector(cursorUpdate:), (IMP) wxOSX_cursorUpdate, "v@:@" ) @@ -1870,13 +1868,8 @@ void wxWidgetCocoaImpl::SetVisibility( bool visible ) double wxWidgetCocoaImpl::GetContentScaleFactor() const { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 NSWindow* tlw = [m_osxView window]; - if ( [ tlw respondsToSelector:@selector(backingScaleFactor) ] ) - return [tlw backingScaleFactor]; - else -#endif - return 1.0; + return [tlw backingScaleFactor]; } // ---------------------------------------------------------------------------- @@ -1884,7 +1877,7 @@ double wxWidgetCocoaImpl::GetContentScaleFactor() const // ---------------------------------------------------------------------------- // define a delegate used to refresh the window during animation -@interface wxNSAnimationDelegate : NSObject wxOSX_10_6_AND_LATER() +@interface wxNSAnimationDelegate : NSObject { wxWindow *m_win; bool m_isDone; From 5d364bf81e529a031a9b8540434bfc93ced48026 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Fri, 7 Aug 2015 16:55:30 +0200 Subject: [PATCH 11/11] Update supported OS versions in Readme files. --- README.md | 4 ++-- docs/readme.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d551a94f92..b224a9f8db 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ Platforms wxWidgets currently supports the following primary platforms: -- Windows XP, Vista, 7 and 8 (32/64 bits). +- Windows XP, Vista, 7, 8 and 10 (32/64 bits). - Most Unix variants using the GTK+ toolkit (version 2.6 or newer or 3.x). - Mac OS X (10.7 or newer) using Cocoa (32/64 bits) or Carbon (32 only). Most popular C++ compilers are supported including but not limited to: -- Microsoft Visual C++ 2003 or later (up to 2013). +- Microsoft Visual C++ 2003 or later (up to 2015). - g++ 3.4 or later, including MinGW/MinGW-64/TDM under Windows. - Clang under OS X and Linux. - Intel icc compiler. diff --git a/docs/readme.txt b/docs/readme.txt index c2f4bcac9b..713fc96d50 100644 --- a/docs/readme.txt +++ b/docs/readme.txt @@ -45,9 +45,9 @@ Platforms supported wxWidgets currently supports the following primary platforms: -- Windows XP, Vista, 7 and 8 (32/64 bits). +- Windows XP, Vista, 7, 8 and 10 (32/64 bits). - Most Unix variants using the GTK+ toolkit (version 2.6 or newer) -- Mac OS X (10.6 or newer) using Cocoa (32/64 bits) or Carbon (32 only) +- Mac OS X (10.7 or newer) using Cocoa (32/64 bits) or Carbon (32 only) There is some support for the following platforms: