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