]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/utils.h
1. wxWindow::IsTopLevel() added and documented
[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/window.h"
27#include "wx/filefn.h"
28
29#include "wx/ioswrap.h"
30
31#ifdef __X__
32 #include <dirent.h>
33 #include <unistd.h>
34#endif
35
36#include <stdio.h>
37
38// ----------------------------------------------------------------------------
39// Forward declaration
40// ----------------------------------------------------------------------------
41
42class WXDLLEXPORT wxProcess;
43class WXDLLEXPORT wxFrame;
44
45// FIXME should use wxStricmp() instead
46#ifdef __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(void) ;
80
81// Get OS version
82WXDLLEXPORT int wxGetOsVersion(int *majorVsn= (int *) NULL,int *minorVsn= (int *) NULL) ;
83
84// Return a string with the current date/time
85WXDLLEXPORT wxString wxNow();
86
87// Don't synthesize KeyUp events holding down a key and producing
88// KeyDown events with autorepeat. On by default and always on
89// in wxMSW.
90WXDLLEXPORT bool wxSetDetectableAutoRepeat( bool flag );
91
92// ----------------------------------------------------------------------------
93// Window ID management
94// ----------------------------------------------------------------------------
95
96// Generate a unique ID
97WXDLLEXPORT long wxNewId();
98#if !defined(NewId) && defined(WXWIN_COMPATIBILITY)
99 #define NewId wxNewId
100#endif
101
102// Ensure subsequent IDs don't clash with this one
103WXDLLEXPORT void wxRegisterId(long id);
104#if !defined(RegisterId) && defined(WXWIN_COMPATIBILITY)
105 #define RegisterId wxRegisterId
106#endif
107
108// Return the current ID
109WXDLLEXPORT long wxGetCurrentId();
110
111// ----------------------------------------------------------------------------
112// Various conversions
113// ----------------------------------------------------------------------------
114
115WXDLLEXPORT_DATA(extern const wxChar*) wxFloatToStringStr;
116WXDLLEXPORT_DATA(extern const wxChar*) wxDoubleToStringStr;
117
118WXDLLEXPORT void StringToFloat(wxChar *s, float *number);
119WXDLLEXPORT wxChar* FloatToString(float number, const wxChar *fmt = wxFloatToStringStr);
120WXDLLEXPORT void StringToDouble(wxChar *s, double *number);
121WXDLLEXPORT wxChar* DoubleToString(double number, const wxChar *fmt = wxDoubleToStringStr);
122WXDLLEXPORT void StringToInt(wxChar *s, int *number);
123WXDLLEXPORT void StringToLong(wxChar *s, long *number);
124WXDLLEXPORT wxChar* IntToString(int number);
125WXDLLEXPORT wxChar* LongToString(long number);
126
127// Convert 2-digit hex number to decimal
128WXDLLEXPORT int wxHexToDec(const wxString& buf);
129
130// Convert decimal integer to 2-character hex string
131WXDLLEXPORT void wxDecToHex(int dec, wxChar *buf);
132WXDLLEXPORT wxString wxDecToHex(int dec);
133
134// ----------------------------------------------------------------------------
135// Process management
136// ----------------------------------------------------------------------------
137
138// Execute another program. Returns 0 if there was an error, a PID otherwise.
139WXDLLEXPORT long wxExecute(wxChar **argv, bool sync = FALSE,
140 wxProcess *process = (wxProcess *) NULL);
141WXDLLEXPORT long wxExecute(const wxString& command, bool sync = FALSE,
142 wxProcess *process = (wxProcess *) NULL);
143
144enum wxSignal
145{
146 wxSIGNONE = 0, // verify if the process exists under Unix
147 wxSIGHUP,
148 wxSIGINT,
149 wxSIGQUIT,
150 wxSIGILL,
151 wxSIGTRAP,
152 wxSIGABRT,
153 wxSIGIOT = wxSIGABRT, // another name
154 wxSIGEMT,
155 wxSIGFPE,
156 wxSIGKILL,
157 wxSIGBUS,
158 wxSIGSEGV,
159 wxSIGSYS,
160 wxSIGPIPE,
161 wxSIGALRM,
162 wxSIGTERM
163
164 // further signals are different in meaning between different Unix systems
165};
166
167// the argument is ignored under Windows - the process is always killed
168WXDLLEXPORT int wxKill(long pid, wxSignal sig = wxSIGTERM);
169
170// Execute a command in an interactive shell window
171// If no command then just the shell
172WXDLLEXPORT bool wxShell(const wxString& command = wxEmptyString);
173
174// Sleep for nSecs seconds under UNIX, do nothing under Windows
175WXDLLEXPORT void wxSleep(int nSecs);
176
177// Sleep for a given amount of milliseconds
178WXDLLEXPORT void wxUsleep(unsigned long milliseconds);
179
180// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
181WXDLLEXPORT long wxGetFreeMemory();
182
183// ----------------------------------------------------------------------------
184// Network and username functions.
185// ----------------------------------------------------------------------------
186
187// NB: "char *" functions are deprecated, use wxString ones!
188
189// Get eMail address
190WXDLLEXPORT bool wxGetEmailAddress(wxChar *buf, int maxSize);
191WXDLLEXPORT wxString wxGetEmailAddress();
192
193// Get hostname.
194WXDLLEXPORT bool wxGetHostName(wxChar *buf, int maxSize);
195WXDLLEXPORT wxString wxGetHostName();
196
197// Get FQDN
198WXDLLEXPORT wxString wxGetFullHostName();
199
200// Get user ID e.g. jacs (this is known as login name under Unix)
201WXDLLEXPORT bool wxGetUserId(wxChar *buf, int maxSize);
202WXDLLEXPORT wxString wxGetUserId();
203
204// Get user name e.g. Julian Smart
205WXDLLEXPORT bool wxGetUserName(wxChar *buf, int maxSize);
206WXDLLEXPORT wxString wxGetUserName();
207
208// Get current Home dir and copy to dest (returns pstr->c_str())
209WXDLLEXPORT const wxChar* wxGetHomeDir(wxString *pstr);
210
211// Get the user's home dir (caller must copy --- volatile)
212// returns NULL is no HOME dir is known
213#if defined(__UNIX__) && wxUSE_UNICODE
214WXDLLEXPORT const wxMB2WXbuf wxGetUserHome(const wxString& user = wxEmptyString);
215#else
216WXDLLEXPORT wxChar* wxGetUserHome(const wxString& user = wxEmptyString);
217#endif
218
219// ----------------------------------------------------------------------------
220// Strip out any menu codes
221// ----------------------------------------------------------------------------
222
223WXDLLEXPORT wxChar* wxStripMenuCodes(wxChar *in, wxChar *out = (wxChar *) NULL);
224WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str);
225
226// ----------------------------------------------------------------------------
227// Window search
228// ----------------------------------------------------------------------------
229
230// Find the window/widget with the given title or label.
231// Pass a parent to begin the search from, or NULL to look through
232// all windows.
233WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
234
235// Find window by name, and if that fails, by label.
236WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
237
238// Returns menu item id or -1 if none.
239WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
240
241// ----------------------------------------------------------------------------
242// Message/event queue helpers
243// ----------------------------------------------------------------------------
244
245// Yield to other apps/messages
246WXDLLEXPORT bool wxYield();
247
248// Yield to other apps/messages and disable user input
249WXDLLEXPORT bool wxSafeYield(wxWindow *win = NULL);
250
251// Enable or disable input to all top level windows
252WXDLLEXPORT void wxEnableTopLevelWindows(bool enable = TRUE);
253
254// Check whether this window wants to process messages, e.g. Stop button
255// in long calculations.
256WXDLLEXPORT bool wxCheckForInterrupt(wxWindow *wnd);
257
258// Consume all events until no more left
259WXDLLEXPORT void wxFlushEvents();
260
261// ----------------------------------------------------------------------------
262// Cursors
263// ----------------------------------------------------------------------------
264
265// Set the cursor to the busy cursor for all windows
266class WXDLLEXPORT wxCursor;
267WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
268WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
269
270// Restore cursor to normal
271WXDLLEXPORT void wxEndBusyCursor();
272
273// TRUE if we're between the above two calls
274WXDLLEXPORT bool wxIsBusy();
275
276// Convenience class so we can just create a wxBusyCursor object on the stack
277class WXDLLEXPORT wxBusyCursor
278{
279public:
280 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR)
281 { wxBeginBusyCursor(cursor); }
282 ~wxBusyCursor()
283 { wxEndBusyCursor(); }
284};
285
286// ----------------------------------------------------------------------------
287// Error message functions used by wxWindows (deprecated, use wxLog)
288// ----------------------------------------------------------------------------
289
290// Format a message on the standard error (UNIX) or the debugging
291// stream (Windows)
292WXDLLEXPORT void wxDebugMsg(const wxChar *fmt ...) ;
293
294// Non-fatal error (continues)
295WXDLLEXPORT_DATA(extern const wxChar*) wxInternalErrorStr;
296WXDLLEXPORT void wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
297
298// Fatal error (exits)
299WXDLLEXPORT_DATA(extern const wxChar*) wxFatalErrorStr;
300WXDLLEXPORT void wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
301
302// ----------------------------------------------------------------------------
303// Reading and writing resources (eg WIN.INI, .Xdefaults)
304// ----------------------------------------------------------------------------
305
306#if wxUSE_RESOURCES
307WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = wxEmptyString);
308WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = wxEmptyString);
309WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = wxEmptyString);
310WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = wxEmptyString);
311
312WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file = wxEmptyString);
313WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = wxEmptyString);
314WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = wxEmptyString);
315WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = wxEmptyString);
316#endif // wxUSE_RESOURCES
317
318void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
319
320// MSW only: get user-defined resource from the .res file.
321// Returns NULL or newly-allocated memory, so use delete[] to clean up.
322#ifdef __WXMSW__
323WXDLLEXPORT extern const wxChar* wxUserResourceStr;
324WXDLLEXPORT wxChar* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
325
326// Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
327// input/output
328WXDLLEXPORT void wxRedirectIOToConsole();
329
330#endif // MSW
331
332// ----------------------------------------------------------------------------
333// Display and colorss (X only)
334// ----------------------------------------------------------------------------
335
336#ifdef __X__
337 WXDisplay *wxGetDisplay();
338 bool wxSetDisplay(const wxString& display_name);
339 wxString wxGetDisplayName();
340#endif
341
342#ifdef __X__
343
344#include <X11/Xlib.h>
345
346#define wxMAX_RGB 0xff
347#define wxMAX_SV 1000
348#define wxSIGN(x) ((x < 0) ? -x : x)
349#define wxH_WEIGHT 4
350#define wxS_WEIGHT 1
351#define wxV_WEIGHT 2
352
353typedef struct wx_hsv {
354 int h,s,v;
355 } wxHSV;
356
357#define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
358#define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
359
360void wxHSVToXColor(wxHSV *hsv,XColor *xcolor);
361void wxXColorToHSV(wxHSV *hsv,XColor *xcolor);
362void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor);
363void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
364
365#endif //__X__
366
367#endif
368 // _WX_UTILSH__