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