]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/platinfo.h
e07be913e8574419bf2b33031f9ac2bb7078ef8a
[wxWidgets.git] / interface / wx / platinfo.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: platinfo.h
3 // Purpose: interface of wxPlatformInfo
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9
10 /**
11 The following are the operating systems which are recognized by wxWidgets and
12 whose version can be detected at run-time.
13
14 The values of the constants are chosen so that they can be combined as flags;
15 this allows to check for operating system families like e.g. @c wxOS_MAC and @c wxOS_UNIX.
16
17 Note that you can obtain more detailed informations about the current OS
18 version in use by checking the major and minor version numbers returned
19 by ::wxGetOsVersion() or by wxPlatformInfo::GetOSMajorVersion(),
20 wxPlatformInfo::GetOSMinorVersion().
21 */
22 enum wxOperatingSystemId
23 {
24 wxOS_UNKNOWN = 0, //!< returned on error
25
26 wxOS_MAC_OS = 1 << 0, //!< Apple Mac OS 8/9/X with Mac paths
27 wxOS_MAC_OSX_DARWIN = 1 << 1, //!< Apple Mac OS X with Unix paths
28
29 //! A combination of all @c wxOS_MAC_* values previously listed.
30 wxOS_MAC = wxOS_MAC_OS|wxOS_MAC_OSX_DARWIN,
31
32 wxOS_WINDOWS_9X = 1 << 2, //!< Windows 9x family (95/98/ME)
33 wxOS_WINDOWS_NT = 1 << 3, //!< Windows NT family (NT/2000/XP/Vista/7)
34 wxOS_WINDOWS_MICRO = 1 << 4, //!< MicroWindows
35 wxOS_WINDOWS_CE = 1 << 5, //!< Windows CE (Window Mobile)
36
37 //! A combination of all @c wxOS_WINDOWS_* values previously listed.
38 wxOS_WINDOWS = wxOS_WINDOWS_9X |
39 wxOS_WINDOWS_NT |
40 wxOS_WINDOWS_MICRO |
41 wxOS_WINDOWS_CE,
42
43 wxOS_UNIX_LINUX = 1 << 6, //!< Linux
44 wxOS_UNIX_FREEBSD = 1 << 7, //!< FreeBSD
45 wxOS_UNIX_OPENBSD = 1 << 8, //!< OpenBSD
46 wxOS_UNIX_NETBSD = 1 << 9, //!< NetBSD
47 wxOS_UNIX_SOLARIS = 1 << 10, //!< SunOS
48 wxOS_UNIX_AIX = 1 << 11, //!< AIX
49 wxOS_UNIX_HPUX = 1 << 12, //!< HP/UX
50
51 //! A combination of all @c wxOS_UNIX_* values previously listed.
52 wxOS_UNIX = wxOS_UNIX_LINUX |
53 wxOS_UNIX_FREEBSD |
54 wxOS_UNIX_OPENBSD |
55 wxOS_UNIX_NETBSD |
56 wxOS_UNIX_SOLARIS |
57 wxOS_UNIX_AIX |
58 wxOS_UNIX_HPUX,
59
60 wxOS_DOS = 1 << 15, //!< Microsoft DOS
61 wxOS_OS2 = 1 << 16 //!< OS/2
62 };
63
64 /**
65 The list of wxWidgets ports.
66
67 Some of them can be used with more than a single (native) toolkit;
68 e.g. wxWinCE port sources can be used with smartphones, pocket PCs
69 and handheld devices SDKs.
70 */
71 enum wxPortId
72 {
73 wxPORT_UNKNOWN = 0, //!< returned on error
74
75 wxPORT_BASE = 1 << 0, //!< wxBase, no native toolkit used
76
77 wxPORT_MSW = 1 << 1, //!< wxMSW, native toolkit is Windows API
78 wxPORT_MOTIF = 1 << 2, //!< wxMotif, using [Open]Motif or Lesstif
79 wxPORT_GTK = 1 << 3, //!< wxGTK, using GTK+ 1.x, 2.x, GPE or Maemo
80 wxPORT_MGL = 1 << 4, //!< wxMGL, using wxUniversal
81 wxPORT_X11 = 1 << 5, //!< wxX11, using wxUniversal
82 wxPORT_OS2 = 1 << 6, //!< wxOS2, using OS/2 Presentation Manager
83 wxPORT_MAC = 1 << 7, //!< wxMac, using Carbon or Classic Mac API
84 wxPORT_COCOA = 1 << 8, //!< wxCocoa, using Cocoa NextStep/Mac API
85 wxPORT_WINCE = 1 << 9, //!< wxWinCE, toolkit is WinCE SDK API
86 wxPORT_DFB = 1 << 10 //!< wxDFB, using wxUniversal
87 };
88
89
90 /**
91 The architecture of the operating system
92 (regardless of the build environment of wxWidgets library - see ::wxIsPlatform64Bit()
93 documentation for more info).
94 */
95 enum wxArchitecture
96 {
97 wxARCH_INVALID = -1, //!< returned on error
98
99 wxARCH_32, //!< 32 bit
100 wxARCH_64, //!< 64 bit
101
102 wxARCH_MAX
103 };
104
105
106 /**
107 The endian-ness of the machine.
108 */
109 enum wxEndianness
110 {
111 wxENDIAN_INVALID = -1, //!< returned on error
112
113 wxENDIAN_BIG, //!< 4321
114 wxENDIAN_LITTLE, //!< 1234
115 wxENDIAN_PDP, //!< 3412
116
117 wxENDIAN_MAX
118 };
119
120 /**
121 A structure containing informations about a Linux distribution as returned
122 by the @c lsb_release utility.
123
124 See wxGetLinuxDistributionInfo() or wxPlatformInfo::GetLinuxDistributionInfo()
125 for more info.
126 */
127 struct wxLinuxDistributionInfo
128 {
129 wxString Id; //!< The id of the distribution; e.g. "Ubuntu"
130 wxString Release; //!< The version of the distribution; e.g. "9.04"
131 wxString CodeName; //!< The code name of the distribution; e.g. "jaunty"
132 wxString Description; //!< The description of the distribution; e.g. "Ubuntu 9.04"
133
134 bool operator==(const wxLinuxDistributionInfo& ldi) const;
135 bool operator!=(const wxLinuxDistributionInfo& ldi) const;
136 };
137
138
139 /**
140 @class wxPlatformInfo
141
142 This class holds informations about the operating system, the toolkit and the
143 basic architecture of the machine where the application is currently running.
144
145 This class does not only have @e getters for the informations above, it also has
146 @e setters. This allows you to e.g. save the current platform informations in a
147 data file (maybe in string form) so that when you later load it, you can easily
148 retrieve (see the static getters for string->enum conversion functions) and store
149 inside a wxPlatformInfo instance (using its setters) the signature of the system
150 which generated it.
151
152 In general however you only need to use the static Get() function and then
153 access the various informations for the current platform:
154 @code
155 wxLogMessage("This application is running under %s.",
156 wxPlatformInfo::Get().GetOperatingSystemIdName());
157 @endcode
158
159 @library{wxbase}
160 @category{cfg}
161
162 @see ::wxGetOsVersion(), wxIsPlatformLittleEndian(), wxIsPlatform64Bit(),
163 wxAppTraits, @ref group_funcmacro_networkuseros
164 */
165 class wxPlatformInfo
166 {
167 public:
168
169 /**
170 Initializes the instance with the values corresponding to the currently
171 running platform.
172
173 This is a fast operation because it only requires to copy the values
174 internally cached for the currently running platform.
175
176 @see Get()
177 */
178 wxPlatformInfo();
179
180 /**
181 Initializes the object using given values.
182 */
183 wxPlatformInfo(wxPortId pid,
184 int tkMajor = -1,
185 int tkMinor = -1,
186 wxOperatingSystemId id = wxOS_UNKNOWN,
187 int osMajor = -1,
188 int osMinor = -1,
189 wxArchitecture arch = wxARCH_INVALID,
190 wxEndianness endian = wxENDIAN_INVALID);
191
192
193 /**
194 Returns @true if the OS version is at least @c major.minor.
195
196 @see GetOSMajorVersion(), GetOSMinorVersion(),
197 CheckToolkitVersion()
198 */
199 bool CheckOSVersion(int major, int minor) const;
200
201 /**
202 Returns @true if the toolkit version is at least @c major.minor.
203
204 @see GetToolkitMajorVersion(),
205 GetToolkitMinorVersion(), CheckOSVersion()
206 */
207 bool CheckToolkitVersion(int major, int minor) const;
208
209
210 /**
211 Returns @true if this instance is fully initialized with valid values.
212 */
213 bool IsOk() const;
214
215 /**
216 Returns @true if this wxPlatformInfo describes wxUniversal build.
217 */
218 bool IsUsingUniversalWidgets() const;
219
220 /**
221 Inequality operator. Tests all class' internal variables.
222 */
223 bool operator!=(const wxPlatformInfo& t) const;
224
225 /**
226 Equality operator. Tests all class' internal variables.
227 */
228 bool operator==(const wxPlatformInfo& t) const;
229
230 /**
231 Returns the global wxPlatformInfo object, initialized with the values
232 for the currently running platform.
233 */
234 static const wxPlatformInfo& Get();
235
236 /**
237 @name Static enum getters
238
239 These getters allow for easy string-to-enumeration-value conversion.
240 */
241 //@{
242
243 /**
244 Converts the given string to a wxArchitecture enum value or to
245 @c wxARCH_INVALID if the given string is not a valid architecture string
246 (i.e. does not contain nor @c 32 nor @c 64 strings).
247 */
248 static wxArchitecture GetArch(const wxString& arch);
249
250 /**
251 Converts the given string to a wxEndianness enum value or to
252 @c wxENDIAN_INVALID if the given string is not a valid endianness
253 string (i.e. does not contain nor little nor big strings).
254 */
255 static wxEndianness GetEndianness(const wxString& end);
256
257 /**
258 Converts the given string to a wxOperatingSystemId enum value or to @c
259 wxOS_UNKNOWN if the given string is not a valid operating system name.
260 */
261 static wxOperatingSystemId GetOperatingSystemId(const wxString& name);
262
263 /**
264 Converts the given string to a wxWidgets port ID value or to @c wxPORT_UNKNOWN
265 if the given string does not match any of the wxWidgets canonical name ports
266 ("wxGTK", "wxMSW", etc) nor any of the short wxWidgets name ports ("gtk", "msw", etc).
267 */
268 static wxPortId GetPortId(const wxString& portname);
269
270 //@}
271
272
273 /**
274 @name Static string-form getters
275
276 These getters allow for easy enumeration-value-to-string conversion.
277 */
278 //@{
279
280 /**
281 Returns the name for the given wxArchitecture enumeration value.
282 */
283 static wxString GetArchName(wxArchitecture arch);
284
285 /**
286 Returns name for the given wxEndianness enumeration value.
287 */
288 static wxString GetEndiannessName(wxEndianness end);
289
290 /**
291 Returns the operating system family name for the given wxOperatingSystemId
292 enumeration value: @c Unix for @c wxOS_UNIX, @c Macintosh for @c wxOS_MAC,
293 @c Windows for @c wxOS_WINDOWS, @c DOS for @c wxOS_DOS, @c OS/2 for @c wxOS_OS2.
294 */
295 static wxString GetOperatingSystemFamilyName(wxOperatingSystemId os);
296
297 /**
298 Returns the name for the given operating system ID value.
299
300 This can be a long name (e.g. <tt>Microsoft Windows NT</tt>);
301 use GetOperatingSystemFamilyName() to retrieve a short, generic name.
302 */
303 static wxString GetOperatingSystemIdName(wxOperatingSystemId os);
304
305 /**
306 Returns the name of the given wxWidgets port ID value.
307 The @a usingUniversal argument specifies whether the port is in its native
308 or wxUniversal variant.
309
310 The returned string always starts with the "wx" prefix and is a mixed-case string.
311 */
312 static wxString GetPortIdName(wxPortId port, bool usingUniversal);
313
314 /**
315 Returns the short name of the given wxWidgets port ID value.
316 The @a usingUniversal argument specifies whether the port is in its native
317 or wxUniversal variant.
318
319 The returned string does not start with the "wx" prefix and is always lower case.
320 */
321 static wxString GetPortIdShortName(wxPortId port,
322 bool usingUniversal);
323
324 /**
325 Returns the operating system directory.
326
327 See wxGetOSDirectory() for more info.
328 */
329 static wxString GetOperatingSystemDirectory();
330
331 //@}
332
333
334 /**
335 @name Getters
336 */
337 //@{
338
339 /**
340 Returns the architecture ID of this wxPlatformInfo instance.
341 */
342 wxArchitecture GetArchitecture() const;
343
344 /**
345 Returns the endianness ID of this wxPlatformInfo instance.
346 */
347 wxEndianness GetEndianness() const;
348
349 /**
350 Returns the run-time major version of the OS associated with this
351 wxPlatformInfo instance.
352
353 @see ::wxGetOsVersion(), CheckOSVersion()
354 */
355 int GetOSMajorVersion() const;
356
357 /**
358 Returns the run-time minor version of the OS associated with this
359 wxPlatformInfo instance.
360
361 @see ::wxGetOsVersion(), CheckOSVersion()
362 */
363 int GetOSMinorVersion() const;
364
365 /**
366 Returns the operating system ID of this wxPlatformInfo instance.
367
368 See wxGetOsVersion() for more info.
369 */
370 wxOperatingSystemId GetOperatingSystemId() const;
371
372 /**
373 Returns the description of the operating system of this wxPlatformInfo instance.
374
375 See wxGetOSDescription() for more info.
376 */
377 wxString GetOperatingSystemDescription() const;
378
379 /**
380 Returns the wxWidgets port ID associated with this wxPlatformInfo instance.
381 */
382 wxPortId GetPortId() const;
383
384 /**
385 Returns the Linux distribution info associated with this wxPlatformInfo instance.
386
387 See wxGetLinuxDistributionInfo() for more info.
388 */
389 wxLinuxDistributionInfo GetLinuxDistributionInfo() const;
390
391 /**
392 Returns the desktop environment associated with this wxPlatformInfo instance.
393
394 See wxAppTraits::GetDesktopEnvironment() for more info.
395 */
396 wxString GetDesktopEnvironment() const;
397
398 /**
399 Returns the run-time major version of the toolkit associated with this
400 wxPlatformInfo instance.
401
402 Note that if GetPortId() returns @c wxPORT_BASE, then this value is zero
403 (unless externally modified with SetToolkitVersion()); that is, no native
404 toolkit is in use.
405 See wxAppTraits::GetToolkitVersion() for more info.
406
407 @see CheckToolkitVersion()
408 */
409 int GetToolkitMajorVersion() const;
410
411 /**
412 Returns the run-time minor version of the toolkit associated with this
413 wxPlatformInfo instance.
414
415 Note that if GetPortId() returns @c wxPORT_BASE, then this value is zero
416 (unless externally modified with SetToolkitVersion()); that is, no native
417 toolkit is in use.
418 See wxAppTraits::GetToolkitVersion() for more info.
419
420 @see CheckToolkitVersion()
421 */
422 int GetToolkitMinorVersion() const;
423
424 //@}
425
426
427 /**
428 @name String-form getters
429 */
430 //@{
431
432 /**
433 Returns the name for the architecture of this wxPlatformInfo instance.
434 */
435 wxString GetArchName() const;
436
437 /**
438 Returns the name for the endianness of this wxPlatformInfo instance.
439 */
440 wxString GetEndiannessName() const;
441
442 /**
443 Returns the operating system family name of the OS associated with this
444 wxPlatformInfo instance.
445 */
446 wxString GetOperatingSystemFamilyName() const;
447
448 /**
449 Returns the operating system name of the OS associated with this wxPlatformInfo
450 instance.
451 */
452 wxString GetOperatingSystemIdName() const;
453
454 /**
455 Returns the name of the wxWidgets port ID associated with this wxPlatformInfo
456 instance.
457 */
458 wxString GetPortIdName() const;
459
460 /**
461 Returns the short name of the wxWidgets port ID associated with this
462 wxPlatformInfo instance.
463 */
464 wxString GetPortIdShortName() const;
465
466 //@}
467
468
469
470 /**
471 @name Setters
472 */
473 //@{
474
475 /**
476 Sets the architecture enum value associated with this wxPlatformInfo instance.
477 */
478 void SetArchitecture(wxArchitecture n);
479
480 /**
481 Sets the endianness enum value associated with this wxPlatformInfo instance.
482 */
483 void SetEndianness(wxEndianness n);
484
485 /**
486 Sets the version of the operating system associated with this wxPlatformInfo
487 instance.
488 */
489 void SetOSVersion(int major, int minor);
490
491 /**
492 Sets the operating system associated with this wxPlatformInfo instance.
493 */
494 void SetOperatingSystemId(wxOperatingSystemId n);
495
496 /**
497 Sets the wxWidgets port ID associated with this wxPlatformInfo instance.
498 */
499 void SetPortId(wxPortId n);
500
501 /**
502 Sets the version of the toolkit associated with this wxPlatformInfo instance.
503 */
504 void SetToolkitVersion(int major, int minor);
505
506 /**
507 Sets the operating system description associated with this wxPlatformInfo instance.
508 */
509 void SetOperatingSystemDescription(const wxString& desc);
510
511 /**
512 Sets the desktop environment associated with this wxPlatformInfo instance.
513 */
514 void SetDesktopEnvironment(const wxString& de);
515
516 /**
517 Sets the linux distribution info associated with this wxPlatformInfo instance.
518 */
519 void SetLinuxDistributionInfo(const wxLinuxDistributionInfo& di);
520
521 //@}
522 };
523