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