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
64 // list of wxWidgets ports - some of them can be used with more than
68 wxPORT_UNKNOWN
= 0, // returned on error
70 wxPORT_BASE
= 1 << 0, // wxBase, no native toolkit used
72 wxPORT_MSW
= 1 << 1, // wxMSW, native toolkit is Windows API
73 wxPORT_MOTIF
= 1 << 2, // wxMotif, using [Open]Motif or Lesstif
74 wxPORT_GTK
= 1 << 3, // wxGTK, using GTK+ 1.x, 2.x, GPE or Maemo
75 wxPORT_MGL
= 1 << 4, // wxMGL, using wxUniversal
76 wxPORT_X11
= 1 << 5, // wxX11, using wxUniversal
77 wxPORT_PM
= 1 << 6, // wxOS2, using OS/2 Presentation Manager
78 wxPORT_OS2
= wxPORT_PM
, // wxOS2, using OS/2 Presentation Manager
79 wxPORT_MAC
= 1 << 7, // wxOSX (former wxMac), using Cocoa, Carbon or iPhone API
80 wxPORT_OSX
= wxPORT_MAC
, // wxOSX, using Cocoa, Carbon or iPhone API
81 wxPORT_COCOA
= 1 << 8, // wxCocoa, using Cocoa NextStep/Mac API
82 wxPORT_WINCE
= 1 << 9, // wxWinCE, toolkit is WinCE SDK API
83 wxPORT_DFB
= 1 << 10 // wxDFB, using wxUniversal
86 // architecture of the operating system
87 // (regardless of the build environment of wxWidgets library - see
88 // wxIsPlatform64bit documentation for more info)
91 wxARCH_INVALID
= -1, // returned on error
100 // endian-ness of the machine
103 wxENDIAN_INVALID
= -1, // returned on error
105 wxENDIAN_BIG
, // 4321
106 wxENDIAN_LITTLE
, // 1234
107 wxENDIAN_PDP
, // 3412
112 // informations about a linux distro returned by the lsb_release utility
113 struct wxLinuxDistributionInfo
118 wxString Description
;
120 bool operator==(const wxLinuxDistributionInfo
& ldi
) const
122 return Id
== ldi
.Id
&&
123 Release
== ldi
.Release
&&
124 CodeName
== ldi
.CodeName
&&
125 Description
== ldi
.Description
;
128 bool operator!=(const wxLinuxDistributionInfo
& ldi
) const
129 { return !(*this == ldi
); }
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 // Information about the toolkit that the app is running under and some basic
138 // platform and architecture info
139 class WXDLLIMPEXP_BASE wxPlatformInfo
143 wxPlatformInfo(wxPortId pid
,
144 int tkMajor
= -1, int tkMinor
= -1,
145 wxOperatingSystemId id
= wxOS_UNKNOWN
,
146 int osMajor
= -1, int osMinor
= -1,
147 wxArchitecture arch
= wxARCH_INVALID
,
148 wxEndianness endian
= wxENDIAN_INVALID
,
149 bool usingUniversal
= false);
151 // default copy ctor, assignment operator and dtor are ok
153 bool operator==(const wxPlatformInfo
&t
) const;
155 bool operator!=(const wxPlatformInfo
&t
) const
156 { return !(*this == t
); }
158 // Gets a wxPlatformInfo already initialized with the values for
159 // the currently running platform.
160 static const wxPlatformInfo
& Get();
164 // string -> enum conversions
165 // ---------------------------------
167 static wxOperatingSystemId
GetOperatingSystemId(const wxString
&name
);
168 static wxPortId
GetPortId(const wxString
&portname
);
170 static wxArchitecture
GetArch(const wxString
&arch
);
171 static wxEndianness
GetEndianness(const wxString
&end
);
173 // enum -> string conversions
174 // ---------------------------------
176 static wxString
GetOperatingSystemFamilyName(wxOperatingSystemId os
);
177 static wxString
GetOperatingSystemIdName(wxOperatingSystemId os
);
178 static wxString
GetPortIdName(wxPortId port
, bool usingUniversal
);
179 static wxString
GetPortIdShortName(wxPortId port
, bool usingUniversal
);
181 static wxString
GetArchName(wxArchitecture arch
);
182 static wxString
GetEndiannessName(wxEndianness end
);
188 int GetOSMajorVersion() const
189 { return m_osVersionMajor
; }
190 int GetOSMinorVersion() const
191 { return m_osVersionMinor
; }
193 // return true if the OS version >= major.minor
194 bool CheckOSVersion(int major
, int minor
) const
196 return DoCheckVersion(GetOSMajorVersion(),
202 int GetToolkitMajorVersion() const
203 { return m_tkVersionMajor
; }
204 int GetToolkitMinorVersion() const
205 { return m_tkVersionMinor
; }
207 bool CheckToolkitVersion(int major
, int minor
) const
209 return DoCheckVersion(GetToolkitMajorVersion(),
210 GetToolkitMinorVersion(),
215 bool IsUsingUniversalWidgets() const
216 { return m_usingUniversal
; }
218 wxOperatingSystemId
GetOperatingSystemId() const
220 wxLinuxDistributionInfo
GetLinuxDistributionInfo() const
222 wxPortId
GetPortId() const
224 wxArchitecture
GetArchitecture() const
226 wxEndianness
GetEndianness() const
233 wxString
GetOperatingSystemFamilyName() const
234 { return GetOperatingSystemFamilyName(m_os
); }
235 wxString
GetOperatingSystemIdName() const
236 { return GetOperatingSystemIdName(m_os
); }
237 wxString
GetPortIdName() const
238 { return GetPortIdName(m_port
, m_usingUniversal
); }
239 wxString
GetPortIdShortName() const
240 { return GetPortIdShortName(m_port
, m_usingUniversal
); }
241 wxString
GetArchName() const
242 { return GetArchName(m_arch
); }
243 wxString
GetEndiannessName() const
244 { return GetEndiannessName(m_endian
); }
245 wxString
GetOperatingSystemDescription() const
247 wxString
GetDesktopEnvironment() const
248 { return m_desktopEnv
; }
250 static wxString
GetOperatingSystemDirectory();
251 // doesn't make sense to store inside wxPlatformInfo the OS directory,
252 // thus this function is static; note that this function simply calls
253 // wxGetOSDirectory() and is here just to make it easier for the user to
254 // find it that feature (global functions can be difficult to find in the docs)
259 void SetOSVersion(int major
, int minor
)
260 { m_osVersionMajor
=major
; m_osVersionMinor
=minor
; }
261 void SetToolkitVersion(int major
, int minor
)
262 { m_tkVersionMajor
=major
; m_tkVersionMinor
=minor
; }
264 void SetOperatingSystemId(wxOperatingSystemId n
)
266 void SetOperatingSystemDescription(const wxString
& desc
)
268 void SetPortId(wxPortId n
)
270 void SetArchitecture(wxArchitecture n
)
272 void SetEndianness(wxEndianness n
)
275 void SetDesktopEnvironment(const wxString
& de
)
276 { m_desktopEnv
= de
; }
277 void SetLinuxDistributionInfo(const wxLinuxDistributionInfo
& di
)
286 return m_osVersionMajor
!= -1 && m_osVersionMinor
!= -1 &&
287 m_os
!= wxOS_UNKNOWN
&&
288 !m_osDesc
.IsEmpty() &&
289 m_tkVersionMajor
!= -1 && m_tkVersionMinor
!= -1 &&
290 m_port
!= wxPORT_UNKNOWN
&&
291 m_arch
!= wxARCH_INVALID
&&
292 m_endian
!= wxENDIAN_INVALID
;
294 // do not check linux-specific info; it's ok to have them empty
299 static bool DoCheckVersion(int majorCur
, int minorCur
, int major
, int minor
)
301 return majorCur
> major
|| (majorCur
== major
&& minorCur
>= minor
);
304 void InitForCurrentPlatform();
310 // Version of the OS; valid if m_os != wxOS_UNKNOWN
311 // (-1 means not initialized yet).
312 int m_osVersionMajor
,
315 // Operating system ID.
316 wxOperatingSystemId m_os
;
318 // Operating system description.
325 wxString m_desktopEnv
;
326 wxLinuxDistributionInfo m_ldi
;
332 // Version of the underlying toolkit
333 // (-1 means not initialized yet; zero means no toolkit).
334 int m_tkVersionMajor
, m_tkVersionMinor
;
336 // name of the wxWidgets port
339 // is using wxUniversal widgets?
340 bool m_usingUniversal
;
346 // architecture of the OS/machine
347 wxArchitecture m_arch
;
349 // endianness of the machine
350 wxEndianness m_endian
;
354 #if WXWIN_COMPATIBILITY_2_6
355 #define wxUNKNOWN_PLATFORM wxOS_UNKNOWN
356 #define wxUnix wxOS_UNIX
357 #define wxWin95 wxOS_WINDOWS_9X
358 #define wxWIN95 wxOS_WINDOWS_9X
359 #define wxWINDOWS_NT wxOS_WINDOWS_NT
360 #define wxMSW wxOS_WINDOWS
361 #define wxWinCE wxOS_WINDOWS_CE
362 #define wxWIN32S wxOS_WINDOWS_9X
364 #define wxOS2 wxPORT_OS2
365 #define wxMGL wxPORT_MGL
366 #define wxCocoa wxPORT_MAC
367 #define wxMac wxPORT_MAC
368 #define wxMotif wxPORT_MOTIF
369 #define wxGTK wxPORT_GTK
370 #endif // WXWIN_COMPATIBILITY_2_6
372 #endif // _WX_PLATINFO_H_