]>
git.saurik.com Git - wxWidgets.git/blob - interface/utils.h
a80edb9d3540cbecb6b715f59be9b57229235187
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxWindowDisabler class
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.
15 This comes in handy when you want to indicate to the user that the application
16 is currently busy and cannot respond to user input.
24 class wxWindowDisabler
28 Disables all top level windows of the applications with the exception of
29 @e winToSkip if it is not @NULL.
31 wxWindowDisabler(wxWindow
* winToSkip
= @NULL
);
34 Reenables back the windows disabled by the constructor.
44 This class makes it easy to tell your user that the program is temporarily busy.
45 Just create a wxBusyCursor object on the stack, and within the current scope,
46 the hourglass will be shown.
53 for (int i = 0; i 100000; i++)
57 It works by calling wxBeginBusyCursor in the constructor,
58 and wxEndBusyCursor in the destructor.
64 wxBeginBusyCursor, wxEndBusyCursor, wxWindowDisabler
70 Constructs a busy cursor object, calling wxBeginBusyCursor.
72 wxBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
);
75 Destroys the busy cursor object, calling wxEndBusyCursor.
81 // ============================================================================
82 // Global functions/macros
83 // ============================================================================
86 Returns the type of power source as one of @c wxPOWER_SOCKET,
87 @c wxPOWER_BATTERY or @c wxPOWER_UNKNOWN.
88 @c wxPOWER_UNKNOWN is also the default on platforms where this
89 feature is not implemented (currently everywhere but MS Windows).
91 wxPowerType
wxGetPowerType();
95 This function returns the "user id" also known as "login name" under Unix i.e.
96 something like "jsmith". It uniquely identifies the current user (on this
99 Under Windows or NT, this function first looks in the environment
100 variables USER and LOGNAME; if neither of these is found, the entry @b UserId
101 in the @b wxWidgets section of the WIN.INI file is tried.
103 The first variant of this function returns the login name if successful or an
104 empty string otherwise. The second (deprecated) function returns @true
105 if successful, @false otherwise.
109 wxString
wxGetUserId();
110 bool wxGetUserId(char * buf
, int sz
);
114 @b NB: This function is now obsolete, please use
115 wxLogFatalError instead.
117 Displays @e msg and exits. This writes to standard error under Unix,
118 and pops up a message box under Windows. Used for fatal internal
119 wxWidgets errors. See also wxError.
121 void wxFatalError(const wxString
& msg
,
122 const wxString
& title
= "wxWidgets Fatal Error");
125 Returns battery state as one of @c wxBATTERY_NORMAL_STATE,
126 @c wxBATTERY_LOW_STATE, @c wxBATTERY_CRITICAL_STATE,
127 @c wxBATTERY_SHUTDOWN_STATE or @c wxBATTERY_UNKNOWN_STATE.
128 @c wxBATTERY_UNKNOWN_STATE is also the default on platforms where
129 this feature is not implemented (currently everywhere but MS Windows).
131 wxBatteryState
wxGetBatteryState();
134 @b NB: This function is obsolete, please use
135 wxWindow::FindWindowByName instead.
137 Find a window by its name (as given in a window constructor or @b Create
139 If @e parent is @NULL, the search will start from all top-level
140 frames and dialog boxes; if non-@NULL, the search will be limited to the given
142 The search is recursive in both cases.
144 If no such named window is found, @b wxFindWindowByLabel is called.
146 wxWindow
* wxFindWindowByName(const wxString
& name
,
147 wxWindow
* parent
=@NULL
);
150 Changes the cursor back to the original cursor, for all windows in the
152 Use with wxBeginBusyCursor.
154 See also wxIsBusy, wxBusyCursor.
156 void wxEndBusyCursor();
159 This function is deprecated as the ids generated by it can conflict with the
160 ids defined by the user code, use @c wxID_ANY to assign ids which are
161 guaranteed to not conflict with the user-defined ids for the controls and menu
162 items you create instead of using this function.
163 Generates an integer identifier unique to this run of the program.
168 Ensures that ids subsequently generated by @b NewId do not clash with
171 void wxRegisterId(long id
);
174 @b NB: This function is now obsolete, replaced by Log
175 functions and wxLogDebug in particular.
177 Display a debugging message; under Windows, this will appear on the
178 debugger command window, and under Unix, it will be written to standard
181 The syntax is identical to @b printf: pass a format string and a
182 variable list of arguments.
184 @b Tip: under Windows, if your application crashes before the
185 message appears in the debugging window, put a wxYield call after
186 each wxDebugMsg call. wxDebugMsg seems to be broken under WIN32s
187 (at least for Watcom C++): preformat your messages and use OutputDebugString
190 void wxDebugMsg(const wxString
& fmt
, ... );
193 For normal keys, returns @true if the specified key is currently down.
195 For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns
196 @true if the key is toggled such that its LED indicator is lit. There is
197 currently no way to test whether togglable keys are up or down.
199 Even though there are virtual key codes defined for mouse buttons, they
200 cannot be used with this function currently.
202 bool wxGetKeyState(wxKeyCode key
);
205 Returns the string containing the description of the current platform in a
206 user-readable form. For example, this function may return strings like
207 @c Windows NT Version 4.0 or @c Linux 2.2.2 i386.
211 wxString
wxGetOsDescription();
214 Return the (current) user's home directory.
216 @sa wxGetUserHome, wxStandardPaths
218 wxString
wxGetHomeDir();
221 Sleeps for the specified number of milliseconds. Notice that usage of this
222 function is encouraged instead of calling usleep(3) directly because the
223 standard usleep() function is not MT safe.
225 void wxMilliSleep(unsigned long milliseconds
);
228 Sleeps for the specified number of microseconds. The microsecond resolution may
229 not, in fact, be available on all platforms (currently only Unix platforms with
230 nanosleep(2) may provide it) in which case this is the same as
231 wxMilliSleep(@e microseconds/1000).
233 void wxMicroSleep(unsigned long microseconds
);
236 Shows a message box with the information about the wxWidgets build used,
237 including its version, most important build parameters and the version of the
238 underlying GUI toolkit. This is mainly used for diagnostic purposes and can be
239 invoked by Ctrl-Alt-middle clicking on any wxWindow which doesn't otherwise
242 This function is new since wxWidgets version 2.9.0
244 void wxInfoMessageBox(wxWindow ( parent
= @NULL
);
247 Find a menu item identifier associated with the given frame's menu bar.
249 int wxFindMenuItemId(wxFrame
* frame
, const wxString
& menuString
,
250 const wxString
& itemString
);
253 This function enables or disables all top level windows. It is used by
256 void wxEnableTopLevelWindows(bool enable
= @
true);
259 Strips any menu codes from @e str and returns the result.
261 By default, the functions strips both the mnemonics character (@c '')
262 which is used to indicate a keyboard shortkey, and the accelerators, which are
263 used only in the menu items and are separated from the main text by the
264 @c \t (TAB) character. By using @e flags of
265 @c wxStrip_Mnemonics or @c wxStrip_Accel to strip only the former
266 or the latter part, respectively.
268 Notice that in most cases
269 wxMenuItem::GetLabelFromText or
270 wxControl::GetLabelText can be used instead.
272 wxString
wxStripMenuCodes(const wxString
& str
,
273 int flags
= wxStrip_All
);
276 @b NB: This function is now obsolete, please use wxLogError
279 Displays @e msg and continues. This writes to standard error under
280 Unix, and pops up a message box under Windows. Used for internal
281 wxWidgets errors. See also wxFatalError.
283 void wxError(const wxString
& msg
,
284 const wxString
& title
= "wxWidgets Internal Error");
287 Open the @e url in user's default browser. If @e flags parameter contains
288 @c wxBROWSER_NEW_WINDOW flag, a new window is opened for the URL
289 (currently this is only supported under Windows). The @e url may also be a
290 local file path (with or without @c file:// prefix), if it doesn't
291 correspond to an existing file and the URL has no scheme @c http:// is
292 prepended to it by default.
294 Returns @true if the application was successfully launched.
296 Note that for some configurations of the running user, the application which
297 is launched to open the given URL may be URL-dependent (e.g. a browser may be
299 local URLs while another one may be used for remote URLs).
301 bool wxLaunchDefaultBrowser(const wxString
& url
, int flags
= 0);
304 Executes a command in an interactive shell window. If no command is
305 specified, then just the shell is spawned.
307 See also wxExecute, @ref overview_sampleexec "Exec sample".
309 bool wxShell(const wxString
& command
= @NULL
);
312 Gets the version and the operating system ID for currently running OS.
313 See wxPlatformInfo for more details about wxOperatingSystemId.
315 @sa ::wxGetOsDescription, wxPlatformInfo
317 wxOperatingSystemId
wxGetOsVersion(int * major
= @NULL
,
318 int * minor
= @NULL
);
321 Returns the FQDN (fully qualified domain host name) or an empty string on
326 wxString
wxGetFullHostName();
329 Changes the cursor to the given cursor for all windows in the application.
330 Use wxEndBusyCursor to revert the cursor back
331 to its previous state. These two calls can be nested, and a counter
332 ensures that only the outer calls take effect.
334 See also wxIsBusy, wxBusyCursor.
336 void wxBeginBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
);
339 Tells the system to delete the specified object when
340 all other events have been processed. In some environments, it is
341 necessary to use this instead of deleting a frame directly with the
342 delete operator, because some GUIs will still send events to a deleted window.
344 Now obsolete: use wxWindow::Close instead.
346 void wxPostDelete(wxObject
* object
);
349 @b NB: This function is obsolete, please use
350 wxWindow::FindWindowByLabel instead.
352 Find a window by its label. Depending on the type of window, the label may be a
354 or panel item label. If @e parent is @NULL, the search will start from all
356 frames and dialog boxes; if non-@NULL, the search will be limited to the given
358 The search is recursive in both cases.
360 wxWindow
* wxFindWindowByLabel(const wxString
& label
,
361 wxWindow
* parent
=@NULL
);
364 This function is similar to wxYield, except that it disables the user input to
365 all program windows before calling wxYield and re-enables it again
366 afterwards. If @e win is not @NULL, this window will remain enabled,
367 allowing the implementation of some limited user interaction.
369 Returns the result of the call to ::wxYield.
371 bool wxSafeYield(wxWindow
* win
= @NULL
, bool onlyIfNeeded
= @
false);
374 Returns the mouse position in screen coordinates.
376 wxPoint
wxGetMousePosition();
379 Loads a user-defined Windows resource as a string. If the resource is found,
381 a new character array and copies the data into it. A pointer to this data is
382 returned. If unsuccessful, @NULL is returned.
384 The resource must be defined in the @c .rc file using the following syntax:
386 myResource TEXT file.ext
389 where @c file.ext is a file that the resource compiler can find.
391 This function is available under Windows only.
393 wxString
wxLoadUserResource(const wxString
& resourceName
,
394 const wxString
& resourceType
="TEXT");
397 Returns the amount of free memory in bytes under environments which
398 support it, and -1 if not supported or failed to perform measurement.
400 wxMemorySize
wxGetFreeMemory();
403 This is a macro defined as @c getenv() or its wide char version in Unicode
406 Note that under Win32 it may not return correct value for the variables set
407 with wxSetEnv, use wxGetEnv function
410 wxChar
* wxGetEnv(const wxString
& var
);
414 Copies the current host machine's name into the supplied buffer. Please note
415 that the returned name is @e not fully qualified, i.e. it does not include
418 Under Windows or NT, this function first looks in the environment
419 variable SYSTEM_NAME; if this is not found, the entry @b HostName
420 in the @b wxWidgets section of the WIN.INI file is tried.
422 The first variant of this function returns the hostname if successful or an
423 empty string otherwise. The second (deprecated) function returns @true
424 if successful, @false otherwise.
426 @sa wxGetFullHostName
428 wxString
wxGetHostName();
429 bool wxGetHostName(char * buf
, int sz
);
433 Returns the current value of the environment variable @e var in @e value.
434 @e value may be @NULL if you just want to know if the variable exists
435 and are not interested in its value.
437 Returns @true if the variable exists, @false otherwise.
439 bool wxGetEnv(const wxString
& var
, wxString
* value
);
442 Under X only, returns the current display name. See also wxSetDisplayName.
444 wxString
wxGetDisplayName();
447 Ring the system bell.
449 Note that this function is categorized as a GUI one and so is not thread-safe.
454 Returns the home directory for the given user. If the @e user is empty
455 (default value), this function behaves like
456 wxGetHomeDir i.e. returns the current user home
459 If the home directory couldn't be determined, an empty string is returned.
461 wxString
wxGetUserHome(const wxString
& user
= "");
465 @b wxPerl note: In wxPerl this function is called @c Wx::ExecuteStdoutStderr
466 and it only takes the @c command argument,
467 and returns a 3-element list @c ( status, output, errors ), where
468 @c output and @c errors are array references.
470 Executes another program in Unix or Windows.
472 The first form takes a command string, such as @c "emacs file.txt".
474 The second form takes an array of values: a command, any number of
475 arguments, terminated by @NULL.
477 The semantics of the third and fourth versions is different from the first two
478 and is described in more details below.
480 If @e flags parameter contains @c wxEXEC_ASYNC flag (the default), flow
481 of control immediately returns. If it contains @c wxEXEC_SYNC, the current
482 application waits until the other program has terminated.
484 In the case of synchronous execution, the return value is the exit code of
485 the process (which terminates by the moment the function returns) and will be
486 -1 if the process couldn't be started and typically 0 if the process
487 terminated successfully. Also, while waiting for the process to
488 terminate, wxExecute will call wxYield. Because of this, by
489 default this function disables all application windows to avoid unexpected
490 reentrancies which could result from the users interaction with the program
491 while the child process is running. If you are sure that it is safe to not
492 disable the program windows, you may pass @c wxEXEC_NODISABLE flag to
493 prevent this automatic disabling from happening.
495 For asynchronous execution, however, the return value is the process id and
496 zero value indicates that the command could not be executed. As an added
497 complication, the return value of -1 in this case indicates that we didn't
498 launch a new process, but connected to the running one (this can only happen in
499 case of using DDE under Windows for command execution). In particular, in this,
500 and only this, case the calling code will not get the notification about
503 If callback isn't @NULL and if execution is asynchronous,
504 wxProcess::OnTerminate will be called when
505 the process finishes. Specifying this parameter also allows you to redirect the
506 standard input and/or output of the process being launched by calling
507 wxProcess::Redirect. If the child process IO is redirected,
508 under Windows the process window is not shown by default (this avoids having to
509 flush an unnecessary console for the processes which don't create any windows
510 anyhow) but a @c wxEXEC_NOHIDE flag can be used to prevent this from
511 happening, i.e. with this flag the child process window will be shown normally.
513 Under Unix the flag @c wxEXEC_MAKE_GROUP_LEADER may be used to ensure
514 that the new process is a group leader (this will create a new session if
515 needed). Calling wxKill passing wxKILL_CHILDREN will
516 kill this process as well as all of its children (except those which have
517 started their own session).
519 The @c wxEXEC_NOEVENTS flag prevents processing of any events from taking
520 place while the child process is running. It should be only used for very
521 short-lived processes as otherwise the application windows risk becoming
522 unresponsive from the users point of view. As this flag only makes sense with
523 @c wxEXEC_SYNC, @c wxEXEC_BLOCK equal to the sum of both of these flags
524 is provided as a convenience.
526 Finally, you may use the third overloaded version of this function to execute
527 a process (always synchronously, the contents of @e flags is or'd with
528 @c wxEXEC_SYNC) and capture its output in the array @e output. The
529 fourth version adds the possibility to additionally capture the messages from
530 standard error output in the @e errors array.
532 @b NB: Currently wxExecute() can only be used from the main thread, calling
533 this function from another thread will result in an assert failure in debug
534 build and won't work.
537 The command to execute and any parameters to pass to it as a
541 The command to execute should be the first element of this
542 array, any additional ones are the command parameters and the array must be
543 terminated with a @NULL pointer.
546 Combination of bit masks wxEXEC_ASYNC,
547 wxEXEC_SYNC and wxEXEC_NOHIDE
550 An optional pointer to wxProcess
552 @sa wxShell, wxProcess, @ref overview_sampleexec "Exec sample".
554 long wxExecute(const wxString
& command
, int sync
= wxEXEC_ASYNC
,
555 wxProcess
* callback
= @NULL
);
556 wxPerl note
: long wxExecute(char ** argv
,
557 int flags
= wxEXEC_ASYNC
,
558 wxProcess
* callback
= @NULL
);
559 wxPerl note
: long wxExecute(const wxString
& command
,
560 wxArrayString
& output
,
562 wxPerl note
: long wxExecute(const wxString
& command
,
563 wxArrayString
& output
,
564 wxArrayString
& errors
,
569 Returns a string representing the current date and time.
574 Returns @true if the operating system the program is running under is 64 bit.
575 The check is performed at run-time and may differ from the value available at
576 compile-time (at compile-time you can just check if @c sizeof(void*)==8)
577 since the program could be running in emulation mode or in a mixed 32/64 bit
579 (bi-architecture operating system).
581 Very important: this function is not 100% reliable on some systems given the
583 that there isn't always a standard way to do a reliable check on the OS
586 bool wxIsPlatform64Bit();
589 Returns the number uniquely identifying the current process in the system.
591 If an error occurs, 0 is returned.
593 unsigned long wxGetProcessId();
596 Equivalent to the Unix kill function: send the given signal @e sig to the
597 process with PID @e pid. The valid signal values are
601 wxSIGNONE = 0, // verify if the process exists under Unix
610 wxSIGKILL, // forcefully kill, dangerous!
616 wxSIGTERM // terminate the process gently
620 @c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning
621 under both Unix and Windows but all the other signals are equivalent to
622 @c wxSIGTERM under Windows.
624 Returns 0 on success, -1 on failure. If @e rc parameter is not @NULL, it will
625 be filled with an element of @c wxKillError enum:
629 wxKILL_OK, // no error
630 wxKILL_BAD_SIGNAL, // no such signal
631 wxKILL_ACCESS_DENIED, // permission denied
632 wxKILL_NO_PROCESS, // no such process
633 wxKILL_ERROR // another, unspecified error
637 The @e flags parameter can be wxKILL_NOCHILDREN (the default),
638 or wxKILL_CHILDREN, in which case the child processes of this
639 process will be killed too. Note that under Unix, for wxKILL_CHILDREN
640 to work you should have created the process by passing wxEXEC_MAKE_GROUP_LEADER
643 @sa wxProcess::Kill, wxProcess::Exists, @ref overview_sampleexec "Exec sample"
645 int wxKill(long pid
, int sig
= wxSIGTERM
, wxKillError rc
= @NULL
,
649 Returns the current state of the mouse. Returns a wxMouseState
650 instance that contains the current position of the mouse pointer in
651 screen coordinates, as well as boolean values indicating the up/down
652 status of the mouse buttons and the modifier keys.
654 wxMouseState
wxGetMouseState();
657 Returns @true if between two wxBeginBusyCursor and
658 wxEndBusyCursor calls.
660 See also wxBusyCursor.
666 Copies the user's email address into the supplied buffer, by
667 concatenating the values returned by wxGetFullHostName
670 Returns @true if successful, @false otherwise.
672 wxString
wxGetEmailAddress();
673 bool wxGetEmailAddress(char * buf
, int sz
);
677 Sleeps for the specified number of seconds.
679 void wxSleep(int secs
);
682 Sets the value of the environment variable @e var (adding it if necessary)
685 Returns @true on success.
689 bool wxSetEnv(const wxString
& var
, const wxString
& value
);
692 Returns @true if the current platform is little endian (instead of big
694 The check is performed at run-time.
696 @sa @ref overview_byteordermacros "Byte order macros"
698 bool wxIsPlatformLittleEndian();
701 Under X only, sets the current display name. This is the X host and display
703 as "colonsay:0.0", and the function indicates which display should be used for
705 windows from this point on. Setting the display within an application allows
709 See also wxGetDisplayName.
711 void wxSetDisplayName(const wxString
& displayName
);