1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/common/platinfo.cpp 
   3 // Purpose:     implements wxPlatformInfo class 
   4 // Author:      Francesco Montorsi 
   6 // Created:     07.07.2006 (based on wxToolkitInfo) 
   8 // Copyright:   (c) 2006 Francesco Montorsi 
   9 // License:     wxWindows license 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  20 // for compilers that support precompilation, includes "wx.h". 
  21 #include "wx/wxprec.h" 
  31 #include "wx/platinfo.h" 
  32 #include "wx/apptrait.h" 
  34 // ---------------------------------------------------------------------------- 
  36 // ---------------------------------------------------------------------------- 
  38 static wxString wxOperatingSystemIdNames
[] = 
  43     _T("Microsoft Windows 9X"), 
  44     _T("Microsoft Windows NT"), 
  45     _T("Microsoft Windows Micro"), 
  46     _T("Microsoft Windows CE"), 
  61 static wxString wxPortIdNames
[] = 
  76 static wxString wxArchitectureNames
[] = 
  82 static wxString wxEndiannessNames
[] = 
  89 // ---------------------------------------------------------------------------- 
  91 // ---------------------------------------------------------------------------- 
  93 // returns log in base 2 of the value, this maps the enum values to the 
  94 // corresponding indices 
  95 static unsigned wxGetIndexFromEnumValue(int value
) 
  97     wxCHECK_MSG( value
, (unsigned)-1, _T("invalid enum value") ); 
 100     while ( !(value 
& 1) ) 
 106     wxASSERT_MSG( value 
== 1, _T("more than one bit set in enum value") ); 
 111 // ---------------------------------------------------------------------------- 
 113 // ---------------------------------------------------------------------------- 
 115 wxPlatformInfo::wxPlatformInfo() 
 117     // autodetect all informations 
 118     const wxAppTraits 
* const traits 
= wxTheApp 
? wxTheApp
->GetTraits() : NULL
; 
 121         wxFAIL_MSG( _T("failed to initialize wxPlatformInfo") ); 
 123         m_port 
= wxPORT_UNKNOWN
; 
 125         m_tkVersionMinor 
= 0; 
 129         m_port 
= traits
->GetToolkitVersion(&m_tkVersionMajor
, &m_tkVersionMinor
); 
 132     m_os 
= wxGetOsVersion(&m_osVersionMajor
, &m_osVersionMinor
); 
 133     m_endian 
= wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE 
: wxENDIAN_BIG
; 
 134     m_arch 
= wxIsPlatform64Bit() ? wxARCH_64 
: wxARCH_32
; 
 137 wxPlatformInfo::wxPlatformInfo(wxPortId pid
, int tkMajor
, int tkMinor
, 
 138                                wxOperatingSystemId id
, int osMajor
, int osMinor
, 
 142     m_tkVersionMajor 
= tkMajor
; 
 143     m_tkVersionMinor 
= tkMinor
; 
 147     m_osVersionMajor 
= osMajor
; 
 148     m_osVersionMinor 
= osMinor
; 
 154 bool wxPlatformInfo::operator==(const wxPlatformInfo 
&t
) const 
 156     return m_tkVersionMajor 
== t
.m_tkVersionMajor 
&& 
 157            m_tkVersionMinor 
== t
.m_tkVersionMinor 
&& 
 158            m_osVersionMajor 
== t
.m_osVersionMajor 
&& 
 159            m_osVersionMinor 
== t
.m_osVersionMinor 
&& 
 161            m_port 
== t
.m_port 
&& 
 162            m_arch 
== t
.m_arch 
&& 
 163            m_endian 
== t
.m_endian
; 
 166 // ---------------------------------------------------------------------------- 
 167 // wxPlatformInfo - enum -> string conversions 
 168 // ---------------------------------------------------------------------------- 
 170 wxString 
wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os
) 
 173         return _T("Macintosh"); 
 174     else if ( os 
& wxOS_WINDOWS 
) 
 175         return _T("Windows"); 
 176     else if ( os 
& wxOS_UNIX 
) 
 178     else if ( os 
== wxOS_DOS 
) 
 180     else if ( os 
== wxOS_OS2 
) 
 183     return _T("Unknown"); 
 186 wxString 
wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os
) 
 188     const unsigned idx 
= wxGetIndexFromEnumValue(os
); 
 190     wxCHECK_MSG( idx 
< WXSIZEOF(wxOperatingSystemIdNames
), wxEmptyString
, 
 191                  _T("invalid OS id") ); 
 193     return wxOperatingSystemIdNames
[idx
]; 
 196 wxString 
wxPlatformInfo::GetPortIdName(wxPortId port
) 
 198     const unsigned idx 
= wxGetIndexFromEnumValue(port
); 
 200     wxCHECK_MSG( idx 
< WXSIZEOF(wxPortIdNames
), wxEmptyString
, 
 201                  _T("invalid port id") ); 
 203     wxString ret 
= wxPortIdNames
[idx
]; 
 205     if ( IsUsingUniversalWidgets() ) 
 206         ret 
+= wxT("/wxUniversal"); 
 211 wxString 
wxPlatformInfo::GetPortIdShortName(wxPortId port
) 
 213     const unsigned idx 
= wxGetIndexFromEnumValue(port
); 
 215     wxCHECK_MSG( idx 
< WXSIZEOF(wxPortIdNames
), wxEmptyString
, 
 216                  _T("invalid port id") ); 
 218     wxString ret 
= wxPortIdNames
[idx
]; 
 219     ret 
= ret
.Mid(2).Lower();       // remove 'wx' prefix 
 221     if ( IsUsingUniversalWidgets() ) 
 227 wxString 
wxPlatformInfo::GetArchName(wxArchitecture arch
) 
 229     wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxArchitectureNames
) == wxARCH_MAX
, 
 230                            wxArchitectureNamesMismatch 
); 
 232     return wxArchitectureNames
[arch
]; 
 235 wxString 
wxPlatformInfo::GetEndiannessName(wxEndianness end
) 
 237     wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxEndiannessNames
) == wxENDIAN_MAX
, 
 238                            wxEndiannessNamesMismatch 
); 
 240     return wxEndiannessNames
[end
]; 
 244 // ---------------------------------------------------------------------------- 
 245 // wxPlatformInfo - string -> enum conversions 
 246 // ---------------------------------------------------------------------------- 
 248 wxOperatingSystemId 
wxPlatformInfo::GetOperatingSystemId(const wxString 
&str
) 
 250     for ( size_t i 
= 0; i 
< WXSIZEOF(wxOperatingSystemIdNames
); i
++ ) 
 252         if ( wxOperatingSystemIdNames
[i
].CmpNoCase(str
) == 0 ) 
 253             return (wxOperatingSystemId
)(1 << i
); 
 259 wxPortId 
wxPlatformInfo::GetPortId(const wxString 
&str
) 
 261     // recognize both short and long port names 
 262     for ( size_t i 
= 0; i 
< WXSIZEOF(wxPortIdNames
); i
++ ) 
 264         wxPortId current 
= (wxPortId
)(1 << i
); 
 266         if ( wxPortIdNames
[i
].CmpNoCase(str
) == 0 ) 
 268         if ( GetPortIdShortName(current
).CmpNoCase(str
) == 0 ) 
 272     return wxPORT_UNKNOWN
; 
 275 wxArchitecture 
wxPlatformInfo::GetArch(const wxString 
&arch
) 
 277     if ( arch
.Contains(wxT("32")) ) 
 280     if ( arch
.Contains(wxT("64")) ) 
 283     return wxARCH_INVALID
; 
 286 wxEndianness 
wxPlatformInfo::GetEndianness(const wxString
& end
) 
 288     wxString 
endl(end
.Lower()); 
 289     if ( end
.StartsWith(wxT("little")) ) 
 290         return wxENDIAN_LITTLE
; 
 292     if ( end
.StartsWith(wxT("big")) ) 
 295     return wxENDIAN_INVALID
;