X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8f4931874c9a832e8d6cc4fe47dd8bbbf943a418..2f36b4d22beeb7f4f0cedf922c0c26d037f54477:/src/common/platinfo.cpp?ds=inline diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp index e9d2553236..ee943915c6 100644 --- a/src/common/platinfo.cpp +++ b/src/common/platinfo.cpp @@ -4,9 +4,8 @@ // Author: Francesco Montorsi // Modified by: // Created: 07.07.2006 (based on wxToolkitInfo) -// RCS-ID: $Id$ // Copyright: (c) 2006 Francesco Montorsi -// License: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -33,70 +32,78 @@ #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 const wxChar* const wxOperatingSystemIdNames[] = { - _T("Apple Mac OS"), - _T("Apple Mac OS X"), + wxT("Apple Mac OS"), + wxT("Apple Mac OS X"), + + wxT("Microsoft Windows 9X"), + wxT("Microsoft Windows NT"), + wxT("Microsoft Windows Micro"), + wxT("Microsoft Windows CE"), - _T("Microsoft Windows 9X"), - _T("Microsoft Windows NT"), - _T("Microsoft Windows Micro"), - _T("Microsoft Windows CE"), + wxT("Linux"), + wxT("FreeBSD"), + wxT("OpenBSD"), + wxT("NetBSD"), - _T("Linux"), - _T("FreeBSD"), - _T("OpenBSD"), - _T("NetBSD"), + wxT("SunOS"), + wxT("AIX"), + wxT("HPUX"), - _T("SunOS"), - _T("AIX"), - _T("HPUX"), + wxT("Other Unix"), + wxT("Other Unix"), - _T("DOS"), - _T("OS/2") + wxT("DOS"), + wxT("OS/2"), }; static const wxChar* const wxPortIdNames[] = { - _T("wxBase"), - _T("wxMSW"), - _T("wxMotif"), - _T("wxGTK"), - _T("wxMGL"), - _T("wxX11"), - _T("wxOS2"), - _T("wxMac"), - _T("wxCocoa"), - _T("wxWinCE"), - _T("wxPalmOS") + wxT("wxBase"), + wxT("wxMSW"), + wxT("wxMotif"), + wxT("wxGTK"), + wxT("wxDFB"), + wxT("wxX11"), + wxT("wxOS2"), + wxT("wxMac"), + wxT("wxCocoa"), + wxT("wxWinCE"), }; static const wxChar* const wxArchitectureNames[] = { - _T("32 bit"), - _T("64 bit") + wxT("32 bit"), + wxT("64 bit") }; static const wxChar* const wxEndiannessNames[] = { - _T("Big endian"), - _T("Little endian"), - _T("PDP endian") + wxT("Big endian"), + wxT("Little endian"), + wxT("PDP endian") }; // ---------------------------------------------------------------------------- // local functions // ---------------------------------------------------------------------------- -// returns log in base 2 of the value, this maps the enum values to the -// corresponding indices +// returns the logarithm in base 2 of 'value'; this maps the enum values to the +// corresponding indexes of the string arrays above static unsigned wxGetIndexFromEnumValue(int value) { - wxCHECK_MSG( value, (unsigned)-1, _T("invalid enum value") ); + wxCHECK_MSG( value, (unsigned)-1, wxT("invalid enum value") ); int n = 0; while ( !(value & 1) ) @@ -105,7 +112,7 @@ static unsigned wxGetIndexFromEnumValue(int value) n++; } - wxASSERT_MSG( value == 1, _T("more than one bit set in enum value") ); + wxASSERT_MSG( value == 1, wxT("more than one bit set in enum value") ); return n; } @@ -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, @@ -164,29 +153,84 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const m_osVersionMajor == t.m_osVersionMajor && m_osVersionMinor == t.m_osVersionMinor && m_os == t.m_os && + m_osDesc == t.m_osDesc && + m_ldi == t.m_ldi && + m_desktopEnv == t.m_desktopEnv && m_port == t.m_port && m_usingUniversal == t.m_usingUniversal && m_arch == t.m_arch && m_endian == t.m_endian; } +void wxPlatformInfo::InitForCurrentPlatform() +{ + // autodetect all informations + const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + if ( !traits ) + { + wxFAIL_MSG( wxT("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_desktopEnv = traits->GetDesktopEnvironment(); + } + + m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor); + m_osDesc = wxGetOsDescription(); + m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG; + m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32; + +#ifdef __LINUX__ + m_ldi = wxGetLinuxDistributionInfo(); +#endif + // else: leave m_ldi empty +} + +/* static */ +const wxPlatformInfo& wxPlatformInfo::Get() +{ + static bool initialized = false; + if ( !initialized ) + { + gs_platInfo.InitForCurrentPlatform(); + initialized = true; + } + + return gs_platInfo; +} + +/* static */ +wxString wxPlatformInfo::GetOperatingSystemDirectory() +{ + return wxGetOSDirectory(); +} + + + // ---------------------------------------------------------------------------- // wxPlatformInfo - enum -> string conversions // ---------------------------------------------------------------------------- wxString wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os) { - const wxChar* string = _T("Unknown"); + const wxChar* string = wxT("Unknown"); if ( os & wxOS_MAC ) - string = _T("Macintosh"); + string = wxT("Macintosh"); else if ( os & wxOS_WINDOWS ) - string = _T("Windows"); + string = wxT("Windows"); else if ( os & wxOS_UNIX ) - string = _T("Unix"); + string = wxT("Unix"); else if ( os == wxOS_DOS ) - string = _T("DOS"); + string = wxT("DOS"); else if ( os == wxOS_OS2 ) - string = _T("OS/2"); + string = wxT("OS/2"); return string; } @@ -196,7 +240,7 @@ wxString wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os) const unsigned idx = wxGetIndexFromEnumValue(os); wxCHECK_MSG( idx < WXSIZEOF(wxOperatingSystemIdNames), wxEmptyString, - _T("invalid OS id") ); + wxT("invalid OS id") ); return wxOperatingSystemIdNames[idx]; } @@ -206,7 +250,7 @@ wxString wxPlatformInfo::GetPortIdName(wxPortId port, bool usingUniversal) const unsigned idx = wxGetIndexFromEnumValue(port); wxCHECK_MSG( idx < WXSIZEOF(wxPortIdNames), wxEmptyString, - _T("invalid port id") ); + wxT("invalid port id") ); wxString ret = wxPortIdNames[idx]; @@ -221,7 +265,7 @@ wxString wxPlatformInfo::GetPortIdShortName(wxPortId port, bool usingUniversal) const unsigned idx = wxGetIndexFromEnumValue(port); wxCHECK_MSG( idx < WXSIZEOF(wxPortIdNames), wxEmptyString, - _T("invalid port id") ); + wxT("invalid port id") ); wxString ret = wxPortIdNames[idx]; ret = ret.Mid(2).Lower(); // remove 'wx' prefix @@ -293,11 +337,11 @@ wxArchitecture wxPlatformInfo::GetArch(const wxString &arch) wxEndianness wxPlatformInfo::GetEndianness(const wxString& end) { - wxString endl(end.Lower()); - if ( end.StartsWith(wxT("little")) ) + const wxString endl(end.Lower()); + if ( endl.StartsWith(wxT("little")) ) return wxENDIAN_LITTLE; - if ( end.StartsWith(wxT("big")) ) + if ( endl.StartsWith(wxT("big")) ) return wxENDIAN_BIG; return wxENDIAN_INVALID;