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