1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Miscellaneous utilities
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/object.h"
21 #include "wx/filefn.h"
22 #include "wx/hashmap.h"
23 #include "wx/versioninfo.h"
24 #include "wx/meta/implicitconversion.h"
27 #include "wx/gdicmn.h"
28 #include "wx/mousestate.h"
31 class WXDLLIMPEXP_FWD_BASE wxArrayString
;
32 class WXDLLIMPEXP_FWD_BASE wxArrayInt
;
34 // need this for wxGetDiskSpace() as we can't, unfortunately, forward declare
36 #include "wx/longlong.h"
38 // needed for wxOperatingSystemId, wxLinuxDistributionInfo
39 #include "wx/platinfo.h"
50 // ----------------------------------------------------------------------------
51 // Forward declaration
52 // ----------------------------------------------------------------------------
54 class WXDLLIMPEXP_FWD_BASE wxProcess
;
55 class WXDLLIMPEXP_FWD_CORE wxFrame
;
56 class WXDLLIMPEXP_FWD_CORE wxWindow
;
57 class WXDLLIMPEXP_FWD_CORE wxWindowList
;
58 class WXDLLIMPEXP_FWD_CORE wxEventLoop
;
60 // ----------------------------------------------------------------------------
61 // Arithmetic functions
62 // ----------------------------------------------------------------------------
64 template<typename T1
, typename T2
>
65 inline typename wxImplicitConversionType
<T1
,T2
>::value
68 typedef typename wxImplicitConversionType
<T1
,T2
>::value ResultType
;
70 // Cast both operands to the same type before comparing them to avoid
71 // warnings about signed/unsigned comparisons from some compilers:
72 return static_cast<ResultType
>(a
) > static_cast<ResultType
>(b
) ? a
: b
;
75 template<typename T1
, typename T2
>
76 inline typename wxImplicitConversionType
<T1
,T2
>::value
79 typedef typename wxImplicitConversionType
<T1
,T2
>::value ResultType
;
81 return static_cast<ResultType
>(a
) < static_cast<ResultType
>(b
) ? a
: b
;
84 template<typename T1
, typename T2
, typename T3
>
85 inline typename wxImplicitConversionType3
<T1
,T2
,T3
>::value
86 wxClip(T1 a
, T2 b
, T3 c
)
88 typedef typename wxImplicitConversionType3
<T1
,T2
,T3
>::value ResultType
;
90 if ( static_cast<ResultType
>(a
) < static_cast<ResultType
>(b
) )
93 if ( static_cast<ResultType
>(a
) > static_cast<ResultType
>(c
) )
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 // wxGetFreeMemory can return huge amount of memory on 32-bit platforms as well
104 // so to always use long long for its result type on all platforms which
107 typedef wxLongLong wxMemorySize
;
109 typedef long wxMemorySize
;
112 // ----------------------------------------------------------------------------
113 // String functions (deprecated, use wxString)
114 // ----------------------------------------------------------------------------
116 #ifdef WXWIN_COMPATIBILITY_2_8
117 // A shorter way of using strcmp
118 wxDEPRECATED_INLINE(inline bool wxStringEq(const char *s1
, const char *s2
),
119 return wxCRT_StrcmpA(s1
, s2
) == 0; )
122 wxDEPRECATED_INLINE(inline bool wxStringEq(const wchar_t *s1
, const wchar_t *s2
),
123 return wxCRT_StrcmpW(s1
, s2
) == 0; )
124 #endif // wxUSE_UNICODE
126 #endif // WXWIN_COMPATIBILITY_2_8
128 // ----------------------------------------------------------------------------
129 // Miscellaneous functions
130 // ----------------------------------------------------------------------------
133 #if !defined __EMX__ && \
134 (defined __WXMOTIF__ || defined __WXGTK__ || defined __WXX11__)
135 WXDLLIMPEXP_CORE
void wxBell();
137 WXDLLIMPEXP_BASE
void wxBell();
141 // Show wxWidgets information
142 WXDLLIMPEXP_CORE
void wxInfoMessageBox(wxWindow
* parent
);
143 #endif // wxUSE_MSGDLG
145 WXDLLIMPEXP_CORE wxVersionInfo
wxGetLibraryVersionInfo();
147 // Get OS description as a user-readable string
148 WXDLLIMPEXP_BASE wxString
wxGetOsDescription();
151 WXDLLIMPEXP_BASE wxOperatingSystemId
wxGetOsVersion(int *majorVsn
= NULL
,
152 int *minorVsn
= NULL
);
154 // Get platform endianness
155 WXDLLIMPEXP_BASE
bool wxIsPlatformLittleEndian();
157 // Get platform architecture
158 WXDLLIMPEXP_BASE
bool wxIsPlatform64Bit();
161 // Get linux-distro informations
162 WXDLLIMPEXP_BASE wxLinuxDistributionInfo
wxGetLinuxDistributionInfo();
165 // Return a string with the current date/time
166 WXDLLIMPEXP_BASE wxString
wxNow();
168 // Return path where wxWidgets is installed (mostly useful in Unices)
169 WXDLLIMPEXP_BASE
const wxChar
*wxGetInstallPrefix();
170 // Return path to wxWin data (/usr/share/wx/%{version}) (Unices)
171 WXDLLIMPEXP_BASE wxString
wxGetDataDir();
175 // Get the state of a key (true if pressed, false if not)
176 // This is generally most useful getting the state of
177 // the modifier or toggle keys.
178 WXDLLIMPEXP_CORE
bool wxGetKeyState(wxKeyCode key
);
180 // Don't synthesize KeyUp events holding down a key and producing
181 // KeyDown events with autorepeat. On by default and always on
183 WXDLLIMPEXP_CORE
bool wxSetDetectableAutoRepeat( bool flag
);
185 // Returns the current state of the mouse position, buttons and modifers
186 WXDLLIMPEXP_CORE wxMouseState
wxGetMouseState();
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
195 * Class to make it easier to specify platform-dependent values
198 * long val = wxPlatform::If(wxMac, 1).ElseIf(wxGTK, 2).ElseIf(stPDA, 5).Else(3);
199 * wxString strVal = wxPlatform::If(wxMac, wxT("Mac")).ElseIf(wxMSW, wxT("MSW")).Else(wxT("Other"));
201 * A custom platform symbol:
205 * wxPlatform::AddPlatform(stPDA);
208 * long windowStyle = wxCAPTION | (long) wxPlatform::IfNot(stPDA, wxRESIZE_BORDER);
212 class WXDLLIMPEXP_BASE wxPlatform
215 wxPlatform() { Init(); }
216 wxPlatform(const wxPlatform
& platform
) { Copy(platform
); }
217 void operator = (const wxPlatform
& platform
) { if (&platform
!= this) Copy(platform
); }
218 void Copy(const wxPlatform
& platform
);
220 // Specify an optional default value
221 wxPlatform(int defValue
) { Init(); m_longValue
= (long)defValue
; }
222 wxPlatform(long defValue
) { Init(); m_longValue
= defValue
; }
223 wxPlatform(const wxString
& defValue
) { Init(); m_stringValue
= defValue
; }
224 wxPlatform(double defValue
) { Init(); m_doubleValue
= defValue
; }
226 static wxPlatform
If(int platform
, long value
);
227 static wxPlatform
IfNot(int platform
, long value
);
228 wxPlatform
& ElseIf(int platform
, long value
);
229 wxPlatform
& ElseIfNot(int platform
, long value
);
230 wxPlatform
& Else(long value
);
232 static wxPlatform
If(int platform
, int value
) { return If(platform
, (long)value
); }
233 static wxPlatform
IfNot(int platform
, int value
) { return IfNot(platform
, (long)value
); }
234 wxPlatform
& ElseIf(int platform
, int value
) { return ElseIf(platform
, (long) value
); }
235 wxPlatform
& ElseIfNot(int platform
, int value
) { return ElseIfNot(platform
, (long) value
); }
236 wxPlatform
& Else(int value
) { return Else((long) value
); }
238 static wxPlatform
If(int platform
, double value
);
239 static wxPlatform
IfNot(int platform
, double value
);
240 wxPlatform
& ElseIf(int platform
, double value
);
241 wxPlatform
& ElseIfNot(int platform
, double value
);
242 wxPlatform
& Else(double value
);
244 static wxPlatform
If(int platform
, const wxString
& value
);
245 static wxPlatform
IfNot(int platform
, const wxString
& value
);
246 wxPlatform
& ElseIf(int platform
, const wxString
& value
);
247 wxPlatform
& ElseIfNot(int platform
, const wxString
& value
);
248 wxPlatform
& Else(const wxString
& value
);
250 long GetInteger() const { return m_longValue
; }
251 const wxString
& GetString() const { return m_stringValue
; }
252 double GetDouble() const { return m_doubleValue
; }
254 operator int() const { return (int) GetInteger(); }
255 operator long() const { return GetInteger(); }
256 operator double() const { return GetDouble(); }
257 operator const wxString
&() const { return GetString(); }
259 static void AddPlatform(int platform
);
260 static bool Is(int platform
);
261 static void ClearPlatforms();
265 void Init() { m_longValue
= 0; m_doubleValue
= 0.0; }
268 double m_doubleValue
;
269 wxString m_stringValue
;
270 static wxArrayInt
* sm_customPlatforms
;
273 /// Function for testing current platform
274 inline bool wxPlatformIs(int platform
) { return wxPlatform::Is(platform
); }
276 // ----------------------------------------------------------------------------
277 // Window ID management
278 // ----------------------------------------------------------------------------
280 // Ensure subsequent IDs don't clash with this one
281 WXDLLIMPEXP_BASE
void wxRegisterId(long id
);
283 // Return the current ID
284 WXDLLIMPEXP_BASE
long wxGetCurrentId();
286 // Generate a unique ID
287 WXDLLIMPEXP_BASE
long wxNewId();
289 // ----------------------------------------------------------------------------
290 // Various conversions
291 // ----------------------------------------------------------------------------
293 // Convert 2-digit hex number to decimal
294 WXDLLIMPEXP_BASE
int wxHexToDec(const wxString
& buf
);
296 // Convert 2-digit hex number to decimal
297 inline int wxHexToDec(const char* buf
)
299 int firstDigit
, secondDigit
;
302 firstDigit
= buf
[0] - 'A' + 10;
304 firstDigit
= buf
[0] - '0';
307 secondDigit
= buf
[1] - 'A' + 10;
309 secondDigit
= buf
[1] - '0';
311 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
315 // Convert decimal integer to 2-character hex string
316 WXDLLIMPEXP_BASE
void wxDecToHex(int dec
, wxChar
*buf
);
317 WXDLLIMPEXP_BASE
void wxDecToHex(int dec
, char* ch1
, char* ch2
);
318 WXDLLIMPEXP_BASE wxString
wxDecToHex(int dec
);
320 // ----------------------------------------------------------------------------
321 // Process management
322 // ----------------------------------------------------------------------------
324 // NB: for backwards compatibility reasons the values of wxEXEC_[A]SYNC *must*
325 // be 0 and 1, don't change!
329 // execute the process asynchronously
332 // execute it synchronously, i.e. wait until it finishes
335 // under Windows, don't hide the child even if it's IO is redirected (this
336 // is done by default)
339 // under Unix, if the process is the group leader then passing wxKILL_CHILDREN to wxKill
340 // kills all children as well as pid
341 wxEXEC_MAKE_GROUP_LEADER
= 4,
343 // by default synchronous execution disables all program windows to avoid
344 // that the user interacts with the program while the child process is
345 // running, you can use this flag to prevent this from happening
346 wxEXEC_NODISABLE
= 8,
348 // by default, the event loop is run while waiting for synchronous execution
349 // to complete and this flag can be used to simply block the main process
350 // until the child process finishes
351 wxEXEC_NOEVENTS
= 16,
353 // convenient synonym for flags given system()-like behaviour
354 wxEXEC_BLOCK
= wxEXEC_SYNC
| wxEXEC_NOEVENTS
357 // Map storing environment variables.
358 typedef wxStringToStringHashMap wxEnvVariableHashMap
;
360 // Used to pass additional parameters for child process to wxExecute(). Could
361 // be extended with other fields later.
364 wxString cwd
; // If empty, CWD is not changed.
365 wxEnvVariableHashMap env
; // If empty, environment is unchanged.
368 // Execute another program.
370 // If flags contain wxEXEC_SYNC, return -1 on failure and the exit code of the
371 // process if everything was ok. Otherwise (i.e. if wxEXEC_ASYNC), return 0 on
372 // failure and the PID of the launched process if ok.
373 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
374 int flags
= wxEXEC_ASYNC
,
375 wxProcess
*process
= NULL
,
376 const wxExecuteEnv
*env
= NULL
);
377 WXDLLIMPEXP_BASE
long wxExecute(char **argv
,
378 int flags
= wxEXEC_ASYNC
,
379 wxProcess
*process
= NULL
,
380 const wxExecuteEnv
*env
= NULL
);
382 WXDLLIMPEXP_BASE
long wxExecute(wchar_t **argv
,
383 int flags
= wxEXEC_ASYNC
,
384 wxProcess
*process
= NULL
,
385 const wxExecuteEnv
*env
= NULL
);
386 #endif // wxUSE_UNICODE
388 // execute the command capturing its output into an array line by line, this is
389 // always synchronous
390 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
391 wxArrayString
& output
,
393 const wxExecuteEnv
*env
= NULL
);
395 // also capture stderr (also synchronous)
396 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
397 wxArrayString
& output
,
398 wxArrayString
& error
,
400 const wxExecuteEnv
*env
= NULL
);
402 #if defined(__WXMSW__) && wxUSE_IPC
403 // ask a DDE server to execute the DDE request with given parameters
404 WXDLLIMPEXP_BASE
bool wxExecuteDDE(const wxString
& ddeServer
,
405 const wxString
& ddeTopic
,
406 const wxString
& ddeCommand
);
407 #endif // __WXMSW__ && wxUSE_IPC
411 wxSIGNONE
= 0, // verify if the process exists under Unix
418 wxSIGIOT
= wxSIGABRT
, // another name
429 // further signals are different in meaning between different Unix systems
434 wxKILL_OK
, // no error
435 wxKILL_BAD_SIGNAL
, // no such signal
436 wxKILL_ACCESS_DENIED
, // permission denied
437 wxKILL_NO_PROCESS
, // no such process
438 wxKILL_ERROR
// another, unspecified error
443 wxKILL_NOCHILDREN
= 0, // don't kill children
444 wxKILL_CHILDREN
= 1 // kill children
449 wxSHUTDOWN_FORCE
= 1,// can be combined with other flags (MSW-only)
450 wxSHUTDOWN_POWEROFF
= 2,// power off the computer
451 wxSHUTDOWN_REBOOT
= 4,// shutdown and reboot
452 wxSHUTDOWN_LOGOFF
= 8 // close session (currently MSW-only)
455 // Shutdown or reboot the PC
456 WXDLLIMPEXP_BASE
bool wxShutdown(int flags
= wxSHUTDOWN_POWEROFF
);
458 // send the given signal to the process (only NONE and KILL are supported under
459 // Windows, all others mean TERM), return 0 if ok and -1 on error
461 // return detailed error in rc if not NULL
462 WXDLLIMPEXP_BASE
int wxKill(long pid
,
463 wxSignal sig
= wxSIGTERM
,
464 wxKillError
*rc
= NULL
,
465 int flags
= wxKILL_NOCHILDREN
);
467 // Execute a command in an interactive shell window (always synchronously)
468 // If no command then just the shell
469 WXDLLIMPEXP_BASE
bool wxShell(const wxString
& command
= wxEmptyString
);
471 // As wxShell(), but must give a (non interactive) command and its output will
472 // be returned in output array
473 WXDLLIMPEXP_BASE
bool wxShell(const wxString
& command
, wxArrayString
& output
);
475 // Sleep for nSecs seconds
476 WXDLLIMPEXP_BASE
void wxSleep(int nSecs
);
478 // Sleep for a given amount of milliseconds
479 WXDLLIMPEXP_BASE
void wxMilliSleep(unsigned long milliseconds
);
481 // Sleep for a given amount of microseconds
482 WXDLLIMPEXP_BASE
void wxMicroSleep(unsigned long microseconds
);
484 #if WXWIN_COMPATIBILITY_2_8
485 // Sleep for a given amount of milliseconds (old, bad name), use wxMilliSleep
486 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxUsleep(unsigned long milliseconds
) );
489 // Get the process id of the current process
490 WXDLLIMPEXP_BASE
unsigned long wxGetProcessId();
492 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
493 WXDLLIMPEXP_BASE wxMemorySize
wxGetFreeMemory();
495 #if wxUSE_ON_FATAL_EXCEPTION
497 // should wxApp::OnFatalException() be called?
498 WXDLLIMPEXP_BASE
bool wxHandleFatalExceptions(bool doit
= true);
500 #endif // wxUSE_ON_FATAL_EXCEPTION
502 // ----------------------------------------------------------------------------
503 // Environment variables
504 // ----------------------------------------------------------------------------
506 // returns true if variable exists (value may be NULL if you just want to check
508 WXDLLIMPEXP_BASE
bool wxGetEnv(const wxString
& var
, wxString
*value
);
510 // set the env var name to the given value, return true on success
511 WXDLLIMPEXP_BASE
bool wxSetEnv(const wxString
& var
, const wxString
& value
);
513 // remove the env var from environment
514 WXDLLIMPEXP_BASE
bool wxUnsetEnv(const wxString
& var
);
516 #if WXWIN_COMPATIBILITY_2_8
517 inline bool wxSetEnv(const wxString
& var
, const char *value
)
518 { return wxSetEnv(var
, wxString(value
)); }
519 inline bool wxSetEnv(const wxString
& var
, const wchar_t *value
)
520 { return wxSetEnv(var
, wxString(value
)); }
522 inline bool wxSetEnv(const wxString
& var
, const wxScopedCharTypeBuffer
<T
>& value
)
523 { return wxSetEnv(var
, wxString(value
)); }
524 inline bool wxSetEnv(const wxString
& var
, const wxCStrData
& value
)
525 { return wxSetEnv(var
, wxString(value
)); }
527 // this one is for passing NULL directly - don't use it, use wxUnsetEnv instead
528 wxDEPRECATED( inline bool wxSetEnv(const wxString
& var
, int value
) );
529 inline bool wxSetEnv(const wxString
& var
, int value
)
531 wxASSERT_MSG( value
== 0, "using non-NULL integer as string?" );
533 wxUnusedVar(value
); // fix unused parameter warning in release build
535 return wxUnsetEnv(var
);
537 #endif // WXWIN_COMPATIBILITY_2_8
539 // Retrieve the complete environment by filling specified map.
540 // Returns true on success or false if an error occurred.
541 WXDLLIMPEXP_BASE
bool wxGetEnvMap(wxEnvVariableHashMap
*map
);
543 // ----------------------------------------------------------------------------
544 // Network and username functions.
545 // ----------------------------------------------------------------------------
547 // NB: "char *" functions are deprecated, use wxString ones!
550 WXDLLIMPEXP_BASE
bool wxGetEmailAddress(wxChar
*buf
, int maxSize
);
551 WXDLLIMPEXP_BASE wxString
wxGetEmailAddress();
554 WXDLLIMPEXP_BASE
bool wxGetHostName(wxChar
*buf
, int maxSize
);
555 WXDLLIMPEXP_BASE wxString
wxGetHostName();
558 WXDLLIMPEXP_BASE wxString
wxGetFullHostName();
559 WXDLLIMPEXP_BASE
bool wxGetFullHostName(wxChar
*buf
, int maxSize
);
561 // Get user ID e.g. jacs (this is known as login name under Unix)
562 WXDLLIMPEXP_BASE
bool wxGetUserId(wxChar
*buf
, int maxSize
);
563 WXDLLIMPEXP_BASE wxString
wxGetUserId();
565 // Get user name e.g. Julian Smart
566 WXDLLIMPEXP_BASE
bool wxGetUserName(wxChar
*buf
, int maxSize
);
567 WXDLLIMPEXP_BASE wxString
wxGetUserName();
569 // Get current Home dir and copy to dest (returns pstr->c_str())
570 WXDLLIMPEXP_BASE wxString
wxGetHomeDir();
571 WXDLLIMPEXP_BASE
const wxChar
* wxGetHomeDir(wxString
*pstr
);
573 // Get the user's (by default use the current user name) home dir,
574 // return empty string on error
575 WXDLLIMPEXP_BASE wxString
wxGetUserHome(const wxString
& user
= wxEmptyString
);
579 typedef wxLongLong wxDiskspaceSize_t
;
581 typedef long wxDiskspaceSize_t
;
584 // get number of total/free bytes on the disk where path belongs
585 WXDLLIMPEXP_BASE
bool wxGetDiskSpace(const wxString
& path
,
586 wxDiskspaceSize_t
*pTotal
= NULL
,
587 wxDiskspaceSize_t
*pFree
= NULL
);
593 typedef int (wxCMPFUNC_CONV
*CMPFUNCDATA
)(const void* pItem1
, const void* pItem2
, const void* user_data
);
597 WXDLLIMPEXP_BASE
void wxQsort(void *const pbase
, size_t total_elems
,
598 size_t size
, CMPFUNCDATA cmp
, const void* user_data
);
601 #if wxUSE_GUI // GUI only things from now on
603 // ----------------------------------------------------------------------------
604 // Launch default browser
605 // ----------------------------------------------------------------------------
607 // flags for wxLaunchDefaultBrowser
610 wxBROWSER_NEW_WINDOW
= 0x01,
611 wxBROWSER_NOBUSYCURSOR
= 0x02
614 // Launch url in the user's default internet browser
615 WXDLLIMPEXP_CORE
bool wxLaunchDefaultBrowser(const wxString
& url
, int flags
= 0);
617 // Launch document in the user's default application
618 WXDLLIMPEXP_CORE
bool wxLaunchDefaultApplication(const wxString
& path
, int flags
= 0);
620 // ----------------------------------------------------------------------------
621 // Menu accelerators related things
622 // ----------------------------------------------------------------------------
624 // flags for wxStripMenuCodes
627 // strip '&' characters
628 wxStrip_Mnemonics
= 1,
630 // strip everything after '\t'
633 // strip everything (this is the default)
634 wxStrip_All
= wxStrip_Mnemonics
| wxStrip_Accel
637 // strip mnemonics and/or accelerators from the label
638 WXDLLIMPEXP_CORE wxString
639 wxStripMenuCodes(const wxString
& str
, int flags
= wxStrip_All
);
641 #if WXWIN_COMPATIBILITY_2_6
642 // obsolete and deprecated version, do not use, use the above overload instead
644 WXDLLIMPEXP_CORE wxChar
* wxStripMenuCodes(const wxChar
*in
, wxChar
*out
= NULL
)
648 class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry
;
650 // use wxAcceleratorEntry::Create() or FromString() methods instead
652 WXDLLIMPEXP_CORE wxAcceleratorEntry
*wxGetAccelFromString(const wxString
& label
)
654 #endif // wxUSE_ACCEL
656 #endif // WXWIN_COMPATIBILITY_2_6
658 // ----------------------------------------------------------------------------
660 // ----------------------------------------------------------------------------
662 // Returns menu item id or wxNOT_FOUND if none.
663 WXDLLIMPEXP_CORE
int wxFindMenuItemId(wxFrame
*frame
, const wxString
& menuString
, const wxString
& itemString
);
665 // Find the wxWindow at the given point. wxGenericFindWindowAtPoint
666 // is always present but may be less reliable than a native version.
667 WXDLLIMPEXP_CORE wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
);
668 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
);
670 // NB: this function is obsolete, use wxWindow::FindWindowByLabel() instead
672 // Find the window/widget with the given title or label.
673 // Pass a parent to begin the search from, or NULL to look through
675 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowByLabel(const wxString
& title
, wxWindow
*parent
= NULL
);
677 // NB: this function is obsolete, use wxWindow::FindWindowByName() instead
679 // Find window by name, and if that fails, by label.
680 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
*parent
= NULL
);
682 // ----------------------------------------------------------------------------
683 // Message/event queue helpers
684 // ----------------------------------------------------------------------------
686 // Yield to other apps/messages and disable user input
687 WXDLLIMPEXP_CORE
bool wxSafeYield(wxWindow
*win
= NULL
, bool onlyIfNeeded
= false);
689 // Enable or disable input to all top level windows
690 WXDLLIMPEXP_CORE
void wxEnableTopLevelWindows(bool enable
= true);
692 // Check whether this window wants to process messages, e.g. Stop button
693 // in long calculations.
694 WXDLLIMPEXP_CORE
bool wxCheckForInterrupt(wxWindow
*wnd
);
696 // Consume all events until no more left
697 WXDLLIMPEXP_CORE
void wxFlushEvents();
699 // a class which disables all windows (except, may be, the given one) in its
700 // ctor and enables them back in its dtor
701 class WXDLLIMPEXP_CORE wxWindowDisabler
704 // this ctor conditionally disables all windows: if the argument is false,
705 // it doesn't do anything
706 wxWindowDisabler(bool disable
= true);
708 // ctor disables all windows except winToSkip
709 wxWindowDisabler(wxWindow
*winToSkip
);
711 // dtor enables back all windows disabled by the ctor
715 // disable all windows except the given one (used by both ctors)
716 void DoDisable(wxWindow
*winToSkip
= NULL
);
718 #if defined(__WXOSX__) && wxOSX_USE_COCOA
719 wxEventLoop
* m_modalEventLoop
;
721 wxWindowList
*m_winDisabled
;
724 wxDECLARE_NO_COPY_CLASS(wxWindowDisabler
);
727 // ----------------------------------------------------------------------------
729 // ----------------------------------------------------------------------------
731 // Set the cursor to the busy cursor for all windows
732 WXDLLIMPEXP_CORE
void wxBeginBusyCursor(const wxCursor
*cursor
= wxHOURGLASS_CURSOR
);
734 // Restore cursor to normal
735 WXDLLIMPEXP_CORE
void wxEndBusyCursor();
737 // true if we're between the above two calls
738 WXDLLIMPEXP_CORE
bool wxIsBusy();
740 // Convenience class so we can just create a wxBusyCursor object on the stack
741 class WXDLLIMPEXP_CORE wxBusyCursor
744 wxBusyCursor(const wxCursor
* cursor
= wxHOURGLASS_CURSOR
)
745 { wxBeginBusyCursor(cursor
); }
747 { wxEndBusyCursor(); }
749 // FIXME: These two methods are currently only implemented (and needed?)
750 // in wxGTK. BusyCursor handling should probably be moved to
751 // common code since the wxGTK and wxMSW implementations are very
752 // similar except for wxMSW using HCURSOR directly instead of
754 static const wxCursor
&GetStoredCursor();
755 static const wxCursor
GetBusyCursor();
758 void WXDLLIMPEXP_CORE
wxGetMousePosition( int* x
, int* y
);
760 // ----------------------------------------------------------------------------
761 // X11 Display access
762 // ----------------------------------------------------------------------------
764 #if defined(__X__) || defined(__WXGTK__)
767 WXDLLIMPEXP_CORE
void *wxGetDisplay();
771 WXDLLIMPEXP_CORE WXDisplay
*wxGetDisplay();
772 WXDLLIMPEXP_CORE
bool wxSetDisplay(const wxString
& display_name
);
773 WXDLLIMPEXP_CORE wxString
wxGetDisplayName();
776 // use this function instead of the functions above in implementation code
777 inline struct _XDisplay
*wxGetX11Display()
779 return (_XDisplay
*)wxGetDisplay();
782 #endif // X11 || wxGTK
786 // ----------------------------------------------------------------------------
787 // wxYield(): these functions are obsolete, please use wxApp methods instead!
788 // ----------------------------------------------------------------------------
790 // avoid redeclaring this function here if it had been already declated by
791 // wx/app.h, this results in warnings from g++ with -Wredundant-decls
792 #ifndef wx_YIELD_DECLARED
793 #define wx_YIELD_DECLARED
795 // Yield to other apps/messages
796 WXDLLIMPEXP_CORE
bool wxYield();
798 #endif // wx_YIELD_DECLARED
800 // Like wxYield, but fails silently if the yield is recursive.
801 WXDLLIMPEXP_CORE
bool wxYieldIfNeeded();
803 // ----------------------------------------------------------------------------
804 // Windows resources access
805 // ----------------------------------------------------------------------------
807 // MSW only: get user-defined resource from the .res file.
809 // default resource type for wxLoadUserResource()
810 extern WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxUserResourceStr
;
812 // Return the pointer to the resource data. This pointer is read-only, use
813 // the overload below if you need to modify the data.
815 // Returns true on success, false on failure. Doesn't log an error message
816 // if the resource is not found (because this could be expected) but does
817 // log one if any other error occurs.
818 WXDLLIMPEXP_BASE
bool
819 wxLoadUserResource(const void **outData
,
821 const wxString
& resourceName
,
822 const wxString
& resourceType
= wxUserResourceStr
,
823 WXHINSTANCE
module = 0);
825 // This function allocates a new buffer and makes a copy of the resource
826 // data, remember to delete[] the buffer. And avoid using it entirely if
827 // the overload above can be used.
829 // Returns NULL on failure.
830 WXDLLIMPEXP_BASE
char*
831 wxLoadUserResource(const wxString
& resourceName
,
832 const wxString
& resourceType
= wxUserResourceStr
,
834 WXHINSTANCE
module = 0);