]> git.saurik.com Git - wxWidgets.git/blame - include/wx/utils.h
move wxApp::GetStdIcon to wxArtProvider
[wxWidgets.git] / include / wx / utils.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.h
3// Purpose: Miscellaneous utilities
4// Author: Julian Smart
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Julian Smart
3f4a0c5b 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_UTILSH__
13#define _WX_UTILSH__
c801d85f 14
d6b9496a
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
c801d85f 19#ifdef __GNUG__
d6b9496a 20 #pragma interface "utils.h"
c801d85f
KB
21#endif
22
c801d85f
KB
23#include "wx/object.h"
24#include "wx/list.h"
c801d85f
KB
25#include "wx/filefn.h"
26
eadd7bd2
VZ
27// need this for wxGetDiskSpace() as we can't, unfortunately, forward declare
28// wxLongLong
29#include "wx/longlong.h"
30
c801d85f 31#ifdef __X__
d6b9496a
VZ
32 #include <dirent.h>
33 #include <unistd.h>
c801d85f
KB
34#endif
35
36#include <stdio.h>
37
d6b9496a
VZ
38// ----------------------------------------------------------------------------
39// Forward declaration
40// ----------------------------------------------------------------------------
41
42class WXDLLEXPORT wxProcess;
43class WXDLLEXPORT wxFrame;
e4b4d60e 44class WXDLLEXPORT wxWindow;
cd6ce4a9 45class WXDLLEXPORT wxWindowList;
59a12e90 46class WXDLLEXPORT wxPoint;
d6b9496a 47
d6b9496a
VZ
48// ----------------------------------------------------------------------------
49// Macros
50// ----------------------------------------------------------------------------
c801d85f 51
d6b9496a
VZ
52#define wxMax(a,b) (((a) > (b)) ? (a) : (b))
53#define wxMin(a,b) (((a) < (b)) ? (a) : (b))
c801d85f 54
d6b9496a
VZ
55// ----------------------------------------------------------------------------
56// String functions (deprecated, use wxString)
57// ----------------------------------------------------------------------------
58
8fd0d89b 59// Useful buffer (FIXME VZ: To be removed!!!)
45ff6421
JS
60// Now only needed in Mac and MSW ports
61#if !defined(__WXMOTIF__) && !defined(__WXGTK__) && !defined(__WXX11__) && !defined(__WXMGL__)
9d2f3c71 62WXDLLEXPORT_DATA(extern wxChar*) wxBuffer;
45ff6421 63#endif
c801d85f
KB
64
65// Make a copy of this string using 'new'
9d2f3c71 66WXDLLEXPORT wxChar* copystring(const wxChar *s);
c801d85f 67
d6b9496a 68// Matches string one within string two regardless of case
bc87fd68 69WXDLLEXPORT bool StringMatch(const wxChar *one, const wxChar *two, bool subString = TRUE, bool exact = FALSE);
d6b9496a
VZ
70
71// A shorter way of using strcmp
9d2f3c71 72#define wxStringEq(s1, s2) (s1 && s2 && (wxStrcmp(s1, s2) == 0))
d6b9496a
VZ
73
74// ----------------------------------------------------------------------------
75// Miscellaneous functions
76// ----------------------------------------------------------------------------
77
78// Sound the bell
e90c1d2a 79WXDLLEXPORT void wxBell();
d6b9496a 80
bdc72a22
VZ
81// Get OS description as a user-readable string
82WXDLLEXPORT wxString wxGetOsDescription();
83
d6b9496a 84// Get OS version
bdc72a22
VZ
85WXDLLEXPORT int wxGetOsVersion(int *majorVsn = (int *) NULL,
86 int *minorVsn = (int *) NULL);
d6b9496a
VZ
87
88// Return a string with the current date/time
89WXDLLEXPORT wxString wxNow();
90
134677bd
VS
91// Return path where wxWindows is installed (mostly useful in Unices)
92WXDLLEXPORT const wxChar *wxGetInstallPrefix();
2c18f21d
VS
93// Return path to wxWin data (/usr/share/wx/%{version}) (Unices)
94WXDLLEXPORT wxString wxGetDataDir();
134677bd
VS
95
96
e90c1d2a 97#if wxUSE_GUI
63cc5d9d
RR
98// Don't synthesize KeyUp events holding down a key and producing
99// KeyDown events with autorepeat. On by default and always on
100// in wxMSW.
f0492f7d
RR
101WXDLLEXPORT bool wxSetDetectableAutoRepeat( bool flag );
102
d6b9496a
VZ
103// ----------------------------------------------------------------------------
104// Window ID management
105// ----------------------------------------------------------------------------
106
c801d85f 107// Generate a unique ID
afb74891 108WXDLLEXPORT long wxNewId();
d6b9496a
VZ
109#if !defined(NewId) && defined(WXWIN_COMPATIBILITY)
110 #define NewId wxNewId
111#endif
c801d85f
KB
112
113// Ensure subsequent IDs don't clash with this one
184b5d99 114WXDLLEXPORT void wxRegisterId(long id);
d6b9496a
VZ
115#if !defined(RegisterId) && defined(WXWIN_COMPATIBILITY)
116 #define RegisterId wxRegisterId
117#endif
c801d85f
KB
118
119// Return the current ID
afb74891 120WXDLLEXPORT long wxGetCurrentId();
c801d85f 121
e90c1d2a
VZ
122#endif // wxUSE_GUI
123
d6b9496a
VZ
124// ----------------------------------------------------------------------------
125// Various conversions
126// ----------------------------------------------------------------------------
c801d85f 127
9d2f3c71
OK
128WXDLLEXPORT_DATA(extern const wxChar*) wxFloatToStringStr;
129WXDLLEXPORT_DATA(extern const wxChar*) wxDoubleToStringStr;
c801d85f 130
bc87fd68 131WXDLLEXPORT void StringToFloat(const wxChar *s, float *number);
9d2f3c71 132WXDLLEXPORT wxChar* FloatToString(float number, const wxChar *fmt = wxFloatToStringStr);
bc87fd68 133WXDLLEXPORT void StringToDouble(const wxChar *s, double *number);
9d2f3c71 134WXDLLEXPORT wxChar* DoubleToString(double number, const wxChar *fmt = wxDoubleToStringStr);
bc87fd68
GD
135WXDLLEXPORT void StringToInt(const wxChar *s, int *number);
136WXDLLEXPORT void StringToLong(const wxChar *s, long *number);
9d2f3c71
OK
137WXDLLEXPORT wxChar* IntToString(int number);
138WXDLLEXPORT wxChar* LongToString(long number);
c801d85f 139
c801d85f 140// Convert 2-digit hex number to decimal
184b5d99 141WXDLLEXPORT int wxHexToDec(const wxString& buf);
c801d85f
KB
142
143// Convert decimal integer to 2-character hex string
9d2f3c71 144WXDLLEXPORT void wxDecToHex(int dec, wxChar *buf);
184b5d99 145WXDLLEXPORT wxString wxDecToHex(int dec);
c801d85f 146
d6b9496a
VZ
147// ----------------------------------------------------------------------------
148// Process management
149// ----------------------------------------------------------------------------
150
fbf456aa
VZ
151// NB: for backwars compatibility reasons the values of wxEXEC_[A]SYNC *must*
152// be 0 and 1, don't change!
153
154enum
155{
156 wxEXEC_ASYNC = 0, // execute the process asynchronously
157 wxEXEC_SYNC = 1, // synchronously
158 wxEXEC_NOHIDE = 2 // under Windows, don't hide the child even if it's
159 // IO is redirected (this is done by default)
160};
161
162// Execute another program.
163//
164// If flags contain wxEXEC_SYNC, return -1 on failure and the exit code of the
165// process if everything was ok. Otherwise (i.e. if wxEXEC_ASYNC), return 0 on
166// failure and the PID of the launched process if ok.
167WXDLLEXPORT long wxExecute(wxChar **argv, int flags = wxEXEC_ASYNC,
c67daf87 168 wxProcess *process = (wxProcess *) NULL);
fbf456aa 169WXDLLEXPORT long wxExecute(const wxString& command, int flags = wxEXEC_ASYNC,
c67daf87 170 wxProcess *process = (wxProcess *) NULL);
c801d85f 171
fbf456aa
VZ
172// execute the command capturing its output into an array line by line, this is
173// always synchronous
f6bcfd97
BP
174WXDLLEXPORT long wxExecute(const wxString& command,
175 wxArrayString& output);
176
fbf456aa 177// also capture stderr (also synchronous)
f6bcfd97
BP
178WXDLLEXPORT long wxExecute(const wxString& command,
179 wxArrayString& output,
180 wxArrayString& error);
cd6ce4a9 181
d6b9496a
VZ
182enum wxSignal
183{
184 wxSIGNONE = 0, // verify if the process exists under Unix
185 wxSIGHUP,
186 wxSIGINT,
187 wxSIGQUIT,
188 wxSIGILL,
189 wxSIGTRAP,
190 wxSIGABRT,
191 wxSIGIOT = wxSIGABRT, // another name
192 wxSIGEMT,
193 wxSIGFPE,
194 wxSIGKILL,
195 wxSIGBUS,
196 wxSIGSEGV,
197 wxSIGSYS,
198 wxSIGPIPE,
199 wxSIGALRM,
200 wxSIGTERM
201
202 // further signals are different in meaning between different Unix systems
203};
c801d85f 204
50567b69
VZ
205enum wxKillError
206{
207 wxKILL_OK, // no error
208 wxKILL_BAD_SIGNAL, // no such signal
209 wxKILL_ACCESS_DENIED, // permission denied
210 wxKILL_NO_PROCESS, // no such process
211 wxKILL_ERROR // another, unspecified error
212};
213
214// send the given signal to the process (only NONE and KILL are supported under
215// Windows, all others mean TERM), return 0 if ok and -1 on error
216//
217// return detailed error in rc if not NULL
218WXDLLEXPORT int wxKill(long pid,
219 wxSignal sig = wxSIGTERM,
220 wxKillError *rc = NULL);
c801d85f 221
2c8e4738 222// Execute a command in an interactive shell window (always synchronously)
c801d85f 223// If no command then just the shell
62448488 224WXDLLEXPORT bool wxShell(const wxString& command = wxEmptyString);
c801d85f 225
2c8e4738
VZ
226// As wxShell(), but must give a (non interactive) command and its output will
227// be returned in output array
228WXDLLEXPORT bool wxShell(const wxString& command, wxArrayString& output);
229
b568d04f 230// Sleep for nSecs seconds
184b5d99 231WXDLLEXPORT void wxSleep(int nSecs);
c801d85f 232
afb74891
VZ
233// Sleep for a given amount of milliseconds
234WXDLLEXPORT void wxUsleep(unsigned long milliseconds);
235
c801d85f 236// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
afb74891 237WXDLLEXPORT long wxGetFreeMemory();
c801d85f 238
a37a5a73
VZ
239// should wxApp::OnFatalException() be called?
240WXDLLEXPORT bool wxHandleFatalExceptions(bool doit = TRUE);
241
8fd0d89b
VZ
242// ----------------------------------------------------------------------------
243// Environment variables
244// ----------------------------------------------------------------------------
245
308978f6
VZ
246// returns TRUE if variable exists (value may be NULL if you just want to check
247// for this)
248WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value);
8fd0d89b
VZ
249
250// set the env var name to the given value, return TRUE on success
251WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value);
252
253// remove the env var from environment
254inline bool wxUnsetEnv(const wxString& var) { return wxSetEnv(var, NULL); }
255
d6b9496a
VZ
256// ----------------------------------------------------------------------------
257// Network and username functions.
258// ----------------------------------------------------------------------------
c801d85f 259
d6b9496a 260// NB: "char *" functions are deprecated, use wxString ones!
c801d85f
KB
261
262// Get eMail address
9d2f3c71 263WXDLLEXPORT bool wxGetEmailAddress(wxChar *buf, int maxSize);
d6b9496a 264WXDLLEXPORT wxString wxGetEmailAddress();
c801d85f
KB
265
266// Get hostname.
9d2f3c71 267WXDLLEXPORT bool wxGetHostName(wxChar *buf, int maxSize);
d6b9496a
VZ
268WXDLLEXPORT wxString wxGetHostName();
269
270// Get FQDN
271WXDLLEXPORT wxString wxGetFullHostName();
96c5bd7f 272WXDLLEXPORT bool wxGetFullHostName(wxChar *buf, int maxSize);
c801d85f 273
d6b9496a 274// Get user ID e.g. jacs (this is known as login name under Unix)
9d2f3c71 275WXDLLEXPORT bool wxGetUserId(wxChar *buf, int maxSize);
d6b9496a 276WXDLLEXPORT wxString wxGetUserId();
c801d85f
KB
277
278// Get user name e.g. Julian Smart
9d2f3c71 279WXDLLEXPORT bool wxGetUserName(wxChar *buf, int maxSize);
d6b9496a
VZ
280WXDLLEXPORT wxString wxGetUserName();
281
282// Get current Home dir and copy to dest (returns pstr->c_str())
c51deffc 283WXDLLEXPORT wxString wxGetHomeDir();
9d2f3c71 284WXDLLEXPORT const wxChar* wxGetHomeDir(wxString *pstr);
d6b9496a
VZ
285
286// Get the user's home dir (caller must copy --- volatile)
287// returns NULL is no HOME dir is known
61ef57fc
OK
288#if defined(__UNIX__) && wxUSE_UNICODE
289WXDLLEXPORT const wxMB2WXbuf wxGetUserHome(const wxString& user = wxEmptyString);
290#else
9d2f3c71 291WXDLLEXPORT wxChar* wxGetUserHome(const wxString& user = wxEmptyString);
61ef57fc 292#endif
d6b9496a 293
eadd7bd2
VZ
294// get number of total/free bytes on the disk where path belongs
295WXDLLEXPORT bool wxGetDiskSpace(const wxString& path,
296 wxLongLong *pTotal = NULL,
297 wxLongLong *pFree = NULL);
298
e90c1d2a
VZ
299#if wxUSE_GUI // GUI only things from now on
300
d6b9496a 301// ----------------------------------------------------------------------------
974e8d94 302// Menu accelerators related things
d6b9496a 303// ----------------------------------------------------------------------------
c801d85f 304
bc87fd68 305WXDLLEXPORT wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = (wxChar *) NULL);
184b5d99 306WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str);
c801d85f 307
974e8d94
VZ
308#if wxUSE_ACCEL
309class WXDLLEXPORT wxAcceleratorEntry;
310WXDLLEXPORT wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
311#endif // wxUSE_ACCEL
312
d6b9496a
VZ
313// ----------------------------------------------------------------------------
314// Window search
315// ----------------------------------------------------------------------------
316
c801d85f
KB
317// Find the window/widget with the given title or label.
318// Pass a parent to begin the search from, or NULL to look through
319// all windows.
184b5d99 320WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
321
322// Find window by name, and if that fails, by label.
184b5d99 323WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
324
325// Returns menu item id or -1 if none.
184b5d99 326WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
c801d85f 327
57591e0e
JS
328// Find the wxWindow at the given point. wxGenericFindWindowAtPoint
329// is always present but may be less reliable than a native version.
330WXDLLEXPORT wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
59a12e90
JS
331WXDLLEXPORT wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
332
d6b9496a
VZ
333// ----------------------------------------------------------------------------
334// Message/event queue helpers
335// ----------------------------------------------------------------------------
c801d85f
KB
336
337// Yield to other apps/messages
afb74891 338WXDLLEXPORT bool wxYield();
c801d85f 339
cb2713bf
JS
340// Like wxYield, but fails silently if the yield is recursive.
341WXDLLEXPORT bool wxYieldIfNeeded();
342
ead7ce10
KB
343// Yield to other apps/messages and disable user input
344WXDLLEXPORT bool wxSafeYield(wxWindow *win = NULL);
345
95dee651
KB
346// Enable or disable input to all top level windows
347WXDLLEXPORT void wxEnableTopLevelWindows(bool enable = TRUE);
348
d6b9496a
VZ
349// Check whether this window wants to process messages, e.g. Stop button
350// in long calculations.
351WXDLLEXPORT bool wxCheckForInterrupt(wxWindow *wnd);
352
353// Consume all events until no more left
354WXDLLEXPORT void wxFlushEvents();
355
cd6ce4a9
VZ
356// a class which disables all windows (except, may be, thegiven one) in its
357// ctor and enables them back in its dtor
358class WXDLLEXPORT wxWindowDisabler
359{
360public:
361 wxWindowDisabler(wxWindow *winToSkip = (wxWindow *)NULL);
362 ~wxWindowDisabler();
363
364private:
365 wxWindowList *m_winDisabled;
366};
367
d6b9496a
VZ
368// ----------------------------------------------------------------------------
369// Cursors
370// ----------------------------------------------------------------------------
c801d85f
KB
371
372// Set the cursor to the busy cursor for all windows
373class WXDLLEXPORT wxCursor;
374WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
184b5d99 375WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
e2a6f233 376
c801d85f 377// Restore cursor to normal
afb74891 378WXDLLEXPORT void wxEndBusyCursor();
d6b9496a 379
c801d85f 380// TRUE if we're between the above two calls
afb74891 381WXDLLEXPORT bool wxIsBusy();
c801d85f 382
e2a6f233
JS
383// Convenience class so we can just create a wxBusyCursor object on the stack
384class WXDLLEXPORT wxBusyCursor
385{
afb74891
VZ
386public:
387 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR)
388 { wxBeginBusyCursor(cursor); }
f6bcfd97 389 ~wxBusyCursor()
afb74891 390 { wxEndBusyCursor(); }
e2a6f233 391
f6bcfd97
BP
392 // FIXME: These two methods are currently only implemented (and needed?)
393 // in wxGTK. BusyCursor handling should probably be moved to
394 // common code since the wxGTK and wxMSW implementations are very
395 // similar except for wxMSW using HCURSOR directly instead of
396 // wxCursor.. -- RL.
397 static const wxCursor &GetStoredCursor();
398 static const wxCursor GetBusyCursor();
399};
c801d85f 400
c801d85f 401
d6b9496a 402// ----------------------------------------------------------------------------
c801d85f 403// Reading and writing resources (eg WIN.INI, .Xdefaults)
d6b9496a
VZ
404// ----------------------------------------------------------------------------
405
47d67540 406#if wxUSE_RESOURCES
62448488
JS
407WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = wxEmptyString);
408WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = wxEmptyString);
409WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = wxEmptyString);
410WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = wxEmptyString);
411
9d2f3c71 412WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file = wxEmptyString);
62448488
JS
413WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = wxEmptyString);
414WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = wxEmptyString);
415WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = wxEmptyString);
47d67540 416#endif // wxUSE_RESOURCES
c801d85f 417
c801d85f
KB
418void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
419
420// MSW only: get user-defined resource from the .res file.
421// Returns NULL or newly-allocated memory, so use delete[] to clean up.
2049ba38 422#ifdef __WXMSW__
373658eb
VZ
423 WXDLLEXPORT extern const wxChar* wxUserResourceStr;
424 WXDLLEXPORT wxChar* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
d6b9496a
VZ
425#endif // MSW
426
427// ----------------------------------------------------------------------------
428// Display and colorss (X only)
429// ----------------------------------------------------------------------------
c801d85f 430
d111a89a
VZ
431#ifdef __WXGTK__
432 void *wxGetDisplay();
433#endif
434
c801d85f 435#ifdef __X__
d6b9496a
VZ
436 WXDisplay *wxGetDisplay();
437 bool wxSetDisplay(const wxString& display_name);
438 wxString wxGetDisplayName();
d111a89a 439#endif // X or GTK+
c801d85f
KB
440
441#ifdef __X__
442
338dd992
JJ
443#ifdef __VMS__ // Xlib.h for VMS is not (yet) compatible with C++
444 // The resulting warnings are switched off here
445#pragma message disable nosimpint
446#endif
7266b672 447// #include <X11/Xlib.h>
338dd992
JJ
448#ifdef __VMS__
449#pragma message enable nosimpint
450#endif
c801d85f 451
c801d85f
KB
452#endif //__X__
453
e90c1d2a
VZ
454#endif // wxUSE_GUI
455
f6bcfd97
BP
456// ----------------------------------------------------------------------------
457// Error message functions used by wxWindows (deprecated, use wxLog)
458// ----------------------------------------------------------------------------
459
73deed44
VZ
460#if WXWIN_COMPATIBILITY_2_2
461
f6bcfd97
BP
462// Format a message on the standard error (UNIX) or the debugging
463// stream (Windows)
464WXDLLEXPORT void wxDebugMsg(const wxChar *fmt ...);
465
466// Non-fatal error (continues)
467WXDLLEXPORT_DATA(extern const wxChar*) wxInternalErrorStr;
468WXDLLEXPORT void wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
469
470// Fatal error (exits)
471WXDLLEXPORT_DATA(extern const wxChar*) wxFatalErrorStr;
472WXDLLEXPORT void wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
473
73deed44 474#endif // WXWIN_COMPATIBILITY_2_2
f6bcfd97 475
c801d85f 476#endif
34138703 477 // _WX_UTILSH__