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