]> git.saurik.com Git - wxWidgets.git/blame - src/common/platinfo.cpp
Fix compilation under MSW with GCC cross.
[wxWidgets.git] / src / common / platinfo.cpp
CommitLineData
8bb6b2c0
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/platinfo.cpp
3// Purpose: implements wxPlatformInfo class
4// Author: Francesco Montorsi
5// Modified by:
6// Created: 07.07.2006 (based on wxToolkitInfo)
7// RCS-ID: $Id$
8// Copyright: (c) 2006 Francesco Montorsi
9// License: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
f566c8e2
PC
27#include "wx/platinfo.h"
28
8bb6b2c0 29#ifndef WX_PRECOMP
f566c8e2 30 #include "wx/app.h"
8bb6b2c0
VZ
31 #include "wx/utils.h"
32#endif //WX_PRECOMP
33
8bb6b2c0
VZ
34#include "wx/apptrait.h"
35
36// ----------------------------------------------------------------------------
37// constants
38// ----------------------------------------------------------------------------
39
8f493187 40static const wxChar* const wxOperatingSystemIdNames[] =
8bb6b2c0
VZ
41{
42 _T("Apple Mac OS"),
43 _T("Apple Mac OS X"),
44
45 _T("Microsoft Windows 9X"),
46 _T("Microsoft Windows NT"),
47 _T("Microsoft Windows Micro"),
48 _T("Microsoft Windows CE"),
49
50 _T("Linux"),
51 _T("FreeBSD"),
52 _T("OpenBSD"),
53 _T("NetBSD"),
54
55 _T("SunOS"),
56 _T("AIX"),
57 _T("HPUX"),
58
59 _T("DOS"),
60 _T("OS/2")
61};
62
8f493187 63static const wxChar* const wxPortIdNames[] =
8bb6b2c0
VZ
64{
65 _T("wxBase"),
66 _T("wxMSW"),
67 _T("wxMotif"),
68 _T("wxGTK"),
69 _T("wxMGL"),
70 _T("wxX11"),
71 _T("wxOS2"),
72 _T("wxMac"),
73 _T("wxCocoa"),
74 _T("wxWinCE"),
75 _T("wxPalmOS")
76};
77
8f493187 78static const wxChar* const wxArchitectureNames[] =
8bb6b2c0
VZ
79{
80 _T("32 bit"),
81 _T("64 bit")
82};
83
8f493187 84static const wxChar* const wxEndiannessNames[] =
8bb6b2c0
VZ
85{
86 _T("Big endian"),
87 _T("Little endian"),
88 _T("PDP endian")
89};
90
91// ----------------------------------------------------------------------------
92// local functions
93// ----------------------------------------------------------------------------
94
95// returns log in base 2 of the value, this maps the enum values to the
96// corresponding indices
78e9b418 97static unsigned wxGetIndexFromEnumValue(int value)
8bb6b2c0 98{
78e9b418 99 wxCHECK_MSG( value, (unsigned)-1, _T("invalid enum value") );
8bb6b2c0
VZ
100
101 int n = 0;
102 while ( !(value & 1) )
103 {
104 value >>= 1;
105 n++;
106 }
107
108 wxASSERT_MSG( value == 1, _T("more than one bit set in enum value") );
109
110 return n;
111}
112
113// ----------------------------------------------------------------------------
114// wxPlatformInfo
115// ----------------------------------------------------------------------------
116
117wxPlatformInfo::wxPlatformInfo()
118{
119 // autodetect all informations
120 const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
121 if ( !traits )
122 {
123 wxFAIL_MSG( _T("failed to initialize wxPlatformInfo") );
124
125 m_port = wxPORT_UNKNOWN;
b98bd6af 126 m_usingUniversal = false;
8bb6b2c0
VZ
127 m_tkVersionMajor =
128 m_tkVersionMinor = 0;
129 }
130 else
131 {
132 m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor);
b98bd6af 133 m_usingUniversal = traits->IsUsingUniversalWidgets();
8bb6b2c0
VZ
134 }
135
136 m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor);
137 m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG;
138 m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32;
139}
140
141wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor,
142 wxOperatingSystemId id, int osMajor, int osMinor,
143 wxArchitecture arch,
b98bd6af
VS
144 wxEndianness endian,
145 bool usingUniversal)
8bb6b2c0
VZ
146{
147 m_tkVersionMajor = tkMajor;
148 m_tkVersionMinor = tkMinor;
149 m_port = pid;
b98bd6af 150 m_usingUniversal = usingUniversal;
8bb6b2c0
VZ
151
152 m_os = id;
153 m_osVersionMajor = osMajor;
154 m_osVersionMinor = osMinor;
155
156 m_endian = endian;
157 m_arch = arch;
158}
159
160bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const
161{
162 return m_tkVersionMajor == t.m_tkVersionMajor &&
163 m_tkVersionMinor == t.m_tkVersionMinor &&
164 m_osVersionMajor == t.m_osVersionMajor &&
165 m_osVersionMinor == t.m_osVersionMinor &&
166 m_os == t.m_os &&
167 m_port == t.m_port &&
b98bd6af 168 m_usingUniversal == t.m_usingUniversal &&
8bb6b2c0
VZ
169 m_arch == t.m_arch &&
170 m_endian == t.m_endian;
171}
172
173// ----------------------------------------------------------------------------
174// wxPlatformInfo - enum -> string conversions
175// ----------------------------------------------------------------------------
176
177wxString wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os)
178{
8f493187 179 const wxChar* string = _T("Unknown");
8bb6b2c0 180 if ( os & wxOS_MAC )
8f493187 181 string = _T("Macintosh");
8bb6b2c0 182 else if ( os & wxOS_WINDOWS )
8f493187 183 string = _T("Windows");
8bb6b2c0 184 else if ( os & wxOS_UNIX )
8f493187 185 string = _T("Unix");
8bb6b2c0 186 else if ( os == wxOS_DOS )
8f493187 187 string = _T("DOS");
8bb6b2c0 188 else if ( os == wxOS_OS2 )
8f493187 189 string = _T("OS/2");
8bb6b2c0 190
8f493187 191 return string;
8bb6b2c0
VZ
192}
193
194wxString wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os)
195{
78e9b418 196 const unsigned idx = wxGetIndexFromEnumValue(os);
8bb6b2c0
VZ
197
198 wxCHECK_MSG( idx < WXSIZEOF(wxOperatingSystemIdNames), wxEmptyString,
199 _T("invalid OS id") );
200
201 return wxOperatingSystemIdNames[idx];
202}
203
b98bd6af 204wxString wxPlatformInfo::GetPortIdName(wxPortId port, bool usingUniversal)
8bb6b2c0 205{
78e9b418 206 const unsigned idx = wxGetIndexFromEnumValue(port);
8bb6b2c0
VZ
207
208 wxCHECK_MSG( idx < WXSIZEOF(wxPortIdNames), wxEmptyString,
209 _T("invalid port id") );
210
211 wxString ret = wxPortIdNames[idx];
212
b98bd6af 213 if ( usingUniversal )
8bb6b2c0
VZ
214 ret += wxT("/wxUniversal");
215
216 return ret;
217}
218
b98bd6af 219wxString wxPlatformInfo::GetPortIdShortName(wxPortId port, bool usingUniversal)
8bb6b2c0 220{
78e9b418 221 const unsigned idx = wxGetIndexFromEnumValue(port);
8bb6b2c0
VZ
222
223 wxCHECK_MSG( idx < WXSIZEOF(wxPortIdNames), wxEmptyString,
224 _T("invalid port id") );
225
226 wxString ret = wxPortIdNames[idx];
227 ret = ret.Mid(2).Lower(); // remove 'wx' prefix
228
b98bd6af 229 if ( usingUniversal )
8bb6b2c0
VZ
230 ret += wxT("univ");
231
232 return ret;
233}
234
235wxString wxPlatformInfo::GetArchName(wxArchitecture arch)
236{
237 wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxArchitectureNames) == wxARCH_MAX,
238 wxArchitectureNamesMismatch );
239
240 return wxArchitectureNames[arch];
241}
242
243wxString wxPlatformInfo::GetEndiannessName(wxEndianness end)
244{
245 wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxEndiannessNames) == wxENDIAN_MAX,
246 wxEndiannessNamesMismatch );
247
248 return wxEndiannessNames[end];
249}
250
251
252// ----------------------------------------------------------------------------
253// wxPlatformInfo - string -> enum conversions
254// ----------------------------------------------------------------------------
255
256wxOperatingSystemId wxPlatformInfo::GetOperatingSystemId(const wxString &str)
257{
258 for ( size_t i = 0; i < WXSIZEOF(wxOperatingSystemIdNames); i++ )
259 {
8f493187 260 if ( wxString(wxOperatingSystemIdNames[i]).CmpNoCase(str) == 0 )
8bb6b2c0
VZ
261 return (wxOperatingSystemId)(1 << i);
262 }
263
264 return wxOS_UNKNOWN;
265}
266
267wxPortId wxPlatformInfo::GetPortId(const wxString &str)
268{
269 // recognize both short and long port names
270 for ( size_t i = 0; i < WXSIZEOF(wxPortIdNames); i++ )
271 {
272 wxPortId current = (wxPortId)(1 << i);
273
8f493187
PC
274 if ( wxString(wxPortIdNames[i]).CmpNoCase(str) == 0 ||
275 GetPortIdShortName(current, true).CmpNoCase(str) == 0 ||
b98bd6af 276 GetPortIdShortName(current, false).CmpNoCase(str) == 0 )
8bb6b2c0
VZ
277 return current;
278 }
279
280 return wxPORT_UNKNOWN;
281}
282
283wxArchitecture wxPlatformInfo::GetArch(const wxString &arch)
284{
285 if ( arch.Contains(wxT("32")) )
286 return wxARCH_32;
287
288 if ( arch.Contains(wxT("64")) )
289 return wxARCH_64;
290
291 return wxARCH_INVALID;
292}
293
294wxEndianness wxPlatformInfo::GetEndianness(const wxString& end)
295{
296 wxString endl(end.Lower());
297 if ( end.StartsWith(wxT("little")) )
298 return wxENDIAN_LITTLE;
299
300 if ( end.StartsWith(wxT("big")) )
301 return wxENDIAN_BIG;
302
303 return wxENDIAN_INVALID;
304}
305