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