]>
git.saurik.com Git - wxWidgets.git/blob - interface/utils.h
806a04a88ac39512ee597a07f4c67278c7a9d67c
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxWindowDisabler
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxWindowDisabler
13 This class disables all windows of the application (may be with the exception
14 of one of them) in its constructor and enables them back in its destructor.
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 of
39 @a winToSkip if it is not @NULL.
41 wxWindowDisabler(wxWindow
* winToSkip
);
44 Reenables back the windows disabled by the constructor.
55 This class makes it easy to tell your user that the program is temporarily busy.
56 Just create a wxBusyCursor object on the stack, and within the current scope,
57 the hourglass will be shown.
64 for (int i = 0; i 100000; i++)
68 It works by calling wxBeginBusyCursor() in the constructor,
69 and wxEndBusyCursor() in the destructor.
74 @see wxBeginBusyCursor(), wxEndBusyCursor(), wxWindowDisabler
80 Constructs a busy cursor object, calling wxBeginBusyCursor().
82 wxBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
);
85 Destroys the busy cursor object, calling wxEndBusyCursor().
95 Represents the mouse state.
97 The methods of this class generally mirror the corresponding methods of
100 @see wxGetMouseState()
105 /// Returns X coordinate of the physical mouse event position.
106 wxCoord
GetX() const;
108 /// Returns Y coordinate of the physical mouse event position.
109 wxCoord
GetY() const;
111 /// Returns @true if the left mouse button changed to down.
112 bool LeftDown() const;
113 /// Returns @true if the middle mouse button changed to down.
114 bool MiddleDown() const;
115 /// Returns @true if the right mouse button changed to down.
116 bool RightDown() const;
117 /// Returns @true if the first extra button mouse button changed to down.
118 bool Aux1Down() const;
119 /// Returns @true if the second extra button mouse button changed to down.
120 bool Aux2Down() const;
122 /// Returns @true if the control key is down.
123 bool ControlDown() const;
124 /// Returns @true if the shift key is down.
125 bool ShiftDown() const;
126 /// Returns @true if the alt key is down.
127 bool AltDown() const;
128 /// Returns @true if the meta key is down.
129 bool MetaDown() const;
130 /// Same as MetaDown() under Mac systems, ControlDown() for the others.
131 bool CmdDown() const;
135 // ============================================================================
136 // Global functions/macros
137 // ============================================================================
140 /** @ingroup group_funcmacro_dialog */
144 Changes the cursor to the given cursor for all windows in the application.
145 Use wxEndBusyCursor() to revert the cursor back to its previous state.
146 These two calls can be nested, and a counter ensures that only the outer
149 @see wxIsBusy(), wxBusyCursor
153 void wxBeginBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
);
156 Changes the cursor back to the original cursor, for all windows in the
157 application. Use with wxBeginBusyCursor().
159 @see wxIsBusy(), wxBusyCursor
163 void wxEndBusyCursor();
166 Returns @true if between two wxBeginBusyCursor() and wxEndBusyCursor()
176 Ring the system bell.
178 @note This function is categorized as a GUI one and so is not thread-safe.
185 Shows a message box with the information about the wxWidgets build used,
186 including its version, most important build parameters and the version of
187 the underlying GUI toolkit. This is mainly used for diagnostic purposes
188 and can be invoked by Ctrl-Alt-middle clicking on any wxWindow which
189 doesn't otherwise handle this event.
195 void wxInfoMessageBox(wxWindow parent
= NULL
);
201 /** @ingroup group_funcmacro_env */
205 This is a macro defined as @c getenv() or its wide char version in Unicode
208 Note that under Win32 it may not return correct value for the variables set
209 with wxSetEnv(), use wxGetEnv() function instead.
213 wxChar
* wxGetenv(const wxString
& var
);
216 Returns the current value of the environment variable @c var in @c value.
217 @c value may be @NULL if you just want to know if the variable exists and
218 are not interested in its value.
220 Returns @true if the variable exists, @false otherwise.
224 bool wxGetEnv(const wxString
& var
, wxString
* value
);
227 Sets the value of the environment variable @c var (adding it if necessary)
230 Returns @true on success.
236 bool wxSetEnv(const wxString
& var
, const wxString
& value
);
239 Removes the variable @c var from the environment. wxGetEnv() will return
240 @NULL after the call to this function.
242 Returns @true on success.
246 bool wxUnsetEnv(const wxString
& var
);
252 /** @ingroup group_funcmacro_misc */
256 Returns battery state as one of @c wxBATTERY_NORMAL_STATE,
257 @c wxBATTERY_LOW_STATE, @c wxBATTERY_CRITICAL_STATE,
258 @c wxBATTERY_SHUTDOWN_STATE or @c wxBATTERY_UNKNOWN_STATE.
259 @c wxBATTERY_UNKNOWN_STATE is also the default on platforms where this
260 feature is not implemented (currently everywhere but MS Windows).
264 wxBatteryState
wxGetBatteryState();
267 Returns the type of power source as one of @c wxPOWER_SOCKET,
268 @c wxPOWER_BATTERY or @c wxPOWER_UNKNOWN. @c wxPOWER_UNKNOWN is also the
269 default on platforms where this feature is not implemented (currently
270 everywhere but MS Windows).
274 wxPowerType
wxGetPowerType();
277 Under X only, returns the current display name.
279 @see wxSetDisplayName()
283 wxString
wxGetDisplayName();
286 For normal keys, returns @true if the specified key is currently down.
288 For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns @true if
289 the key is toggled such that its LED indicator is lit. There is currently
290 no way to test whether togglable keys are up or down.
292 Even though there are virtual key codes defined for mouse buttons, they
293 cannot be used with this function currently.
297 bool wxGetKeyState(wxKeyCode key
);
300 Returns the mouse position in screen coordinates.
304 wxPoint
wxGetMousePosition();
307 Returns the current state of the mouse. Returns a wxMouseState instance
308 that contains the current position of the mouse pointer in screen
309 coordinates, as well as boolean values indicating the up/down status of the
310 mouse buttons and the modifier keys.
314 wxMouseState
wxGetMouseState();
317 This function enables or disables all top level windows. It is used by
322 void wxEnableTopLevelWindows(bool enable
= true);
325 Find the deepest window at the given mouse position in screen coordinates,
326 returning the window if found, or @NULL if not.
330 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
);
333 @deprecated Replaced by wxWindow::FindWindowByLabel().
335 Find a window by its label. Depending on the type of window, the label may
336 be a window title or panel item label. If @a parent is @NULL, the search
337 will start from all top-level frames and dialog boxes; if non-@NULL, the
338 search will be limited to the given window hierarchy. The search is
339 recursive in both cases.
343 wxWindow
* wxFindWindowByLabel(const wxString
& label
,
344 wxWindow
* parent
= NULL
);
347 @deprecated Replaced by wxWindow::FindWindowByName().
349 Find a window by its name (as given in a window constructor or @e Create
350 function call). If @a parent is @NULL, the search will start from all
351 top-level frames and dialog boxes; if non-@NULL, the search will be limited
352 to the given window hierarchy. The search is recursive in both cases.
354 If no such named window is found, wxFindWindowByLabel() is called.
358 wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
* parent
= NULL
);
361 Find a menu item identifier associated with the given frame's menu bar.
365 int wxFindMenuItemId(wxFrame
* frame
, const wxString
& menuString
,
366 const wxString
& itemString
);
369 @deprecated Ids generated by it can conflict with the Ids defined by the
370 user code, use @c wxID_ANY to assign ids which are guaranteed
371 to not conflict with the user-defined ids for the controls and
372 menu items you create instead of using this function.
374 Generates an integer identifier unique to this run of the program.
381 Ensures that Ids subsequently generated by wxNewId() do not clash with the
386 void wxRegisterId(long id
);
389 Opens the @a url in user's default browser. If the @a flags parameter
390 contains @c wxBROWSER_NEW_WINDOW flag, a new window is opened for the URL
391 (currently this is only supported under Windows). The @a url may also be a
392 local file path (with or without the "file://" prefix), if it doesn't
393 correspond to an existing file and the URL has no scheme "http://" is
394 prepended to it by default.
396 Returns @true if the application was successfully launched.
398 @note For some configurations of the running user, the application which is
399 launched to open the given URL may be URL-dependent (e.g. a browser
400 may be used for local URLs while another one may be used for remote
405 bool wxLaunchDefaultBrowser(const wxString
& url
, int flags
= 0);
408 Loads a user-defined Windows resource as a string. If the resource is
409 found, the function creates a new character array and copies the data into
410 it. A pointer to this data is returned. If unsuccessful, @NULL is returned.
412 The resource must be defined in the @c .rc file using the following syntax:
415 myResource TEXT file.ext
418 Where @c file.ext is a file that the resource compiler can find.
420 This function is available under Windows only.
424 wxString
wxLoadUserResource(const wxString
& resourceName
,
425 const wxString
& resourceType
= "TEXT");
428 @deprecated Replaced by wxWindow::Close(). See the
429 @ref overview_windowdeletion "window deletion overview".
431 Tells the system to delete the specified object when all other events have
432 been processed. In some environments, it is necessary to use this instead
433 of deleting a frame directly with the delete operator, because some GUIs
434 will still send events to a deleted window.
438 void wxPostDelete(wxObject
* object
);
441 Under X only, sets the current display name. This is the X host and display
442 name such as "colonsay:0.0", and the function indicates which display
443 should be used for creating windows from this point on. Setting the display
444 within an application allows multiple displays to be used.
446 @see wxGetDisplayName()
450 void wxSetDisplayName(const wxString
& displayName
);
453 Strips any menu codes from @a str and returns the result.
455 By default, the functions strips both the mnemonics character (@c '&')
456 which is used to indicate a keyboard shortkey, and the accelerators, which
457 are used only in the menu items and are separated from the main text by the
458 @c \t (TAB) character. By using @a flags of @c wxStrip_Mnemonics or
459 @c wxStrip_Accel to strip only the former or the latter part, respectively.
461 Notice that in most cases wxMenuItem::GetLabelFromText() or
462 wxControl::GetLabelText() can be used instead.
466 wxString
wxStripMenuCodes(const wxString
& str
, int flags
= wxStrip_All
);
472 /** @ingroup group_funcmacro_networkuseros */
476 Copies the user's email address into the supplied buffer, by concatenating
477 the values returned by wxGetFullHostName() and wxGetUserId().
479 @returns @true if successful, @false otherwise.
483 wxString
wxGetEmailAddress();
486 @deprecated Use wxGetEmailAddress() instead.
488 @param buf Buffer to store the email address in.
489 @param sz Size of the buffer.
491 @returns @true if successful, @false otherwise.
495 bool wxGetEmailAddress(char* buf
, int sz
);
498 Returns the amount of free memory in bytes under environments which support
499 it, and -1 if not supported or failed to perform measurement.
503 wxMemorySize
wxGetFreeMemory();
506 Return the (current) user's home directory.
508 @see wxGetUserHome(), wxStandardPaths
512 wxString
wxGetHomeDir();
515 Copies the current host machine's name into the supplied buffer. Please
516 note that the returned name is @e not fully qualified, i.e. it does not
517 include the domain name.
519 Under Windows or NT, this function first looks in the environment variable
520 SYSTEM_NAME; if this is not found, the entry @b HostName in the wxWidgets
521 section of the WIN.INI file is tried.
523 @returns The hostname if successful or an empty string otherwise.
525 @see wxGetFullHostName()
529 wxString
wxGetHostName();
532 @deprecated Use wxGetHostName() instead.
534 @param buf Buffer to store the host name in.
535 @param sz Size of the buffer.
537 @returns @true if successful, @false otherwise.
541 bool wxGetHostName(char* buf
, int sz
);
544 Returns the FQDN (fully qualified domain host name) or an empty string on
551 wxString
wxGetFullHostName();
554 Returns the home directory for the given user. If the @a user is empty
555 (default value), this function behaves like wxGetHomeDir() (i.e. returns
556 the current user home directory).
558 If the home directory couldn't be determined, an empty string is returned.
562 wxString
wxGetUserHome(const wxString
& user
= "");
565 This function returns the "user id" also known as "login name" under Unix
566 (i.e. something like "jsmith"). It uniquely identifies the current user (on
567 this system). Under Windows or NT, this function first looks in the
568 environment variables USER and LOGNAME; if neither of these is found, the
569 entry @b UserId in the @b wxWidgets section of the WIN.INI file is tried.
571 @returns The login name if successful or an empty string otherwise.
577 wxString
wxGetUserId();
580 @deprecated Use wxGetUserId() instead.
582 @param buf Buffer to store the login name in.
583 @param sz Size of the buffer.
585 @returns @true if successful, @false otherwise.
589 bool wxGetUserId(char* buf
, int sz
);
592 This function returns the full user name (something like "Mr. John Smith").
594 Under Windows or NT, this function looks for the entry UserName in the
595 wxWidgets section of the WIN.INI file. If PenWindows is running, the entry
596 Current in the section User of the PENWIN.INI file is used.
598 @returns The full user name if successful or an empty string otherwise.
604 wxString
wxGetUserName();
607 @deprecated Use wxGetUserName() instead.
609 @param buf Buffer to store the full user name in.
610 @param sz Size of the buffer.
612 @returns @true if successful, @false otherwise.
616 bool wxGetUserName(char* buf
, int sz
);
619 Returns the string containing the description of the current platform in a
620 user-readable form. For example, this function may return strings like
621 "Windows NT Version 4.0" or "Linux 2.2.2 i386".
623 @see wxGetOsVersion()
627 wxString
wxGetOsDescription();
630 Gets the version and the operating system ID for currently running OS. See
631 wxPlatformInfo for more details about wxOperatingSystemId.
633 @see wxGetOsDescription(), wxPlatformInfo
637 wxOperatingSystemId
wxGetOsVersion(int* major
= NULL
, int* minor
= NULL
);
640 Returns @true if the operating system the program is running under is 64
641 bit. The check is performed at run-time and may differ from the value
642 available at compile-time (at compile-time you can just check if
643 <tt>sizeof(void*) == 8</tt>) since the program could be running in
644 emulation mode or in a mixed 32/64 bit system (bi-architecture operating
647 @note This function is not 100% reliable on some systems given the fact
648 that there isn't always a standard way to do a reliable check on the
653 bool wxIsPlatform64Bit();
656 Returns @true if the current platform is little endian (instead of big
657 endian). The check is performed at run-time.
659 @see @ref group_funcmacro_byteorder "Byte Order Functions and Macros"
663 bool wxIsPlatformLittleEndian();
669 /** @ingroup group_funcmacro_procctrl */
673 Executes another program in Unix or Windows.
675 In the overloaded versions of this function, if @a flags parameter contains
676 @c wxEXEC_ASYNC flag (the default), flow of control immediately returns. If
677 it contains @c wxEXEC_SYNC, the current application waits until the other
678 program has terminated.
680 In the case of synchronous execution, the return value is the exit code of
681 the process (which terminates by the moment the function returns) and will
682 be -1 if the process couldn't be started and typically 0 if the process
683 terminated successfully. Also, while waiting for the process to terminate,
684 wxExecute() will call wxYield(). Because of this, by default this function
685 disables all application windows to avoid unexpected reentrancies which
686 could result from the users interaction with the program while the child
687 process is running. If you are sure that it is safe to not disable the
688 program windows, you may pass @c wxEXEC_NODISABLE flag to prevent this
689 automatic disabling from happening.
691 For asynchronous execution, however, the return value is the process id and
692 zero value indicates that the command could not be executed. As an added
693 complication, the return value of -1 in this case indicates that we didn't
694 launch a new process, but connected to the running one (this can only
695 happen when using DDE under Windows for command execution). In particular,
696 in this case only, the calling code will not get the notification about
699 If @a callback isn't @NULL and if execution is asynchronous,
700 wxProcess::OnTerminate() will be called when the process finishes.
701 Specifying this parameter also allows you to redirect the standard input
702 and/or output of the process being launched by calling
703 wxProcess::Redirect(). If the child process IO is redirected, under Windows
704 the process window is not shown by default (this avoids having to flush an
705 unnecessary console for the processes which don't create any windows
706 anyhow) but a @c wxEXEC_NOHIDE flag can be used to prevent this from
707 happening, i.e. with this flag the child process window will be shown
710 Under Unix the flag @c wxEXEC_MAKE_GROUP_LEADER may be used to ensure that
711 the new process is a group leader (this will create a new session if
712 needed). Calling wxKill() passing wxKILL_CHILDREN will kill this process as
713 well as all of its children (except those which have started their own
716 The @c wxEXEC_NOEVENTS flag prevents processing of any events from taking
717 place while the child process is running. It should be only used for very
718 short-lived processes as otherwise the application windows risk becoming
719 unresponsive from the users point of view. As this flag only makes sense
720 with @c wxEXEC_SYNC, @c wxEXEC_BLOCK equal to the sum of both of these
721 flags is provided as a convenience.
723 @note Currently wxExecute() can only be used from the main thread, calling
724 this function from another thread will result in an assert failure in
725 debug build and won't work.
728 The command to execute and any parameters to pass to it as a single
729 string, i.e. "emacs file.txt".
731 Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
732 wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or
733 wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to
734 their combination, in wxEXEC_SYNC case.
736 An optional pointer to wxProcess.
738 @see wxShell(), wxProcess, @ref page_samples_exec
743 This function is called @c Wx::ExecuteStdoutStderr and it only takes the
744 @a command argument, and returns a 3-element list (@c status, @c output,
745 @c errors), where @c output and @c errors are array references.
748 long wxExecute(const wxString
& command
, int flags
= wxEXEC_ASYNC
,
749 wxProcess
* callback
= NULL
);
753 /** @ingroup group_funcmacro_procctrl */
756 This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
757 please see its documentation for general information.
759 This version takes an array of values: a command, any number of arguments,
763 The command to execute should be the first element of this array, any
764 additional ones are the command parameters and the array must be
765 terminated with a @NULL pointer.
767 Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
768 wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or
769 wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to
770 their combination, in wxEXEC_SYNC case.
772 An optional pointer to wxProcess.
776 long wxExecute(char** argv
, int flags
= wxEXEC_ASYNC
,
777 wxProcess
* callback
= NULL
);
778 long wxExecute(wchar_t** argv
, int flags
= wxEXEC_ASYNC
,
779 wxProcess
* callback
= NULL
);
782 /** @ingroup group_funcmacro_procctrl */
786 This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
787 please see its documentation for general information.
789 This version can be used to execute a process (always synchronously, the
790 contents of @a flags is or'd with @c wxEXEC_SYNC) and capture its output in
794 The command to execute and any parameters to pass to it as a single
797 Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
798 wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or
799 wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to
800 their combination, in wxEXEC_SYNC case.
804 long wxExecute(const wxString
& command
, wxArrayString
& output
,
808 This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
809 please see its documentation for general information.
811 This version adds the possibility to additionally capture the messages from
812 standard error output in the @a errors array.
815 The command to execute and any parameters to pass to it as a single
818 Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
819 wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or
820 wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to
821 their combination, in wxEXEC_SYNC case.
825 long wxExecute(const wxString
& command
, wxArrayString
& output
,
826 wxArrayString
& errors
, int flags
= 0);
829 Returns the number uniquely identifying the current process in the system.
830 If an error occurs, 0 is returned.
834 unsigned long wxGetProcessId();
837 Equivalent to the Unix kill function: send the given signal @a sig to the
838 process with PID @a pid. The valid signal values are:
843 wxSIGNONE = 0, // verify if the process exists under Unix
852 wxSIGKILL, // forcefully kill, dangerous!
858 wxSIGTERM // terminate the process gently
862 @c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning under
863 both Unix and Windows but all the other signals are equivalent to
864 @c wxSIGTERM under Windows.
866 Returns 0 on success, -1 on failure. If the @a rc parameter is not @NULL,
867 it will be filled with a value of the the @c wxKillError enum:
872 wxKILL_OK, // no error
873 wxKILL_BAD_SIGNAL, // no such signal
874 wxKILL_ACCESS_DENIED, // permission denied
875 wxKILL_NO_PROCESS, // no such process
876 wxKILL_ERROR // another, unspecified error
880 The @a flags parameter can be wxKILL_NOCHILDREN (the default), or
881 wxKILL_CHILDREN, in which case the child processes of this process will be
882 killed too. Note that under Unix, for wxKILL_CHILDREN to work you should
883 have created the process by passing wxEXEC_MAKE_GROUP_LEADER to
886 @see wxProcess::Kill(), wxProcess::Exists(), @ref page_samples_exec
890 int wxKill(long pid
, int sig
= wxSIGTERM
,
891 wxKillError rc
= NULL
, int flags
= 0);
894 Executes a command in an interactive shell window. If no command is
895 specified, then just the shell is spawned.
897 @see wxExecute(), @ref page_samples_exec
901 bool wxShell(const wxString
& command
= NULL
);
904 This function shuts down or reboots the computer depending on the value of
907 @note Doing this requires the corresponding access rights (superuser under
908 Unix, SE_SHUTDOWN privilege under Windows NT) and that this function
909 is only implemented under Unix and Win32.
912 Either wxSHUTDOWN_POWEROFF or wxSHUTDOWN_REBOOT
914 @returns @true on success, @false if an error occurred.
918 bool wxShutdown(wxShutdownFlags flags
);
924 /** @ingroup group_funcmacro_time */
928 Sleeps for the specified number of microseconds. The microsecond resolution
929 may not, in fact, be available on all platforms (currently only Unix
930 platforms with nanosleep(2) may provide it) in which case this is the same
931 as calling wxMilliSleep() with the argument of @e microseconds/1000.
935 void wxMicroSleep(unsigned long microseconds
);
938 Sleeps for the specified number of milliseconds. Notice that usage of this
939 function is encouraged instead of calling usleep(3) directly because the
940 standard @e usleep() function is not MT safe.
944 void wxMilliSleep(unsigned long milliseconds
);
947 Returns a string representing the current date and time.
954 Sleeps for the specified number of seconds.
958 void wxSleep(int secs
);
961 @deprecated This function is deprecated because its name is misleading:
962 notice that the argument is in milliseconds, not microseconds.
963 Please use either wxMilliSleep() or wxMicroSleep() depending on
964 the resolution you need.
966 Sleeps for the specified number of milliseconds.
970 void wxUsleep(unsigned long milliseconds
);