From 2739d4f0528b324700973169b67750107568bf12 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Jun 2003 00:16:04 +0000 Subject: [PATCH] moved GetOSVersion() to the base traits class; implement it in platform-specific files git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21437 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/apptrait.h | 9 +++++++ include/wx/msw/apptbase.h | 7 +++++ include/wx/unix/apptbase.h | 9 ------- src/common/utilscmn.cpp | 21 ++++++++------- src/msw/utils.cpp | 55 +++++++++++++++----------------------- src/unix/baseunix.cpp | 2 +- src/unix/utilsunx.cpp | 11 -------- 7 files changed, 51 insertions(+), 63 deletions(-) diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index b61ca8bac3..488645e1b1 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -81,6 +81,15 @@ public: // remove this object from the pending delete list in GUI, do nothing in // wxBase virtual void RemoveFromPendingDelete(wxObject *object) = 0; + + + // other miscellaneous helpers + // --------------------------- + + // wxGetOsVersion() behaves differently in GUI and non-GUI builds under + // Unix: in the former case it returns the information about the toolkit + // and in the latter -- about the OS, so we need to virtualize it + virtual int GetOSVersion(int *verMaj, int *verMin) = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/wx/msw/apptbase.h b/include/wx/msw/apptbase.h index a080eea7b7..e7cfa68886 100644 --- a/include/wx/msw/apptbase.h +++ b/include/wx/msw/apptbase.h @@ -40,6 +40,13 @@ public: // process a message while waiting for a(nother) thread, should return // false if and only if we have to exit the application virtual bool DoMessageFromThreadWait() = 0; + + // other miscellaneous helpers + // --------------------------- + + // under MSW this function does the same thing for console and GUI + // applications so we can implement it directly in the base class + virtual int GetOSVersion(int *verMaj, int *verMin); }; #endif // _WX_MSW_APPTBASE_H_ diff --git a/include/wx/unix/apptbase.h b/include/wx/unix/apptbase.h index 3832761d13..a4488c6a1b 100644 --- a/include/wx/unix/apptbase.h +++ b/include/wx/unix/apptbase.h @@ -48,15 +48,6 @@ public: // ---------------- // TODO - - - // other miscellaneous helpers - // --------------------------- - - // wxGetOsVersion() behaves differently in GUI and non-GUI builds udner - // Unix: in the former case it returns the information about the toolkit - // and in the latter -- about the OS, so we need to virtualize it - virtual int GetOSVersion(int *verMaj, int *verMin) = 0; }; #endif // _WX_UNIX_APPTBASE_H_ diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 5d53b623fc..0580ea7678 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -36,7 +36,6 @@ #include "wx/log.h" #if wxUSE_GUI - #include "wx/app.h" #include "wx/window.h" #include "wx/frame.h" #include "wx/menu.h" @@ -50,10 +49,10 @@ #endif // wxUSE_GUI #endif // WX_PRECOMP -#ifndef __WIN16__ +#include "wx/apptrait.h" + #include "wx/process.h" #include "wx/txtstrm.h" -#endif #include #include @@ -292,6 +291,16 @@ wxString wxGetDataDir() return dir; } +int wxGetOsVersion(int *verMaj, int *verMin) +{ + // we want this function to work even if there is no wxApp + wxConsoleAppTraits traitsConsole; + wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + if ( ! traits ) + traits = &traitsConsole; + + return traits->GetOSVersion(verMaj, verMin); +} // ---------------------------------------------------------------------------- // network and user id functions @@ -472,11 +481,6 @@ static long wxDoExecuteWithCapture(const wxString& command, wxArrayString& output, wxArrayString* error) { -#ifdef __WIN16__ - wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16."); - - return 0; -#else // !Win16 // create a wxProcess which will capture the output wxProcess *process = new wxProcess; process->Redirect(); @@ -501,7 +505,6 @@ static long wxDoExecuteWithCapture(const wxString& command, delete process; return rc; -#endif // IO redirection supported } long wxExecute(const wxString& command, wxArrayString& output) diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index ab861dff71..bc79244d0b 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -31,6 +31,8 @@ #include "wx/log.h" #endif //WX_PRECOMP +#include "wx/apptrait.h" + #include "wx/msw/private.h" // includes #ifdef __GNUWIN32_OLD__ @@ -974,64 +976,51 @@ wxString wxGetOsDescription() #endif // Win32/16 } -int wxGetOsVersion(int *majorVsn, int *minorVsn) +int wxAppTraits::GetOSVersion(int *verMaj, int *verMin) { -#if defined(__WIN32__) - static int ver = -1, major = -1, minor = -1; + // cache the version info, it's not going to change + // + // NB: this is MT-safe, we may use these static vars from different threads + // but as they always have the same value it doesn't matter + static int s_ver = -1, + s_major = -1, + s_minor = -1; - if ( ver == -1 ) + if ( s_ver == -1 ) { OSVERSIONINFO info; wxZeroMemory(info); - ver = wxWINDOWS; + s_ver = wxWINDOWS; info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if ( ::GetVersionEx(&info) ) { - major = info.dwMajorVersion; - minor = info.dwMinorVersion; + s_major = info.dwMajorVersion; + s_minor = info.dwMinorVersion; switch ( info.dwPlatformId ) { case VER_PLATFORM_WIN32s: - ver = wxWIN32S; + s_ver = wxWIN32S; break; case VER_PLATFORM_WIN32_WINDOWS: - ver = wxWIN95; + s_ver = wxWIN95; break; case VER_PLATFORM_WIN32_NT: - ver = wxWINDOWS_NT; + s_ver = wxWINDOWS_NT; break; } } } - if (majorVsn && major != -1) - *majorVsn = major; - if (minorVsn && minor != -1) - *minorVsn = minor; - - return ver; -#else // Win16 - int retValue = wxWINDOWS; - #ifdef __WINDOWS_386__ - retValue = wxWIN386; - #else - #if !defined(__WATCOMC__) && !defined(GNUWIN32) && wxUSE_PENWINDOWS - extern HANDLE g_hPenWin; - retValue = g_hPenWin ? wxPENWINDOWS : wxWINDOWS; - #endif - #endif - - if (majorVsn) - *majorVsn = 3; - if (minorVsn) - *minorVsn = 1; + if ( verMaj ) + *verMaj = s_major; + if ( verMin ) + *verMin = s_minor; - return retValue; -#endif + return s_ver; } // ---------------------------------------------------------------------------- diff --git a/src/unix/baseunix.cpp b/src/unix/baseunix.cpp index ef7f1e1f9d..d28b5225c0 100644 --- a/src/unix/baseunix.cpp +++ b/src/unix/baseunix.cpp @@ -94,7 +94,7 @@ int wxConsoleAppTraits::GetOSVersion(int *verMaj, int *verMin) int major, minor; char name[256]; - if ( sscanf(WXWIN_OS_DESCRIPTION, "%s %d.%d", name, &major, &minor) != 3 ) + if ( sscanf(WXWIN_OS_DESCRIPTION, "%.255s %d.%d", name, &major, &minor) != 3 ) { // unreckognized uname string format major = diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 6cf4086cbf..b6c1fe4bf7 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -817,17 +817,6 @@ wxString wxGetOsDescription() #endif // !__WXMAC__ -int wxGetOsVersion(int *verMaj, int *verMin) -{ - // we want this function to work even if there is no wxApp - wxConsoleAppTraits traitsConsole; - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; - if ( ! traits ) - traits = &traitsConsole; - - return traits->GetOSVersion(verMaj, verMin); -} - unsigned long wxGetProcessId() { return (unsigned long)getpid(); -- 2.45.2