]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/platinfo.cpp
Added pango_context_get_language to speed up pango_context_get_metrics
[wxWidgets.git] / src / common / platinfo.cpp
... / ...
CommitLineData
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
27#include "wx/platinfo.h"
28
29#ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/utils.h"
32#endif //WX_PRECOMP
33
34#include "wx/apptrait.h"
35
36// ----------------------------------------------------------------------------
37// constants
38// ----------------------------------------------------------------------------
39
40static const wxChar* const wxOperatingSystemIdNames[] =
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
63static const wxChar* const wxPortIdNames[] =
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 _T("wxDFB")
77};
78
79static const wxChar* const wxArchitectureNames[] =
80{
81 _T("32 bit"),
82 _T("64 bit")
83};
84
85static const wxChar* const wxEndiannessNames[] =
86{
87 _T("Big endian"),
88 _T("Little endian"),
89 _T("PDP endian")
90};
91
92// ----------------------------------------------------------------------------
93// local functions
94// ----------------------------------------------------------------------------
95
96// returns log in base 2 of the value, this maps the enum values to the
97// corresponding indices
98static unsigned wxGetIndexFromEnumValue(int value)
99{
100 wxCHECK_MSG( value, (unsigned)-1, _T("invalid enum value") );
101
102 int n = 0;
103 while ( !(value & 1) )
104 {
105 value >>= 1;
106 n++;
107 }
108
109 wxASSERT_MSG( value == 1, _T("more than one bit set in enum value") );
110
111 return n;
112}
113
114// ----------------------------------------------------------------------------
115// wxPlatformInfo
116// ----------------------------------------------------------------------------
117
118wxPlatformInfo::wxPlatformInfo()
119{
120 // autodetect all informations
121 const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
122 if ( !traits )
123 {
124 wxFAIL_MSG( _T("failed to initialize wxPlatformInfo") );
125
126 m_port = wxPORT_UNKNOWN;
127 m_usingUniversal = false;
128 m_tkVersionMajor =
129 m_tkVersionMinor = 0;
130 }
131 else
132 {
133 m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor);
134 m_usingUniversal = traits->IsUsingUniversalWidgets();
135 }
136
137 m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor);
138 m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG;
139 m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32;
140}
141
142wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor,
143 wxOperatingSystemId id, int osMajor, int osMinor,
144 wxArchitecture arch,
145 wxEndianness endian,
146 bool usingUniversal)
147{
148 m_tkVersionMajor = tkMajor;
149 m_tkVersionMinor = tkMinor;
150 m_port = pid;
151 m_usingUniversal = usingUniversal;
152
153 m_os = id;
154 m_osVersionMajor = osMajor;
155 m_osVersionMinor = osMinor;
156
157 m_endian = endian;
158 m_arch = arch;
159}
160
161bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const
162{
163 return m_tkVersionMajor == t.m_tkVersionMajor &&
164 m_tkVersionMinor == t.m_tkVersionMinor &&
165 m_osVersionMajor == t.m_osVersionMajor &&
166 m_osVersionMinor == t.m_osVersionMinor &&
167 m_os == t.m_os &&
168 m_port == t.m_port &&
169 m_usingUniversal == t.m_usingUniversal &&
170 m_arch == t.m_arch &&
171 m_endian == t.m_endian;
172}
173
174// ----------------------------------------------------------------------------
175// wxPlatformInfo - enum -> string conversions
176// ----------------------------------------------------------------------------
177
178wxString wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os)
179{
180 const wxChar* string = _T("Unknown");
181 if ( os & wxOS_MAC )
182 string = _T("Macintosh");
183 else if ( os & wxOS_WINDOWS )
184 string = _T("Windows");
185 else if ( os & wxOS_UNIX )
186 string = _T("Unix");
187 else if ( os == wxOS_DOS )
188 string = _T("DOS");
189 else if ( os == wxOS_OS2 )
190 string = _T("OS/2");
191
192 return string;
193}
194
195wxString wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os)
196{
197 const unsigned idx = wxGetIndexFromEnumValue(os);
198
199 wxCHECK_MSG( idx < WXSIZEOF(wxOperatingSystemIdNames), wxEmptyString,
200 _T("invalid OS id") );
201
202 return wxOperatingSystemIdNames[idx];
203}
204
205wxString wxPlatformInfo::GetPortIdName(wxPortId port, bool usingUniversal)
206{
207 const unsigned idx = wxGetIndexFromEnumValue(port);
208
209 wxCHECK_MSG( idx < WXSIZEOF(wxPortIdNames), wxEmptyString,
210 _T("invalid port id") );
211
212 wxString ret = wxPortIdNames[idx];
213
214 if ( usingUniversal )
215 ret += wxT("/wxUniversal");
216
217 return ret;
218}
219
220wxString wxPlatformInfo::GetPortIdShortName(wxPortId port, bool usingUniversal)
221{
222 const unsigned idx = wxGetIndexFromEnumValue(port);
223
224 wxCHECK_MSG( idx < WXSIZEOF(wxPortIdNames), wxEmptyString,
225 _T("invalid port id") );
226
227 wxString ret = wxPortIdNames[idx];
228 ret = ret.Mid(2).Lower(); // remove 'wx' prefix
229
230 if ( usingUniversal )
231 ret += wxT("univ");
232
233 return ret;
234}
235
236wxString wxPlatformInfo::GetArchName(wxArchitecture arch)
237{
238 wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxArchitectureNames) == wxARCH_MAX,
239 wxArchitectureNamesMismatch );
240
241 return wxArchitectureNames[arch];
242}
243
244wxString wxPlatformInfo::GetEndiannessName(wxEndianness end)
245{
246 wxCOMPILE_TIME_ASSERT( WXSIZEOF(wxEndiannessNames) == wxENDIAN_MAX,
247 wxEndiannessNamesMismatch );
248
249 return wxEndiannessNames[end];
250}
251
252
253// ----------------------------------------------------------------------------
254// wxPlatformInfo - string -> enum conversions
255// ----------------------------------------------------------------------------
256
257wxOperatingSystemId wxPlatformInfo::GetOperatingSystemId(const wxString &str)
258{
259 for ( size_t i = 0; i < WXSIZEOF(wxOperatingSystemIdNames); i++ )
260 {
261 if ( wxString(wxOperatingSystemIdNames[i]).CmpNoCase(str) == 0 )
262 return (wxOperatingSystemId)(1 << i);
263 }
264
265 return wxOS_UNKNOWN;
266}
267
268wxPortId wxPlatformInfo::GetPortId(const wxString &str)
269{
270 // recognize both short and long port names
271 for ( size_t i = 0; i < WXSIZEOF(wxPortIdNames); i++ )
272 {
273 wxPortId current = (wxPortId)(1 << i);
274
275 if ( wxString(wxPortIdNames[i]).CmpNoCase(str) == 0 ||
276 GetPortIdShortName(current, true).CmpNoCase(str) == 0 ||
277 GetPortIdShortName(current, false).CmpNoCase(str) == 0 )
278 return current;
279 }
280
281 return wxPORT_UNKNOWN;
282}
283
284wxArchitecture wxPlatformInfo::GetArch(const wxString &arch)
285{
286 if ( arch.Contains(wxT("32")) )
287 return wxARCH_32;
288
289 if ( arch.Contains(wxT("64")) )
290 return wxARCH_64;
291
292 return wxARCH_INVALID;
293}
294
295wxEndianness wxPlatformInfo::GetEndianness(const wxString& end)
296{
297 wxString endl(end.Lower());
298 if ( end.StartsWith(wxT("little")) )
299 return wxENDIAN_LITTLE;
300
301 if ( end.StartsWith(wxT("big")) )
302 return wxENDIAN_BIG;
303
304 return wxENDIAN_INVALID;
305}
306