X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b98bd6af23c1c73eb2cddf14da18455e5668de6d..80a779275ae04443c568dca919adb26cf6f5002c:/src/common/platinfo.cpp diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp index b8ee8fcc1c..1d8d99e22f 100644 --- a/src/common/platinfo.cpp +++ b/src/common/platinfo.cpp @@ -33,11 +33,17 @@ #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 // ---------------------------------------------------------------------------- -static wxString wxOperatingSystemIdNames[] = +static const wxChar* const wxOperatingSystemIdNames[] = { _T("Apple Mac OS"), _T("Apple Mac OS X"), @@ -60,7 +66,7 @@ static wxString wxOperatingSystemIdNames[] = _T("OS/2") }; -static wxString wxPortIdNames[] = +static const wxChar* const wxPortIdNames[] = { _T("wxBase"), _T("wxMSW"), @@ -72,16 +78,17 @@ static wxString wxPortIdNames[] = _T("wxMac"), _T("wxCocoa"), _T("wxWinCE"), - _T("wxPalmOS") + _T("wxPalmOS"), + _T("wxDFB") }; -static wxString wxArchitectureNames[] = +static const wxChar* const wxArchitectureNames[] = { _T("32 bit"), _T("64 bit") }; -static wxString wxEndiannessNames[] = +static const wxChar* const wxEndiannessNames[] = { _T("Big endian"), _T("Little endian"), @@ -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,24 +159,64 @@ 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 // ---------------------------------------------------------------------------- wxString wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os) { + const wxChar* string = _T("Unknown"); if ( os & wxOS_MAC ) - return _T("Macintosh"); + string = _T("Macintosh"); else if ( os & wxOS_WINDOWS ) - return _T("Windows"); + string = _T("Windows"); else if ( os & wxOS_UNIX ) - return _T("Unix"); + string = _T("Unix"); else if ( os == wxOS_DOS ) - return _T("DOS"); + string = _T("DOS"); else if ( os == wxOS_OS2 ) - return _T("OS/2"); + string = _T("OS/2"); - return _T("Unknown"); + return string; } wxString wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os) @@ -256,7 +285,7 @@ wxOperatingSystemId wxPlatformInfo::GetOperatingSystemId(const wxString &str) { for ( size_t i = 0; i < WXSIZEOF(wxOperatingSystemIdNames); i++ ) { - if ( wxOperatingSystemIdNames[i].CmpNoCase(str) == 0 ) + if ( wxString(wxOperatingSystemIdNames[i]).CmpNoCase(str) == 0 ) return (wxOperatingSystemId)(1 << i); } @@ -270,9 +299,8 @@ wxPortId wxPlatformInfo::GetPortId(const wxString &str) { wxPortId current = (wxPortId)(1 << i); - if ( wxPortIdNames[i].CmpNoCase(str) == 0 ) - return current; - if ( GetPortIdShortName(current, true).CmpNoCase(str) == 0 || + if ( wxString(wxPortIdNames[i]).CmpNoCase(str) == 0 || + GetPortIdShortName(current, true).CmpNoCase(str) == 0 || GetPortIdShortName(current, false).CmpNoCase(str) == 0 ) return current; }