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