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