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