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)
7 // Copyright:   (c) 2006 Francesco Montorsi
8 // Licence:     wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_PLATINFO_H_
12 #define _WX_PLATINFO_H_
13 
14 #include "wx/string.h"
15 
16 // ----------------------------------------------------------------------------
17 // wxPlatformInfo enums & structs
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,     // obsolete
34     wxOS_WINDOWS_NT     = 1 << 3,     // obsolete
35     wxOS_WINDOWS_MICRO  = 1 << 4,     // obsolete
36     wxOS_WINDOWS_CE     = 1 << 5,     // obsolete
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,      // obsolete
60     wxOS_OS2            = 1 << 16       // obsolete
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, 3.x
74     wxPORT_DFB      = 1 << 4,       // wxDFB, using wxUniversal
75     wxPORT_X11      = 1 << 5,       // wxX11, using wxUniversal
76     wxPORT_PM       = 1 << 6,       // obsolete
77     wxPORT_OS2      = wxPORT_PM,    // obsolete
78     wxPORT_MAC      = 1 << 7,       // wxOSX (former wxMac), using Cocoa or iPhone API
79     wxPORT_OSX      = wxPORT_MAC,   // wxOSX, using Cocoa or iPhone API
80     wxPORT_COCOA    = 1 << 8,       // wxCocoa, using Cocoa NextStep/Mac API
81     wxPORT_WINCE    = 1 << 9,       // obsolete
82     wxPORT_QT       = 1 << 10       // wxQT, using Qt 5+
83 };
84 
85 // architecture bitness of the operating system
86 // (regardless of the build environment of wxWidgets library - see
87 // wxIsPlatform64bit documentation for more info)
88 
89 enum wxBitness
90 {
91     wxBITNESS_INVALID = -1,     // returned on error
92 
93     wxBITNESS_32,
94     wxBITNESS_64,
95 
96     wxBITNESS_MAX
97 };
98 
99 typedef wxBitness wxArchitecture;
100 
101 const wxArchitecture
102     wxARCH_INVALID = wxBITNESS_INVALID,
103     wxARCH_32 = wxBITNESS_32,
104     wxARCH_64 = wxBITNESS_64,
105     wxARCH_MAX = wxBITNESS_MAX;
106 
107 
108 // endian-ness of the machine
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 // information about a linux distro returned by the lsb_release utility
121 struct wxLinuxDistributionInfo
122 {
123     wxString Id;
124     wxString Release;
125     wxString CodeName;
126     wxString Description;
127 
128     bool operator==(const wxLinuxDistributionInfo& ldi) const
129     {
130         return Id == ldi.Id &&
131                Release == ldi.Release &&
132                CodeName == ldi.CodeName &&
133                Description == ldi.Description;
134     }
135 
136     bool operator!=(const wxLinuxDistributionInfo& ldi) const
137     { return !(*this == ldi); }
138 };
139 
140 // Platform ID is a very broad platform categorization used in external files
141 // (e.g. XRC), so the values here must remain stable and cannot be changed.
142 class wxPlatformId
143 {
144 public:
145     // Returns the preferred current platform name, use MatchesCurrent() to
146     // check if the name is one of the possibly several names corresponding to
147     // the current platform.
GetCurrent()148     static wxString GetCurrent()
149     {
150 #ifdef __WINDOWS__
151         return wxASCII_STR("msw");
152 #elif defined(__APPLE__)
153         return wxASCII_STR("mac");
154 #elif defined(__UNIX__)
155         return wxASCII_STR("unix");
156 #else
157         return wxString();
158 #endif
159     }
160 
161     // Returns true if the given string matches the current platform.
MatchesCurrent(const wxString & s)162     static bool MatchesCurrent(const wxString& s)
163     {
164         // Under MSW we also support "win" platform name for compatibility with
165         // the existing XRC files using it.
166 #ifdef __WINDOWS__
167         if (s == wxASCII_STR("win"))
168             return true;
169 #endif // __WINDOWS__
170 
171         return s == GetCurrent();
172     }
173 };
174 
175 // ----------------------------------------------------------------------------
176 // wxPlatformInfo
177 // ----------------------------------------------------------------------------
178 
179 // Information about the toolkit that the app is running under and some basic
180 // platform and architecture bitness info
181 class WXDLLIMPEXP_BASE wxPlatformInfo
182 {
183 public:
184     wxPlatformInfo();
185     wxPlatformInfo(wxPortId pid,
186                    int tkMajor = -1, int tkMinor = -1,
187                    wxOperatingSystemId id = wxOS_UNKNOWN,
188                    int osMajor = -1, int osMinor = -1,
189                    wxBitness bitness = wxBITNESS_INVALID,
190                    wxEndianness endian = wxENDIAN_INVALID,
191                    bool usingUniversal = false);
192 
193     // default copy ctor, assignment operator and dtor are ok
194 
195     bool operator==(const wxPlatformInfo &t) const;
196 
197     bool operator!=(const wxPlatformInfo &t) const
198         { return !(*this == t); }
199 
200     // Gets a wxPlatformInfo already initialized with the values for
201     // the currently running platform.
202     static const wxPlatformInfo& Get();
203 
204 
205 
206     // string -> enum conversions
207     // ---------------------------------
208 
209     static wxOperatingSystemId GetOperatingSystemId(const wxString &name);
210     static wxPortId GetPortId(const wxString &portname);
211 
212     static wxBitness GetBitness(const wxString &bitness);
213     wxDEPRECATED_MSG("Use GetBitness() instead")
214     static wxArchitecture GetArch(const wxString &arch);
215     static wxEndianness GetEndianness(const wxString &end);
216 
217     // enum -> string conversions
218     // ---------------------------------
219 
220     static wxString GetOperatingSystemFamilyName(wxOperatingSystemId os);
221     static wxString GetOperatingSystemIdName(wxOperatingSystemId os);
222     static wxString GetPortIdName(wxPortId port, bool usingUniversal);
223     static wxString GetPortIdShortName(wxPortId port, bool usingUniversal);
224 
225     static wxString GetBitnessName(wxBitness bitness);
226     wxDEPRECATED_MSG("Use GetBitnessName() instead")
227     static wxString GetArchName(wxArchitecture arch);
228     static wxString GetEndiannessName(wxEndianness end);
229 
230 
231     // getters
232     // -----------------
233 
GetOSMajorVersion()234     int GetOSMajorVersion() const
235         { return m_osVersionMajor; }
GetOSMinorVersion()236     int GetOSMinorVersion() const
237         { return m_osVersionMinor; }
GetOSMicroVersion()238     int GetOSMicroVersion() const
239         { return m_osVersionMicro; }
240 
241     // return true if the OS version >= major.minor
242     bool CheckOSVersion(int major, int minor, int micro = 0) const;
243 
GetToolkitMajorVersion()244     int GetToolkitMajorVersion() const
245         { return m_tkVersionMajor; }
GetToolkitMinorVersion()246     int GetToolkitMinorVersion() const
247         { return m_tkVersionMinor; }
GetToolkitMicroVersion()248     int GetToolkitMicroVersion() const
249         { return m_tkVersionMicro; }
250 
251     bool CheckToolkitVersion(int major, int minor, int micro = 0) const
252     {
253         return DoCheckVersion(GetToolkitMajorVersion(),
254                               GetToolkitMinorVersion(),
255                               GetToolkitMicroVersion(),
256                               major,
257                               minor,
258                               micro);
259     }
260 
IsUsingUniversalWidgets()261     bool IsUsingUniversalWidgets() const
262         { return m_usingUniversal; }
263 
GetOperatingSystemId()264     wxOperatingSystemId GetOperatingSystemId() const
265         { return m_os; }
GetLinuxDistributionInfo()266     wxLinuxDistributionInfo GetLinuxDistributionInfo() const
267         { return m_ldi; }
GetPortId()268     wxPortId GetPortId() const
269         { return m_port; }
GetBitness()270     wxBitness GetBitness() const
271         { return m_bitness; }
272     wxDEPRECATED_MSG("Use GetBitness() instead")
GetArchitecture()273     wxArchitecture GetArchitecture() const
274         { return GetBitness(); }
GetEndianness()275     wxEndianness GetEndianness() const
276         { return m_endian; }
277 
278 
279     // string getters
280     // -----------------
281 
GetOperatingSystemFamilyName()282     wxString GetOperatingSystemFamilyName() const
283         { return GetOperatingSystemFamilyName(m_os); }
GetOperatingSystemIdName()284     wxString GetOperatingSystemIdName() const
285         { return GetOperatingSystemIdName(m_os); }
GetPortIdName()286     wxString GetPortIdName() const
287         { return GetPortIdName(m_port, m_usingUniversal); }
GetPortIdShortName()288     wxString GetPortIdShortName() const
289         { return GetPortIdShortName(m_port, m_usingUniversal); }
GetBitnessName()290     wxString GetBitnessName() const
291         { return GetBitnessName(m_bitness); }
292     wxDEPRECATED_MSG("Use GetBitnessName() instead")
GetArchName()293     wxString GetArchName() const
294         { return GetBitnessName(); }
GetEndiannessName()295     wxString GetEndiannessName() const
296         { return GetEndiannessName(m_endian); }
GetCpuArchitectureName()297     wxString GetCpuArchitectureName() const
298         { return m_cpuArch; }
GetOperatingSystemDescription()299     wxString GetOperatingSystemDescription() const
300         { return m_osDesc; }
GetDesktopEnvironment()301     wxString GetDesktopEnvironment() const
302         { return m_desktopEnv; }
303 
304     static wxString GetOperatingSystemDirectory();
305         // doesn't make sense to store inside wxPlatformInfo the OS directory,
306         // thus this function is static; note that this function simply calls
307         // wxGetOSDirectory() and is here just to make it easier for the user to
308         // find it that feature (global functions can be difficult to find in the docs)
309 
310     // setters
311     // -----------------
312 
313     void SetOSVersion(int major, int minor, int micro = 0)
314     {
315         m_osVersionMajor = major;
316         m_osVersionMinor = minor;
317         m_osVersionMicro = micro;
318     }
319 
320     void SetToolkitVersion(int major, int minor, int micro = 0)
321     {
322         m_tkVersionMajor = major;
323         m_tkVersionMinor = minor;
324         m_tkVersionMicro = micro;
325     }
326 
SetOperatingSystemId(wxOperatingSystemId n)327     void SetOperatingSystemId(wxOperatingSystemId n)
328         { m_os = n; }
SetOperatingSystemDescription(const wxString & desc)329     void SetOperatingSystemDescription(const wxString& desc)
330         { m_osDesc = desc; }
SetPortId(wxPortId n)331     void SetPortId(wxPortId n)
332         { m_port = n; }
SetBitness(wxBitness n)333     void SetBitness(wxBitness n)
334         { m_bitness = n; }
335     wxDEPRECATED_MSG("Use SetBitness() instead")
SetArchitecture(wxBitness n)336     void SetArchitecture(wxBitness n)
337         { SetBitness(n); }
SetEndianness(wxEndianness n)338     void SetEndianness(wxEndianness n)
339         { m_endian = n; }
SetCpuArchitectureName(const wxString & cpuArch)340     void SetCpuArchitectureName(const wxString& cpuArch)
341         { m_cpuArch = cpuArch; }
342 
SetDesktopEnvironment(const wxString & de)343     void SetDesktopEnvironment(const wxString& de)
344         { m_desktopEnv = de; }
SetLinuxDistributionInfo(const wxLinuxDistributionInfo & di)345     void SetLinuxDistributionInfo(const wxLinuxDistributionInfo& di)
346         { m_ldi = di; }
347 
348 
349     // miscellaneous
350     // -----------------
351 
IsOk()352     bool IsOk() const
353     {
354         return m_osVersionMajor != -1 && m_osVersionMinor != -1 &&
355                m_osVersionMicro != -1 &&
356                m_os != wxOS_UNKNOWN &&
357                !m_osDesc.IsEmpty() &&
358                m_tkVersionMajor != -1 && m_tkVersionMinor != -1 &&
359                m_tkVersionMicro != -1 &&
360                m_port != wxPORT_UNKNOWN &&
361                m_bitness != wxBITNESS_INVALID &&
362                m_endian != wxENDIAN_INVALID;
363 
364                // do not check linux-specific info; it's ok to have them empty
365     }
366 
367 
368 protected:
DoCheckVersion(int majorCur,int minorCur,int microCur,int major,int minor,int micro)369     static bool DoCheckVersion(int majorCur, int minorCur, int microCur,
370                                int major, int minor, int micro)
371     {
372         return majorCur > major
373             || (majorCur == major && minorCur > minor)
374             || (majorCur == major && minorCur == minor && microCur >= micro);
375     }
376 
377     bool m_initializedForCurrentPlatform;
378 
379     void InitForCurrentPlatform();
380 
381 
382     // OS stuff
383     // -----------------
384 
385     // Version of the OS; valid if m_os != wxOS_UNKNOWN
386     // (-1 means not initialized yet).
387     int m_osVersionMajor,
388         m_osVersionMinor,
389         m_osVersionMicro;
390 
391     // Operating system ID.
392     wxOperatingSystemId m_os;
393 
394     // Operating system description.
395     wxString m_osDesc;
396 
397 
398     // linux-specific
399     // -----------------
400 
401     wxString m_desktopEnv;
402     wxLinuxDistributionInfo m_ldi;
403 
404 
405     // toolkit
406     // -----------------
407 
408     // Version of the underlying toolkit
409     // (-1 means not initialized yet; zero means no toolkit).
410     int m_tkVersionMajor, m_tkVersionMinor, m_tkVersionMicro;
411 
412     // name of the wxWidgets port
413     wxPortId m_port;
414 
415     // is using wxUniversal widgets?
416     bool m_usingUniversal;
417 
418 
419     // others
420     // -----------------
421 
422     // architecture bitness of the OS/machine
423     wxBitness m_bitness;
424 
425     // endianness of the machine
426     wxEndianness m_endian;
427 
428     // CPU architecture family name, possibly empty if unknown
429     wxString m_cpuArch;
430 };
431 
432 
433 
434 #endif // _WX_PLATINFO_H_
435