From 8bb6b2c057edbcc5b87f00a8af6ac70f6fd69727 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 13 Aug 2006 21:00:32 +0000 Subject: [PATCH] wxPlatformInfo (patch 1532064) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40599 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- build/bakefiles/files.bkl | 2 + docs/changes.txt | 1 + docs/latex/wx/apptraits.tex | 23 +- docs/latex/wx/classes.tex | 1 + docs/latex/wx/function.tex | 65 ++++-- docs/latex/wx/platinfo.tex | 392 +++++++++++++++++++++++++++++++++++ include/wx/apptrait.h | 46 ++-- include/wx/defs.h | 62 ------ include/wx/msw/apptbase.h | 8 - include/wx/msw/apptrait.h | 2 +- include/wx/os2/apptrait.h | 3 +- include/wx/palmos/apptbase.h | 8 - include/wx/palmos/apptrait.h | 2 +- include/wx/platinfo.h | 282 +++++++++++++++++++++++++ include/wx/unix/apptrait.h | 4 +- include/wx/utils.h | 13 +- samples/console/console.cpp | 32 ++- src/common/dynlib.cpp | 8 +- src/common/intl.cpp | 10 +- src/common/platinfo.cpp | 297 ++++++++++++++++++++++++++ src/common/utilscmn.cpp | 22 +- src/common/wincmn.cpp | 76 ++----- src/gtk/utilsgtk.cpp | 31 +-- src/gtk1/utilsgtk.cpp | 29 ++- src/mac/carbon/utils.cpp | 36 +--- src/mac/classic/utils.cpp | 47 ++--- src/mgl/utils.cpp | 52 +---- src/motif/utils.cpp | 28 +-- src/msdos/utilsdos.cpp | 26 ++- src/msw/app.cpp | 31 +-- src/msw/utils.cpp | 84 ++++---- src/os2/utils.cpp | 15 +- src/os2/utilsgui.cpp | 27 +-- src/palmos/app.cpp | 16 +- src/palmos/utils.cpp | 9 +- src/unix/baseunix.cpp | 42 ---- src/unix/utilsunx.cpp | 86 ++++++-- src/x11/utils.cpp | 21 +- 38 files changed, 1375 insertions(+), 564 deletions(-) create mode 100644 docs/latex/wx/platinfo.tex create mode 100644 include/wx/platinfo.h create mode 100644 src/common/platinfo.cpp diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index b6e0335b80..2e1a14d6d7 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -323,6 +323,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/common/module.cpp src/common/mstream.cpp src/common/object.cpp + src/common/platinfo.cpp src/common/powercmn.cpp src/common/process.cpp src/common/regex.cpp @@ -421,6 +422,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/mstream.h wx/object.h wx/platform.h + wx/platinfo.h wx/power.h wx/process.h wx/ptr_scpd.h diff --git a/docs/changes.txt b/docs/changes.txt index 694bd0ccd6..cf84ea1b1f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -51,6 +51,7 @@ Major changes in 2.7 release All: - Added wxDir::FindFirst() (Francesco Montorsi) +- Added wxPlatformInfo class (Francesco Montorsi) All (GUI): diff --git a/docs/latex/wx/apptraits.tex b/docs/latex/wx/apptraits.tex index f50a1c01d3..6c8074cf66 100644 --- a/docs/latex/wx/apptraits.tex +++ b/docs/latex/wx/apptraits.tex @@ -36,12 +36,27 @@ None \latexignore{\rtfignore{\wxheading{Members}}} -\membersection{wxAppTraits::GetToolkitInfo}\label{wxapptraitsgettoolkitinfo} +\membersection{wxAppTraits::GetPlatformInfo}\label{wxapptraitsgetplatforminfo} -\func{virtual wxToolkitInfo \&}{GetToolkitInfo}{\void} +\func{virtual wxPlatformInfo \&}{GetPlatformInfo}{\void} + +Returns information about which platform is the program running on. +See \helpref{wxPlatformInfo}{wxplatforminfo} for more details. + + +\membersection{wxAppTraits::GetToolkitVersion}\label{wxapptraitsgettoolkitversion} + +\func{virtual wxPortId}{GetToolkitVersion}{\param{int *}{major = NULL}, \param{int *}{minor = NULL}} + +Returns the wxWidgets port ID used by the running program and eventually +fills the given pointers with the values of the major and minor digits +of the native toolkit currently used. + +E.g. if your program is using wxGTK port this function will return wxPORT_GTK and +put in given pointers the versions of the GTK library in use. + +See \helpref{wxPlatformInfo}{wxplatforminfo} for more details. -Returns information about which toolkit is running. See \helpref{wxToolkitInfo}{wxtoolkitinfo} -for more details. \membersection{wxAppTraits::HasStderr}\label{wxapptraitshasstderr} diff --git a/docs/latex/wx/classes.tex b/docs/latex/wx/classes.tex index befff7981c..4c8ef85674 100644 --- a/docs/latex/wx/classes.tex +++ b/docs/latex/wx/classes.tex @@ -264,6 +264,7 @@ \input pathlist.tex \input pen.tex \input pickerbase.tex +\input platinfo.tex \input point.tex \input postscpt.tex \input powerevt.tex diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex index 4a8f89a7a1..f3565f5b8e 100644 --- a/docs/latex/wx/function.tex +++ b/docs/latex/wx/function.tex @@ -173,6 +173,8 @@ the corresponding topic. \helpref{wxIsEmpty}{wxisempty}\\ \helpref{wxIsMainThread}{wxismainthread}\\ \helpref{wxIsNaN}{wxisnan}\\ +\helpref{wxIsPlatformLittleEndian}{wxisplatformlittleendian}\\ +\helpref{wxIsPlatform64Bit}{wxisplatform64bit}\\ \helpref{wxIsWild}{wxiswild}\\ \helpref{wxKill}{wxkill}\\ \helpref{wxLaunchDefaultBrowser}{wxlaunchdefaultbrowser}\\ @@ -1404,32 +1406,49 @@ user-readable form. For example, this function may return strings like \membersection{::wxGetOsVersion}\label{wxgetosversion} -\func{int}{wxGetOsVersion}{\param{int *}{major = NULL}, \param{int *}{minor = NULL}} +\func{wxOperatingSystemId}{wxGetOsVersion}{\param{int *}{major = NULL}, \param{int *}{minor = NULL}} -Gets operating system version information. +Gets the version and the operating system ID for currently running OS. +See \helpref{wxPlatformInfo}{wxplatforminfo} for more details about wxOperatingSystemId. -\begin{twocollist}\itemsep=0pt -\twocolitemruled{Platform}{Return types} -\twocolitem{Mac OS}{Return value is wxMAC when compiled with CodeWarrior under Mac OS 8.x/9.x and Mac OS X, wxMAC\_DARWIN when compiled with the Apple Developer Tools under Mac OS X. - -Both {\it major} and {\it minor} have to be looked at as hexadecimal numbers. So System 10.2.4 returns 0x10, resp 16 for {\it major} and 0x24, resp 36 for {\it minor}. } -\twocolitem{GTK}{Return value is wxGTK, For GTK 1.0, {\it major} is 1, {\it minor} is 0. } -\twocolitem{Motif}{Return value is wxMOTIF\_X, {\it major} is X version, {\it minor} is X revision.} -\twocolitem{OS/2}{Return value is wxOS2\_PM.} -\twocolitem{Windows 3.1}{Return value is wxWINDOWS, {\it major} is 3, {\it minor} is 1.} -\twocolitem{Windows NT/2000}{Return value is wxWINDOWS\_NT, version is returned in {\it major} and {\it minor}.} -\twocolitem{Windows 98}{Return value is wxWIN95, {\it major} is 4, {\it minor} is 1 or greater.} -\twocolitem{Windows 95}{Return value is wxWIN95, {\it major} is 4, {\it minor} is 0.} -\twocolitem{Win32s (Windows 3.1)}{Return value is wxWIN32S, {\it major} is 3, {\it minor} is 1.} -\twocolitem{Windows PocketPC}{Return value is wxWINDOWS\_POCKETPC, version is returned in {\it major} and {\it minor}.} -\twocolitem{Windows Smartphone}{Return value is wxWINDOWS\_SMARTPHONE, version is returned in {\it major} and {\it minor}.} -\twocolitem{Windows CE (non-specific)}{Return value is wxWINDOWS\_CE, version is returned in {\it major} and {\it minor}.} -\twocolitem{Watcom C++ 386 supervisor mode (Windows 3.1)}{Return value is wxWIN386, {\it major} is 3, {\it minor} is 1.} -\end{twocollist} +\wxheading{See also} + +\helpref{::wxGetOsDescription}{wxgetosdescription}, +\helpref{wxPlatformInfo}{wxplatforminfo} + +\wxheading{Include files} + + + + +\membersection{::wxIsPlatformLittleEndian}\label{wxisplatformlittleendian} + +\func{bool}{wxIsPlatformLittleEndian}{\void} + +Returns \true if the current platform is little endian (instead of big endian). +The check is performed at run-time. \wxheading{See also} -\helpref{::wxGetOsDescription}{wxgetosdescription} +\helpref{Byte order macros}{byteordermacros} + +\wxheading{Include files} + + + + +\membersection{::wxIsPlatform64Bit}\label{wxisplatform64bit} + +\func{bool}{wxIsPlatform64Bit}{\void} + +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 available at +compile-time (at compile-time you can just check if {\tt sizeof(void*)==8}) +since the program could be running in emulation mode or in a mixed 32/64 bit system +(bi-architecture operating system). + +Very important: this function is not 100\% reliable on some systems given the fact +that there isn't always a standard way to do a reliable check on the OS architecture. \wxheading{Include files} @@ -3233,8 +3252,8 @@ used only in the menu items and are separated from the main text by the \texttt{wxStrip\_Mnemonics} or \texttt{wxStrip\_Accel} to strip only the former or the latter part, respectively. -Notice that in most cases -\helpref{wxMenuItem::GetLabelFromText}{wxmenuitemgetlabelfromtext} or +Notice that in most cases +\helpref{wxMenuItem::GetLabelFromText}{wxmenuitemgetlabelfromtext} or \helpref{wxControl::GetLabelText}{wxcontrolgetlabeltext} can be used instead. \wxheading{Include files} diff --git a/docs/latex/wx/platinfo.tex b/docs/latex/wx/platinfo.tex new file mode 100644 index 0000000000..78d075fd89 --- /dev/null +++ b/docs/latex/wx/platinfo.tex @@ -0,0 +1,392 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Name: platinfo.tex +%% Purpose: wxPlatformInfo +%% Author: Francesco Montorsi +%% Modified by: +%% Created: 31-7-2006 +%% RCS-ID: $Id$ +%% Copyright: (c) wxWidgets Team +%% License: wxWindows license +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\section{\class{wxPlatformInfo}}\label{wxplatforminfo} + +This class holds informations about the operating system and the toolkit that the application +is running under and some basic architecture info of the machine where it's running. + +\wxheading{Derived from} + +\helpref{wxObject}{wxobject} + +\wxheading{Include files} + + + +\wxheading{See also} + +\helpref{wxGetOSVersion}{wxgetosversion}, \helpref{wxIsPlatformLittleEndian}{wxisplatformlittleendian}, +\helpref{wxIsPlatform64Bit}{wxisplatform64bit}, \helpref{wxAppTraits}{wxapptraits} + +\wxheading{Data structures} + +The following are the operating systems which are recognized by wxWidgets +and whose version can be detected at run-time. The values of the constants +are chosen so that they can be combined as flags; this allows to check +for operating system {\it families} like e.g. wxOS\_MAC and wxOS\_UNIX. + +\begin{verbatim} +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, + + wxOS_DOS = 1 << 15, // Microsoft DOS + wxOS_OS2 = 1 << 16 // OS/2 +}; +\end{verbatim} + +The list of wxWidgets ports. Some of them can be used with more than +a single (native) toolkit; e.g. wxWinCE port sources can be used with +smartphones, pocket PCs and handheld devices SDKs. + +\begin{verbatim} +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 +}; +\end{verbatim} + +The architecture of the operating system (regardless of the build environment +of wxWidgets library - see \helpref{wxIsPlatform64bit}{wxisplatform64bit} documentation +for more info). + +\begin{verbatim} +enum wxArchitecture +{ + wxARCH_INVALID = -1, // returned on error + + wxARCH_32, // 32 bit + wxARCH_64, + + wxARCH_MAX +} +\end{verbatim} + +The endian-ness of the machine. + +\begin{verbatim} +enum wxEndianness +{ + wxENDIAN_INVALID = -1, // returned on error + + wxENDIAN_BIG, // 4321 + wxENDIAN_LITTLE, // 1234 + wxENDIAN_PDP, // 3412 + + wxENDIAN_MAX +} +\end{verbatim} + +\latexignore{\rtfignore{\wxheading{Members}}} + + +\membersection{wxPlatformInfo::wxPlatformInfo}\label{wxplatforminfowxplatforminfo} + +\func{}{wxPlatformInfo}{} + +Initializes the instance with the values corresponding to the currently running platform. + +\func{}{wxPlatformInfo}{\param{wxPortId }{pid = wxPORT\_UNKNOWN}, \param{int }{tkMajor = -1}, \param{int }{tkMinor = -1}, \param{wxOperatingSystemId }{id = wxOS\_UNKNOWN}, \param{int }{osMajor = -1}, \param{int }{osMinor = -1}, \param{wxArchitecture }{arch = wxARCH\_INVALID}, \param{wxEndianness }{endian = wxENDIAN\_INVALID}} + +Initializes the object using given values. + + + + +\membersection{wxPlatformInfo::GetArch}\label{wxplatforminfogetarch} + +\func{static wxArchitecture}{GetArch}{\param{const wxString\& }{arch}} + +Converts the given string to a wxArchitecture enum value or to +wxARCH_INVALID if the given string is not a valid architecture string +(i.e. does not contain nor {\tt 32} nor {\tt 64} strings). + + +\membersection{wxPlatformInfo::GetArchName}\label{wxplatforminfogetarchname} + +\func{static wxString}{GetArchName}{\param{wxArchitecture }{arch}} + +Returns the name for the given wxArchitecture enumeration value. + +\constfunc{wxString}{GetArchName}{\void} + +Returns the name for the architecture of this wxPlatformInfo instance. + + +\membersection{wxPlatformInfo::GetArchitecture}\label{wxplatforminfogetarchitecture} + +\constfunc{wxArchitecture}{GetArchitecture}{\void} + +Returns the architecture ID of this wxPlatformInfo instance. + + + + +\membersection{wxPlatformInfo::GetEndianness}\label{wxplatforminfogetendianness} + +\func{static wxEndianness}{GetEndianness}{\param{const wxString\& }{end}} + +Converts the given string to a wxEndianness enum value or to +wxENDIAN_INVALID if the given string is not a valid endianness string +(i.e. does not contain nor {\tt little} nor {\tt big} strings). + +\constfunc{wxEndianness}{GetEndianness}{\void} + +Returns the endianness ID of this wxPlatformInfo instance. + +\membersection{wxPlatformInfo::GetEndiannessName}\label{wxplatforminfogetendiannessname} + +\func{static wxString}{GetEndiannessName}{\param{wxEndianness }{end}} + +Returns name for the given wxEndianness enumeration value. + +\constfunc{wxString}{GetEndiannessName}{\void} + +Returns the name for the endianness of this wxPlatformInfo instance. + + + + + +\membersection{wxPlatformInfo::GetOSMajorVersion}\label{wxplatforminfogetosmajorversion} + +\constfunc{int}{GetOSMajorVersion}{\void} + +Returns the major version of the OS associated with this wxPlatformInfo instance. + +\membersection{wxPlatformInfo::GetOSMinorVersion}\label{wxplatforminfogetosminorversion} + +\constfunc{int}{GetOSMinorVersion}{\void} + +Returns the minor version of the OS associated with this wxPlatformInfo instance. + + + + +\membersection{wxPlatformInfo::GetOperatingSystemFamilyName}\label{wxplatforminfogetoperatingsystemfamilyname} + +\func{static wxString}{GetOperatingSystemFamilyName}{\param{wxOperatingSystemId }{os}} + +Returns the operating system family name for the given wxOperatingSystemId enumeration value: +{\tt Unix} for wxOS_UNIX, {\tt Macintosh} for wxOS_MAC, {\tt Windows} for wxOS_WINDOWS, +{\tt DOS} for wxOS_DOS, {\tt OS/2} for wxOS_OS2. + +\constfunc{wxString}{GetOperatingSystemFamilyName}{\void} + +Returns the operating system family name of the OS associated with this wxPlatformInfo instance. + + + +\membersection{wxPlatformInfo::GetOperatingSystemId}\label{wxplatforminfogetoperatingsystemid} + +\func{static wxOperatingSystemId}{GetOperatingSystemId}{\param{const wxString\& }{name}} + +Converts the given string to a wxOperatingSystemId enum value or to +wxOS_UNKNOWN if the given string is not a valid operating system name. + +\constfunc{wxOperatingSystemId}{GetOperatingSystemId}{\void} + +Returns the operating system ID of this wxPlatformInfo instance. + + + +\membersection{wxPlatformInfo::GetOperatingSystemIdName}\label{wxplatforminfogetoperatingsystemidname} + +\func{static wxString}{GetOperatingSystemIdName}{\param{wxOperatingSystemId }{os}} + +Returns the name for the given operating system ID value. This can be a long name +(e.g. {\tt Microsoft Windows NT}); use \helpref{GetOperatingSystemFamilyName}{wxplatforminfogetoperatingsystemfamilyname} to +retrieve a short, generic name. + + +\constfunc{wxString}{GetOperatingSystemIdName}{\void} + +Returns the operating system name of the OS associated with this wxPlatformInfo instance. + + + + + +\membersection{wxPlatformInfo::GetPortId}\label{wxplatforminfogetportid} + +\func{static wxPortId}{GetPortId}{\param{const wxString\& }{portname}} + +Converts the given string to a wxWidgets port ID value or to wxPORT_UNKNOWN if +the given string does not match any of the wxWidgets canonical name ports ("wxGTK", "wxMSW", etc) +nor any of the short wxWidgets name ports ("gtk", "msw", etc). + +\constfunc{wxPortId}{GetPortId}{\void} + +Returns the wxWidgets port ID associated with this wxPlatformInfo instance. + +\membersection{wxPlatformInfo::GetPortIdName}\label{wxplatforminfogetportidname} + +\func{static wxString}{GetPortIdName}{\param{wxPortId }{port}} + +Returns the name of the given wxWidgets port ID value. The returned string always starts with +the "wx" prefix and is a mixed-case string. + +\constfunc{wxString}{GetPortIdName}{\void} + +Returns the name of the wxWidgets port ID associated with this wxPlatformInfo instance. + + + + +\membersection{wxPlatformInfo::GetPortIdShortName}\label{wxplatforminfogetportidshortname} + +\func{static wxString}{GetPortIdShortName}{\param{wxPortId }{port}} + +Returns the short name of the given wxWidgets port ID value. The returned string does not start with +the "wx" prefix and is always lower case. + +\constfunc{wxString}{GetPortIdShortName}{\void} + +Returns the short name of the wxWidgets port ID associated with this wxPlatformInfo instance. + + + + +\membersection{wxPlatformInfo::GetToolkitMajorVersion}\label{wxplatforminfogettoolkitmajorversion} + +\constfunc{int}{GetToolkitMajorVersion}{\void} + +Returns the major version of the toolkit associated with this wxPlatformInfo instance. +Note that if {GetPortId}{wxplatforminfogetportid} returns wxPORT_BASE, then this value is zero (unless externally modified with SetToolkitVersion); that is, no native toolkit is in use. + +\membersection{wxPlatformInfo::GetToolkitMinorVersion}\label{wxplatforminfogettoolkitminorversion} + +\constfunc{int}{GetToolkitMinorVersion}{\void} + +Returns the minor version of the toolkit associated with this wxPlatformInfo instance. +Note that if {GetPortId}{wxplatforminfogetportid} returns wxPORT_BASE, then this value is zero (unless externally modified with SetToolkitVersion); that is, no native toolkit is in use. + + + + +\membersection{wxPlatformInfo::IsOk}\label{wxplatforminfoisok} + +\constfunc{bool}{IsOk}{\void} + +Returns \true if this instance is fully initialized with valid values. + + + +\membersection{wxPlatformInfo::IsUsingUniversalWidgets}\label{wxplatforminfoisusinguniversalwidgets} + +\func{bool}{IsUsingUniversalWidgets}{\void} + +Returns \true if __WXUNIVERSAL__ symbol is defined. Note that this function always +returns a constant value defined at compile-time and exists just for completeness. + + +\membersection{wxPlatformInfo::SetArchitecture}\label{wxplatforminfosetarchitecture} + +\func{void}{SetArchitecture}{\param{wxArchitecture }{n}} + +Sets the architecture enum value associated with this wxPlatformInfo instance. + + + +\membersection{wxPlatformInfo::SetEndianness}\label{wxplatforminfosetendianness} + +\func{void}{SetEndianness}{\param{wxEndianness }{n}} + +Sets the endianness enum value associated with this wxPlatformInfo instance. + + +\membersection{wxPlatformInfo::SetOSVersion}\label{wxplatforminfosetosversion} + +\func{void}{SetOSVersion}{\param{int }{major}, \param{int }{minor}} + +Sets the version of the operating system associated with this wxPlatformInfo instance. + + + +\membersection{wxPlatformInfo::SetOperatingSystemId}\label{wxplatforminfosetoperatingsystemid} + +\func{void}{SetOperatingSystemId}{\param{wxOperatingSystemId }{n}} + +Sets the operating system associated with this wxPlatformInfo instance. + + + +\membersection{wxPlatformInfo::SetPortId}\label{wxplatforminfosetportid} + +\func{void}{SetPortId}{\param{wxPortId }{n}} + +Sets the wxWidgets port ID associated with this wxPlatformInfo instance. + + + +\membersection{wxPlatformInfo::SetToolkitVersion}\label{wxplatforminfosettoolkitversion} + +\func{void}{SetToolkitVersion}{\param{int }{major}, \param{int }{minor}} + +Sets the version of the toolkit associated with this wxPlatformInfo instance. + + + +\membersection{wxPlatformInfo::operator!=}\label{wxplatforminfooperatorunknown} + +\constfunc{bool}{operator!=}{\param{const wxPlatformInfo\& }{t}} + +Inequality operator. Tests all class' internal variables. + + +\membersection{wxPlatformInfo::operator==}\label{wxplatforminfooperatorequal} + +\constfunc{bool}{operator==}{\param{const wxPlatformInfo\& }{t}} + +Equality operator. Tests all class' internal variables. + diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index ef7686fd46..12d9dba4ac 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -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 diff --git a/include/wx/defs.h b/include/wx/defs.h index f40be35174..64fcabb534 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -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 */ /* ---------------------------------------------------------------------------- */ diff --git a/include/wx/msw/apptbase.h b/include/wx/msw/apptbase.h index 6105eca8ee..d9c7e9d8ea 100644 --- a/include/wx/msw/apptbase.h +++ b/include/wx/msw/apptbase.h @@ -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_ diff --git a/include/wx/msw/apptrait.h b/include/wx/msw/apptrait.h index 55e0cf3e27..5d3e733ef3 100644 --- a/include/wx/msw/apptrait.h +++ b/include/wx/msw/apptrait.h @@ -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 diff --git a/include/wx/os2/apptrait.h b/include/wx/os2/apptrait.h index 2ac1f4a891..c4b107a0ed 100644 --- a/include/wx/os2/apptrait.h +++ b/include/wx/os2/apptrait.h @@ -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 // ---------------- diff --git a/include/wx/palmos/apptbase.h b/include/wx/palmos/apptbase.h index 1356d26cb2..b86e9cf3d4 100644 --- a/include/wx/palmos/apptbase.h +++ b/include/wx/palmos/apptbase.h @@ -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_ diff --git a/include/wx/palmos/apptrait.h b/include/wx/palmos/apptrait.h index f01d5b8fb3..cfe8fde4f9 100644 --- a/include/wx/palmos/apptrait.h +++ b/include/wx/palmos/apptrait.h @@ -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 diff --git a/include/wx/platinfo.h b/include/wx/platinfo.h new file mode 100644 index 0000000000..6169cb1069 --- /dev/null +++ b/include/wx/platinfo.h @@ -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_ diff --git a/include/wx/unix/apptrait.h b/include/wx/unix/apptrait.h index 964413cde7..a7870cbdd1 100644 --- a/include/wx/unix/apptrait.h +++ b/include/wx/unix/apptrait.h @@ -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 diff --git a/include/wx/utils.h b/include/wx/utils.h index 237793b05d..549899ae7c 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -30,6 +30,9 @@ class WXDLLIMPEXP_BASE wxArrayInt; // wxLongLong #include "wx/longlong.h" +// need for wxOperatingSystemId +#include "wx/platinfo.h" + #ifdef __WATCOMC__ #include #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(); diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 73c652357b..23c2eb4b0c 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -25,6 +25,8 @@ #include "wx/file.h" #include "wx/app.h" #include "wx/log.h" +#include "wx/apptrait.h" +#include "wx/platinfo.h" // without this pragma, the stupid compiler precompiles #defines below so that // changing them doesn't "take place" later! @@ -86,7 +88,7 @@ #define TEST_WCHAR #define TEST_ZIP #else // #if TEST_ALL - #define TEST_MODULE + #define TEST_INFO_FUNCTIONS #endif // some tests are interactive, define this to run them @@ -1510,6 +1512,23 @@ static void TestOsInfo() wxPuts(wxEmptyString); } +static void TestPlatformInfo() +{ + wxPuts(_T("*** Testing wxPlatformInfo functions ***\n")); + + // get this platform + wxPlatformInfo plat; + + wxPrintf(_T("Operating system family name is: %s\n"), plat.GetOperatingSystemFamilyName().c_str()); + wxPrintf(_T("Operating system name is: %s\n"), plat.GetOperatingSystemIdName().c_str()); + wxPrintf(_T("Port ID name is: %s\n"), plat.GetPortIdName().c_str()); + wxPrintf(_T("Port ID short name is: %s\n"), plat.GetPortIdShortName().c_str()); + wxPrintf(_T("Architecture is: %s\n"), plat.GetArchName().c_str()); + wxPrintf(_T("Endianness is: %s\n"), plat.GetEndiannessName().c_str()); + + wxPuts(wxEmptyString); +} + static void TestUserInfo() { wxPuts(_T("*** Testing user info functions ***\n")); @@ -4332,13 +4351,12 @@ int main(int argc, char **argv) #endif // TEST_MIME #ifdef TEST_INFO_FUNCTIONS - #if TEST_ALL - TestOsInfo(); - TestUserInfo(); + TestOsInfo(); + TestPlatformInfo(); + TestUserInfo(); - #if TEST_INTERACTIVE - TestDiskInfo(); - #endif + #if TEST_INTERACTIVE + TestDiskInfo(); #endif #endif // TEST_INFO_FUNCTIONS diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index f400389c4a..9068ffbca0 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -40,7 +40,7 @@ #include "wx/filefn.h" #include "wx/filename.h" // for SplitPath() -#include "wx/apptrait.h" +#include "wx/platinfo.h" #include "wx/arrimpl.cpp" @@ -247,11 +247,7 @@ wxString wxDynamicLibrary::CanonicalizePluginName(const wxString& name, wxString suffix; if ( cat == wxDL_PLUGIN_GUI ) { - wxAppTraits *traits = wxAppConsole::GetInstance() ? - wxAppConsole::GetInstance()->GetTraits() : NULL; - wxCHECK_MSG( traits, wxEmptyString, - _("can't query for GUI plugins name in console applications") ); - suffix = traits->GetToolkitInfo().shortName; + suffix = wxPlatformInfo().GetPortIdShortName(); } #if wxUSE_UNICODE suffix << _T('u'); diff --git a/src/common/intl.cpp b/src/common/intl.cpp index a5e863883e..2bb34b78cf 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -1583,11 +1583,13 @@ bool wxLocale::Init(const wxChar *szName, // there may be a catalog with toolkit specific overrides, it is not // an error if this does not exist - if ( bOk && wxTheApp ) + if ( bOk ) { - wxAppTraits *traits = wxTheApp->GetTraits(); - if (traits) - AddCatalog(traits->GetToolkitInfo().name.BeforeFirst(wxT('/')).MakeLower()); + wxString port(wxPlatformInfo().GetPortIdName()); + if ( !port.empty() ) + { + AddCatalog(port.BeforeFirst(wxT('/')).MakeLower()); + } } } diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp new file mode 100644 index 0000000000..998d0e964e --- /dev/null +++ b/src/common/platinfo.cpp @@ -0,0 +1,297 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/common/platinfo.cpp +// Purpose: implements 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 +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/utils.h" +#endif //WX_PRECOMP + +#include "wx/platinfo.h" +#include "wx/apptrait.h" + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +static wxString wxOperatingSystemIdNames[] = +{ + _T("Apple Mac OS"), + _T("Apple Mac OS X"), + + _T("Microsoft Windows 9X"), + _T("Microsoft Windows NT"), + _T("Microsoft Windows Micro"), + _T("Microsoft Windows CE"), + + _T("Linux"), + _T("FreeBSD"), + _T("OpenBSD"), + _T("NetBSD"), + + _T("SunOS"), + _T("AIX"), + _T("HPUX"), + + _T("DOS"), + _T("OS/2") +}; + +static wxString wxPortIdNames[] = +{ + _T("wxBase"), + _T("wxMSW"), + _T("wxMotif"), + _T("wxGTK"), + _T("wxMGL"), + _T("wxX11"), + _T("wxOS2"), + _T("wxMac"), + _T("wxCocoa"), + _T("wxWinCE"), + _T("wxPalmOS") +}; + +static wxString wxArchitectureNames[] = +{ + _T("32 bit"), + _T("64 bit") +}; + +static wxString wxEndiannessNames[] = +{ + _T("Big endian"), + _T("Little endian"), + _T("PDP endian") +}; + +// ---------------------------------------------------------------------------- +// local functions +// ---------------------------------------------------------------------------- + +// returns log in base 2 of the value, this maps the enum values to the +// corresponding indices +static int wxGetIndexFromEnumValue(int value) +{ + wxCHECK_MSG( value, -1, _T("invalid enum value") ); + + int n = 0; + while ( !(value & 1) ) + { + value >>= 1; + n++; + } + + wxASSERT_MSG( value == 1, _T("more than one bit set in enum value") ); + + return n; +} + +// ---------------------------------------------------------------------------- +// wxPlatformInfo +// ---------------------------------------------------------------------------- + +wxPlatformInfo::wxPlatformInfo() +{ + // autodetect all informations + const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + if ( !traits ) + { + wxFAIL_MSG( _T("failed to initialize wxPlatformInfo") ); + + m_port = wxPORT_UNKNOWN; + m_tkVersionMajor = + m_tkVersionMinor = 0; + } + else + { + m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor); + } + + m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor); + m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG; + m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32; +} + +wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor, + wxOperatingSystemId id, int osMajor, int osMinor, + wxArchitecture arch, + wxEndianness endian) +{ + m_tkVersionMajor = tkMajor; + m_tkVersionMinor = tkMinor; + m_port = pid; + + m_os = id; + m_osVersionMajor = osMajor; + m_osVersionMinor = osMinor; + + m_endian = endian; + m_arch = arch; +} + +bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const +{ + return m_tkVersionMajor == t.m_tkVersionMajor && + m_tkVersionMinor == t.m_tkVersionMinor && + m_osVersionMajor == t.m_osVersionMajor && + m_osVersionMinor == t.m_osVersionMinor && + m_os == t.m_os && + m_port == t.m_port && + m_arch == t.m_arch && + m_endian == t.m_endian; +} + +// ---------------------------------------------------------------------------- +// wxPlatformInfo - enum -> string conversions +// ---------------------------------------------------------------------------- + +wxString wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os) +{ + if ( os & wxOS_MAC ) + return _T("Macintosh"); + else if ( os & wxOS_WINDOWS ) + return _T("Windows"); + else if ( os & wxOS_UNIX ) + return _T("Unix"); + else if ( os == wxOS_DOS ) + return _T("DOS"); + else if ( os == wxOS_OS2 ) + return _T("OS/2"); + + return _T("Unknown"); +} + +wxString wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os) +{ + const int idx = wxGetIndexFromEnumValue(os); + + wxCHECK_MSG( idx < WXSIZEOF(wxOperatingSystemIdNames), wxEmptyString, + _T("invalid OS id") ); + + return wxOperatingSystemIdNames[idx]; +} + +wxString wxPlatformInfo::GetPortIdName(wxPortId port) +{ + const int idx = wxGetIndexFromEnumValue(port); + + wxCHECK_MSG( idx < WXSIZEOF(wxPortIdNames), wxEmptyString, + _T("invalid port id") ); + + wxString ret = wxPortIdNames[idx]; + + if ( IsUsingUniversalWidgets() ) + ret += wxT("/wxUniversal"); + + return ret; +} + +wxString wxPlatformInfo::GetPortIdShortName(wxPortId port) +{ + const int idx = wxGetIndexFromEnumValue(port); + + wxCHECK_MSG( idx < WXSIZEOF(wxPortIdNames), wxEmptyString, + _T("invalid port id") ); + + wxString ret = wxPortIdNames[idx]; + ret = ret.Mid(2).Lower(); // remove 'wx' prefix + + if ( IsUsingUniversalWidgets() ) + ret += wxT("univ"); + + return ret; +} + +wxString wxPlatformInfo::GetArchName(wxArchitecture arch) +{ + wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxArchitectureNames) == wxARCH_MAX, + wxArchitectureNamesMismatch ); + + return wxArchitectureNames[arch]; +} + +wxString wxPlatformInfo::GetEndiannessName(wxEndianness end) +{ + wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxEndiannessNames) == wxENDIAN_MAX, + wxEndiannessNamesMismatch ); + + return wxEndiannessNames[end]; +} + + +// ---------------------------------------------------------------------------- +// wxPlatformInfo - string -> enum conversions +// ---------------------------------------------------------------------------- + +wxOperatingSystemId wxPlatformInfo::GetOperatingSystemId(const wxString &str) +{ + for ( size_t i = 0; i < WXSIZEOF(wxOperatingSystemIdNames); i++ ) + { + if ( wxOperatingSystemIdNames[i].CmpNoCase(str) == 0 ) + return (wxOperatingSystemId)(1 << i); + } + + return wxOS_UNKNOWN; +} + +wxPortId wxPlatformInfo::GetPortId(const wxString &str) +{ + // recognize both short and long port names + for ( size_t i = 0; i < WXSIZEOF(wxPortIdNames); i++ ) + { + wxPortId current = (wxPortId)(1 << i); + + if ( wxPortIdNames[i].CmpNoCase(str) == 0 ) + return current; + if ( GetPortIdShortName(current).CmpNoCase(str) == 0 ) + return current; + } + + return wxPORT_UNKNOWN; +} + +wxArchitecture wxPlatformInfo::GetArch(const wxString &arch) +{ + if ( arch.Contains(wxT("32")) ) + return wxARCH_32; + + if ( arch.Contains(wxT("64")) ) + return wxARCH_64; + + return wxARCH_INVALID; +} + +wxEndianness wxPlatformInfo::GetEndianness(const wxString& end) +{ + wxString endl(end.Lower()); + if ( end.StartsWith(wxT("little")) ) + return wxENDIAN_LITTLE; + + if ( end.StartsWith(wxT("big")) ) + return wxENDIAN_BIG; + + return wxENDIAN_INVALID; +} + diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 303e31881f..79dae2984d 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -287,22 +287,20 @@ wxString wxGetDataDir() return dir; } -int wxGetOsVersion(int *verMaj, int *verMin) +bool wxIsPlatformLittleEndian() { - // we want this function to work even if there is no wxApp - wxConsoleAppTraits traitsConsole; - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; - if ( ! traits ) - traits = &traitsConsole; + // Are we little or big endian? This method is from Harbison & Steele. + union + { + long l; + char c[sizeof(long)]; + } u; + u.l = 1; - wxToolkitInfo& info = traits->GetToolkitInfo(); - if ( verMaj ) - *verMaj = info.versionMajor; - if ( verMin ) - *verMin = info.versionMinor; - return info.os; + return u.c[0] == 1; } + /* * Class to make it easier to specify platform-dependent values */ diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index e9d6e9eda1..82aa246a64 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -83,6 +83,8 @@ extern const unsigned int gtk_micro_version; #endif +#include "wx/platinfo.h" + // Windows List WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows; @@ -2164,69 +2166,35 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) #endif // __WXDEBUG__ #if wxUSE_MSGDLG - // don't translate these strings - wxString port; - -#ifdef __WXUNIVERSAL__ - port = _T("Univ/"); -#endif // __WXUNIVERSAL__ - - switch ( wxGetOsVersion() ) - { - case wxMOTIF_X: port += _T("Motif"); break; - case wxMAC: - case wxMAC_DARWIN: port += _T("Mac"); break; - case wxBEOS: port += _T("BeOS"); break; - case wxGTK: - case wxGTK_WIN32: - case wxGTK_OS2: - case wxGTK_BEOS: port += _T("GTK"); break; - case wxWINDOWS: - case wxPENWINDOWS: - case wxWINDOWS_NT: - case wxWIN32S: - case wxWIN95: - case wxWIN386: port += _T("MS Windows"); break; - case wxMGL_UNIX: - case wxMGL_X: - case wxMGL_WIN32: - case wxMGL_OS2: port += _T("MGL"); break; - case wxWINDOWS_OS2: - case wxOS2_PM: port += _T("OS/2"); break; - case wxPALMOS: port += _T("Palm OS"); break; - case wxWINDOWS_CE: port += _T("Windows CE (generic)"); break; - case wxWINDOWS_POCKETPC: port += _T("Windows CE PocketPC"); break; - case wxWINDOWS_SMARTPHONE: port += _T("Windows CE Smartphone"); break; - default: port += _T("unknown"); break; - } - - wxMessageBox(wxString::Format( - _T( - " wxWidgets Library (%s port)\nVersion %d.%d.%d%s%s, compiled at %s %s%s\n Copyright (c) 1995-2006 wxWidgets team" - ), - port.c_str(), - wxMAJOR_VERSION, - wxMINOR_VERSION, - wxRELEASE_NUMBER, + // don't translate these strings, they're for diagnostics purposes only + wxString msg; + msg.Printf(_T("wxWidgets Library (%s port)\n") + _T("Version %d.%d.%d%s%s, compiled at %s %s%s\n") + _T("Copyright (c) 1995-2006 wxWidgets team"), + wxPlatformInfo().GetPortIdName().c_str(), + wxMAJOR_VERSION, + wxMINOR_VERSION, + wxRELEASE_NUMBER, #if wxUSE_UNICODE - L" (Unicode)", + L" (Unicode)", #else - "", + wxEmptyString, #endif #ifdef __WXDEBUG__ - _T(" Debug build"), + _T(" Debug build"), #else - wxEmptyString, + wxEmptyString, #endif - __TDATE__, - __TTIME__, + __TDATE__, + __TTIME__, #ifdef __WXGTK__ - wxString::Format(_T("\nagainst GTK+ %d.%d.%d. Runtime GTK+ version: %d.%d.%d"), GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION, gtk_major_version, gtk_minor_version, gtk_micro_version).c_str() + wxString::Format(_T("\nagainst GTK+ %d.%d.%d. Runtime GTK+ version: %d.%d.%d"), GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION, gtk_major_version, gtk_minor_version, gtk_micro_version).c_str() #else - "" + wxEmptyString #endif - ), - _T("wxWidgets information"), + ); + + wxMessageBox(msg, _T("wxWidgets information"), wxICON_INFORMATION | wxOK, (wxWindow *)this); } diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index f615293ba2..4ffa937042 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -163,21 +163,6 @@ int wxDisplayDepth() return gdk_drawable_get_visual( wxGetRootWindow()->window )->depth; } -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() -{ - static wxToolkitInfo info; - info.shortName = _T("gtk2"); - info.name = _T("wxGTK"); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); -#endif - info.versionMajor = gtk_major_version; - info.versionMinor = gtk_minor_version; - info.os = wxGTK; - return info; -} - wxWindow* wxFindWindowAtPoint(const wxPoint& pt) { return wxGenericFindWindowAtPoint(pt); @@ -259,3 +244,19 @@ int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) return tag; } + + + +// ---------------------------------------------------------------------------- +// wxPlatformInfo-related +// ---------------------------------------------------------------------------- + +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const +{ + if ( verMaj ) + *verMaj = gtk_major_version; + if ( verMin ) + *verMin = gtk_minor_version; + + return wxPORT_GTK; +} diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp index 56fb435d13..35524cd469 100644 --- a/src/gtk1/utilsgtk.cpp +++ b/src/gtk1/utilsgtk.cpp @@ -129,21 +129,6 @@ int wxDisplayDepth() return gdk_window_get_visual( wxGetRootWindow()->window )->depth; } -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() -{ - static wxToolkitInfo info; - info.shortName = _T("gtk"); - info.name = _T("wxGTK"); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); -#endif - info.versionMajor = gtk_major_version; - info.versionMinor = gtk_minor_version; - info.os = wxGTK; - return info; -} - wxWindow* wxFindWindowAtPoint(const wxPoint& pt) { return wxGenericFindWindowAtPoint(pt); @@ -197,3 +182,17 @@ int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) return tag; } + +// ---------------------------------------------------------------------------- +// wxPlatformInfo-related +// ---------------------------------------------------------------------------- + +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const +{ + if ( verMaj ) + *verMaj = gtk_major_version; + if ( verMin ) + *verMin = gtk_minor_version; + + return wxPORT_GTK; +} diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index df1f155679..54913b5d00 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -72,7 +72,7 @@ // --------------------------------------------------------------------------- // our OS version is the same in non GUI and GUI cases -static int DoGetOSVersion(int *majorVsn, int *minorVsn) +wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) { long theSystem; @@ -85,14 +85,15 @@ static int DoGetOSVersion(int *majorVsn, int *minorVsn) if (majorVsn != NULL) *majorVsn = (theSystem >> 8); -#ifdef __DARWIN__ - return wxMAC_DARWIN; +#if defined( __DARWIN__ ) + return wxOS_MAC_OSX_DARWIN; #else - return wxMAC; + return wxOS_MAC_OS; #endif } + #if wxUSE_BASE // ---------------------------------------------------------------------------- @@ -370,34 +371,17 @@ void wxBell() SysBeep(30); } -wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() -{ - static wxToolkitInfo info; - - info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); - info.name = _T("wxBase"); - - return info; -} #endif // wxUSE_BASE #if wxUSE_GUI -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; - - info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); - info.shortName = _T("mac"); - info.name = _T("wxMac"); + // We suppose that toolkit version is the same as OS version under Mac + wxGetOsVersion(verMaj, verMin); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); -#endif - - return info; + return wxPORT_MAC; } // Reading and writing resources (eg WIN.INI, .Xdefaults) @@ -1151,7 +1135,7 @@ void wxMacControl::SetRect( Rect *r ) HIViewSetFrame ( m_controlRef , &hir ); // eventuall we might have to do a SetVisibility( false , true ); // before and a SetVisibility( true , true ); after - } +} void wxMacControl::GetRect( Rect *r ) { diff --git a/src/mac/classic/utils.cpp b/src/mac/classic/utils.cpp index 7078e7a3c7..f28c2042f6 100644 --- a/src/mac/classic/utils.cpp +++ b/src/mac/classic/utils.cpp @@ -61,23 +61,23 @@ // --------------------------------------------------------------------------- // our OS version is the same in non GUI and GUI cases -static int DoGetOSVersion(int *majorVsn, int *minorVsn) +wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) { - long theSystem ; + long theSystem; // are there x-platform conventions ? - Gestalt(gestaltSystemVersion, &theSystem) ; - if (minorVsn != NULL) { - *minorVsn = (theSystem & 0xFF ) ; - } - if (majorVsn != NULL) { - *majorVsn = (theSystem >> 8 ) ; - } -#ifdef __DARWIN__ - return wxMAC_DARWIN; + Gestalt(gestaltSystemVersion, &theSystem); + if (minorVsn != NULL) + *minorVsn = (theSystem & 0xFF); + + if (majorVsn != NULL) + *majorVsn = (theSystem >> 8); + +#if defined( __DARWIN__ ) + return wxOS_MAC_OSX_DARWIN; #else - return wxMAC; + return wxOS_MAC_OS; #endif } @@ -224,29 +224,16 @@ void wxBell() SysBeep(30); } -wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() -{ - static wxToolkitInfo info; - info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); - info.name = _T("wxBase"); - return info; -} - #endif // wxUSE_BASE #if wxUSE_GUI -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; - info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); - info.shortName = _T("mac"); - info.name = _T("wxMac"); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); -#endif - return info; + // We suppose that toolkit version is the same as OS version under Mac + wxGetOsVersion(verMaj, verMin); + + return wxPORT_MAC; } // Reading and writing resources (eg WIN.INI, .Xdefaults) diff --git a/src/mgl/utils.cpp b/src/mgl/utils.cpp index c6dad8291a..7fad2ad588 100644 --- a/src/mgl/utils.cpp +++ b/src/mgl/utils.cpp @@ -103,55 +103,15 @@ int wxDisplayDepth() return g_displayDC->getBitsPerPixel(); } -#if wxUSE_GUI - -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; - info.shortName = _T("mgluniv"); - info.name = _T("wxMGL"); - info.versionMajor = MGL_RELEASE_MAJOR; - info.versionMinor = MGL_RELEASE_MINOR; - info.os = wxGTK; -#if defined(__UNIX__) - info.os = wxMGL_UNIX; -#elif defined(__OS2__) - info.os = wxMGL_OS2; -#elif defined(__WIN32__) - info.os = wxMGL_WIN32; -#elif defined(__DOS__) - info.os = wxMGL_DOS; -#else - #error Platform not supported by wxMGL! -#endif - return info; -} - -#endif + if ( verMaj ) + *verMaj = MGL_RELEASE_MAJOR; + if ( verMin ) + *verMin = MGL_RELEASE_MINOR; -#if 0 -wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() -{ - static wxToolkitInfo info; - info.shortName = _T("mglbase"); - info.versionMajor = MGL_RELEASE_MAJOR; - info.versionMinor = MGL_RELEASE_MINOR; - info.name = _T("wxBase"); - info.os = wxGTK; -#if defined(__UNIX__) - info.os = wxMGL_UNIX; -#elif defined(__OS2__) - info.os = wxMGL_OS2; -#elif defined(__WIN32__) - info.os = wxMGL_WIN32; -#elif defined(__DOS__) - info.os = wxMGL_DOS; -#else - #error Platform not supported by wxMGL! -#endif - return info; + return wxPORT_MGL; } -#endif void wxGetMousePosition(int* x, int* y) { diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index 632f36eff4..84bc1a6d9a 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -143,30 +143,18 @@ void wxBell() } #endif -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; + // XmVERSION and XmREVISION are defined in Xm/Xm.h + if ( verMaj ) + *verMaj = XmVERSION; + if ( verMin ) + *verMin = XmREVISION; - info.shortName = _T("motif"); - info.name = _T("wxMotif"); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); -#endif - // FIXME TODO - // This code is WRONG!! Does NOT return the - // Motif version of the libs but the X protocol - // version! - Display *display = wxGlobalDisplay(); - if (display) - { - info.versionMajor = ProtocolVersion (display); - info.versionMinor = ProtocolRevision (display); - } - info.os = wxMOTIF_X; - return info; + return wxPORT_MOTIF; } + // ---------------------------------------------------------------------------- // Reading and writing resources (eg WIN.INI, .Xdefaults) // ---------------------------------------------------------------------------- diff --git a/src/msdos/utilsdos.cpp b/src/msdos/utilsdos.cpp index 189009fdee..c876b6939e 100644 --- a/src/msdos/utilsdos.cpp +++ b/src/msdos/utilsdos.cpp @@ -467,22 +467,9 @@ long wxExecute(wxChar **argv, int flags, wxProcess *process) return result; } -//---------------------------------------------------------------------------- -// Traits for console apps -//---------------------------------------------------------------------------- - -wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() -{ - static wxToolkitInfo info; - info.versionMajor = _osmajor; - info.versionMinor = _osminor; - info.name = _T("wxBase"); - info.os = wxDOS; - return info; -} //---------------------------------------------------------------------------- -// OS Description +// OS-related //---------------------------------------------------------------------------- wxString wxGetOsDescription() @@ -490,3 +477,14 @@ wxString wxGetOsDescription() wxString osname(_T("DOS")); return osname; } + +wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) +{ + if ( verMaj ) + *verMaj = _osmajor; + if ( verMin ) + *verMin = _osminor; + + return wxOS_DOS; +} + diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 6a18714bf7..23307d06b1 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -226,20 +226,27 @@ bool wxGUIAppTraits::DoMessageFromThreadWait() return evtLoop->Dispatch(); } -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const { - static wxToolkitInfo info; - wxToolkitInfo& baseInfo = wxAppTraits::GetToolkitInfo(); - info.versionMajor = baseInfo.versionMajor; - info.versionMinor = baseInfo.versionMinor; - info.os = baseInfo.os; - info.shortName = _T("msw"); - info.name = _T("wxMSW"); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); + OSVERSIONINFO info; + wxZeroMemory(info); + + // on Windows, the toolkit version is the same of the OS version + // as Windows integrates the OS kernel with the GUI toolkit. + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if ( ::GetVersionEx(&info) ) + { + if ( majVer ) + *majVer = info.dwMajorVersion; + if ( minVer ) + *minVer = info.dwMinorVersion; + } + +#if defined(__WXHANDHELD__) || defined(__WXWINCE__) + return wxPORT_WINCE; +#else + return wxPORT_MSW; #endif - return info; } // =========================================================================== diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 7409cd6c8f..ece5167e97 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -1162,61 +1162,49 @@ wxString wxGetOsDescription() return str; } -wxToolkitInfo& wxAppTraits::GetToolkitInfo() +// taken from http://blogs.msdn.com/oldnewthing/archive/2005/02/01/364563.aspx +bool wxIsPlatform64Bit() { - // 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 ( s_ver == -1 ) - { - OSVERSIONINFO info; - wxZeroMemory(info); +#if defined(_WIN64) + return true; // 64-bit programs run only on Win64 +#elif defined(_WIN32) + // 32-bit programs run on both 32-bit and 64-bit Windows + // so must sniff + BOOL f64 = FALSE; + return IsWow64Process(GetCurrentProcess(), &f64) && f64; +#else + return false; // Win64 does not support Win16 +#endif +} - s_ver = wxWINDOWS; - info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if ( ::GetVersionEx(&info) ) - { - s_major = info.dwMajorVersion; - s_minor = info.dwMinorVersion; +wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) +{ + OSVERSIONINFO info; + wxZeroMemory(info); -#ifdef __SMARTPHONE__ - s_ver = wxWINDOWS_SMARTPHONE; -#elif defined(__POCKETPC__) - s_ver = wxWINDOWS_POCKETPC; -#else - switch ( info.dwPlatformId ) - { - case VER_PLATFORM_WIN32s: - s_ver = wxWIN32S; - break; + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if ( ::GetVersionEx(&info) ) + { + if (verMaj) *verMaj = info.dwMajorVersion; + if (verMin) *verMin = info.dwMinorVersion; + } - case VER_PLATFORM_WIN32_WINDOWS: - s_ver = wxWIN95; - break; +#if defined(__WXHANDHELD__) || defined( __WXWINCE__ ) + return wxOS_WINDOWS_WINCE; +#elif defined( __WXMICROWIN__ ) + return wxOS_WINDOWS_MICRO; +#else + switch ( info.dwPlatformId ) + { + case VER_PLATFORM_WIN32_NT: + return wxOS_WINDOWS_NT; - case VER_PLATFORM_WIN32_NT: - s_ver = wxWINDOWS_NT; - break; -#ifdef __WXWINCE__ - case VER_PLATFORM_WIN32_CE: - s_ver = wxWINDOWS_CE; -#endif - } -#endif - } + case VER_PLATFORM_WIN32_WINDOWS: + return wxOS_WINDOWS_9X; } - static wxToolkitInfo info; - info.versionMajor = s_major; - info.versionMinor = s_minor; - info.os = s_ver; - info.name = _T("wxBase"); - return info; + return wxOS_UNKNOWN; +#endif } wxWinVersion wxGetWinVersion() diff --git a/src/os2/utils.cpp b/src/os2/utils.cpp index 02f775d5fd..b963638d6d 100644 --- a/src/os2/utils.cpp +++ b/src/os2/utils.cpp @@ -326,27 +326,30 @@ void wxAppTraits::TerminateGui(unsigned long WXUNUSED(ulHab)) { } -wxToolkitInfo & wxConsoleAppTraits::GetToolkitInfo() +wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) { static wxToolkitInfo vInfo; ULONG ulSysInfo[QSV_MAX] = {0}; APIRET ulrc; - vInfo.name = _T("wxBase"); ulrc = ::DosQuerySysInfo( 1L ,QSV_MAX ,(PVOID)ulSysInfo ,sizeof(ULONG) * QSV_MAX ); + if (ulrc == 0L) { - vInfo.versionMajor = ulSysInfo[QSV_VERSION_MAJOR] / 10; - vInfo.versionMinor = ulSysInfo[QSV_VERSION_MINOR]; + if ( verMaj ) + *verMaj = ulSysInfo[QSV_VERSION_MAJOR] / 10; + if ( verMin ) + *verMin = ulSysInfo[QSV_VERSION_MINOR]; } - vInfo.os = wxOS2_PM; - return vInfo; + + return wxOS_OS2; } + // --------------------------------------------------------------------------- const wxChar* wxGetHomeDir( wxString* pStr diff --git a/src/os2/utilsgui.cpp b/src/os2/utilsgui.cpp index 9e3748e124..a3779dee7f 100644 --- a/src/os2/utilsgui.cpp +++ b/src/os2/utilsgui.cpp @@ -437,32 +437,13 @@ void wxGUIAppTraits::TerminateGui(unsigned long ulHab) ::WinTerminate(ulHab); } -wxToolkitInfo & wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo vInfo; - ULONG ulSysInfo[QSV_MAX] = {0}; - APIRET ulrc; - - vInfo.shortName = _T("PM"); - vInfo.name = _T("wxOS2"); -#ifdef __WXUNIVERSAL__ - vInfo.shortName << _T("univ"); - vInfo.name << _T("/wxUniversal"); -#endif - ulrc = ::DosQuerySysInfo( 1L - ,QSV_MAX - ,(PVOID)ulSysInfo - ,sizeof(ULONG) * QSV_MAX - ); - if (ulrc == 0L) - { - vInfo.versionMajor = ulSysInfo[QSV_VERSION_MAJOR] / 10; - vInfo.versionMinor = ulSysInfo[QSV_VERSION_MINOR]; - } - vInfo.os = wxOS2_PM; - return vInfo; + // TODO: how to get version of PM ? + return wxPORT_OS2; } + // --------------------------------------------------------------------------- // window information functions // --------------------------------------------------------------------------- diff --git a/src/palmos/app.cpp b/src/palmos/app.cpp index b96a01e117..cc947d8823 100644 --- a/src/palmos/app.cpp +++ b/src/palmos/app.cpp @@ -113,20 +113,10 @@ bool wxGUIAppTraits::DoMessageFromThreadWait() return false; } -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const { - static wxToolkitInfo info; - wxToolkitInfo& baseInfo = wxAppTraits::GetToolkitInfo(); - info.versionMajor = baseInfo.versionMajor; - info.versionMinor = baseInfo.versionMinor; - info.os = baseInfo.os; - info.shortName = _T("palmos"); - info.name = _T("wxPalmOS"); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); -#endif - return info; + // TODO: how to get PalmOS GUI system version ? + return wxPORT_PALMOS; } // =========================================================================== diff --git a/src/palmos/utils.cpp b/src/palmos/utils.cpp index 788f6e6b50..f1f40adad7 100644 --- a/src/palmos/utils.cpp +++ b/src/palmos/utils.cpp @@ -215,12 +215,11 @@ wxString wxGetOsDescription() return strOS; } -wxToolkitInfo& wxAppTraits::GetToolkitInfo() +wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) { - static wxToolkitInfo info; - info.os = wxPALMOS; - info.name = _T("wxBase"); - return info; + // TODO + + return wxOS_UNKNOWN; } // ---------------------------------------------------------------------------- diff --git a/src/unix/baseunix.cpp b/src/unix/baseunix.cpp index de2ee2f156..8f63455618 100644 --- a/src/unix/baseunix.cpp +++ b/src/unix/baseunix.cpp @@ -81,45 +81,3 @@ wxConsoleAppTraits::WaitForChild(wxExecuteData& execData) return exitcode; } -// ---------------------------------------------------------------------------- -// misc other stuff -// ---------------------------------------------------------------------------- - -// this is in mac/utils.cpp under Mac -#if !defined(__WXMAC__) - -wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() -{ - static wxToolkitInfo info; - int major, minor; - - FILE *f = popen("uname -r", "r"); - if (f) - { - char buf[32]; - size_t c = fread(buf, 1, sizeof(buf) - 1, f); - pclose(f); - buf[c] = '\0'; - if ( sscanf(buf, "%d.%d", &major, &minor) != 2 ) - { - // unrecognized uname string format - major = - minor = -1; - } - } - else - { - // failed to run uname - major = - minor = -1; - } - - info.versionMajor = major; - info.versionMinor = minor; - info.name = _T("wxBase"); - info.os = wxUNIX; - - return info; -} - -#endif // __WXMAC__ diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 41f5184b3a..d14a33a5e6 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -746,6 +746,35 @@ char *wxGetUserHome( const wxString &user ) // network and user id routines // ---------------------------------------------------------------------------- +// private utility function which returns output of the given command, removing +// the trailing newline +static wxString wxGetCommandOutput(const wxString &cmd) +{ + FILE *f = popen(cmd.ToAscii(), "r"); + if ( !f ) + { + wxLogSysError(_T("Executing \"%s\" failed"), cmd.c_str()); + return wxEmptyString; + } + + wxString s; + char buf[256]; + while ( !feof(f) ) + { + if ( !fgets(buf, sizeof(buf), f) ) + break; + + s += wxString::FromAscii(buf); + } + + pclose(f); + + if ( !s.empty() && s.Last() == _T('\n') ) + s.RemoveLast(); + + return s; +} + // retrieve either the hostname or FQDN depending on platform (caller must // check whether it's one or the other, this is why this function is for // private use only) @@ -862,25 +891,54 @@ bool wxGetUserName(wxChar *buf, int sz) return false; } +wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) +{ + // get OS version + int major, minor; + wxString release = wxGetCommandOutput(wxT("uname -r")); + if ( !release.empty() && wxSscanf(release, "%d.%d", &major, &minor) != 2 ) + { + // unrecognized uname string format + major = + minor = -1; + } + + if ( verMaj ) + *verMaj = major; + if ( verMin ) + *verMin = minor; + + // try to understand which OS are we running + wxString kernel = wxGetCommandOutput(wxT("uname -s")); + if ( kernel.empty() ) + kernel = wxGetCommandOutput(wxT("uname -o")); + + if ( kernel.empty() ) + return wxOS_UNKNOWN; + + return wxPlatformInfo::GetOperatingSystemId(kernel); +} + +bool wxIsPlatform64Bit() +{ + wxString machine = wxGetCommandOutput(wxT("uname -m")); + + // NOTE: these tests are not 100% reliable! + return machine.Contains(wxT("AMD64")) || + machine.Contains(wxT("IA64")) || + machine.Contains(wxT("x64")) || + machine.Contains(wxT("X64")) || + machine.Contains(wxT("alpha")) || + machine.Contains(wxT("hppa64")) || + machine.Contains(wxT("ppc64")); +} + // this function is in mac/utils.cpp for wxMac #ifndef __WXMAC__ wxString wxGetOsDescription() { - FILE *f = popen("uname -s -r -m", "r"); - if (f) - { - char buf[256]; - size_t c = fread(buf, 1, sizeof(buf) - 1, f); - pclose(f); - // Trim newline from output. - if (c && buf[c - 1] == '\n') - --c; - buf[c] = '\0'; - return wxString::FromAscii( buf ); - } - wxFAIL_MSG( _T("uname failed") ); - return wxEmptyString; + return wxGetCommandOutput(wxT("uname -s -r -m")); } #endif // !__WXMAC__ diff --git a/src/x11/utils.cpp b/src/x11/utils.cpp index 4640a12221..6c8fa963cb 100644 --- a/src/x11/utils.cpp +++ b/src/x11/utils.cpp @@ -153,17 +153,22 @@ void wxBell() } #endif -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; - info.shortName = _T("x11univ"); - info.name = _T("wxX11"); - info.versionMajor = 0; - info.versionMinor = 0; - info.os = wxX11; - return info; + // get X protocol version + Display *display = wxGlobalDisplay(); + if (display) + { + if ( verMaj ) + *verMaj = ProtocolVersion (display); + if ( verMin ) + *verMin = ProtocolRevision (display); + } + + return wxPORT_X11; } + // ---------------------------------------------------------------------------- // display info // ---------------------------------------------------------------------------- -- 2.45.2