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