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