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