]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/utils.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of various utility classes and functions
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxWindowDisabler
12 This class disables all windows of the application (may be with the
13 exception of one of them) in its constructor and enables them back in its
16 This is useful when you want to indicate to the user that the application
17 is currently busy and cannot respond to user input.
24 class wxWindowDisabler
28 Disables all top level windows of the applications.
30 If @a disable is @c false nothing is done. This can be convenient if
31 the windows should be disabled depending on some condition.
35 wxWindowDisabler(bool disable
= true);
38 Disables all top level windows of the applications with the exception
39 of @a winToSkip if it is not @NULL.
41 wxWindowDisabler(wxWindow
* winToSkip
);
44 Reenables the windows disabled by the constructor.
54 This class makes it easy to tell your user that the program is temporarily
55 busy. Just create a wxBusyCursor object on the stack, and within the
56 current scope, the hourglass will be shown.
63 for (int i = 0; i < 100000; i++)
67 It works by calling wxBeginBusyCursor() in the constructor, and
68 wxEndBusyCursor() in the destructor.
73 @see wxBeginBusyCursor(), wxEndBusyCursor(), wxWindowDisabler
79 Constructs a busy cursor object, calling wxBeginBusyCursor().
81 wxBusyCursor(const wxCursor
* cursor
= wxHOURGLASS_CURSOR
);
84 Destroys the busy cursor object, calling wxEndBusyCursor().
91 // ============================================================================
92 // Global functions/macros
93 // ============================================================================
96 /** @ingroup group_funcmacro_dialog */
100 Changes the cursor to the given cursor for all windows in the application.
101 Use wxEndBusyCursor() to revert the cursor back to its previous state.
102 These two calls can be nested, and a counter ensures that only the outer
105 @see wxIsBusy(), wxBusyCursor
109 void wxBeginBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
);
112 Changes the cursor back to the original cursor, for all windows in the
113 application. Use with wxBeginBusyCursor().
115 @see wxIsBusy(), wxBusyCursor
119 void wxEndBusyCursor();
122 Returns @true if between two wxBeginBusyCursor() and wxEndBusyCursor()
132 Ring the system bell.
134 @note This function is categorized as a GUI one and so is not thread-safe.
141 Shows a message box with the information about the wxWidgets build used,
142 including its version, most important build parameters and the version of
143 the underlying GUI toolkit. This is mainly used for diagnostic purposes
144 and can be invoked by Ctrl-Alt-middle clicking on any wxWindow which
145 doesn't otherwise handle this event.
151 void wxInfoMessageBox(wxWindow parent
= NULL
);
157 /** @ingroup group_funcmacro_env */
161 This is a macro defined as @c getenv() or its wide char version in Unicode
164 Note that under Win32 it may not return correct value for the variables set
165 with wxSetEnv(), use wxGetEnv() function instead.
169 wxChar
* wxGetenv(const wxString
& var
);
172 Returns the current value of the environment variable @c var in @c value.
173 @c value may be @NULL if you just want to know if the variable exists and
174 are not interested in its value.
176 Returns @true if the variable exists, @false otherwise.
180 bool wxGetEnv(const wxString
& var
, wxString
* value
);
183 Sets the value of the environment variable @c var (adding it if necessary)
186 Returns @true on success.
192 bool wxSetEnv(const wxString
& var
, const wxString
& value
);
195 Removes the variable @c var from the environment. wxGetEnv() will return
196 @NULL after the call to this function.
198 Returns @true on success.
202 bool wxUnsetEnv(const wxString
& var
);
208 /** @ingroup group_funcmacro_misc */
212 Returns battery state as one of @c wxBATTERY_NORMAL_STATE,
213 @c wxBATTERY_LOW_STATE, @c wxBATTERY_CRITICAL_STATE,
214 @c wxBATTERY_SHUTDOWN_STATE or @c wxBATTERY_UNKNOWN_STATE.
215 @c wxBATTERY_UNKNOWN_STATE is also the default on platforms where this
216 feature is not implemented (currently everywhere but MS Windows).
220 wxBatteryState
wxGetBatteryState();
223 Returns the type of power source as one of @c wxPOWER_SOCKET,
224 @c wxPOWER_BATTERY or @c wxPOWER_UNKNOWN. @c wxPOWER_UNKNOWN is also the
225 default on platforms where this feature is not implemented (currently
226 everywhere but MS Windows).
230 wxPowerType
wxGetPowerType();
233 Under X only, returns the current display name.
235 @see wxSetDisplayName()
239 wxString
wxGetDisplayName();
242 For normal keys, returns @true if the specified key is currently down.
244 For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns @true if
245 the key is toggled such that its LED indicator is lit. There is currently
246 no way to test whether togglable keys are up or down.
248 Even though there are virtual key codes defined for mouse buttons, they
249 cannot be used with this function currently.
253 bool wxGetKeyState(wxKeyCode key
);
256 Returns the mouse position in screen coordinates.
260 wxPoint
wxGetMousePosition();
263 Returns the current state of the mouse. Returns a wxMouseState instance
264 that contains the current position of the mouse pointer in screen
265 coordinates, as well as boolean values indicating the up/down status of the
266 mouse buttons and the modifier keys.
270 wxMouseState
wxGetMouseState();
273 This function enables or disables all top level windows. It is used by
278 void wxEnableTopLevelWindows(bool enable
= true);
281 Find the deepest window at the given mouse position in screen coordinates,
282 returning the window if found, or @NULL if not.
286 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
);
289 @deprecated Replaced by wxWindow::FindWindowByLabel().
291 Find a window by its label. Depending on the type of window, the label may
292 be a window title or panel item label. If @a parent is @NULL, the search
293 will start from all top-level frames and dialog boxes; if non-@NULL, the
294 search will be limited to the given window hierarchy. The search is
295 recursive in both cases.
299 wxWindow
* wxFindWindowByLabel(const wxString
& label
,
300 wxWindow
* parent
= NULL
);
303 @deprecated Replaced by wxWindow::FindWindowByName().
305 Find a window by its name (as given in a window constructor or @e Create
306 function call). If @a parent is @NULL, the search will start from all
307 top-level frames and dialog boxes; if non-@NULL, the search will be limited
308 to the given window hierarchy. The search is recursive in both cases.
310 If no such named window is found, wxFindWindowByLabel() is called.
314 wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
* parent
= NULL
);
317 Find a menu item identifier associated with the given frame's menu bar.
321 int wxFindMenuItemId(wxFrame
* frame
, const wxString
& menuString
,
322 const wxString
& itemString
);
325 @deprecated Ids generated by it can conflict with the Ids defined by the
326 user code, use @c wxID_ANY to assign ids which are guaranteed
327 to not conflict with the user-defined ids for the controls and
328 menu items you create instead of using this function.
330 Generates an integer identifier unique to this run of the program.
337 Ensures that Ids subsequently generated by wxNewId() do not clash with the
342 void wxRegisterId(long id
);
345 Opens the @a document in the application associated with the files of this
348 The @a flags parameter is currently not used
350 Returns @true if the application was successfully launched.
352 @see wxLaunchDefaultBrowser(), wxExecute()
356 bool wxLaunchDefaultApplication(const wxString
& document
, int flags
= 0);
359 Opens the @a url in user's default browser.
361 If the @a flags parameter contains @c wxBROWSER_NEW_WINDOW flag, a new
362 window is opened for the URL (currently this is only supported under
365 And unless the @a flags parameter contains @c wxBROWSER_NOBUSYCURSOR flag,
366 a busy cursor is shown while the browser is being launched (using
369 The @a url may also be a local file path (with or without the "file://"
370 prefix), if it doesn't correspond to an existing file and the URL has no
371 scheme "http://" is prepended to it by default.
373 Returns @true if the application was successfully launched.
375 @note For some configurations of the running user, the application which is
376 launched to open the given URL may be URL-dependent (e.g. a browser
377 may be used for local URLs while another one may be used for remote
380 @see wxLaunchDefaultApplication(), wxExecute()
384 bool wxLaunchDefaultBrowser(const wxString
& url
, int flags
= 0);
387 Loads a user-defined Windows resource as a string. If the resource is
388 found, the function creates a new character array and copies the data into
389 it. A pointer to this data is returned. If unsuccessful, @NULL is returned.
391 The resource must be defined in the @c .rc file using the following syntax:
394 myResource TEXT file.ext
397 Where @c file.ext is a file that the resource compiler can find.
399 This function is available under Windows only.
403 wxString
wxLoadUserResource(const wxString
& resourceName
,
404 const wxString
& resourceType
= "TEXT");
407 @deprecated Replaced by wxWindow::Close(). See the
408 @ref overview_windowdeletion "window deletion overview".
410 Tells the system to delete the specified object when all other events have
411 been processed. In some environments, it is necessary to use this instead
412 of deleting a frame directly with the delete operator, because some GUIs
413 will still send events to a deleted window.
417 void wxPostDelete(wxObject
* object
);
420 Under X only, sets the current display name. This is the X host and display
421 name such as "colonsay:0.0", and the function indicates which display
422 should be used for creating windows from this point on. Setting the display
423 within an application allows multiple displays to be used.
425 @see wxGetDisplayName()
429 void wxSetDisplayName(const wxString
& displayName
);
432 Strips any menu codes from @a str and returns the result.
434 By default, the functions strips both the mnemonics character (@c '&')
435 which is used to indicate a keyboard shortkey, and the accelerators, which
436 are used only in the menu items and are separated from the main text by the
437 @c \\t (TAB) character. By using @a flags of @c wxStrip_Mnemonics or
438 @c wxStrip_Accel to strip only the former or the latter part, respectively.
440 Notice that in most cases wxMenuItem::GetLabelFromText() or
441 wxControl::GetLabelText() can be used instead.
445 wxString
wxStripMenuCodes(const wxString
& str
, int flags
= wxStrip_All
);
451 /** @ingroup group_funcmacro_networkuseros */
455 Copies the user's email address into the supplied buffer, by concatenating
456 the values returned by wxGetFullHostName() and wxGetUserId().
458 @return @true if successful, @false otherwise.
462 wxString
wxGetEmailAddress();
465 @deprecated Use wxGetEmailAddress() instead.
467 @param buf Buffer to store the email address in.
468 @param sz Size of the buffer.
470 @return @true if successful, @false otherwise.
474 bool wxGetEmailAddress(char* buf
, int sz
);
477 Returns the amount of free memory in bytes under environments which support
478 it, and -1 if not supported or failed to perform measurement.
482 wxMemorySize
wxGetFreeMemory();
485 Return the (current) user's home directory.
487 @see wxGetUserHome(), wxStandardPaths
491 wxString
wxGetHomeDir();
494 Copies the current host machine's name into the supplied buffer. Please
495 note that the returned name is @e not fully qualified, i.e. it does not
496 include the domain name.
498 Under Windows or NT, this function first looks in the environment variable
499 SYSTEM_NAME; if this is not found, the entry @b HostName in the wxWidgets
500 section of the WIN.INI file is tried.
502 @return The hostname if successful or an empty string otherwise.
504 @see wxGetFullHostName()
508 wxString
wxGetHostName();
511 @deprecated Use wxGetHostName() instead.
513 @param buf Buffer to store the host name in.
514 @param sz Size of the buffer.
516 @return @true if successful, @false otherwise.
520 bool wxGetHostName(char* buf
, int sz
);
523 Returns the FQDN (fully qualified domain host name) or an empty string on
530 wxString
wxGetFullHostName();
533 Returns the home directory for the given user. If the @a user is empty
534 (default value), this function behaves like wxGetHomeDir() (i.e. returns
535 the current user home directory).
537 If the home directory couldn't be determined, an empty string is returned.
541 wxString
wxGetUserHome(const wxString
& user
= "");
544 This function returns the "user id" also known as "login name" under Unix
545 (i.e. something like "jsmith"). It uniquely identifies the current user (on
546 this system). Under Windows or NT, this function first looks in the
547 environment variables USER and LOGNAME; if neither of these is found, the
548 entry @b UserId in the @b wxWidgets section of the WIN.INI file is tried.
550 @return The login name if successful or an empty string otherwise.
556 wxString
wxGetUserId();
559 @deprecated Use wxGetUserId() instead.
561 @param buf Buffer to store the login name in.
562 @param sz Size of the buffer.
564 @return @true if successful, @false otherwise.
568 bool wxGetUserId(char* buf
, int sz
);
571 This function returns the full user name (something like "Mr. John Smith").
573 Under Windows or NT, this function looks for the entry UserName in the
574 wxWidgets section of the WIN.INI file. If PenWindows is running, the entry
575 Current in the section User of the PENWIN.INI file is used.
577 @return The full user name if successful or an empty string otherwise.
583 wxString
wxGetUserName();
586 @deprecated Use wxGetUserName() instead.
588 @param buf Buffer to store the full user name in.
589 @param sz Size of the buffer.
591 @return @true if successful, @false otherwise.
595 bool wxGetUserName(char* buf
, int sz
);
598 Returns the string containing the description of the current platform in a
599 user-readable form. For example, this function may return strings like
600 "Windows NT Version 4.0" or "Linux 2.2.2 i386".
602 @see wxGetOsVersion()
606 wxString
wxGetOsDescription();
609 Gets the version and the operating system ID for currently running OS. See
610 wxPlatformInfo for more details about wxOperatingSystemId.
612 @see wxGetOsDescription(), wxPlatformInfo
616 wxOperatingSystemId
wxGetOsVersion(int* major
= NULL
, int* minor
= NULL
);
619 Returns @true if the operating system the program is running under is 64
620 bit. The check is performed at run-time and may differ from the value
621 available at compile-time (at compile-time you can just check if
622 <tt>sizeof(void*) == 8</tt>) since the program could be running in
623 emulation mode or in a mixed 32/64 bit system (bi-architecture operating
626 @note This function is not 100% reliable on some systems given the fact
627 that there isn't always a standard way to do a reliable check on the
632 bool wxIsPlatform64Bit();
635 Returns @true if the current platform is little endian (instead of big
636 endian). The check is performed at run-time.
638 @see @ref group_funcmacro_byteorder "Byte Order Functions and Macros"
642 bool wxIsPlatformLittleEndian();
648 /** @ingroup group_funcmacro_procctrl */
652 Executes another program in Unix or Windows.
654 In the overloaded versions of this function, if @a flags parameter contains
655 @c wxEXEC_ASYNC flag (the default), flow of control immediately returns. If
656 it contains @c wxEXEC_SYNC, the current application waits until the other
657 program has terminated.
659 In the case of synchronous execution, the return value is the exit code of
660 the process (which terminates by the moment the function returns) and will
661 be -1 if the process couldn't be started and typically 0 if the process
662 terminated successfully. Also, while waiting for the process to terminate,
663 wxExecute() will call wxYield(). Because of this, by default this function
664 disables all application windows to avoid unexpected reentrancies which
665 could result from the users interaction with the program while the child
666 process is running. If you are sure that it is safe to not disable the
667 program windows, you may pass @c wxEXEC_NODISABLE flag to prevent this
668 automatic disabling from happening.
670 For asynchronous execution, however, the return value is the process id and
671 zero value indicates that the command could not be executed. As an added
672 complication, the return value of -1 in this case indicates that we didn't
673 launch a new process, but connected to the running one (this can only
674 happen when using DDE under Windows for command execution). In particular,
675 in this case only, the calling code will not get the notification about
678 If @a callback isn't @NULL and if execution is asynchronous,
679 wxProcess::OnTerminate() will be called when the process finishes.
680 Specifying this parameter also allows you to redirect the standard input
681 and/or output of the process being launched by calling
682 wxProcess::Redirect(). If the child process IO is redirected, under Windows
683 the process window is not shown by default (this avoids having to flush an
684 unnecessary console for the processes which don't create any windows
685 anyhow) but a @c wxEXEC_NOHIDE flag can be used to prevent this from
686 happening, i.e. with this flag the child process window will be shown
689 Under Unix the flag @c wxEXEC_MAKE_GROUP_LEADER may be used to ensure that
690 the new process is a group leader (this will create a new session if
691 needed). Calling wxKill() passing wxKILL_CHILDREN will kill this process as
692 well as all of its children (except those which have started their own
695 The @c wxEXEC_NOEVENTS flag prevents processing of any events from taking
696 place while the child process is running. It should be only used for very
697 short-lived processes as otherwise the application windows risk becoming
698 unresponsive from the users point of view. As this flag only makes sense
699 with @c wxEXEC_SYNC, @c wxEXEC_BLOCK equal to the sum of both of these
700 flags is provided as a convenience.
702 @note Currently wxExecute() can only be used from the main thread, calling
703 this function from another thread will result in an assert failure in
704 debug build and won't work.
707 The command to execute and any parameters to pass to it as a single
708 string, i.e. "emacs file.txt".
710 Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
711 wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or
712 wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to
713 their combination, in wxEXEC_SYNC case.
715 An optional pointer to wxProcess.
717 @see wxShell(), wxProcess, @ref page_samples_exec,
718 wxLaunchDefaultApplication(), wxLaunchDefaultBrowser()
723 This function is called @c Wx::ExecuteStdoutStderr and it only takes the
724 @a command argument, and returns a 3-element list (@c status, @c output,
725 @c errors), where @c output and @c errors are array references.
728 long wxExecute(const wxString
& command
, int flags
= wxEXEC_ASYNC
,
729 wxProcess
* callback
= NULL
);
733 /** @ingroup group_funcmacro_procctrl */
736 This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
737 please see its documentation for general information.
739 This version takes an array of values: a command, any number of arguments,
743 The command to execute should be the first element of this array, any
744 additional ones are the command parameters and the array must be
745 terminated with a @NULL pointer.
747 Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
748 wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or
749 wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to
750 their combination, in wxEXEC_SYNC case.
752 An optional pointer to wxProcess.
754 @see wxShell(), wxProcess, @ref page_samples_exec,
755 wxLaunchDefaultApplication(), wxLaunchDefaultBrowser()
759 long wxExecute(char** argv
, int flags
= wxEXEC_ASYNC
,
760 wxProcess
* callback
= NULL
);
761 long wxExecute(wchar_t** argv
, int flags
= wxEXEC_ASYNC
,
762 wxProcess
* callback
= NULL
);
765 /** @ingroup group_funcmacro_procctrl */
769 This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
770 please see its documentation for general information.
772 This version can be used to execute a process (always synchronously, the
773 contents of @a flags is or'd with @c wxEXEC_SYNC) and capture its output in
777 The command to execute and any parameters to pass to it as a single
780 The string array where the stdout of the executed process is saved.
782 Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
783 wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or
784 wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to
785 their combination, in wxEXEC_SYNC case.
787 @see wxShell(), wxProcess, @ref page_samples_exec,
788 wxLaunchDefaultApplication(), wxLaunchDefaultBrowser()
792 long wxExecute(const wxString
& command
, wxArrayString
& output
, int flags
= 0);
795 This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
796 please see its documentation for general information.
798 This version adds the possibility to additionally capture the messages from
799 standard error output in the @a errors array.
802 The command to execute and any parameters to pass to it as a single
805 The string array where the stdout of the executed process is saved.
807 The string array where the stderr of the executed process is saved.
809 Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
810 wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or
811 wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to
812 their combination, in wxEXEC_SYNC case.
814 @see wxShell(), wxProcess, @ref page_samples_exec,
815 wxLaunchDefaultApplication(), wxLaunchDefaultBrowser()
819 long wxExecute(const wxString
& command
, wxArrayString
& output
,
820 wxArrayString
& errors
, int flags
= 0);
823 Returns the number uniquely identifying the current process in the system.
824 If an error occurs, 0 is returned.
828 unsigned long wxGetProcessId();
831 Equivalent to the Unix kill function: send the given signal @a sig to the
832 process with PID @a pid. The valid signal values are:
837 wxSIGNONE = 0, // verify if the process exists under Unix
846 wxSIGKILL, // forcefully kill, dangerous!
852 wxSIGTERM // terminate the process gently
856 @c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning under
857 both Unix and Windows but all the other signals are equivalent to
858 @c wxSIGTERM under Windows.
860 Returns 0 on success, -1 on failure. If the @a rc parameter is not @NULL,
861 it will be filled with a value of the the @c wxKillError enum:
866 wxKILL_OK, // no error
867 wxKILL_BAD_SIGNAL, // no such signal
868 wxKILL_ACCESS_DENIED, // permission denied
869 wxKILL_NO_PROCESS, // no such process
870 wxKILL_ERROR // another, unspecified error
874 The @a flags parameter can be wxKILL_NOCHILDREN (the default), or
875 wxKILL_CHILDREN, in which case the child processes of this process will be
876 killed too. Note that under Unix, for wxKILL_CHILDREN to work you should
877 have created the process by passing wxEXEC_MAKE_GROUP_LEADER to
880 @see wxProcess::Kill(), wxProcess::Exists(), @ref page_samples_exec
884 int wxKill(long pid
, int sig
= wxSIGTERM
,
885 wxKillError rc
= NULL
, int flags
= 0);
888 Executes a command in an interactive shell window. If no command is
889 specified, then just the shell is spawned.
891 @see wxExecute(), @ref page_samples_exec
895 bool wxShell(const wxString
& command
= NULL
);
898 This function shuts down or reboots the computer depending on the value of
901 @note Note that performing the shutdown requires the corresponding access
902 rights (superuser under Unix, SE_SHUTDOWN privilege under Windows NT)
903 and that this function is only implemented under Unix and MSW.
906 One of @c wxSHUTDOWN_POWEROFF, @c wxSHUTDOWN_REBOOT or
907 @c wxSHUTDOWN_LOGOFF (currently implemented only for MSW) possibly
908 combined with @c wxSHUTDOWN_FORCE which forces shutdown under MSW by
909 forcefully terminating all the applications. As doing this can result
910 in a data loss, this flag shouldn't be used unless really necessary.
912 @return @true on success, @false if an error occurred.
916 bool wxShutdown(int flags
= wxSHUTDOWN_POWEROFF
);
922 /** @ingroup group_funcmacro_time */
926 Sleeps for the specified number of microseconds. The microsecond resolution
927 may not, in fact, be available on all platforms (currently only Unix
928 platforms with nanosleep(2) may provide it) in which case this is the same
929 as calling wxMilliSleep() with the argument of @e microseconds/1000.
933 void wxMicroSleep(unsigned long microseconds
);
936 Sleeps for the specified number of milliseconds. Notice that usage of this
937 function is encouraged instead of calling usleep(3) directly because the
938 standard @e usleep() function is not MT safe.
942 void wxMilliSleep(unsigned long milliseconds
);
945 Returns a string representing the current date and time.
952 Sleeps for the specified number of seconds.
956 void wxSleep(int secs
);
959 @deprecated This function is deprecated because its name is misleading:
960 notice that the argument is in milliseconds, not microseconds.
961 Please use either wxMilliSleep() or wxMicroSleep() depending on
962 the resolution you need.
964 Sleeps for the specified number of milliseconds.
968 void wxUsleep(unsigned long milliseconds
);