]>
git.saurik.com Git - wxWidgets.git/blob - interface/utils.h
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.
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.
23 class wxWindowDisabler
27 Disables all top level windows of the applications with the exception of
28 @a winToSkip if it is not @NULL.
30 wxWindowDisabler(wxWindow
* winToSkip
= NULL
);
33 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.
63 @see wxBeginBusyCursor(), wxEndBusyCursor(), wxWindowDisabler
69 Constructs a busy cursor object, calling wxBeginBusyCursor().
71 wxBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
);
74 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
98 Under Windows or NT, this function first looks in the environment
99 variables USER and LOGNAME; if neither of these is found, the entry @b UserId
100 in the @b wxWidgets section of the WIN.INI file is tried.
101 The first variant of this function returns the login name if successful or an
102 empty string otherwise. The second (deprecated) function returns @true
103 if successful, @false otherwise.
107 wxString
wxGetUserId();
108 bool wxGetUserId(char* buf
, int sz
);
112 @b NB: This function is now obsolete, please use
113 wxLogFatalError() instead.
114 Displays @a msg and exits. This writes to standard error under Unix,
115 and pops up a message box under Windows. Used for fatal internal
116 wxWidgets errors. See also wxError().
118 void wxFatalError(const wxString
& msg
,
119 const wxString
& title
= "wxWidgets Fatal Error");
122 Returns battery state as one of @c wxBATTERY_NORMAL_STATE,
123 @c wxBATTERY_LOW_STATE, @c wxBATTERY_CRITICAL_STATE,
124 @c wxBATTERY_SHUTDOWN_STATE or @c wxBATTERY_UNKNOWN_STATE.
125 @c wxBATTERY_UNKNOWN_STATE is also the default on platforms where
126 this feature is not implemented (currently everywhere but MS Windows).
128 wxBatteryState
wxGetBatteryState();
131 @b NB: This function is obsolete, please use
132 wxWindow::FindWindowByName instead.
133 Find a window by its name (as given in a window constructor or @b Create
135 If @a parent is @NULL, the search will start from all top-level
136 frames and dialog boxes; if non-@NULL, the search will be limited to the given
138 The search is recursive in both cases.
139 If no such named window is found, @b wxFindWindowByLabel is called.
141 wxWindow
* wxFindWindowByName(const wxString
& name
,
142 wxWindow
* parent
= NULL
);
145 Changes the cursor back to the original cursor, for all windows in the
147 Use with wxBeginBusyCursor().
148 See also wxIsBusy(), wxBusyCursor.
150 void wxEndBusyCursor();
153 This function is deprecated as the ids generated by it can conflict with the
154 ids defined by the user code, use @c wxID_ANY to assign ids which are
155 guaranteed to not conflict with the user-defined ids for the controls and menu
156 items you create instead of using this function.
158 Generates an integer identifier unique to this run of the program.
163 Ensures that ids subsequently generated by @b NewId do not clash with
166 void wxRegisterId(long id
);
169 @b NB: This function is now obsolete, replaced by Log
170 functions() and wxLogDebug() in particular.
171 Display a debugging message; under Windows, this will appear on the
172 debugger command window, and under Unix, it will be written to standard
174 The syntax is identical to @b printf: pass a format string and a
175 variable list of arguments.
176 @b Tip: under Windows, if your application crashes before the
177 message appears in the debugging window, put a wxYield call after
178 each wxDebugMsg call. wxDebugMsg seems to be broken under WIN32s
179 (at least for Watcom C++): preformat your messages and use OutputDebugString
182 void wxDebugMsg(const wxString
& fmt
, ... );
185 For normal keys, returns @true if the specified key is currently down.
186 For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns
187 @true if the key is toggled such that its LED indicator is lit. There is
188 currently no way to test whether togglable keys are up or down.
189 Even though there are virtual key codes defined for mouse buttons, they
190 cannot be used with this function currently.
192 bool wxGetKeyState(wxKeyCode key
);
195 Returns the string containing the description of the current platform in a
196 user-readable form. For example, this function may return strings like
197 @c Windows NT Version 4.0 or @c Linux 2.2.2 i386.
199 @see ::wxGetOsVersion
201 wxString
wxGetOsDescription();
204 Return the (current) user's home directory.
206 @see wxGetUserHome(), wxStandardPaths
208 wxString
wxGetHomeDir();
211 Sleeps for the specified number of milliseconds. Notice that usage of this
212 function is encouraged instead of calling usleep(3) directly because the
213 standard usleep() function is not MT safe.
215 void wxMilliSleep(unsigned long milliseconds
);
218 Sleeps for the specified number of microseconds. The microsecond resolution may
219 not, in fact, be available on all platforms (currently only Unix platforms with
220 nanosleep(2) may provide it) in which case this is the same as
221 wxMilliSleep()(@e microseconds/1000).
223 void wxMicroSleep(unsigned long microseconds
);
226 Shows a message box with the information about the wxWidgets build used,
227 including its version, most important build parameters and the version of the
228 underlying GUI toolkit. This is mainly used for diagnostic purposes and can be
229 invoked by Ctrl-Alt-middle clicking on any wxWindow which doesn't otherwise
234 void wxInfoMessageBox(wxWindow ( parent
= NULL
);
237 Find a menu item identifier associated with the given frame's menu bar.
239 int wxFindMenuItemId(wxFrame
* frame
, const wxString
& menuString
,
240 const wxString
& itemString
);
243 This function enables or disables all top level windows. It is used by
246 void wxEnableTopLevelWindows(bool enable
= true);
249 Strips any menu codes from @a str and returns the result.
250 By default, the functions strips both the mnemonics character (@c '')
251 which is used to indicate a keyboard shortkey, and the accelerators, which are
252 used only in the menu items and are separated from the main text by the
253 @c \t (TAB) character. By using @a flags of
254 @c wxStrip_Mnemonics or @c wxStrip_Accel to strip only the former
255 or the latter part, respectively.
256 Notice that in most cases
257 wxMenuItem::GetLabelFromText or
258 wxControl::GetLabelText can be used instead.
260 wxString
wxStripMenuCodes(const wxString
& str
,
261 int flags
= wxStrip_All
);
264 @b NB: This function is now obsolete, please use wxLogError()
266 Displays @a msg and continues. This writes to standard error under
267 Unix, and pops up a message box under Windows. Used for internal
268 wxWidgets errors. See also wxFatalError().
270 void wxError(const wxString
& msg
,
271 const wxString
& title
= "wxWidgets Internal Error");
274 Open the @a url in user's default browser. If @a flags parameter contains
275 @c wxBROWSER_NEW_WINDOW flag, a new window is opened for the URL
276 (currently this is only supported under Windows). The @a url may also be a
277 local file path (with or without @c file:// prefix), if it doesn't
278 correspond to an existing file and the URL has no scheme @c http:// is
279 prepended to it by default.
280 Returns @true if the application was successfully launched.
281 Note that for some configurations of the running user, the application which
282 is launched to open the given URL may be URL-dependent (e.g. a browser may be
284 local URLs while another one may be used for remote URLs).
286 bool wxLaunchDefaultBrowser(const wxString
& url
, int flags
= 0);
289 Executes a command in an interactive shell window. If no command is
290 specified, then just the shell is spawned.
291 See also wxExecute(), @ref overview_sampleexec "Exec sample".
293 bool wxShell(const wxString
& command
= NULL
);
296 Gets the version and the operating system ID for currently running OS.
297 See wxPlatformInfo for more details about wxOperatingSystemId.
299 @see ::wxGetOsDescription, wxPlatformInfo
301 wxOperatingSystemId
wxGetOsVersion(int* major
= NULL
,
305 Returns the FQDN (fully qualified domain host name) or an empty string on
310 wxString
wxGetFullHostName();
313 Changes the cursor to the given cursor for all windows in the application.
314 Use wxEndBusyCursor() to revert the cursor back
315 to its previous state. These two calls can be nested, and a counter
316 ensures that only the outer calls take effect.
317 See also wxIsBusy(), wxBusyCursor.
319 void wxBeginBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
);
322 Tells the system to delete the specified object when
323 all other events have been processed. In some environments, it is
324 necessary to use this instead of deleting a frame directly with the
325 delete operator, because some GUIs will still send events to a deleted window.
326 Now obsolete: use wxWindow::Close instead.
328 void wxPostDelete(wxObject
* object
);
331 @b NB: This function is obsolete, please use
332 wxWindow::FindWindowByLabel instead.
333 Find a window by its label. Depending on the type of window, the label may be a
335 or panel item label. If @a parent is @NULL, the search will start from all
337 frames and dialog boxes; if non-@NULL, the search will be limited to the given
339 The search is recursive in both cases.
341 wxWindow
* wxFindWindowByLabel(const wxString
& label
,
342 wxWindow
* parent
= NULL
);
346 Returns the mouse position in screen coordinates.
348 wxPoint
wxGetMousePosition();
351 Loads a user-defined Windows resource as a string. If the resource is found,
353 a new character array and copies the data into it. A pointer to this data is
354 returned. If unsuccessful, @NULL is returned.
355 The resource must be defined in the @c .rc file using the following syntax:
358 myResource TEXT file.ext
361 where @c file.ext is a file that the resource compiler can find.
362 This function is available under Windows only.
364 wxString
wxLoadUserResource(const wxString
& resourceName
,
365 const wxString
& resourceType
= "TEXT");
368 Returns the amount of free memory in bytes under environments which
369 support it, and -1 if not supported or failed to perform measurement.
371 wxMemorySize
wxGetFreeMemory();
374 This is a macro defined as @c getenv() or its wide char version in Unicode
376 Note that under Win32 it may not return correct value for the variables set
377 with wxSetEnv(), use wxGetEnv() function
380 wxChar
* wxGetEnv(const wxString
& var
);
384 Copies the current host machine's name into the supplied buffer. Please note
385 that the returned name is @e not fully qualified, i.e. it does not include
387 Under Windows or NT, this function first looks in the environment
388 variable SYSTEM_NAME; if this is not found, the entry @b HostName
389 in the @b wxWidgets section of the WIN.INI file is tried.
390 The first variant of this function returns the hostname if successful or an
391 empty string otherwise. The second (deprecated) function returns @true
392 if successful, @false otherwise.
394 @see wxGetFullHostName()
396 wxString
wxGetHostName();
397 bool wxGetHostName(char* buf
, int sz
);
401 Returns the current value of the environment variable @a var in @e value.
402 @a value may be @NULL if you just want to know if the variable exists
403 and are not interested in its value.
404 Returns @true if the variable exists, @false otherwise.
406 bool wxGetEnv(const wxString
& var
, wxString
* value
);
409 Under X only, returns the current display name. See also wxSetDisplayName().
411 wxString
wxGetDisplayName();
414 Ring the system bell.
415 Note that this function is categorized as a GUI one and so is not thread-safe.
420 Returns the home directory for the given user. If the @a user is empty
421 (default value), this function behaves like
422 wxGetHomeDir() i.e. returns the current user home
424 If the home directory couldn't be determined, an empty string is returned.
426 wxString
wxGetUserHome(const wxString
& user
= "");
430 @b wxPerl note: In wxPerl this function is called @c Wx::ExecuteStdoutStderr
431 and it only takes the @c command argument,
432 and returns a 3-element list @c ( status, output, errors ), where
433 @c output and @c errors are array references.
434 Executes another program in Unix or Windows.
435 The first form takes a command string, such as @c "emacs file.txt".
436 The second form takes an array of values: a command, any number of
437 arguments, terminated by @NULL.
438 The semantics of the third and fourth versions is different from the first two
439 and is described in more details below.
440 If @a flags parameter contains @c wxEXEC_ASYNC flag (the default), flow
441 of control immediately returns. If it contains @c wxEXEC_SYNC, the current
442 application waits until the other program has terminated.
443 In the case of synchronous execution, the return value is the exit code of
444 the process (which terminates by the moment the function returns) and will be
445 -1 if the process couldn't be started and typically 0 if the process
446 terminated successfully. Also, while waiting for the process to
447 terminate, wxExecute will call wxYield(). Because of this, by
448 default this function disables all application windows to avoid unexpected
449 reentrancies which could result from the users interaction with the program
450 while the child process is running. If you are sure that it is safe to not
451 disable the program windows, you may pass @c wxEXEC_NODISABLE flag to
452 prevent this automatic disabling from happening.
453 For asynchronous execution, however, the return value is the process id and
454 zero value indicates that the command could not be executed. As an added
455 complication, the return value of -1 in this case indicates that we didn't
456 launch a new process, but connected to the running one (this can only happen in
457 case of using DDE under Windows for command execution). In particular, in this,
458 and only this, case the calling code will not get the notification about
460 If callback isn't @NULL and if execution is asynchronous,
461 wxProcess::OnTerminate will be called when
462 the process finishes. Specifying this parameter also allows you to redirect the
463 standard input and/or output of the process being launched by calling
464 wxProcess::Redirect. If the child process IO is redirected,
465 under Windows the process window is not shown by default (this avoids having to
466 flush an unnecessary console for the processes which don't create any windows
467 anyhow) but a @c wxEXEC_NOHIDE flag can be used to prevent this from
468 happening, i.e. with this flag the child process window will be shown normally.
469 Under Unix the flag @c wxEXEC_MAKE_GROUP_LEADER may be used to ensure
470 that the new process is a group leader (this will create a new session if
471 needed). Calling wxKill() passing wxKILL_CHILDREN will
472 kill this process as well as all of its children (except those which have
473 started their own session).
474 The @c wxEXEC_NOEVENTS flag prevents processing of any events from taking
475 place while the child process is running. It should be only used for very
476 short-lived processes as otherwise the application windows risk becoming
477 unresponsive from the users point of view. As this flag only makes sense with
478 @c wxEXEC_SYNC, @c wxEXEC_BLOCK equal to the sum of both of these flags
479 is provided as a convenience.
480 Finally, you may use the third overloaded version of this function to execute
481 a process (always synchronously, the contents of @a flags is or'd with
482 @c wxEXEC_SYNC) and capture its output in the array @e output. The
483 fourth version adds the possibility to additionally capture the messages from
484 standard error output in the @a errors array.
485 @b NB: Currently wxExecute() can only be used from the main thread, calling
486 this function from another thread will result in an assert failure in debug
487 build and won't work.
490 The command to execute and any parameters to pass to it as a
493 The command to execute should be the first element of this
494 array, any additional ones are the command parameters and the array must be
495 terminated with a @NULL pointer.
497 Combination of bit masks wxEXEC_ASYNC,
498 wxEXEC_SYNC and wxEXEC_NOHIDE
500 An optional pointer to wxProcess
502 @see wxShell(), wxProcess, @ref overview_sampleexec "Exec sample".
504 long wxExecute(const wxString
& command
, int sync
= wxEXEC_ASYNC
,
505 wxProcess
* callback
= NULL
);
506 wxPerl note
: long wxExecute(char** argv
,
507 int flags
= wxEXEC_ASYNC
,
508 wxProcess
* callback
= NULL
);
509 wxPerl note
: long wxExecute(const wxString
& command
,
510 wxArrayString
& output
,
512 wxPerl note
: long wxExecute(const wxString
& command
,
513 wxArrayString
& output
,
514 wxArrayString
& errors
,
519 Returns a string representing the current date and time.
524 Returns @true if the operating system the program is running under is 64 bit.
525 The check is performed at run-time and may differ from the value available at
526 compile-time (at compile-time you can just check if @c sizeof(void*)==8)
527 since the program could be running in emulation mode or in a mixed 32/64 bit
529 (bi-architecture operating system).
530 Very important: this function is not 100% reliable on some systems given the
532 that there isn't always a standard way to do a reliable check on the OS
535 bool wxIsPlatform64Bit();
538 Returns the number uniquely identifying the current process in the system.
539 If an error occurs, 0 is returned.
541 unsigned long wxGetProcessId();
544 Equivalent to the Unix kill function: send the given signal @a sig to the
545 process with PID @e pid. The valid signal values are
550 wxSIGNONE = 0, // verify if the process exists under Unix
559 wxSIGKILL, // forcefully kill, dangerous!
565 wxSIGTERM // terminate the process gently
569 @c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning
570 under both Unix and Windows but all the other signals are equivalent to
571 @c wxSIGTERM under Windows.
572 Returns 0 on success, -1 on failure. If @a rc parameter is not @NULL, it will
573 be filled with an element of @c wxKillError enum:
578 wxKILL_OK, // no error
579 wxKILL_BAD_SIGNAL, // no such signal
580 wxKILL_ACCESS_DENIED, // permission denied
581 wxKILL_NO_PROCESS, // no such process
582 wxKILL_ERROR // another, unspecified error
586 The @a flags parameter can be wxKILL_NOCHILDREN (the default),
587 or wxKILL_CHILDREN, in which case the child processes of this
588 process will be killed too. Note that under Unix, for wxKILL_CHILDREN
589 to work you should have created the process by passing wxEXEC_MAKE_GROUP_LEADER
592 @see wxProcess::Kill, wxProcess::Exists, @ref overview_sampleexec "Exec sample"
594 int wxKill(long pid
, int sig
= wxSIGTERM
, wxKillError rc
= NULL
,
598 Returns the current state of the mouse. Returns a wxMouseState
599 instance that contains the current position of the mouse pointer in
600 screen coordinates, as well as boolean values indicating the up/down
601 status of the mouse buttons and the modifier keys.
603 wxMouseState
wxGetMouseState();
606 Returns @true if between two wxBeginBusyCursor() and
607 wxEndBusyCursor() calls.
608 See also wxBusyCursor.
614 Copies the user's email address into the supplied buffer, by
615 concatenating the values returned by wxGetFullHostName()
617 Returns @true if successful, @false otherwise.
619 wxString
wxGetEmailAddress();
620 bool wxGetEmailAddress(char* buf
, int sz
);
624 Sleeps for the specified number of seconds.
626 void wxSleep(int secs
);
629 Sets the value of the environment variable @a var (adding it if necessary)
631 Returns @true on success.
635 bool wxSetEnv(const wxString
& var
, const wxString
& value
);
638 Returns @true if the current platform is little endian (instead of big
640 The check is performed at run-time.
642 @see @ref overview_byteordermacros "Byte order macros"
644 bool wxIsPlatformLittleEndian();
647 Under X only, sets the current display name. This is the X host and display
649 as "colonsay:0.0", and the function indicates which display should be used for
651 windows from this point on. Setting the display within an application allows
654 See also wxGetDisplayName().
656 void wxSetDisplayName(const wxString
& displayName
);