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"
27 #include "wx/platinfo.h"
34 #include "wx/apptrait.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 static wxString wxOperatingSystemIdNames
[] =
45 _T("Microsoft Windows 9X"),
46 _T("Microsoft Windows NT"),
47 _T("Microsoft Windows Micro"),
48 _T("Microsoft Windows CE"),
63 static wxString wxPortIdNames
[] =
78 static wxString wxArchitectureNames
[] =
84 static wxString wxEndiannessNames
[] =
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 // returns log in base 2 of the value, this maps the enum values to the
96 // corresponding indices
97 static unsigned wxGetIndexFromEnumValue(int value
)
99 wxCHECK_MSG( value
, (unsigned)-1, _T("invalid enum value") );
102 while ( !(value
& 1) )
108 wxASSERT_MSG( value
== 1, _T("more than one bit set in enum value") );
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 wxPlatformInfo::wxPlatformInfo()
119 // autodetect all informations
120 const wxAppTraits
* const traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
123 wxFAIL_MSG( _T("failed to initialize wxPlatformInfo") );
125 m_port
= wxPORT_UNKNOWN
;
127 m_tkVersionMinor
= 0;
131 m_port
= traits
->GetToolkitVersion(&m_tkVersionMajor
, &m_tkVersionMinor
);
134 m_os
= wxGetOsVersion(&m_osVersionMajor
, &m_osVersionMinor
);
135 m_endian
= wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE
: wxENDIAN_BIG
;
136 m_arch
= wxIsPlatform64Bit() ? wxARCH_64
: wxARCH_32
;
139 wxPlatformInfo::wxPlatformInfo(wxPortId pid
, int tkMajor
, int tkMinor
,
140 wxOperatingSystemId id
, int osMajor
, int osMinor
,
144 m_tkVersionMajor
= tkMajor
;
145 m_tkVersionMinor
= tkMinor
;
149 m_osVersionMajor
= osMajor
;
150 m_osVersionMinor
= osMinor
;
156 bool wxPlatformInfo::operator==(const wxPlatformInfo
&t
) const
158 return m_tkVersionMajor
== t
.m_tkVersionMajor
&&
159 m_tkVersionMinor
== t
.m_tkVersionMinor
&&
160 m_osVersionMajor
== t
.m_osVersionMajor
&&
161 m_osVersionMinor
== t
.m_osVersionMinor
&&
163 m_port
== t
.m_port
&&
164 m_arch
== t
.m_arch
&&
165 m_endian
== t
.m_endian
;
168 // ----------------------------------------------------------------------------
169 // wxPlatformInfo - enum -> string conversions
170 // ----------------------------------------------------------------------------
172 wxString
wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os
)
175 return _T("Macintosh");
176 else if ( os
& wxOS_WINDOWS
)
177 return _T("Windows");
178 else if ( os
& wxOS_UNIX
)
180 else if ( os
== wxOS_DOS
)
182 else if ( os
== wxOS_OS2
)
185 return _T("Unknown");
188 wxString
wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os
)
190 const unsigned idx
= wxGetIndexFromEnumValue(os
);
192 wxCHECK_MSG( idx
< WXSIZEOF(wxOperatingSystemIdNames
), wxEmptyString
,
193 _T("invalid OS id") );
195 return wxOperatingSystemIdNames
[idx
];
198 wxString
wxPlatformInfo::GetPortIdName(wxPortId port
)
200 const unsigned idx
= wxGetIndexFromEnumValue(port
);
202 wxCHECK_MSG( idx
< WXSIZEOF(wxPortIdNames
), wxEmptyString
,
203 _T("invalid port id") );
205 wxString ret
= wxPortIdNames
[idx
];
207 if ( IsUsingUniversalWidgets() )
208 ret
+= wxT("/wxUniversal");
213 wxString
wxPlatformInfo::GetPortIdShortName(wxPortId port
)
215 const unsigned idx
= wxGetIndexFromEnumValue(port
);
217 wxCHECK_MSG( idx
< WXSIZEOF(wxPortIdNames
), wxEmptyString
,
218 _T("invalid port id") );
220 wxString ret
= wxPortIdNames
[idx
];
221 ret
= ret
.Mid(2).Lower(); // remove 'wx' prefix
223 if ( IsUsingUniversalWidgets() )
229 wxString
wxPlatformInfo::GetArchName(wxArchitecture arch
)
231 wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxArchitectureNames
) == wxARCH_MAX
,
232 wxArchitectureNamesMismatch
);
234 return wxArchitectureNames
[arch
];
237 wxString
wxPlatformInfo::GetEndiannessName(wxEndianness end
)
239 wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxEndiannessNames
) == wxENDIAN_MAX
,
240 wxEndiannessNamesMismatch
);
242 return wxEndiannessNames
[end
];
246 // ----------------------------------------------------------------------------
247 // wxPlatformInfo - string -> enum conversions
248 // ----------------------------------------------------------------------------
250 wxOperatingSystemId
wxPlatformInfo::GetOperatingSystemId(const wxString
&str
)
252 for ( size_t i
= 0; i
< WXSIZEOF(wxOperatingSystemIdNames
); i
++ )
254 if ( wxOperatingSystemIdNames
[i
].CmpNoCase(str
) == 0 )
255 return (wxOperatingSystemId
)(1 << i
);
261 wxPortId
wxPlatformInfo::GetPortId(const wxString
&str
)
263 // recognize both short and long port names
264 for ( size_t i
= 0; i
< WXSIZEOF(wxPortIdNames
); i
++ )
266 wxPortId current
= (wxPortId
)(1 << i
);
268 if ( wxPortIdNames
[i
].CmpNoCase(str
) == 0 )
270 if ( GetPortIdShortName(current
).CmpNoCase(str
) == 0 )
274 return wxPORT_UNKNOWN
;
277 wxArchitecture
wxPlatformInfo::GetArch(const wxString
&arch
)
279 if ( arch
.Contains(wxT("32")) )
282 if ( arch
.Contains(wxT("64")) )
285 return wxARCH_INVALID
;
288 wxEndianness
wxPlatformInfo::GetEndianness(const wxString
& end
)
290 wxString
endl(end
.Lower());
291 if ( end
.StartsWith(wxT("little")) )
292 return wxENDIAN_LITTLE
;
294 if ( end
.StartsWith(wxT("big")) )
297 return wxENDIAN_INVALID
;