utils.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/utils.h
  3. // Purpose: Miscellaneous utilities
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 29/01/98
  7. // Copyright: (c) 1998 Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UTILS_H_
  11. #define _WX_UTILS_H_
  12. // ----------------------------------------------------------------------------
  13. // headers
  14. // ----------------------------------------------------------------------------
  15. #include "wx/object.h"
  16. #include "wx/list.h"
  17. #include "wx/filefn.h"
  18. #include "wx/hashmap.h"
  19. #include "wx/versioninfo.h"
  20. #include "wx/meta/implicitconversion.h"
  21. #if wxUSE_GUI
  22. #include "wx/gdicmn.h"
  23. #include "wx/mousestate.h"
  24. #endif
  25. class WXDLLIMPEXP_FWD_BASE wxArrayString;
  26. class WXDLLIMPEXP_FWD_BASE wxArrayInt;
  27. // need this for wxGetDiskSpace() as we can't, unfortunately, forward declare
  28. // wxLongLong
  29. #include "wx/longlong.h"
  30. // needed for wxOperatingSystemId, wxLinuxDistributionInfo
  31. #include "wx/platinfo.h"
  32. #ifdef __WATCOMC__
  33. #include <direct.h>
  34. #elif defined(__X__)
  35. #include <dirent.h>
  36. #include <unistd.h>
  37. #endif
  38. #include <stdio.h>
  39. // ----------------------------------------------------------------------------
  40. // Forward declaration
  41. // ----------------------------------------------------------------------------
  42. class WXDLLIMPEXP_FWD_BASE wxProcess;
  43. class WXDLLIMPEXP_FWD_CORE wxFrame;
  44. class WXDLLIMPEXP_FWD_CORE wxWindow;
  45. class wxWindowList;
  46. class WXDLLIMPEXP_FWD_CORE wxEventLoop;
  47. // ----------------------------------------------------------------------------
  48. // Arithmetic functions
  49. // ----------------------------------------------------------------------------
  50. template<typename T1, typename T2>
  51. inline typename wxImplicitConversionType<T1,T2>::value
  52. wxMax(T1 a, T2 b)
  53. {
  54. typedef typename wxImplicitConversionType<T1,T2>::value ResultType;
  55. // Cast both operands to the same type before comparing them to avoid
  56. // warnings about signed/unsigned comparisons from some compilers:
  57. return static_cast<ResultType>(a) > static_cast<ResultType>(b) ? a : b;
  58. }
  59. template<typename T1, typename T2>
  60. inline typename wxImplicitConversionType<T1,T2>::value
  61. wxMin(T1 a, T2 b)
  62. {
  63. typedef typename wxImplicitConversionType<T1,T2>::value ResultType;
  64. return static_cast<ResultType>(a) < static_cast<ResultType>(b) ? a : b;
  65. }
  66. template<typename T1, typename T2, typename T3>
  67. inline typename wxImplicitConversionType3<T1,T2,T3>::value
  68. wxClip(T1 a, T2 b, T3 c)
  69. {
  70. typedef typename wxImplicitConversionType3<T1,T2,T3>::value ResultType;
  71. if ( static_cast<ResultType>(a) < static_cast<ResultType>(b) )
  72. return b;
  73. if ( static_cast<ResultType>(a) > static_cast<ResultType>(c) )
  74. return c;
  75. return a;
  76. }
  77. // ----------------------------------------------------------------------------
  78. // wxMemorySize
  79. // ----------------------------------------------------------------------------
  80. // wxGetFreeMemory can return huge amount of memory on 32-bit platforms as well
  81. // so to always use long long for its result type on all platforms which
  82. // support it
  83. #if wxUSE_LONGLONG
  84. typedef wxLongLong wxMemorySize;
  85. #else
  86. typedef long wxMemorySize;
  87. #endif
  88. // ----------------------------------------------------------------------------
  89. // String functions (deprecated, use wxString)
  90. // ----------------------------------------------------------------------------
  91. #if WXWIN_COMPATIBILITY_2_8
  92. // A shorter way of using strcmp
  93. wxDEPRECATED_INLINE(inline bool wxStringEq(const char *s1, const char *s2),
  94. return wxCRT_StrcmpA(s1, s2) == 0; )
  95. #if wxUSE_UNICODE
  96. wxDEPRECATED_INLINE(inline bool wxStringEq(const wchar_t *s1, const wchar_t *s2),
  97. return wxCRT_StrcmpW(s1, s2) == 0; )
  98. #endif // wxUSE_UNICODE
  99. #endif // WXWIN_COMPATIBILITY_2_8
  100. // ----------------------------------------------------------------------------
  101. // Miscellaneous functions
  102. // ----------------------------------------------------------------------------
  103. // Sound the bell
  104. WXDLLIMPEXP_CORE void wxBell();
  105. #if wxUSE_MSGDLG
  106. // Show wxWidgets information
  107. WXDLLIMPEXP_CORE void wxInfoMessageBox(wxWindow* parent);
  108. #endif // wxUSE_MSGDLG
  109. WXDLLIMPEXP_CORE wxVersionInfo wxGetLibraryVersionInfo();
  110. // Get OS description as a user-readable string
  111. WXDLLIMPEXP_BASE wxString wxGetOsDescription();
  112. // Get OS version
  113. WXDLLIMPEXP_BASE wxOperatingSystemId wxGetOsVersion(int *majorVsn = NULL,
  114. int *minorVsn = NULL);
  115. // Get platform endianness
  116. WXDLLIMPEXP_BASE bool wxIsPlatformLittleEndian();
  117. // Get platform architecture
  118. WXDLLIMPEXP_BASE bool wxIsPlatform64Bit();
  119. #ifdef __LINUX__
  120. // Get linux-distro informations
  121. WXDLLIMPEXP_BASE wxLinuxDistributionInfo wxGetLinuxDistributionInfo();
  122. #endif
  123. // Return a string with the current date/time
  124. WXDLLIMPEXP_BASE wxString wxNow();
  125. // Return path where wxWidgets is installed (mostly useful in Unices)
  126. WXDLLIMPEXP_BASE const wxChar *wxGetInstallPrefix();
  127. // Return path to wxWin data (/usr/share/wx/%{version}) (Unices)
  128. WXDLLIMPEXP_BASE wxString wxGetDataDir();
  129. #if wxUSE_GUI
  130. // Get the state of a key (true if pressed, false if not)
  131. // This is generally most useful getting the state of
  132. // the modifier or toggle keys.
  133. WXDLLIMPEXP_CORE bool wxGetKeyState(wxKeyCode key);
  134. // Don't synthesize KeyUp events holding down a key and producing
  135. // KeyDown events with autorepeat. On by default and always on
  136. // in wxMSW.
  137. WXDLLIMPEXP_CORE bool wxSetDetectableAutoRepeat( bool flag );
  138. // Returns the current state of the mouse position, buttons and modifers
  139. WXDLLIMPEXP_CORE wxMouseState wxGetMouseState();
  140. #endif // wxUSE_GUI
  141. // ----------------------------------------------------------------------------
  142. // wxPlatform
  143. // ----------------------------------------------------------------------------
  144. /*
  145. * Class to make it easier to specify platform-dependent values
  146. *
  147. * Examples:
  148. * long val = wxPlatform::If(wxMac, 1).ElseIf(wxGTK, 2).ElseIf(stPDA, 5).Else(3);
  149. * wxString strVal = wxPlatform::If(wxMac, wxT("Mac")).ElseIf(wxMSW, wxT("MSW")).Else(wxT("Other"));
  150. *
  151. * A custom platform symbol:
  152. *
  153. * #define stPDA 100
  154. * #ifdef __WXWINCE__
  155. * wxPlatform::AddPlatform(stPDA);
  156. * #endif
  157. *
  158. * long windowStyle = wxCAPTION | (long) wxPlatform::IfNot(stPDA, wxRESIZE_BORDER);
  159. *
  160. */
  161. class WXDLLIMPEXP_BASE wxPlatform
  162. {
  163. public:
  164. wxPlatform() { Init(); }
  165. wxPlatform(const wxPlatform& platform) { Copy(platform); }
  166. void operator = (const wxPlatform& platform) { if (&platform != this) Copy(platform); }
  167. void Copy(const wxPlatform& platform);
  168. // Specify an optional default value
  169. wxPlatform(int defValue) { Init(); m_longValue = (long)defValue; }
  170. wxPlatform(long defValue) { Init(); m_longValue = defValue; }
  171. wxPlatform(const wxString& defValue) { Init(); m_stringValue = defValue; }
  172. wxPlatform(double defValue) { Init(); m_doubleValue = defValue; }
  173. static wxPlatform If(int platform, long value);
  174. static wxPlatform IfNot(int platform, long value);
  175. wxPlatform& ElseIf(int platform, long value);
  176. wxPlatform& ElseIfNot(int platform, long value);
  177. wxPlatform& Else(long value);
  178. static wxPlatform If(int platform, int value) { return If(platform, (long)value); }
  179. static wxPlatform IfNot(int platform, int value) { return IfNot(platform, (long)value); }
  180. wxPlatform& ElseIf(int platform, int value) { return ElseIf(platform, (long) value); }
  181. wxPlatform& ElseIfNot(int platform, int value) { return ElseIfNot(platform, (long) value); }
  182. wxPlatform& Else(int value) { return Else((long) value); }
  183. static wxPlatform If(int platform, double value);
  184. static wxPlatform IfNot(int platform, double value);
  185. wxPlatform& ElseIf(int platform, double value);
  186. wxPlatform& ElseIfNot(int platform, double value);
  187. wxPlatform& Else(double value);
  188. static wxPlatform If(int platform, const wxString& value);
  189. static wxPlatform IfNot(int platform, const wxString& value);
  190. wxPlatform& ElseIf(int platform, const wxString& value);
  191. wxPlatform& ElseIfNot(int platform, const wxString& value);
  192. wxPlatform& Else(const wxString& value);
  193. long GetInteger() const { return m_longValue; }
  194. const wxString& GetString() const { return m_stringValue; }
  195. double GetDouble() const { return m_doubleValue; }
  196. operator int() const { return (int) GetInteger(); }
  197. operator long() const { return GetInteger(); }
  198. operator double() const { return GetDouble(); }
  199. operator const wxString&() const { return GetString(); }
  200. static void AddPlatform(int platform);
  201. static bool Is(int platform);
  202. static void ClearPlatforms();
  203. private:
  204. void Init() { m_longValue = 0; m_doubleValue = 0.0; }
  205. long m_longValue;
  206. double m_doubleValue;
  207. wxString m_stringValue;
  208. static wxArrayInt* sm_customPlatforms;
  209. };
  210. /// Function for testing current platform
  211. inline bool wxPlatformIs(int platform) { return wxPlatform::Is(platform); }
  212. // ----------------------------------------------------------------------------
  213. // Window ID management
  214. // ----------------------------------------------------------------------------
  215. // Ensure subsequent IDs don't clash with this one
  216. WXDLLIMPEXP_BASE void wxRegisterId(int id);
  217. // Return the current ID
  218. WXDLLIMPEXP_BASE int wxGetCurrentId();
  219. // Generate a unique ID
  220. WXDLLIMPEXP_BASE int wxNewId();
  221. // ----------------------------------------------------------------------------
  222. // Various conversions
  223. // ----------------------------------------------------------------------------
  224. // Convert 2-digit hex number to decimal
  225. WXDLLIMPEXP_BASE int wxHexToDec(const wxString& buf);
  226. // Convert 2-digit hex number to decimal
  227. inline int wxHexToDec(const char* buf)
  228. {
  229. int firstDigit, secondDigit;
  230. if (buf[0] >= 'A')
  231. firstDigit = buf[0] - 'A' + 10;
  232. else
  233. firstDigit = buf[0] - '0';
  234. if (buf[1] >= 'A')
  235. secondDigit = buf[1] - 'A' + 10;
  236. else
  237. secondDigit = buf[1] - '0';
  238. return (firstDigit & 0xF) * 16 + (secondDigit & 0xF );
  239. }
  240. // Convert decimal integer to 2-character hex string
  241. WXDLLIMPEXP_BASE void wxDecToHex(int dec, wxChar *buf);
  242. WXDLLIMPEXP_BASE void wxDecToHex(int dec, char* ch1, char* ch2);
  243. WXDLLIMPEXP_BASE wxString wxDecToHex(int dec);
  244. // ----------------------------------------------------------------------------
  245. // Process management
  246. // ----------------------------------------------------------------------------
  247. // NB: for backwards compatibility reasons the values of wxEXEC_[A]SYNC *must*
  248. // be 0 and 1, don't change!
  249. enum
  250. {
  251. // execute the process asynchronously
  252. wxEXEC_ASYNC = 0,
  253. // execute it synchronously, i.e. wait until it finishes
  254. wxEXEC_SYNC = 1,
  255. // under Windows, don't hide the child even if it's IO is redirected (this
  256. // is done by default)
  257. wxEXEC_SHOW_CONSOLE = 2,
  258. // deprecated synonym for wxEXEC_SHOW_CONSOLE, use the new name as it's
  259. // more clear
  260. wxEXEC_NOHIDE = wxEXEC_SHOW_CONSOLE,
  261. // under Unix, if the process is the group leader then passing wxKILL_CHILDREN to wxKill
  262. // kills all children as well as pid
  263. // under Windows (NT family only), sets the CREATE_NEW_PROCESS_GROUP flag,
  264. // which allows to target Ctrl-Break signal to the spawned process.
  265. // applies to console processes only.
  266. wxEXEC_MAKE_GROUP_LEADER = 4,
  267. // by default synchronous execution disables all program windows to avoid
  268. // that the user interacts with the program while the child process is
  269. // running, you can use this flag to prevent this from happening
  270. wxEXEC_NODISABLE = 8,
  271. // by default, the event loop is run while waiting for synchronous execution
  272. // to complete and this flag can be used to simply block the main process
  273. // until the child process finishes
  274. wxEXEC_NOEVENTS = 16,
  275. // under Windows, hide the console of the child process if it has one, even
  276. // if its IO is not redirected
  277. wxEXEC_HIDE_CONSOLE = 32,
  278. // convenient synonym for flags given system()-like behaviour
  279. wxEXEC_BLOCK = wxEXEC_SYNC | wxEXEC_NOEVENTS
  280. };
  281. // Map storing environment variables.
  282. typedef wxStringToStringHashMap wxEnvVariableHashMap;
  283. // Used to pass additional parameters for child process to wxExecute(). Could
  284. // be extended with other fields later.
  285. struct wxExecuteEnv
  286. {
  287. wxString cwd; // If empty, CWD is not changed.
  288. wxEnvVariableHashMap env; // If empty, environment is unchanged.
  289. };
  290. // Execute another program.
  291. //
  292. // If flags contain wxEXEC_SYNC, return -1 on failure and the exit code of the
  293. // process if everything was ok. Otherwise (i.e. if wxEXEC_ASYNC), return 0 on
  294. // failure and the PID of the launched process if ok.
  295. WXDLLIMPEXP_BASE long wxExecute(const wxString& command,
  296. int flags = wxEXEC_ASYNC,
  297. wxProcess *process = NULL,
  298. const wxExecuteEnv *env = NULL);
  299. WXDLLIMPEXP_BASE long wxExecute(char **argv,
  300. int flags = wxEXEC_ASYNC,
  301. wxProcess *process = NULL,
  302. const wxExecuteEnv *env = NULL);
  303. #if wxUSE_UNICODE
  304. WXDLLIMPEXP_BASE long wxExecute(wchar_t **argv,
  305. int flags = wxEXEC_ASYNC,
  306. wxProcess *process = NULL,
  307. const wxExecuteEnv *env = NULL);
  308. #endif // wxUSE_UNICODE
  309. // execute the command capturing its output into an array line by line, this is
  310. // always synchronous
  311. WXDLLIMPEXP_BASE long wxExecute(const wxString& command,
  312. wxArrayString& output,
  313. int flags = 0,
  314. const wxExecuteEnv *env = NULL);
  315. // also capture stderr (also synchronous)
  316. WXDLLIMPEXP_BASE long wxExecute(const wxString& command,
  317. wxArrayString& output,
  318. wxArrayString& error,
  319. int flags = 0,
  320. const wxExecuteEnv *env = NULL);
  321. #if defined(__WINDOWS__) && wxUSE_IPC
  322. // ask a DDE server to execute the DDE request with given parameters
  323. WXDLLIMPEXP_BASE bool wxExecuteDDE(const wxString& ddeServer,
  324. const wxString& ddeTopic,
  325. const wxString& ddeCommand);
  326. #endif // __WINDOWS__ && wxUSE_IPC
  327. enum wxSignal
  328. {
  329. wxSIGNONE = 0, // verify if the process exists under Unix
  330. wxSIGHUP,
  331. wxSIGINT,
  332. wxSIGQUIT,
  333. wxSIGILL,
  334. wxSIGTRAP,
  335. wxSIGABRT,
  336. wxSIGIOT = wxSIGABRT, // another name
  337. wxSIGEMT,
  338. wxSIGFPE,
  339. wxSIGKILL,
  340. wxSIGBUS,
  341. wxSIGSEGV,
  342. wxSIGSYS,
  343. wxSIGPIPE,
  344. wxSIGALRM,
  345. wxSIGTERM
  346. // further signals are different in meaning between different Unix systems
  347. };
  348. enum wxKillError
  349. {
  350. wxKILL_OK, // no error
  351. wxKILL_BAD_SIGNAL, // no such signal
  352. wxKILL_ACCESS_DENIED, // permission denied
  353. wxKILL_NO_PROCESS, // no such process
  354. wxKILL_ERROR // another, unspecified error
  355. };
  356. enum wxKillFlags
  357. {
  358. wxKILL_NOCHILDREN = 0, // don't kill children
  359. wxKILL_CHILDREN = 1 // kill children
  360. };
  361. enum wxShutdownFlags
  362. {
  363. wxSHUTDOWN_FORCE = 1,// can be combined with other flags (MSW-only)
  364. wxSHUTDOWN_POWEROFF = 2,// power off the computer
  365. wxSHUTDOWN_REBOOT = 4,// shutdown and reboot
  366. wxSHUTDOWN_LOGOFF = 8 // close session (currently MSW-only)
  367. };
  368. // Shutdown or reboot the PC
  369. WXDLLIMPEXP_BASE bool wxShutdown(int flags = wxSHUTDOWN_POWEROFF);
  370. // send the given signal to the process (only NONE and KILL are supported under
  371. // Windows, all others mean TERM), return 0 if ok and -1 on error
  372. //
  373. // return detailed error in rc if not NULL
  374. WXDLLIMPEXP_BASE int wxKill(long pid,
  375. wxSignal sig = wxSIGTERM,
  376. wxKillError *rc = NULL,
  377. int flags = wxKILL_NOCHILDREN);
  378. // Execute a command in an interactive shell window (always synchronously)
  379. // If no command then just the shell
  380. WXDLLIMPEXP_BASE bool wxShell(const wxString& command = wxEmptyString);
  381. // As wxShell(), but must give a (non interactive) command and its output will
  382. // be returned in output array
  383. WXDLLIMPEXP_BASE bool wxShell(const wxString& command, wxArrayString& output);
  384. // Sleep for nSecs seconds
  385. WXDLLIMPEXP_BASE void wxSleep(int nSecs);
  386. // Sleep for a given amount of milliseconds
  387. WXDLLIMPEXP_BASE void wxMilliSleep(unsigned long milliseconds);
  388. // Sleep for a given amount of microseconds
  389. WXDLLIMPEXP_BASE void wxMicroSleep(unsigned long microseconds);
  390. #if WXWIN_COMPATIBILITY_2_8
  391. // Sleep for a given amount of milliseconds (old, bad name), use wxMilliSleep
  392. wxDEPRECATED( WXDLLIMPEXP_BASE void wxUsleep(unsigned long milliseconds) );
  393. #endif
  394. // Get the process id of the current process
  395. WXDLLIMPEXP_BASE unsigned long wxGetProcessId();
  396. // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
  397. WXDLLIMPEXP_BASE wxMemorySize wxGetFreeMemory();
  398. #if wxUSE_ON_FATAL_EXCEPTION
  399. // should wxApp::OnFatalException() be called?
  400. WXDLLIMPEXP_BASE bool wxHandleFatalExceptions(bool doit = true);
  401. #endif // wxUSE_ON_FATAL_EXCEPTION
  402. // ----------------------------------------------------------------------------
  403. // Environment variables
  404. // ----------------------------------------------------------------------------
  405. // returns true if variable exists (value may be NULL if you just want to check
  406. // for this)
  407. WXDLLIMPEXP_BASE bool wxGetEnv(const wxString& var, wxString *value);
  408. // set the env var name to the given value, return true on success
  409. WXDLLIMPEXP_BASE bool wxSetEnv(const wxString& var, const wxString& value);
  410. // remove the env var from environment
  411. WXDLLIMPEXP_BASE bool wxUnsetEnv(const wxString& var);
  412. #if WXWIN_COMPATIBILITY_2_8
  413. inline bool wxSetEnv(const wxString& var, const char *value)
  414. { return wxSetEnv(var, wxString(value)); }
  415. inline bool wxSetEnv(const wxString& var, const wchar_t *value)
  416. { return wxSetEnv(var, wxString(value)); }
  417. template<typename T>
  418. inline bool wxSetEnv(const wxString& var, const wxScopedCharTypeBuffer<T>& value)
  419. { return wxSetEnv(var, wxString(value)); }
  420. inline bool wxSetEnv(const wxString& var, const wxCStrData& value)
  421. { return wxSetEnv(var, wxString(value)); }
  422. // this one is for passing NULL directly - don't use it, use wxUnsetEnv instead
  423. wxDEPRECATED( inline bool wxSetEnv(const wxString& var, int value) );
  424. inline bool wxSetEnv(const wxString& var, int value)
  425. {
  426. wxASSERT_MSG( value == 0, "using non-NULL integer as string?" );
  427. wxUnusedVar(value); // fix unused parameter warning in release build
  428. return wxUnsetEnv(var);
  429. }
  430. #endif // WXWIN_COMPATIBILITY_2_8
  431. // Retrieve the complete environment by filling specified map.
  432. // Returns true on success or false if an error occurred.
  433. WXDLLIMPEXP_BASE bool wxGetEnvMap(wxEnvVariableHashMap *map);
  434. // ----------------------------------------------------------------------------
  435. // Network and username functions.
  436. // ----------------------------------------------------------------------------
  437. // NB: "char *" functions are deprecated, use wxString ones!
  438. // Get eMail address
  439. WXDLLIMPEXP_BASE bool wxGetEmailAddress(wxChar *buf, int maxSize);
  440. WXDLLIMPEXP_BASE wxString wxGetEmailAddress();
  441. // Get hostname.
  442. WXDLLIMPEXP_BASE bool wxGetHostName(wxChar *buf, int maxSize);
  443. WXDLLIMPEXP_BASE wxString wxGetHostName();
  444. // Get FQDN
  445. WXDLLIMPEXP_BASE wxString wxGetFullHostName();
  446. WXDLLIMPEXP_BASE bool wxGetFullHostName(wxChar *buf, int maxSize);
  447. // Get user ID e.g. jacs (this is known as login name under Unix)
  448. WXDLLIMPEXP_BASE bool wxGetUserId(wxChar *buf, int maxSize);
  449. WXDLLIMPEXP_BASE wxString wxGetUserId();
  450. // Get user name e.g. Julian Smart
  451. WXDLLIMPEXP_BASE bool wxGetUserName(wxChar *buf, int maxSize);
  452. WXDLLIMPEXP_BASE wxString wxGetUserName();
  453. // Get current Home dir and copy to dest (returns pstr->c_str())
  454. WXDLLIMPEXP_BASE wxString wxGetHomeDir();
  455. WXDLLIMPEXP_BASE const wxChar* wxGetHomeDir(wxString *pstr);
  456. // Get the user's (by default use the current user name) home dir,
  457. // return empty string on error
  458. WXDLLIMPEXP_BASE wxString wxGetUserHome(const wxString& user = wxEmptyString);
  459. #if wxUSE_LONGLONG
  460. typedef wxLongLong wxDiskspaceSize_t;
  461. #else
  462. typedef long wxDiskspaceSize_t;
  463. #endif
  464. // get number of total/free bytes on the disk where path belongs
  465. WXDLLIMPEXP_BASE bool wxGetDiskSpace(const wxString& path,
  466. wxDiskspaceSize_t *pTotal = NULL,
  467. wxDiskspaceSize_t *pFree = NULL);
  468. typedef int (*wxSortCallback)(const void* pItem1,
  469. const void* pItem2,
  470. const void* user_data);
  471. WXDLLIMPEXP_BASE void wxQsort(void* pbase, size_t total_elems,
  472. size_t size, wxSortCallback cmp,
  473. const void* user_data);
  474. #if wxUSE_GUI // GUI only things from now on
  475. // ----------------------------------------------------------------------------
  476. // Launch default browser
  477. // ----------------------------------------------------------------------------
  478. // flags for wxLaunchDefaultBrowser
  479. enum
  480. {
  481. wxBROWSER_NEW_WINDOW = 0x01,
  482. wxBROWSER_NOBUSYCURSOR = 0x02
  483. };
  484. // Launch url in the user's default internet browser
  485. WXDLLIMPEXP_CORE bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0);
  486. // Launch document in the user's default application
  487. WXDLLIMPEXP_CORE bool wxLaunchDefaultApplication(const wxString& path, int flags = 0);
  488. // ----------------------------------------------------------------------------
  489. // Menu accelerators related things
  490. // ----------------------------------------------------------------------------
  491. // flags for wxStripMenuCodes
  492. enum
  493. {
  494. // strip '&' characters
  495. wxStrip_Mnemonics = 1,
  496. // strip everything after '\t'
  497. wxStrip_Accel = 2,
  498. // strip everything (this is the default)
  499. wxStrip_All = wxStrip_Mnemonics | wxStrip_Accel
  500. };
  501. // strip mnemonics and/or accelerators from the label
  502. WXDLLIMPEXP_CORE wxString
  503. wxStripMenuCodes(const wxString& str, int flags = wxStrip_All);
  504. #if WXWIN_COMPATIBILITY_2_6
  505. // obsolete and deprecated version, do not use, use the above overload instead
  506. wxDEPRECATED(
  507. WXDLLIMPEXP_CORE wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = NULL)
  508. );
  509. #if wxUSE_ACCEL
  510. class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry;
  511. // use wxAcceleratorEntry::Create() or FromString() methods instead
  512. wxDEPRECATED(
  513. WXDLLIMPEXP_CORE wxAcceleratorEntry *wxGetAccelFromString(const wxString& label)
  514. );
  515. #endif // wxUSE_ACCEL
  516. #endif // WXWIN_COMPATIBILITY_2_6
  517. // ----------------------------------------------------------------------------
  518. // Window search
  519. // ----------------------------------------------------------------------------
  520. // Returns menu item id or wxNOT_FOUND if none.
  521. WXDLLIMPEXP_CORE int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
  522. // Find the wxWindow at the given point. wxGenericFindWindowAtPoint
  523. // is always present but may be less reliable than a native version.
  524. WXDLLIMPEXP_CORE wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
  525. WXDLLIMPEXP_CORE wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
  526. // NB: this function is obsolete, use wxWindow::FindWindowByLabel() instead
  527. //
  528. // Find the window/widget with the given title or label.
  529. // Pass a parent to begin the search from, or NULL to look through
  530. // all windows.
  531. WXDLLIMPEXP_CORE wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = NULL);
  532. // NB: this function is obsolete, use wxWindow::FindWindowByName() instead
  533. //
  534. // Find window by name, and if that fails, by label.
  535. WXDLLIMPEXP_CORE wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = NULL);
  536. // ----------------------------------------------------------------------------
  537. // Message/event queue helpers
  538. // ----------------------------------------------------------------------------
  539. // Yield to other apps/messages and disable user input
  540. WXDLLIMPEXP_CORE bool wxSafeYield(wxWindow *win = NULL, bool onlyIfNeeded = false);
  541. // Enable or disable input to all top level windows
  542. WXDLLIMPEXP_CORE void wxEnableTopLevelWindows(bool enable = true);
  543. // Check whether this window wants to process messages, e.g. Stop button
  544. // in long calculations.
  545. WXDLLIMPEXP_CORE bool wxCheckForInterrupt(wxWindow *wnd);
  546. // Consume all events until no more left
  547. WXDLLIMPEXP_CORE void wxFlushEvents();
  548. // a class which disables all windows (except, may be, the given one) in its
  549. // ctor and enables them back in its dtor
  550. class WXDLLIMPEXP_CORE wxWindowDisabler
  551. {
  552. public:
  553. // this ctor conditionally disables all windows: if the argument is false,
  554. // it doesn't do anything
  555. wxWindowDisabler(bool disable = true);
  556. // ctor disables all windows except winToSkip
  557. wxWindowDisabler(wxWindow *winToSkip);
  558. // dtor enables back all windows disabled by the ctor
  559. ~wxWindowDisabler();
  560. private:
  561. // disable all windows except the given one (used by both ctors)
  562. void DoDisable(wxWindow *winToSkip = NULL);
  563. #if defined(__WXOSX__) && wxOSX_USE_COCOA
  564. wxEventLoop* m_modalEventLoop;
  565. #endif
  566. wxWindowList *m_winDisabled;
  567. bool m_disabled;
  568. wxDECLARE_NO_COPY_CLASS(wxWindowDisabler);
  569. };
  570. // ----------------------------------------------------------------------------
  571. // Cursors
  572. // ----------------------------------------------------------------------------
  573. // Set the cursor to the busy cursor for all windows
  574. WXDLLIMPEXP_CORE void wxBeginBusyCursor(const wxCursor *cursor = wxHOURGLASS_CURSOR);
  575. // Restore cursor to normal
  576. WXDLLIMPEXP_CORE void wxEndBusyCursor();
  577. // true if we're between the above two calls
  578. WXDLLIMPEXP_CORE bool wxIsBusy();
  579. // Convenience class so we can just create a wxBusyCursor object on the stack
  580. class WXDLLIMPEXP_CORE wxBusyCursor
  581. {
  582. public:
  583. wxBusyCursor(const wxCursor* cursor = wxHOURGLASS_CURSOR)
  584. { wxBeginBusyCursor(cursor); }
  585. ~wxBusyCursor()
  586. { wxEndBusyCursor(); }
  587. // Obsolete internal methods, do not use.
  588. static const wxCursor &GetStoredCursor();
  589. static const wxCursor GetBusyCursor();
  590. };
  591. void WXDLLIMPEXP_CORE wxGetMousePosition( int* x, int* y );
  592. // ----------------------------------------------------------------------------
  593. // X11 Display access
  594. // ----------------------------------------------------------------------------
  595. #if defined(__X__) || defined(__WXGTK__)
  596. #ifdef __WXGTK__
  597. WXDLLIMPEXP_CORE void *wxGetDisplay();
  598. #endif
  599. #ifdef __X__
  600. WXDLLIMPEXP_CORE WXDisplay *wxGetDisplay();
  601. WXDLLIMPEXP_CORE bool wxSetDisplay(const wxString& display_name);
  602. WXDLLIMPEXP_CORE wxString wxGetDisplayName();
  603. #endif // X or GTK+
  604. // use this function instead of the functions above in implementation code
  605. inline struct _XDisplay *wxGetX11Display()
  606. {
  607. return (_XDisplay *)wxGetDisplay();
  608. }
  609. #endif // X11 || wxGTK
  610. #endif // wxUSE_GUI
  611. // ----------------------------------------------------------------------------
  612. // wxYield(): these functions are obsolete, please use wxApp methods instead!
  613. // ----------------------------------------------------------------------------
  614. // avoid redeclaring this function here if it had been already declated by
  615. // wx/app.h, this results in warnings from g++ with -Wredundant-decls
  616. #ifndef wx_YIELD_DECLARED
  617. #define wx_YIELD_DECLARED
  618. // Yield to other apps/messages
  619. WXDLLIMPEXP_CORE bool wxYield();
  620. #endif // wx_YIELD_DECLARED
  621. // Like wxYield, but fails silently if the yield is recursive.
  622. WXDLLIMPEXP_CORE bool wxYieldIfNeeded();
  623. // ----------------------------------------------------------------------------
  624. // Windows resources access
  625. // ----------------------------------------------------------------------------
  626. // Windows only: get user-defined resource from the .res file.
  627. #ifdef __WINDOWS__
  628. // default resource type for wxLoadUserResource()
  629. extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxUserResourceStr;
  630. // Return the pointer to the resource data. This pointer is read-only, use
  631. // the overload below if you need to modify the data.
  632. //
  633. // Notice that the resource type can be either a real string or an integer
  634. // produced by MAKEINTRESOURCE(). In particular, any standard resource type,
  635. // i.e any RT_XXX constant, could be passed here.
  636. //
  637. // Returns true on success, false on failure. Doesn't log an error message
  638. // if the resource is not found (because this could be expected) but does
  639. // log one if any other error occurs.
  640. WXDLLIMPEXP_BASE bool
  641. wxLoadUserResource(const void **outData,
  642. size_t *outLen,
  643. const wxString& resourceName,
  644. const wxChar* resourceType = wxUserResourceStr,
  645. WXHINSTANCE module = 0);
  646. // This function allocates a new buffer and makes a copy of the resource
  647. // data, remember to delete[] the buffer. And avoid using it entirely if
  648. // the overload above can be used.
  649. //
  650. // Returns NULL on failure.
  651. WXDLLIMPEXP_BASE char*
  652. wxLoadUserResource(const wxString& resourceName,
  653. const wxChar* resourceType = wxUserResourceStr,
  654. int* pLen = NULL,
  655. WXHINSTANCE module = 0);
  656. #endif // __WINDOWS__
  657. #endif
  658. // _WX_UTILSH__