]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/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 licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_UTILS_H_ | |
13 | #define _WX_UTILS_H_ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | #include "wx/object.h" | |
20 | #include "wx/list.h" | |
21 | #include "wx/filefn.h" | |
22 | #include "wx/hashmap.h" | |
23 | #include "wx/versioninfo.h" | |
24 | #include "wx/meta/implicitconversion.h" | |
25 | ||
26 | #if wxUSE_GUI | |
27 | #include "wx/gdicmn.h" | |
28 | #include "wx/mousestate.h" | |
29 | #endif | |
30 | ||
31 | class WXDLLIMPEXP_FWD_BASE wxArrayString; | |
32 | class WXDLLIMPEXP_FWD_BASE wxArrayInt; | |
33 | ||
34 | // need this for wxGetDiskSpace() as we can't, unfortunately, forward declare | |
35 | // wxLongLong | |
36 | #include "wx/longlong.h" | |
37 | ||
38 | // needed for wxOperatingSystemId, wxLinuxDistributionInfo | |
39 | #include "wx/platinfo.h" | |
40 | ||
41 | #ifdef __WATCOMC__ | |
42 | #include <direct.h> | |
43 | #elif defined(__X__) | |
44 | #include <dirent.h> | |
45 | #include <unistd.h> | |
46 | #endif | |
47 | ||
48 | #include <stdio.h> | |
49 | ||
50 | // ---------------------------------------------------------------------------- | |
51 | // Forward declaration | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | class WXDLLIMPEXP_FWD_BASE wxProcess; | |
55 | class WXDLLIMPEXP_FWD_CORE wxFrame; | |
56 | class WXDLLIMPEXP_FWD_CORE wxWindow; | |
57 | class wxWindowList; | |
58 | class WXDLLIMPEXP_FWD_CORE wxEventLoop; | |
59 | ||
60 | // ---------------------------------------------------------------------------- | |
61 | // Arithmetic functions | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
64 | template<typename T1, typename T2> | |
65 | inline typename wxImplicitConversionType<T1,T2>::value | |
66 | wxMax(T1 a, T2 b) | |
67 | { | |
68 | typedef typename wxImplicitConversionType<T1,T2>::value ResultType; | |
69 | ||
70 | // Cast both operands to the same type before comparing them to avoid | |
71 | // warnings about signed/unsigned comparisons from some compilers: | |
72 | return static_cast<ResultType>(a) > static_cast<ResultType>(b) ? a : b; | |
73 | } | |
74 | ||
75 | template<typename T1, typename T2> | |
76 | inline typename wxImplicitConversionType<T1,T2>::value | |
77 | wxMin(T1 a, T2 b) | |
78 | { | |
79 | typedef typename wxImplicitConversionType<T1,T2>::value ResultType; | |
80 | ||
81 | return static_cast<ResultType>(a) < static_cast<ResultType>(b) ? a : b; | |
82 | } | |
83 | ||
84 | template<typename T1, typename T2, typename T3> | |
85 | inline typename wxImplicitConversionType3<T1,T2,T3>::value | |
86 | wxClip(T1 a, T2 b, T3 c) | |
87 | { | |
88 | typedef typename wxImplicitConversionType3<T1,T2,T3>::value ResultType; | |
89 | ||
90 | if ( static_cast<ResultType>(a) < static_cast<ResultType>(b) ) | |
91 | return b; | |
92 | ||
93 | if ( static_cast<ResultType>(a) > static_cast<ResultType>(c) ) | |
94 | return c; | |
95 | ||
96 | return a; | |
97 | } | |
98 | ||
99 | // ---------------------------------------------------------------------------- | |
100 | // wxMemorySize | |
101 | // ---------------------------------------------------------------------------- | |
102 | ||
103 | // wxGetFreeMemory can return huge amount of memory on 32-bit platforms as well | |
104 | // so to always use long long for its result type on all platforms which | |
105 | // support it | |
106 | #if wxUSE_LONGLONG | |
107 | typedef wxLongLong wxMemorySize; | |
108 | #else | |
109 | typedef long wxMemorySize; | |
110 | #endif | |
111 | ||
112 | // ---------------------------------------------------------------------------- | |
113 | // String functions (deprecated, use wxString) | |
114 | // ---------------------------------------------------------------------------- | |
115 | ||
116 | #if WXWIN_COMPATIBILITY_2_8 | |
117 | // A shorter way of using strcmp | |
118 | wxDEPRECATED_INLINE(inline bool wxStringEq(const char *s1, const char *s2), | |
119 | return wxCRT_StrcmpA(s1, s2) == 0; ) | |
120 | ||
121 | #if wxUSE_UNICODE | |
122 | wxDEPRECATED_INLINE(inline bool wxStringEq(const wchar_t *s1, const wchar_t *s2), | |
123 | return wxCRT_StrcmpW(s1, s2) == 0; ) | |
124 | #endif // wxUSE_UNICODE | |
125 | ||
126 | #endif // WXWIN_COMPATIBILITY_2_8 | |
127 | ||
128 | // ---------------------------------------------------------------------------- | |
129 | // Miscellaneous functions | |
130 | // ---------------------------------------------------------------------------- | |
131 | ||
132 | // Sound the bell | |
133 | WXDLLIMPEXP_CORE void wxBell(); | |
134 | ||
135 | #if wxUSE_MSGDLG | |
136 | // Show wxWidgets information | |
137 | WXDLLIMPEXP_CORE void wxInfoMessageBox(wxWindow* parent); | |
138 | #endif // wxUSE_MSGDLG | |
139 | ||
140 | WXDLLIMPEXP_CORE wxVersionInfo wxGetLibraryVersionInfo(); | |
141 | ||
142 | // Get OS description as a user-readable string | |
143 | WXDLLIMPEXP_BASE wxString wxGetOsDescription(); | |
144 | ||
145 | // Get OS version | |
146 | WXDLLIMPEXP_BASE wxOperatingSystemId wxGetOsVersion(int *majorVsn = NULL, | |
147 | int *minorVsn = NULL); | |
148 | ||
149 | // Get platform endianness | |
150 | WXDLLIMPEXP_BASE bool wxIsPlatformLittleEndian(); | |
151 | ||
152 | // Get platform architecture | |
153 | WXDLLIMPEXP_BASE bool wxIsPlatform64Bit(); | |
154 | ||
155 | #ifdef __LINUX__ | |
156 | // Get linux-distro informations | |
157 | WXDLLIMPEXP_BASE wxLinuxDistributionInfo wxGetLinuxDistributionInfo(); | |
158 | #endif | |
159 | ||
160 | // Return a string with the current date/time | |
161 | WXDLLIMPEXP_BASE wxString wxNow(); | |
162 | ||
163 | // Return path where wxWidgets is installed (mostly useful in Unices) | |
164 | WXDLLIMPEXP_BASE const wxChar *wxGetInstallPrefix(); | |
165 | // Return path to wxWin data (/usr/share/wx/%{version}) (Unices) | |
166 | WXDLLIMPEXP_BASE wxString wxGetDataDir(); | |
167 | ||
168 | #if wxUSE_GUI | |
169 | ||
170 | // Get the state of a key (true if pressed, false if not) | |
171 | // This is generally most useful getting the state of | |
172 | // the modifier or toggle keys. | |
173 | WXDLLIMPEXP_CORE bool wxGetKeyState(wxKeyCode key); | |
174 | ||
175 | // Don't synthesize KeyUp events holding down a key and producing | |
176 | // KeyDown events with autorepeat. On by default and always on | |
177 | // in wxMSW. | |
178 | WXDLLIMPEXP_CORE bool wxSetDetectableAutoRepeat( bool flag ); | |
179 | ||
180 | // Returns the current state of the mouse position, buttons and modifers | |
181 | WXDLLIMPEXP_CORE wxMouseState wxGetMouseState(); | |
182 | ||
183 | #endif // wxUSE_GUI | |
184 | ||
185 | // ---------------------------------------------------------------------------- | |
186 | // wxPlatform | |
187 | // ---------------------------------------------------------------------------- | |
188 | ||
189 | /* | |
190 | * Class to make it easier to specify platform-dependent values | |
191 | * | |
192 | * Examples: | |
193 | * long val = wxPlatform::If(wxMac, 1).ElseIf(wxGTK, 2).ElseIf(stPDA, 5).Else(3); | |
194 | * wxString strVal = wxPlatform::If(wxMac, wxT("Mac")).ElseIf(wxMSW, wxT("MSW")).Else(wxT("Other")); | |
195 | * | |
196 | * A custom platform symbol: | |
197 | * | |
198 | * #define stPDA 100 | |
199 | * #ifdef __WXWINCE__ | |
200 | * wxPlatform::AddPlatform(stPDA); | |
201 | * #endif | |
202 | * | |
203 | * long windowStyle = wxCAPTION | (long) wxPlatform::IfNot(stPDA, wxRESIZE_BORDER); | |
204 | * | |
205 | */ | |
206 | ||
207 | class WXDLLIMPEXP_BASE wxPlatform | |
208 | { | |
209 | public: | |
210 | wxPlatform() { Init(); } | |
211 | wxPlatform(const wxPlatform& platform) { Copy(platform); } | |
212 | void operator = (const wxPlatform& platform) { if (&platform != this) Copy(platform); } | |
213 | void Copy(const wxPlatform& platform); | |
214 | ||
215 | // Specify an optional default value | |
216 | wxPlatform(int defValue) { Init(); m_longValue = (long)defValue; } | |
217 | wxPlatform(long defValue) { Init(); m_longValue = defValue; } | |
218 | wxPlatform(const wxString& defValue) { Init(); m_stringValue = defValue; } | |
219 | wxPlatform(double defValue) { Init(); m_doubleValue = defValue; } | |
220 | ||
221 | static wxPlatform If(int platform, long value); | |
222 | static wxPlatform IfNot(int platform, long value); | |
223 | wxPlatform& ElseIf(int platform, long value); | |
224 | wxPlatform& ElseIfNot(int platform, long value); | |
225 | wxPlatform& Else(long value); | |
226 | ||
227 | static wxPlatform If(int platform, int value) { return If(platform, (long)value); } | |
228 | static wxPlatform IfNot(int platform, int value) { return IfNot(platform, (long)value); } | |
229 | wxPlatform& ElseIf(int platform, int value) { return ElseIf(platform, (long) value); } | |
230 | wxPlatform& ElseIfNot(int platform, int value) { return ElseIfNot(platform, (long) value); } | |
231 | wxPlatform& Else(int value) { return Else((long) value); } | |
232 | ||
233 | static wxPlatform If(int platform, double value); | |
234 | static wxPlatform IfNot(int platform, double value); | |
235 | wxPlatform& ElseIf(int platform, double value); | |
236 | wxPlatform& ElseIfNot(int platform, double value); | |
237 | wxPlatform& Else(double value); | |
238 | ||
239 | static wxPlatform If(int platform, const wxString& value); | |
240 | static wxPlatform IfNot(int platform, const wxString& value); | |
241 | wxPlatform& ElseIf(int platform, const wxString& value); | |
242 | wxPlatform& ElseIfNot(int platform, const wxString& value); | |
243 | wxPlatform& Else(const wxString& value); | |
244 | ||
245 | long GetInteger() const { return m_longValue; } | |
246 | const wxString& GetString() const { return m_stringValue; } | |
247 | double GetDouble() const { return m_doubleValue; } | |
248 | ||
249 | operator int() const { return (int) GetInteger(); } | |
250 | operator long() const { return GetInteger(); } | |
251 | operator double() const { return GetDouble(); } | |
252 | operator const wxString&() const { return GetString(); } | |
253 | ||
254 | static void AddPlatform(int platform); | |
255 | static bool Is(int platform); | |
256 | static void ClearPlatforms(); | |
257 | ||
258 | private: | |
259 | ||
260 | void Init() { m_longValue = 0; m_doubleValue = 0.0; } | |
261 | ||
262 | long m_longValue; | |
263 | double m_doubleValue; | |
264 | wxString m_stringValue; | |
265 | static wxArrayInt* sm_customPlatforms; | |
266 | }; | |
267 | ||
268 | /// Function for testing current platform | |
269 | inline bool wxPlatformIs(int platform) { return wxPlatform::Is(platform); } | |
270 | ||
271 | // ---------------------------------------------------------------------------- | |
272 | // Window ID management | |
273 | // ---------------------------------------------------------------------------- | |
274 | ||
275 | // Ensure subsequent IDs don't clash with this one | |
276 | WXDLLIMPEXP_BASE void wxRegisterId(int id); | |
277 | ||
278 | // Return the current ID | |
279 | WXDLLIMPEXP_BASE int wxGetCurrentId(); | |
280 | ||
281 | // Generate a unique ID | |
282 | WXDLLIMPEXP_BASE int wxNewId(); | |
283 | ||
284 | // ---------------------------------------------------------------------------- | |
285 | // Various conversions | |
286 | // ---------------------------------------------------------------------------- | |
287 | ||
288 | // Convert 2-digit hex number to decimal | |
289 | WXDLLIMPEXP_BASE int wxHexToDec(const wxString& buf); | |
290 | ||
291 | // Convert 2-digit hex number to decimal | |
292 | inline int wxHexToDec(const char* buf) | |
293 | { | |
294 | int firstDigit, secondDigit; | |
295 | ||
296 | if (buf[0] >= 'A') | |
297 | firstDigit = buf[0] - 'A' + 10; | |
298 | else | |
299 | firstDigit = buf[0] - '0'; | |
300 | ||
301 | if (buf[1] >= 'A') | |
302 | secondDigit = buf[1] - 'A' + 10; | |
303 | else | |
304 | secondDigit = buf[1] - '0'; | |
305 | ||
306 | return (firstDigit & 0xF) * 16 + (secondDigit & 0xF ); | |
307 | } | |
308 | ||
309 | ||
310 | // Convert decimal integer to 2-character hex string | |
311 | WXDLLIMPEXP_BASE void wxDecToHex(int dec, wxChar *buf); | |
312 | WXDLLIMPEXP_BASE void wxDecToHex(int dec, char* ch1, char* ch2); | |
313 | WXDLLIMPEXP_BASE wxString wxDecToHex(int dec); | |
314 | ||
315 | // ---------------------------------------------------------------------------- | |
316 | // Process management | |
317 | // ---------------------------------------------------------------------------- | |
318 | ||
319 | // NB: for backwards compatibility reasons the values of wxEXEC_[A]SYNC *must* | |
320 | // be 0 and 1, don't change! | |
321 | ||
322 | enum | |
323 | { | |
324 | // execute the process asynchronously | |
325 | wxEXEC_ASYNC = 0, | |
326 | ||
327 | // execute it synchronously, i.e. wait until it finishes | |
328 | wxEXEC_SYNC = 1, | |
329 | ||
330 | // under Windows, don't hide the child even if it's IO is redirected (this | |
331 | // is done by default) | |
332 | wxEXEC_SHOW_CONSOLE = 2, | |
333 | ||
334 | // deprecated synonym for wxEXEC_SHOW_CONSOLE, use the new name as it's | |
335 | // more clear | |
336 | wxEXEC_NOHIDE = wxEXEC_SHOW_CONSOLE, | |
337 | ||
338 | // under Unix, if the process is the group leader then passing wxKILL_CHILDREN to wxKill | |
339 | // kills all children as well as pid | |
340 | // under Windows (NT family only), sets the CREATE_NEW_PROCESS_GROUP flag, | |
341 | // which allows to target Ctrl-Break signal to the spawned process. | |
342 | // applies to console processes only. | |
343 | wxEXEC_MAKE_GROUP_LEADER = 4, | |
344 | ||
345 | // by default synchronous execution disables all program windows to avoid | |
346 | // that the user interacts with the program while the child process is | |
347 | // running, you can use this flag to prevent this from happening | |
348 | wxEXEC_NODISABLE = 8, | |
349 | ||
350 | // by default, the event loop is run while waiting for synchronous execution | |
351 | // to complete and this flag can be used to simply block the main process | |
352 | // until the child process finishes | |
353 | wxEXEC_NOEVENTS = 16, | |
354 | ||
355 | // under Windows, hide the console of the child process if it has one, even | |
356 | // if its IO is not redirected | |
357 | wxEXEC_HIDE_CONSOLE = 32, | |
358 | ||
359 | // convenient synonym for flags given system()-like behaviour | |
360 | wxEXEC_BLOCK = wxEXEC_SYNC | wxEXEC_NOEVENTS | |
361 | }; | |
362 | ||
363 | // Map storing environment variables. | |
364 | typedef wxStringToStringHashMap wxEnvVariableHashMap; | |
365 | ||
366 | // Used to pass additional parameters for child process to wxExecute(). Could | |
367 | // be extended with other fields later. | |
368 | struct wxExecuteEnv | |
369 | { | |
370 | wxString cwd; // If empty, CWD is not changed. | |
371 | wxEnvVariableHashMap env; // If empty, environment is unchanged. | |
372 | }; | |
373 | ||
374 | // Execute another program. | |
375 | // | |
376 | // If flags contain wxEXEC_SYNC, return -1 on failure and the exit code of the | |
377 | // process if everything was ok. Otherwise (i.e. if wxEXEC_ASYNC), return 0 on | |
378 | // failure and the PID of the launched process if ok. | |
379 | WXDLLIMPEXP_BASE long wxExecute(const wxString& command, | |
380 | int flags = wxEXEC_ASYNC, | |
381 | wxProcess *process = NULL, | |
382 | const wxExecuteEnv *env = NULL); | |
383 | WXDLLIMPEXP_BASE long wxExecute(char **argv, | |
384 | int flags = wxEXEC_ASYNC, | |
385 | wxProcess *process = NULL, | |
386 | const wxExecuteEnv *env = NULL); | |
387 | #if wxUSE_UNICODE | |
388 | WXDLLIMPEXP_BASE long wxExecute(wchar_t **argv, | |
389 | int flags = wxEXEC_ASYNC, | |
390 | wxProcess *process = NULL, | |
391 | const wxExecuteEnv *env = NULL); | |
392 | #endif // wxUSE_UNICODE | |
393 | ||
394 | // execute the command capturing its output into an array line by line, this is | |
395 | // always synchronous | |
396 | WXDLLIMPEXP_BASE long wxExecute(const wxString& command, | |
397 | wxArrayString& output, | |
398 | int flags = 0, | |
399 | const wxExecuteEnv *env = NULL); | |
400 | ||
401 | // also capture stderr (also synchronous) | |
402 | WXDLLIMPEXP_BASE long wxExecute(const wxString& command, | |
403 | wxArrayString& output, | |
404 | wxArrayString& error, | |
405 | int flags = 0, | |
406 | const wxExecuteEnv *env = NULL); | |
407 | ||
408 | #if defined(__WINDOWS__) && wxUSE_IPC | |
409 | // ask a DDE server to execute the DDE request with given parameters | |
410 | WXDLLIMPEXP_BASE bool wxExecuteDDE(const wxString& ddeServer, | |
411 | const wxString& ddeTopic, | |
412 | const wxString& ddeCommand); | |
413 | #endif // __WINDOWS__ && wxUSE_IPC | |
414 | ||
415 | enum wxSignal | |
416 | { | |
417 | wxSIGNONE = 0, // verify if the process exists under Unix | |
418 | wxSIGHUP, | |
419 | wxSIGINT, | |
420 | wxSIGQUIT, | |
421 | wxSIGILL, | |
422 | wxSIGTRAP, | |
423 | wxSIGABRT, | |
424 | wxSIGIOT = wxSIGABRT, // another name | |
425 | wxSIGEMT, | |
426 | wxSIGFPE, | |
427 | wxSIGKILL, | |
428 | wxSIGBUS, | |
429 | wxSIGSEGV, | |
430 | wxSIGSYS, | |
431 | wxSIGPIPE, | |
432 | wxSIGALRM, | |
433 | wxSIGTERM | |
434 | ||
435 | // further signals are different in meaning between different Unix systems | |
436 | }; | |
437 | ||
438 | enum wxKillError | |
439 | { | |
440 | wxKILL_OK, // no error | |
441 | wxKILL_BAD_SIGNAL, // no such signal | |
442 | wxKILL_ACCESS_DENIED, // permission denied | |
443 | wxKILL_NO_PROCESS, // no such process | |
444 | wxKILL_ERROR // another, unspecified error | |
445 | }; | |
446 | ||
447 | enum wxKillFlags | |
448 | { | |
449 | wxKILL_NOCHILDREN = 0, // don't kill children | |
450 | wxKILL_CHILDREN = 1 // kill children | |
451 | }; | |
452 | ||
453 | enum wxShutdownFlags | |
454 | { | |
455 | wxSHUTDOWN_FORCE = 1,// can be combined with other flags (MSW-only) | |
456 | wxSHUTDOWN_POWEROFF = 2,// power off the computer | |
457 | wxSHUTDOWN_REBOOT = 4,// shutdown and reboot | |
458 | wxSHUTDOWN_LOGOFF = 8 // close session (currently MSW-only) | |
459 | }; | |
460 | ||
461 | // Shutdown or reboot the PC | |
462 | WXDLLIMPEXP_BASE bool wxShutdown(int flags = wxSHUTDOWN_POWEROFF); | |
463 | ||
464 | // send the given signal to the process (only NONE and KILL are supported under | |
465 | // Windows, all others mean TERM), return 0 if ok and -1 on error | |
466 | // | |
467 | // return detailed error in rc if not NULL | |
468 | WXDLLIMPEXP_BASE int wxKill(long pid, | |
469 | wxSignal sig = wxSIGTERM, | |
470 | wxKillError *rc = NULL, | |
471 | int flags = wxKILL_NOCHILDREN); | |
472 | ||
473 | // Execute a command in an interactive shell window (always synchronously) | |
474 | // If no command then just the shell | |
475 | WXDLLIMPEXP_BASE bool wxShell(const wxString& command = wxEmptyString); | |
476 | ||
477 | // As wxShell(), but must give a (non interactive) command and its output will | |
478 | // be returned in output array | |
479 | WXDLLIMPEXP_BASE bool wxShell(const wxString& command, wxArrayString& output); | |
480 | ||
481 | // Sleep for nSecs seconds | |
482 | WXDLLIMPEXP_BASE void wxSleep(int nSecs); | |
483 | ||
484 | // Sleep for a given amount of milliseconds | |
485 | WXDLLIMPEXP_BASE void wxMilliSleep(unsigned long milliseconds); | |
486 | ||
487 | // Sleep for a given amount of microseconds | |
488 | WXDLLIMPEXP_BASE void wxMicroSleep(unsigned long microseconds); | |
489 | ||
490 | #if WXWIN_COMPATIBILITY_2_8 | |
491 | // Sleep for a given amount of milliseconds (old, bad name), use wxMilliSleep | |
492 | wxDEPRECATED( WXDLLIMPEXP_BASE void wxUsleep(unsigned long milliseconds) ); | |
493 | #endif | |
494 | ||
495 | // Get the process id of the current process | |
496 | WXDLLIMPEXP_BASE unsigned long wxGetProcessId(); | |
497 | ||
498 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) | |
499 | WXDLLIMPEXP_BASE wxMemorySize wxGetFreeMemory(); | |
500 | ||
501 | #if wxUSE_ON_FATAL_EXCEPTION | |
502 | ||
503 | // should wxApp::OnFatalException() be called? | |
504 | WXDLLIMPEXP_BASE bool wxHandleFatalExceptions(bool doit = true); | |
505 | ||
506 | #endif // wxUSE_ON_FATAL_EXCEPTION | |
507 | ||
508 | // ---------------------------------------------------------------------------- | |
509 | // Environment variables | |
510 | // ---------------------------------------------------------------------------- | |
511 | ||
512 | // returns true if variable exists (value may be NULL if you just want to check | |
513 | // for this) | |
514 | WXDLLIMPEXP_BASE bool wxGetEnv(const wxString& var, wxString *value); | |
515 | ||
516 | // set the env var name to the given value, return true on success | |
517 | WXDLLIMPEXP_BASE bool wxSetEnv(const wxString& var, const wxString& value); | |
518 | ||
519 | // remove the env var from environment | |
520 | WXDLLIMPEXP_BASE bool wxUnsetEnv(const wxString& var); | |
521 | ||
522 | #if WXWIN_COMPATIBILITY_2_8 | |
523 | inline bool wxSetEnv(const wxString& var, const char *value) | |
524 | { return wxSetEnv(var, wxString(value)); } | |
525 | inline bool wxSetEnv(const wxString& var, const wchar_t *value) | |
526 | { return wxSetEnv(var, wxString(value)); } | |
527 | template<typename T> | |
528 | inline bool wxSetEnv(const wxString& var, const wxScopedCharTypeBuffer<T>& value) | |
529 | { return wxSetEnv(var, wxString(value)); } | |
530 | inline bool wxSetEnv(const wxString& var, const wxCStrData& value) | |
531 | { return wxSetEnv(var, wxString(value)); } | |
532 | ||
533 | // this one is for passing NULL directly - don't use it, use wxUnsetEnv instead | |
534 | wxDEPRECATED( inline bool wxSetEnv(const wxString& var, int value) ); | |
535 | inline bool wxSetEnv(const wxString& var, int value) | |
536 | { | |
537 | wxASSERT_MSG( value == 0, "using non-NULL integer as string?" ); | |
538 | ||
539 | wxUnusedVar(value); // fix unused parameter warning in release build | |
540 | ||
541 | return wxUnsetEnv(var); | |
542 | } | |
543 | #endif // WXWIN_COMPATIBILITY_2_8 | |
544 | ||
545 | // Retrieve the complete environment by filling specified map. | |
546 | // Returns true on success or false if an error occurred. | |
547 | WXDLLIMPEXP_BASE bool wxGetEnvMap(wxEnvVariableHashMap *map); | |
548 | ||
549 | // ---------------------------------------------------------------------------- | |
550 | // Network and username functions. | |
551 | // ---------------------------------------------------------------------------- | |
552 | ||
553 | // NB: "char *" functions are deprecated, use wxString ones! | |
554 | ||
555 | // Get eMail address | |
556 | WXDLLIMPEXP_BASE bool wxGetEmailAddress(wxChar *buf, int maxSize); | |
557 | WXDLLIMPEXP_BASE wxString wxGetEmailAddress(); | |
558 | ||
559 | // Get hostname. | |
560 | WXDLLIMPEXP_BASE bool wxGetHostName(wxChar *buf, int maxSize); | |
561 | WXDLLIMPEXP_BASE wxString wxGetHostName(); | |
562 | ||
563 | // Get FQDN | |
564 | WXDLLIMPEXP_BASE wxString wxGetFullHostName(); | |
565 | WXDLLIMPEXP_BASE bool wxGetFullHostName(wxChar *buf, int maxSize); | |
566 | ||
567 | // Get user ID e.g. jacs (this is known as login name under Unix) | |
568 | WXDLLIMPEXP_BASE bool wxGetUserId(wxChar *buf, int maxSize); | |
569 | WXDLLIMPEXP_BASE wxString wxGetUserId(); | |
570 | ||
571 | // Get user name e.g. Julian Smart | |
572 | WXDLLIMPEXP_BASE bool wxGetUserName(wxChar *buf, int maxSize); | |
573 | WXDLLIMPEXP_BASE wxString wxGetUserName(); | |
574 | ||
575 | // Get current Home dir and copy to dest (returns pstr->c_str()) | |
576 | WXDLLIMPEXP_BASE wxString wxGetHomeDir(); | |
577 | WXDLLIMPEXP_BASE const wxChar* wxGetHomeDir(wxString *pstr); | |
578 | ||
579 | // Get the user's (by default use the current user name) home dir, | |
580 | // return empty string on error | |
581 | WXDLLIMPEXP_BASE wxString wxGetUserHome(const wxString& user = wxEmptyString); | |
582 | ||
583 | ||
584 | #if wxUSE_LONGLONG | |
585 | typedef wxLongLong wxDiskspaceSize_t; | |
586 | #else | |
587 | typedef long wxDiskspaceSize_t; | |
588 | #endif | |
589 | ||
590 | // get number of total/free bytes on the disk where path belongs | |
591 | WXDLLIMPEXP_BASE bool wxGetDiskSpace(const wxString& path, | |
592 | wxDiskspaceSize_t *pTotal = NULL, | |
593 | wxDiskspaceSize_t *pFree = NULL); | |
594 | ||
595 | ||
596 | ||
597 | typedef int (*wxSortCallback)(const void* pItem1, | |
598 | const void* pItem2, | |
599 | const void* user_data); | |
600 | ||
601 | ||
602 | WXDLLIMPEXP_BASE void wxQsort(void* pbase, size_t total_elems, | |
603 | size_t size, wxSortCallback cmp, | |
604 | const void* user_data); | |
605 | ||
606 | ||
607 | #if wxUSE_GUI // GUI only things from now on | |
608 | ||
609 | // ---------------------------------------------------------------------------- | |
610 | // Launch default browser | |
611 | // ---------------------------------------------------------------------------- | |
612 | ||
613 | // flags for wxLaunchDefaultBrowser | |
614 | enum | |
615 | { | |
616 | wxBROWSER_NEW_WINDOW = 0x01, | |
617 | wxBROWSER_NOBUSYCURSOR = 0x02 | |
618 | }; | |
619 | ||
620 | // Launch url in the user's default internet browser | |
621 | WXDLLIMPEXP_CORE bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0); | |
622 | ||
623 | // Launch document in the user's default application | |
624 | WXDLLIMPEXP_CORE bool wxLaunchDefaultApplication(const wxString& path, int flags = 0); | |
625 | ||
626 | // ---------------------------------------------------------------------------- | |
627 | // Menu accelerators related things | |
628 | // ---------------------------------------------------------------------------- | |
629 | ||
630 | // flags for wxStripMenuCodes | |
631 | enum | |
632 | { | |
633 | // strip '&' characters | |
634 | wxStrip_Mnemonics = 1, | |
635 | ||
636 | // strip everything after '\t' | |
637 | wxStrip_Accel = 2, | |
638 | ||
639 | // strip everything (this is the default) | |
640 | wxStrip_All = wxStrip_Mnemonics | wxStrip_Accel | |
641 | }; | |
642 | ||
643 | // strip mnemonics and/or accelerators from the label | |
644 | WXDLLIMPEXP_CORE wxString | |
645 | wxStripMenuCodes(const wxString& str, int flags = wxStrip_All); | |
646 | ||
647 | #if WXWIN_COMPATIBILITY_2_6 | |
648 | // obsolete and deprecated version, do not use, use the above overload instead | |
649 | wxDEPRECATED( | |
650 | WXDLLIMPEXP_CORE wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = NULL) | |
651 | ); | |
652 | ||
653 | #if wxUSE_ACCEL | |
654 | class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry; | |
655 | ||
656 | // use wxAcceleratorEntry::Create() or FromString() methods instead | |
657 | wxDEPRECATED( | |
658 | WXDLLIMPEXP_CORE wxAcceleratorEntry *wxGetAccelFromString(const wxString& label) | |
659 | ); | |
660 | #endif // wxUSE_ACCEL | |
661 | ||
662 | #endif // WXWIN_COMPATIBILITY_2_6 | |
663 | ||
664 | // ---------------------------------------------------------------------------- | |
665 | // Window search | |
666 | // ---------------------------------------------------------------------------- | |
667 | ||
668 | // Returns menu item id or wxNOT_FOUND if none. | |
669 | WXDLLIMPEXP_CORE int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString); | |
670 | ||
671 | // Find the wxWindow at the given point. wxGenericFindWindowAtPoint | |
672 | // is always present but may be less reliable than a native version. | |
673 | WXDLLIMPEXP_CORE wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt); | |
674 | WXDLLIMPEXP_CORE wxWindow* wxFindWindowAtPoint(const wxPoint& pt); | |
675 | ||
676 | // NB: this function is obsolete, use wxWindow::FindWindowByLabel() instead | |
677 | // | |
678 | // Find the window/widget with the given title or label. | |
679 | // Pass a parent to begin the search from, or NULL to look through | |
680 | // all windows. | |
681 | WXDLLIMPEXP_CORE wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = NULL); | |
682 | ||
683 | // NB: this function is obsolete, use wxWindow::FindWindowByName() instead | |
684 | // | |
685 | // Find window by name, and if that fails, by label. | |
686 | WXDLLIMPEXP_CORE wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = NULL); | |
687 | ||
688 | // ---------------------------------------------------------------------------- | |
689 | // Message/event queue helpers | |
690 | // ---------------------------------------------------------------------------- | |
691 | ||
692 | // Yield to other apps/messages and disable user input | |
693 | WXDLLIMPEXP_CORE bool wxSafeYield(wxWindow *win = NULL, bool onlyIfNeeded = false); | |
694 | ||
695 | // Enable or disable input to all top level windows | |
696 | WXDLLIMPEXP_CORE void wxEnableTopLevelWindows(bool enable = true); | |
697 | ||
698 | // Check whether this window wants to process messages, e.g. Stop button | |
699 | // in long calculations. | |
700 | WXDLLIMPEXP_CORE bool wxCheckForInterrupt(wxWindow *wnd); | |
701 | ||
702 | // Consume all events until no more left | |
703 | WXDLLIMPEXP_CORE void wxFlushEvents(); | |
704 | ||
705 | // a class which disables all windows (except, may be, the given one) in its | |
706 | // ctor and enables them back in its dtor | |
707 | class WXDLLIMPEXP_CORE wxWindowDisabler | |
708 | { | |
709 | public: | |
710 | // this ctor conditionally disables all windows: if the argument is false, | |
711 | // it doesn't do anything | |
712 | wxWindowDisabler(bool disable = true); | |
713 | ||
714 | // ctor disables all windows except winToSkip | |
715 | wxWindowDisabler(wxWindow *winToSkip); | |
716 | ||
717 | // dtor enables back all windows disabled by the ctor | |
718 | ~wxWindowDisabler(); | |
719 | ||
720 | private: | |
721 | // disable all windows except the given one (used by both ctors) | |
722 | void DoDisable(wxWindow *winToSkip = NULL); | |
723 | ||
724 | #if defined(__WXOSX__) && wxOSX_USE_COCOA | |
725 | wxEventLoop* m_modalEventLoop; | |
726 | #endif | |
727 | wxWindowList *m_winDisabled; | |
728 | bool m_disabled; | |
729 | ||
730 | wxDECLARE_NO_COPY_CLASS(wxWindowDisabler); | |
731 | }; | |
732 | ||
733 | // ---------------------------------------------------------------------------- | |
734 | // Cursors | |
735 | // ---------------------------------------------------------------------------- | |
736 | ||
737 | // Set the cursor to the busy cursor for all windows | |
738 | WXDLLIMPEXP_CORE void wxBeginBusyCursor(const wxCursor *cursor = wxHOURGLASS_CURSOR); | |
739 | ||
740 | // Restore cursor to normal | |
741 | WXDLLIMPEXP_CORE void wxEndBusyCursor(); | |
742 | ||
743 | // true if we're between the above two calls | |
744 | WXDLLIMPEXP_CORE bool wxIsBusy(); | |
745 | ||
746 | // Convenience class so we can just create a wxBusyCursor object on the stack | |
747 | class WXDLLIMPEXP_CORE wxBusyCursor | |
748 | { | |
749 | public: | |
750 | wxBusyCursor(const wxCursor* cursor = wxHOURGLASS_CURSOR) | |
751 | { wxBeginBusyCursor(cursor); } | |
752 | ~wxBusyCursor() | |
753 | { wxEndBusyCursor(); } | |
754 | ||
755 | // FIXME: These two methods are currently only implemented (and needed?) | |
756 | // in wxGTK. BusyCursor handling should probably be moved to | |
757 | // common code since the wxGTK and wxMSW implementations are very | |
758 | // similar except for wxMSW using HCURSOR directly instead of | |
759 | // wxCursor.. -- RL. | |
760 | static const wxCursor &GetStoredCursor(); | |
761 | static const wxCursor GetBusyCursor(); | |
762 | }; | |
763 | ||
764 | void WXDLLIMPEXP_CORE wxGetMousePosition( int* x, int* y ); | |
765 | ||
766 | // ---------------------------------------------------------------------------- | |
767 | // X11 Display access | |
768 | // ---------------------------------------------------------------------------- | |
769 | ||
770 | #if defined(__X__) || defined(__WXGTK__) | |
771 | ||
772 | #ifdef __WXGTK__ | |
773 | WXDLLIMPEXP_CORE void *wxGetDisplay(); | |
774 | #endif | |
775 | ||
776 | #ifdef __X__ | |
777 | WXDLLIMPEXP_CORE WXDisplay *wxGetDisplay(); | |
778 | WXDLLIMPEXP_CORE bool wxSetDisplay(const wxString& display_name); | |
779 | WXDLLIMPEXP_CORE wxString wxGetDisplayName(); | |
780 | #endif // X or GTK+ | |
781 | ||
782 | // use this function instead of the functions above in implementation code | |
783 | inline struct _XDisplay *wxGetX11Display() | |
784 | { | |
785 | return (_XDisplay *)wxGetDisplay(); | |
786 | } | |
787 | ||
788 | #endif // X11 || wxGTK | |
789 | ||
790 | #endif // wxUSE_GUI | |
791 | ||
792 | // ---------------------------------------------------------------------------- | |
793 | // wxYield(): these functions are obsolete, please use wxApp methods instead! | |
794 | // ---------------------------------------------------------------------------- | |
795 | ||
796 | // avoid redeclaring this function here if it had been already declated by | |
797 | // wx/app.h, this results in warnings from g++ with -Wredundant-decls | |
798 | #ifndef wx_YIELD_DECLARED | |
799 | #define wx_YIELD_DECLARED | |
800 | ||
801 | // Yield to other apps/messages | |
802 | WXDLLIMPEXP_CORE bool wxYield(); | |
803 | ||
804 | #endif // wx_YIELD_DECLARED | |
805 | ||
806 | // Like wxYield, but fails silently if the yield is recursive. | |
807 | WXDLLIMPEXP_CORE bool wxYieldIfNeeded(); | |
808 | ||
809 | // ---------------------------------------------------------------------------- | |
810 | // Windows resources access | |
811 | // ---------------------------------------------------------------------------- | |
812 | ||
813 | // Windows only: get user-defined resource from the .res file. | |
814 | #ifdef __WINDOWS__ | |
815 | // default resource type for wxLoadUserResource() | |
816 | extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxUserResourceStr; | |
817 | ||
818 | // Return the pointer to the resource data. This pointer is read-only, use | |
819 | // the overload below if you need to modify the data. | |
820 | // | |
821 | // Notice that the resource type can be either a real string or an integer | |
822 | // produced by MAKEINTRESOURCE(). In particular, any standard resource type, | |
823 | // i.e any RT_XXX constant, could be passed here. | |
824 | // | |
825 | // Returns true on success, false on failure. Doesn't log an error message | |
826 | // if the resource is not found (because this could be expected) but does | |
827 | // log one if any other error occurs. | |
828 | WXDLLIMPEXP_BASE bool | |
829 | wxLoadUserResource(const void **outData, | |
830 | size_t *outLen, | |
831 | const wxString& resourceName, | |
832 | const wxChar* resourceType = wxUserResourceStr, | |
833 | WXHINSTANCE module = 0); | |
834 | ||
835 | // This function allocates a new buffer and makes a copy of the resource | |
836 | // data, remember to delete[] the buffer. And avoid using it entirely if | |
837 | // the overload above can be used. | |
838 | // | |
839 | // Returns NULL on failure. | |
840 | WXDLLIMPEXP_BASE char* | |
841 | wxLoadUserResource(const wxString& resourceName, | |
842 | const wxChar* resourceType = wxUserResourceStr, | |
843 | int* pLen = NULL, | |
844 | WXHINSTANCE module = 0); | |
845 | #endif // __WINDOWS__ | |
846 | ||
847 | #endif | |
848 | // _WX_UTILSH__ |