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