]> git.saurik.com Git - wxWidgets.git/blob - include/wx/utils.h
Dialog unit mods; wxProp tidying
[wxWidgets.git] / include / wx / utils.h
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 #ifdef __GNUG__
16 #pragma interface "utils.h"
17 #endif
18
19 #include "wx/setup.h"
20 #include "wx/object.h"
21 #include "wx/list.h"
22 #include "wx/window.h"
23 #include "wx/filefn.h"
24 #include "wx/process.h"
25
26 #if wxUSE_IOSTREAMH
27 #include <iostream.h>
28 #else
29 #include <iostream>
30 #endif
31
32 #ifdef __X__
33 #ifndef __VMS__
34 /*steve: these two are not known under VMS */
35 #include <dirent.h>
36 #include <unistd.h>
37 #endif
38 #endif
39
40 #include <stdio.h>
41
42 #ifdef __GNUWIN32__
43 #define stricmp strcasecmp
44 #define strnicmp strncasecmp
45 #endif
46
47 // Forward declaration
48 class WXDLLEXPORT wxFrame;
49
50 // Stupid ASCII macros
51 #define wxToUpper(C) (((C) >= 'a' && (C) <= 'z')? (C) - 'a' + 'A': (C))
52 #define wxToLower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
53
54 // Return a string with the current date/time
55 wxString WXDLLEXPORT wxNow(void);
56
57 // Make a copy of this string using 'new'
58 char* WXDLLEXPORT copystring(const char *s);
59
60 // Generate a unique ID
61 long WXDLLEXPORT wxNewId(void);
62 #define NewId wxNewId
63
64 // Ensure subsequent IDs don't clash with this one
65 void WXDLLEXPORT wxRegisterId(long id);
66 #define RegisterId wxRegisterId
67
68 // Return the current ID
69 long WXDLLEXPORT wxGetCurrentId(void);
70
71 // Useful buffer
72 WXDLLEXPORT_DATA(extern char*) wxBuffer;
73
74 WXDLLEXPORT_DATA(extern const char*) wxFloatToStringStr;
75 WXDLLEXPORT_DATA(extern const char*) wxDoubleToStringStr;
76
77 // Various conversions
78 void WXDLLEXPORT StringToFloat(char *s, float *number);
79 char* WXDLLEXPORT FloatToString(float number, const char *fmt = wxFloatToStringStr);
80 void WXDLLEXPORT StringToDouble(char *s, double *number);
81 char* WXDLLEXPORT DoubleToString(double number, const char *fmt = wxDoubleToStringStr);
82 void WXDLLEXPORT StringToInt(char *s, int *number);
83 void WXDLLEXPORT StringToLong(char *s, long *number);
84 char* WXDLLEXPORT IntToString(int number);
85 char* WXDLLEXPORT LongToString(long number);
86
87 // Matches string one within string two regardless of case
88 bool WXDLLEXPORT StringMatch(char *one, char *two, bool subString = TRUE, bool exact = FALSE);
89
90 // A shorter way of using strcmp
91 #define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))
92
93 // Convert 2-digit hex number to decimal
94 int WXDLLEXPORT wxHexToDec(const wxString& buf);
95
96 // Convert decimal integer to 2-character hex string
97 void WXDLLEXPORT wxDecToHex(int dec, char *buf);
98 wxString WXDLLEXPORT wxDecToHex(int dec);
99
100 // Execute another program. Returns 0 if there was an error, a PID otherwise.
101 long WXDLLEXPORT wxExecute(char **argv, bool sync = FALSE,
102 wxProcess *process = (wxProcess *) NULL);
103 long WXDLLEXPORT wxExecute(const wxString& command, bool sync = FALSE,
104 wxProcess *process = (wxProcess *) NULL);
105
106 #define wxSIGTERM 1
107
108 int WXDLLEXPORT wxKill(long pid, int sig=wxSIGTERM);
109
110 // Execute a command in an interactive shell window
111 // If no command then just the shell
112 bool WXDLLEXPORT wxShell(const wxString& command = "");
113
114 // Sleep for nSecs seconds under UNIX, do nothing under Windows
115 void WXDLLEXPORT wxSleep(int nSecs);
116
117 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
118 long WXDLLEXPORT wxGetFreeMemory(void);
119
120 // Consume all events until no more left
121 void WXDLLEXPORT wxFlushEvents(void);
122
123 /*
124 * Network and username functions.
125 *
126 */
127
128 // Get eMail address
129 bool WXDLLEXPORT wxGetEmailAddress(char *buf, int maxSize);
130
131 // Get hostname.
132 bool WXDLLEXPORT wxGetHostName(char *buf, int maxSize);
133
134 // Get user ID e.g. jacs
135 bool WXDLLEXPORT wxGetUserId(char *buf, int maxSize);
136
137 // Get user name e.g. Julian Smart
138 bool WXDLLEXPORT wxGetUserName(char *buf, int maxSize);
139
140 /*
141 * Strip out any menu codes
142 */
143 char* WXDLLEXPORT wxStripMenuCodes(char *in, char *out = (char *) NULL);
144
145 // Find the window/widget with the given title or label.
146 // Pass a parent to begin the search from, or NULL to look through
147 // all windows.
148 wxWindow* WXDLLEXPORT wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
149
150 // Find window by name, and if that fails, by label.
151 wxWindow* WXDLLEXPORT wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
152
153 // Returns menu item id or -1 if none.
154 int WXDLLEXPORT wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
155
156 // A debugging stream buffer.
157 // Under Windows, this writes to the Windows debug output.
158 // Under other platforms, it writes to cerr.
159
160 // ALl this horrible gubbins required for Borland, because the calling
161 // convention needs to be the same as for streambuf.
162 // Thanks to Gerhard.Vogt@embl-heidelberg.de for this solution.
163
164 #if defined(__BORLANDC__) && defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
165 #pragma option -po-
166 #endif
167
168 // Can't export a class derived from a non-export class
169 #if !defined(_WINDLL) && !defined(WXUSINGDLL)
170
171 // #ifdef new
172 // #undef new
173 // #endif
174
175 class WXDLLEXPORT wxDebugStreamBuf: public streambuf
176 {
177 public:
178 wxDebugStreamBuf(void);
179 ~wxDebugStreamBuf(void) {}
180
181 int overflow(int i);
182 inline int underflow(void) { return EOF; }
183 int sync(void);
184 };
185
186 // #if WXDEBUG && wxUSE_GLOBAL_MEMORY_OPERATORS
187 // #define new WXDEBUG_NEW
188 // #endif
189
190 #endif
191
192 #if defined(__BORLANDC__) && defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
193 #pragma option -po.
194 #endif
195
196 /*
197 #if (!defined(__MINMAX_DEFINED) && !defined(max))
198 #define max(a,b) (((a) > (b)) ? (a) : (b))
199 #define min(a,b) (((a) < (b)) ? (a) : (b))
200 #define __MINMAX_DEFINED 1
201 #endif
202 */
203 #define wxMax(a,b) (((a) > (b)) ? (a) : (b))
204 #define wxMin(a,b) (((a) < (b)) ? (a) : (b))
205
206 // Yield to other apps/messages
207 bool WXDLLEXPORT wxYield(void);
208
209 // Format a message on the standard error (UNIX) or the debugging
210 // stream (Windows)
211 void WXDLLEXPORT wxDebugMsg(const char *fmt ...) ;
212
213 // Sound the bell
214 void WXDLLEXPORT wxBell(void) ;
215
216 // Get OS version
217 int WXDLLEXPORT wxGetOsVersion(int *majorVsn= (int *) NULL,int *minorVsn= (int *) NULL) ;
218
219 // Set the cursor to the busy cursor for all windows
220 class WXDLLEXPORT wxCursor;
221 WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
222 void WXDLLEXPORT wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
223
224 // Restore cursor to normal
225 void WXDLLEXPORT wxEndBusyCursor(void);
226
227 // TRUE if we're between the above two calls
228 bool WXDLLEXPORT wxIsBusy(void);
229
230 /* Error message functions used by wxWindows */
231
232 // Non-fatal error (continues)
233 WXDLLEXPORT_DATA(extern const char*) wxInternalErrorStr;
234 void WXDLLEXPORT wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
235
236 // Fatal error (exits)
237 WXDLLEXPORT_DATA(extern const char*) wxFatalErrorStr;
238 void WXDLLEXPORT wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
239
240 // Reading and writing resources (eg WIN.INI, .Xdefaults)
241 #if wxUSE_RESOURCES
242 bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = "");
243 bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = "");
244 bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = "");
245 bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = "");
246
247 bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file = "");
248 bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = "");
249 bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = "");
250 bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = "");
251 #endif // wxUSE_RESOURCES
252
253 // Get current Home dir and copy to dest (returns pstr->c_str())
254 const char* WXDLLEXPORT wxGetHomeDir(wxString *pstr);
255
256 // Get the user's home dir (caller must copy--- volatile)
257 // returns NULL is no HOME dir is known
258 char* WXDLLEXPORT wxGetUserHome(const wxString& user = "");
259
260 // Check whether this window wants to process messages, e.g. Stop button
261 // in long calculations.
262 bool WXDLLEXPORT wxCheckForInterrupt(wxWindow *wnd);
263
264 void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
265
266 // MSW only: get user-defined resource from the .res file.
267 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
268 #ifdef __WXMSW__
269 extern const char* WXDLLEXPORT wxUserResourceStr;
270 char* WXDLLEXPORT wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
271 #endif
272
273 // X only
274 #ifdef __X__
275 WXDisplay *wxGetDisplay();
276 bool wxSetDisplay(const wxString& display_name);
277 wxString wxGetDisplayName();
278 #endif
279
280 #ifdef __X__
281
282 #include <X11/Xlib.h>
283
284 #define wxMAX_RGB 0xff
285 #define wxMAX_SV 1000
286 #define wxSIGN(x) ((x < 0) ? -x : x)
287 #define wxH_WEIGHT 4
288 #define wxS_WEIGHT 1
289 #define wxV_WEIGHT 2
290
291 typedef struct wx_hsv {
292 int h,s,v;
293 } wxHSV;
294
295 #define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
296 #define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
297
298 #define wxMax2(x,y) ((x > y) ? x : y)
299 #define wxMin2(x,y) ((x < y) ? x : y)
300
301 void wxHSVToXColor(wxHSV *hsv,XColor *xcolor);
302 void wxXColorToHSV(wxHSV *hsv,XColor *xcolor);
303 void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor);
304 void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
305
306 #endif //__X__
307
308 #endif
309 // _WX_UTILSH__