1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Miscellaneous utilities
4 // Author: Julian Smart
7 // Copyright: (c) 1998 Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 #include "wx/object.h"
20 #include "wx/filefn.h"
21 #include "wx/hashmap.h"
22 #include "wx/versioninfo.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
;
57 class WXDLLIMPEXP_FWD_CORE wxEventLoop
;
59 // ----------------------------------------------------------------------------
60 // Arithmetic functions
61 // ----------------------------------------------------------------------------
63 template<typename T1
, typename T2
>
64 inline typename wxImplicitConversionType
<T1
,T2
>::value
67 typedef typename wxImplicitConversionType
<T1
,T2
>::value ResultType
;
69 // Cast both operands to the same type before comparing them to avoid
70 // warnings about signed/unsigned comparisons from some compilers:
71 return static_cast<ResultType
>(a
) > static_cast<ResultType
>(b
) ? a
: b
;
74 template<typename T1
, typename T2
>
75 inline typename wxImplicitConversionType
<T1
,T2
>::value
78 typedef typename wxImplicitConversionType
<T1
,T2
>::value ResultType
;
80 return static_cast<ResultType
>(a
) < static_cast<ResultType
>(b
) ? a
: b
;
83 template<typename T1
, typename T2
, typename T3
>
84 inline typename wxImplicitConversionType3
<T1
,T2
,T3
>::value
85 wxClip(T1 a
, T2 b
, T3 c
)
87 typedef typename wxImplicitConversionType3
<T1
,T2
,T3
>::value ResultType
;
89 if ( static_cast<ResultType
>(a
) < static_cast<ResultType
>(b
) )
92 if ( static_cast<ResultType
>(a
) > static_cast<ResultType
>(c
) )
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 // wxGetFreeMemory can return huge amount of memory on 32-bit platforms as well
103 // so to always use long long for its result type on all platforms which
106 typedef wxLongLong wxMemorySize
;
108 typedef long wxMemorySize
;
111 // ----------------------------------------------------------------------------
112 // String functions (deprecated, use wxString)
113 // ----------------------------------------------------------------------------
115 #if WXWIN_COMPATIBILITY_2_8
116 // A shorter way of using strcmp
117 wxDEPRECATED_INLINE(inline bool wxStringEq(const char *s1
, const char *s2
),
118 return wxCRT_StrcmpA(s1
, s2
) == 0; )
121 wxDEPRECATED_INLINE(inline bool wxStringEq(const wchar_t *s1
, const wchar_t *s2
),
122 return wxCRT_StrcmpW(s1
, s2
) == 0; )
123 #endif // wxUSE_UNICODE
125 #endif // WXWIN_COMPATIBILITY_2_8
127 // ----------------------------------------------------------------------------
128 // Miscellaneous functions
129 // ----------------------------------------------------------------------------
132 WXDLLIMPEXP_CORE
void wxBell();
135 // Show wxWidgets information
136 WXDLLIMPEXP_CORE
void wxInfoMessageBox(wxWindow
* parent
);
137 #endif // wxUSE_MSGDLG
139 WXDLLIMPEXP_CORE wxVersionInfo
wxGetLibraryVersionInfo();
141 // Get OS description as a user-readable string
142 WXDLLIMPEXP_BASE wxString
wxGetOsDescription();
145 WXDLLIMPEXP_BASE wxOperatingSystemId
wxGetOsVersion(int *majorVsn
= NULL
,
146 int *minorVsn
= NULL
);
148 // Get platform endianness
149 WXDLLIMPEXP_BASE
bool wxIsPlatformLittleEndian();
151 // Get platform architecture
152 WXDLLIMPEXP_BASE
bool wxIsPlatform64Bit();
155 // Get linux-distro informations
156 WXDLLIMPEXP_BASE wxLinuxDistributionInfo
wxGetLinuxDistributionInfo();
159 // Return a string with the current date/time
160 WXDLLIMPEXP_BASE wxString
wxNow();
162 // Return path where wxWidgets is installed (mostly useful in Unices)
163 WXDLLIMPEXP_BASE
const wxChar
*wxGetInstallPrefix();
164 // Return path to wxWin data (/usr/share/wx/%{version}) (Unices)
165 WXDLLIMPEXP_BASE wxString
wxGetDataDir();
169 // Get the state of a key (true if pressed, false if not)
170 // This is generally most useful getting the state of
171 // the modifier or toggle keys.
172 WXDLLIMPEXP_CORE
bool wxGetKeyState(wxKeyCode key
);
174 // Don't synthesize KeyUp events holding down a key and producing
175 // KeyDown events with autorepeat. On by default and always on
177 WXDLLIMPEXP_CORE
bool wxSetDetectableAutoRepeat( bool flag
);
179 // Returns the current state of the mouse position, buttons and modifers
180 WXDLLIMPEXP_CORE wxMouseState
wxGetMouseState();
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
189 * Class to make it easier to specify platform-dependent values
192 * long val = wxPlatform::If(wxMac, 1).ElseIf(wxGTK, 2).ElseIf(stPDA, 5).Else(3);
193 * wxString strVal = wxPlatform::If(wxMac, wxT("Mac")).ElseIf(wxMSW, wxT("MSW")).Else(wxT("Other"));
195 * A custom platform symbol:
199 * wxPlatform::AddPlatform(stPDA);
202 * long windowStyle = wxCAPTION | (long) wxPlatform::IfNot(stPDA, wxRESIZE_BORDER);
206 class WXDLLIMPEXP_BASE wxPlatform
209 wxPlatform() { Init(); }
210 wxPlatform(const wxPlatform
& platform
) { Copy(platform
); }
211 void operator = (const wxPlatform
& platform
) { if (&platform
!= this) Copy(platform
); }
212 void Copy(const wxPlatform
& platform
);
214 // Specify an optional default value
215 wxPlatform(int defValue
) { Init(); m_longValue
= (long)defValue
; }
216 wxPlatform(long defValue
) { Init(); m_longValue
= defValue
; }
217 wxPlatform(const wxString
& defValue
) { Init(); m_stringValue
= defValue
; }
218 wxPlatform(double defValue
) { Init(); m_doubleValue
= defValue
; }
220 static wxPlatform
If(int platform
, long value
);
221 static wxPlatform
IfNot(int platform
, long value
);
222 wxPlatform
& ElseIf(int platform
, long value
);
223 wxPlatform
& ElseIfNot(int platform
, long value
);
224 wxPlatform
& Else(long value
);
226 static wxPlatform
If(int platform
, int value
) { return If(platform
, (long)value
); }
227 static wxPlatform
IfNot(int platform
, int value
) { return IfNot(platform
, (long)value
); }
228 wxPlatform
& ElseIf(int platform
, int value
) { return ElseIf(platform
, (long) value
); }
229 wxPlatform
& ElseIfNot(int platform
, int value
) { return ElseIfNot(platform
, (long) value
); }
230 wxPlatform
& Else(int value
) { return Else((long) value
); }
232 static wxPlatform
If(int platform
, double value
);
233 static wxPlatform
IfNot(int platform
, double value
);
234 wxPlatform
& ElseIf(int platform
, double value
);
235 wxPlatform
& ElseIfNot(int platform
, double value
);
236 wxPlatform
& Else(double value
);
238 static wxPlatform
If(int platform
, const wxString
& value
);
239 static wxPlatform
IfNot(int platform
, const wxString
& value
);
240 wxPlatform
& ElseIf(int platform
, const wxString
& value
);
241 wxPlatform
& ElseIfNot(int platform
, const wxString
& value
);
242 wxPlatform
& Else(const wxString
& value
);
244 long GetInteger() const { return m_longValue
; }
245 const wxString
& GetString() const { return m_stringValue
; }
246 double GetDouble() const { return m_doubleValue
; }
248 operator int() const { return (int) GetInteger(); }
249 operator long() const { return GetInteger(); }
250 operator double() const { return GetDouble(); }
251 operator const wxString
&() const { return GetString(); }
253 static void AddPlatform(int platform
);
254 static bool Is(int platform
);
255 static void ClearPlatforms();
259 void Init() { m_longValue
= 0; m_doubleValue
= 0.0; }
262 double m_doubleValue
;
263 wxString m_stringValue
;
264 static wxArrayInt
* sm_customPlatforms
;
267 /// Function for testing current platform
268 inline bool wxPlatformIs(int platform
) { return wxPlatform::Is(platform
); }
270 // ----------------------------------------------------------------------------
271 // Window ID management
272 // ----------------------------------------------------------------------------
274 // Ensure subsequent IDs don't clash with this one
275 WXDLLIMPEXP_BASE
void wxRegisterId(int id
);
277 // Return the current ID
278 WXDLLIMPEXP_BASE
int wxGetCurrentId();
280 // Generate a unique ID
281 WXDLLIMPEXP_BASE
int wxNewId();
283 // ----------------------------------------------------------------------------
284 // Various conversions
285 // ----------------------------------------------------------------------------
287 // Convert 2-digit hex number to decimal
288 WXDLLIMPEXP_BASE
int wxHexToDec(const wxString
& buf
);
290 // Convert 2-digit hex number to decimal
291 inline int wxHexToDec(const char* buf
)
293 int firstDigit
, secondDigit
;
296 firstDigit
= buf
[0] - 'A' + 10;
298 firstDigit
= buf
[0] - '0';
301 secondDigit
= buf
[1] - 'A' + 10;
303 secondDigit
= buf
[1] - '0';
305 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
309 // Convert decimal integer to 2-character hex string
310 WXDLLIMPEXP_BASE
void wxDecToHex(int dec
, wxChar
*buf
);
311 WXDLLIMPEXP_BASE
void wxDecToHex(int dec
, char* ch1
, char* ch2
);
312 WXDLLIMPEXP_BASE wxString
wxDecToHex(int dec
);
314 // ----------------------------------------------------------------------------
315 // Process management
316 // ----------------------------------------------------------------------------
318 // NB: for backwards compatibility reasons the values of wxEXEC_[A]SYNC *must*
319 // be 0 and 1, don't change!
323 // execute the process asynchronously
326 // execute it synchronously, i.e. wait until it finishes
329 // under Windows, don't hide the child even if it's IO is redirected (this
330 // is done by default)
331 wxEXEC_SHOW_CONSOLE
= 2,
333 // deprecated synonym for wxEXEC_SHOW_CONSOLE, use the new name as it's
335 wxEXEC_NOHIDE
= wxEXEC_SHOW_CONSOLE
,
337 // under Unix, if the process is the group leader then passing wxKILL_CHILDREN to wxKill
338 // kills all children as well as pid
339 // under Windows (NT family only), sets the CREATE_NEW_PROCESS_GROUP flag,
340 // which allows to target Ctrl-Break signal to the spawned process.
341 // applies to console processes only.
342 wxEXEC_MAKE_GROUP_LEADER
= 4,
344 // by default synchronous execution disables all program windows to avoid
345 // that the user interacts with the program while the child process is
346 // running, you can use this flag to prevent this from happening
347 wxEXEC_NODISABLE
= 8,
349 // by default, the event loop is run while waiting for synchronous execution
350 // to complete and this flag can be used to simply block the main process
351 // until the child process finishes
352 wxEXEC_NOEVENTS
= 16,
354 // under Windows, hide the console of the child process if it has one, even
355 // if its IO is not redirected
356 wxEXEC_HIDE_CONSOLE
= 32,
358 // convenient synonym for flags given system()-like behaviour
359 wxEXEC_BLOCK
= wxEXEC_SYNC
| wxEXEC_NOEVENTS
362 // Map storing environment variables.
363 typedef wxStringToStringHashMap wxEnvVariableHashMap
;
365 // Used to pass additional parameters for child process to wxExecute(). Could
366 // be extended with other fields later.
369 wxString cwd
; // If empty, CWD is not changed.
370 wxEnvVariableHashMap env
; // If empty, environment is unchanged.
373 // Execute another program.
375 // If flags contain wxEXEC_SYNC, return -1 on failure and the exit code of the
376 // process if everything was ok. Otherwise (i.e. if wxEXEC_ASYNC), return 0 on
377 // failure and the PID of the launched process if ok.
378 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
379 int flags
= wxEXEC_ASYNC
,
380 wxProcess
*process
= NULL
,
381 const wxExecuteEnv
*env
= NULL
);
382 WXDLLIMPEXP_BASE
long wxExecute(char **argv
,
383 int flags
= wxEXEC_ASYNC
,
384 wxProcess
*process
= NULL
,
385 const wxExecuteEnv
*env
= NULL
);
387 WXDLLIMPEXP_BASE
long wxExecute(wchar_t **argv
,
388 int flags
= wxEXEC_ASYNC
,
389 wxProcess
*process
= NULL
,
390 const wxExecuteEnv
*env
= NULL
);
391 #endif // wxUSE_UNICODE
393 // execute the command capturing its output into an array line by line, this is
394 // always synchronous
395 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
396 wxArrayString
& output
,
398 const wxExecuteEnv
*env
= NULL
);
400 // also capture stderr (also synchronous)
401 WXDLLIMPEXP_BASE
long wxExecute(const wxString
& command
,
402 wxArrayString
& output
,
403 wxArrayString
& error
,
405 const wxExecuteEnv
*env
= NULL
);
407 #if defined(__WINDOWS__) && wxUSE_IPC
408 // ask a DDE server to execute the DDE request with given parameters
409 WXDLLIMPEXP_BASE
bool wxExecuteDDE(const wxString
& ddeServer
,
410 const wxString
& ddeTopic
,
411 const wxString
& ddeCommand
);
412 #endif // __WINDOWS__ && wxUSE_IPC
416 wxSIGNONE
= 0, // verify if the process exists under Unix
423 wxSIGIOT
= wxSIGABRT
, // another name
434 // further signals are different in meaning between different Unix systems
439 wxKILL_OK
, // no error
440 wxKILL_BAD_SIGNAL
, // no such signal
441 wxKILL_ACCESS_DENIED
, // permission denied
442 wxKILL_NO_PROCESS
, // no such process
443 wxKILL_ERROR
// another, unspecified error
448 wxKILL_NOCHILDREN
= 0, // don't kill children
449 wxKILL_CHILDREN
= 1 // kill children
454 wxSHUTDOWN_FORCE
= 1,// can be combined with other flags (MSW-only)
455 wxSHUTDOWN_POWEROFF
= 2,// power off the computer
456 wxSHUTDOWN_REBOOT
= 4,// shutdown and reboot
457 wxSHUTDOWN_LOGOFF
= 8 // close session (currently MSW-only)
460 // Shutdown or reboot the PC
461 WXDLLIMPEXP_BASE
bool wxShutdown(int flags
= wxSHUTDOWN_POWEROFF
);
463 // send the given signal to the process (only NONE and KILL are supported under
464 // Windows, all others mean TERM), return 0 if ok and -1 on error
466 // return detailed error in rc if not NULL
467 WXDLLIMPEXP_BASE
int wxKill(long pid
,
468 wxSignal sig
= wxSIGTERM
,
469 wxKillError
*rc
= NULL
,
470 int flags
= wxKILL_NOCHILDREN
);
472 // Execute a command in an interactive shell window (always synchronously)
473 // If no command then just the shell
474 WXDLLIMPEXP_BASE
bool wxShell(const wxString
& command
= wxEmptyString
);
476 // As wxShell(), but must give a (non interactive) command and its output will
477 // be returned in output array
478 WXDLLIMPEXP_BASE
bool wxShell(const wxString
& command
, wxArrayString
& output
);
480 // Sleep for nSecs seconds
481 WXDLLIMPEXP_BASE
void wxSleep(int nSecs
);
483 // Sleep for a given amount of milliseconds
484 WXDLLIMPEXP_BASE
void wxMilliSleep(unsigned long milliseconds
);
486 // Sleep for a given amount of microseconds
487 WXDLLIMPEXP_BASE
void wxMicroSleep(unsigned long microseconds
);
489 #if WXWIN_COMPATIBILITY_2_8
490 // Sleep for a given amount of milliseconds (old, bad name), use wxMilliSleep
491 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxUsleep(unsigned long milliseconds
) );
494 // Get the process id of the current process
495 WXDLLIMPEXP_BASE
unsigned long wxGetProcessId();
497 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
498 WXDLLIMPEXP_BASE wxMemorySize
wxGetFreeMemory();
500 #if wxUSE_ON_FATAL_EXCEPTION
502 // should wxApp::OnFatalException() be called?
503 WXDLLIMPEXP_BASE
bool wxHandleFatalExceptions(bool doit
= true);
505 #endif // wxUSE_ON_FATAL_EXCEPTION
507 // ----------------------------------------------------------------------------
508 // Environment variables
509 // ----------------------------------------------------------------------------
511 // returns true if variable exists (value may be NULL if you just want to check
513 WXDLLIMPEXP_BASE
bool wxGetEnv(const wxString
& var
, wxString
*value
);
515 // set the env var name to the given value, return true on success
516 WXDLLIMPEXP_BASE
bool wxSetEnv(const wxString
& var
, const wxString
& value
);
518 // remove the env var from environment
519 WXDLLIMPEXP_BASE
bool wxUnsetEnv(const wxString
& var
);
521 #if WXWIN_COMPATIBILITY_2_8
522 inline bool wxSetEnv(const wxString
& var
, const char *value
)
523 { return wxSetEnv(var
, wxString(value
)); }
524 inline bool wxSetEnv(const wxString
& var
, const wchar_t *value
)
525 { return wxSetEnv(var
, wxString(value
)); }
527 inline bool wxSetEnv(const wxString
& var
, const wxScopedCharTypeBuffer
<T
>& value
)
528 { return wxSetEnv(var
, wxString(value
)); }
529 inline bool wxSetEnv(const wxString
& var
, const wxCStrData
& value
)
530 { return wxSetEnv(var
, wxString(value
)); }
532 // this one is for passing NULL directly - don't use it, use wxUnsetEnv instead
533 wxDEPRECATED( inline bool wxSetEnv(const wxString
& var
, int value
) );
534 inline bool wxSetEnv(const wxString
& var
, int value
)
536 wxASSERT_MSG( value
== 0, "using non-NULL integer as string?" );
538 wxUnusedVar(value
); // fix unused parameter warning in release build
540 return wxUnsetEnv(var
);
542 #endif // WXWIN_COMPATIBILITY_2_8
544 // Retrieve the complete environment by filling specified map.
545 // Returns true on success or false if an error occurred.
546 WXDLLIMPEXP_BASE
bool wxGetEnvMap(wxEnvVariableHashMap
*map
);
548 // ----------------------------------------------------------------------------
549 // Network and username functions.
550 // ----------------------------------------------------------------------------
552 // NB: "char *" functions are deprecated, use wxString ones!
555 WXDLLIMPEXP_BASE
bool wxGetEmailAddress(wxChar
*buf
, int maxSize
);
556 WXDLLIMPEXP_BASE wxString
wxGetEmailAddress();
559 WXDLLIMPEXP_BASE
bool wxGetHostName(wxChar
*buf
, int maxSize
);
560 WXDLLIMPEXP_BASE wxString
wxGetHostName();
563 WXDLLIMPEXP_BASE wxString
wxGetFullHostName();
564 WXDLLIMPEXP_BASE
bool wxGetFullHostName(wxChar
*buf
, int maxSize
);
566 // Get user ID e.g. jacs (this is known as login name under Unix)
567 WXDLLIMPEXP_BASE
bool wxGetUserId(wxChar
*buf
, int maxSize
);
568 WXDLLIMPEXP_BASE wxString
wxGetUserId();
570 // Get user name e.g. Julian Smart
571 WXDLLIMPEXP_BASE
bool wxGetUserName(wxChar
*buf
, int maxSize
);
572 WXDLLIMPEXP_BASE wxString
wxGetUserName();
574 // Get current Home dir and copy to dest (returns pstr->c_str())
575 WXDLLIMPEXP_BASE wxString
wxGetHomeDir();
576 WXDLLIMPEXP_BASE
const wxChar
* wxGetHomeDir(wxString
*pstr
);
578 // Get the user's (by default use the current user name) home dir,
579 // return empty string on error
580 WXDLLIMPEXP_BASE wxString
wxGetUserHome(const wxString
& user
= wxEmptyString
);
584 typedef wxLongLong wxDiskspaceSize_t
;
586 typedef long wxDiskspaceSize_t
;
589 // get number of total/free bytes on the disk where path belongs
590 WXDLLIMPEXP_BASE
bool wxGetDiskSpace(const wxString
& path
,
591 wxDiskspaceSize_t
*pTotal
= NULL
,
592 wxDiskspaceSize_t
*pFree
= NULL
);
596 typedef int (*wxSortCallback
)(const void* pItem1
,
598 const void* user_data
);
601 WXDLLIMPEXP_BASE
void wxQsort(void* pbase
, size_t total_elems
,
602 size_t size
, wxSortCallback cmp
,
603 const void* user_data
);
606 #if wxUSE_GUI // GUI only things from now on
608 // ----------------------------------------------------------------------------
609 // Launch default browser
610 // ----------------------------------------------------------------------------
612 // flags for wxLaunchDefaultBrowser
615 wxBROWSER_NEW_WINDOW
= 0x01,
616 wxBROWSER_NOBUSYCURSOR
= 0x02
619 // Launch url in the user's default internet browser
620 WXDLLIMPEXP_CORE
bool wxLaunchDefaultBrowser(const wxString
& url
, int flags
= 0);
622 // Launch document in the user's default application
623 WXDLLIMPEXP_CORE
bool wxLaunchDefaultApplication(const wxString
& path
, int flags
= 0);
625 // ----------------------------------------------------------------------------
626 // Menu accelerators related things
627 // ----------------------------------------------------------------------------
629 // flags for wxStripMenuCodes
632 // strip '&' characters
633 wxStrip_Mnemonics
= 1,
635 // strip everything after '\t'
638 // strip everything (this is the default)
639 wxStrip_All
= wxStrip_Mnemonics
| wxStrip_Accel
642 // strip mnemonics and/or accelerators from the label
643 WXDLLIMPEXP_CORE wxString
644 wxStripMenuCodes(const wxString
& str
, int flags
= wxStrip_All
);
646 #if WXWIN_COMPATIBILITY_2_6
647 // obsolete and deprecated version, do not use, use the above overload instead
649 WXDLLIMPEXP_CORE wxChar
* wxStripMenuCodes(const wxChar
*in
, wxChar
*out
= NULL
)
653 class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry
;
655 // use wxAcceleratorEntry::Create() or FromString() methods instead
657 WXDLLIMPEXP_CORE wxAcceleratorEntry
*wxGetAccelFromString(const wxString
& label
)
659 #endif // wxUSE_ACCEL
661 #endif // WXWIN_COMPATIBILITY_2_6
663 // ----------------------------------------------------------------------------
665 // ----------------------------------------------------------------------------
667 // Returns menu item id or wxNOT_FOUND if none.
668 WXDLLIMPEXP_CORE
int wxFindMenuItemId(wxFrame
*frame
, const wxString
& menuString
, const wxString
& itemString
);
670 // Find the wxWindow at the given point. wxGenericFindWindowAtPoint
671 // is always present but may be less reliable than a native version.
672 WXDLLIMPEXP_CORE wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
);
673 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
);
675 // NB: this function is obsolete, use wxWindow::FindWindowByLabel() instead
677 // Find the window/widget with the given title or label.
678 // Pass a parent to begin the search from, or NULL to look through
680 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowByLabel(const wxString
& title
, wxWindow
*parent
= NULL
);
682 // NB: this function is obsolete, use wxWindow::FindWindowByName() instead
684 // Find window by name, and if that fails, by label.
685 WXDLLIMPEXP_CORE wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
*parent
= NULL
);
687 // ----------------------------------------------------------------------------
688 // Message/event queue helpers
689 // ----------------------------------------------------------------------------
691 // Yield to other apps/messages and disable user input
692 WXDLLIMPEXP_CORE
bool wxSafeYield(wxWindow
*win
= NULL
, bool onlyIfNeeded
= false);
694 // Enable or disable input to all top level windows
695 WXDLLIMPEXP_CORE
void wxEnableTopLevelWindows(bool enable
= true);
697 // Check whether this window wants to process messages, e.g. Stop button
698 // in long calculations.
699 WXDLLIMPEXP_CORE
bool wxCheckForInterrupt(wxWindow
*wnd
);
701 // Consume all events until no more left
702 WXDLLIMPEXP_CORE
void wxFlushEvents();
704 // a class which disables all windows (except, may be, the given one) in its
705 // ctor and enables them back in its dtor
706 class WXDLLIMPEXP_CORE wxWindowDisabler
709 // this ctor conditionally disables all windows: if the argument is false,
710 // it doesn't do anything
711 wxWindowDisabler(bool disable
= true);
713 // ctor disables all windows except winToSkip
714 wxWindowDisabler(wxWindow
*winToSkip
);
716 // dtor enables back all windows disabled by the ctor
720 // disable all windows except the given one (used by both ctors)
721 void DoDisable(wxWindow
*winToSkip
= NULL
);
723 #if defined(__WXOSX__) && wxOSX_USE_COCOA
724 wxEventLoop
* m_modalEventLoop
;
726 wxWindowList
*m_winDisabled
;
729 wxDECLARE_NO_COPY_CLASS(wxWindowDisabler
);
732 // ----------------------------------------------------------------------------
734 // ----------------------------------------------------------------------------
736 // Set the cursor to the busy cursor for all windows
737 WXDLLIMPEXP_CORE
void wxBeginBusyCursor(const wxCursor
*cursor
= wxHOURGLASS_CURSOR
);
739 // Restore cursor to normal
740 WXDLLIMPEXP_CORE
void wxEndBusyCursor();
742 // true if we're between the above two calls
743 WXDLLIMPEXP_CORE
bool wxIsBusy();
745 // Convenience class so we can just create a wxBusyCursor object on the stack
746 class WXDLLIMPEXP_CORE wxBusyCursor
749 wxBusyCursor(const wxCursor
* cursor
= wxHOURGLASS_CURSOR
)
750 { wxBeginBusyCursor(cursor
); }
752 { wxEndBusyCursor(); }
754 // FIXME: These two methods are currently only implemented (and needed?)
755 // in wxGTK. BusyCursor handling should probably be moved to
756 // common code since the wxGTK and wxMSW implementations are very
757 // similar except for wxMSW using HCURSOR directly instead of
759 static const wxCursor
&GetStoredCursor();
760 static const wxCursor
GetBusyCursor();
763 void WXDLLIMPEXP_CORE
wxGetMousePosition( int* x
, int* y
);
765 // ----------------------------------------------------------------------------
766 // X11 Display access
767 // ----------------------------------------------------------------------------
769 #if defined(__X__) || defined(__WXGTK__)
772 WXDLLIMPEXP_CORE
void *wxGetDisplay();
776 WXDLLIMPEXP_CORE WXDisplay
*wxGetDisplay();
777 WXDLLIMPEXP_CORE
bool wxSetDisplay(const wxString
& display_name
);
778 WXDLLIMPEXP_CORE wxString
wxGetDisplayName();
781 // use this function instead of the functions above in implementation code
782 inline struct _XDisplay
*wxGetX11Display()
784 return (_XDisplay
*)wxGetDisplay();
787 #endif // X11 || wxGTK
791 // ----------------------------------------------------------------------------
792 // wxYield(): these functions are obsolete, please use wxApp methods instead!
793 // ----------------------------------------------------------------------------
795 // avoid redeclaring this function here if it had been already declated by
796 // wx/app.h, this results in warnings from g++ with -Wredundant-decls
797 #ifndef wx_YIELD_DECLARED
798 #define wx_YIELD_DECLARED
800 // Yield to other apps/messages
801 WXDLLIMPEXP_CORE
bool wxYield();
803 #endif // wx_YIELD_DECLARED
805 // Like wxYield, but fails silently if the yield is recursive.
806 WXDLLIMPEXP_CORE
bool wxYieldIfNeeded();
808 // ----------------------------------------------------------------------------
809 // Windows resources access
810 // ----------------------------------------------------------------------------
812 // Windows only: get user-defined resource from the .res file.
814 // default resource type for wxLoadUserResource()
815 extern WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxUserResourceStr
;
817 // Return the pointer to the resource data. This pointer is read-only, use
818 // the overload below if you need to modify the data.
820 // Notice that the resource type can be either a real string or an integer
821 // produced by MAKEINTRESOURCE(). In particular, any standard resource type,
822 // i.e any RT_XXX constant, could be passed here.
824 // Returns true on success, false on failure. Doesn't log an error message
825 // if the resource is not found (because this could be expected) but does
826 // log one if any other error occurs.
827 WXDLLIMPEXP_BASE
bool
828 wxLoadUserResource(const void **outData
,
830 const wxString
& resourceName
,
831 const wxChar
* resourceType
= wxUserResourceStr
,
832 WXHINSTANCE
module = 0);
834 // This function allocates a new buffer and makes a copy of the resource
835 // data, remember to delete[] the buffer. And avoid using it entirely if
836 // the overload above can be used.
838 // Returns NULL on failure.
839 WXDLLIMPEXP_BASE
char*
840 wxLoadUserResource(const wxString
& resourceName
,
841 const wxChar
* resourceType
= wxUserResourceStr
,
843 WXHINSTANCE
module = 0);
844 #endif // __WINDOWS__