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