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