]> git.saurik.com Git - wxWidgets.git/blob - include/wx/utils.h
More efficient access to name and value
[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 // needed for wxOperatingSystemId, wxLinuxDistributionInfo
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 = NULL,
111 int *minorVsn = NULL);
112
113 // Get platform endianness
114 WXDLLIMPEXP_BASE bool wxIsPlatformLittleEndian();
115
116 // Get platform architecture
117 WXDLLIMPEXP_BASE bool wxIsPlatform64Bit();
118
119 #ifdef __LINUX__
120 // Get linux-distro informations
121 WXDLLIMPEXP_BASE wxLinuxDistributionInfo wxGetLinuxDistributionInfo();
122 #endif
123
124 // Return a string with the current date/time
125 WXDLLIMPEXP_BASE wxString wxNow();
126
127 // Return path where wxWidgets is installed (mostly useful in Unices)
128 WXDLLIMPEXP_BASE const wxChar *wxGetInstallPrefix();
129 // Return path to wxWin data (/usr/share/wx/%{version}) (Unices)
130 WXDLLIMPEXP_BASE wxString wxGetDataDir();
131
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.
137 WXDLLIMPEXP_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.
142 WXDLLIMPEXP_CORE bool wxSetDetectableAutoRepeat( bool flag );
143
144 // Returns the current state of the mouse position, buttons and modifers
145 WXDLLIMPEXP_CORE wxMouseState wxGetMouseState();
146
147 #endif // wxUSE_GUI
148
149 // ----------------------------------------------------------------------------
150 // wxPlatform
151 // ----------------------------------------------------------------------------
152
153 /*
154 * Class to make it easier to specify platform-dependent values
155 *
156 * Examples:
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"));
159 *
160 * A custom platform symbol:
161 *
162 * #define stPDA 100
163 * #ifdef __WXWINCE__
164 * wxPlatform::AddPlatform(stPDA);
165 * #endif
166 *
167 * long windowStyle = wxCAPTION | (long) wxPlatform::IfNot(stPDA, wxRESIZE_BORDER);
168 *
169 */
170
171 class WXDLLIMPEXP_BASE wxPlatform
172 {
173 public:
174 wxPlatform() { Init(); }
175 wxPlatform(const wxPlatform& platform) { Copy(platform); }
176 void operator = (const wxPlatform& platform) { if (&platform != this) Copy(platform); }
177 void Copy(const wxPlatform& platform);
178
179 // Specify an optional default value
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; }
184
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
191 static wxPlatform If(int platform, int value) { return If(platform, (long)value); }
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);
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(); }
216 operator const wxString&() const { return GetString(); }
217
218 static void AddPlatform(int platform);
219 static bool Is(int platform);
220 static void ClearPlatforms();
221
222 private:
223
224 void Init() { m_longValue = 0; m_doubleValue = 0.0; }
225
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
233 inline bool wxPlatformIs(int platform) { return wxPlatform::Is(platform); }
234
235 // ----------------------------------------------------------------------------
236 // Window ID management
237 // ----------------------------------------------------------------------------
238
239 // Ensure subsequent IDs don't clash with this one
240 WXDLLIMPEXP_BASE void wxRegisterId(long id);
241
242 // Return the current ID
243 WXDLLIMPEXP_BASE long wxGetCurrentId();
244
245 // Generate a unique ID
246 WXDLLIMPEXP_BASE long wxNewId();
247
248 // ----------------------------------------------------------------------------
249 // Various conversions
250 // ----------------------------------------------------------------------------
251
252 // Convert 2-digit hex number to decimal
253 WXDLLIMPEXP_BASE int wxHexToDec(const wxString& buf);
254
255 // Convert 2-digit hex number to decimal
256 inline int wxHexToDec(const char* buf)
257 {
258 int firstDigit, secondDigit;
259
260 if (buf[0] >= 'A')
261 firstDigit = buf[0] - 'A' + 10;
262 else
263 firstDigit = buf[0] - '0';
264
265 if (buf[1] >= 'A')
266 secondDigit = buf[1] - 'A' + 10;
267 else
268 secondDigit = buf[1] - '0';
269
270 return (firstDigit & 0xF) * 16 + (secondDigit & 0xF );
271 }
272
273
274 // Convert decimal integer to 2-character hex string
275 WXDLLIMPEXP_BASE void wxDecToHex(int dec, wxChar *buf);
276 WXDLLIMPEXP_BASE void wxDecToHex(int dec, char* ch1, char* ch2);
277 WXDLLIMPEXP_BASE wxString wxDecToHex(int dec);
278
279 // ----------------------------------------------------------------------------
280 // Process management
281 // ----------------------------------------------------------------------------
282
283 // NB: for backwards compatibility reasons the values of wxEXEC_[A]SYNC *must*
284 // be 0 and 1, don't change!
285
286 enum
287 {
288 // execute the process asynchronously
289 wxEXEC_ASYNC = 0,
290
291 // execute it synchronously, i.e. wait until it finishes
292 wxEXEC_SYNC = 1,
293
294 // under Windows, don't hide the child even if it's IO is redirected (this
295 // is done by default)
296 wxEXEC_NOHIDE = 2,
297
298 // under Unix, if the process is the group leader then passing wxKILL_CHILDREN to wxKill
299 // kills all children as well as pid
300 wxEXEC_MAKE_GROUP_LEADER = 4,
301
302 // by default synchronous execution disables all program windows to avoid
303 // that the user interacts with the program while the child process is
304 // running, you can use this flag to prevent this from happening
305 wxEXEC_NODISABLE = 8,
306
307 // by default, the event loop is run while waiting for synchronous execution
308 // to complete and this flag can be used to simply block the main process
309 // until the child process finishes
310 wxEXEC_NOEVENTS = 16,
311
312 // convenient synonym for flags given system()-like behaviour
313 wxEXEC_BLOCK = wxEXEC_SYNC | wxEXEC_NOEVENTS
314 };
315
316 // Execute another program.
317 //
318 // If flags contain wxEXEC_SYNC, return -1 on failure and the exit code of the
319 // process if everything was ok. Otherwise (i.e. if wxEXEC_ASYNC), return 0 on
320 // failure and the PID of the launched process if ok.
321 WXDLLIMPEXP_BASE long wxExecute(const wxString& command,
322 int flags = wxEXEC_ASYNC,
323 wxProcess *process = NULL);
324 WXDLLIMPEXP_BASE long wxExecute(char **argv,
325 int flags = wxEXEC_ASYNC,
326 wxProcess *process = NULL);
327 #if wxUSE_UNICODE
328 WXDLLIMPEXP_BASE long wxExecute(wchar_t **argv,
329 int flags = wxEXEC_ASYNC,
330 wxProcess *process = NULL);
331 #endif // wxUSE_UNICODE
332
333 // execute the command capturing its output into an array line by line, this is
334 // always synchronous
335 WXDLLIMPEXP_BASE long wxExecute(const wxString& command,
336 wxArrayString& output,
337 int flags = 0);
338
339 // also capture stderr (also synchronous)
340 WXDLLIMPEXP_BASE long wxExecute(const wxString& command,
341 wxArrayString& output,
342 wxArrayString& error,
343 int flags = 0);
344
345 #if defined(__WXMSW__) && wxUSE_IPC
346 // ask a DDE server to execute the DDE request with given parameters
347 WXDLLIMPEXP_BASE bool wxExecuteDDE(const wxString& ddeServer,
348 const wxString& ddeTopic,
349 const wxString& ddeCommand);
350 #endif // __WXMSW__ && wxUSE_IPC
351
352 enum wxSignal
353 {
354 wxSIGNONE = 0, // verify if the process exists under Unix
355 wxSIGHUP,
356 wxSIGINT,
357 wxSIGQUIT,
358 wxSIGILL,
359 wxSIGTRAP,
360 wxSIGABRT,
361 wxSIGIOT = wxSIGABRT, // another name
362 wxSIGEMT,
363 wxSIGFPE,
364 wxSIGKILL,
365 wxSIGBUS,
366 wxSIGSEGV,
367 wxSIGSYS,
368 wxSIGPIPE,
369 wxSIGALRM,
370 wxSIGTERM
371
372 // further signals are different in meaning between different Unix systems
373 };
374
375 enum wxKillError
376 {
377 wxKILL_OK, // no error
378 wxKILL_BAD_SIGNAL, // no such signal
379 wxKILL_ACCESS_DENIED, // permission denied
380 wxKILL_NO_PROCESS, // no such process
381 wxKILL_ERROR // another, unspecified error
382 };
383
384 enum wxKillFlags
385 {
386 wxKILL_NOCHILDREN = 0, // don't kill children
387 wxKILL_CHILDREN = 1 // kill children
388 };
389
390 enum wxShutdownFlags
391 {
392 wxSHUTDOWN_FORCE = 1,// can be combined with other flags (MSW-only)
393 wxSHUTDOWN_POWEROFF = 2,// power off the computer
394 wxSHUTDOWN_REBOOT = 4,// shutdown and reboot
395 wxSHUTDOWN_LOGOFF = 8 // close session (currently MSW-only)
396 };
397
398 // Shutdown or reboot the PC
399 WXDLLIMPEXP_BASE bool wxShutdown(int flags = wxSHUTDOWN_POWEROFF);
400
401 // send the given signal to the process (only NONE and KILL are supported under
402 // Windows, all others mean TERM), return 0 if ok and -1 on error
403 //
404 // return detailed error in rc if not NULL
405 WXDLLIMPEXP_BASE int wxKill(long pid,
406 wxSignal sig = wxSIGTERM,
407 wxKillError *rc = NULL,
408 int flags = wxKILL_NOCHILDREN);
409
410 // Execute a command in an interactive shell window (always synchronously)
411 // If no command then just the shell
412 WXDLLIMPEXP_BASE bool wxShell(const wxString& command = wxEmptyString);
413
414 // As wxShell(), but must give a (non interactive) command and its output will
415 // be returned in output array
416 WXDLLIMPEXP_BASE bool wxShell(const wxString& command, wxArrayString& output);
417
418 // Sleep for nSecs seconds
419 WXDLLIMPEXP_BASE void wxSleep(int nSecs);
420
421 // Sleep for a given amount of milliseconds
422 WXDLLIMPEXP_BASE void wxMilliSleep(unsigned long milliseconds);
423
424 // Sleep for a given amount of microseconds
425 WXDLLIMPEXP_BASE void wxMicroSleep(unsigned long microseconds);
426
427 #if WXWIN_COMPATIBILITY_2_8
428 // Sleep for a given amount of milliseconds (old, bad name), use wxMilliSleep
429 wxDEPRECATED( WXDLLIMPEXP_BASE void wxUsleep(unsigned long milliseconds) );
430 #endif
431
432 // Get the process id of the current process
433 WXDLLIMPEXP_BASE unsigned long wxGetProcessId();
434
435 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
436 WXDLLIMPEXP_BASE wxMemorySize wxGetFreeMemory();
437
438 #if wxUSE_ON_FATAL_EXCEPTION
439
440 // should wxApp::OnFatalException() be called?
441 WXDLLIMPEXP_BASE bool wxHandleFatalExceptions(bool doit = true);
442
443 #endif // wxUSE_ON_FATAL_EXCEPTION
444
445 // ----------------------------------------------------------------------------
446 // Environment variables
447 // ----------------------------------------------------------------------------
448
449 // returns true if variable exists (value may be NULL if you just want to check
450 // for this)
451 WXDLLIMPEXP_BASE bool wxGetEnv(const wxString& var, wxString *value);
452
453 // set the env var name to the given value, return true on success
454 WXDLLIMPEXP_BASE bool wxSetEnv(const wxString& var, const wxString& value);
455
456 // remove the env var from environment
457 WXDLLIMPEXP_BASE bool wxUnsetEnv(const wxString& var);
458
459 #if WXWIN_COMPATIBILITY_2_8
460 inline bool wxSetEnv(const wxString& var, const char *value)
461 { return wxSetEnv(var, wxString(value)); }
462 inline bool wxSetEnv(const wxString& var, const wchar_t *value)
463 { return wxSetEnv(var, wxString(value)); }
464 template<typename T>
465 inline bool wxSetEnv(const wxString& var, const wxScopedCharTypeBuffer<T>& value)
466 { return wxSetEnv(var, wxString(value)); }
467 inline bool wxSetEnv(const wxString& var, const wxCStrData& value)
468 { return wxSetEnv(var, wxString(value)); }
469
470 // this one is for passing NULL directly - don't use it, use wxUnsetEnv instead
471 wxDEPRECATED( inline bool wxSetEnv(const wxString& var, int value) );
472 inline bool wxSetEnv(const wxString& var, int value)
473 {
474 wxASSERT_MSG( value == 0, "using non-NULL integer as string?" );
475
476 wxUnusedVar(value); // fix unused parameter warning in release build
477
478 return wxUnsetEnv(var);
479 }
480 #endif // WXWIN_COMPATIBILITY_2_8
481
482 // ----------------------------------------------------------------------------
483 // Network and username functions.
484 // ----------------------------------------------------------------------------
485
486 // NB: "char *" functions are deprecated, use wxString ones!
487
488 // Get eMail address
489 WXDLLIMPEXP_BASE bool wxGetEmailAddress(wxChar *buf, int maxSize);
490 WXDLLIMPEXP_BASE wxString wxGetEmailAddress();
491
492 // Get hostname.
493 WXDLLIMPEXP_BASE bool wxGetHostName(wxChar *buf, int maxSize);
494 WXDLLIMPEXP_BASE wxString wxGetHostName();
495
496 // Get FQDN
497 WXDLLIMPEXP_BASE wxString wxGetFullHostName();
498 WXDLLIMPEXP_BASE bool wxGetFullHostName(wxChar *buf, int maxSize);
499
500 // Get user ID e.g. jacs (this is known as login name under Unix)
501 WXDLLIMPEXP_BASE bool wxGetUserId(wxChar *buf, int maxSize);
502 WXDLLIMPEXP_BASE wxString wxGetUserId();
503
504 // Get user name e.g. Julian Smart
505 WXDLLIMPEXP_BASE bool wxGetUserName(wxChar *buf, int maxSize);
506 WXDLLIMPEXP_BASE wxString wxGetUserName();
507
508 // Get current Home dir and copy to dest (returns pstr->c_str())
509 WXDLLIMPEXP_BASE wxString wxGetHomeDir();
510 WXDLLIMPEXP_BASE const wxChar* wxGetHomeDir(wxString *pstr);
511
512 // Get the user's (by default use the current user name) home dir,
513 // return empty string on error
514 WXDLLIMPEXP_BASE wxString wxGetUserHome(const wxString& user = wxEmptyString);
515
516
517 #if wxUSE_LONGLONG
518 typedef wxLongLong wxDiskspaceSize_t;
519 #else
520 typedef long wxDiskspaceSize_t;
521 #endif
522
523 // get number of total/free bytes on the disk where path belongs
524 WXDLLIMPEXP_BASE bool wxGetDiskSpace(const wxString& path,
525 wxDiskspaceSize_t *pTotal = NULL,
526 wxDiskspaceSize_t *pFree = NULL);
527
528
529
530 extern "C"
531 {
532 typedef int (wxCMPFUNC_CONV *CMPFUNCDATA)(const void* pItem1, const void* pItem2, const void* user_data);
533 }
534
535
536 WXDLLIMPEXP_BASE void wxQsort(void *const pbase, size_t total_elems,
537 size_t size, CMPFUNCDATA cmp, const void* user_data);
538
539
540 #if wxUSE_GUI // GUI only things from now on
541
542 // ----------------------------------------------------------------------------
543 // Launch default browser
544 // ----------------------------------------------------------------------------
545
546 // flags for wxLaunchDefaultBrowser
547 enum
548 {
549 wxBROWSER_NEW_WINDOW = 0x01,
550 wxBROWSER_NOBUSYCURSOR = 0x02
551 };
552
553 // Launch url in the user's default internet browser
554 WXDLLIMPEXP_CORE bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0);
555
556 // Launch document in the user's default application
557 WXDLLIMPEXP_CORE bool wxLaunchDefaultApplication(const wxString& path, int flags = 0);
558
559 // ----------------------------------------------------------------------------
560 // Menu accelerators related things
561 // ----------------------------------------------------------------------------
562
563 // flags for wxStripMenuCodes
564 enum
565 {
566 // strip '&' characters
567 wxStrip_Mnemonics = 1,
568
569 // strip everything after '\t'
570 wxStrip_Accel = 2,
571
572 // strip everything (this is the default)
573 wxStrip_All = wxStrip_Mnemonics | wxStrip_Accel
574 };
575
576 // strip mnemonics and/or accelerators from the label
577 WXDLLIMPEXP_CORE wxString
578 wxStripMenuCodes(const wxString& str, int flags = wxStrip_All);
579
580 #if WXWIN_COMPATIBILITY_2_6
581 // obsolete and deprecated version, do not use, use the above overload instead
582 wxDEPRECATED(
583 WXDLLIMPEXP_CORE wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = NULL)
584 );
585
586 #if wxUSE_ACCEL
587 class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry;
588
589 // use wxAcceleratorEntry::Create() or FromString() methods instead
590 wxDEPRECATED(
591 WXDLLIMPEXP_CORE wxAcceleratorEntry *wxGetAccelFromString(const wxString& label)
592 );
593 #endif // wxUSE_ACCEL
594
595 #endif // WXWIN_COMPATIBILITY_2_6
596
597 // ----------------------------------------------------------------------------
598 // Window search
599 // ----------------------------------------------------------------------------
600
601 // Returns menu item id or wxNOT_FOUND if none.
602 WXDLLIMPEXP_CORE int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
603
604 // Find the wxWindow at the given point. wxGenericFindWindowAtPoint
605 // is always present but may be less reliable than a native version.
606 WXDLLIMPEXP_CORE wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
607 WXDLLIMPEXP_CORE wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
608
609 // NB: this function is obsolete, use wxWindow::FindWindowByLabel() instead
610 //
611 // Find the window/widget with the given title or label.
612 // Pass a parent to begin the search from, or NULL to look through
613 // all windows.
614 WXDLLIMPEXP_CORE wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = NULL);
615
616 // NB: this function is obsolete, use wxWindow::FindWindowByName() instead
617 //
618 // Find window by name, and if that fails, by label.
619 WXDLLIMPEXP_CORE wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = NULL);
620
621 // ----------------------------------------------------------------------------
622 // Message/event queue helpers
623 // ----------------------------------------------------------------------------
624
625 // Yield to other apps/messages and disable user input
626 WXDLLIMPEXP_CORE bool wxSafeYield(wxWindow *win = NULL, bool onlyIfNeeded = false);
627
628 // Enable or disable input to all top level windows
629 WXDLLIMPEXP_CORE void wxEnableTopLevelWindows(bool enable = true);
630
631 // Check whether this window wants to process messages, e.g. Stop button
632 // in long calculations.
633 WXDLLIMPEXP_CORE bool wxCheckForInterrupt(wxWindow *wnd);
634
635 // Consume all events until no more left
636 WXDLLIMPEXP_CORE void wxFlushEvents();
637
638 // a class which disables all windows (except, may be, the given one) in its
639 // ctor and enables them back in its dtor
640 class WXDLLIMPEXP_CORE wxWindowDisabler
641 {
642 public:
643 // this ctor conditionally disables all windows: if the argument is false,
644 // it doesn't do anything
645 wxWindowDisabler(bool disable = true);
646
647 // ctor disables all windows except winToSkip
648 wxWindowDisabler(wxWindow *winToSkip);
649
650 // dtor enables back all windows disabled by the ctor
651 ~wxWindowDisabler();
652
653 private:
654 // disable all windows except the given one (used by both ctors)
655 void DoDisable(wxWindow *winToSkip = NULL);
656
657
658 wxWindowList *m_winDisabled;
659 bool m_disabled;
660
661 wxDECLARE_NO_COPY_CLASS(wxWindowDisabler);
662 };
663
664 // ----------------------------------------------------------------------------
665 // Cursors
666 // ----------------------------------------------------------------------------
667
668 // Set the cursor to the busy cursor for all windows
669 WXDLLIMPEXP_CORE void wxBeginBusyCursor(const wxCursor *cursor = wxHOURGLASS_CURSOR);
670
671 // Restore cursor to normal
672 WXDLLIMPEXP_CORE void wxEndBusyCursor();
673
674 // true if we're between the above two calls
675 WXDLLIMPEXP_CORE bool wxIsBusy();
676
677 // Convenience class so we can just create a wxBusyCursor object on the stack
678 class WXDLLIMPEXP_CORE wxBusyCursor
679 {
680 public:
681 wxBusyCursor(const wxCursor* cursor = wxHOURGLASS_CURSOR)
682 { wxBeginBusyCursor(cursor); }
683 ~wxBusyCursor()
684 { wxEndBusyCursor(); }
685
686 // FIXME: These two methods are currently only implemented (and needed?)
687 // in wxGTK. BusyCursor handling should probably be moved to
688 // common code since the wxGTK and wxMSW implementations are very
689 // similar except for wxMSW using HCURSOR directly instead of
690 // wxCursor.. -- RL.
691 static const wxCursor &GetStoredCursor();
692 static const wxCursor GetBusyCursor();
693 };
694
695 void WXDLLIMPEXP_CORE wxGetMousePosition( int* x, int* y );
696
697 // ----------------------------------------------------------------------------
698 // X11 Display access
699 // ----------------------------------------------------------------------------
700
701 #if defined(__X__) || defined(__WXGTK__)
702
703 #ifdef __WXGTK__
704 WXDLLIMPEXP_CORE void *wxGetDisplay();
705 #endif
706
707 #ifdef __X__
708 WXDLLIMPEXP_CORE WXDisplay *wxGetDisplay();
709 WXDLLIMPEXP_CORE bool wxSetDisplay(const wxString& display_name);
710 WXDLLIMPEXP_CORE wxString wxGetDisplayName();
711 #endif // X or GTK+
712
713 // use this function instead of the functions above in implementation code
714 inline struct _XDisplay *wxGetX11Display()
715 {
716 return (_XDisplay *)wxGetDisplay();
717 }
718
719 #endif // X11 || wxGTK
720
721 #endif // wxUSE_GUI
722
723 // ----------------------------------------------------------------------------
724 // wxYield(): these functions are obsolete, please use wxApp methods instead!
725 // ----------------------------------------------------------------------------
726
727 // avoid redeclaring this function here if it had been already declated by
728 // wx/app.h, this results in warnings from g++ with -Wredundant-decls
729 #ifndef wx_YIELD_DECLARED
730 #define wx_YIELD_DECLARED
731
732 // Yield to other apps/messages
733 WXDLLIMPEXP_CORE bool wxYield();
734
735 #endif // wx_YIELD_DECLARED
736
737 // Like wxYield, but fails silently if the yield is recursive.
738 WXDLLIMPEXP_CORE bool wxYieldIfNeeded();
739
740 // ----------------------------------------------------------------------------
741 // Windows resources access
742 // ----------------------------------------------------------------------------
743
744 // MSW only: get user-defined resource from the .res file.
745 #ifdef __WXMSW__
746 // default resource type for wxLoadUserResource()
747 extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxUserResourceStr;
748
749 // Return the pointer to the resource data. This pointer is read-only, use
750 // the overload below if you need to modify the data.
751 //
752 // Returns true on success, false on failure. Doesn't log an error message
753 // if the resource is not found (because this could be expected) but does
754 // log one if any other error occurs.
755 WXDLLIMPEXP_BASE bool
756 wxLoadUserResource(const void **outData,
757 size_t *outLen,
758 const wxString& resourceName,
759 const wxString& resourceType = wxUserResourceStr,
760 WXHINSTANCE module = 0);
761
762 // This function allocates a new buffer and makes a copy of the resource
763 // data, remember to delete[] the buffer. And avoid using it entirely if
764 // the overload above can be used.
765 //
766 // Returns NULL on failure.
767 WXDLLIMPEXP_BASE char*
768 wxLoadUserResource(const wxString& resourceName,
769 const wxString& resourceType = wxUserResourceStr,
770 int* pLen = NULL,
771 WXHINSTANCE module = 0);
772 #endif // MSW
773
774 #endif
775 // _WX_UTILSH__