Factor out platform detection from XRC code into wxPlatformId
This will allow reusing the same strings in other places. Also use this as opportunity to add "msw" as the (preferred) synonym for "win" for general consistency.
This commit is contained in:
parent
da45f88c53
commit
8293dcedef
@ -2674,14 +2674,15 @@ should be processed on. It is filtered out and ignored on any other platforms.
|
||||
|
||||
Possible elemental values are:
|
||||
@beginDefList
|
||||
@itemdef{ @c win, Windows }
|
||||
@itemdef{ @c mac, macOS (or Mac Classic in wxWidgets version supporting it) }
|
||||
@itemdef{ @c msw, Windows, preferred platform name }
|
||||
@itemdef{ @c win, Windows, alternative synonym }
|
||||
@itemdef{ @c mac, macOS or iOS }
|
||||
@itemdef{ @c unix, Any Unix platform @em except macOS }
|
||||
@endDefList
|
||||
|
||||
Examples:
|
||||
@code
|
||||
<label platform="win">Windows</label>
|
||||
<label platform="msw">Windows</label>
|
||||
<label platform="unix">Unix</label>
|
||||
<label platform="mac">macOS</label>
|
||||
<help platform="mac|unix">Not a Windows machine</help>
|
||||
|
@ -137,6 +137,40 @@ struct wxLinuxDistributionInfo
|
||||
{ return !(*this == ldi); }
|
||||
};
|
||||
|
||||
// Platform ID is a very broad platform categorization used in external files
|
||||
// (e.g. XRC), so the values here must remain stable and cannot be changed.
|
||||
class wxPlatformId
|
||||
{
|
||||
public:
|
||||
// Returns the preferred current platform name, use MatchesCurrent() to
|
||||
// check if the name is one of the possibly several names corresponding to
|
||||
// the current platform.
|
||||
static wxString GetCurrent()
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
return wxASCII_STR("msw");
|
||||
#elif defined(__APPLE__)
|
||||
return wxASCII_STR("mac");
|
||||
#elif defined(__UNIX__)
|
||||
return wxASCII_STR("unix");
|
||||
#else
|
||||
return wxString();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Returns true if the given string matches the current platform.
|
||||
static bool MatchesCurrent(const wxString& s)
|
||||
{
|
||||
// Under MSW we also support "win" platform name for compatibility with
|
||||
// the existing XRC files using it.
|
||||
#ifdef __WINDOWS__
|
||||
if (s == wxASCII_STR("win"))
|
||||
return true;
|
||||
#endif // __WINDOWS__
|
||||
|
||||
return s == GetCurrent();
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxPlatformInfo
|
||||
|
@ -138,6 +138,45 @@ struct wxLinuxDistributionInfo
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@class wxPlatformId
|
||||
|
||||
Defines a very broad platform categorization.
|
||||
|
||||
Usually you would use wxPlatformInfo to get all the platform details rather
|
||||
than this class which only distinguishes between MSW, Mac and Unix
|
||||
platforms.
|
||||
|
||||
This class is mostly useful if a short string describing the platform
|
||||
corresponds to the current platform, i.e. the platform under which the
|
||||
executable runs. The recognized strings are:
|
||||
|
||||
- "msw" (preferred) or "win" (for compatibility) for MSW.
|
||||
- "mac" for Apple systems, i.e. macOS and iOS.
|
||||
- "unix" for the (other) Unix-like systems.
|
||||
|
||||
@since 3.1.5
|
||||
*/
|
||||
class wxPlatformId
|
||||
{
|
||||
/**
|
||||
Returns the preferred current platform name.
|
||||
|
||||
Use MatchesCurrent() to check if the name is one of the possibly
|
||||
several names corresponding to the current platform.
|
||||
|
||||
Returns one of "msw", "mac" or "unix" or an empty string if the current
|
||||
platform is not recognized.
|
||||
*/
|
||||
static wxString GetCurrent();
|
||||
|
||||
/**
|
||||
Returns true if the given string matches the current platform.
|
||||
*/
|
||||
static bool MatchesCurrent(const wxString& s);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@class wxPlatformInfo
|
||||
|
||||
@ -590,4 +629,3 @@ public:
|
||||
|
||||
//@}
|
||||
};
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "wx/hashset.h"
|
||||
#include "wx/scopedptr.h"
|
||||
#include "wx/config.h"
|
||||
#include "wx/platinfo.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
@ -585,15 +586,7 @@ static void ProcessPlatformProperty(wxXmlNode *node)
|
||||
|
||||
while (tkn.HasMoreTokens())
|
||||
{
|
||||
s = tkn.GetNextToken();
|
||||
#ifdef __WINDOWS__
|
||||
if (s == wxT("win")) isok = true;
|
||||
#endif
|
||||
#if defined(__MAC__) || defined(__APPLE__)
|
||||
if (s == wxT("mac")) isok = true;
|
||||
#elif defined(__UNIX__)
|
||||
if (s == wxT("unix")) isok = true;
|
||||
#endif
|
||||
isok = wxPlatformId::MatchesCurrent(tkn.GetNextToken());
|
||||
|
||||
if (isok)
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user