From 449090b54d2e74bfd28c217bab25d11764ca38cc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Oct 2006 15:58:56 +0000 Subject: [PATCH] added static wxPlatformInfo::Get() and use it (patch 1549176) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41807 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/apptraits.tex | 2 ++ docs/latex/wx/platinfo.tex | 32 ++++++++++++++---- include/wx/apptrait.h | 3 +- include/wx/platinfo.h | 8 +++++ src/common/dynlib.cpp | 2 +- src/common/intl.cpp | 2 +- src/common/platinfo.cpp | 67 ++++++++++++++++++++++++++----------- src/common/wincmn.cpp | 9 +++-- 8 files changed, 92 insertions(+), 33 deletions(-) diff --git a/docs/latex/wx/apptraits.tex b/docs/latex/wx/apptraits.tex index 6c15c18363..39e0ff6a84 100644 --- a/docs/latex/wx/apptraits.tex +++ b/docs/latex/wx/apptraits.tex @@ -83,6 +83,8 @@ It's normally the same for wxBase and wxGUI except in the case of wxMac and wxCo 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. +The version numbers returned are thus detected at run-time and not compile-time +(except when this is not possible e.g. wxMotif). 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. diff --git a/docs/latex/wx/platinfo.tex b/docs/latex/wx/platinfo.tex index 3edc674fe5..4e6cab1973 100644 --- a/docs/latex/wx/platinfo.tex +++ b/docs/latex/wx/platinfo.tex @@ -92,7 +92,8 @@ enum wxPortId 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 + wxPORT_PALMOS = 1 << 10, // wxPalmOS, toolkit is PalmOS API + wxPORT_DFB = 1 << 11 // wxDFB, using wxUniversal }; \end{verbatim} @@ -135,6 +136,8 @@ enum wxEndianness \func{}{wxPlatformInfo}{} Initializes the instance with the values corresponding to the currently running platform. +This is a fast operation because it only requires to copy the values internally cached for the +currently running platform (see also \helpref{Get}{wxplatforminfoget}). \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}} @@ -169,6 +172,13 @@ Returns \true if the toolkit version is at least \texttt{major.minor}. +\membersection{wxPlatformInfo::Get}\label{wxplatforminfoget} + +\func{static const wxPlatformInfo\& }{Get}{\void} + +Returns the global wxPlatformInfo object, initialized with the values for the currently running platform. + + \membersection{wxPlatformInfo::GetArch}\label{wxplatforminfogetarch} \func{static wxArchitecture}{GetArch}{\param{const wxString\& }{arch}} @@ -228,7 +238,8 @@ Returns the name for the endianness of this wxPlatformInfo instance. \constfunc{int}{GetOSMajorVersion}{\void} -Returns the major version of the OS associated with this wxPlatformInfo instance. +Returns the run-time major version of the OS associated with this wxPlatformInfo instance. +See \helpref{wxGetOsVersion}{wxgetosversion} for more info. \wxheading{See also} @@ -239,7 +250,10 @@ Returns the major version of the OS associated with this wxPlatformInfo instance \constfunc{int}{GetOSMinorVersion}{\void} -Returns the minor version of the OS associated with this wxPlatformInfo instance. +Returns the run-time minor version of the OS associated with this wxPlatformInfo instance. +See \helpref{wxGetOsVersion}{wxgetosversion} for more info. + +\wxheading{See also} \helpref{CheckOSVersion}{wxplatforminfocheckosversion} @@ -340,8 +354,11 @@ Returns the short name of the wxWidgets port ID associated with this wxPlatformI \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. +Returns the run-time major version of the toolkit associated with this wxPlatformInfo instance. +Note that if \helpref{GetPortId}{wxplatforminfogetportid} returns wxPORT\_BASE, then this value is zero (unless externally modified with \helpref{SetToolkitVersion}{wxplatforminfosettoolkitversion}); that is, no native toolkit is in use. + +See \helpref{wxAppTraits::GetToolkitVersion}{wxapptraitsgettoolkitversion} for more info. + \wxheading{See also} @@ -352,9 +369,10 @@ Note that if {GetPortId}{wxplatforminfogetportid} returns wxPORT\_BASE, then thi \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. +Returns the run-time minor version of the toolkit associated with this wxPlatformInfo instance. +Note that if \helpref{GetPortId}{wxplatforminfogetportid} returns wxPORT\_BASE, then this value is zero (unless externally modified with \helpref{SetToolkitVersion}{wxplatforminfosettoolkitversion}); that is, no native toolkit is in use. +See \helpref{wxAppTraits::GetToolkitVersion}{wxapptraitsgettoolkitversion} for more info. \wxheading{See also} \helpref{CheckToolkitVersion}{wxplatforminfochecktoolkitversion} diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index 1de2cfea7d..3aa0e293ab 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -110,7 +110,8 @@ public: virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0; #endif - // return information about the (native) toolkit currently used; + // return information about the (native) toolkit currently used and its + // runtime (not compile-time) version. // 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; diff --git a/include/wx/platinfo.h b/include/wx/platinfo.h index 2065e01a7f..809a314673 100644 --- a/include/wx/platinfo.h +++ b/include/wx/platinfo.h @@ -130,6 +130,11 @@ public: bool operator!=(const wxPlatformInfo &t) const { return !(*this == t); } + // Gets a wxPlatformInfo already initialized with the values for + // the currently running platform. + static const wxPlatformInfo& Get(); + + // string -> enum conversions // --------------------------------- @@ -246,6 +251,9 @@ protected: return majorCur > major || (majorCur == major && minorCur >= minor); } + void InitForCurrentPlatform(); + + // OS stuff // ----------------- diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 9068ffbca0..3e78472bce 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -247,7 +247,7 @@ wxString wxDynamicLibrary::CanonicalizePluginName(const wxString& name, wxString suffix; if ( cat == wxDL_PLUGIN_GUI ) { - suffix = wxPlatformInfo().GetPortIdShortName(); + suffix = wxPlatformInfo::Get().GetPortIdShortName(); } #if wxUSE_UNICODE suffix << _T('u'); diff --git a/src/common/intl.cpp b/src/common/intl.cpp index c0d360ea0f..4d689229a7 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -1591,7 +1591,7 @@ bool wxLocale::Init(const wxChar *szName, // an error if this does not exist if ( bOk ) { - wxString port(wxPlatformInfo().GetPortIdName()); + wxString port(wxPlatformInfo::Get().GetPortIdName()); if ( !port.empty() ) { AddCatalog(port.BeforeFirst(wxT('/')).MakeLower()); diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp index df765b153a..1d8d99e22f 100644 --- a/src/common/platinfo.cpp +++ b/src/common/platinfo.cpp @@ -33,6 +33,12 @@ #include "wx/apptrait.h" +// global object +// VERY IMPORTANT: do not use the default constructor since it would +// try to init the wxPlatformInfo instance using +// gs_platInfo itself! +static wxPlatformInfo gs_platInfo(wxPORT_UNKNOWN); + // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -117,26 +123,8 @@ static unsigned wxGetIndexFromEnumValue(int value) 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_usingUniversal = false; - m_tkVersionMajor = - m_tkVersionMinor = 0; - } - else - { - m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor); - m_usingUniversal = traits->IsUsingUniversalWidgets(); - } - - m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor); - m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG; - m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32; + // just copy platform info for currently running platform + *this = Get(); } wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor, @@ -171,6 +159,45 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const m_endian == t.m_endian; } +void wxPlatformInfo::InitForCurrentPlatform() +{ + // 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_usingUniversal = false; + m_tkVersionMajor = + m_tkVersionMinor = 0; + } + else + { + m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor); + m_usingUniversal = traits->IsUsingUniversalWidgets(); + } + + m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor); + m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG; + m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32; +} + +/* static */ +const wxPlatformInfo& wxPlatformInfo::Get() +{ + static bool initialized = false; + if ( !initialized ) + { + gs_platInfo.InitForCurrentPlatform(); + initialized = true; + } + + return gs_platInfo; +} + + + // ---------------------------------------------------------------------------- // wxPlatformInfo - enum -> string conversions // ---------------------------------------------------------------------------- diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 2c79fc55e6..44b93da89d 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2199,9 +2199,10 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) // 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("Version %d.%d.%d%s%s, compiled at %s %s\n") + _T("Runtime version of toolkit used is %d.%d.%s\n") _T("Copyright (c) 1995-2006 wxWidgets team"), - wxPlatformInfo().GetPortIdName().c_str(), + wxPlatformInfo::Get().GetPortIdName().c_str(), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, @@ -2217,8 +2218,10 @@ void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) #endif __TDATE__, __TTIME__, + wxPlatformInfo::Get().GetToolkitMajorVersion(), + wxPlatformInfo::Get().GetToolkitMinorVersion(), #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("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION).c_str() #else wxEmptyString #endif -- 2.45.2