]> git.saurik.com Git - wxWidgets.git/blob - interface/utils.h
pen.h depends from brush.h in compat mode
[wxWidgets.git] / interface / utils.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utils.h
3 // Purpose: interface of wxWindowDisabler
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxWindowDisabler
11 @wxheader{utils.h}
12
13 This class disables all windows of the application (may be with the exception
14 of one of them) in its constructor and enables them back in its destructor.
15 This comes in handy when you want to indicate to the user that the application
16 is currently busy and cannot respond to user input.
17
18 @library{wxcore}
19 @category{FIXME}
20
21 @see wxBusyCursor
22 */
23 class wxWindowDisabler
24 {
25 public:
26 /**
27 Disables all top level windows of the applications with the exception of
28 @a winToSkip if it is not @NULL.
29 */
30 wxWindowDisabler(wxWindow* winToSkip = NULL);
31
32 /**
33 Reenables back the windows disabled by the constructor.
34 */
35 ~wxWindowDisabler();
36 };
37
38
39
40 /**
41 @class wxBusyCursor
42 @wxheader{utils.h}
43
44 This class makes it easy to tell your user that the program is temporarily busy.
45 Just create a wxBusyCursor object on the stack, and within the current scope,
46 the hourglass will be shown.
47
48 For example:
49
50 @code
51 wxBusyCursor wait;
52
53 for (int i = 0; i 100000; i++)
54 DoACalculation();
55 @endcode
56
57 It works by calling wxBeginBusyCursor() in the constructor,
58 and wxEndBusyCursor() in the destructor.
59
60 @library{wxcore}
61 @category{FIXME}
62
63 @see wxBeginBusyCursor(), wxEndBusyCursor(), wxWindowDisabler
64 */
65 class wxBusyCursor
66 {
67 public:
68 /**
69 Constructs a busy cursor object, calling wxBeginBusyCursor().
70 */
71 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
72
73 /**
74 Destroys the busy cursor object, calling wxEndBusyCursor().
75 */
76 ~wxBusyCursor();
77 };
78
79
80
81 // ============================================================================
82 // Global functions/macros
83 // ============================================================================
84
85 /**
86 Returns the type of power source as one of @c wxPOWER_SOCKET,
87 @c wxPOWER_BATTERY or @c wxPOWER_UNKNOWN.
88 @c wxPOWER_UNKNOWN is also the default on platforms where this
89 feature is not implemented (currently everywhere but MS Windows).
90 */
91 wxPowerType wxGetPowerType();
92
93 //@{
94 /**
95 This function returns the "user id" also known as "login name" under Unix i.e.
96 something like "jsmith". It uniquely identifies the current user (on this
97 system).
98 Under Windows or NT, this function first looks in the environment
99 variables USER and LOGNAME; if neither of these is found, the entry @b UserId
100 in the @b wxWidgets section of the WIN.INI file is tried.
101 The first variant of this function returns the login name if successful or an
102 empty string otherwise. The second (deprecated) function returns @true
103 if successful, @false otherwise.
104
105 @see wxGetUserName()
106 */
107 wxString wxGetUserId();
108 bool wxGetUserId(char* buf, int sz);
109 //@}
110
111 /**
112 @b NB: This function is now obsolete, please use
113 wxLogFatalError() instead.
114 Displays @a msg and exits. This writes to standard error under Unix,
115 and pops up a message box under Windows. Used for fatal internal
116 wxWidgets errors. See also wxError().
117 */
118 void wxFatalError(const wxString& msg,
119 const wxString& title = "wxWidgets Fatal Error");
120
121 /**
122 Returns battery state as one of @c wxBATTERY_NORMAL_STATE,
123 @c wxBATTERY_LOW_STATE, @c wxBATTERY_CRITICAL_STATE,
124 @c wxBATTERY_SHUTDOWN_STATE or @c wxBATTERY_UNKNOWN_STATE.
125 @c wxBATTERY_UNKNOWN_STATE is also the default on platforms where
126 this feature is not implemented (currently everywhere but MS Windows).
127 */
128 wxBatteryState wxGetBatteryState();
129
130 /**
131 @b NB: This function is obsolete, please use
132 wxWindow::FindWindowByName instead.
133 Find a window by its name (as given in a window constructor or @b Create
134 function call).
135 If @a parent is @NULL, the search will start from all top-level
136 frames and dialog boxes; if non-@NULL, the search will be limited to the given
137 window hierarchy.
138 The search is recursive in both cases.
139 If no such named window is found, @b wxFindWindowByLabel is called.
140 */
141 wxWindow* wxFindWindowByName(const wxString& name,
142 wxWindow* parent = NULL);
143
144 /**
145 Changes the cursor back to the original cursor, for all windows in the
146 application.
147 Use with wxBeginBusyCursor().
148 See also wxIsBusy(), wxBusyCursor.
149 */
150 void wxEndBusyCursor();
151
152 /**
153 This function is deprecated as the ids generated by it can conflict with the
154 ids defined by the user code, use @c wxID_ANY to assign ids which are
155 guaranteed to not conflict with the user-defined ids for the controls and menu
156 items you create instead of using this function.
157
158 Generates an integer identifier unique to this run of the program.
159 */
160 long wxNewId();
161
162 /**
163 Ensures that ids subsequently generated by @b NewId do not clash with
164 the given @b id.
165 */
166 void wxRegisterId(long id);
167
168 /**
169 @b NB: This function is now obsolete, replaced by Log
170 functions() and wxLogDebug() in particular.
171 Display a debugging message; under Windows, this will appear on the
172 debugger command window, and under Unix, it will be written to standard
173 error.
174 The syntax is identical to @b printf: pass a format string and a
175 variable list of arguments.
176 @b Tip: under Windows, if your application crashes before the
177 message appears in the debugging window, put a wxYield call after
178 each wxDebugMsg call. wxDebugMsg seems to be broken under WIN32s
179 (at least for Watcom C++): preformat your messages and use OutputDebugString
180 instead.
181 */
182 void wxDebugMsg(const wxString& fmt, ... );
183
184 /**
185 For normal keys, returns @true if the specified key is currently down.
186 For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns
187 @true if the key is toggled such that its LED indicator is lit. There is
188 currently no way to test whether togglable keys are up or down.
189 Even though there are virtual key codes defined for mouse buttons, they
190 cannot be used with this function currently.
191 */
192 bool wxGetKeyState(wxKeyCode key);
193
194 /**
195 Returns the string containing the description of the current platform in a
196 user-readable form. For example, this function may return strings like
197 @c Windows NT Version 4.0 or @c Linux 2.2.2 i386.
198
199 @see ::wxGetOsVersion
200 */
201 wxString wxGetOsDescription();
202
203 /**
204 Return the (current) user's home directory.
205
206 @see wxGetUserHome(), wxStandardPaths
207 */
208 wxString wxGetHomeDir();
209
210 /**
211 Sleeps for the specified number of milliseconds. Notice that usage of this
212 function is encouraged instead of calling usleep(3) directly because the
213 standard usleep() function is not MT safe.
214 */
215 void wxMilliSleep(unsigned long milliseconds);
216
217 /**
218 Sleeps for the specified number of microseconds. The microsecond resolution may
219 not, in fact, be available on all platforms (currently only Unix platforms with
220 nanosleep(2) may provide it) in which case this is the same as
221 wxMilliSleep()(@e microseconds/1000).
222 */
223 void wxMicroSleep(unsigned long microseconds);
224
225 /**
226 Shows a message box with the information about the wxWidgets build used,
227 including its version, most important build parameters and the version of the
228 underlying GUI toolkit. This is mainly used for diagnostic purposes and can be
229 invoked by Ctrl-Alt-middle clicking on any wxWindow which doesn't otherwise
230 handle this event.
231
232 @wxsince{2.9.0}
233 */
234 void wxInfoMessageBox(wxWindow ( parent = NULL);
235
236 /**
237 Find a menu item identifier associated with the given frame's menu bar.
238 */
239 int wxFindMenuItemId(wxFrame* frame, const wxString& menuString,
240 const wxString& itemString);
241
242 /**
243 This function enables or disables all top level windows. It is used by
244 ::wxSafeYield.
245 */
246 void wxEnableTopLevelWindows(bool enable = true);
247
248 /**
249 Strips any menu codes from @a str and returns the result.
250 By default, the functions strips both the mnemonics character (@c '')
251 which is used to indicate a keyboard shortkey, and the accelerators, which are
252 used only in the menu items and are separated from the main text by the
253 @c \t (TAB) character. By using @a flags of
254 @c wxStrip_Mnemonics or @c wxStrip_Accel to strip only the former
255 or the latter part, respectively.
256 Notice that in most cases
257 wxMenuItem::GetLabelFromText or
258 wxControl::GetLabelText can be used instead.
259 */
260 wxString wxStripMenuCodes(const wxString& str,
261 int flags = wxStrip_All);
262
263 /**
264 @b NB: This function is now obsolete, please use wxLogError()
265 instead.
266 Displays @a msg and continues. This writes to standard error under
267 Unix, and pops up a message box under Windows. Used for internal
268 wxWidgets errors. See also wxFatalError().
269 */
270 void wxError(const wxString& msg,
271 const wxString& title = "wxWidgets Internal Error");
272
273 /**
274 Open the @a url in user's default browser. If @a flags parameter contains
275 @c wxBROWSER_NEW_WINDOW flag, a new window is opened for the URL
276 (currently this is only supported under Windows). The @a url may also be a
277 local file path (with or without @c file:// prefix), if it doesn't
278 correspond to an existing file and the URL has no scheme @c http:// is
279 prepended to it by default.
280 Returns @true if the application was successfully launched.
281 Note that for some configurations of the running user, the application which
282 is launched to open the given URL may be URL-dependent (e.g. a browser may be
283 used for
284 local URLs while another one may be used for remote URLs).
285 */
286 bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0);
287
288 /**
289 Executes a command in an interactive shell window. If no command is
290 specified, then just the shell is spawned.
291 See also wxExecute(), @ref overview_sampleexec "Exec sample".
292 */
293 bool wxShell(const wxString& command = NULL);
294
295 /**
296 Gets the version and the operating system ID for currently running OS.
297 See wxPlatformInfo for more details about wxOperatingSystemId.
298
299 @see ::wxGetOsDescription, wxPlatformInfo
300 */
301 wxOperatingSystemId wxGetOsVersion(int* major = NULL,
302 int* minor = NULL);
303
304 /**
305 Returns the FQDN (fully qualified domain host name) or an empty string on
306 error.
307
308 @see wxGetHostName()
309 */
310 wxString wxGetFullHostName();
311
312 /**
313 Changes the cursor to the given cursor for all windows in the application.
314 Use wxEndBusyCursor() to revert the cursor back
315 to its previous state. These two calls can be nested, and a counter
316 ensures that only the outer calls take effect.
317 See also wxIsBusy(), wxBusyCursor.
318 */
319 void wxBeginBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
320
321 /**
322 Tells the system to delete the specified object when
323 all other events have been processed. In some environments, it is
324 necessary to use this instead of deleting a frame directly with the
325 delete operator, because some GUIs will still send events to a deleted window.
326 Now obsolete: use wxWindow::Close instead.
327 */
328 void wxPostDelete(wxObject* object);
329
330 /**
331 @b NB: This function is obsolete, please use
332 wxWindow::FindWindowByLabel instead.
333 Find a window by its label. Depending on the type of window, the label may be a
334 window title
335 or panel item label. If @a parent is @NULL, the search will start from all
336 top-level
337 frames and dialog boxes; if non-@NULL, the search will be limited to the given
338 window hierarchy.
339 The search is recursive in both cases.
340 */
341 wxWindow* wxFindWindowByLabel(const wxString& label,
342 wxWindow* parent = NULL);
343
344
345 /**
346 Returns the mouse position in screen coordinates.
347 */
348 wxPoint wxGetMousePosition();
349
350 /**
351 Loads a user-defined Windows resource as a string. If the resource is found,
352 the function creates
353 a new character array and copies the data into it. A pointer to this data is
354 returned. If unsuccessful, @NULL is returned.
355 The resource must be defined in the @c .rc file using the following syntax:
356
357 @code
358 myResource TEXT file.ext
359 @endcode
360
361 where @c file.ext is a file that the resource compiler can find.
362 This function is available under Windows only.
363 */
364 wxString wxLoadUserResource(const wxString& resourceName,
365 const wxString& resourceType = "TEXT");
366
367 /**
368 Returns the amount of free memory in bytes under environments which
369 support it, and -1 if not supported or failed to perform measurement.
370 */
371 wxMemorySize wxGetFreeMemory();
372
373 /**
374 This is a macro defined as @c getenv() or its wide char version in Unicode
375 mode.
376 Note that under Win32 it may not return correct value for the variables set
377 with wxSetEnv(), use wxGetEnv() function
378 instead.
379 */
380 wxChar* wxGetEnv(const wxString& var);
381
382 //@{
383 /**
384 Copies the current host machine's name into the supplied buffer. Please note
385 that the returned name is @e not fully qualified, i.e. it does not include
386 the domain name.
387 Under Windows or NT, this function first looks in the environment
388 variable SYSTEM_NAME; if this is not found, the entry @b HostName
389 in the @b wxWidgets section of the WIN.INI file is tried.
390 The first variant of this function returns the hostname if successful or an
391 empty string otherwise. The second (deprecated) function returns @true
392 if successful, @false otherwise.
393
394 @see wxGetFullHostName()
395 */
396 wxString wxGetHostName();
397 bool wxGetHostName(char* buf, int sz);
398 //@}
399
400 /**
401 Returns the current value of the environment variable @a var in @e value.
402 @a value may be @NULL if you just want to know if the variable exists
403 and are not interested in its value.
404 Returns @true if the variable exists, @false otherwise.
405 */
406 bool wxGetEnv(const wxString& var, wxString* value);
407
408 /**
409 Under X only, returns the current display name. See also wxSetDisplayName().
410 */
411 wxString wxGetDisplayName();
412
413 /**
414 Ring the system bell.
415 Note that this function is categorized as a GUI one and so is not thread-safe.
416 */
417 void wxBell();
418
419 /**
420 Returns the home directory for the given user. If the @a user is empty
421 (default value), this function behaves like
422 wxGetHomeDir() i.e. returns the current user home
423 directory.
424 If the home directory couldn't be determined, an empty string is returned.
425 */
426 wxString wxGetUserHome(const wxString& user = "");
427
428 //@{
429 /**
430 @b wxPerl note: In wxPerl this function is called @c Wx::ExecuteStdoutStderr
431 and it only takes the @c command argument,
432 and returns a 3-element list @c ( status, output, errors ), where
433 @c output and @c errors are array references.
434 Executes another program in Unix or Windows.
435 The first form takes a command string, such as @c "emacs file.txt".
436 The second form takes an array of values: a command, any number of
437 arguments, terminated by @NULL.
438 The semantics of the third and fourth versions is different from the first two
439 and is described in more details below.
440 If @a flags parameter contains @c wxEXEC_ASYNC flag (the default), flow
441 of control immediately returns. If it contains @c wxEXEC_SYNC, the current
442 application waits until the other program has terminated.
443 In the case of synchronous execution, the return value is the exit code of
444 the process (which terminates by the moment the function returns) and will be
445 -1 if the process couldn't be started and typically 0 if the process
446 terminated successfully. Also, while waiting for the process to
447 terminate, wxExecute will call wxYield(). Because of this, by
448 default this function disables all application windows to avoid unexpected
449 reentrancies which could result from the users interaction with the program
450 while the child process is running. If you are sure that it is safe to not
451 disable the program windows, you may pass @c wxEXEC_NODISABLE flag to
452 prevent this automatic disabling from happening.
453 For asynchronous execution, however, the return value is the process id and
454 zero value indicates that the command could not be executed. As an added
455 complication, the return value of -1 in this case indicates that we didn't
456 launch a new process, but connected to the running one (this can only happen in
457 case of using DDE under Windows for command execution). In particular, in this,
458 and only this, case the calling code will not get the notification about
459 process termination.
460 If callback isn't @NULL and if execution is asynchronous,
461 wxProcess::OnTerminate will be called when
462 the process finishes. Specifying this parameter also allows you to redirect the
463 standard input and/or output of the process being launched by calling
464 wxProcess::Redirect. If the child process IO is redirected,
465 under Windows the process window is not shown by default (this avoids having to
466 flush an unnecessary console for the processes which don't create any windows
467 anyhow) but a @c wxEXEC_NOHIDE flag can be used to prevent this from
468 happening, i.e. with this flag the child process window will be shown normally.
469 Under Unix the flag @c wxEXEC_MAKE_GROUP_LEADER may be used to ensure
470 that the new process is a group leader (this will create a new session if
471 needed). Calling wxKill() passing wxKILL_CHILDREN will
472 kill this process as well as all of its children (except those which have
473 started their own session).
474 The @c wxEXEC_NOEVENTS flag prevents processing of any events from taking
475 place while the child process is running. It should be only used for very
476 short-lived processes as otherwise the application windows risk becoming
477 unresponsive from the users point of view. As this flag only makes sense with
478 @c wxEXEC_SYNC, @c wxEXEC_BLOCK equal to the sum of both of these flags
479 is provided as a convenience.
480 Finally, you may use the third overloaded version of this function to execute
481 a process (always synchronously, the contents of @a flags is or'd with
482 @c wxEXEC_SYNC) and capture its output in the array @e output. The
483 fourth version adds the possibility to additionally capture the messages from
484 standard error output in the @a errors array.
485 @b NB: Currently wxExecute() can only be used from the main thread, calling
486 this function from another thread will result in an assert failure in debug
487 build and won't work.
488
489 @param command
490 The command to execute and any parameters to pass to it as a
491 single string.
492 @param argv
493 The command to execute should be the first element of this
494 array, any additional ones are the command parameters and the array must be
495 terminated with a @NULL pointer.
496 @param flags
497 Combination of bit masks wxEXEC_ASYNC,
498 wxEXEC_SYNC and wxEXEC_NOHIDE
499 @param callback
500 An optional pointer to wxProcess
501
502 @see wxShell(), wxProcess, @ref overview_sampleexec "Exec sample".
503 */
504 long wxExecute(const wxString& command, int sync = wxEXEC_ASYNC,
505 wxProcess* callback = NULL);
506 wxPerl note: long wxExecute(char** argv,
507 int flags = wxEXEC_ASYNC,
508 wxProcess* callback = NULL);
509 wxPerl note: long wxExecute(const wxString& command,
510 wxArrayString& output,
511 int flags = 0);
512 wxPerl note: long wxExecute(const wxString& command,
513 wxArrayString& output,
514 wxArrayString& errors,
515 int flags = 0);
516 //@}
517
518 /**
519 Returns a string representing the current date and time.
520 */
521 wxString wxNow();
522
523 /**
524 Returns @true if the operating system the program is running under is 64 bit.
525 The check is performed at run-time and may differ from the value available at
526 compile-time (at compile-time you can just check if @c sizeof(void*)==8)
527 since the program could be running in emulation mode or in a mixed 32/64 bit
528 system
529 (bi-architecture operating system).
530 Very important: this function is not 100% reliable on some systems given the
531 fact
532 that there isn't always a standard way to do a reliable check on the OS
533 architecture.
534 */
535 bool wxIsPlatform64Bit();
536
537 /**
538 Returns the number uniquely identifying the current process in the system.
539 If an error occurs, 0 is returned.
540 */
541 unsigned long wxGetProcessId();
542
543 /**
544 Equivalent to the Unix kill function: send the given signal @a sig to the
545 process with PID @e pid. The valid signal values are
546
547 @code
548 enum wxSignal
549 {
550 wxSIGNONE = 0, // verify if the process exists under Unix
551 wxSIGHUP,
552 wxSIGINT,
553 wxSIGQUIT,
554 wxSIGILL,
555 wxSIGTRAP,
556 wxSIGABRT,
557 wxSIGEMT,
558 wxSIGFPE,
559 wxSIGKILL, // forcefully kill, dangerous!
560 wxSIGBUS,
561 wxSIGSEGV,
562 wxSIGSYS,
563 wxSIGPIPE,
564 wxSIGALRM,
565 wxSIGTERM // terminate the process gently
566 };
567 @endcode
568
569 @c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning
570 under both Unix and Windows but all the other signals are equivalent to
571 @c wxSIGTERM under Windows.
572 Returns 0 on success, -1 on failure. If @a rc parameter is not @NULL, it will
573 be filled with an element of @c wxKillError enum:
574
575 @code
576 enum wxKillError
577 {
578 wxKILL_OK, // no error
579 wxKILL_BAD_SIGNAL, // no such signal
580 wxKILL_ACCESS_DENIED, // permission denied
581 wxKILL_NO_PROCESS, // no such process
582 wxKILL_ERROR // another, unspecified error
583 };
584 @endcode
585
586 The @a flags parameter can be wxKILL_NOCHILDREN (the default),
587 or wxKILL_CHILDREN, in which case the child processes of this
588 process will be killed too. Note that under Unix, for wxKILL_CHILDREN
589 to work you should have created the process by passing wxEXEC_MAKE_GROUP_LEADER
590 to wxExecute.
591
592 @see wxProcess::Kill, wxProcess::Exists, @ref overview_sampleexec "Exec sample"
593 */
594 int wxKill(long pid, int sig = wxSIGTERM, wxKillError rc = NULL,
595 int flags = 0);
596
597 /**
598 Returns the current state of the mouse. Returns a wxMouseState
599 instance that contains the current position of the mouse pointer in
600 screen coordinates, as well as boolean values indicating the up/down
601 status of the mouse buttons and the modifier keys.
602 */
603 wxMouseState wxGetMouseState();
604
605 /**
606 Returns @true if between two wxBeginBusyCursor() and
607 wxEndBusyCursor() calls.
608 See also wxBusyCursor.
609 */
610 bool wxIsBusy();
611
612 //@{
613 /**
614 Copies the user's email address into the supplied buffer, by
615 concatenating the values returned by wxGetFullHostName()
616 and wxGetUserId().
617 Returns @true if successful, @false otherwise.
618 */
619 wxString wxGetEmailAddress();
620 bool wxGetEmailAddress(char* buf, int sz);
621 //@}
622
623 /**
624 Sleeps for the specified number of seconds.
625 */
626 void wxSleep(int secs);
627
628 /**
629 Sets the value of the environment variable @a var (adding it if necessary)
630 to @e value.
631 Returns @true on success.
632
633 @see wxUnsetEnv()
634 */
635 bool wxSetEnv(const wxString& var, const wxString& value);
636
637 /**
638 Returns @true if the current platform is little endian (instead of big
639 endian).
640 The check is performed at run-time.
641
642 @see @ref overview_byteordermacros "Byte order macros"
643 */
644 bool wxIsPlatformLittleEndian();
645
646 /**
647 Under X only, sets the current display name. This is the X host and display
648 name such
649 as "colonsay:0.0", and the function indicates which display should be used for
650 creating
651 windows from this point on. Setting the display within an application allows
652 multiple
653 displays to be used.
654 See also wxGetDisplayName().
655 */
656 void wxSetDisplayName(const wxString& displayName);
657