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
This commit is contained in:
Vadim Zeitlin 2003-06-27 00:16:04 +00:00
parent 18f0a2c5aa
commit 2739d4f052
7 changed files with 51 additions and 63 deletions

View File

@ -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;
};
// ----------------------------------------------------------------------------

View File

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

View File

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

View File

@ -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 <ctype.h>
#include <stdio.h>
@ -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)

View File

@ -31,6 +31,8 @@
#include "wx/log.h"
#endif //WX_PRECOMP
#include "wx/apptrait.h"
#include "wx/msw/private.h" // includes <windows.h>
#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;
if ( verMaj )
*verMaj = s_major;
if ( verMin )
*verMin = s_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;
return retValue;
#endif
return s_ver;
}
// ----------------------------------------------------------------------------

View File

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

View File

@ -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();