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