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