X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8f4931874c9a832e8d6cc4fe47dd8bbbf943a418..ce7208d49d5ce2ca1dc0b3b83f14f1d04f29c4bf:/src/common/platinfo.cpp?ds=sidebyside diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp index e9d2553236..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 // ---------------------------------------------------------------------------- @@ -72,7 +78,8 @@ static const wxChar* const wxPortIdNames[] = _T("wxMac"), _T("wxCocoa"), _T("wxWinCE"), - _T("wxPalmOS") + _T("wxPalmOS"), + _T("wxDFB") }; static const wxChar* const wxArchitectureNames[] = @@ -116,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, @@ -170,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 // ----------------------------------------------------------------------------