]> git.saurik.com Git - wxWidgets.git/blame - include/wx/utils.h
Fix so OGL can build without wxBuffer
[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
c801d85f 151// Execute another program. Returns 0 if there was an error, a PID otherwise.
9d2f3c71 152WXDLLEXPORT long wxExecute(wxChar **argv, bool sync = FALSE,
c67daf87 153 wxProcess *process = (wxProcess *) NULL);
184b5d99 154WXDLLEXPORT long wxExecute(const wxString& command, bool sync = FALSE,
c67daf87 155 wxProcess *process = (wxProcess *) NULL);
c801d85f 156
cd6ce4a9 157// execute the command capturing its output into an array line by line
f6bcfd97
BP
158WXDLLEXPORT long wxExecute(const wxString& command,
159 wxArrayString& output);
160
161// also capture stderr
162WXDLLEXPORT long wxExecute(const wxString& command,
163 wxArrayString& output,
164 wxArrayString& error);
cd6ce4a9 165
d6b9496a
VZ
166enum wxSignal
167{
168 wxSIGNONE = 0, // verify if the process exists under Unix
169 wxSIGHUP,
170 wxSIGINT,
171 wxSIGQUIT,
172 wxSIGILL,
173 wxSIGTRAP,
174 wxSIGABRT,
175 wxSIGIOT = wxSIGABRT, // another name
176 wxSIGEMT,
177 wxSIGFPE,
178 wxSIGKILL,
179 wxSIGBUS,
180 wxSIGSEGV,
181 wxSIGSYS,
182 wxSIGPIPE,
183 wxSIGALRM,
184 wxSIGTERM
185
186 // further signals are different in meaning between different Unix systems
187};
c801d85f 188
50567b69
VZ
189enum wxKillError
190{
191 wxKILL_OK, // no error
192 wxKILL_BAD_SIGNAL, // no such signal
193 wxKILL_ACCESS_DENIED, // permission denied
194 wxKILL_NO_PROCESS, // no such process
195 wxKILL_ERROR // another, unspecified error
196};
197
198// send the given signal to the process (only NONE and KILL are supported under
199// Windows, all others mean TERM), return 0 if ok and -1 on error
200//
201// return detailed error in rc if not NULL
202WXDLLEXPORT int wxKill(long pid,
203 wxSignal sig = wxSIGTERM,
204 wxKillError *rc = NULL);
c801d85f 205
2c8e4738 206// Execute a command in an interactive shell window (always synchronously)
c801d85f 207// If no command then just the shell
62448488 208WXDLLEXPORT bool wxShell(const wxString& command = wxEmptyString);
c801d85f 209
2c8e4738
VZ
210// As wxShell(), but must give a (non interactive) command and its output will
211// be returned in output array
212WXDLLEXPORT bool wxShell(const wxString& command, wxArrayString& output);
213
b568d04f 214// Sleep for nSecs seconds
184b5d99 215WXDLLEXPORT void wxSleep(int nSecs);
c801d85f 216
afb74891
VZ
217// Sleep for a given amount of milliseconds
218WXDLLEXPORT void wxUsleep(unsigned long milliseconds);
219
c801d85f 220// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
afb74891 221WXDLLEXPORT long wxGetFreeMemory();
c801d85f 222
a37a5a73
VZ
223// should wxApp::OnFatalException() be called?
224WXDLLEXPORT bool wxHandleFatalExceptions(bool doit = TRUE);
225
8fd0d89b
VZ
226// ----------------------------------------------------------------------------
227// Environment variables
228// ----------------------------------------------------------------------------
229
308978f6
VZ
230// returns TRUE if variable exists (value may be NULL if you just want to check
231// for this)
232WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value);
8fd0d89b
VZ
233
234// set the env var name to the given value, return TRUE on success
235WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value);
236
237// remove the env var from environment
238inline bool wxUnsetEnv(const wxString& var) { return wxSetEnv(var, NULL); }
239
d6b9496a
VZ
240// ----------------------------------------------------------------------------
241// Network and username functions.
242// ----------------------------------------------------------------------------
c801d85f 243
d6b9496a 244// NB: "char *" functions are deprecated, use wxString ones!
c801d85f
KB
245
246// Get eMail address
9d2f3c71 247WXDLLEXPORT bool wxGetEmailAddress(wxChar *buf, int maxSize);
d6b9496a 248WXDLLEXPORT wxString wxGetEmailAddress();
c801d85f
KB
249
250// Get hostname.
9d2f3c71 251WXDLLEXPORT bool wxGetHostName(wxChar *buf, int maxSize);
d6b9496a
VZ
252WXDLLEXPORT wxString wxGetHostName();
253
254// Get FQDN
255WXDLLEXPORT wxString wxGetFullHostName();
96c5bd7f 256WXDLLEXPORT bool wxGetFullHostName(wxChar *buf, int maxSize);
c801d85f 257
d6b9496a 258// Get user ID e.g. jacs (this is known as login name under Unix)
9d2f3c71 259WXDLLEXPORT bool wxGetUserId(wxChar *buf, int maxSize);
d6b9496a 260WXDLLEXPORT wxString wxGetUserId();
c801d85f
KB
261
262// Get user name e.g. Julian Smart
9d2f3c71 263WXDLLEXPORT bool wxGetUserName(wxChar *buf, int maxSize);
d6b9496a
VZ
264WXDLLEXPORT wxString wxGetUserName();
265
266// Get current Home dir and copy to dest (returns pstr->c_str())
c51deffc 267WXDLLEXPORT wxString wxGetHomeDir();
9d2f3c71 268WXDLLEXPORT const wxChar* wxGetHomeDir(wxString *pstr);
d6b9496a
VZ
269
270// Get the user's home dir (caller must copy --- volatile)
271// returns NULL is no HOME dir is known
61ef57fc
OK
272#if defined(__UNIX__) && wxUSE_UNICODE
273WXDLLEXPORT const wxMB2WXbuf wxGetUserHome(const wxString& user = wxEmptyString);
274#else
9d2f3c71 275WXDLLEXPORT wxChar* wxGetUserHome(const wxString& user = wxEmptyString);
61ef57fc 276#endif
d6b9496a 277
eadd7bd2
VZ
278// get number of total/free bytes on the disk where path belongs
279WXDLLEXPORT bool wxGetDiskSpace(const wxString& path,
280 wxLongLong *pTotal = NULL,
281 wxLongLong *pFree = NULL);
282
e90c1d2a
VZ
283#if wxUSE_GUI // GUI only things from now on
284
d6b9496a 285// ----------------------------------------------------------------------------
974e8d94 286// Menu accelerators related things
d6b9496a 287// ----------------------------------------------------------------------------
c801d85f 288
bc87fd68 289WXDLLEXPORT wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = (wxChar *) NULL);
184b5d99 290WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str);
c801d85f 291
974e8d94
VZ
292#if wxUSE_ACCEL
293class WXDLLEXPORT wxAcceleratorEntry;
294WXDLLEXPORT wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
295#endif // wxUSE_ACCEL
296
d6b9496a
VZ
297// ----------------------------------------------------------------------------
298// Window search
299// ----------------------------------------------------------------------------
300
c801d85f
KB
301// Find the window/widget with the given title or label.
302// Pass a parent to begin the search from, or NULL to look through
303// all windows.
184b5d99 304WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
305
306// Find window by name, and if that fails, by label.
184b5d99 307WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
308
309// Returns menu item id or -1 if none.
184b5d99 310WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
c801d85f 311
57591e0e
JS
312// Find the wxWindow at the given point. wxGenericFindWindowAtPoint
313// is always present but may be less reliable than a native version.
314WXDLLEXPORT wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
59a12e90
JS
315WXDLLEXPORT wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
316
d6b9496a
VZ
317// ----------------------------------------------------------------------------
318// Message/event queue helpers
319// ----------------------------------------------------------------------------
c801d85f
KB
320
321// Yield to other apps/messages
afb74891 322WXDLLEXPORT bool wxYield();
c801d85f 323
cb2713bf
JS
324// Like wxYield, but fails silently if the yield is recursive.
325WXDLLEXPORT bool wxYieldIfNeeded();
326
ead7ce10
KB
327// Yield to other apps/messages and disable user input
328WXDLLEXPORT bool wxSafeYield(wxWindow *win = NULL);
329
95dee651
KB
330// Enable or disable input to all top level windows
331WXDLLEXPORT void wxEnableTopLevelWindows(bool enable = TRUE);
332
d6b9496a
VZ
333// Check whether this window wants to process messages, e.g. Stop button
334// in long calculations.
335WXDLLEXPORT bool wxCheckForInterrupt(wxWindow *wnd);
336
337// Consume all events until no more left
338WXDLLEXPORT void wxFlushEvents();
339
cd6ce4a9
VZ
340// a class which disables all windows (except, may be, thegiven one) in its
341// ctor and enables them back in its dtor
342class WXDLLEXPORT wxWindowDisabler
343{
344public:
345 wxWindowDisabler(wxWindow *winToSkip = (wxWindow *)NULL);
346 ~wxWindowDisabler();
347
348private:
349 wxWindowList *m_winDisabled;
350};
351
d6b9496a
VZ
352// ----------------------------------------------------------------------------
353// Cursors
354// ----------------------------------------------------------------------------
c801d85f
KB
355
356// Set the cursor to the busy cursor for all windows
357class WXDLLEXPORT wxCursor;
358WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
184b5d99 359WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
e2a6f233 360
c801d85f 361// Restore cursor to normal
afb74891 362WXDLLEXPORT void wxEndBusyCursor();
d6b9496a 363
c801d85f 364// TRUE if we're between the above two calls
afb74891 365WXDLLEXPORT bool wxIsBusy();
c801d85f 366
e2a6f233
JS
367// Convenience class so we can just create a wxBusyCursor object on the stack
368class WXDLLEXPORT wxBusyCursor
369{
afb74891
VZ
370public:
371 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR)
372 { wxBeginBusyCursor(cursor); }
f6bcfd97 373 ~wxBusyCursor()
afb74891 374 { wxEndBusyCursor(); }
e2a6f233 375
f6bcfd97
BP
376 // FIXME: These two methods are currently only implemented (and needed?)
377 // in wxGTK. BusyCursor handling should probably be moved to
378 // common code since the wxGTK and wxMSW implementations are very
379 // similar except for wxMSW using HCURSOR directly instead of
380 // wxCursor.. -- RL.
381 static const wxCursor &GetStoredCursor();
382 static const wxCursor GetBusyCursor();
383};
c801d85f 384
c801d85f 385
d6b9496a 386// ----------------------------------------------------------------------------
c801d85f 387// Reading and writing resources (eg WIN.INI, .Xdefaults)
d6b9496a
VZ
388// ----------------------------------------------------------------------------
389
47d67540 390#if wxUSE_RESOURCES
62448488
JS
391WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = wxEmptyString);
392WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = wxEmptyString);
393WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = wxEmptyString);
394WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = wxEmptyString);
395
9d2f3c71 396WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file = wxEmptyString);
62448488
JS
397WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = wxEmptyString);
398WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = wxEmptyString);
399WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = wxEmptyString);
47d67540 400#endif // wxUSE_RESOURCES
c801d85f 401
c801d85f
KB
402void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
403
404// MSW only: get user-defined resource from the .res file.
405// Returns NULL or newly-allocated memory, so use delete[] to clean up.
2049ba38 406#ifdef __WXMSW__
373658eb
VZ
407 WXDLLEXPORT extern const wxChar* wxUserResourceStr;
408 WXDLLEXPORT wxChar* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
d6b9496a
VZ
409#endif // MSW
410
411// ----------------------------------------------------------------------------
412// Display and colorss (X only)
413// ----------------------------------------------------------------------------
c801d85f 414
d111a89a
VZ
415#ifdef __WXGTK__
416 void *wxGetDisplay();
417#endif
418
c801d85f 419#ifdef __X__
d6b9496a
VZ
420 WXDisplay *wxGetDisplay();
421 bool wxSetDisplay(const wxString& display_name);
422 wxString wxGetDisplayName();
d111a89a 423#endif // X or GTK+
c801d85f
KB
424
425#ifdef __X__
426
338dd992
JJ
427#ifdef __VMS__ // Xlib.h for VMS is not (yet) compatible with C++
428 // The resulting warnings are switched off here
429#pragma message disable nosimpint
430#endif
7266b672 431// #include <X11/Xlib.h>
338dd992
JJ
432#ifdef __VMS__
433#pragma message enable nosimpint
434#endif
c801d85f 435
c801d85f
KB
436#endif //__X__
437
e90c1d2a
VZ
438#endif // wxUSE_GUI
439
f6bcfd97
BP
440// ----------------------------------------------------------------------------
441// Error message functions used by wxWindows (deprecated, use wxLog)
442// ----------------------------------------------------------------------------
443
444// Format a message on the standard error (UNIX) or the debugging
445// stream (Windows)
446WXDLLEXPORT void wxDebugMsg(const wxChar *fmt ...);
447
448// Non-fatal error (continues)
449WXDLLEXPORT_DATA(extern const wxChar*) wxInternalErrorStr;
450WXDLLEXPORT void wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
451
452// Fatal error (exits)
453WXDLLEXPORT_DATA(extern const wxChar*) wxFatalErrorStr;
454WXDLLEXPORT void wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
455
456
c801d85f 457#endif
34138703 458 // _WX_UTILSH__