1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of the wxPlatformInfo class
4 // Author: Francesco Montorsi
6 // Created: 07.07.2006 (based on wxToolkitInfo)
7 // Copyright: (c) 2006 Francesco Montorsi
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PLATINFO_H_
12 #define _WX_PLATINFO_H_
14 #include "wx/string.h"
16 // ----------------------------------------------------------------------------
17 // wxPlatformInfo enums & structs
18 // ----------------------------------------------------------------------------
20 // VERY IMPORTANT: when changing these enum values, also change the relative
21 // string tables in src/common/platinfo.cpp
24 // families & sub-families of operating systems
25 enum wxOperatingSystemId
27 wxOS_UNKNOWN
= 0, // returned on error
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
,
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
|
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
|
57 // 1<<13 and 1<<14 available for other Unix flavours
59 wxOS_DOS
= 1 << 15, // Microsoft DOS
60 wxOS_OS2
= 1 << 16 // OS/2
63 // list of wxWidgets ports - some of them can be used with more than
67 wxPORT_UNKNOWN
= 0, // returned on error
69 wxPORT_BASE
= 1 << 0, // wxBase, no native toolkit used
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
74 wxPORT_DFB
= 1 << 4, // wxDFB, using wxUniversal
75 wxPORT_X11
= 1 << 5, // wxX11, using wxUniversal
76 wxPORT_PM
= 1 << 6, // wxOS2, using OS/2 Presentation Manager
77 wxPORT_OS2
= wxPORT_PM
, // wxOS2, using OS/2 Presentation Manager
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
80 wxPORT_COCOA
= 1 << 8, // wxCocoa, using Cocoa NextStep/Mac API
81 wxPORT_WINCE
= 1 << 9 // wxWinCE, toolkit is WinCE SDK API
84 // architecture of the operating system
85 // (regardless of the build environment of wxWidgets library - see
86 // wxIsPlatform64bit documentation for more info)
89 wxARCH_INVALID
= -1, // returned on error
98 // endian-ness of the machine
101 wxENDIAN_INVALID
= -1, // returned on error
103 wxENDIAN_BIG
, // 4321
104 wxENDIAN_LITTLE
, // 1234
105 wxENDIAN_PDP
, // 3412
110 // informations about a linux distro returned by the lsb_release utility
111 struct wxLinuxDistributionInfo
116 wxString Description
;
118 bool operator==(const wxLinuxDistributionInfo
& ldi
) const
120 return Id
== ldi
.Id
&&
121 Release
== ldi
.Release
&&
122 CodeName
== ldi
.CodeName
&&
123 Description
== ldi
.Description
;
126 bool operator!=(const wxLinuxDistributionInfo
& ldi
) const
127 { return !(*this == ldi
); }
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 // Information about the toolkit that the app is running under and some basic
136 // platform and architecture info
137 class WXDLLIMPEXP_BASE 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
,
146 wxEndianness endian
= wxENDIAN_INVALID
,
147 bool usingUniversal
= false);
149 // default copy ctor, assignment operator and dtor are ok
151 bool operator==(const wxPlatformInfo
&t
) const;
153 bool operator!=(const wxPlatformInfo
&t
) const
154 { return !(*this == t
); }
156 // Gets a wxPlatformInfo already initialized with the values for
157 // the currently running platform.
158 static const wxPlatformInfo
& Get();
162 // string -> enum conversions
163 // ---------------------------------
165 static wxOperatingSystemId
GetOperatingSystemId(const wxString
&name
);
166 static wxPortId
GetPortId(const wxString
&portname
);
168 static wxArchitecture
GetArch(const wxString
&arch
);
169 static wxEndianness
GetEndianness(const wxString
&end
);
171 // enum -> string conversions
172 // ---------------------------------
174 static wxString
GetOperatingSystemFamilyName(wxOperatingSystemId os
);
175 static wxString
GetOperatingSystemIdName(wxOperatingSystemId os
);
176 static wxString
GetPortIdName(wxPortId port
, bool usingUniversal
);
177 static wxString
GetPortIdShortName(wxPortId port
, bool usingUniversal
);
179 static wxString
GetArchName(wxArchitecture arch
);
180 static wxString
GetEndiannessName(wxEndianness end
);
186 int GetOSMajorVersion() const
187 { return m_osVersionMajor
; }
188 int GetOSMinorVersion() const
189 { return m_osVersionMinor
; }
191 // return true if the OS version >= major.minor
192 bool CheckOSVersion(int major
, int minor
) const
194 return DoCheckVersion(GetOSMajorVersion(),
200 int GetToolkitMajorVersion() const
201 { return m_tkVersionMajor
; }
202 int GetToolkitMinorVersion() const
203 { return m_tkVersionMinor
; }
205 bool CheckToolkitVersion(int major
, int minor
) const
207 return DoCheckVersion(GetToolkitMajorVersion(),
208 GetToolkitMinorVersion(),
213 bool IsUsingUniversalWidgets() const
214 { return m_usingUniversal
; }
216 wxOperatingSystemId
GetOperatingSystemId() const
218 wxLinuxDistributionInfo
GetLinuxDistributionInfo() const
220 wxPortId
GetPortId() const
222 wxArchitecture
GetArchitecture() const
224 wxEndianness
GetEndianness() const
231 wxString
GetOperatingSystemFamilyName() const
232 { return GetOperatingSystemFamilyName(m_os
); }
233 wxString
GetOperatingSystemIdName() const
234 { return GetOperatingSystemIdName(m_os
); }
235 wxString
GetPortIdName() const
236 { return GetPortIdName(m_port
, m_usingUniversal
); }
237 wxString
GetPortIdShortName() const
238 { return GetPortIdShortName(m_port
, m_usingUniversal
); }
239 wxString
GetArchName() const
240 { return GetArchName(m_arch
); }
241 wxString
GetEndiannessName() const
242 { return GetEndiannessName(m_endian
); }
243 wxString
GetOperatingSystemDescription() const
245 wxString
GetDesktopEnvironment() const
246 { return m_desktopEnv
; }
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
251 // wxGetOSDirectory() and is here just to make it easier for the user to
252 // find it that feature (global functions can be difficult to find in the docs)
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
; }
262 void SetOperatingSystemId(wxOperatingSystemId n
)
264 void SetOperatingSystemDescription(const wxString
& desc
)
266 void SetPortId(wxPortId n
)
268 void SetArchitecture(wxArchitecture n
)
270 void SetEndianness(wxEndianness n
)
273 void SetDesktopEnvironment(const wxString
& de
)
274 { m_desktopEnv
= de
; }
275 void SetLinuxDistributionInfo(const wxLinuxDistributionInfo
& di
)
284 return m_osVersionMajor
!= -1 && m_osVersionMinor
!= -1 &&
285 m_os
!= wxOS_UNKNOWN
&&
286 !m_osDesc
.IsEmpty() &&
287 m_tkVersionMajor
!= -1 && m_tkVersionMinor
!= -1 &&
288 m_port
!= wxPORT_UNKNOWN
&&
289 m_arch
!= wxARCH_INVALID
&&
290 m_endian
!= wxENDIAN_INVALID
;
292 // do not check linux-specific info; it's ok to have them empty
297 static bool DoCheckVersion(int majorCur
, int minorCur
, int major
, int minor
)
299 return majorCur
> major
|| (majorCur
== major
&& minorCur
>= minor
);
302 void InitForCurrentPlatform();
308 // Version of the OS; valid if m_os != wxOS_UNKNOWN
309 // (-1 means not initialized yet).
310 int m_osVersionMajor
,
313 // Operating system ID.
314 wxOperatingSystemId m_os
;
316 // Operating system description.
323 wxString m_desktopEnv
;
324 wxLinuxDistributionInfo m_ldi
;
330 // Version of the underlying toolkit
331 // (-1 means not initialized yet; zero means no toolkit).
332 int m_tkVersionMajor
, m_tkVersionMinor
;
334 // name of the wxWidgets port
337 // is using wxUniversal widgets?
338 bool m_usingUniversal
;
344 // architecture of the OS/machine
345 wxArchitecture m_arch
;
347 // endianness of the machine
348 wxEndianness m_endian
;
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
362 #define wxOS2 wxPORT_OS2
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
369 #endif // _WX_PLATINFO_H_