platinfo.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. #ifndef _WX_PLATINFO_H_
  11. #define _WX_PLATINFO_H_
  12. #include "wx/string.h"
  13. // ----------------------------------------------------------------------------
  14. // wxPlatformInfo enums & structs
  15. // ----------------------------------------------------------------------------
  16. // VERY IMPORTANT: when changing these enum values, also change the relative
  17. // string tables in src/common/platinfo.cpp
  18. // families & sub-families of operating systems
  19. enum wxOperatingSystemId
  20. {
  21. wxOS_UNKNOWN = 0, // returned on error
  22. wxOS_MAC_OS = 1 << 0, // Apple Mac OS 8/9/X with Mac paths
  23. wxOS_MAC_OSX_DARWIN = 1 << 1, // Apple Mac OS X with Unix paths
  24. wxOS_MAC = wxOS_MAC_OS|wxOS_MAC_OSX_DARWIN,
  25. wxOS_WINDOWS_9X = 1 << 2, // Windows 9x family (95/98/ME)
  26. wxOS_WINDOWS_NT = 1 << 3, // Windows NT family (NT/2000/XP)
  27. wxOS_WINDOWS_MICRO = 1 << 4, // MicroWindows
  28. wxOS_WINDOWS_CE = 1 << 5, // Windows CE (Window Mobile)
  29. wxOS_WINDOWS = wxOS_WINDOWS_9X |
  30. wxOS_WINDOWS_NT |
  31. wxOS_WINDOWS_MICRO |
  32. wxOS_WINDOWS_CE,
  33. wxOS_UNIX_LINUX = 1 << 6, // Linux
  34. wxOS_UNIX_FREEBSD = 1 << 7, // FreeBSD
  35. wxOS_UNIX_OPENBSD = 1 << 8, // OpenBSD
  36. wxOS_UNIX_NETBSD = 1 << 9, // NetBSD
  37. wxOS_UNIX_SOLARIS = 1 << 10, // SunOS
  38. wxOS_UNIX_AIX = 1 << 11, // AIX
  39. wxOS_UNIX_HPUX = 1 << 12, // HP/UX
  40. wxOS_UNIX = wxOS_UNIX_LINUX |
  41. wxOS_UNIX_FREEBSD |
  42. wxOS_UNIX_OPENBSD |
  43. wxOS_UNIX_NETBSD |
  44. wxOS_UNIX_SOLARIS |
  45. wxOS_UNIX_AIX |
  46. wxOS_UNIX_HPUX,
  47. // 1<<13 and 1<<14 available for other Unix flavours
  48. wxOS_DOS = 1 << 15, // Microsoft DOS
  49. wxOS_OS2 = 1 << 16 // OS/2
  50. };
  51. // list of wxWidgets ports - some of them can be used with more than
  52. // a single toolkit.
  53. enum wxPortId
  54. {
  55. wxPORT_UNKNOWN = 0, // returned on error
  56. wxPORT_BASE = 1 << 0, // wxBase, no native toolkit used
  57. wxPORT_MSW = 1 << 1, // wxMSW, native toolkit is Windows API
  58. wxPORT_MOTIF = 1 << 2, // wxMotif, using [Open]Motif or Lesstif
  59. wxPORT_GTK = 1 << 3, // wxGTK, using GTK+ 1.x, 2.x, GPE or Maemo
  60. wxPORT_DFB = 1 << 4, // wxDFB, using wxUniversal
  61. wxPORT_X11 = 1 << 5, // wxX11, using wxUniversal
  62. wxPORT_PM = 1 << 6, // wxOS2, using OS/2 Presentation Manager
  63. wxPORT_OS2 = wxPORT_PM, // wxOS2, using OS/2 Presentation Manager
  64. wxPORT_MAC = 1 << 7, // wxOSX (former wxMac), using Cocoa, Carbon or iPhone API
  65. wxPORT_OSX = wxPORT_MAC, // wxOSX, using Cocoa, Carbon or iPhone API
  66. wxPORT_COCOA = 1 << 8, // wxCocoa, using Cocoa NextStep/Mac API
  67. wxPORT_WINCE = 1 << 9 // wxWinCE, toolkit is WinCE SDK API
  68. };
  69. // architecture of the operating system
  70. // (regardless of the build environment of wxWidgets library - see
  71. // wxIsPlatform64bit documentation for more info)
  72. enum wxArchitecture
  73. {
  74. wxARCH_INVALID = -1, // returned on error
  75. wxARCH_32, // 32 bit
  76. wxARCH_64,
  77. wxARCH_MAX
  78. };
  79. // endian-ness of the machine
  80. enum wxEndianness
  81. {
  82. wxENDIAN_INVALID = -1, // returned on error
  83. wxENDIAN_BIG, // 4321
  84. wxENDIAN_LITTLE, // 1234
  85. wxENDIAN_PDP, // 3412
  86. wxENDIAN_MAX
  87. };
  88. // informations about a linux distro returned by the lsb_release utility
  89. struct wxLinuxDistributionInfo
  90. {
  91. wxString Id;
  92. wxString Release;
  93. wxString CodeName;
  94. wxString Description;
  95. bool operator==(const wxLinuxDistributionInfo& ldi) const
  96. {
  97. return Id == ldi.Id &&
  98. Release == ldi.Release &&
  99. CodeName == ldi.CodeName &&
  100. Description == ldi.Description;
  101. }
  102. bool operator!=(const wxLinuxDistributionInfo& ldi) const
  103. { return !(*this == ldi); }
  104. };
  105. // ----------------------------------------------------------------------------
  106. // wxPlatformInfo
  107. // ----------------------------------------------------------------------------
  108. // Information about the toolkit that the app is running under and some basic
  109. // platform and architecture info
  110. class WXDLLIMPEXP_BASE wxPlatformInfo
  111. {
  112. public:
  113. wxPlatformInfo();
  114. wxPlatformInfo(wxPortId pid,
  115. int tkMajor = -1, int tkMinor = -1,
  116. wxOperatingSystemId id = wxOS_UNKNOWN,
  117. int osMajor = -1, int osMinor = -1,
  118. wxArchitecture arch = wxARCH_INVALID,
  119. wxEndianness endian = wxENDIAN_INVALID,
  120. bool usingUniversal = false);
  121. // default copy ctor, assignment operator and dtor are ok
  122. bool operator==(const wxPlatformInfo &t) const;
  123. bool operator!=(const wxPlatformInfo &t) const
  124. { return !(*this == t); }
  125. // Gets a wxPlatformInfo already initialized with the values for
  126. // the currently running platform.
  127. static const wxPlatformInfo& Get();
  128. // string -> enum conversions
  129. // ---------------------------------
  130. static wxOperatingSystemId GetOperatingSystemId(const wxString &name);
  131. static wxPortId GetPortId(const wxString &portname);
  132. static wxArchitecture GetArch(const wxString &arch);
  133. static wxEndianness GetEndianness(const wxString &end);
  134. // enum -> string conversions
  135. // ---------------------------------
  136. static wxString GetOperatingSystemFamilyName(wxOperatingSystemId os);
  137. static wxString GetOperatingSystemIdName(wxOperatingSystemId os);
  138. static wxString GetPortIdName(wxPortId port, bool usingUniversal);
  139. static wxString GetPortIdShortName(wxPortId port, bool usingUniversal);
  140. static wxString GetArchName(wxArchitecture arch);
  141. static wxString GetEndiannessName(wxEndianness end);
  142. // getters
  143. // -----------------
  144. int GetOSMajorVersion() const
  145. { return m_osVersionMajor; }
  146. int GetOSMinorVersion() const
  147. { return m_osVersionMinor; }
  148. // return true if the OS version >= major.minor
  149. bool CheckOSVersion(int major, int minor) const
  150. {
  151. return DoCheckVersion(GetOSMajorVersion(),
  152. GetOSMinorVersion(),
  153. major,
  154. minor);
  155. }
  156. int GetToolkitMajorVersion() const
  157. { return m_tkVersionMajor; }
  158. int GetToolkitMinorVersion() const
  159. { return m_tkVersionMinor; }
  160. bool CheckToolkitVersion(int major, int minor) const
  161. {
  162. return DoCheckVersion(GetToolkitMajorVersion(),
  163. GetToolkitMinorVersion(),
  164. major,
  165. minor);
  166. }
  167. bool IsUsingUniversalWidgets() const
  168. { return m_usingUniversal; }
  169. wxOperatingSystemId GetOperatingSystemId() const
  170. { return m_os; }
  171. wxLinuxDistributionInfo GetLinuxDistributionInfo() const
  172. { return m_ldi; }
  173. wxPortId GetPortId() const
  174. { return m_port; }
  175. wxArchitecture GetArchitecture() const
  176. { return m_arch; }
  177. wxEndianness GetEndianness() const
  178. { return m_endian; }
  179. // string getters
  180. // -----------------
  181. wxString GetOperatingSystemFamilyName() const
  182. { return GetOperatingSystemFamilyName(m_os); }
  183. wxString GetOperatingSystemIdName() const
  184. { return GetOperatingSystemIdName(m_os); }
  185. wxString GetPortIdName() const
  186. { return GetPortIdName(m_port, m_usingUniversal); }
  187. wxString GetPortIdShortName() const
  188. { return GetPortIdShortName(m_port, m_usingUniversal); }
  189. wxString GetArchName() const
  190. { return GetArchName(m_arch); }
  191. wxString GetEndiannessName() const
  192. { return GetEndiannessName(m_endian); }
  193. wxString GetOperatingSystemDescription() const
  194. { return m_osDesc; }
  195. wxString GetDesktopEnvironment() const
  196. { return m_desktopEnv; }
  197. static wxString GetOperatingSystemDirectory();
  198. // doesn't make sense to store inside wxPlatformInfo the OS directory,
  199. // thus this function is static; note that this function simply calls
  200. // wxGetOSDirectory() and is here just to make it easier for the user to
  201. // find it that feature (global functions can be difficult to find in the docs)
  202. // setters
  203. // -----------------
  204. void SetOSVersion(int major, int minor)
  205. { m_osVersionMajor=major; m_osVersionMinor=minor; }
  206. void SetToolkitVersion(int major, int minor)
  207. { m_tkVersionMajor=major; m_tkVersionMinor=minor; }
  208. void SetOperatingSystemId(wxOperatingSystemId n)
  209. { m_os = n; }
  210. void SetOperatingSystemDescription(const wxString& desc)
  211. { m_osDesc = desc; }
  212. void SetPortId(wxPortId n)
  213. { m_port = n; }
  214. void SetArchitecture(wxArchitecture n)
  215. { m_arch = n; }
  216. void SetEndianness(wxEndianness n)
  217. { m_endian = n; }
  218. void SetDesktopEnvironment(const wxString& de)
  219. { m_desktopEnv = de; }
  220. void SetLinuxDistributionInfo(const wxLinuxDistributionInfo& di)
  221. { m_ldi = di; }
  222. // miscellaneous
  223. // -----------------
  224. bool IsOk() const
  225. {
  226. return m_osVersionMajor != -1 && m_osVersionMinor != -1 &&
  227. m_os != wxOS_UNKNOWN &&
  228. !m_osDesc.IsEmpty() &&
  229. m_tkVersionMajor != -1 && m_tkVersionMinor != -1 &&
  230. m_port != wxPORT_UNKNOWN &&
  231. m_arch != wxARCH_INVALID &&
  232. m_endian != wxENDIAN_INVALID;
  233. // do not check linux-specific info; it's ok to have them empty
  234. }
  235. protected:
  236. static bool DoCheckVersion(int majorCur, int minorCur, int major, int minor)
  237. {
  238. return majorCur > major || (majorCur == major && minorCur >= minor);
  239. }
  240. void InitForCurrentPlatform();
  241. // OS stuff
  242. // -----------------
  243. // Version of the OS; valid if m_os != wxOS_UNKNOWN
  244. // (-1 means not initialized yet).
  245. int m_osVersionMajor,
  246. m_osVersionMinor;
  247. // Operating system ID.
  248. wxOperatingSystemId m_os;
  249. // Operating system description.
  250. wxString m_osDesc;
  251. // linux-specific
  252. // -----------------
  253. wxString m_desktopEnv;
  254. wxLinuxDistributionInfo m_ldi;
  255. // toolkit
  256. // -----------------
  257. // Version of the underlying toolkit
  258. // (-1 means not initialized yet; zero means no toolkit).
  259. int m_tkVersionMajor, m_tkVersionMinor;
  260. // name of the wxWidgets port
  261. wxPortId m_port;
  262. // is using wxUniversal widgets?
  263. bool m_usingUniversal;
  264. // others
  265. // -----------------
  266. // architecture of the OS/machine
  267. wxArchitecture m_arch;
  268. // endianness of the machine
  269. wxEndianness m_endian;
  270. };
  271. #if WXWIN_COMPATIBILITY_2_6
  272. #define wxUNKNOWN_PLATFORM wxOS_UNKNOWN
  273. #define wxUnix wxOS_UNIX
  274. #define wxWin95 wxOS_WINDOWS_9X
  275. #define wxWIN95 wxOS_WINDOWS_9X
  276. #define wxWINDOWS_NT wxOS_WINDOWS_NT
  277. #define wxMSW wxOS_WINDOWS
  278. #define wxWinCE wxOS_WINDOWS_CE
  279. #define wxWIN32S wxOS_WINDOWS_9X
  280. #define wxOS2 wxPORT_OS2
  281. #define wxCocoa wxPORT_MAC
  282. #define wxMac wxPORT_MAC
  283. #define wxMotif wxPORT_MOTIF
  284. #define wxGTK wxPORT_GTK
  285. #endif // WXWIN_COMPATIBILITY_2_6
  286. #endif // _WX_PLATINFO_H_