Coverage Report

Created: 2026-11-12 06:13

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