platinfo.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: platinfo.h
  3. // Purpose: interface of wxPlatformInfo
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. The following are the operating systems which are recognized by wxWidgets and
  9. whose version can be detected at run-time.
  10. The values of the constants are chosen so that they can be combined as flags;
  11. this allows to check for operating system families like e.g. @c wxOS_MAC and @c wxOS_UNIX.
  12. Note that you can obtain more detailed information about the current OS
  13. version in use by checking the major and minor version numbers returned
  14. by ::wxGetOsVersion() or by wxPlatformInfo::GetOSMajorVersion(),
  15. wxPlatformInfo::GetOSMinorVersion().
  16. */
  17. enum wxOperatingSystemId
  18. {
  19. wxOS_UNKNOWN = 0, //!< returned on error
  20. wxOS_MAC_OS = 1 << 0, //!< Apple Mac OS 8/9/X with Mac paths
  21. wxOS_MAC_OSX_DARWIN = 1 << 1, //!< Apple Mac OS X with Unix paths
  22. //! A combination of all @c wxOS_MAC_* values previously listed.
  23. wxOS_MAC = wxOS_MAC_OS|wxOS_MAC_OSX_DARWIN,
  24. wxOS_WINDOWS_9X = 1 << 2, //!< Windows 9x family (95/98/ME)
  25. wxOS_WINDOWS_NT = 1 << 3, //!< Windows NT family (NT/2000/XP/Vista/7)
  26. wxOS_WINDOWS_MICRO = 1 << 4, //!< MicroWindows
  27. wxOS_WINDOWS_CE = 1 << 5, //!< Windows CE (Window Mobile)
  28. //! A combination of all @c wxOS_WINDOWS_* values previously listed.
  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. //! A combination of all @c wxOS_UNIX_* values previously listed.
  41. wxOS_UNIX = wxOS_UNIX_LINUX |
  42. wxOS_UNIX_FREEBSD |
  43. wxOS_UNIX_OPENBSD |
  44. wxOS_UNIX_NETBSD |
  45. wxOS_UNIX_SOLARIS |
  46. wxOS_UNIX_AIX |
  47. wxOS_UNIX_HPUX,
  48. wxOS_DOS = 1 << 15, //!< Microsoft DOS
  49. wxOS_OS2 = 1 << 16 //!< OS/2
  50. };
  51. /**
  52. The list of wxWidgets ports.
  53. Some of them can be used with more than a single (native) toolkit;
  54. e.g. wxWinCE port sources can be used with smartphones, pocket PCs
  55. and handheld devices SDKs.
  56. */
  57. enum wxPortId
  58. {
  59. wxPORT_UNKNOWN = 0, //!< returned on error
  60. wxPORT_BASE = 1 << 0, //!< wxBase, no native toolkit used
  61. wxPORT_MSW = 1 << 1, //!< wxMSW, native toolkit is Windows API
  62. wxPORT_MOTIF = 1 << 2, //!< wxMotif, using [Open]Motif or Lesstif
  63. wxPORT_GTK = 1 << 3, //!< wxGTK, using GTK+ 1.x, 2.x, GPE or Maemo
  64. wxPORT_DFB = 1 << 4, //!< wxDFB, using wxUniversal
  65. wxPORT_X11 = 1 << 5, //!< wxX11, using wxUniversal
  66. wxPORT_OS2 = 1 << 6, //!< wxOS2, using OS/2 Presentation Manager
  67. wxPORT_MAC = 1 << 7, //!< wxMac, using Carbon or Classic Mac API
  68. wxPORT_COCOA = 1 << 8, //!< wxCocoa, using Cocoa NextStep/Mac API
  69. wxPORT_WINCE = 1 << 9 //!< wxWinCE, toolkit is WinCE SDK API
  70. };
  71. /**
  72. The architecture of the operating system
  73. (regardless of the build environment of wxWidgets library - see ::wxIsPlatform64Bit()
  74. documentation for more info).
  75. */
  76. enum wxArchitecture
  77. {
  78. wxARCH_INVALID = -1, //!< returned on error
  79. wxARCH_32, //!< 32 bit
  80. wxARCH_64, //!< 64 bit
  81. wxARCH_MAX
  82. };
  83. /**
  84. The endian-ness of the machine.
  85. */
  86. enum wxEndianness
  87. {
  88. wxENDIAN_INVALID = -1, //!< returned on error
  89. wxENDIAN_BIG, //!< 4321
  90. wxENDIAN_LITTLE, //!< 1234
  91. wxENDIAN_PDP, //!< 3412
  92. wxENDIAN_MAX
  93. };
  94. /**
  95. A structure containing information about a Linux distribution as returned
  96. by the @c lsb_release utility.
  97. See wxGetLinuxDistributionInfo() or wxPlatformInfo::GetLinuxDistributionInfo()
  98. for more info.
  99. */
  100. struct wxLinuxDistributionInfo
  101. {
  102. wxString Id; //!< The id of the distribution; e.g. "Ubuntu"
  103. wxString Release; //!< The version of the distribution; e.g. "9.04"
  104. wxString CodeName; //!< The code name of the distribution; e.g. "jaunty"
  105. wxString Description; //!< The description of the distribution; e.g. "Ubuntu 9.04"
  106. bool operator==(const wxLinuxDistributionInfo& ldi) const;
  107. bool operator!=(const wxLinuxDistributionInfo& ldi) const;
  108. };
  109. /**
  110. @class wxPlatformInfo
  111. This class holds information about the operating system, the toolkit and the
  112. basic architecture of the machine where the application is currently running.
  113. This class does not only have @e getters for the information above, it also has
  114. @e setters. This allows you to e.g. save the current platform information in a
  115. data file (maybe in string form) so that when you later load it, you can easily
  116. retrieve (see the static getters for string->enum conversion functions) and store
  117. inside a wxPlatformInfo instance (using its setters) the signature of the system
  118. which generated it.
  119. In general however you only need to use the static Get() function and then
  120. access the various information for the current platform:
  121. @code
  122. wxLogMessage("This application is running under %s.",
  123. wxPlatformInfo::Get().GetOperatingSystemIdName());
  124. @endcode
  125. @library{wxbase}
  126. @category{cfg}
  127. @see ::wxGetOsVersion(), wxIsPlatformLittleEndian(), wxIsPlatform64Bit(),
  128. wxAppTraits, @ref group_funcmacro_networkuseros
  129. */
  130. class wxPlatformInfo
  131. {
  132. public:
  133. /**
  134. Initializes the instance with the values corresponding to the currently
  135. running platform.
  136. This is a fast operation because it only requires to copy the values
  137. internally cached for the currently running platform.
  138. @see Get()
  139. */
  140. wxPlatformInfo();
  141. /**
  142. Initializes the object using given values.
  143. */
  144. wxPlatformInfo(wxPortId pid,
  145. int tkMajor = -1,
  146. int tkMinor = -1,
  147. wxOperatingSystemId id = wxOS_UNKNOWN,
  148. int osMajor = -1,
  149. int osMinor = -1,
  150. wxArchitecture arch = wxARCH_INVALID,
  151. wxEndianness endian = wxENDIAN_INVALID);
  152. /**
  153. Returns @true if the OS version is at least @c major.minor.
  154. @see GetOSMajorVersion(), GetOSMinorVersion(),
  155. CheckToolkitVersion()
  156. */
  157. bool CheckOSVersion(int major, int minor) const;
  158. /**
  159. Returns @true if the toolkit version is at least @c major.minor.
  160. @see GetToolkitMajorVersion(),
  161. GetToolkitMinorVersion(), CheckOSVersion()
  162. */
  163. bool CheckToolkitVersion(int major, int minor) const;
  164. /**
  165. Returns @true if this instance is fully initialized with valid values.
  166. */
  167. bool IsOk() const;
  168. /**
  169. Returns @true if this wxPlatformInfo describes wxUniversal build.
  170. */
  171. bool IsUsingUniversalWidgets() const;
  172. /**
  173. Inequality operator. Tests all class' internal variables.
  174. */
  175. bool operator!=(const wxPlatformInfo& t) const;
  176. /**
  177. Equality operator. Tests all class' internal variables.
  178. */
  179. bool operator==(const wxPlatformInfo& t) const;
  180. /**
  181. Returns the global wxPlatformInfo object, initialized with the values
  182. for the currently running platform.
  183. */
  184. static const wxPlatformInfo& Get();
  185. /**
  186. @name Static enum getters
  187. These getters allow for easy string-to-enumeration-value conversion.
  188. */
  189. //@{
  190. /**
  191. Converts the given string to a wxArchitecture enum value or to
  192. @c wxARCH_INVALID if the given string is not a valid architecture string
  193. (i.e. does not contain nor @c 32 nor @c 64 strings).
  194. */
  195. static wxArchitecture GetArch(const wxString& arch);
  196. /**
  197. Converts the given string to a wxEndianness enum value or to
  198. @c wxENDIAN_INVALID if the given string is not a valid endianness
  199. string (i.e. does not contain nor little nor big strings).
  200. */
  201. static wxEndianness GetEndianness(const wxString& end);
  202. /**
  203. Converts the given string to a wxOperatingSystemId enum value or to @c
  204. wxOS_UNKNOWN if the given string is not a valid operating system name.
  205. */
  206. static wxOperatingSystemId GetOperatingSystemId(const wxString& name);
  207. /**
  208. Converts the given string to a wxWidgets port ID value or to @c wxPORT_UNKNOWN
  209. if the given string does not match any of the wxWidgets canonical name ports
  210. ("wxGTK", "wxMSW", etc) nor any of the short wxWidgets name ports ("gtk", "msw", etc).
  211. */
  212. static wxPortId GetPortId(const wxString& portname);
  213. //@}
  214. /**
  215. @name Static string-form getters
  216. These getters allow for easy enumeration-value-to-string conversion.
  217. */
  218. //@{
  219. /**
  220. Returns the name for the given wxArchitecture enumeration value.
  221. */
  222. static wxString GetArchName(wxArchitecture arch);
  223. /**
  224. Returns name for the given wxEndianness enumeration value.
  225. */
  226. static wxString GetEndiannessName(wxEndianness end);
  227. /**
  228. Returns the operating system family name for the given wxOperatingSystemId
  229. enumeration value: @c Unix for @c wxOS_UNIX, @c Macintosh for @c wxOS_MAC,
  230. @c Windows for @c wxOS_WINDOWS, @c DOS for @c wxOS_DOS, @c OS/2 for @c wxOS_OS2.
  231. */
  232. static wxString GetOperatingSystemFamilyName(wxOperatingSystemId os);
  233. /**
  234. Returns the name for the given operating system ID value.
  235. This can be a long name (e.g. <tt>Microsoft Windows NT</tt>);
  236. use GetOperatingSystemFamilyName() to retrieve a short, generic name.
  237. */
  238. static wxString GetOperatingSystemIdName(wxOperatingSystemId os);
  239. /**
  240. Returns the name of the given wxWidgets port ID value.
  241. The @a usingUniversal argument specifies whether the port is in its native
  242. or wxUniversal variant.
  243. The returned string always starts with the "wx" prefix and is a mixed-case string.
  244. */
  245. static wxString GetPortIdName(wxPortId port, bool usingUniversal);
  246. /**
  247. Returns the short name of the given wxWidgets port ID value.
  248. The @a usingUniversal argument specifies whether the port is in its native
  249. or wxUniversal variant.
  250. The returned string does not start with the "wx" prefix and is always lower case.
  251. */
  252. static wxString GetPortIdShortName(wxPortId port,
  253. bool usingUniversal);
  254. /**
  255. Returns the operating system directory.
  256. See wxGetOSDirectory() for more info.
  257. */
  258. static wxString GetOperatingSystemDirectory();
  259. //@}
  260. /**
  261. @name Getters
  262. */
  263. //@{
  264. /**
  265. Returns the architecture ID of this wxPlatformInfo instance.
  266. */
  267. wxArchitecture GetArchitecture() const;
  268. /**
  269. Returns the endianness ID of this wxPlatformInfo instance.
  270. */
  271. wxEndianness GetEndianness() const;
  272. /**
  273. Returns the run-time major version of the OS associated with this
  274. wxPlatformInfo instance.
  275. @see ::wxGetOsVersion(), CheckOSVersion()
  276. */
  277. int GetOSMajorVersion() const;
  278. /**
  279. Returns the run-time minor version of the OS associated with this
  280. wxPlatformInfo instance.
  281. @see ::wxGetOsVersion(), CheckOSVersion()
  282. */
  283. int GetOSMinorVersion() const;
  284. /**
  285. Returns the operating system ID of this wxPlatformInfo instance.
  286. See wxGetOsVersion() for more info.
  287. */
  288. wxOperatingSystemId GetOperatingSystemId() const;
  289. /**
  290. Returns the description of the operating system of this wxPlatformInfo instance.
  291. See wxGetOSDescription() for more info.
  292. */
  293. wxString GetOperatingSystemDescription() const;
  294. /**
  295. Returns the wxWidgets port ID associated with this wxPlatformInfo instance.
  296. */
  297. wxPortId GetPortId() const;
  298. /**
  299. Returns the Linux distribution info associated with this wxPlatformInfo instance.
  300. See wxGetLinuxDistributionInfo() for more info.
  301. */
  302. wxLinuxDistributionInfo GetLinuxDistributionInfo() const;
  303. /**
  304. Returns the desktop environment associated with this wxPlatformInfo instance.
  305. See wxAppTraits::GetDesktopEnvironment() for more info.
  306. */
  307. wxString GetDesktopEnvironment() const;
  308. /**
  309. Returns the run-time major version of the toolkit associated with this
  310. wxPlatformInfo instance.
  311. Note that if GetPortId() returns @c wxPORT_BASE, then this value is zero
  312. (unless externally modified with SetToolkitVersion()); that is, no native
  313. toolkit is in use.
  314. See wxAppTraits::GetToolkitVersion() for more info.
  315. @see CheckToolkitVersion()
  316. */
  317. int GetToolkitMajorVersion() const;
  318. /**
  319. Returns the run-time minor version of the toolkit associated with this
  320. wxPlatformInfo instance.
  321. Note that if GetPortId() returns @c wxPORT_BASE, then this value is zero
  322. (unless externally modified with SetToolkitVersion()); that is, no native
  323. toolkit is in use.
  324. See wxAppTraits::GetToolkitVersion() for more info.
  325. @see CheckToolkitVersion()
  326. */
  327. int GetToolkitMinorVersion() const;
  328. //@}
  329. /**
  330. @name String-form getters
  331. */
  332. //@{
  333. /**
  334. Returns the name for the architecture of this wxPlatformInfo instance.
  335. */
  336. wxString GetArchName() const;
  337. /**
  338. Returns the name for the endianness of this wxPlatformInfo instance.
  339. */
  340. wxString GetEndiannessName() const;
  341. /**
  342. Returns the operating system family name of the OS associated with this
  343. wxPlatformInfo instance.
  344. */
  345. wxString GetOperatingSystemFamilyName() const;
  346. /**
  347. Returns the operating system name of the OS associated with this wxPlatformInfo
  348. instance.
  349. */
  350. wxString GetOperatingSystemIdName() const;
  351. /**
  352. Returns the name of the wxWidgets port ID associated with this wxPlatformInfo
  353. instance.
  354. */
  355. wxString GetPortIdName() const;
  356. /**
  357. Returns the short name of the wxWidgets port ID associated with this
  358. wxPlatformInfo instance.
  359. */
  360. wxString GetPortIdShortName() const;
  361. //@}
  362. /**
  363. @name Setters
  364. */
  365. //@{
  366. /**
  367. Sets the architecture enum value associated with this wxPlatformInfo instance.
  368. */
  369. void SetArchitecture(wxArchitecture n);
  370. /**
  371. Sets the endianness enum value associated with this wxPlatformInfo instance.
  372. */
  373. void SetEndianness(wxEndianness n);
  374. /**
  375. Sets the version of the operating system associated with this wxPlatformInfo
  376. instance.
  377. */
  378. void SetOSVersion(int major, int minor);
  379. /**
  380. Sets the operating system associated with this wxPlatformInfo instance.
  381. */
  382. void SetOperatingSystemId(wxOperatingSystemId n);
  383. /**
  384. Sets the wxWidgets port ID associated with this wxPlatformInfo instance.
  385. */
  386. void SetPortId(wxPortId n);
  387. /**
  388. Sets the version of the toolkit associated with this wxPlatformInfo instance.
  389. */
  390. void SetToolkitVersion(int major, int minor);
  391. /**
  392. Sets the operating system description associated with this wxPlatformInfo instance.
  393. */
  394. void SetOperatingSystemDescription(const wxString& desc);
  395. /**
  396. Sets the desktop environment associated with this wxPlatformInfo instance.
  397. */
  398. void SetDesktopEnvironment(const wxString& de);
  399. /**
  400. Sets the linux distribution info associated with this wxPlatformInfo instance.
  401. */
  402. void SetLinuxDistributionInfo(const wxLinuxDistributionInfo& di);
  403. //@}
  404. };