]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: utils.h | |
fbec75d0 | 3 | // Purpose: interface of various utility classes and functions |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
50e55c13 RD |
9 | /** |
10 | Signal constants used by wxProcess. | |
11 | */ | |
12 | enum wxSignal | |
13 | { | |
14 | wxSIGNONE = 0, //!< verify if the process exists under Unix | |
15 | wxSIGHUP, | |
16 | wxSIGINT, | |
17 | wxSIGQUIT, | |
18 | wxSIGILL, | |
19 | wxSIGTRAP, | |
20 | wxSIGABRT, | |
21 | wxSIGEMT, | |
22 | wxSIGFPE, | |
23 | wxSIGKILL, //!< forcefully kill, dangerous! | |
24 | wxSIGBUS, | |
25 | wxSIGSEGV, | |
26 | wxSIGSYS, | |
27 | wxSIGPIPE, | |
28 | wxSIGALRM, | |
29 | wxSIGTERM //!< terminate the process gently | |
30 | }; | |
31 | ||
32 | /** | |
33 | Return values for wxProcess::Kill. | |
34 | */ | |
35 | enum wxKillError | |
36 | { | |
37 | wxKILL_OK, //!< no error | |
38 | wxKILL_BAD_SIGNAL, //!< no such signal | |
39 | wxKILL_ACCESS_DENIED, //!< permission denied | |
40 | wxKILL_NO_PROCESS, //!< no such process | |
41 | wxKILL_ERROR //!< another, unspecified error | |
42 | }; | |
43 | ||
44 | enum wxKillFlags | |
45 | { | |
46 | wxKILL_NOCHILDREN = 0, //!< don't kill children | |
47 | wxKILL_CHILDREN = 1 //!< kill children | |
48 | }; | |
49 | ||
50 | enum wxShutdownFlags | |
51 | { | |
52 | wxSHUTDOWN_FORCE = 1, //!< can be combined with other flags (MSW-only) | |
53 | wxSHUTDOWN_POWEROFF = 2, //!< power off the computer | |
54 | wxSHUTDOWN_REBOOT = 4, //!< shutdown and reboot | |
55 | wxSHUTDOWN_LOGOFF = 8 //!< close session (currently MSW-only) | |
56 | }; | |
57 | ||
58 | ||
23324ae1 FM |
59 | /** |
60 | @class wxWindowDisabler | |
7c913512 | 61 | |
fbec75d0 BP |
62 | This class disables all windows of the application (may be with the |
63 | exception of one of them) in its constructor and enables them back in its | |
64 | destructor. | |
2ecd1756 VZ |
65 | |
66 | This is useful when you want to indicate to the user that the application | |
23324ae1 | 67 | is currently busy and cannot respond to user input. |
7c913512 | 68 | |
23324ae1 | 69 | @library{wxcore} |
fbec75d0 | 70 | @category{misc} |
7c913512 | 71 | |
e54c96f1 | 72 | @see wxBusyCursor |
23324ae1 | 73 | */ |
7c913512 | 74 | class wxWindowDisabler |
23324ae1 FM |
75 | { |
76 | public: | |
2ecd1756 VZ |
77 | /** |
78 | Disables all top level windows of the applications. | |
79 | ||
80 | If @a disable is @c false nothing is done. This can be convenient if | |
81 | the windows should be disabled depending on some condition. | |
82 | ||
83 | @since 2.9.0 | |
84 | */ | |
85 | wxWindowDisabler(bool disable = true); | |
86 | ||
23324ae1 | 87 | /** |
fbec75d0 BP |
88 | Disables all top level windows of the applications with the exception |
89 | of @a winToSkip if it is not @NULL. | |
40cb56e2 VZ |
90 | |
91 | Notice that under MSW if @a winToSkip appears in the taskbar, the user | |
92 | will be able to close the entire application (even though its main | |
93 | window is disabled) by right clicking on the taskbar icon and selecting | |
94 | the appropriate "Close" command from the context menu. To prevent this | |
95 | from happening you may want to use wxFRAME_TOOL_WINDOW, if applicable, | |
96 | or wxFRAME_NO_TASKBAR style when creating the window that will remain | |
97 | enabled. | |
23324ae1 | 98 | */ |
2ecd1756 | 99 | wxWindowDisabler(wxWindow* winToSkip); |
23324ae1 FM |
100 | |
101 | /** | |
fbec75d0 | 102 | Reenables the windows disabled by the constructor. |
23324ae1 FM |
103 | */ |
104 | ~wxWindowDisabler(); | |
105 | }; | |
106 | ||
107 | ||
e54c96f1 | 108 | |
23324ae1 FM |
109 | /** |
110 | @class wxBusyCursor | |
7c913512 | 111 | |
fbec75d0 BP |
112 | This class makes it easy to tell your user that the program is temporarily |
113 | busy. Just create a wxBusyCursor object on the stack, and within the | |
114 | current scope, the hourglass will be shown. | |
7c913512 | 115 | |
23324ae1 | 116 | For example: |
7c913512 | 117 | |
23324ae1 FM |
118 | @code |
119 | wxBusyCursor wait; | |
7c913512 | 120 | |
fbec75d0 | 121 | for (int i = 0; i < 100000; i++) |
23324ae1 FM |
122 | DoACalculation(); |
123 | @endcode | |
7c913512 | 124 | |
fbec75d0 BP |
125 | It works by calling wxBeginBusyCursor() in the constructor, and |
126 | wxEndBusyCursor() in the destructor. | |
7c913512 | 127 | |
23324ae1 | 128 | @library{wxcore} |
fbec75d0 | 129 | @category{misc} |
7c913512 | 130 | |
e54c96f1 | 131 | @see wxBeginBusyCursor(), wxEndBusyCursor(), wxWindowDisabler |
23324ae1 | 132 | */ |
7c913512 | 133 | class wxBusyCursor |
23324ae1 FM |
134 | { |
135 | public: | |
136 | /** | |
e54c96f1 | 137 | Constructs a busy cursor object, calling wxBeginBusyCursor(). |
23324ae1 | 138 | */ |
98ccd545 | 139 | wxBusyCursor(const wxCursor* cursor = wxHOURGLASS_CURSOR); |
23324ae1 FM |
140 | |
141 | /** | |
e54c96f1 | 142 | Destroys the busy cursor object, calling wxEndBusyCursor(). |
23324ae1 FM |
143 | */ |
144 | ~wxBusyCursor(); | |
145 | }; | |
146 | ||
147 | ||
fbec75d0 | 148 | |
23324ae1 FM |
149 | // ============================================================================ |
150 | // Global functions/macros | |
151 | // ============================================================================ | |
152 | ||
ba2874ff | 153 | |
b21126db | 154 | /** @addtogroup group_funcmacro_dialog */ |
ba2874ff BP |
155 | //@{ |
156 | ||
157 | /** | |
158 | Changes the cursor to the given cursor for all windows in the application. | |
159 | Use wxEndBusyCursor() to revert the cursor back to its previous state. | |
160 | These two calls can be nested, and a counter ensures that only the outer | |
161 | calls take effect. | |
162 | ||
163 | @see wxIsBusy(), wxBusyCursor | |
164 | ||
165 | @header{wx/utils.h} | |
166 | */ | |
05b0355a | 167 | void wxBeginBusyCursor(const wxCursor* cursor = wxHOURGLASS_CURSOR); |
ba2874ff BP |
168 | |
169 | /** | |
170 | Changes the cursor back to the original cursor, for all windows in the | |
171 | application. Use with wxBeginBusyCursor(). | |
172 | ||
173 | @see wxIsBusy(), wxBusyCursor | |
174 | ||
175 | @header{wx/utils.h} | |
176 | */ | |
177 | void wxEndBusyCursor(); | |
178 | ||
179 | /** | |
180 | Returns @true if between two wxBeginBusyCursor() and wxEndBusyCursor() | |
181 | calls. | |
182 | ||
183 | @see wxBusyCursor. | |
184 | ||
185 | @header{wx/utils.h} | |
186 | */ | |
187 | bool wxIsBusy(); | |
188 | ||
189 | /** | |
190 | Ring the system bell. | |
191 | ||
192 | @note This function is categorized as a GUI one and so is not thread-safe. | |
193 | ||
194 | @header{wx/utils.h} | |
598fe99d VZ |
195 | |
196 | @library{wxcore} | |
ba2874ff BP |
197 | */ |
198 | void wxBell(); | |
199 | ||
200 | /** | |
201 | Shows a message box with the information about the wxWidgets build used, | |
202 | including its version, most important build parameters and the version of | |
203 | the underlying GUI toolkit. This is mainly used for diagnostic purposes | |
204 | and can be invoked by Ctrl-Alt-middle clicking on any wxWindow which | |
205 | doesn't otherwise handle this event. | |
206 | ||
1e24c2af | 207 | @since 2.9.0 |
ce45dbe3 | 208 | |
ccec9093 | 209 | @see wxGetLibraryVersionInfo() |
ce45dbe3 | 210 | |
ccec9093 VZ |
211 | @header{wx/utils.h} |
212 | */ | |
213 | void wxInfoMessageBox(wxWindow* parent); | |
ba2874ff | 214 | |
9aea2510 VZ |
215 | //@} |
216 | ||
217 | /** @addtogroup group_funcmacro_version */ | |
218 | //@{ | |
219 | ||
ccec9093 VZ |
220 | /** |
221 | Get wxWidgets version information. | |
222 | ||
223 | @since 2.9.2 | |
ce45dbe3 | 224 | |
ccec9093 | 225 | @see wxVersionInfo |
ce45dbe3 | 226 | |
ba2874ff | 227 | @header{wx/utils.h} |
ce45dbe3 | 228 | |
9aea2510 | 229 | @library{wxcore} |
ba2874ff | 230 | */ |
ccec9093 | 231 | wxVersionInfo wxGetLibraryVersionInfo(); |
ba2874ff BP |
232 | |
233 | //@} | |
234 | ||
235 | ||
236 | ||
b21126db | 237 | /** @addtogroup group_funcmacro_env */ |
1ba0de2e BP |
238 | //@{ |
239 | ||
164db92c VZ |
240 | /** |
241 | A map type containing environment variables names and values. | |
242 | ||
243 | This type is used with wxGetEnvMap() function and wxExecuteEnv structure | |
244 | optionally passed to wxExecute(). | |
245 | ||
246 | @since 2.9.2 | |
247 | ||
248 | @header{wx/utils.h} | |
249 | */ | |
250 | typedef wxStringToStringHashMap wxEnvVariableHashMap; | |
251 | ||
1ba0de2e BP |
252 | /** |
253 | This is a macro defined as @c getenv() or its wide char version in Unicode | |
254 | mode. | |
255 | ||
256 | Note that under Win32 it may not return correct value for the variables set | |
257 | with wxSetEnv(), use wxGetEnv() function instead. | |
258 | ||
259 | @header{wx/utils.h} | |
260 | */ | |
261 | wxChar* wxGetenv(const wxString& var); | |
262 | ||
263 | /** | |
787de19a VZ |
264 | Returns the current value of the environment variable @a var in @a value. |
265 | ||
266 | @a value may be @NULL if you just want to know if the variable exists and | |
1ba0de2e BP |
267 | are not interested in its value. |
268 | ||
269 | Returns @true if the variable exists, @false otherwise. | |
270 | ||
271 | @header{wx/utils.h} | |
272 | */ | |
273 | bool wxGetEnv(const wxString& var, wxString* value); | |
274 | ||
275 | /** | |
787de19a VZ |
276 | Sets the value of the environment variable @a var (adding it if necessary) |
277 | to @a value. | |
278 | ||
279 | Notice that under Windows platforms the program may have two different | |
280 | environment blocks: the first one is that of a Windows process and is | |
281 | always present, but the CRT may maintain its own independent copy of the | |
282 | environment. wxSetEnv() will always update the first copy, which means that | |
283 | wxGetEnv(), which uses it directly, will always return the expected value | |
284 | after this call. But wxSetEnv() only updates the second copy for some | |
1b2f7b6d VZ |
285 | compilers/CRT implementations (currently only MSVC and MinGW which uses the |
286 | same MSVC CRT) and so using wxGetenv() (notice the difference in case) may | |
287 | not return the updated value. | |
787de19a VZ |
288 | |
289 | @param var | |
290 | The environment variable to be set, must not contain @c '=' character. | |
291 | @param value | |
292 | New value of the variable. | |
293 | @return | |
294 | @true on success or @false if changing the value failed. | |
1ba0de2e BP |
295 | |
296 | @see wxUnsetEnv() | |
297 | ||
298 | @header{wx/utils.h} | |
299 | */ | |
300 | bool wxSetEnv(const wxString& var, const wxString& value); | |
301 | ||
302 | /** | |
787de19a VZ |
303 | Removes the variable @a var from the environment. |
304 | ||
305 | wxGetEnv() will return @NULL after the call to this function. | |
1ba0de2e BP |
306 | |
307 | Returns @true on success. | |
308 | ||
309 | @header{wx/utils.h} | |
310 | */ | |
311 | bool wxUnsetEnv(const wxString& var); | |
312 | ||
164db92c VZ |
313 | /** |
314 | Fill a map with the complete content of current environment. | |
315 | ||
316 | The map will contain the environment variable names as keys and their | |
317 | values as values. | |
318 | ||
319 | @param map | |
320 | The environment map to fill, must be non-@NULL. | |
321 | @return | |
322 | @true if environment was successfully retrieved or @false otherwise. | |
323 | ||
324 | @header{wx/utils.h} | |
325 | ||
326 | @since 2.9.2 | |
327 | */ | |
328 | bool wxGetEnvMap(wxEnvVariableHashMap *map); | |
1ba0de2e BP |
329 | //@} |
330 | ||
331 | ||
332 | ||
b21126db | 333 | /** @addtogroup group_funcmacro_misc */ |
7fa7088e BP |
334 | //@{ |
335 | ||
23324ae1 | 336 | /** |
7fa7088e BP |
337 | Returns battery state as one of @c wxBATTERY_NORMAL_STATE, |
338 | @c wxBATTERY_LOW_STATE, @c wxBATTERY_CRITICAL_STATE, | |
339 | @c wxBATTERY_SHUTDOWN_STATE or @c wxBATTERY_UNKNOWN_STATE. | |
340 | @c wxBATTERY_UNKNOWN_STATE is also the default on platforms where this | |
23324ae1 | 341 | feature is not implemented (currently everywhere but MS Windows). |
ba2874ff BP |
342 | |
343 | @header{wx/utils.h} | |
23324ae1 | 344 | */ |
7fa7088e | 345 | wxBatteryState wxGetBatteryState(); |
23324ae1 | 346 | |
23324ae1 | 347 | /** |
7fa7088e BP |
348 | Returns the type of power source as one of @c wxPOWER_SOCKET, |
349 | @c wxPOWER_BATTERY or @c wxPOWER_UNKNOWN. @c wxPOWER_UNKNOWN is also the | |
350 | default on platforms where this feature is not implemented (currently | |
351 | everywhere but MS Windows). | |
ba2874ff BP |
352 | |
353 | @header{wx/utils.h} | |
23324ae1 | 354 | */ |
7fa7088e | 355 | wxPowerType wxGetPowerType(); |
ce323d38 VS |
356 | |
357 | /** | |
7fa7088e | 358 | Under X only, returns the current display name. |
ce323d38 | 359 | |
7fa7088e | 360 | @see wxSetDisplayName() |
ce323d38 | 361 | |
7fa7088e BP |
362 | @header{wx/utils.h} |
363 | */ | |
364 | wxString wxGetDisplayName(); | |
23324ae1 | 365 | |
23324ae1 | 366 | /** |
7fa7088e BP |
367 | For normal keys, returns @true if the specified key is currently down. |
368 | ||
369 | For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns @true if | |
370 | the key is toggled such that its LED indicator is lit. There is currently | |
371 | no way to test whether togglable keys are up or down. | |
372 | ||
373 | Even though there are virtual key codes defined for mouse buttons, they | |
374 | cannot be used with this function currently. | |
ba2874ff BP |
375 | |
376 | @header{wx/utils.h} | |
23324ae1 | 377 | */ |
7fa7088e | 378 | bool wxGetKeyState(wxKeyCode key); |
23324ae1 FM |
379 | |
380 | /** | |
7fa7088e | 381 | Returns the mouse position in screen coordinates. |
ba2874ff BP |
382 | |
383 | @header{wx/utils.h} | |
23324ae1 | 384 | */ |
7fa7088e | 385 | wxPoint wxGetMousePosition(); |
23324ae1 | 386 | |
23324ae1 | 387 | /** |
7fa7088e BP |
388 | Returns the current state of the mouse. Returns a wxMouseState instance |
389 | that contains the current position of the mouse pointer in screen | |
390 | coordinates, as well as boolean values indicating the up/down status of the | |
391 | mouse buttons and the modifier keys. | |
ba2874ff BP |
392 | |
393 | @header{wx/utils.h} | |
23324ae1 | 394 | */ |
7fa7088e | 395 | wxMouseState wxGetMouseState(); |
23324ae1 FM |
396 | |
397 | /** | |
7fa7088e BP |
398 | This function enables or disables all top level windows. It is used by |
399 | wxSafeYield(). | |
ba2874ff BP |
400 | |
401 | @header{wx/utils.h} | |
23324ae1 | 402 | */ |
7fa7088e | 403 | void wxEnableTopLevelWindows(bool enable = true); |
23324ae1 | 404 | |
23324ae1 | 405 | /** |
7fa7088e BP |
406 | Find the deepest window at the given mouse position in screen coordinates, |
407 | returning the window if found, or @NULL if not. | |
ba2874ff | 408 | |
e18a74e2 VZ |
409 | This function takes child windows at the given position into account even |
410 | if they are disabled. The hidden children are however skipped by it. | |
411 | ||
ba2874ff | 412 | @header{wx/utils.h} |
23324ae1 | 413 | */ |
7fa7088e | 414 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt); |
23324ae1 FM |
415 | |
416 | /** | |
7fa7088e | 417 | @deprecated Replaced by wxWindow::FindWindowByLabel(). |
7c913512 | 418 | |
7fa7088e BP |
419 | Find a window by its label. Depending on the type of window, the label may |
420 | be a window title or panel item label. If @a parent is @NULL, the search | |
421 | will start from all top-level frames and dialog boxes; if non-@NULL, the | |
422 | search will be limited to the given window hierarchy. The search is | |
423 | recursive in both cases. | |
ba2874ff BP |
424 | |
425 | @header{wx/utils.h} | |
23324ae1 | 426 | */ |
7fa7088e BP |
427 | wxWindow* wxFindWindowByLabel(const wxString& label, |
428 | wxWindow* parent = NULL); | |
23324ae1 FM |
429 | |
430 | /** | |
7fa7088e | 431 | @deprecated Replaced by wxWindow::FindWindowByName(). |
7c913512 | 432 | |
7fa7088e BP |
433 | Find a window by its name (as given in a window constructor or @e Create |
434 | function call). If @a parent is @NULL, the search will start from all | |
435 | top-level frames and dialog boxes; if non-@NULL, the search will be limited | |
436 | to the given window hierarchy. The search is recursive in both cases. | |
437 | ||
438 | If no such named window is found, wxFindWindowByLabel() is called. | |
ba2874ff BP |
439 | |
440 | @header{wx/utils.h} | |
23324ae1 | 441 | */ |
7fa7088e | 442 | wxWindow* wxFindWindowByName(const wxString& name, wxWindow* parent = NULL); |
23324ae1 FM |
443 | |
444 | /** | |
7fa7088e | 445 | Find a menu item identifier associated with the given frame's menu bar. |
ba2874ff BP |
446 | |
447 | @header{wx/utils.h} | |
23324ae1 | 448 | */ |
7fa7088e BP |
449 | int wxFindMenuItemId(wxFrame* frame, const wxString& menuString, |
450 | const wxString& itemString); | |
23324ae1 FM |
451 | |
452 | /** | |
7fa7088e BP |
453 | @deprecated Ids generated by it can conflict with the Ids defined by the |
454 | user code, use @c wxID_ANY to assign ids which are guaranteed | |
455 | to not conflict with the user-defined ids for the controls and | |
456 | menu items you create instead of using this function. | |
457 | ||
458 | Generates an integer identifier unique to this run of the program. | |
ba2874ff BP |
459 | |
460 | @header{wx/utils.h} | |
23324ae1 | 461 | */ |
7fa7088e | 462 | long wxNewId(); |
23324ae1 | 463 | |
7fa7088e BP |
464 | /** |
465 | Ensures that Ids subsequently generated by wxNewId() do not clash with the | |
466 | given @a id. | |
467 | ||
468 | @header{wx/utils.h} | |
469 | */ | |
470 | void wxRegisterId(long id); | |
23324ae1 | 471 | |
f06832c1 VZ |
472 | /** |
473 | Opens the @a document in the application associated with the files of this | |
474 | type. | |
475 | ||
476 | The @a flags parameter is currently not used | |
477 | ||
478 | Returns @true if the application was successfully launched. | |
479 | ||
b2bd89e3 FM |
480 | @see wxLaunchDefaultBrowser(), wxExecute() |
481 | ||
f06832c1 VZ |
482 | @header{wx/utils.h} |
483 | */ | |
b2bd89e3 | 484 | bool wxLaunchDefaultApplication(const wxString& document, int flags = 0); |
f06832c1 | 485 | |
39fb8056 | 486 | /** |
f75e0c15 VZ |
487 | Opens the @a url in user's default browser. |
488 | ||
489 | If the @a flags parameter contains @c wxBROWSER_NEW_WINDOW flag, a new | |
490 | window is opened for the URL (currently this is only supported under | |
491 | Windows). | |
492 | ||
493 | And unless the @a flags parameter contains @c wxBROWSER_NOBUSYCURSOR flag, | |
494 | a busy cursor is shown while the browser is being launched (using | |
495 | wxBusyCursor). | |
496 | ||
4290e8ed FM |
497 | The parameter @a url is interpreted as follows: |
498 | - if it has a valid scheme (e.g. @c "file:", @c "http:" or @c "mailto:") | |
499 | it is passed to the appropriate browser configured in the user system. | |
500 | - if it has no valid scheme (e.g. it's a local file path without the @c "file:" | |
501 | prefix), then ::wxFileExists and ::wxDirExists are used to test if it's a | |
502 | local file/directory; if it is, then the browser is called with the | |
503 | @a url parameter eventually prefixed by @c "file:". | |
504 | - if it has no valid scheme and it's not a local file/directory, then @c "http:" | |
505 | is prepended and the browser is called. | |
7fa7088e BP |
506 | |
507 | Returns @true if the application was successfully launched. | |
508 | ||
509 | @note For some configurations of the running user, the application which is | |
510 | launched to open the given URL may be URL-dependent (e.g. a browser | |
511 | may be used for local URLs while another one may be used for remote | |
512 | URLs). | |
ba2874ff | 513 | |
b2bd89e3 FM |
514 | @see wxLaunchDefaultApplication(), wxExecute() |
515 | ||
ba2874ff | 516 | @header{wx/utils.h} |
39fb8056 | 517 | */ |
7fa7088e | 518 | bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0); |
39fb8056 FM |
519 | |
520 | /** | |
7fa7088e BP |
521 | Loads a user-defined Windows resource as a string. If the resource is |
522 | found, the function creates a new character array and copies the data into | |
523 | it. A pointer to this data is returned. If unsuccessful, @NULL is returned. | |
524 | ||
525 | The resource must be defined in the @c .rc file using the following syntax: | |
526 | ||
527 | @code | |
528 | myResource TEXT file.ext | |
529 | @endcode | |
530 | ||
531 | Where @c file.ext is a file that the resource compiler can find. | |
532 | ||
533 | This function is available under Windows only. | |
ba2874ff BP |
534 | |
535 | @header{wx/utils.h} | |
39fb8056 | 536 | */ |
7fa7088e BP |
537 | wxString wxLoadUserResource(const wxString& resourceName, |
538 | const wxString& resourceType = "TEXT"); | |
39fb8056 FM |
539 | |
540 | /** | |
7fa7088e BP |
541 | @deprecated Replaced by wxWindow::Close(). See the |
542 | @ref overview_windowdeletion "window deletion overview". | |
543 | ||
544 | Tells the system to delete the specified object when all other events have | |
545 | been processed. In some environments, it is necessary to use this instead | |
546 | of deleting a frame directly with the delete operator, because some GUIs | |
547 | will still send events to a deleted window. | |
ba2874ff BP |
548 | |
549 | @header{wx/utils.h} | |
39fb8056 | 550 | */ |
7fa7088e | 551 | void wxPostDelete(wxObject* object); |
39fb8056 | 552 | |
ea11aeee RR |
553 | |
554 | /** | |
555 | Compare function type for use with wxQsort() | |
556 | ||
557 | @header{wx/utils.h} | |
558 | */ | |
449cc351 | 559 | typedef int (*wxSortCallback)(const void* pItem1, const void* pItem2, const void* user_data); |
ea11aeee RR |
560 | |
561 | /** | |
449cc351 VZ |
562 | Function implementing quick sort algorithm. |
563 | ||
564 | This function sorts @a total_elems objects of size @a size located at @a | |
565 | pbase. It uses @a cmp function for comparing them and passes @a user_data | |
566 | pointer to the comparison function each time it's called. | |
ea11aeee RR |
567 | |
568 | @header{wx/utils.h} | |
569 | */ | |
449cc351 VZ |
570 | void wxQsort(void* pbase, size_t total_elems, |
571 | size_t size, wxSortCallback cmp, const void* user_data); | |
ea11aeee RR |
572 | |
573 | ||
39fb8056 | 574 | /** |
7fa7088e BP |
575 | Under X only, sets the current display name. This is the X host and display |
576 | name such as "colonsay:0.0", and the function indicates which display | |
577 | should be used for creating windows from this point on. Setting the display | |
578 | within an application allows multiple displays to be used. | |
579 | ||
580 | @see wxGetDisplayName() | |
ba2874ff BP |
581 | |
582 | @header{wx/utils.h} | |
39fb8056 | 583 | */ |
7fa7088e | 584 | void wxSetDisplayName(const wxString& displayName); |
39fb8056 | 585 | |
50e55c13 RD |
586 | |
587 | /** | |
588 | flags for wxStripMenuCodes | |
589 | */ | |
590 | enum | |
591 | { | |
592 | // strip '&' characters | |
593 | wxStrip_Mnemonics = 1, | |
594 | ||
595 | // strip everything after '\t' | |
596 | wxStrip_Accel = 2, | |
597 | ||
598 | // strip everything (this is the default) | |
599 | wxStrip_All = wxStrip_Mnemonics | wxStrip_Accel | |
600 | }; | |
601 | ||
39fb8056 | 602 | /** |
7fa7088e BP |
603 | Strips any menu codes from @a str and returns the result. |
604 | ||
605 | By default, the functions strips both the mnemonics character (@c '&') | |
606 | which is used to indicate a keyboard shortkey, and the accelerators, which | |
607 | are used only in the menu items and are separated from the main text by the | |
4d60a2d5 | 608 | @c \\t (TAB) character. By using @a flags of @c wxStrip_Mnemonics or |
7fa7088e BP |
609 | @c wxStrip_Accel to strip only the former or the latter part, respectively. |
610 | ||
611 | Notice that in most cases wxMenuItem::GetLabelFromText() or | |
612 | wxControl::GetLabelText() can be used instead. | |
ba2874ff BP |
613 | |
614 | @header{wx/utils.h} | |
39fb8056 | 615 | */ |
7fa7088e BP |
616 | wxString wxStripMenuCodes(const wxString& str, int flags = wxStrip_All); |
617 | ||
618 | //@} | |
619 | ||
620 | ||
621 | ||
b21126db | 622 | /** @addtogroup group_funcmacro_networkuseros */ |
3950d49c | 623 | //@{ |
7fa7088e | 624 | |
3950d49c BP |
625 | /** |
626 | Copies the user's email address into the supplied buffer, by concatenating | |
627 | the values returned by wxGetFullHostName() and wxGetUserId(). | |
7fa7088e | 628 | |
d29a9a8a | 629 | @return @true if successful, @false otherwise. |
3950d49c BP |
630 | |
631 | @header{wx/utils.h} | |
632 | */ | |
633 | wxString wxGetEmailAddress(); | |
39fb8056 FM |
634 | |
635 | /** | |
3950d49c | 636 | @deprecated Use wxGetEmailAddress() instead. |
39fb8056 | 637 | |
3950d49c BP |
638 | @param buf Buffer to store the email address in. |
639 | @param sz Size of the buffer. | |
7fa7088e | 640 | |
d29a9a8a | 641 | @return @true if successful, @false otherwise. |
ba2874ff BP |
642 | |
643 | @header{wx/utils.h} | |
39fb8056 | 644 | */ |
3950d49c BP |
645 | bool wxGetEmailAddress(char* buf, int sz); |
646 | ||
647 | /** | |
648 | Returns the amount of free memory in bytes under environments which support | |
649 | it, and -1 if not supported or failed to perform measurement. | |
650 | ||
651 | @header{wx/utils.h} | |
652 | */ | |
653 | wxMemorySize wxGetFreeMemory(); | |
654 | ||
655 | /** | |
656 | Return the (current) user's home directory. | |
657 | ||
658 | @see wxGetUserHome(), wxStandardPaths | |
659 | ||
660 | @header{wx/utils.h} | |
661 | */ | |
662 | wxString wxGetHomeDir(); | |
663 | ||
664 | /** | |
665 | Copies the current host machine's name into the supplied buffer. Please | |
666 | note that the returned name is @e not fully qualified, i.e. it does not | |
667 | include the domain name. | |
668 | ||
669 | Under Windows or NT, this function first looks in the environment variable | |
670 | SYSTEM_NAME; if this is not found, the entry @b HostName in the wxWidgets | |
671 | section of the WIN.INI file is tried. | |
672 | ||
d29a9a8a | 673 | @return The hostname if successful or an empty string otherwise. |
3950d49c BP |
674 | |
675 | @see wxGetFullHostName() | |
676 | ||
677 | @header{wx/utils.h} | |
678 | */ | |
679 | wxString wxGetHostName(); | |
39fb8056 FM |
680 | |
681 | /** | |
3950d49c | 682 | @deprecated Use wxGetHostName() instead. |
39fb8056 | 683 | |
3950d49c | 684 | @param buf Buffer to store the host name in. |
7fa7088e BP |
685 | @param sz Size of the buffer. |
686 | ||
d29a9a8a | 687 | @return @true if successful, @false otherwise. |
3950d49c BP |
688 | |
689 | @header{wx/utils.h} | |
690 | */ | |
691 | bool wxGetHostName(char* buf, int sz); | |
7fa7088e BP |
692 | |
693 | /** | |
3950d49c BP |
694 | Returns the FQDN (fully qualified domain host name) or an empty string on |
695 | error. | |
7fa7088e | 696 | |
3950d49c | 697 | @see wxGetHostName() |
39fb8056 | 698 | |
ba2874ff | 699 | @header{wx/utils.h} |
39fb8056 | 700 | */ |
3950d49c | 701 | wxString wxGetFullHostName(); |
39fb8056 FM |
702 | |
703 | /** | |
3950d49c BP |
704 | Returns the home directory for the given user. If the @a user is empty |
705 | (default value), this function behaves like wxGetHomeDir() (i.e. returns | |
706 | the current user home directory). | |
7fa7088e | 707 | |
3950d49c | 708 | If the home directory couldn't be determined, an empty string is returned. |
ba2874ff BP |
709 | |
710 | @header{wx/utils.h} | |
39fb8056 | 711 | */ |
e9c3992c | 712 | wxString wxGetUserHome(const wxString& user = wxEmptyString); |
39fb8056 FM |
713 | |
714 | /** | |
3950d49c BP |
715 | This function returns the "user id" also known as "login name" under Unix |
716 | (i.e. something like "jsmith"). It uniquely identifies the current user (on | |
717 | this system). Under Windows or NT, this function first looks in the | |
718 | environment variables USER and LOGNAME; if neither of these is found, the | |
719 | entry @b UserId in the @b wxWidgets section of the WIN.INI file is tried. | |
720 | ||
d29a9a8a | 721 | @return The login name if successful or an empty string otherwise. |
3950d49c BP |
722 | |
723 | @see wxGetUserName() | |
ba2874ff BP |
724 | |
725 | @header{wx/utils.h} | |
39fb8056 | 726 | */ |
3950d49c | 727 | wxString wxGetUserId(); |
39fb8056 | 728 | |
7fa7088e | 729 | /** |
3950d49c BP |
730 | @deprecated Use wxGetUserId() instead. |
731 | ||
732 | @param buf Buffer to store the login name in. | |
733 | @param sz Size of the buffer. | |
734 | ||
d29a9a8a | 735 | @return @true if successful, @false otherwise. |
7fa7088e BP |
736 | |
737 | @header{wx/utils.h} | |
738 | */ | |
3950d49c | 739 | bool wxGetUserId(char* buf, int sz); |
39fb8056 FM |
740 | |
741 | /** | |
3950d49c BP |
742 | This function returns the full user name (something like "Mr. John Smith"). |
743 | ||
744 | Under Windows or NT, this function looks for the entry UserName in the | |
745 | wxWidgets section of the WIN.INI file. If PenWindows is running, the entry | |
746 | Current in the section User of the PENWIN.INI file is used. | |
747 | ||
d29a9a8a | 748 | @return The full user name if successful or an empty string otherwise. |
3950d49c BP |
749 | |
750 | @see wxGetUserId() | |
ba2874ff BP |
751 | |
752 | @header{wx/utils.h} | |
39fb8056 | 753 | */ |
3950d49c | 754 | wxString wxGetUserName(); |
39fb8056 FM |
755 | |
756 | /** | |
3950d49c BP |
757 | @deprecated Use wxGetUserName() instead. |
758 | ||
759 | @param buf Buffer to store the full user name in. | |
760 | @param sz Size of the buffer. | |
39fb8056 | 761 | |
d29a9a8a | 762 | @return @true if successful, @false otherwise. |
39fb8056 | 763 | |
7fa7088e BP |
764 | @header{wx/utils.h} |
765 | */ | |
3950d49c | 766 | bool wxGetUserName(char* buf, int sz); |
7fa7088e BP |
767 | |
768 | /** | |
3950d49c BP |
769 | Returns the string containing the description of the current platform in a |
770 | user-readable form. For example, this function may return strings like | |
771 | "Windows NT Version 4.0" or "Linux 2.2.2 i386". | |
7fa7088e | 772 | |
3950d49c | 773 | @see wxGetOsVersion() |
ba2874ff BP |
774 | |
775 | @header{wx/utils.h} | |
39fb8056 | 776 | */ |
3950d49c | 777 | wxString wxGetOsDescription(); |
39fb8056 FM |
778 | |
779 | /** | |
9bbb78b9 FM |
780 | Gets the version and the operating system ID for currently running OS. |
781 | The returned wxOperatingSystemId value can be used for a basic categorization | |
782 | of the OS family; the major and minor version numbers allows to detect a specific | |
783 | system. | |
784 | ||
785 | For Unix-like systems (@c wxOS_UNIX) the major and minor version integers will | |
786 | contain the kernel major and minor version numbers (as returned by the | |
787 | 'uname -r' command); e.g. "2" and "6" if the machine is using kernel 2.6.19. | |
788 | ||
789 | For Mac OS X systems (@c wxOS_MAC) the major and minor version integers are the | |
d13b34d3 | 790 | natural version numbers associated with the OS; e.g. "10" and "6" if the machine |
9bbb78b9 FM |
791 | is using Mac OS X Snow Leopard. |
792 | ||
793 | For Windows-like systems (@c wxOS_WINDOWS) the major and minor version integers will | |
794 | contain the following values: | |
795 | @beginTable | |
796 | @row3col{<b>Windows OS name</b>, <b>Major version</b>, <b>Minor version</b>} | |
797 | @row3col{Windows 7, 6, 1} | |
798 | @row3col{Windows Server 2008 R2, 6, 1} | |
799 | @row3col{Windows Server 2008, 6, 0} | |
800 | @row3col{Windows Vista, 6, 0} | |
801 | @row3col{Windows Server 2003 R2, 5, 2} | |
802 | @row3col{Windows Server 2003, 5, 2} | |
803 | @row3col{Windows XP, 5, 1} | |
804 | @row3col{Windows 2000, 5, 0} | |
805 | @endDefList | |
806 | See the <a href="http://msdn.microsoft.com/en-us/library/ms724832(VS.85).aspx">MSDN</a> | |
807 | for more info about the values above. | |
3950d49c BP |
808 | |
809 | @see wxGetOsDescription(), wxPlatformInfo | |
810 | ||
811 | @header{wx/utils.h} | |
39fb8056 | 812 | */ |
3950d49c | 813 | wxOperatingSystemId wxGetOsVersion(int* major = NULL, int* minor = NULL); |
39fb8056 | 814 | |
39fb8056 | 815 | /** |
3950d49c BP |
816 | Returns @true if the operating system the program is running under is 64 |
817 | bit. The check is performed at run-time and may differ from the value | |
818 | available at compile-time (at compile-time you can just check if | |
819 | <tt>sizeof(void*) == 8</tt>) since the program could be running in | |
820 | emulation mode or in a mixed 32/64 bit system (bi-architecture operating | |
821 | system). | |
39fb8056 | 822 | |
3950d49c BP |
823 | @note This function is not 100% reliable on some systems given the fact |
824 | that there isn't always a standard way to do a reliable check on the | |
825 | OS architecture. | |
ba2874ff BP |
826 | |
827 | @header{wx/utils.h} | |
39fb8056 | 828 | */ |
3950d49c | 829 | bool wxIsPlatform64Bit(); |
23324ae1 | 830 | |
39fb8056 | 831 | /** |
3950d49c BP |
832 | Returns @true if the current platform is little endian (instead of big |
833 | endian). The check is performed at run-time. | |
834 | ||
835 | @see @ref group_funcmacro_byteorder "Byte Order Functions and Macros" | |
ba2874ff BP |
836 | |
837 | @header{wx/utils.h} | |
39fb8056 | 838 | */ |
3950d49c | 839 | bool wxIsPlatformLittleEndian(); |
23324ae1 | 840 | |
23790a2a FM |
841 | /** |
842 | Returns a structure containing informations about the currently running | |
843 | Linux distribution. | |
844 | ||
845 | This function uses the @c lsb_release utility which is part of the | |
846 | <tt>Linux Standard Base Core</tt> specification | |
847 | (see http://refspecs.linux-foundation.org/lsb.shtml) since the very first LSB | |
848 | release 1.0 (released in 2001). | |
849 | The @c lsb_release utility is very common on modern Linux distributions but in | |
850 | case it's not available, then this function will return a ::wxLinuxDistributionInfo | |
851 | structure containing empty strings. | |
852 | ||
853 | This function is Linux-specific and is only available when the @c __LINUX__ | |
854 | symbol is defined. | |
855 | */ | |
856 | wxLinuxDistributionInfo wxGetLinuxDistributionInfo(); | |
857 | ||
3950d49c BP |
858 | //@} |
859 | ||
860 | ||
861 | ||
b21126db | 862 | /** @addtogroup group_funcmacro_procctrl */ |
23324ae1 | 863 | //@{ |
3950d49c | 864 | |
164db92c VZ |
865 | /** |
866 | @struct wxExecuteEnv | |
867 | ||
868 | This structure can optionally be passed to wxExecute() to specify | |
869 | additional options to use for the child process. | |
870 | ||
871 | @since 2.9.2 | |
872 | ||
873 | @header{wx/utils.h} | |
874 | */ | |
875 | struct wxExecuteEnv | |
876 | { | |
877 | /** | |
878 | The initial working directory for the new process. | |
879 | ||
880 | If this field is empty, the current working directory of this process | |
881 | is used. | |
882 | */ | |
883 | wxString cwd; | |
884 | ||
885 | /** | |
886 | The environment variable map. | |
887 | ||
888 | If the map is empty, the environment variables of the current process | |
889 | are also used for the child one, otherwise only the variables defined | |
890 | in this map are used. | |
891 | */ | |
892 | wxEnvVariableHashMap env; | |
893 | }; | |
894 | ||
02661032 VZ |
895 | /** |
896 | Bit flags that can be used with wxExecute(). | |
897 | */ | |
898 | enum | |
899 | { | |
900 | /** | |
901 | Execute the process asynchronously. | |
902 | ||
903 | Notice that, due to its value, this is the default. | |
904 | */ | |
905 | wxEXEC_ASYNC = 0, | |
906 | ||
907 | /** | |
908 | Execute the process synchronously. | |
909 | */ | |
910 | wxEXEC_SYNC = 1, | |
911 | ||
912 | /** | |
913 | Always show the child process console under MSW. | |
914 | ||
915 | The child console is hidden by default if the child IO is redirected, | |
916 | this flag allows to change this and show it nevertheless. | |
917 | ||
918 | This flag is ignored under the other platforms. | |
919 | */ | |
920 | wxEXEC_SHOW_CONSOLE = 2, | |
921 | ||
922 | /** | |
923 | Make the new process a group leader. | |
924 | ||
925 | Under Unix, if the process is the group leader then passing | |
926 | wxKILL_CHILDREN to wxKill() kills all children as well as pid. | |
927 | ||
ee4d4380 VZ |
928 | Under MSW, applies only to console applications and is only supported |
929 | under NT family (i.e. not under Windows 9x). It corresponds to the | |
930 | native @c CREATE_NEW_PROCESS_GROUP and, in particular, ensures that | |
931 | Ctrl-Break signals will be sent to all children of this process as well | |
932 | to the process itself. Support for this flag under MSW was added in | |
933 | version 2.9.4 of wxWidgets. | |
02661032 VZ |
934 | */ |
935 | wxEXEC_MAKE_GROUP_LEADER = 4, | |
936 | ||
937 | /** | |
938 | Don't disable the program UI while running the child synchronously. | |
939 | ||
940 | By default synchronous execution disables all program windows to avoid | |
941 | that the user interacts with the program while the child process is | |
942 | running, you can use this flag to prevent this from happening. | |
943 | ||
944 | This flag can only be used with ::wxEXEC_SYNC. | |
945 | */ | |
946 | wxEXEC_NODISABLE = 8, | |
947 | ||
948 | /** | |
949 | Don't dispatch events while the child process is executed. | |
950 | ||
951 | By default, the event loop is run while waiting for synchronous | |
952 | execution to complete and this flag can be used to simply block the | |
953 | main process until the child process finishes | |
954 | ||
955 | This flag can only be used with ::wxEXEC_SYNC. | |
956 | */ | |
957 | wxEXEC_NOEVENTS = 16, | |
958 | ||
4fe4a7c5 VZ |
959 | /** |
960 | Hide child process console under MSW. | |
961 | ||
962 | Under MSW, hide the console of the child process if it has one, | |
963 | even if its IO is not redirected. | |
964 | ||
965 | This flag is ignored under the other platforms. | |
966 | */ | |
967 | wxEXEC_HIDE_CONSOLE = 32, | |
968 | ||
02661032 VZ |
969 | /** |
970 | Convenient synonym for flags given system()-like behaviour. | |
971 | */ | |
972 | wxEXEC_BLOCK = wxEXEC_SYNC | wxEXEC_NOEVENTS | |
973 | }; | |
39fb8056 | 974 | /** |
39fb8056 | 975 | Executes another program in Unix or Windows. |
3950d49c BP |
976 | |
977 | In the overloaded versions of this function, if @a flags parameter contains | |
978 | @c wxEXEC_ASYNC flag (the default), flow of control immediately returns. If | |
979 | it contains @c wxEXEC_SYNC, the current application waits until the other | |
980 | program has terminated. | |
981 | ||
39fb8056 | 982 | In the case of synchronous execution, the return value is the exit code of |
3950d49c BP |
983 | the process (which terminates by the moment the function returns) and will |
984 | be -1 if the process couldn't be started and typically 0 if the process | |
985 | terminated successfully. Also, while waiting for the process to terminate, | |
986 | wxExecute() will call wxYield(). Because of this, by default this function | |
987 | disables all application windows to avoid unexpected reentrancies which | |
988 | could result from the users interaction with the program while the child | |
989 | process is running. If you are sure that it is safe to not disable the | |
990 | program windows, you may pass @c wxEXEC_NODISABLE flag to prevent this | |
991 | automatic disabling from happening. | |
992 | ||
39fb8056 FM |
993 | For asynchronous execution, however, the return value is the process id and |
994 | zero value indicates that the command could not be executed. As an added | |
995 | complication, the return value of -1 in this case indicates that we didn't | |
3950d49c BP |
996 | launch a new process, but connected to the running one (this can only |
997 | happen when using DDE under Windows for command execution). In particular, | |
998 | in this case only, the calling code will not get the notification about | |
39fb8056 | 999 | process termination. |
3950d49c BP |
1000 | |
1001 | If @a callback isn't @NULL and if execution is asynchronous, | |
1002 | wxProcess::OnTerminate() will be called when the process finishes. | |
1003 | Specifying this parameter also allows you to redirect the standard input | |
1004 | and/or output of the process being launched by calling | |
4fe4a7c5 VZ |
1005 | wxProcess::Redirect(). |
1006 | ||
1007 | Under Windows, when launching a console process its console is shown by | |
1008 | default but hidden if its IO is redirected. Both of these default | |
1009 | behaviours may be overridden: if ::wxEXEC_HIDE_CONSOLE is specified, the | |
1010 | console will never be shown. If ::wxEXEC_SHOW_CONSOLE is used, the console | |
1011 | will be shown even if the child process IO is redirected. Neither of these | |
1012 | flags affect non-console Windows applications or does anything under the | |
1013 | other systems. | |
3950d49c BP |
1014 | |
1015 | Under Unix the flag @c wxEXEC_MAKE_GROUP_LEADER may be used to ensure that | |
1016 | the new process is a group leader (this will create a new session if | |
1017 | needed). Calling wxKill() passing wxKILL_CHILDREN will kill this process as | |
1018 | well as all of its children (except those which have started their own | |
ee4d4380 VZ |
1019 | session). Under MSW, this flag can be used with console processes only and |
1020 | corresponds to the native @c CREATE_NEW_PROCESS_GROUP flag. | |
3950d49c | 1021 | |
39fb8056 FM |
1022 | The @c wxEXEC_NOEVENTS flag prevents processing of any events from taking |
1023 | place while the child process is running. It should be only used for very | |
1024 | short-lived processes as otherwise the application windows risk becoming | |
3950d49c BP |
1025 | unresponsive from the users point of view. As this flag only makes sense |
1026 | with @c wxEXEC_SYNC, @c wxEXEC_BLOCK equal to the sum of both of these | |
1027 | flags is provided as a convenience. | |
1028 | ||
1029 | @note Currently wxExecute() can only be used from the main thread, calling | |
1030 | this function from another thread will result in an assert failure in | |
1031 | debug build and won't work. | |
39fb8056 FM |
1032 | |
1033 | @param command | |
3950d49c BP |
1034 | The command to execute and any parameters to pass to it as a single |
1035 | string, i.e. "emacs file.txt". | |
1036 | @param flags | |
1037 | Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include | |
4fe4a7c5 VZ |
1038 | wxEXEC_SHOW_CONSOLE, wxEXEC_HIDE_CONSOLE, wxEXEC_MAKE_GROUP_LEADER (in |
1039 | either case) or wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, | |
1040 | which is equal to their combination, in wxEXEC_SYNC case. | |
3950d49c BP |
1041 | @param callback |
1042 | An optional pointer to wxProcess. | |
164db92c VZ |
1043 | @param env |
1044 | An optional pointer to additional parameters for the child process, | |
1045 | such as its initial working directory and environment variables. This | |
1046 | parameter is available in wxWidgets 2.9.2 and later only. | |
3950d49c | 1047 | |
b2bd89e3 FM |
1048 | @see wxShell(), wxProcess, @ref page_samples_exec, |
1049 | wxLaunchDefaultApplication(), wxLaunchDefaultBrowser() | |
3950d49c BP |
1050 | |
1051 | @header{wx/utils.h} | |
1052 | ||
1053 | @beginWxPerlOnly | |
1058f652 | 1054 | In wxPerl this function is called @c Wx::ExecuteCommand. |
3950d49c BP |
1055 | @endWxPerlOnly |
1056 | */ | |
1057 | long wxExecute(const wxString& command, int flags = wxEXEC_ASYNC, | |
164db92c VZ |
1058 | wxProcess* callback = NULL, |
1059 | const wxExecuteEnv* env = NULL); | |
3950d49c BP |
1060 | //@} |
1061 | ||
b21126db | 1062 | /** @addtogroup group_funcmacro_procctrl */ |
3950d49c BP |
1063 | //@{ |
1064 | /** | |
1065 | This is an overloaded version of wxExecute(const wxString&,int,wxProcess*), | |
1066 | please see its documentation for general information. | |
1067 | ||
1068 | This version takes an array of values: a command, any number of arguments, | |
1069 | terminated by @NULL. | |
1070 | ||
39fb8056 | 1071 | @param argv |
3950d49c BP |
1072 | The command to execute should be the first element of this array, any |
1073 | additional ones are the command parameters and the array must be | |
39fb8056 FM |
1074 | terminated with a @NULL pointer. |
1075 | @param flags | |
02661032 | 1076 | Same as for wxExecute(const wxString&,int,wxProcess*) overload. |
39fb8056 | 1077 | @param callback |
3950d49c | 1078 | An optional pointer to wxProcess. |
164db92c VZ |
1079 | @param env |
1080 | An optional pointer to additional parameters for the child process, | |
1081 | such as its initial working directory and environment variables. This | |
1082 | parameter is available in wxWidgets 2.9.2 and later only. | |
3950d49c | 1083 | |
b2bd89e3 FM |
1084 | @see wxShell(), wxProcess, @ref page_samples_exec, |
1085 | wxLaunchDefaultApplication(), wxLaunchDefaultBrowser() | |
1086 | ||
3950d49c | 1087 | @header{wx/utils.h} |
1058f652 MB |
1088 | |
1089 | @beginWxPerlOnly | |
1090 | In wxPerl this function is called @c Wx::ExecuteArgs. | |
1091 | @endWxPerlOnly | |
3950d49c BP |
1092 | */ |
1093 | long wxExecute(char** argv, int flags = wxEXEC_ASYNC, | |
164db92c VZ |
1094 | wxProcess* callback = NULL, |
1095 | const wxExecuteEnv *env = NULL); | |
3950d49c | 1096 | long wxExecute(wchar_t** argv, int flags = wxEXEC_ASYNC, |
164db92c VZ |
1097 | wxProcess* callback = NULL, |
1098 | const wxExecuteEnv *env = NULL); | |
23324ae1 FM |
1099 | //@} |
1100 | ||
b21126db | 1101 | /** @addtogroup group_funcmacro_procctrl */ |
3950d49c BP |
1102 | //@{ |
1103 | ||
39fb8056 | 1104 | /** |
3950d49c BP |
1105 | This is an overloaded version of wxExecute(const wxString&,int,wxProcess*), |
1106 | please see its documentation for general information. | |
1107 | ||
1108 | This version can be used to execute a process (always synchronously, the | |
1109 | contents of @a flags is or'd with @c wxEXEC_SYNC) and capture its output in | |
1110 | the array @e output. | |
1111 | ||
1112 | @param command | |
1113 | The command to execute and any parameters to pass to it as a single | |
1114 | string. | |
77bfb902 FM |
1115 | @param output |
1116 | The string array where the stdout of the executed process is saved. | |
3950d49c | 1117 | @param flags |
02661032 | 1118 | Combination of flags to which ::wxEXEC_SYNC is always implicitly added. |
164db92c VZ |
1119 | @param env |
1120 | An optional pointer to additional parameters for the child process, | |
1121 | such as its initial working directory and environment variables. This | |
1122 | parameter is available in wxWidgets 2.9.2 and later only. | |
ba2874ff | 1123 | |
b2bd89e3 FM |
1124 | @see wxShell(), wxProcess, @ref page_samples_exec, |
1125 | wxLaunchDefaultApplication(), wxLaunchDefaultBrowser() | |
1126 | ||
ba2874ff | 1127 | @header{wx/utils.h} |
1058f652 MB |
1128 | |
1129 | @beginWxPerlOnly | |
1130 | This function is called @c Wx::ExecuteStdout: it only takes the | |
1131 | @a command argument, and returns a 2-element list (@c status, @c output), | |
1132 | where @c output in an array reference. | |
1133 | @endWxPerlOnly | |
39fb8056 | 1134 | */ |
164db92c VZ |
1135 | long wxExecute(const wxString& command, wxArrayString& output, int flags = 0, |
1136 | const wxExecuteEnv *env = NULL); | |
39fb8056 FM |
1137 | |
1138 | /** | |
3950d49c BP |
1139 | This is an overloaded version of wxExecute(const wxString&,int,wxProcess*), |
1140 | please see its documentation for general information. | |
1141 | ||
1142 | This version adds the possibility to additionally capture the messages from | |
b5d9d763 VZ |
1143 | standard error output in the @a errors array. As with the above overload |
1144 | capturing standard output only, execution is always synchronous. | |
3950d49c BP |
1145 | |
1146 | @param command | |
1147 | The command to execute and any parameters to pass to it as a single | |
1148 | string. | |
77bfb902 FM |
1149 | @param output |
1150 | The string array where the stdout of the executed process is saved. | |
1151 | @param errors | |
1152 | The string array where the stderr of the executed process is saved. | |
3950d49c | 1153 | @param flags |
02661032 | 1154 | Combination of flags to which ::wxEXEC_SYNC is always implicitly added. |
164db92c VZ |
1155 | @param env |
1156 | An optional pointer to additional parameters for the child process, | |
1157 | such as its initial working directory and environment variables. This | |
1158 | parameter is available in wxWidgets 2.9.2 and later only. | |
ba2874ff | 1159 | |
b2bd89e3 FM |
1160 | @see wxShell(), wxProcess, @ref page_samples_exec, |
1161 | wxLaunchDefaultApplication(), wxLaunchDefaultBrowser() | |
1162 | ||
ba2874ff | 1163 | @header{wx/utils.h} |
1058f652 MB |
1164 | |
1165 | @beginWxPerlOnly | |
1166 | This function is called @c Wx::ExecuteStdoutStderr: it only takes the | |
1167 | @a command argument, and returns a 3-element list (@c status, @c output, | |
1168 | @c errors), where @c output and @c errors are array references. | |
1169 | @endWxPerlOnly | |
39fb8056 | 1170 | */ |
3950d49c | 1171 | long wxExecute(const wxString& command, wxArrayString& output, |
164db92c VZ |
1172 | wxArrayString& errors, int flags = 0, |
1173 | const wxExecuteEnv *env = NULL); | |
39fb8056 FM |
1174 | |
1175 | /** | |
1176 | Returns the number uniquely identifying the current process in the system. | |
1177 | If an error occurs, 0 is returned. | |
ba2874ff BP |
1178 | |
1179 | @header{wx/utils.h} | |
39fb8056 FM |
1180 | */ |
1181 | unsigned long wxGetProcessId(); | |
1182 | ||
1183 | /** | |
1184 | Equivalent to the Unix kill function: send the given signal @a sig to the | |
732c0c48 VZ |
1185 | process with PID @a pid. |
1186 | ||
1187 | The valid signal values are: | |
39fb8056 FM |
1188 | |
1189 | @code | |
1190 | enum wxSignal | |
1191 | { | |
3950d49c | 1192 | wxSIGNONE = 0, // verify if the process exists under Unix |
39fb8056 FM |
1193 | wxSIGHUP, |
1194 | wxSIGINT, | |
1195 | wxSIGQUIT, | |
1196 | wxSIGILL, | |
1197 | wxSIGTRAP, | |
1198 | wxSIGABRT, | |
1199 | wxSIGEMT, | |
1200 | wxSIGFPE, | |
3950d49c | 1201 | wxSIGKILL, // forcefully kill, dangerous! |
39fb8056 FM |
1202 | wxSIGBUS, |
1203 | wxSIGSEGV, | |
1204 | wxSIGSYS, | |
1205 | wxSIGPIPE, | |
1206 | wxSIGALRM, | |
3950d49c | 1207 | wxSIGTERM // terminate the process gently |
39fb8056 FM |
1208 | }; |
1209 | @endcode | |
1210 | ||
3950d49c BP |
1211 | @c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning under |
1212 | both Unix and Windows but all the other signals are equivalent to | |
39fb8056 | 1213 | @c wxSIGTERM under Windows. |
3950d49c BP |
1214 | |
1215 | Returns 0 on success, -1 on failure. If the @a rc parameter is not @NULL, | |
732c0c48 | 1216 | it will be filled with a value from the @c wxKillError enum: |
39fb8056 FM |
1217 | |
1218 | @code | |
1219 | enum wxKillError | |
1220 | { | |
3950d49c BP |
1221 | wxKILL_OK, // no error |
1222 | wxKILL_BAD_SIGNAL, // no such signal | |
1223 | wxKILL_ACCESS_DENIED, // permission denied | |
1224 | wxKILL_NO_PROCESS, // no such process | |
1225 | wxKILL_ERROR // another, unspecified error | |
39fb8056 FM |
1226 | }; |
1227 | @endcode | |
1228 | ||
3950d49c BP |
1229 | The @a flags parameter can be wxKILL_NOCHILDREN (the default), or |
1230 | wxKILL_CHILDREN, in which case the child processes of this process will be | |
1231 | killed too. Note that under Unix, for wxKILL_CHILDREN to work you should | |
1232 | have created the process by passing wxEXEC_MAKE_GROUP_LEADER to | |
1233 | wxExecute(). | |
39fb8056 | 1234 | |
3950d49c | 1235 | @see wxProcess::Kill(), wxProcess::Exists(), @ref page_samples_exec |
ba2874ff BP |
1236 | |
1237 | @header{wx/utils.h} | |
39fb8056 | 1238 | */ |
05b0355a RD |
1239 | int wxKill(long pid, wxSignal sig = wxSIGTERM, |
1240 | wxKillError* rc = NULL, int flags = wxKILL_NOCHILDREN); | |
39fb8056 | 1241 | |
39fb8056 | 1242 | /** |
3950d49c BP |
1243 | Executes a command in an interactive shell window. If no command is |
1244 | specified, then just the shell is spawned. | |
1245 | ||
1246 | @see wxExecute(), @ref page_samples_exec | |
ba2874ff BP |
1247 | |
1248 | @header{wx/utils.h} | |
39fb8056 | 1249 | */ |
05b0355a | 1250 | bool wxShell(const wxString& command = wxEmptyString); |
3950d49c BP |
1251 | |
1252 | /** | |
1253 | This function shuts down or reboots the computer depending on the value of | |
1254 | the @a flags. | |
1255 | ||
118a41d9 VZ |
1256 | @note Note that performing the shutdown requires the corresponding access |
1257 | rights (superuser under Unix, SE_SHUTDOWN privilege under Windows NT) | |
1258 | and that this function is only implemented under Unix and MSW. | |
3950d49c BP |
1259 | |
1260 | @param flags | |
118a41d9 VZ |
1261 | One of @c wxSHUTDOWN_POWEROFF, @c wxSHUTDOWN_REBOOT or |
1262 | @c wxSHUTDOWN_LOGOFF (currently implemented only for MSW) possibly | |
1263 | combined with @c wxSHUTDOWN_FORCE which forces shutdown under MSW by | |
1264 | forcefully terminating all the applications. As doing this can result | |
1265 | in a data loss, this flag shouldn't be used unless really necessary. | |
3950d49c | 1266 | |
d29a9a8a | 1267 | @return @true on success, @false if an error occurred. |
3950d49c BP |
1268 | |
1269 | @header{wx/utils.h} | |
1270 | */ | |
118a41d9 | 1271 | bool wxShutdown(int flags = wxSHUTDOWN_POWEROFF); |
3950d49c | 1272 | |
7c913512 | 1273 | //@} |
23324ae1 | 1274 | |
3950d49c BP |
1275 | |
1276 | ||
b21126db | 1277 | /** @addtogroup group_funcmacro_time */ |
3950d49c BP |
1278 | //@{ |
1279 | ||
1280 | /** | |
1281 | Sleeps for the specified number of microseconds. The microsecond resolution | |
1282 | may not, in fact, be available on all platforms (currently only Unix | |
1283 | platforms with nanosleep(2) may provide it) in which case this is the same | |
1284 | as calling wxMilliSleep() with the argument of @e microseconds/1000. | |
1285 | ||
1286 | @header{wx/utils.h} | |
1287 | */ | |
1288 | void wxMicroSleep(unsigned long microseconds); | |
1289 | ||
1290 | /** | |
1291 | Sleeps for the specified number of milliseconds. Notice that usage of this | |
1292 | function is encouraged instead of calling usleep(3) directly because the | |
1293 | standard @e usleep() function is not MT safe. | |
1294 | ||
1295 | @header{wx/utils.h} | |
1296 | */ | |
1297 | void wxMilliSleep(unsigned long milliseconds); | |
1298 | ||
1299 | /** | |
1300 | Returns a string representing the current date and time. | |
1301 | ||
1302 | @header{wx/utils.h} | |
1303 | */ | |
1304 | wxString wxNow(); | |
1305 | ||
39fb8056 FM |
1306 | /** |
1307 | Sleeps for the specified number of seconds. | |
ba2874ff BP |
1308 | |
1309 | @header{wx/utils.h} | |
39fb8056 FM |
1310 | */ |
1311 | void wxSleep(int secs); | |
1312 | ||
39fb8056 | 1313 | /** |
3950d49c BP |
1314 | @deprecated This function is deprecated because its name is misleading: |
1315 | notice that the argument is in milliseconds, not microseconds. | |
1316 | Please use either wxMilliSleep() or wxMicroSleep() depending on | |
1317 | the resolution you need. | |
39fb8056 | 1318 | |
3950d49c | 1319 | Sleeps for the specified number of milliseconds. |
ba2874ff BP |
1320 | |
1321 | @header{wx/utils.h} | |
39fb8056 | 1322 | */ |
3950d49c BP |
1323 | void wxUsleep(unsigned long milliseconds); |
1324 | ||
1325 | //@} | |
39fb8056 | 1326 |