]>
Commit | Line | Data |
---|---|---|
8bb6b2c0 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/platinfo.h | |
3 | // Purpose: declaration of the wxPlatformInfo class | |
4 | // Author: Francesco Montorsi | |
5 | // Modified by: | |
6 | // Created: 07.07.2006 (based on wxToolkitInfo) | |
8bb6b2c0 | 7 | // Copyright: (c) 2006 Francesco Montorsi |
526954c5 | 8 | // Licence: wxWindows licence |
8bb6b2c0 VZ |
9 | /////////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_PLATINFO_H_ | |
12 | #define _WX_PLATINFO_H_ | |
13 | ||
b20ca997 | 14 | #include "wx/string.h" |
8bb6b2c0 VZ |
15 | |
16 | // ---------------------------------------------------------------------------- | |
23790a2a | 17 | // wxPlatformInfo enums & structs |
8bb6b2c0 VZ |
18 | // ---------------------------------------------------------------------------- |
19 | ||
20 | // VERY IMPORTANT: when changing these enum values, also change the relative | |
21 | // string tables in src/common/platinfo.cpp | |
22 | ||
23 | ||
24 | // families & sub-families of operating systems | |
25 | enum wxOperatingSystemId | |
26 | { | |
27 | wxOS_UNKNOWN = 0, // returned on error | |
28 | ||
29 | wxOS_MAC_OS = 1 << 0, // Apple Mac OS 8/9/X with Mac paths | |
30 | wxOS_MAC_OSX_DARWIN = 1 << 1, // Apple Mac OS X with Unix paths | |
31 | wxOS_MAC = wxOS_MAC_OS|wxOS_MAC_OSX_DARWIN, | |
32 | ||
33 | wxOS_WINDOWS_9X = 1 << 2, // Windows 9x family (95/98/ME) | |
34 | wxOS_WINDOWS_NT = 1 << 3, // Windows NT family (NT/2000/XP) | |
35 | wxOS_WINDOWS_MICRO = 1 << 4, // MicroWindows | |
36 | wxOS_WINDOWS_CE = 1 << 5, // Windows CE (Window Mobile) | |
37 | wxOS_WINDOWS = wxOS_WINDOWS_9X | | |
38 | wxOS_WINDOWS_NT | | |
39 | wxOS_WINDOWS_MICRO | | |
40 | wxOS_WINDOWS_CE, | |
41 | ||
42 | wxOS_UNIX_LINUX = 1 << 6, // Linux | |
43 | wxOS_UNIX_FREEBSD = 1 << 7, // FreeBSD | |
44 | wxOS_UNIX_OPENBSD = 1 << 8, // OpenBSD | |
45 | wxOS_UNIX_NETBSD = 1 << 9, // NetBSD | |
46 | wxOS_UNIX_SOLARIS = 1 << 10, // SunOS | |
47 | wxOS_UNIX_AIX = 1 << 11, // AIX | |
48 | wxOS_UNIX_HPUX = 1 << 12, // HP/UX | |
49 | wxOS_UNIX = wxOS_UNIX_LINUX | | |
50 | wxOS_UNIX_FREEBSD | | |
51 | wxOS_UNIX_OPENBSD | | |
52 | wxOS_UNIX_NETBSD | | |
53 | wxOS_UNIX_SOLARIS | | |
54 | wxOS_UNIX_AIX | | |
55 | wxOS_UNIX_HPUX, | |
56 | ||
57 | // 1<<13 and 1<<14 available for other Unix flavours | |
58 | ||
59 | wxOS_DOS = 1 << 15, // Microsoft DOS | |
bd362275 | 60 | wxOS_OS2 = 1 << 16 // OS/2 |
8bb6b2c0 VZ |
61 | }; |
62 | ||
63 | // list of wxWidgets ports - some of them can be used with more than | |
64 | // a single toolkit. | |
65 | enum wxPortId | |
66 | { | |
67 | wxPORT_UNKNOWN = 0, // returned on error | |
68 | ||
69 | wxPORT_BASE = 1 << 0, // wxBase, no native toolkit used | |
70 | ||
71 | wxPORT_MSW = 1 << 1, // wxMSW, native toolkit is Windows API | |
72 | wxPORT_MOTIF = 1 << 2, // wxMotif, using [Open]Motif or Lesstif | |
73 | wxPORT_GTK = 1 << 3, // wxGTK, using GTK+ 1.x, 2.x, GPE or Maemo | |
0e1f8ea4 | 74 | wxPORT_DFB = 1 << 4, // wxDFB, using wxUniversal |
8bb6b2c0 | 75 | wxPORT_X11 = 1 << 5, // wxX11, using wxUniversal |
8ab09e65 SN |
76 | wxPORT_PM = 1 << 6, // wxOS2, using OS/2 Presentation Manager |
77 | wxPORT_OS2 = wxPORT_PM, // wxOS2, using OS/2 Presentation Manager | |
ac9e3f1f SC |
78 | wxPORT_MAC = 1 << 7, // wxOSX (former wxMac), using Cocoa, Carbon or iPhone API |
79 | wxPORT_OSX = wxPORT_MAC, // wxOSX, using Cocoa, Carbon or iPhone API | |
8bb6b2c0 | 80 | wxPORT_COCOA = 1 << 8, // wxCocoa, using Cocoa NextStep/Mac API |
0e1f8ea4 | 81 | wxPORT_WINCE = 1 << 9 // wxWinCE, toolkit is WinCE SDK API |
8bb6b2c0 VZ |
82 | }; |
83 | ||
84 | // architecture of the operating system | |
85 | // (regardless of the build environment of wxWidgets library - see | |
86 | // wxIsPlatform64bit documentation for more info) | |
87 | enum wxArchitecture | |
88 | { | |
89 | wxARCH_INVALID = -1, // returned on error | |
90 | ||
91 | wxARCH_32, // 32 bit | |
92 | wxARCH_64, | |
93 | ||
94 | wxARCH_MAX | |
95 | }; | |
96 | ||
97 | ||
98 | // endian-ness of the machine | |
99 | enum wxEndianness | |
100 | { | |
101 | wxENDIAN_INVALID = -1, // returned on error | |
102 | ||
103 | wxENDIAN_BIG, // 4321 | |
104 | wxENDIAN_LITTLE, // 1234 | |
105 | wxENDIAN_PDP, // 3412 | |
106 | ||
107 | wxENDIAN_MAX | |
108 | }; | |
109 | ||
23790a2a FM |
110 | // informations about a linux distro returned by the lsb_release utility |
111 | struct wxLinuxDistributionInfo | |
112 | { | |
113 | wxString Id; | |
114 | wxString Release; | |
115 | wxString CodeName; | |
116 | wxString Description; | |
03647350 | 117 | |
23790a2a | 118 | bool operator==(const wxLinuxDistributionInfo& ldi) const |
03647350 | 119 | { |
23790a2a FM |
120 | return Id == ldi.Id && |
121 | Release == ldi.Release && | |
122 | CodeName == ldi.CodeName && | |
123 | Description == ldi.Description; | |
124 | } | |
03647350 | 125 | |
23790a2a FM |
126 | bool operator!=(const wxLinuxDistributionInfo& ldi) const |
127 | { return !(*this == ldi); } | |
128 | }; | |
129 | ||
130 | ||
131 | // ---------------------------------------------------------------------------- | |
132 | // wxPlatformInfo | |
133 | // ---------------------------------------------------------------------------- | |
134 | ||
8bb6b2c0 VZ |
135 | // Information about the toolkit that the app is running under and some basic |
136 | // platform and architecture info | |
137 | class WXDLLIMPEXP_BASE wxPlatformInfo | |
138 | { | |
139 | public: | |
140 | wxPlatformInfo(); | |
141 | wxPlatformInfo(wxPortId pid, | |
142 | int tkMajor = -1, int tkMinor = -1, | |
143 | wxOperatingSystemId id = wxOS_UNKNOWN, | |
144 | int osMajor = -1, int osMinor = -1, | |
145 | wxArchitecture arch = wxARCH_INVALID, | |
b98bd6af VS |
146 | wxEndianness endian = wxENDIAN_INVALID, |
147 | bool usingUniversal = false); | |
8bb6b2c0 VZ |
148 | |
149 | // default copy ctor, assignment operator and dtor are ok | |
150 | ||
151 | bool operator==(const wxPlatformInfo &t) const; | |
152 | ||
153 | bool operator!=(const wxPlatformInfo &t) const | |
154 | { return !(*this == t); } | |
155 | ||
449090b5 VZ |
156 | // Gets a wxPlatformInfo already initialized with the values for |
157 | // the currently running platform. | |
158 | static const wxPlatformInfo& Get(); | |
159 | ||
160 | ||
8bb6b2c0 VZ |
161 | |
162 | // string -> enum conversions | |
163 | // --------------------------------- | |
164 | ||
165 | static wxOperatingSystemId GetOperatingSystemId(const wxString &name); | |
166 | static wxPortId GetPortId(const wxString &portname); | |
167 | ||
168 | static wxArchitecture GetArch(const wxString &arch); | |
169 | static wxEndianness GetEndianness(const wxString &end); | |
170 | ||
171 | // enum -> string conversions | |
172 | // --------------------------------- | |
173 | ||
174 | static wxString GetOperatingSystemFamilyName(wxOperatingSystemId os); | |
175 | static wxString GetOperatingSystemIdName(wxOperatingSystemId os); | |
b98bd6af VS |
176 | static wxString GetPortIdName(wxPortId port, bool usingUniversal); |
177 | static wxString GetPortIdShortName(wxPortId port, bool usingUniversal); | |
8bb6b2c0 VZ |
178 | |
179 | static wxString GetArchName(wxArchitecture arch); | |
180 | static wxString GetEndiannessName(wxEndianness end); | |
181 | ||
03647350 | 182 | |
8bb6b2c0 VZ |
183 | // getters |
184 | // ----------------- | |
185 | ||
186 | int GetOSMajorVersion() const | |
187 | { return m_osVersionMajor; } | |
188 | int GetOSMinorVersion() const | |
189 | { return m_osVersionMinor; } | |
190 | ||
a24db82d VZ |
191 | // return true if the OS version >= major.minor |
192 | bool CheckOSVersion(int major, int minor) const | |
193 | { | |
194 | return DoCheckVersion(GetOSMajorVersion(), | |
195 | GetOSMinorVersion(), | |
196 | major, | |
197 | minor); | |
198 | } | |
199 | ||
8bb6b2c0 VZ |
200 | int GetToolkitMajorVersion() const |
201 | { return m_tkVersionMajor; } | |
202 | int GetToolkitMinorVersion() const | |
203 | { return m_tkVersionMinor; } | |
204 | ||
a24db82d VZ |
205 | bool CheckToolkitVersion(int major, int minor) const |
206 | { | |
207 | return DoCheckVersion(GetToolkitMajorVersion(), | |
208 | GetToolkitMinorVersion(), | |
209 | major, | |
210 | minor); | |
211 | } | |
212 | ||
b98bd6af VS |
213 | bool IsUsingUniversalWidgets() const |
214 | { return m_usingUniversal; } | |
215 | ||
8bb6b2c0 VZ |
216 | wxOperatingSystemId GetOperatingSystemId() const |
217 | { return m_os; } | |
23790a2a FM |
218 | wxLinuxDistributionInfo GetLinuxDistributionInfo() const |
219 | { return m_ldi; } | |
8bb6b2c0 VZ |
220 | wxPortId GetPortId() const |
221 | { return m_port; } | |
222 | wxArchitecture GetArchitecture() const | |
223 | { return m_arch; } | |
224 | wxEndianness GetEndianness() const | |
225 | { return m_endian; } | |
226 | ||
227 | ||
228 | // string getters | |
229 | // ----------------- | |
230 | ||
231 | wxString GetOperatingSystemFamilyName() const | |
232 | { return GetOperatingSystemFamilyName(m_os); } | |
233 | wxString GetOperatingSystemIdName() const | |
234 | { return GetOperatingSystemIdName(m_os); } | |
235 | wxString GetPortIdName() const | |
b98bd6af | 236 | { return GetPortIdName(m_port, m_usingUniversal); } |
8bb6b2c0 | 237 | wxString GetPortIdShortName() const |
b98bd6af | 238 | { return GetPortIdShortName(m_port, m_usingUniversal); } |
8bb6b2c0 VZ |
239 | wxString GetArchName() const |
240 | { return GetArchName(m_arch); } | |
241 | wxString GetEndiannessName() const | |
242 | { return GetEndiannessName(m_endian); } | |
23790a2a FM |
243 | wxString GetOperatingSystemDescription() const |
244 | { return m_osDesc; } | |
245 | wxString GetDesktopEnvironment() const | |
246 | { return m_desktopEnv; } | |
03647350 | 247 | |
23790a2a FM |
248 | static wxString GetOperatingSystemDirectory(); |
249 | // doesn't make sense to store inside wxPlatformInfo the OS directory, | |
250 | // thus this function is static; note that this function simply calls | |
03647350 | 251 | // wxGetOSDirectory() and is here just to make it easier for the user to |
23790a2a | 252 | // find it that feature (global functions can be difficult to find in the docs) |
8bb6b2c0 VZ |
253 | |
254 | // setters | |
255 | // ----------------- | |
256 | ||
257 | void SetOSVersion(int major, int minor) | |
258 | { m_osVersionMajor=major; m_osVersionMinor=minor; } | |
259 | void SetToolkitVersion(int major, int minor) | |
260 | { m_tkVersionMajor=major; m_tkVersionMinor=minor; } | |
261 | ||
262 | void SetOperatingSystemId(wxOperatingSystemId n) | |
a24db82d | 263 | { m_os = n; } |
23790a2a FM |
264 | void SetOperatingSystemDescription(const wxString& desc) |
265 | { m_osDesc = desc; } | |
8bb6b2c0 | 266 | void SetPortId(wxPortId n) |
a24db82d | 267 | { m_port = n; } |
8bb6b2c0 | 268 | void SetArchitecture(wxArchitecture n) |
a24db82d | 269 | { m_arch = n; } |
8bb6b2c0 | 270 | void SetEndianness(wxEndianness n) |
a24db82d | 271 | { m_endian = n; } |
03647350 | 272 | |
23790a2a FM |
273 | void SetDesktopEnvironment(const wxString& de) |
274 | { m_desktopEnv = de; } | |
275 | void SetLinuxDistributionInfo(const wxLinuxDistributionInfo& di) | |
276 | { m_ldi = di; } | |
277 | ||
8bb6b2c0 VZ |
278 | |
279 | // miscellaneous | |
280 | // ----------------- | |
281 | ||
282 | bool IsOk() const | |
283 | { | |
284 | return m_osVersionMajor != -1 && m_osVersionMinor != -1 && | |
285 | m_os != wxOS_UNKNOWN && | |
23790a2a | 286 | !m_osDesc.IsEmpty() && |
8bb6b2c0 VZ |
287 | m_tkVersionMajor != -1 && m_tkVersionMinor != -1 && |
288 | m_port != wxPORT_UNKNOWN && | |
03647350 | 289 | m_arch != wxARCH_INVALID && |
23790a2a | 290 | m_endian != wxENDIAN_INVALID; |
03647350 | 291 | |
23790a2a | 292 | // do not check linux-specific info; it's ok to have them empty |
8bb6b2c0 VZ |
293 | } |
294 | ||
8bb6b2c0 VZ |
295 | |
296 | protected: | |
a24db82d VZ |
297 | static bool DoCheckVersion(int majorCur, int minorCur, int major, int minor) |
298 | { | |
299 | return majorCur > major || (majorCur == major && minorCur >= minor); | |
300 | } | |
301 | ||
449090b5 VZ |
302 | void InitForCurrentPlatform(); |
303 | ||
304 | ||
8bb6b2c0 VZ |
305 | // OS stuff |
306 | // ----------------- | |
307 | ||
308 | // Version of the OS; valid if m_os != wxOS_UNKNOWN | |
309 | // (-1 means not initialized yet). | |
a24db82d VZ |
310 | int m_osVersionMajor, |
311 | m_osVersionMinor; | |
8bb6b2c0 VZ |
312 | |
313 | // Operating system ID. | |
314 | wxOperatingSystemId m_os; | |
03647350 | 315 | |
23790a2a FM |
316 | // Operating system description. |
317 | wxString m_osDesc; | |
03647350 VZ |
318 | |
319 | ||
23790a2a FM |
320 | // linux-specific |
321 | // ----------------- | |
03647350 | 322 | |
23790a2a FM |
323 | wxString m_desktopEnv; |
324 | wxLinuxDistributionInfo m_ldi; | |
8bb6b2c0 VZ |
325 | |
326 | ||
327 | // toolkit | |
328 | // ----------------- | |
329 | ||
330 | // Version of the underlying toolkit | |
331 | // (-1 means not initialized yet; zero means no toolkit). | |
332 | int m_tkVersionMajor, m_tkVersionMinor; | |
333 | ||
334 | // name of the wxWidgets port | |
335 | wxPortId m_port; | |
336 | ||
b98bd6af VS |
337 | // is using wxUniversal widgets? |
338 | bool m_usingUniversal; | |
339 | ||
8bb6b2c0 VZ |
340 | |
341 | // others | |
342 | // ----------------- | |
343 | ||
23790a2a | 344 | // architecture of the OS/machine |
8bb6b2c0 VZ |
345 | wxArchitecture m_arch; |
346 | ||
347 | // endianness of the machine | |
348 | wxEndianness m_endian; | |
349 | }; | |
350 | ||
351 | ||
352 | #if WXWIN_COMPATIBILITY_2_6 | |
353 | #define wxUNKNOWN_PLATFORM wxOS_UNKNOWN | |
354 | #define wxUnix wxOS_UNIX | |
355 | #define wxWin95 wxOS_WINDOWS_9X | |
356 | #define wxWIN95 wxOS_WINDOWS_9X | |
357 | #define wxWINDOWS_NT wxOS_WINDOWS_NT | |
358 | #define wxMSW wxOS_WINDOWS | |
359 | #define wxWinCE wxOS_WINDOWS_CE | |
360 | #define wxWIN32S wxOS_WINDOWS_9X | |
361 | ||
8bb6b2c0 | 362 | #define wxOS2 wxPORT_OS2 |
8bb6b2c0 VZ |
363 | #define wxCocoa wxPORT_MAC |
364 | #define wxMac wxPORT_MAC | |
365 | #define wxMotif wxPORT_MOTIF | |
366 | #define wxGTK wxPORT_GTK | |
367 | #endif // WXWIN_COMPATIBILITY_2_6 | |
368 | ||
369 | #endif // _WX_PLATINFO_H_ |