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/meta/implicitconversion.h"
26 #include "wx/gdicmn.h"
27 #include "wx/mousestate.h"
30 class WXDLLIMPEXP_FWD_BASE wxArrayString
;
31 class WXDLLIMPEXP_FWD_BASE wxArrayInt
;
33 // need this for wxGetDiskSpace() as we can't, unfortunately, forward declare
35 #include "wx/longlong.h"
37 // needed for wxOperatingSystemId, wxLinuxDistributionInfo
38 #include "wx/platinfo.h"
49 // ----------------------------------------------------------------------------
50 // Forward declaration
51 // ----------------------------------------------------------------------------
53 class WXDLLIMPEXP_FWD_BASE wxProcess
;
54 class WXDLLIMPEXP_FWD_CORE wxFrame
;
55 class WXDLLIMPEXP_FWD_CORE wxWindow
;
56 class WXDLLIMPEXP_FWD_CORE wxWindowList
;
58 // ----------------------------------------------------------------------------
59 // Arithmetic functions
60 // ----------------------------------------------------------------------------
62 template<typename T1
, typename T2
>
63 inline typename wxImplicitConversionType
<T1
,T2
>::value
66 typedef typename wxImplicitConversionType
<T1
,T2
>::value ResultType
;
68 // Cast both operands to the same type before comparing them to avoid
69 // warnings about signed/unsigned comparisons from some compilers:
70 return static_cast<ResultType
>(a
) > static_cast<ResultType
>(b
) ? a
: b
;
73 template<typename T1
, typename T2
>
74 inline typename wxImplicitConversionType
<T1
,T2
>::value
77 typedef typename wxImplicitConversionType
<T1
,T2
>::value ResultType
;
79 return static_cast<ResultType
>(a
) < static_cast<ResultType
>(b
) ? a
: b
;
82 template<typename T1
, typename T2
, typename T3
>
83 inline typename wxImplicitConversionType3
<T1
,T2
,T3
>::value
84 wxClip(T1 a
, T2 b
, T3 c
)
86 typedef typename wxImplicitConversionType3
<T1
,T2
,T3
>::value ResultType
;
88 if ( static_cast<ResultType
>(a
) < static_cast<ResultType
>(b
) )
91 if ( static_cast<ResultType
>(a
) > static_cast<ResultType
>(c
) )
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // wxGetFreeMemory can return huge amount of memory on 32-bit platforms as well
102 // so to always use long long for its result type on all platforms which
105 typedef wxLongLong wxMemorySize
;
107 typedef long wxMemorySize
;
110 // ----------------------------------------------------------------------------
111 // String functions (deprecated, use wxString)
112 // ----------------------------------------------------------------------------
114 #ifdef WXWIN_COMPATIBILITY_2_8
115 // A shorter way of using strcmp
116 wxDEPRECATED_INLINE(inline bool wxStringEq(const char *s1
, const char *s2
),
117 return wxCRT_StrcmpA(s1
, s2
) == 0; )
120 wxDEPRECATED_INLINE(inline bool wxStringEq(const wchar_t *s1
, const wchar_t *s2
),
121 return wxCRT_StrcmpW(s1
, s2
) == 0; )
122 #endif // wxUSE_UNICODE
124 #endif // WXWIN_COMPATIBILITY_2_8
126 // ----------------------------------------------------------------------------
127 // Miscellaneous functions
128 // ----------------------------------------------------------------------------
131 #if !defined __EMX__ && \
132 (defined __WXMOTIF__ || defined __WXGTK__ || defined __WXX11__)
133 WXDLLIMPEXP_CORE
void wxBell();
135 WXDLLIMPEXP_BASE
void wxBell();
139 // Show wxWidgets information
140 WXDLLIMPEXP_CORE
void wxInfoMessageBox(wxWindow
* parent
);
141 #endif // wxUSE_MSGDLG
143 // Get OS description as a user-readable string
144 WXDLLIMPEXP_BASE wxString
wxGetOsDescription();
147 WXDLLIMPEXP_BASE wxOperatingSystemId
wxGetOsVersion(int *majorVsn
= NULL
,
148 int *minorVsn
= NULL
);
150 // Get platform endianness
151 WXDLLIMPEXP_BASE
bool wxIsPlatformLittleEndian();
153 // Get platform architecture
154 WXDLLIMPEXP_BASE
bool wxIsPlatform64Bit();
157 // Get linux-distro informations
158 WXDLLIMPEXP_BASE wxLinuxDistributionInfo
wxGetLinuxDistributionInfo();
161 // Return a string with the current date/time
162 WXDLLIMPEXP_BASE wxString
wxNow();
164 // Return path where wxWidgets is installed (mostly useful in Unices)
165 WXDLLIMPEXP_BASE
const wxChar
*wxGetInstallPrefix();
166 // Return path to wxWin data (/usr/share/wx/%{version}) (Unices)
167 WXDLLIMPEXP_BASE wxString
wxGetDataDir();
171 // Get the state of a key (true if pressed, false if not)
172 // This is generally most useful getting the state of
173 // the modifier or toggle keys.
174 WXDLLIMPEXP_CORE
bool wxGetKeyState(wxKeyCode key
);
176 // Don't synthesize KeyUp events holding down a key and producing
177 // KeyDown events with autorepeat. On by default and always on
179 WXDLLIMPEXP_CORE
bool wxSetDetectableAutoRepeat( bool flag
);
181 // Returns the current state of the mouse position, buttons and modifers
182 WXDLLIMPEXP_CORE wxMouseState
wxGetMouseState();
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
191 * Class to make it easier to specify platform-dependent values
194 * long val = wxPlatform::If(wxMac, 1).ElseIf(wxGTK, 2).ElseIf(stPDA, 5).Else(3);
195 * wxString strVal = wxPlatform::If(wxMac, wxT("Mac")).ElseIf(wxMSW, wxT("MSW")).Else(wxT("Other"));
197 * A custom platform symbol:
201 * wxPlatform::AddPlatform(stPDA);
204 * long windowStyle = wxCAPTION | (long) wxPlatform::IfNot(stPDA, wxRESIZE_BORDER);
208 class WXDLLIMPEXP_BASE wxPlatform
211 wxPlatform() { Init(); }
212 wxPlatform(const wxPlatform
& platform
) { Copy(platform
); }
213 void operator = (const wxPlatform
& platform
) { if (&platform
!= this) Copy(platform
); }
214 void Copy(const wxPlatform
& platform
);
216 // Specify an optional default value
217 wxPlatform(int defValue
) { Init(); m_longValue
= (long)defValue
; }
218 wxPlatform(long defValue
) { Init(); m_longValue
= defValue
; }
219 wxPlatform(const wxString
& defValue
) { Init(); m_stringValue
= defValue
; }
220 wxPlatform(double defValue
) { Init(); m_doubleValue
= defValue
; }
222 static wxPlatform
If(int platform
, long value
);
223 static wxPlatform
IfNot(int platform
, long value
);
224 wxPlatform
& ElseIf(int platform
, long value
);
225 wxPlatform
& ElseIfNot(int platform
, long value
);
226 wxPlatform
& Else(long value
);
228 static wxPlatform
If(int platform
, int value
) { return If(platform
, (long)value
); }
229 static wxPlatform
IfNot(int platform
, int value
) { return IfNot(platform
, (long)value
); }
230 wxPlatform
& ElseIf(int platform
, int value
) { return ElseIf(platform
, (long) value
); }
231 wxPlatform
& ElseIfNot(int platform
, int value
) { return ElseIfNot(platform
, (long) value
); }
232 wxPlatform
& Else(int value
) { return Else((long) value
); }
234 static wxPlatform
If(int platform
, double value
);
235 static wxPlatform
IfNot(int platform
, double value
);
236 wxPlatform
& ElseIf(int platform
, double value
);
237 wxPlatform
& ElseIfNot(int platform
, double value
);
238 wxPlatform
& Else(double value
);
240 static wxPlatform
If(int platform
, const wxString
& value
);
241 static wxPlatform
IfNot(int platform
, const wxString
& value
);
242 wxPlatform
& ElseIf(int platform
, const wxString
& value
);
243 wxPlatform
& ElseIfNot(int platform
, const wxString
& value
);
244 wxPlatform
& Else(const wxString
& value
);
246 long GetInteger() const { return m_longValue
; }
247 const wxString
& GetString() const { return m_stringValue
; }
248 double GetDouble() const { return m_doubleValue
; }
250 operator int() const { return (int) GetInteger(); }
251 operator long() const { return GetInteger(); }
252 operator double() const { return GetDouble(); }
253 operator const wxString
&() const { return GetString(); }
255 static void AddPlatform(int platform
);
256 static bool Is(int platform
);
257 static void ClearPlatforms();
261 void Init() { m_longValue
= 0; m_doubleValue
= 0.0; }
264 double m_doubleValue
;
265 wxString m_stringValue
;
266 static wxArrayInt
* sm_customPlatforms
;
269 /// Function for testing current platform
270 inline bool wxPlatformIs(int platform
) { return wxPlatform::Is(platform
); }
272 // ----------------------------------------------------------------------------
273 // Window ID management
274 // ----------------------------------------------------------------------------
276 // Ensure subsequent IDs don't clash with this one
277 WXDLLIMPEXP_BASE
void wxRegisterId(long id
);
279 // Return the current ID
280 WXDLLIMPEXP_BASE
long wxGetCurrentId();
282 // Generate a unique ID
283 WXDLLIMPEXP_BASE
long wxNewId();
285 // ----------------------------------------------------------------------------
286 // Various conversions
287 // ----------------------------------------------------------------------------
289 // Convert 2-digit hex number to decimal
290 WXDLLIMPEXP_BASE
int wxHexToDec(const wxString
& buf
);
292 // Convert 2-digit hex number to decimal
293 inline int wxHexToDec(const char* buf
)
295 int firstDigit
, secondDigit
;
298 firstDigit
= buf
[0] - 'A' + 10;
300 firstDigit
= buf
[0] - '0';
303 secondDigit
= buf
[1] - 'A' + 10;
305 secondDigit
= buf
[1] - '0';
307 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
311 // Convert decimal integer to 2-character hex string
312 WXDLLIMPEXP_BASE
void wxDecToHex(int dec
, wxChar
*buf
);
313 WXDLLIMPEXP_BASE
void wxDecToHex(int dec
, char* ch1
, char* ch2
);
314 WXDLLIMPEXP_BASE wxString
wxDecToHex(int dec
);
316 // ----------------------------------------------------------------------------
317 // Process management
318 // ----------------------------------------------------------------------------
320 // NB: for backwards compatibility reasons the values of wxEXEC_[A]SYNC *must*
321 // be 0 and 1, don't change!
325 // execute the process asynchronously
328 // execute it synchronously, i.e. wait until it finishes
331 // under Windows, don't hide the child even if it's IO is redirected (this
332 // is done by default)
335 // under Unix, if the process is the group leader then passing wxKILL_CHILDREN to wxKill
336 // kills all children as well as pid
337 wxEXEC_MAKE_GROUP_LEADER
= 4,
339 // by default synchronous execution disables all program windows to avoid
340 // that the user interacts with the program while the child process is
341 // running, you can use this flag to prevent this from happening
342 wxEXEC_NODISABLE
= 8,
344 // by default, the event loop is run while waiting for synchronous execution
345 // to complete and this flag can be used to simply block the main process
346 // until the child process finishes
347 wxEXEC_NOEVENTS
= 16,
349 // convenient synonym for flags given system()-like behaviour
350 wxEXEC_BLOCK
= wxEXEC_SYNC
| wxEXEC_NOEVENTS
353 // Map storing environment variables.
354 typedef wxStringToStringHashMap wxEnvVariableHashMap
;
356 // Used to pass additional parameters for child process to wxExecute(). Could
357 // be extended with other fields later.
360 wxString cwd
; // If empty, CWD is not changed.
361 wxEnvVariableHashMap env
; // If empty, environment is unchanged.
364 // Execute another program.
366 // If flags contain wxEXEC_SYNC, return -1 on failure and the exit code of the
367 // process if everything was ok. Otherwise (i.e. if wxEXEC_ASYNC), return 0 on
368 // failure and the PID of the launched process if ok.
369 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
370 int flags
= wxEXEC_ASYNC
,
371 wxProcess
*process
= NULL
,
372 const wxExecuteEnv
*env
= NULL
);
373 WXDLLIMPEXP_BASE
long wxExecute(char **argv
,
374 int flags
= wxEXEC_ASYNC
,
375 wxProcess
*process
= NULL
,
376 const wxExecuteEnv
*env
= NULL
);
378 WXDLLIMPEXP_BASE
long wxExecute(wchar_t **argv
,
379 int flags
= wxEXEC_ASYNC
,
380 wxProcess
*process
= NULL
,
381 const wxExecuteEnv
*env
= NULL
);
382 #endif // wxUSE_UNICODE
384 // execute the command capturing its output into an array line by line, this is
385 // always synchronous
386 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
387 wxArrayString
& output
,
389 const wxExecuteEnv
*env
= NULL
);
391 // also capture stderr (also synchronous)
392 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
393 wxArrayString
& output
,
394 wxArrayString
& error
,
396 const wxExecuteEnv
*env
= NULL
);
398 #if defined(__WXMSW__) && wxUSE_IPC
399 // ask a DDE server to execute the DDE request with given parameters
400 WXDLLIMPEXP_BASE
bool wxExecuteDDE(const wxString
& ddeServer
,
401 const wxString
& ddeTopic
,
402 const wxString
& ddeCommand
);
403 #endif // __WXMSW__ && wxUSE_IPC
407 wxSIGNONE
= 0, // verify if the process exists under Unix
414 wxSIGIOT
= wxSIGABRT
, // another name
425 // further signals are different in meaning between different Unix systems
430 wxKILL_OK
, // no error
431 wxKILL_BAD_SIGNAL
, // no such signal
432 wxKILL_ACCESS_DENIED
, // permission denied
433 wxKILL_NO_PROCESS
, // no such process
434 wxKILL_ERROR
// another, unspecified error
439 wxKILL_NOCHILDREN
= 0, // don't kill children
440 wxKILL_CHILDREN
= 1 // kill children
445 wxSHUTDOWN_FORCE
= 1,// can be combined with other flags (MSW-only)
446 wxSHUTDOWN_POWEROFF
= 2,// power off the computer
447 wxSHUTDOWN_REBOOT
= 4,// shutdown and reboot
448 wxSHUTDOWN_LOGOFF
= 8 // close session (currently MSW-only)
451 // Shutdown or reboot the PC
452 WXDLLIMPEXP_BASE
bool wxShutdown(int flags
= wxSHUTDOWN_POWEROFF
);
454 // send the given signal to the process (only NONE and KILL are supported under
455 // Windows, all others mean TERM), return 0 if ok and -1 on error
457 // return detailed error in rc if not NULL
458 WXDLLIMPEXP_BASE
int wxKill(long pid
,
459 wxSignal sig
= wxSIGTERM
,
460 wxKillError
*rc
= NULL
,
461 int flags
= wxKILL_NOCHILDREN
);
463 // Execute a command in an interactive shell window (always synchronously)
464 // If no command then just the shell
465 WXDLLIMPEXP_BASE
bool wxShell(const wxString
& command
= wxEmptyString
);
467 // As wxShell(), but must give a (non interactive) command and its output will
468 // be returned in output array
469 WXDLLIMPEXP_BASE
bool wxShell(const wxString
& command
, wxArrayString
& output
);
471 // Sleep for nSecs seconds
472 WXDLLIMPEXP_BASE
void wxSleep(int nSecs
);
474 // Sleep for a given amount of milliseconds
475 WXDLLIMPEXP_BASE
void wxMilliSleep(unsigned long milliseconds
);
477 // Sleep for a given amount of microseconds
478 WXDLLIMPEXP_BASE
void wxMicroSleep(unsigned long microseconds
);
480 #if WXWIN_COMPATIBILITY_2_8
481 // Sleep for a given amount of milliseconds (old, bad name), use wxMilliSleep
482 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxUsleep(unsigned long milliseconds
) );
485 // Get the process id of the current process
486 WXDLLIMPEXP_BASE
unsigned long wxGetProcessId();
488 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
489 WXDLLIMPEXP_BASE wxMemorySize
wxGetFreeMemory();
491 #if wxUSE_ON_FATAL_EXCEPTION
493 // should wxApp::OnFatalException() be called?
494 WXDLLIMPEXP_BASE
bool wxHandleFatalExceptions(bool doit
= true);
496 #endif // wxUSE_ON_FATAL_EXCEPTION
498 // ----------------------------------------------------------------------------
499 // Environment variables
500 // ----------------------------------------------------------------------------
502 // returns true if variable exists (value may be NULL if you just want to check
504 WXDLLIMPEXP_BASE
bool wxGetEnv(const wxString
& var
, wxString
*value
);
506 // set the env var name to the given value, return true on success
507 WXDLLIMPEXP_BASE
bool wxSetEnv(const wxString
& var
, const wxString
& value
);
509 // remove the env var from environment
510 WXDLLIMPEXP_BASE
bool wxUnsetEnv(const wxString
& var
);
512 #if WXWIN_COMPATIBILITY_2_8
513 inline bool wxSetEnv(const wxString
& var
, const char *value
)
514 { return wxSetEnv(var
, wxString(value
)); }
515 inline bool wxSetEnv(const wxString
& var
, const wchar_t *value
)
516 { return wxSetEnv(var
, wxString(value
)); }
518 inline bool wxSetEnv(const wxString
& var
, const wxScopedCharTypeBuffer
<T
>& value
)
519 { return wxSetEnv(var
, wxString(value
)); }
520 inline bool wxSetEnv(const wxString
& var
, const wxCStrData
& value
)
521 { return wxSetEnv(var
, wxString(value
)); }
523 // this one is for passing NULL directly - don't use it, use wxUnsetEnv instead
524 wxDEPRECATED( inline bool wxSetEnv(const wxString
& var
, int value
) );
525 inline bool wxSetEnv(const wxString
& var
, int value
)
527 wxASSERT_MSG( value
== 0, "using non-NULL integer as string?" );
529 wxUnusedVar(value
); // fix unused parameter warning in release build
531 return wxUnsetEnv(var
);
533 #endif // WXWIN_COMPATIBILITY_2_8
535 // Retrieve the complete environment by filling specified map.
536 // Returns true on success or false if an error occurred.
537 WXDLLIMPEXP_BASE
bool wxGetEnvMap(wxEnvVariableHashMap
*map
);
539 // ----------------------------------------------------------------------------
540 // Network and username functions.
541 // ----------------------------------------------------------------------------
543 // NB: "char *" functions are deprecated, use wxString ones!
546 WXDLLIMPEXP_BASE
bool wxGetEmailAddress(wxChar
*buf
, int maxSize
);
547 WXDLLIMPEXP_BASE wxString
wxGetEmailAddress();
550 WXDLLIMPEXP_BASE
bool wxGetHostName(wxChar
*buf
, int maxSize
);
551 WXDLLIMPEXP_BASE wxString
wxGetHostName();
554 WXDLLIMPEXP_BASE wxString
wxGetFullHostName();
555 WXDLLIMPEXP_BASE
bool wxGetFullHostName(wxChar
*buf
, int maxSize
);
557 // Get user ID e.g. jacs (this is known as login name under Unix)
558 WXDLLIMPEXP_BASE
bool wxGetUserId(wxChar
*buf
, int maxSize
);
559 WXDLLIMPEXP_BASE wxString
wxGetUserId();
561 // Get user name e.g. Julian Smart
562 WXDLLIMPEXP_BASE
bool wxGetUserName(wxChar
*buf
, int maxSize
);
563 WXDLLIMPEXP_BASE wxString
wxGetUserName();
565 // Get current Home dir and copy to dest (returns pstr->c_str())
566 WXDLLIMPEXP_BASE wxString
wxGetHomeDir();
567 WXDLLIMPEXP_BASE
const wxChar
* wxGetHomeDir(wxString
*pstr
);
569 // Get the user's (by default use the current user name) home dir,
570 // return empty string on error
571 WXDLLIMPEXP_BASE wxString
wxGetUserHome(const wxString
& user
= wxEmptyString
);
575 typedef wxLongLong wxDiskspaceSize_t
;
577 typedef long wxDiskspaceSize_t
;
580 // get number of total/free bytes on the disk where path belongs
581 WXDLLIMPEXP_BASE
bool wxGetDiskSpace(const wxString
& path
,
582 wxDiskspaceSize_t
*pTotal
= NULL
,
583 wxDiskspaceSize_t
*pFree
= NULL
);
589 typedef int (wxCMPFUNC_CONV
*CMPFUNCDATA
)(const void* pItem1
, const void* pItem2
, const void* user_data
);
593 WXDLLIMPEXP_BASE
void wxQsort(void *const pbase
, size_t total_elems
,
594 size_t size
, CMPFUNCDATA cmp
, const void* user_data
);
597 #if wxUSE_GUI // GUI only things from now on
599 // ----------------------------------------------------------------------------
600 // Launch default browser
601 // ----------------------------------------------------------------------------
603 // flags for wxLaunchDefaultBrowser
606 wxBROWSER_NEW_WINDOW
= 0x01,
607 wxBROWSER_NOBUSYCURSOR
= 0x02
610 // Launch url in the user's default internet browser
611 WXDLLIMPEXP_CORE
bool wxLaunchDefaultBrowser(const wxString
& url
, int flags
= 0);
613 // Launch document in the user's default application
614 WXDLLIMPEXP_CORE
bool wxLaunchDefaultApplication(const wxString
& path
, int flags
= 0);
616 // ----------------------------------------------------------------------------
617 // Menu accelerators related things
618 // ----------------------------------------------------------------------------
620 // flags for wxStripMenuCodes
623 // strip '&' characters
624 wxStrip_Mnemonics
= 1,
626 // strip everything after '\t'
629 // strip everything (this is the default)
630 wxStrip_All
= wxStrip_Mnemonics
| wxStrip_Accel
633 // strip mnemonics and/or accelerators from the label
634 WXDLLIMPEXP_CORE wxString
635 wxStripMenuCodes(const wxString
& str
, int flags
= wxStrip_All
);
637 #if WXWIN_COMPATIBILITY_2_6
638 // obsolete and deprecated version, do not use, use the above overload instead
640 WXDLLIMPEXP_CORE wxChar
* wxStripMenuCodes(const wxChar
*in
, wxChar
*out
= NULL
)
644 class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry
;
646 // use wxAcceleratorEntry::Create() or FromString() methods instead
648 WXDLLIMPEXP_CORE wxAcceleratorEntry
*wxGetAccelFromString(const wxString
& label
)
650 #endif // wxUSE_ACCEL
652 #endif // WXWIN_COMPATIBILITY_2_6
654 // ----------------------------------------------------------------------------
656 // ----------------------------------------------------------------------------
658 // Returns menu item id or wxNOT_FOUND if none.
659 WXDLLIMPEXP_CORE
int wxFindMenuItemId(wxFrame
*frame
, const wxString
& menuString
, const wxString
& itemString
);
661 // Find the wxWindow at the given point. wxGenericFindWindowAtPoint
662 // is always present but may be less reliable than a native version.
663 WXDLLIMPEXP_CORE wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
);
664 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
);
666 // NB: this function is obsolete, use wxWindow::FindWindowByLabel() instead
668 // Find the window/widget with the given title or label.
669 // Pass a parent to begin the search from, or NULL to look through
671 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowByLabel(const wxString
& title
, wxWindow
*parent
= NULL
);
673 // NB: this function is obsolete, use wxWindow::FindWindowByName() instead
675 // Find window by name, and if that fails, by label.
676 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
*parent
= NULL
);
678 // ----------------------------------------------------------------------------
679 // Message/event queue helpers
680 // ----------------------------------------------------------------------------
682 // Yield to other apps/messages and disable user input
683 WXDLLIMPEXP_CORE
bool wxSafeYield(wxWindow
*win
= NULL
, bool onlyIfNeeded
= false);
685 // Enable or disable input to all top level windows
686 WXDLLIMPEXP_CORE
void wxEnableTopLevelWindows(bool enable
= true);
688 // Check whether this window wants to process messages, e.g. Stop button
689 // in long calculations.
690 WXDLLIMPEXP_CORE
bool wxCheckForInterrupt(wxWindow
*wnd
);
692 // Consume all events until no more left
693 WXDLLIMPEXP_CORE
void wxFlushEvents();
695 // a class which disables all windows (except, may be, the given one) in its
696 // ctor and enables them back in its dtor
697 class WXDLLIMPEXP_CORE wxWindowDisabler
700 // this ctor conditionally disables all windows: if the argument is false,
701 // it doesn't do anything
702 wxWindowDisabler(bool disable
= true);
704 // ctor disables all windows except winToSkip
705 wxWindowDisabler(wxWindow
*winToSkip
);
707 // dtor enables back all windows disabled by the ctor
711 // disable all windows except the given one (used by both ctors)
712 void DoDisable(wxWindow
*winToSkip
= NULL
);
715 wxWindowList
*m_winDisabled
;
718 wxDECLARE_NO_COPY_CLASS(wxWindowDisabler
);
721 // ----------------------------------------------------------------------------
723 // ----------------------------------------------------------------------------
725 // Set the cursor to the busy cursor for all windows
726 WXDLLIMPEXP_CORE
void wxBeginBusyCursor(const wxCursor
*cursor
= wxHOURGLASS_CURSOR
);
728 // Restore cursor to normal
729 WXDLLIMPEXP_CORE
void wxEndBusyCursor();
731 // true if we're between the above two calls
732 WXDLLIMPEXP_CORE
bool wxIsBusy();
734 // Convenience class so we can just create a wxBusyCursor object on the stack
735 class WXDLLIMPEXP_CORE wxBusyCursor
738 wxBusyCursor(const wxCursor
* cursor
= wxHOURGLASS_CURSOR
)
739 { wxBeginBusyCursor(cursor
); }
741 { wxEndBusyCursor(); }
743 // FIXME: These two methods are currently only implemented (and needed?)
744 // in wxGTK. BusyCursor handling should probably be moved to
745 // common code since the wxGTK and wxMSW implementations are very
746 // similar except for wxMSW using HCURSOR directly instead of
748 static const wxCursor
&GetStoredCursor();
749 static const wxCursor
GetBusyCursor();
752 void WXDLLIMPEXP_CORE
wxGetMousePosition( int* x
, int* y
);
754 // ----------------------------------------------------------------------------
755 // X11 Display access
756 // ----------------------------------------------------------------------------
758 #if defined(__X__) || defined(__WXGTK__)
761 WXDLLIMPEXP_CORE
void *wxGetDisplay();
765 WXDLLIMPEXP_CORE WXDisplay
*wxGetDisplay();
766 WXDLLIMPEXP_CORE
bool wxSetDisplay(const wxString
& display_name
);
767 WXDLLIMPEXP_CORE wxString
wxGetDisplayName();
770 // use this function instead of the functions above in implementation code
771 inline struct _XDisplay
*wxGetX11Display()
773 return (_XDisplay
*)wxGetDisplay();
776 #endif // X11 || wxGTK
780 // ----------------------------------------------------------------------------
781 // wxYield(): these functions are obsolete, please use wxApp methods instead!
782 // ----------------------------------------------------------------------------
784 // avoid redeclaring this function here if it had been already declated by
785 // wx/app.h, this results in warnings from g++ with -Wredundant-decls
786 #ifndef wx_YIELD_DECLARED
787 #define wx_YIELD_DECLARED
789 // Yield to other apps/messages
790 WXDLLIMPEXP_CORE
bool wxYield();
792 #endif // wx_YIELD_DECLARED
794 // Like wxYield, but fails silently if the yield is recursive.
795 WXDLLIMPEXP_CORE
bool wxYieldIfNeeded();
797 // ----------------------------------------------------------------------------
798 // Windows resources access
799 // ----------------------------------------------------------------------------
801 // MSW only: get user-defined resource from the .res file.
803 // default resource type for wxLoadUserResource()
804 extern WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxUserResourceStr
;
806 // Return the pointer to the resource data. This pointer is read-only, use
807 // the overload below if you need to modify the data.
809 // Returns true on success, false on failure. Doesn't log an error message
810 // if the resource is not found (because this could be expected) but does
811 // log one if any other error occurs.
812 WXDLLIMPEXP_BASE
bool
813 wxLoadUserResource(const void **outData
,
815 const wxString
& resourceName
,
816 const wxString
& resourceType
= wxUserResourceStr
,
817 WXHINSTANCE
module = 0);
819 // This function allocates a new buffer and makes a copy of the resource
820 // data, remember to delete[] the buffer. And avoid using it entirely if
821 // the overload above can be used.
823 // Returns NULL on failure.
824 WXDLLIMPEXP_BASE
char*
825 wxLoadUserResource(const wxString
& resourceName
,
826 const wxString
& resourceType
= wxUserResourceStr
,
828 WXHINSTANCE
module = 0);