wxPlatformInfo (patch 1532064)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40599 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-08-13 21:00:32 +00:00
parent 10d878a9ea
commit 8bb6b2c057
38 changed files with 1378 additions and 567 deletions

View File

@@ -13,6 +13,7 @@
#define _WX_APPTRAIT_H_
#include "wx/string.h"
#include "wx/platinfo.h"
class WXDLLIMPEXP_BASE wxObject;
class WXDLLEXPORT wxAppTraits;
@@ -26,24 +27,6 @@ class WXDLLIMPEXP_BASE wxString;
class GSocketGUIFunctionsTable;
// ----------------------------------------------------------------------------
// toolkit information
// ----------------------------------------------------------------------------
// Information about the toolkit that the app is running under (e.g. wxMSW):
struct WXDLLIMPEXP_BASE wxToolkitInfo
{
// Short name of the toolkit (e.g. "msw" or "mswuniv"); empty for console:
wxString shortName;
// Descriptive name of the toolkit, human readable (e.g. "wxMSW" or
// "wxMSW/Universal"); "wxBase" for console apps:
wxString name;
// Version of the underlying toolkit or of the OS for console apps:
int versionMajor, versionMinor;
// OS mnenomics, e.g. wxGTK or wxMSW:
int os;
};
// ----------------------------------------------------------------------------
// wxAppTraits: this class defines various configurable aspects of wxApp
@@ -127,15 +110,10 @@ public:
virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0;
#endif
// return information about what toolkit is running; we need for two things
// that are both contained in wxBase:
// - 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
// - wxDynamicLibrary::CanonicalizePluginName() must embed toolkit
// signature in DLL name
virtual wxToolkitInfo& GetToolkitInfo() = 0;
// return information about the (native) toolkit currently used;
// returns wxPORT_BASE for console applications and one of the remaining
// wxPORT_* values for GUI applications.
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const = 0;
};
// ----------------------------------------------------------------------------
@@ -192,6 +170,17 @@ public:
virtual void ScheduleForDestroy(wxObject *object);
virtual void RemoveFromPendingDelete(wxObject *object);
// the GetToolkitVersion for console application is always the same
wxPortId GetToolkitVersion(int *verMaj, int *verMin) const
{
// no toolkits (wxBase is for console applications without GUI support)
// NB: zero means "no toolkit", -1 means "not initialized yet"
// so we must use zero here!
if (verMaj) *verMaj = 0;
if (verMin) *verMin = 0;
return wxPORT_BASE;
}
};
// ----------------------------------------------------------------------------
@@ -242,16 +231,13 @@ public:
#elif defined(__WXPM__)
#include "wx/os2/apptrait.h"
#else
// at least, we need an implementation of GetToolkitInfo !
#if wxUSE_GUI
class wxGUIAppTraits : public wxGUIAppTraitsBase
{
virtual wxToolkitInfo& GetToolkitInfo();
};
#endif // wxUSE_GUI
class wxConsoleAppTraits: public wxConsoleAppTraitsBase
{
virtual wxToolkitInfo& GetToolkitInfo();
};
#endif // platform

View File

@@ -664,68 +664,6 @@ typedef int wxWindowID;
# endif
#endif
/* ---------------------------------------------------------------------------- */
/* OS mnemonics -- Identify the running OS (useful for Windows) */
/* ---------------------------------------------------------------------------- */
/* Not all platforms are currently available or supported */
enum
{
wxUNKNOWN_PLATFORM,
wxCURSES, /* Text-only CURSES */
wxXVIEW_X, /* Sun's XView OpenLOOK toolkit */
wxMOTIF_X, /* OSF Motif 1.x.x */
wxCOSE_X, /* OSF Common Desktop Environment */
wxNEXTSTEP, /* NeXTStep */
wxMAC, /* Apple Mac OS 8/9/X with Mac paths */
wxMAC_DARWIN, /* Apple Mac OS X with Unix paths */
wxBEOS, /* BeOS */
wxGTK, /* GTK on X */
wxGTK_WIN32, /* GTK on Win32 */
wxGTK_OS2, /* GTK on OS/2 */
wxGTK_BEOS, /* GTK on BeOS */
wxGEOS, /* GEOS */
wxOS2_PM, /* OS/2 Workplace */
wxWINDOWS, /* Windows or WfW */
wxMICROWINDOWS, /* MicroWindows */
wxPENWINDOWS, /* Windows for Pen Computing */
wxWINDOWS_NT, /* Windows NT */
wxWIN32S, /* Windows 32S API */
wxWIN95, /* Windows 95 */
wxWIN386, /* Watcom 32-bit supervisor modus */
wxWINDOWS_CE, /* Windows CE (generic) */
wxWINDOWS_POCKETPC, /* Windows CE PocketPC */
wxWINDOWS_SMARTPHONE, /* Windows CE Smartphone */
wxMGL_UNIX, /* MGL with direct hardware access */
wxMGL_X, /* MGL on X */
wxMGL_WIN32, /* MGL on Win32 */
wxMGL_OS2, /* MGL on OS/2 */
wxMGL_DOS, /* MGL on MS-DOS */
wxWINDOWS_OS2, /* Native OS/2 PM */
wxUNIX, /* wxBase under Unix */
wxX11, /* Plain X11 and Universal widgets */
wxPALMOS, /* PalmOS */
wxDOS /* wxBase under MS-DOS */
};
/* Friendlier platform names */
enum
{
wxMotif = wxMOTIF_X,
wxMac = wxMAC,
wxMSW = wxWINDOWS,
wxWinCE = wxWINDOWS_CE,
wxWinPocketPC = wxWINDOWS_POCKETPC,
wxWinSmartPhone = wxWINDOWS_SMARTPHONE,
wxWin95= wxWIN95,
wxUnix = wxUNIX, /* wxBase under Unix */
wxPalmOS = wxPALMOS, /* PalmOS */
wxOS2 = wxOS2_PM,
wxMGL = 100,
wxCocoa
};
/* ---------------------------------------------------------------------------- */
/* standard wxWidgets types */
/* ---------------------------------------------------------------------------- */

View File

@@ -40,14 +40,6 @@ 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 returns same version for both console and GUI
// applications so we can implement it directly in the base class and only
// override it wxGUIAppTraits to fill in toolkit information
virtual wxToolkitInfo& GetToolkitInfo();
};
#endif // _WX_MSW_APPTBASE_H_

View File

@@ -36,7 +36,7 @@ public:
virtual void AfterChildWaitLoop(void *data);
virtual bool DoMessageFromThreadWait();
virtual wxToolkitInfo& GetToolkitInfo();
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
};
#endif // wxUSE_GUI

View File

@@ -19,7 +19,6 @@
class WXDLLIMPEXP_BASE wxConsoleAppTraits : public wxConsoleAppTraitsBase
{
public:
virtual wxToolkitInfo& GetToolkitInfo();
};
#if wxUSE_GUI
@@ -27,7 +26,7 @@ public:
class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase
{
public:
virtual wxToolkitInfo& GetToolkitInfo();
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
// wxThread helpers
// ----------------

View File

@@ -40,14 +40,6 @@ 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 returns same version for both console and GUI
// applications so we can implement it directly in the base class and only
// override it wxGUIAppTraits to fill in toolkit information
virtual wxToolkitInfo& GetToolkitInfo();
};
#endif // _WX_PALMOS_APPTBASE_H_

View File

@@ -36,7 +36,7 @@ public:
virtual void AfterChildWaitLoop(void *data);
virtual bool DoMessageFromThreadWait();
virtual wxToolkitInfo& GetToolkitInfo();
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
};
#endif // wxUSE_GUI

282
include/wx/platinfo.h Normal file
View File

@@ -0,0 +1,282 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/platinfo.h
// Purpose: declaration of the wxPlatformInfo class
// Author: Francesco Montorsi
// Modified by:
// Created: 07.07.2006 (based on wxToolkitInfo)
// RCS-ID: $Id$
// Copyright: (c) 2006 Francesco Montorsi
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PLATINFO_H_
#define _WX_PLATINFO_H_
#include "wx/defs.h"
// ----------------------------------------------------------------------------
// wxPlatformInfo
// ----------------------------------------------------------------------------
// VERY IMPORTANT: when changing these enum values, also change the relative
// string tables in src/common/platinfo.cpp
// families & sub-families of operating systems
enum wxOperatingSystemId
{
wxOS_UNKNOWN = 0, // returned on error
wxOS_MAC_OS = 1 << 0, // Apple Mac OS 8/9/X with Mac paths
wxOS_MAC_OSX_DARWIN = 1 << 1, // Apple Mac OS X with Unix paths
wxOS_MAC = wxOS_MAC_OS|wxOS_MAC_OSX_DARWIN,
wxOS_WINDOWS_9X = 1 << 2, // Windows 9x family (95/98/ME)
wxOS_WINDOWS_NT = 1 << 3, // Windows NT family (NT/2000/XP)
wxOS_WINDOWS_MICRO = 1 << 4, // MicroWindows
wxOS_WINDOWS_CE = 1 << 5, // Windows CE (Window Mobile)
wxOS_WINDOWS = wxOS_WINDOWS_9X |
wxOS_WINDOWS_NT |
wxOS_WINDOWS_MICRO |
wxOS_WINDOWS_CE,
wxOS_UNIX_LINUX = 1 << 6, // Linux
wxOS_UNIX_FREEBSD = 1 << 7, // FreeBSD
wxOS_UNIX_OPENBSD = 1 << 8, // OpenBSD
wxOS_UNIX_NETBSD = 1 << 9, // NetBSD
wxOS_UNIX_SOLARIS = 1 << 10, // SunOS
wxOS_UNIX_AIX = 1 << 11, // AIX
wxOS_UNIX_HPUX = 1 << 12, // HP/UX
wxOS_UNIX = wxOS_UNIX_LINUX |
wxOS_UNIX_FREEBSD |
wxOS_UNIX_OPENBSD |
wxOS_UNIX_NETBSD |
wxOS_UNIX_SOLARIS |
wxOS_UNIX_AIX |
wxOS_UNIX_HPUX,
// 1<<13 and 1<<14 available for other Unix flavours
wxOS_DOS = 1 << 15, // Microsoft DOS
wxOS_OS2 = 1 << 16 // OS/2
};
// list of wxWidgets ports - some of them can be used with more than
// a single toolkit.
enum wxPortId
{
wxPORT_UNKNOWN = 0, // returned on error
wxPORT_BASE = 1 << 0, // wxBase, no native toolkit used
wxPORT_MSW = 1 << 1, // wxMSW, native toolkit is Windows API
wxPORT_MOTIF = 1 << 2, // wxMotif, using [Open]Motif or Lesstif
wxPORT_GTK = 1 << 3, // wxGTK, using GTK+ 1.x, 2.x, GPE or Maemo
wxPORT_MGL = 1 << 4, // wxMGL, using wxUniversal
wxPORT_X11 = 1 << 5, // wxX11, using wxUniversal
wxPORT_OS2 = 1 << 6, // wxOS2, using OS/2 Presentation Manager
wxPORT_MAC = 1 << 7, // wxMac, using Carbon or Classic Mac API
wxPORT_COCOA = 1 << 8, // wxCocoa, using Cocoa NextStep/Mac API
wxPORT_WINCE = 1 << 9, // wxWinCE, toolkit is WinCE SDK API
wxPORT_PALMOS = 1 << 10 // wxPalmOS, toolkit is PalmOS API
};
// architecture of the operating system
// (regardless of the build environment of wxWidgets library - see
// wxIsPlatform64bit documentation for more info)
enum wxArchitecture
{
wxARCH_INVALID = -1, // returned on error
wxARCH_32, // 32 bit
wxARCH_64,
wxARCH_MAX
};
// endian-ness of the machine
enum wxEndianness
{
wxENDIAN_INVALID = -1, // returned on error
wxENDIAN_BIG, // 4321
wxENDIAN_LITTLE, // 1234
wxENDIAN_PDP, // 3412
wxENDIAN_MAX
};
// Information about the toolkit that the app is running under and some basic
// platform and architecture info
class WXDLLIMPEXP_BASE wxPlatformInfo
{
public:
wxPlatformInfo();
wxPlatformInfo(wxPortId pid,
int tkMajor = -1, int tkMinor = -1,
wxOperatingSystemId id = wxOS_UNKNOWN,
int osMajor = -1, int osMinor = -1,
wxArchitecture arch = wxARCH_INVALID,
wxEndianness endian = wxENDIAN_INVALID);
// default copy ctor, assignment operator and dtor are ok
bool operator==(const wxPlatformInfo &t) const;
bool operator!=(const wxPlatformInfo &t) const
{ return !(*this == t); }
// string -> enum conversions
// ---------------------------------
static wxOperatingSystemId GetOperatingSystemId(const wxString &name);
static wxPortId GetPortId(const wxString &portname);
static wxArchitecture GetArch(const wxString &arch);
static wxEndianness GetEndianness(const wxString &end);
// enum -> string conversions
// ---------------------------------
static wxString GetOperatingSystemFamilyName(wxOperatingSystemId os);
static wxString GetOperatingSystemIdName(wxOperatingSystemId os);
static wxString GetPortIdName(wxPortId port);
static wxString GetPortIdShortName(wxPortId port);
static wxString GetArchName(wxArchitecture arch);
static wxString GetEndiannessName(wxEndianness end);
// getters
// -----------------
int GetOSMajorVersion() const
{ return m_osVersionMajor; }
int GetOSMinorVersion() const
{ return m_osVersionMinor; }
int GetToolkitMajorVersion() const
{ return m_tkVersionMajor; }
int GetToolkitMinorVersion() const
{ return m_tkVersionMinor; }
wxOperatingSystemId GetOperatingSystemId() const
{ return m_os; }
wxPortId GetPortId() const
{ return m_port; }
wxArchitecture GetArchitecture() const
{ return m_arch; }
wxEndianness GetEndianness() const
{ return m_endian; }
// string getters
// -----------------
wxString GetOperatingSystemFamilyName() const
{ return GetOperatingSystemFamilyName(m_os); }
wxString GetOperatingSystemIdName() const
{ return GetOperatingSystemIdName(m_os); }
wxString GetPortIdName() const
{ return GetPortIdName(m_port); }
wxString GetPortIdShortName() const
{ return GetPortIdShortName(m_port); }
wxString GetArchName() const
{ return GetArchName(m_arch); }
wxString GetEndiannessName() const
{ return GetEndiannessName(m_endian); }
// setters
// -----------------
void SetOSVersion(int major, int minor)
{ m_osVersionMajor=major; m_osVersionMinor=minor; }
void SetToolkitVersion(int major, int minor)
{ m_tkVersionMajor=major; m_tkVersionMinor=minor; }
void SetOperatingSystemId(wxOperatingSystemId n)
{ m_os=n; }
void SetPortId(wxPortId n)
{ m_port=n; }
void SetArchitecture(wxArchitecture n)
{ m_arch=n; }
void SetEndianness(wxEndianness n)
{ m_endian=n; }
// miscellaneous
// -----------------
bool IsOk() const
{
return m_osVersionMajor != -1 && m_osVersionMinor != -1 &&
m_os != wxOS_UNKNOWN &&
m_tkVersionMajor != -1 && m_tkVersionMinor != -1 &&
m_port != wxPORT_UNKNOWN &&
m_arch != wxARCH_INVALID && m_endian != wxENDIAN_INVALID;
}
static bool IsUsingUniversalWidgets()
{
#ifdef __WXUNIVERSAL__
return true;
#else
return false;
#endif
}
protected:
// OS stuff
// -----------------
// Version of the OS; valid if m_os != wxOS_UNKNOWN
// (-1 means not initialized yet).
int m_osVersionMajor, m_osVersionMinor;
// Operating system ID.
wxOperatingSystemId m_os;
// toolkit
// -----------------
// Version of the underlying toolkit
// (-1 means not initialized yet; zero means no toolkit).
int m_tkVersionMajor, m_tkVersionMinor;
// name of the wxWidgets port
wxPortId m_port;
// others
// -----------------
// architecture of the OS
wxArchitecture m_arch;
// endianness of the machine
wxEndianness m_endian;
};
#if WXWIN_COMPATIBILITY_2_6
#define wxUNKNOWN_PLATFORM wxOS_UNKNOWN
#define wxUnix wxOS_UNIX
#define wxWin95 wxOS_WINDOWS_9X
#define wxWIN95 wxOS_WINDOWS_9X
#define wxWINDOWS_NT wxOS_WINDOWS_NT
#define wxMSW wxOS_WINDOWS
#define wxWinCE wxOS_WINDOWS_CE
#define wxWIN32S wxOS_WINDOWS_9X
#define wxPalmOS wxPORT_PALMOS
#define wxOS2 wxPORT_OS2
#define wxMGL wxPORT_MGL
#define wxCocoa wxPORT_MAC
#define wxMac wxPORT_MAC
#define wxMotif wxPORT_MOTIF
#define wxGTK wxPORT_GTK
#endif // WXWIN_COMPATIBILITY_2_6
#endif // _WX_PLATINFO_H_

View File

@@ -23,8 +23,6 @@ public:
virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd);
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
virtual int WaitForChild(wxExecuteData& execData);
virtual wxToolkitInfo& GetToolkitInfo();
};
#if wxUSE_GUI
@@ -40,7 +38,7 @@ public:
#if defined(__WXMAC__) || defined(__WXCOCOA__)
virtual wxStandardPathsBase& GetStandardPaths();
#endif
virtual wxToolkitInfo& GetToolkitInfo();
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
};
#endif // wxUSE_GUI

View File

@@ -30,6 +30,9 @@ class WXDLLIMPEXP_BASE wxArrayInt;
// wxLongLong
#include "wx/longlong.h"
// need for wxOperatingSystemId
#include "wx/platinfo.h"
#ifdef __WATCOMC__
#include <direct.h>
#elif defined(__X__)
@@ -93,8 +96,14 @@ WXDLLIMPEXP_BASE void wxBell();
WXDLLIMPEXP_BASE wxString wxGetOsDescription();
// Get OS version
WXDLLIMPEXP_BASE int wxGetOsVersion(int *majorVsn = (int *) NULL,
int *minorVsn = (int *) NULL);
WXDLLIMPEXP_BASE wxOperatingSystemId wxGetOsVersion(int *majorVsn = (int *) NULL,
int *minorVsn = (int *) NULL);
// Get platform endianness
WXDLLIMPEXP_BASE bool wxIsPlatformLittleEndian();
// Get platform architecture
WXDLLIMPEXP_BASE bool wxIsPlatform64Bit();
// Return a string with the current date/time
WXDLLIMPEXP_BASE wxString wxNow();