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