1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of the wxPlatformInfo class
4 // Author: Francesco Montorsi
6 // Created: 07.07.2006 (based on wxToolkitInfo)
8 // Copyright: (c) 2006 Francesco Montorsi
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PLATINFO_H_
13 #define _WX_PLATINFO_H_
15 #include "wx/string.h"
17 // ----------------------------------------------------------------------------
18 // wxPlatformInfo enums & structs
19 // ----------------------------------------------------------------------------
21 // VERY IMPORTANT: when changing these enum values, also change the relative
22 // string tables in src/common/platinfo.cpp
25 // families & sub-families of operating systems
26 enum wxOperatingSystemId
28 wxOS_UNKNOWN
= 0, // returned on error
30 wxOS_MAC_OS
= 1 << 0, // Apple Mac OS 8/9/X with Mac paths
31 wxOS_MAC_OSX_DARWIN
= 1 << 1, // Apple Mac OS X with Unix paths
32 wxOS_MAC
= wxOS_MAC_OS
|wxOS_MAC_OSX_DARWIN
,
34 wxOS_WINDOWS_9X
= 1 << 2, // Windows 9x family (95/98/ME)
35 wxOS_WINDOWS_NT
= 1 << 3, // Windows NT family (NT/2000/XP)
36 wxOS_WINDOWS_MICRO
= 1 << 4, // MicroWindows
37 wxOS_WINDOWS_CE
= 1 << 5, // Windows CE (Window Mobile)
38 wxOS_WINDOWS
= wxOS_WINDOWS_9X
|
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 wxOS_UNIX
= wxOS_UNIX_LINUX
|
58 // 1<<13 and 1<<14 available for other Unix flavours
60 wxOS_DOS
= 1 << 15, // Microsoft DOS
61 wxOS_OS2
= 1 << 16, // OS/2
63 wxOS_PALM_OS
= 1 << 17, // Pure Palm OS
64 wxOS_PALM_LINUX
= 1 << 18, // Palm over linux
65 wxOS_PALM
= wxOS_PALM_OS
| wxOS_PALM_LINUX
68 // list of wxWidgets ports - some of them can be used with more than
72 wxPORT_UNKNOWN
= 0, // returned on error
74 wxPORT_BASE
= 1 << 0, // wxBase, no native toolkit used
76 wxPORT_MSW
= 1 << 1, // wxMSW, native toolkit is Windows API
77 wxPORT_MOTIF
= 1 << 2, // wxMotif, using [Open]Motif or Lesstif
78 wxPORT_GTK
= 1 << 3, // wxGTK, using GTK+ 1.x, 2.x, GPE or Maemo
79 wxPORT_MGL
= 1 << 4, // wxMGL, using wxUniversal
80 wxPORT_X11
= 1 << 5, // wxX11, using wxUniversal
81 wxPORT_PM
= 1 << 6, // wxOS2, using OS/2 Presentation Manager
82 wxPORT_OS2
= wxPORT_PM
, // wxOS2, using OS/2 Presentation Manager
83 wxPORT_MAC
= 1 << 7, // wxOSX (former wxMac), using Cocoa, Carbon or iPhone API
84 wxPORT_OSX
= wxPORT_MAC
, // wxOSX, using Cocoa, Carbon or iPhone API
85 wxPORT_COCOA
= 1 << 8, // wxCocoa, using Cocoa NextStep/Mac API
86 wxPORT_WINCE
= 1 << 9, // wxWinCE, toolkit is WinCE SDK API
87 wxPORT_PALMOS
= 1 << 10, // wxPalmOS, toolkit is PalmOS API
88 wxPORT_DFB
= 1 << 11 // wxDFB, using wxUniversal
91 // architecture of the operating system
92 // (regardless of the build environment of wxWidgets library - see
93 // wxIsPlatform64bit documentation for more info)
96 wxARCH_INVALID
= -1, // returned on error
105 // endian-ness of the machine
108 wxENDIAN_INVALID
= -1, // returned on error
110 wxENDIAN_BIG
, // 4321
111 wxENDIAN_LITTLE
, // 1234
112 wxENDIAN_PDP
, // 3412
117 // informations about a linux distro returned by the lsb_release utility
118 struct wxLinuxDistributionInfo
123 wxString Description
;
125 bool operator==(const wxLinuxDistributionInfo
& ldi
) const
127 return Id
== ldi
.Id
&&
128 Release
== ldi
.Release
&&
129 CodeName
== ldi
.CodeName
&&
130 Description
== ldi
.Description
;
133 bool operator!=(const wxLinuxDistributionInfo
& ldi
) const
134 { return !(*this == ldi
); }
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 // Information about the toolkit that the app is running under and some basic
143 // platform and architecture info
144 class WXDLLIMPEXP_BASE wxPlatformInfo
148 wxPlatformInfo(wxPortId pid
,
149 int tkMajor
= -1, int tkMinor
= -1,
150 wxOperatingSystemId id
= wxOS_UNKNOWN
,
151 int osMajor
= -1, int osMinor
= -1,
152 wxArchitecture arch
= wxARCH_INVALID
,
153 wxEndianness endian
= wxENDIAN_INVALID
,
154 bool usingUniversal
= false);
156 // default copy ctor, assignment operator and dtor are ok
158 bool operator==(const wxPlatformInfo
&t
) const;
160 bool operator!=(const wxPlatformInfo
&t
) const
161 { return !(*this == t
); }
163 // Gets a wxPlatformInfo already initialized with the values for
164 // the currently running platform.
165 static const wxPlatformInfo
& Get();
169 // string -> enum conversions
170 // ---------------------------------
172 static wxOperatingSystemId
GetOperatingSystemId(const wxString
&name
);
173 static wxPortId
GetPortId(const wxString
&portname
);
175 static wxArchitecture
GetArch(const wxString
&arch
);
176 static wxEndianness
GetEndianness(const wxString
&end
);
178 // enum -> string conversions
179 // ---------------------------------
181 static wxString
GetOperatingSystemFamilyName(wxOperatingSystemId os
);
182 static wxString
GetOperatingSystemIdName(wxOperatingSystemId os
);
183 static wxString
GetPortIdName(wxPortId port
, bool usingUniversal
);
184 static wxString
GetPortIdShortName(wxPortId port
, bool usingUniversal
);
186 static wxString
GetArchName(wxArchitecture arch
);
187 static wxString
GetEndiannessName(wxEndianness end
);
193 int GetOSMajorVersion() const
194 { return m_osVersionMajor
; }
195 int GetOSMinorVersion() const
196 { return m_osVersionMinor
; }
198 // return true if the OS version >= major.minor
199 bool CheckOSVersion(int major
, int minor
) const
201 return DoCheckVersion(GetOSMajorVersion(),
207 int GetToolkitMajorVersion() const
208 { return m_tkVersionMajor
; }
209 int GetToolkitMinorVersion() const
210 { return m_tkVersionMinor
; }
212 bool CheckToolkitVersion(int major
, int minor
) const
214 return DoCheckVersion(GetToolkitMajorVersion(),
215 GetToolkitMinorVersion(),
220 bool IsUsingUniversalWidgets() const
221 { return m_usingUniversal
; }
223 wxOperatingSystemId
GetOperatingSystemId() const
225 wxLinuxDistributionInfo
GetLinuxDistributionInfo() const
227 wxPortId
GetPortId() const
229 wxArchitecture
GetArchitecture() const
231 wxEndianness
GetEndianness() const
238 wxString
GetOperatingSystemFamilyName() const
239 { return GetOperatingSystemFamilyName(m_os
); }
240 wxString
GetOperatingSystemIdName() const
241 { return GetOperatingSystemIdName(m_os
); }
242 wxString
GetPortIdName() const
243 { return GetPortIdName(m_port
, m_usingUniversal
); }
244 wxString
GetPortIdShortName() const
245 { return GetPortIdShortName(m_port
, m_usingUniversal
); }
246 wxString
GetArchName() const
247 { return GetArchName(m_arch
); }
248 wxString
GetEndiannessName() const
249 { return GetEndiannessName(m_endian
); }
250 wxString
GetOperatingSystemDescription() const
252 wxString
GetDesktopEnvironment() const
253 { return m_desktopEnv
; }
255 static wxString
GetOperatingSystemDirectory();
256 // doesn't make sense to store inside wxPlatformInfo the OS directory,
257 // thus this function is static; note that this function simply calls
258 // wxGetOSDirectory() and is here just to make it easier for the user to
259 // find it that feature (global functions can be difficult to find in the docs)
264 void SetOSVersion(int major
, int minor
)
265 { m_osVersionMajor
=major
; m_osVersionMinor
=minor
; }
266 void SetToolkitVersion(int major
, int minor
)
267 { m_tkVersionMajor
=major
; m_tkVersionMinor
=minor
; }
269 void SetOperatingSystemId(wxOperatingSystemId n
)
271 void SetOperatingSystemDescription(const wxString
& desc
)
273 void SetPortId(wxPortId n
)
275 void SetArchitecture(wxArchitecture n
)
277 void SetEndianness(wxEndianness n
)
280 void SetDesktopEnvironment(const wxString
& de
)
281 { m_desktopEnv
= de
; }
282 void SetLinuxDistributionInfo(const wxLinuxDistributionInfo
& di
)
291 return m_osVersionMajor
!= -1 && m_osVersionMinor
!= -1 &&
292 m_os
!= wxOS_UNKNOWN
&&
293 !m_osDesc
.IsEmpty() &&
294 m_tkVersionMajor
!= -1 && m_tkVersionMinor
!= -1 &&
295 m_port
!= wxPORT_UNKNOWN
&&
296 m_arch
!= wxARCH_INVALID
&&
297 m_endian
!= wxENDIAN_INVALID
;
299 // do not check linux-specific info; it's ok to have them empty
304 static bool DoCheckVersion(int majorCur
, int minorCur
, int major
, int minor
)
306 return majorCur
> major
|| (majorCur
== major
&& minorCur
>= minor
);
309 void InitForCurrentPlatform();
315 // Version of the OS; valid if m_os != wxOS_UNKNOWN
316 // (-1 means not initialized yet).
317 int m_osVersionMajor
,
320 // Operating system ID.
321 wxOperatingSystemId m_os
;
323 // Operating system description.
330 wxString m_desktopEnv
;
331 wxLinuxDistributionInfo m_ldi
;
337 // Version of the underlying toolkit
338 // (-1 means not initialized yet; zero means no toolkit).
339 int m_tkVersionMajor
, m_tkVersionMinor
;
341 // name of the wxWidgets port
344 // is using wxUniversal widgets?
345 bool m_usingUniversal
;
351 // architecture of the OS/machine
352 wxArchitecture m_arch
;
354 // endianness of the machine
355 wxEndianness m_endian
;
359 #if WXWIN_COMPATIBILITY_2_6
360 #define wxUNKNOWN_PLATFORM wxOS_UNKNOWN
361 #define wxUnix wxOS_UNIX
362 #define wxWin95 wxOS_WINDOWS_9X
363 #define wxWIN95 wxOS_WINDOWS_9X
364 #define wxWINDOWS_NT wxOS_WINDOWS_NT
365 #define wxMSW wxOS_WINDOWS
366 #define wxWinCE wxOS_WINDOWS_CE
367 #define wxWIN32S wxOS_WINDOWS_9X
369 #define wxPalmOS wxPORT_PALMOS
370 #define wxOS2 wxPORT_OS2
371 #define wxMGL wxPORT_MGL
372 #define wxCocoa wxPORT_MAC
373 #define wxMac wxPORT_MAC
374 #define wxMotif wxPORT_MOTIF
375 #define wxGTK wxPORT_GTK
376 #endif // WXWIN_COMPATIBILITY_2_6
378 #endif // _WX_PLATINFO_H_