]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: utils.h | |
e54c96f1 | 3 | // Purpose: interface of wxWindowDisabler |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxWindowDisabler | |
11 | @wxheader{utils.h} | |
7c913512 | 12 | |
23324ae1 FM |
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. | |
2ecd1756 VZ |
15 | |
16 | This is useful when you want to indicate to the user that the application | |
23324ae1 | 17 | is currently busy and cannot respond to user input. |
7c913512 | 18 | |
23324ae1 FM |
19 | @library{wxcore} |
20 | @category{FIXME} | |
7c913512 | 21 | |
e54c96f1 | 22 | @see wxBusyCursor |
23324ae1 | 23 | */ |
7c913512 | 24 | class wxWindowDisabler |
23324ae1 FM |
25 | { |
26 | public: | |
2ecd1756 VZ |
27 | /** |
28 | Disables all top level windows of the applications. | |
29 | ||
30 | If @a disable is @c false nothing is done. This can be convenient if | |
31 | the windows should be disabled depending on some condition. | |
32 | ||
33 | @since 2.9.0 | |
34 | */ | |
35 | wxWindowDisabler(bool disable = true); | |
36 | ||
23324ae1 | 37 | /** |
7c913512 | 38 | Disables all top level windows of the applications with the exception of |
4cc4bfaf | 39 | @a winToSkip if it is not @NULL. |
23324ae1 | 40 | */ |
2ecd1756 | 41 | wxWindowDisabler(wxWindow* winToSkip); |
23324ae1 FM |
42 | |
43 | /** | |
44 | Reenables back the windows disabled by the constructor. | |
45 | */ | |
46 | ~wxWindowDisabler(); | |
47 | }; | |
48 | ||
49 | ||
e54c96f1 | 50 | |
23324ae1 FM |
51 | /** |
52 | @class wxBusyCursor | |
53 | @wxheader{utils.h} | |
7c913512 | 54 | |
23324ae1 FM |
55 | This class makes it easy to tell your user that the program is temporarily busy. |
56 | Just create a wxBusyCursor object on the stack, and within the current scope, | |
57 | the hourglass will be shown. | |
7c913512 | 58 | |
23324ae1 | 59 | For example: |
7c913512 | 60 | |
23324ae1 FM |
61 | @code |
62 | wxBusyCursor wait; | |
7c913512 | 63 | |
23324ae1 FM |
64 | for (int i = 0; i 100000; i++) |
65 | DoACalculation(); | |
66 | @endcode | |
7c913512 | 67 | |
e54c96f1 FM |
68 | It works by calling wxBeginBusyCursor() in the constructor, |
69 | and wxEndBusyCursor() in the destructor. | |
7c913512 | 70 | |
23324ae1 FM |
71 | @library{wxcore} |
72 | @category{FIXME} | |
7c913512 | 73 | |
e54c96f1 | 74 | @see wxBeginBusyCursor(), wxEndBusyCursor(), wxWindowDisabler |
23324ae1 | 75 | */ |
7c913512 | 76 | class wxBusyCursor |
23324ae1 FM |
77 | { |
78 | public: | |
79 | /** | |
e54c96f1 | 80 | Constructs a busy cursor object, calling wxBeginBusyCursor(). |
23324ae1 FM |
81 | */ |
82 | wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR); | |
83 | ||
84 | /** | |
e54c96f1 | 85 | Destroys the busy cursor object, calling wxEndBusyCursor(). |
23324ae1 FM |
86 | */ |
87 | ~wxBusyCursor(); | |
88 | }; | |
89 | ||
90 | ||
e54c96f1 | 91 | |
23324ae1 FM |
92 | // ============================================================================ |
93 | // Global functions/macros | |
94 | // ============================================================================ | |
95 | ||
ba2874ff BP |
96 | |
97 | /** @ingroup group_funcmacro_dialog */ | |
98 | //@{ | |
99 | ||
100 | /** | |
101 | Changes the cursor to the given cursor for all windows in the application. | |
102 | Use wxEndBusyCursor() to revert the cursor back to its previous state. | |
103 | These two calls can be nested, and a counter ensures that only the outer | |
104 | calls take effect. | |
105 | ||
106 | @see wxIsBusy(), wxBusyCursor | |
107 | ||
108 | @header{wx/utils.h} | |
109 | */ | |
110 | void wxBeginBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR); | |
111 | ||
112 | /** | |
113 | Changes the cursor back to the original cursor, for all windows in the | |
114 | application. Use with wxBeginBusyCursor(). | |
115 | ||
116 | @see wxIsBusy(), wxBusyCursor | |
117 | ||
118 | @header{wx/utils.h} | |
119 | */ | |
120 | void wxEndBusyCursor(); | |
121 | ||
122 | /** | |
123 | Returns @true if between two wxBeginBusyCursor() and wxEndBusyCursor() | |
124 | calls. | |
125 | ||
126 | @see wxBusyCursor. | |
127 | ||
128 | @header{wx/utils.h} | |
129 | */ | |
130 | bool wxIsBusy(); | |
131 | ||
132 | /** | |
133 | Ring the system bell. | |
134 | ||
135 | @note This function is categorized as a GUI one and so is not thread-safe. | |
136 | ||
137 | @header{wx/utils.h} | |
138 | */ | |
139 | void wxBell(); | |
140 | ||
141 | /** | |
142 | Shows a message box with the information about the wxWidgets build used, | |
143 | including its version, most important build parameters and the version of | |
144 | the underlying GUI toolkit. This is mainly used for diagnostic purposes | |
145 | and can be invoked by Ctrl-Alt-middle clicking on any wxWindow which | |
146 | doesn't otherwise handle this event. | |
147 | ||
148 | @wxsince{2.9.0} | |
149 | ||
150 | @header{wx/utils.h} | |
151 | */ | |
152 | void wxInfoMessageBox(wxWindow parent = NULL); | |
153 | ||
154 | //@} | |
155 | ||
156 | ||
157 | ||
1ba0de2e BP |
158 | /** @ingroup group_funcmacro_env */ |
159 | //@{ | |
160 | ||
161 | /** | |
162 | This is a macro defined as @c getenv() or its wide char version in Unicode | |
163 | mode. | |
164 | ||
165 | Note that under Win32 it may not return correct value for the variables set | |
166 | with wxSetEnv(), use wxGetEnv() function instead. | |
167 | ||
168 | @header{wx/utils.h} | |
169 | */ | |
170 | wxChar* wxGetenv(const wxString& var); | |
171 | ||
172 | /** | |
173 | Returns the current value of the environment variable @c var in @c value. | |
174 | @c value may be @NULL if you just want to know if the variable exists and | |
175 | are not interested in its value. | |
176 | ||
177 | Returns @true if the variable exists, @false otherwise. | |
178 | ||
179 | @header{wx/utils.h} | |
180 | */ | |
181 | bool wxGetEnv(const wxString& var, wxString* value); | |
182 | ||
183 | /** | |
184 | Sets the value of the environment variable @c var (adding it if necessary) | |
185 | to @c value. | |
186 | ||
187 | Returns @true on success. | |
188 | ||
189 | @see wxUnsetEnv() | |
190 | ||
191 | @header{wx/utils.h} | |
192 | */ | |
193 | bool wxSetEnv(const wxString& var, const wxString& value); | |
194 | ||
195 | /** | |
196 | Removes the variable @c var from the environment. wxGetEnv() will return | |
197 | @NULL after the call to this function. | |
198 | ||
199 | Returns @true on success. | |
200 | ||
201 | @header{wx/utils.h} | |
202 | */ | |
203 | bool wxUnsetEnv(const wxString& var); | |
204 | ||
205 | //@} | |
206 | ||
207 | ||
208 | ||
7fa7088e BP |
209 | /** @ingroup group_funcmacro_misc */ |
210 | //@{ | |
211 | ||
23324ae1 | 212 | /** |
7fa7088e BP |
213 | Returns battery state as one of @c wxBATTERY_NORMAL_STATE, |
214 | @c wxBATTERY_LOW_STATE, @c wxBATTERY_CRITICAL_STATE, | |
215 | @c wxBATTERY_SHUTDOWN_STATE or @c wxBATTERY_UNKNOWN_STATE. | |
216 | @c wxBATTERY_UNKNOWN_STATE is also the default on platforms where this | |
23324ae1 | 217 | feature is not implemented (currently everywhere but MS Windows). |
ba2874ff BP |
218 | |
219 | @header{wx/utils.h} | |
23324ae1 | 220 | */ |
7fa7088e | 221 | wxBatteryState wxGetBatteryState(); |
23324ae1 | 222 | |
23324ae1 | 223 | /** |
7fa7088e BP |
224 | Returns the type of power source as one of @c wxPOWER_SOCKET, |
225 | @c wxPOWER_BATTERY or @c wxPOWER_UNKNOWN. @c wxPOWER_UNKNOWN is also the | |
226 | default on platforms where this feature is not implemented (currently | |
227 | everywhere but MS Windows). | |
ba2874ff BP |
228 | |
229 | @header{wx/utils.h} | |
23324ae1 | 230 | */ |
7fa7088e | 231 | wxPowerType wxGetPowerType(); |
ce323d38 VS |
232 | |
233 | /** | |
7fa7088e | 234 | Under X only, returns the current display name. |
ce323d38 | 235 | |
7fa7088e | 236 | @see wxSetDisplayName() |
ce323d38 | 237 | |
7fa7088e BP |
238 | @header{wx/utils.h} |
239 | */ | |
240 | wxString wxGetDisplayName(); | |
23324ae1 | 241 | |
23324ae1 | 242 | /** |
7fa7088e BP |
243 | For normal keys, returns @true if the specified key is currently down. |
244 | ||
245 | For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns @true if | |
246 | the key is toggled such that its LED indicator is lit. There is currently | |
247 | no way to test whether togglable keys are up or down. | |
248 | ||
249 | Even though there are virtual key codes defined for mouse buttons, they | |
250 | cannot be used with this function currently. | |
ba2874ff BP |
251 | |
252 | @header{wx/utils.h} | |
23324ae1 | 253 | */ |
7fa7088e | 254 | bool wxGetKeyState(wxKeyCode key); |
23324ae1 FM |
255 | |
256 | /** | |
7fa7088e | 257 | Returns the mouse position in screen coordinates. |
ba2874ff BP |
258 | |
259 | @header{wx/utils.h} | |
23324ae1 | 260 | */ |
7fa7088e | 261 | wxPoint wxGetMousePosition(); |
23324ae1 | 262 | |
23324ae1 | 263 | /** |
7fa7088e BP |
264 | Returns the current state of the mouse. Returns a wxMouseState instance |
265 | that contains the current position of the mouse pointer in screen | |
266 | coordinates, as well as boolean values indicating the up/down status of the | |
267 | mouse buttons and the modifier keys. | |
ba2874ff BP |
268 | |
269 | @header{wx/utils.h} | |
23324ae1 | 270 | */ |
7fa7088e | 271 | wxMouseState wxGetMouseState(); |
23324ae1 FM |
272 | |
273 | /** | |
7fa7088e BP |
274 | This function enables or disables all top level windows. It is used by |
275 | wxSafeYield(). | |
ba2874ff BP |
276 | |
277 | @header{wx/utils.h} | |
23324ae1 | 278 | */ |
7fa7088e | 279 | void wxEnableTopLevelWindows(bool enable = true); |
23324ae1 | 280 | |
23324ae1 | 281 | /** |
7fa7088e BP |
282 | Find the deepest window at the given mouse position in screen coordinates, |
283 | returning the window if found, or @NULL if not. | |
ba2874ff BP |
284 | |
285 | @header{wx/utils.h} | |
23324ae1 | 286 | */ |
7fa7088e | 287 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt); |
23324ae1 FM |
288 | |
289 | /** | |
7fa7088e | 290 | @deprecated Replaced by wxWindow::FindWindowByLabel(). |
7c913512 | 291 | |
7fa7088e BP |
292 | Find a window by its label. Depending on the type of window, the label may |
293 | be a window title or panel item label. If @a parent is @NULL, the search | |
294 | will start from all top-level frames and dialog boxes; if non-@NULL, the | |
295 | search will be limited to the given window hierarchy. The search is | |
296 | recursive in both cases. | |
ba2874ff BP |
297 | |
298 | @header{wx/utils.h} | |
23324ae1 | 299 | */ |
7fa7088e BP |
300 | wxWindow* wxFindWindowByLabel(const wxString& label, |
301 | wxWindow* parent = NULL); | |
23324ae1 FM |
302 | |
303 | /** | |
7fa7088e | 304 | @deprecated Replaced by wxWindow::FindWindowByName(). |
7c913512 | 305 | |
7fa7088e BP |
306 | Find a window by its name (as given in a window constructor or @e Create |
307 | function call). If @a parent is @NULL, the search will start from all | |
308 | top-level frames and dialog boxes; if non-@NULL, the search will be limited | |
309 | to the given window hierarchy. The search is recursive in both cases. | |
310 | ||
311 | If no such named window is found, wxFindWindowByLabel() is called. | |
ba2874ff BP |
312 | |
313 | @header{wx/utils.h} | |
23324ae1 | 314 | */ |
7fa7088e | 315 | wxWindow* wxFindWindowByName(const wxString& name, wxWindow* parent = NULL); |
23324ae1 FM |
316 | |
317 | /** | |
7fa7088e | 318 | Find a menu item identifier associated with the given frame's menu bar. |
ba2874ff BP |
319 | |
320 | @header{wx/utils.h} | |
23324ae1 | 321 | */ |
7fa7088e BP |
322 | int wxFindMenuItemId(wxFrame* frame, const wxString& menuString, |
323 | const wxString& itemString); | |
23324ae1 FM |
324 | |
325 | /** | |
7fa7088e BP |
326 | @deprecated Ids generated by it can conflict with the Ids defined by the |
327 | user code, use @c wxID_ANY to assign ids which are guaranteed | |
328 | to not conflict with the user-defined ids for the controls and | |
329 | menu items you create instead of using this function. | |
330 | ||
331 | Generates an integer identifier unique to this run of the program. | |
ba2874ff BP |
332 | |
333 | @header{wx/utils.h} | |
23324ae1 | 334 | */ |
7fa7088e | 335 | long wxNewId(); |
23324ae1 | 336 | |
7fa7088e BP |
337 | /** |
338 | Ensures that Ids subsequently generated by wxNewId() do not clash with the | |
339 | given @a id. | |
340 | ||
341 | @header{wx/utils.h} | |
342 | */ | |
343 | void wxRegisterId(long id); | |
23324ae1 | 344 | |
39fb8056 | 345 | /** |
7fa7088e BP |
346 | Opens the @a url in user's default browser. If the @a flags parameter |
347 | contains @c wxBROWSER_NEW_WINDOW flag, a new window is opened for the URL | |
348 | (currently this is only supported under Windows). The @a url may also be a | |
349 | local file path (with or without the "file://" prefix), if it doesn't | |
350 | correspond to an existing file and the URL has no scheme "http://" is | |
351 | prepended to it by default. | |
352 | ||
353 | Returns @true if the application was successfully launched. | |
354 | ||
355 | @note For some configurations of the running user, the application which is | |
356 | launched to open the given URL may be URL-dependent (e.g. a browser | |
357 | may be used for local URLs while another one may be used for remote | |
358 | URLs). | |
ba2874ff BP |
359 | |
360 | @header{wx/utils.h} | |
39fb8056 | 361 | */ |
7fa7088e | 362 | bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0); |
39fb8056 FM |
363 | |
364 | /** | |
7fa7088e BP |
365 | Loads a user-defined Windows resource as a string. If the resource is |
366 | found, the function creates a new character array and copies the data into | |
367 | it. A pointer to this data is returned. If unsuccessful, @NULL is returned. | |
368 | ||
369 | The resource must be defined in the @c .rc file using the following syntax: | |
370 | ||
371 | @code | |
372 | myResource TEXT file.ext | |
373 | @endcode | |
374 | ||
375 | Where @c file.ext is a file that the resource compiler can find. | |
376 | ||
377 | This function is available under Windows only. | |
ba2874ff BP |
378 | |
379 | @header{wx/utils.h} | |
39fb8056 | 380 | */ |
7fa7088e BP |
381 | wxString wxLoadUserResource(const wxString& resourceName, |
382 | const wxString& resourceType = "TEXT"); | |
39fb8056 FM |
383 | |
384 | /** | |
7fa7088e BP |
385 | @deprecated Replaced by wxWindow::Close(). See the |
386 | @ref overview_windowdeletion "window deletion overview". | |
387 | ||
388 | Tells the system to delete the specified object when all other events have | |
389 | been processed. In some environments, it is necessary to use this instead | |
390 | of deleting a frame directly with the delete operator, because some GUIs | |
391 | will still send events to a deleted window. | |
ba2874ff BP |
392 | |
393 | @header{wx/utils.h} | |
39fb8056 | 394 | */ |
7fa7088e | 395 | void wxPostDelete(wxObject* object); |
39fb8056 | 396 | |
39fb8056 | 397 | /** |
7fa7088e BP |
398 | Under X only, sets the current display name. This is the X host and display |
399 | name such as "colonsay:0.0", and the function indicates which display | |
400 | should be used for creating windows from this point on. Setting the display | |
401 | within an application allows multiple displays to be used. | |
402 | ||
403 | @see wxGetDisplayName() | |
ba2874ff BP |
404 | |
405 | @header{wx/utils.h} | |
39fb8056 | 406 | */ |
7fa7088e | 407 | void wxSetDisplayName(const wxString& displayName); |
39fb8056 FM |
408 | |
409 | /** | |
7fa7088e BP |
410 | Strips any menu codes from @a str and returns the result. |
411 | ||
412 | By default, the functions strips both the mnemonics character (@c '&') | |
413 | which is used to indicate a keyboard shortkey, and the accelerators, which | |
414 | are used only in the menu items and are separated from the main text by the | |
415 | @c \t (TAB) character. By using @a flags of @c wxStrip_Mnemonics or | |
416 | @c wxStrip_Accel to strip only the former or the latter part, respectively. | |
417 | ||
418 | Notice that in most cases wxMenuItem::GetLabelFromText() or | |
419 | wxControl::GetLabelText() can be used instead. | |
ba2874ff BP |
420 | |
421 | @header{wx/utils.h} | |
39fb8056 | 422 | */ |
7fa7088e BP |
423 | wxString wxStripMenuCodes(const wxString& str, int flags = wxStrip_All); |
424 | ||
425 | //@} | |
426 | ||
427 | ||
428 | ||
3950d49c BP |
429 | /** @ingroup group_funcmacro_networkuseros */ |
430 | //@{ | |
7fa7088e | 431 | |
3950d49c BP |
432 | /** |
433 | Copies the user's email address into the supplied buffer, by concatenating | |
434 | the values returned by wxGetFullHostName() and wxGetUserId(). | |
7fa7088e | 435 | |
3950d49c BP |
436 | @returns @true if successful, @false otherwise. |
437 | ||
438 | @header{wx/utils.h} | |
439 | */ | |
440 | wxString wxGetEmailAddress(); | |
39fb8056 FM |
441 | |
442 | /** | |
3950d49c | 443 | @deprecated Use wxGetEmailAddress() instead. |
39fb8056 | 444 | |
3950d49c BP |
445 | @param buf Buffer to store the email address in. |
446 | @param sz Size of the buffer. | |
7fa7088e | 447 | |
3950d49c | 448 | @returns @true if successful, @false otherwise. |
ba2874ff BP |
449 | |
450 | @header{wx/utils.h} | |
39fb8056 | 451 | */ |
3950d49c BP |
452 | bool wxGetEmailAddress(char* buf, int sz); |
453 | ||
454 | /** | |
455 | Returns the amount of free memory in bytes under environments which support | |
456 | it, and -1 if not supported or failed to perform measurement. | |
457 | ||
458 | @header{wx/utils.h} | |
459 | */ | |
460 | wxMemorySize wxGetFreeMemory(); | |
461 | ||
462 | /** | |
463 | Return the (current) user's home directory. | |
464 | ||
465 | @see wxGetUserHome(), wxStandardPaths | |
466 | ||
467 | @header{wx/utils.h} | |
468 | */ | |
469 | wxString wxGetHomeDir(); | |
470 | ||
471 | /** | |
472 | Copies the current host machine's name into the supplied buffer. Please | |
473 | note that the returned name is @e not fully qualified, i.e. it does not | |
474 | include the domain name. | |
475 | ||
476 | Under Windows or NT, this function first looks in the environment variable | |
477 | SYSTEM_NAME; if this is not found, the entry @b HostName in the wxWidgets | |
478 | section of the WIN.INI file is tried. | |
479 | ||
480 | @returns The hostname if successful or an empty string otherwise. | |
481 | ||
482 | @see wxGetFullHostName() | |
483 | ||
484 | @header{wx/utils.h} | |
485 | */ | |
486 | wxString wxGetHostName(); | |
39fb8056 FM |
487 | |
488 | /** | |
3950d49c | 489 | @deprecated Use wxGetHostName() instead. |
39fb8056 | 490 | |
3950d49c | 491 | @param buf Buffer to store the host name in. |
7fa7088e BP |
492 | @param sz Size of the buffer. |
493 | ||
3950d49c BP |
494 | @returns @true if successful, @false otherwise. |
495 | ||
496 | @header{wx/utils.h} | |
497 | */ | |
498 | bool wxGetHostName(char* buf, int sz); | |
7fa7088e BP |
499 | |
500 | /** | |
3950d49c BP |
501 | Returns the FQDN (fully qualified domain host name) or an empty string on |
502 | error. | |
7fa7088e | 503 | |
3950d49c | 504 | @see wxGetHostName() |
39fb8056 | 505 | |
ba2874ff | 506 | @header{wx/utils.h} |
39fb8056 | 507 | */ |
3950d49c | 508 | wxString wxGetFullHostName(); |
39fb8056 FM |
509 | |
510 | /** | |
3950d49c BP |
511 | Returns the home directory for the given user. If the @a user is empty |
512 | (default value), this function behaves like wxGetHomeDir() (i.e. returns | |
513 | the current user home directory). | |
7fa7088e | 514 | |
3950d49c | 515 | If the home directory couldn't be determined, an empty string is returned. |
ba2874ff BP |
516 | |
517 | @header{wx/utils.h} | |
39fb8056 | 518 | */ |
3950d49c | 519 | wxString wxGetUserHome(const wxString& user = ""); |
39fb8056 FM |
520 | |
521 | /** | |
3950d49c BP |
522 | This function returns the "user id" also known as "login name" under Unix |
523 | (i.e. something like "jsmith"). It uniquely identifies the current user (on | |
524 | this system). Under Windows or NT, this function first looks in the | |
525 | environment variables USER and LOGNAME; if neither of these is found, the | |
526 | entry @b UserId in the @b wxWidgets section of the WIN.INI file is tried. | |
527 | ||
528 | @returns The login name if successful or an empty string otherwise. | |
529 | ||
530 | @see wxGetUserName() | |
ba2874ff BP |
531 | |
532 | @header{wx/utils.h} | |
39fb8056 | 533 | */ |
3950d49c | 534 | wxString wxGetUserId(); |
39fb8056 | 535 | |
7fa7088e | 536 | /** |
3950d49c BP |
537 | @deprecated Use wxGetUserId() instead. |
538 | ||
539 | @param buf Buffer to store the login name in. | |
540 | @param sz Size of the buffer. | |
541 | ||
542 | @returns @true if successful, @false otherwise. | |
7fa7088e BP |
543 | |
544 | @header{wx/utils.h} | |
545 | */ | |
3950d49c | 546 | bool wxGetUserId(char* buf, int sz); |
39fb8056 FM |
547 | |
548 | /** | |
3950d49c BP |
549 | This function returns the full user name (something like "Mr. John Smith"). |
550 | ||
551 | Under Windows or NT, this function looks for the entry UserName in the | |
552 | wxWidgets section of the WIN.INI file. If PenWindows is running, the entry | |
553 | Current in the section User of the PENWIN.INI file is used. | |
554 | ||
555 | @returns The full user name if successful or an empty string otherwise. | |
556 | ||
557 | @see wxGetUserId() | |
ba2874ff BP |
558 | |
559 | @header{wx/utils.h} | |
39fb8056 | 560 | */ |
3950d49c | 561 | wxString wxGetUserName(); |
39fb8056 FM |
562 | |
563 | /** | |
3950d49c BP |
564 | @deprecated Use wxGetUserName() instead. |
565 | ||
566 | @param buf Buffer to store the full user name in. | |
567 | @param sz Size of the buffer. | |
39fb8056 | 568 | |
3950d49c | 569 | @returns @true if successful, @false otherwise. |
39fb8056 | 570 | |
7fa7088e BP |
571 | @header{wx/utils.h} |
572 | */ | |
3950d49c | 573 | bool wxGetUserName(char* buf, int sz); |
7fa7088e BP |
574 | |
575 | /** | |
3950d49c BP |
576 | Returns the string containing the description of the current platform in a |
577 | user-readable form. For example, this function may return strings like | |
578 | "Windows NT Version 4.0" or "Linux 2.2.2 i386". | |
7fa7088e | 579 | |
3950d49c | 580 | @see wxGetOsVersion() |
ba2874ff BP |
581 | |
582 | @header{wx/utils.h} | |
39fb8056 | 583 | */ |
3950d49c | 584 | wxString wxGetOsDescription(); |
39fb8056 FM |
585 | |
586 | /** | |
3950d49c BP |
587 | Gets the version and the operating system ID for currently running OS. See |
588 | wxPlatformInfo for more details about wxOperatingSystemId. | |
589 | ||
590 | @see wxGetOsDescription(), wxPlatformInfo | |
591 | ||
592 | @header{wx/utils.h} | |
39fb8056 | 593 | */ |
3950d49c | 594 | wxOperatingSystemId wxGetOsVersion(int* major = NULL, int* minor = NULL); |
39fb8056 | 595 | |
39fb8056 | 596 | /** |
3950d49c BP |
597 | Returns @true if the operating system the program is running under is 64 |
598 | bit. The check is performed at run-time and may differ from the value | |
599 | available at compile-time (at compile-time you can just check if | |
600 | <tt>sizeof(void*) == 8</tt>) since the program could be running in | |
601 | emulation mode or in a mixed 32/64 bit system (bi-architecture operating | |
602 | system). | |
39fb8056 | 603 | |
3950d49c BP |
604 | @note This function is not 100% reliable on some systems given the fact |
605 | that there isn't always a standard way to do a reliable check on the | |
606 | OS architecture. | |
ba2874ff BP |
607 | |
608 | @header{wx/utils.h} | |
39fb8056 | 609 | */ |
3950d49c | 610 | bool wxIsPlatform64Bit(); |
23324ae1 | 611 | |
39fb8056 | 612 | /** |
3950d49c BP |
613 | Returns @true if the current platform is little endian (instead of big |
614 | endian). The check is performed at run-time. | |
615 | ||
616 | @see @ref group_funcmacro_byteorder "Byte Order Functions and Macros" | |
ba2874ff BP |
617 | |
618 | @header{wx/utils.h} | |
39fb8056 | 619 | */ |
3950d49c | 620 | bool wxIsPlatformLittleEndian(); |
23324ae1 | 621 | |
3950d49c BP |
622 | //@} |
623 | ||
624 | ||
625 | ||
626 | /** @ingroup group_funcmacro_procctrl */ | |
23324ae1 | 627 | //@{ |
3950d49c | 628 | |
39fb8056 | 629 | /** |
39fb8056 | 630 | Executes another program in Unix or Windows. |
3950d49c BP |
631 | |
632 | In the overloaded versions of this function, if @a flags parameter contains | |
633 | @c wxEXEC_ASYNC flag (the default), flow of control immediately returns. If | |
634 | it contains @c wxEXEC_SYNC, the current application waits until the other | |
635 | program has terminated. | |
636 | ||
39fb8056 | 637 | In the case of synchronous execution, the return value is the exit code of |
3950d49c BP |
638 | the process (which terminates by the moment the function returns) and will |
639 | be -1 if the process couldn't be started and typically 0 if the process | |
640 | terminated successfully. Also, while waiting for the process to terminate, | |
641 | wxExecute() will call wxYield(). Because of this, by default this function | |
642 | disables all application windows to avoid unexpected reentrancies which | |
643 | could result from the users interaction with the program while the child | |
644 | process is running. If you are sure that it is safe to not disable the | |
645 | program windows, you may pass @c wxEXEC_NODISABLE flag to prevent this | |
646 | automatic disabling from happening. | |
647 | ||
39fb8056 FM |
648 | For asynchronous execution, however, the return value is the process id and |
649 | zero value indicates that the command could not be executed. As an added | |
650 | complication, the return value of -1 in this case indicates that we didn't | |
3950d49c BP |
651 | launch a new process, but connected to the running one (this can only |
652 | happen when using DDE under Windows for command execution). In particular, | |
653 | in this case only, the calling code will not get the notification about | |
39fb8056 | 654 | process termination. |
3950d49c BP |
655 | |
656 | If @a callback isn't @NULL and if execution is asynchronous, | |
657 | wxProcess::OnTerminate() will be called when the process finishes. | |
658 | Specifying this parameter also allows you to redirect the standard input | |
659 | and/or output of the process being launched by calling | |
660 | wxProcess::Redirect(). If the child process IO is redirected, under Windows | |
661 | the process window is not shown by default (this avoids having to flush an | |
662 | unnecessary console for the processes which don't create any windows | |
39fb8056 | 663 | anyhow) but a @c wxEXEC_NOHIDE flag can be used to prevent this from |
3950d49c BP |
664 | happening, i.e. with this flag the child process window will be shown |
665 | normally. | |
666 | ||
667 | Under Unix the flag @c wxEXEC_MAKE_GROUP_LEADER may be used to ensure that | |
668 | the new process is a group leader (this will create a new session if | |
669 | needed). Calling wxKill() passing wxKILL_CHILDREN will kill this process as | |
670 | well as all of its children (except those which have started their own | |
671 | session). | |
672 | ||
39fb8056 FM |
673 | The @c wxEXEC_NOEVENTS flag prevents processing of any events from taking |
674 | place while the child process is running. It should be only used for very | |
675 | short-lived processes as otherwise the application windows risk becoming | |
3950d49c BP |
676 | unresponsive from the users point of view. As this flag only makes sense |
677 | with @c wxEXEC_SYNC, @c wxEXEC_BLOCK equal to the sum of both of these | |
678 | flags is provided as a convenience. | |
679 | ||
680 | @note Currently wxExecute() can only be used from the main thread, calling | |
681 | this function from another thread will result in an assert failure in | |
682 | debug build and won't work. | |
39fb8056 FM |
683 | |
684 | @param command | |
3950d49c BP |
685 | The command to execute and any parameters to pass to it as a single |
686 | string, i.e. "emacs file.txt". | |
687 | @param flags | |
688 | Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include | |
689 | wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or | |
690 | wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to | |
691 | their combination, in wxEXEC_SYNC case. | |
692 | @param callback | |
693 | An optional pointer to wxProcess. | |
694 | ||
695 | @see wxShell(), wxProcess, @ref page_samples_exec | |
696 | ||
697 | @header{wx/utils.h} | |
698 | ||
699 | @beginWxPerlOnly | |
700 | This function is called @c Wx::ExecuteStdoutStderr and it only takes the | |
701 | @a command argument, and returns a 3-element list (@c status, @c output, | |
702 | @c errors), where @c output and @c errors are array references. | |
703 | @endWxPerlOnly | |
704 | */ | |
705 | long wxExecute(const wxString& command, int flags = wxEXEC_ASYNC, | |
706 | wxProcess* callback = NULL); | |
707 | ||
708 | //@} | |
709 | ||
710 | /** @ingroup group_funcmacro_procctrl */ | |
711 | //@{ | |
712 | /** | |
713 | This is an overloaded version of wxExecute(const wxString&,int,wxProcess*), | |
714 | please see its documentation for general information. | |
715 | ||
716 | This version takes an array of values: a command, any number of arguments, | |
717 | terminated by @NULL. | |
718 | ||
39fb8056 | 719 | @param argv |
3950d49c BP |
720 | The command to execute should be the first element of this array, any |
721 | additional ones are the command parameters and the array must be | |
39fb8056 FM |
722 | terminated with a @NULL pointer. |
723 | @param flags | |
05718a98 VZ |
724 | Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include |
725 | wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or | |
726 | wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to | |
727 | their combination, in wxEXEC_SYNC case. | |
39fb8056 | 728 | @param callback |
3950d49c BP |
729 | An optional pointer to wxProcess. |
730 | ||
731 | @header{wx/utils.h} | |
732 | */ | |
733 | long wxExecute(char** argv, int flags = wxEXEC_ASYNC, | |
734 | wxProcess* callback = NULL); | |
735 | long wxExecute(wchar_t** argv, int flags = wxEXEC_ASYNC, | |
736 | wxProcess* callback = NULL); | |
23324ae1 FM |
737 | //@} |
738 | ||
3950d49c BP |
739 | /** @ingroup group_funcmacro_procctrl */ |
740 | //@{ | |
741 | ||
39fb8056 | 742 | /** |
3950d49c BP |
743 | This is an overloaded version of wxExecute(const wxString&,int,wxProcess*), |
744 | please see its documentation for general information. | |
745 | ||
746 | This version can be used to execute a process (always synchronously, the | |
747 | contents of @a flags is or'd with @c wxEXEC_SYNC) and capture its output in | |
748 | the array @e output. | |
749 | ||
750 | @param command | |
751 | The command to execute and any parameters to pass to it as a single | |
752 | string. | |
753 | @param flags | |
754 | Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include | |
755 | wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or | |
756 | wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to | |
757 | their combination, in wxEXEC_SYNC case. | |
ba2874ff BP |
758 | |
759 | @header{wx/utils.h} | |
39fb8056 | 760 | */ |
3950d49c BP |
761 | long wxExecute(const wxString& command, wxArrayString& output, |
762 | int flags = 0); | |
39fb8056 FM |
763 | |
764 | /** | |
3950d49c BP |
765 | This is an overloaded version of wxExecute(const wxString&,int,wxProcess*), |
766 | please see its documentation for general information. | |
767 | ||
768 | This version adds the possibility to additionally capture the messages from | |
769 | standard error output in the @a errors array. | |
770 | ||
771 | @param command | |
772 | The command to execute and any parameters to pass to it as a single | |
773 | string. | |
774 | @param flags | |
775 | Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include | |
776 | wxEXEC_NOHIDE, wxEXEC_MAKE_GROUP_LEADER (in either case) or | |
777 | wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK, which is equal to | |
778 | their combination, in wxEXEC_SYNC case. | |
ba2874ff BP |
779 | |
780 | @header{wx/utils.h} | |
39fb8056 | 781 | */ |
3950d49c BP |
782 | long wxExecute(const wxString& command, wxArrayString& output, |
783 | wxArrayString& errors, int flags = 0); | |
39fb8056 FM |
784 | |
785 | /** | |
786 | Returns the number uniquely identifying the current process in the system. | |
787 | If an error occurs, 0 is returned. | |
ba2874ff BP |
788 | |
789 | @header{wx/utils.h} | |
39fb8056 FM |
790 | */ |
791 | unsigned long wxGetProcessId(); | |
792 | ||
793 | /** | |
794 | Equivalent to the Unix kill function: send the given signal @a sig to the | |
3950d49c | 795 | process with PID @a pid. The valid signal values are: |
39fb8056 FM |
796 | |
797 | @code | |
798 | enum wxSignal | |
799 | { | |
3950d49c | 800 | wxSIGNONE = 0, // verify if the process exists under Unix |
39fb8056 FM |
801 | wxSIGHUP, |
802 | wxSIGINT, | |
803 | wxSIGQUIT, | |
804 | wxSIGILL, | |
805 | wxSIGTRAP, | |
806 | wxSIGABRT, | |
807 | wxSIGEMT, | |
808 | wxSIGFPE, | |
3950d49c | 809 | wxSIGKILL, // forcefully kill, dangerous! |
39fb8056 FM |
810 | wxSIGBUS, |
811 | wxSIGSEGV, | |
812 | wxSIGSYS, | |
813 | wxSIGPIPE, | |
814 | wxSIGALRM, | |
3950d49c | 815 | wxSIGTERM // terminate the process gently |
39fb8056 FM |
816 | }; |
817 | @endcode | |
818 | ||
3950d49c BP |
819 | @c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning under |
820 | both Unix and Windows but all the other signals are equivalent to | |
39fb8056 | 821 | @c wxSIGTERM under Windows. |
3950d49c BP |
822 | |
823 | Returns 0 on success, -1 on failure. If the @a rc parameter is not @NULL, | |
824 | it will be filled with a value of the the @c wxKillError enum: | |
39fb8056 FM |
825 | |
826 | @code | |
827 | enum wxKillError | |
828 | { | |
3950d49c BP |
829 | wxKILL_OK, // no error |
830 | wxKILL_BAD_SIGNAL, // no such signal | |
831 | wxKILL_ACCESS_DENIED, // permission denied | |
832 | wxKILL_NO_PROCESS, // no such process | |
833 | wxKILL_ERROR // another, unspecified error | |
39fb8056 FM |
834 | }; |
835 | @endcode | |
836 | ||
3950d49c BP |
837 | The @a flags parameter can be wxKILL_NOCHILDREN (the default), or |
838 | wxKILL_CHILDREN, in which case the child processes of this process will be | |
839 | killed too. Note that under Unix, for wxKILL_CHILDREN to work you should | |
840 | have created the process by passing wxEXEC_MAKE_GROUP_LEADER to | |
841 | wxExecute(). | |
39fb8056 | 842 | |
3950d49c | 843 | @see wxProcess::Kill(), wxProcess::Exists(), @ref page_samples_exec |
ba2874ff BP |
844 | |
845 | @header{wx/utils.h} | |
39fb8056 | 846 | */ |
3950d49c BP |
847 | int wxKill(long pid, int sig = wxSIGTERM, |
848 | wxKillError rc = NULL, int flags = 0); | |
39fb8056 | 849 | |
39fb8056 | 850 | /** |
3950d49c BP |
851 | Executes a command in an interactive shell window. If no command is |
852 | specified, then just the shell is spawned. | |
853 | ||
854 | @see wxExecute(), @ref page_samples_exec | |
ba2874ff BP |
855 | |
856 | @header{wx/utils.h} | |
39fb8056 | 857 | */ |
3950d49c BP |
858 | bool wxShell(const wxString& command = NULL); |
859 | ||
860 | /** | |
861 | This function shuts down or reboots the computer depending on the value of | |
862 | the @a flags. | |
863 | ||
864 | @note Doing this requires the corresponding access rights (superuser under | |
865 | Unix, SE_SHUTDOWN privilege under Windows NT) and that this function | |
866 | is only implemented under Unix and Win32. | |
867 | ||
868 | @param flags | |
869 | Either wxSHUTDOWN_POWEROFF or wxSHUTDOWN_REBOOT | |
870 | ||
871 | @returns @true on success, @false if an error occurred. | |
872 | ||
873 | @header{wx/utils.h} | |
874 | */ | |
875 | bool wxShutdown(wxShutdownFlags flags); | |
876 | ||
7c913512 | 877 | //@} |
23324ae1 | 878 | |
3950d49c BP |
879 | |
880 | ||
881 | /** @ingroup group_funcmacro_time */ | |
882 | //@{ | |
883 | ||
884 | /** | |
885 | Sleeps for the specified number of microseconds. The microsecond resolution | |
886 | may not, in fact, be available on all platforms (currently only Unix | |
887 | platforms with nanosleep(2) may provide it) in which case this is the same | |
888 | as calling wxMilliSleep() with the argument of @e microseconds/1000. | |
889 | ||
890 | @header{wx/utils.h} | |
891 | */ | |
892 | void wxMicroSleep(unsigned long microseconds); | |
893 | ||
894 | /** | |
895 | Sleeps for the specified number of milliseconds. Notice that usage of this | |
896 | function is encouraged instead of calling usleep(3) directly because the | |
897 | standard @e usleep() function is not MT safe. | |
898 | ||
899 | @header{wx/utils.h} | |
900 | */ | |
901 | void wxMilliSleep(unsigned long milliseconds); | |
902 | ||
903 | /** | |
904 | Returns a string representing the current date and time. | |
905 | ||
906 | @header{wx/utils.h} | |
907 | */ | |
908 | wxString wxNow(); | |
909 | ||
39fb8056 FM |
910 | /** |
911 | Sleeps for the specified number of seconds. | |
ba2874ff BP |
912 | |
913 | @header{wx/utils.h} | |
39fb8056 FM |
914 | */ |
915 | void wxSleep(int secs); | |
916 | ||
39fb8056 | 917 | /** |
3950d49c BP |
918 | @deprecated This function is deprecated because its name is misleading: |
919 | notice that the argument is in milliseconds, not microseconds. | |
920 | Please use either wxMilliSleep() or wxMicroSleep() depending on | |
921 | the resolution you need. | |
39fb8056 | 922 | |
3950d49c | 923 | Sleeps for the specified number of milliseconds. |
ba2874ff BP |
924 | |
925 | @header{wx/utils.h} | |
39fb8056 | 926 | */ |
3950d49c BP |
927 | void wxUsleep(unsigned long milliseconds); |
928 | ||
929 | //@} | |
39fb8056 | 930 |