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