]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
55034339 | 2 | // Name: wx/utils.h |
c801d85f KB |
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 | |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_UTILSH__ |
13 | #define _WX_UTILSH__ | |
c801d85f | 14 | |
d6b9496a VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
c801d85f KB |
19 | #include "wx/object.h" |
20 | #include "wx/list.h" | |
c801d85f | 21 | #include "wx/filefn.h" |
2da2f941 MB |
22 | |
23 | class WXDLLIMPEXP_BASE wxArrayString; | |
230c9077 | 24 | class WXDLLIMPEXP_BASE wxArrayInt; |
c801d85f | 25 | |
eadd7bd2 VZ |
26 | // need this for wxGetDiskSpace() as we can't, unfortunately, forward declare |
27 | // wxLongLong | |
28 | #include "wx/longlong.h" | |
29 | ||
55034339 WS |
30 | #ifdef __WATCOMC__ |
31 | #include <direct.h> | |
32 | #elif defined(__X__) | |
d6b9496a VZ |
33 | #include <dirent.h> |
34 | #include <unistd.h> | |
c801d85f KB |
35 | #endif |
36 | ||
37 | #include <stdio.h> | |
38 | ||
d6b9496a VZ |
39 | // ---------------------------------------------------------------------------- |
40 | // Forward declaration | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
62a9d04c VS |
43 | class WXDLLIMPEXP_CORE wxProcess; |
44 | class WXDLLIMPEXP_CORE wxFrame; | |
45 | class WXDLLIMPEXP_CORE wxWindow; | |
46 | class WXDLLIMPEXP_CORE wxWindowList; | |
47 | class WXDLLIMPEXP_CORE wxPoint; | |
d6b9496a | 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 | |
9ad34f61 VZ |
56 | // wxGetFreeMemory can return huge amount of memory on 32-bit platforms as well |
57 | // so to always use long long for its result type on all platforms which | |
58 | // support it | |
59 | #if wxUSE_LONGLONG | |
60 | typedef wxLongLong wxMemorySize; | |
9d8aca48 | 61 | #else |
9ad34f61 | 62 | typedef long wxMemorySize; |
9d8aca48 WS |
63 | #endif |
64 | ||
d6b9496a VZ |
65 | // ---------------------------------------------------------------------------- |
66 | // String functions (deprecated, use wxString) | |
67 | // ---------------------------------------------------------------------------- | |
68 | ||
c801d85f | 69 | // Make a copy of this string using 'new' |
f526f752 | 70 | #if WXWIN_COMPATIBILITY_2_4 |
eecb33b0 | 71 | wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* copystring(const wxChar *s) ); |
f526f752 | 72 | #endif |
c801d85f | 73 | |
d6b9496a | 74 | // A shorter way of using strcmp |
9d2f3c71 | 75 | #define wxStringEq(s1, s2) (s1 && s2 && (wxStrcmp(s1, s2) == 0)) |
d6b9496a VZ |
76 | |
77 | // ---------------------------------------------------------------------------- | |
78 | // Miscellaneous functions | |
79 | // ---------------------------------------------------------------------------- | |
80 | ||
81 | // Sound the bell | |
968eb2ef MW |
82 | #if !defined __EMX__ && \ |
83 | (defined __WXMOTIF__ || defined __WXGTK__ || defined __WXX11__) | |
84 | WXDLLIMPEXP_CORE void wxBell(); | |
85 | #else | |
bddd7a8d | 86 | WXDLLIMPEXP_BASE void wxBell(); |
968eb2ef | 87 | #endif |
d6b9496a | 88 | |
bdc72a22 | 89 | // Get OS description as a user-readable string |
bddd7a8d | 90 | WXDLLIMPEXP_BASE wxString wxGetOsDescription(); |
bdc72a22 | 91 | |
d6b9496a | 92 | // Get OS version |
bddd7a8d | 93 | WXDLLIMPEXP_BASE int wxGetOsVersion(int *majorVsn = (int *) NULL, |
bdc72a22 | 94 | int *minorVsn = (int *) NULL); |
d6b9496a VZ |
95 | |
96 | // Return a string with the current date/time | |
bddd7a8d | 97 | WXDLLIMPEXP_BASE wxString wxNow(); |
d6b9496a | 98 | |
77ffb593 | 99 | // Return path where wxWidgets is installed (mostly useful in Unices) |
bddd7a8d | 100 | WXDLLIMPEXP_BASE const wxChar *wxGetInstallPrefix(); |
2c18f21d | 101 | // Return path to wxWin data (/usr/share/wx/%{version}) (Unices) |
bddd7a8d | 102 | WXDLLIMPEXP_BASE wxString wxGetDataDir(); |
134677bd | 103 | |
230c9077 JS |
104 | /* |
105 | * Class to make it easier to specify platform-dependent values | |
106 | * | |
107 | * Examples: | |
108 | * long val = wxPlatform(3).Is(wxMac, 1).Is(wxGTK, 2).Is(stPDA, 5); | |
109 | * wxString strVal = wxPlatform(wxT("Hello")).Is(wxMac, wxT("Mac")).Is(wxMSW, wxT("MSW")); | |
110 | * | |
111 | * A custom platform symbol: | |
112 | * | |
113 | * #define stPDA 100 | |
114 | * #ifdef __WXWINCE__ | |
115 | * wxPlatform::AddPlatform(stPDA); | |
116 | * #endif | |
117 | * | |
118 | * long windowStyle = wxCAPTION | (long) wxPlatform().IsNot(stPDA, wxRESIZE_BORDER); | |
119 | * | |
120 | */ | |
121 | ||
122 | class WXDLLIMPEXP_BASE wxPlatform | |
123 | { | |
124 | public: | |
125 | wxPlatform() { m_longValue = 0; m_doubleValue = 0.0; } | |
126 | ||
127 | // Specify an optional default value | |
128 | wxPlatform(long defValue) { m_longValue = defValue; m_doubleValue = 0.0; } | |
129 | wxPlatform(const wxString& defValue) { m_stringValue = defValue; m_longValue = 0; m_doubleValue = 0.0; } | |
130 | wxPlatform(double defValue) { m_longValue = 0; m_doubleValue = defValue; } | |
131 | ||
132 | wxPlatform& Is(int platform, long value); | |
133 | wxPlatform& IsNot(int platform, long value); | |
134 | ||
135 | wxPlatform& Is(int platform, int value) { return Is(platform, (long) value); } | |
136 | wxPlatform& IsNot(int platform, int value) { return IsNot(platform, (long) value); } | |
137 | ||
138 | wxPlatform& Is(int platform, const wxString& value); | |
139 | wxPlatform& IsNot(int platform, const wxString& value); | |
140 | ||
141 | wxPlatform& Is(int platform, double value); | |
142 | wxPlatform& IsNot(int platform, double value); | |
143 | ||
144 | // This should be specified first to set the default value, or simply | |
145 | // pass the value to the constructor | |
146 | wxPlatform& Default(long value); | |
147 | wxPlatform& Default(const wxString& value); | |
148 | wxPlatform& Default(double value); | |
149 | ||
150 | long GetInteger() const { return m_longValue; } | |
151 | const wxString& GetString() const { return m_stringValue; } | |
152 | double GetDouble() const { return m_doubleValue; } | |
153 | ||
154 | operator int() const { return (int) GetInteger(); } | |
155 | operator long() const { return GetInteger(); } | |
156 | operator double() const { return GetDouble(); } | |
157 | operator const wxString() const { return GetString(); } | |
158 | operator const wxChar*() const { return (const wxChar*) GetString(); } | |
159 | ||
160 | static void AddPlatform(int platform); | |
161 | static bool PlatformIs(int platform); | |
162 | static void ClearPlatforms(); | |
163 | ||
164 | private: | |
165 | long m_longValue; | |
166 | double m_doubleValue; | |
167 | wxString m_stringValue; | |
168 | static wxArrayInt* sm_customPlatforms; | |
169 | }; | |
170 | ||
171 | /// Function for testing current platform | |
172 | inline bool wxPlatformIs(int platform) { return wxPlatform::PlatformIs(platform); } | |
134677bd | 173 | |
e90c1d2a | 174 | #if wxUSE_GUI |
97698dc4 RD |
175 | |
176 | // Get the state of a key (true if pressed, false if not) | |
177 | // This is generally most useful getting the state of | |
178 | // the modifier or toggle keys. | |
1751226c | 179 | WXDLLEXPORT bool wxGetKeyState(wxKeyCode key); |
97698dc4 | 180 | |
14dfb3d2 | 181 | |
63cc5d9d RR |
182 | // Don't synthesize KeyUp events holding down a key and producing |
183 | // KeyDown events with autorepeat. On by default and always on | |
184 | // in wxMSW. | |
f0492f7d RR |
185 | WXDLLEXPORT bool wxSetDetectableAutoRepeat( bool flag ); |
186 | ||
7dd40b6f RD |
187 | |
188 | // wxMouseState is used to hold information about button and modifier state | |
189 | // and is what is returned from wxGetMouseState. | |
190 | class WXDLLEXPORT wxMouseState | |
191 | { | |
192 | public: | |
193 | wxMouseState() | |
194 | : m_x(0), m_y(0), | |
195 | m_leftDown(false), m_middleDown(false), m_rightDown(false), | |
196 | m_controlDown(false), m_shiftDown(false), m_altDown(false), | |
197 | m_metaDown(false) | |
198 | {} | |
199 | ||
200 | wxCoord GetX() { return m_x; } | |
201 | wxCoord GetY() { return m_y; } | |
202 | ||
203 | bool LeftDown() { return m_leftDown; } | |
204 | bool MiddleDown() { return m_middleDown; } | |
205 | bool RightDown() { return m_rightDown; } | |
206 | ||
207 | bool ControlDown() { return m_controlDown; } | |
208 | bool ShiftDown() { return m_shiftDown; } | |
209 | bool AltDown() { return m_altDown; } | |
210 | bool MetaDown() { return m_metaDown; } | |
211 | bool CmdDown() | |
212 | { | |
213 | #if defined(__WXMAC__) || defined(__WXCOCOA__) | |
214 | return MetaDown(); | |
215 | #else | |
216 | return ControlDown(); | |
217 | #endif | |
218 | } | |
219 | ||
220 | void SetX(wxCoord x) { m_x = x; } | |
221 | void SetY(wxCoord y) { m_y = y; } | |
222 | ||
223 | void SetLeftDown(bool down) { m_leftDown = down; } | |
224 | void SetMiddleDown(bool down) { m_middleDown = down; } | |
225 | void SetRightDown(bool down) { m_rightDown = down; } | |
226 | ||
227 | void SetControlDown(bool down) { m_controlDown = down; } | |
228 | void SetShiftDown(bool down) { m_shiftDown = down; } | |
229 | void SetAltDown(bool down) { m_altDown = down; } | |
230 | void SetMetaDown(bool down) { m_metaDown = down; } | |
231 | ||
232 | private: | |
233 | wxCoord m_x; | |
234 | wxCoord m_y; | |
235 | ||
236 | bool m_leftDown; | |
237 | bool m_middleDown; | |
238 | bool m_rightDown; | |
239 | ||
240 | bool m_controlDown; | |
241 | bool m_shiftDown; | |
242 | bool m_altDown; | |
243 | bool m_metaDown; | |
244 | }; | |
245 | ||
246 | ||
247 | // Returns the current state of the mouse position, buttons and modifers | |
248 | WXDLLEXPORT wxMouseState wxGetMouseState(); | |
249 | ||
250 | ||
d6b9496a VZ |
251 | // ---------------------------------------------------------------------------- |
252 | // Window ID management | |
253 | // ---------------------------------------------------------------------------- | |
254 | ||
c801d85f | 255 | // Generate a unique ID |
afb74891 | 256 | WXDLLEXPORT long wxNewId(); |
c801d85f KB |
257 | |
258 | // Ensure subsequent IDs don't clash with this one | |
184b5d99 | 259 | WXDLLEXPORT void wxRegisterId(long id); |
c801d85f KB |
260 | |
261 | // Return the current ID | |
afb74891 | 262 | WXDLLEXPORT long wxGetCurrentId(); |
c801d85f | 263 | |
e90c1d2a VZ |
264 | #endif // wxUSE_GUI |
265 | ||
d6b9496a VZ |
266 | // ---------------------------------------------------------------------------- |
267 | // Various conversions | |
268 | // ---------------------------------------------------------------------------- | |
c801d85f | 269 | |
e12c92c2 VZ |
270 | // these functions are deprecated, use wxString methods instead! |
271 | #if WXWIN_COMPATIBILITY_2_4 | |
272 | ||
16cba29d WS |
273 | extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxFloatToStringStr; |
274 | extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxDoubleToStringStr; | |
c801d85f | 275 | |
eecb33b0 WS |
276 | wxDEPRECATED( WXDLLIMPEXP_BASE void StringToFloat(const wxChar *s, float *number) ); |
277 | wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* FloatToString(float number, const wxChar *fmt = wxFloatToStringStr) ); | |
278 | wxDEPRECATED( WXDLLIMPEXP_BASE void StringToDouble(const wxChar *s, double *number) ); | |
279 | wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* DoubleToString(double number, const wxChar *fmt = wxDoubleToStringStr) ); | |
280 | wxDEPRECATED( WXDLLIMPEXP_BASE void StringToInt(const wxChar *s, int *number) ); | |
281 | wxDEPRECATED( WXDLLIMPEXP_BASE void StringToLong(const wxChar *s, long *number) ); | |
282 | wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* IntToString(int number) ); | |
283 | wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* LongToString(long number) ); | |
c801d85f | 284 | |
e12c92c2 VZ |
285 | #endif // WXWIN_COMPATIBILITY_2_4 |
286 | ||
c801d85f | 287 | // Convert 2-digit hex number to decimal |
bddd7a8d | 288 | WXDLLIMPEXP_BASE int wxHexToDec(const wxString& buf); |
c801d85f KB |
289 | |
290 | // Convert decimal integer to 2-character hex string | |
bddd7a8d VZ |
291 | WXDLLIMPEXP_BASE void wxDecToHex(int dec, wxChar *buf); |
292 | WXDLLIMPEXP_BASE wxString wxDecToHex(int dec); | |
c801d85f | 293 | |
d6b9496a VZ |
294 | // ---------------------------------------------------------------------------- |
295 | // Process management | |
296 | // ---------------------------------------------------------------------------- | |
297 | ||
e0f6b731 | 298 | // NB: for backwards compatibility reasons the values of wxEXEC_[A]SYNC *must* |
fbf456aa VZ |
299 | // be 0 and 1, don't change! |
300 | ||
301 | enum | |
302 | { | |
e1082c9f VZ |
303 | // execute the process asynchronously |
304 | wxEXEC_ASYNC = 0, | |
305 | ||
306 | // execute it synchronously, i.e. wait until it finishes | |
307 | wxEXEC_SYNC = 1, | |
308 | ||
309 | // under Windows, don't hide the child even if it's IO is redirected (this | |
310 | // is done by default) | |
311 | wxEXEC_NOHIDE = 2, | |
312 | ||
e0f6b731 JS |
313 | // under Unix, if the process is the group leader then passing wxKILL_CHILDREN to wxKill |
314 | // kills all children as well as pid | |
f38f6899 VZ |
315 | wxEXEC_MAKE_GROUP_LEADER = 4, |
316 | ||
317 | // by default synchronous execution disables all program windows to avoid | |
318 | // that the user interacts with the program while the child process is | |
319 | // running, you can use this flag to prevent this from happening | |
320 | wxEXEC_NODISABLE = 8 | |
fbf456aa VZ |
321 | }; |
322 | ||
323 | // Execute another program. | |
324 | // | |
325 | // If flags contain wxEXEC_SYNC, return -1 on failure and the exit code of the | |
326 | // process if everything was ok. Otherwise (i.e. if wxEXEC_ASYNC), return 0 on | |
327 | // failure and the PID of the launched process if ok. | |
bddd7a8d | 328 | WXDLLIMPEXP_BASE long wxExecute(wxChar **argv, int flags = wxEXEC_ASYNC, |
c67daf87 | 329 | wxProcess *process = (wxProcess *) NULL); |
bddd7a8d | 330 | WXDLLIMPEXP_BASE long wxExecute(const wxString& command, int flags = wxEXEC_ASYNC, |
c67daf87 | 331 | wxProcess *process = (wxProcess *) NULL); |
c801d85f | 332 | |
fbf456aa VZ |
333 | // execute the command capturing its output into an array line by line, this is |
334 | // always synchronous | |
bddd7a8d | 335 | WXDLLIMPEXP_BASE long wxExecute(const wxString& command, |
4d172154 VZ |
336 | wxArrayString& output, |
337 | int flags = 0); | |
f6bcfd97 | 338 | |
fbf456aa | 339 | // also capture stderr (also synchronous) |
bddd7a8d | 340 | WXDLLIMPEXP_BASE long wxExecute(const wxString& command, |
4d172154 VZ |
341 | wxArrayString& output, |
342 | wxArrayString& error, | |
343 | int flags = 0); | |
cd6ce4a9 | 344 | |
5ccb95f6 | 345 | #if defined(__WXMSW__) && wxUSE_IPC |
42d0df00 VZ |
346 | // ask a DDE server to execute the DDE request with given parameters |
347 | WXDLLIMPEXP_BASE bool wxExecuteDDE(const wxString& ddeServer, | |
348 | const wxString& ddeTopic, | |
349 | const wxString& ddeCommand); | |
5ccb95f6 | 350 | #endif // __WXMSW__ && wxUSE_IPC |
42d0df00 | 351 | |
d6b9496a VZ |
352 | enum wxSignal |
353 | { | |
354 | wxSIGNONE = 0, // verify if the process exists under Unix | |
355 | wxSIGHUP, | |
356 | wxSIGINT, | |
357 | wxSIGQUIT, | |
358 | wxSIGILL, | |
359 | wxSIGTRAP, | |
360 | wxSIGABRT, | |
361 | wxSIGIOT = wxSIGABRT, // another name | |
362 | wxSIGEMT, | |
363 | wxSIGFPE, | |
364 | wxSIGKILL, | |
365 | wxSIGBUS, | |
366 | wxSIGSEGV, | |
367 | wxSIGSYS, | |
368 | wxSIGPIPE, | |
369 | wxSIGALRM, | |
370 | wxSIGTERM | |
371 | ||
372 | // further signals are different in meaning between different Unix systems | |
373 | }; | |
c801d85f | 374 | |
50567b69 VZ |
375 | enum wxKillError |
376 | { | |
377 | wxKILL_OK, // no error | |
378 | wxKILL_BAD_SIGNAL, // no such signal | |
379 | wxKILL_ACCESS_DENIED, // permission denied | |
380 | wxKILL_NO_PROCESS, // no such process | |
381 | wxKILL_ERROR // another, unspecified error | |
382 | }; | |
383 | ||
e0f6b731 JS |
384 | enum wxKillFlags |
385 | { | |
386 | wxKILL_NOCHILDREN = 0, // don't kill children | |
387 | wxKILL_CHILDREN = 1 // kill children | |
388 | }; | |
389 | ||
f6ba47d9 VZ |
390 | enum wxShutdownFlags |
391 | { | |
392 | wxSHUTDOWN_POWEROFF, // power off the computer | |
393 | wxSHUTDOWN_REBOOT // shutdown and reboot | |
394 | }; | |
395 | ||
c1cb4153 | 396 | // Shutdown or reboot the PC |
bddd7a8d | 397 | WXDLLIMPEXP_BASE bool wxShutdown(wxShutdownFlags wFlags); |
f6ba47d9 | 398 | |
8ea92b4d WS |
399 | enum wxPowerType |
400 | { | |
401 | wxPOWER_SOCKET, | |
402 | wxPOWER_BATTERY, | |
403 | wxPOWER_UNKNOWN | |
404 | }; | |
405 | ||
406 | WXDLLIMPEXP_BASE wxPowerType wxGetPowerType(); | |
407 | ||
408 | enum wxBatteryState | |
409 | { | |
410 | wxBATTERY_NORMAL_STATE, // system is fully usable | |
411 | wxBATTERY_LOW_STATE, // start to worry | |
412 | wxBATTERY_CRITICAL_STATE, // save quickly | |
413 | wxBATTERY_SHUTDOWN_STATE, // too late | |
414 | wxBATTERY_UNKNOWN_STATE | |
415 | }; | |
416 | ||
417 | WXDLLIMPEXP_BASE wxBatteryState wxGetBatteryState(); | |
418 | ||
50567b69 VZ |
419 | // send the given signal to the process (only NONE and KILL are supported under |
420 | // Windows, all others mean TERM), return 0 if ok and -1 on error | |
421 | // | |
422 | // return detailed error in rc if not NULL | |
bddd7a8d | 423 | WXDLLIMPEXP_BASE int wxKill(long pid, |
50567b69 | 424 | wxSignal sig = wxSIGTERM, |
e0f6b731 JS |
425 | wxKillError *rc = NULL, |
426 | int flags = wxKILL_NOCHILDREN); | |
c801d85f | 427 | |
2c8e4738 | 428 | // Execute a command in an interactive shell window (always synchronously) |
c801d85f | 429 | // If no command then just the shell |
bddd7a8d | 430 | WXDLLIMPEXP_BASE bool wxShell(const wxString& command = wxEmptyString); |
c801d85f | 431 | |
2c8e4738 VZ |
432 | // As wxShell(), but must give a (non interactive) command and its output will |
433 | // be returned in output array | |
bddd7a8d | 434 | WXDLLIMPEXP_BASE bool wxShell(const wxString& command, wxArrayString& output); |
2c8e4738 | 435 | |
b568d04f | 436 | // Sleep for nSecs seconds |
bddd7a8d | 437 | WXDLLIMPEXP_BASE void wxSleep(int nSecs); |
c801d85f | 438 | |
afb74891 | 439 | // Sleep for a given amount of milliseconds |
08873d36 VZ |
440 | WXDLLIMPEXP_BASE void wxMilliSleep(unsigned long milliseconds); |
441 | ||
442 | // Sleep for a given amount of microseconds | |
443 | WXDLLIMPEXP_BASE void wxMicroSleep(unsigned long microseconds); | |
444 | ||
445 | // Sleep for a given amount of milliseconds (old, bad name), use wxMilliSleep | |
446 | wxDEPRECATED( WXDLLIMPEXP_BASE void wxUsleep(unsigned long milliseconds) ); | |
afb74891 | 447 | |
c1cb4153 | 448 | // Get the process id of the current process |
bddd7a8d | 449 | WXDLLIMPEXP_BASE unsigned long wxGetProcessId(); |
c1cb4153 | 450 | |
c801d85f | 451 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) |
9d8aca48 | 452 | WXDLLIMPEXP_BASE wxMemorySize wxGetFreeMemory(); |
c801d85f | 453 | |
a76d8a29 VZ |
454 | #if wxUSE_ON_FATAL_EXCEPTION |
455 | ||
a37a5a73 | 456 | // should wxApp::OnFatalException() be called? |
cb719f2e | 457 | WXDLLIMPEXP_BASE bool wxHandleFatalExceptions(bool doit = true); |
a37a5a73 | 458 | |
a76d8a29 VZ |
459 | #endif // wxUSE_ON_FATAL_EXCEPTION |
460 | ||
42d0df00 VZ |
461 | // flags for wxLaunchDefaultBrowser |
462 | enum | |
463 | { | |
464 | wxBROWSER_NEW_WINDOW = 1 | |
465 | }; | |
466 | ||
498a1eeb | 467 | // Launch url in the user's default internet browser |
42d0df00 | 468 | WXDLLIMPEXP_BASE bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0); |
498a1eeb | 469 | |
8fd0d89b VZ |
470 | // ---------------------------------------------------------------------------- |
471 | // Environment variables | |
472 | // ---------------------------------------------------------------------------- | |
473 | ||
cb719f2e | 474 | // returns true if variable exists (value may be NULL if you just want to check |
308978f6 | 475 | // for this) |
bddd7a8d | 476 | WXDLLIMPEXP_BASE bool wxGetEnv(const wxString& var, wxString *value); |
8fd0d89b | 477 | |
cb719f2e | 478 | // set the env var name to the given value, return true on success |
bddd7a8d | 479 | WXDLLIMPEXP_BASE bool wxSetEnv(const wxString& var, const wxChar *value); |
8fd0d89b VZ |
480 | |
481 | // remove the env var from environment | |
482 | inline bool wxUnsetEnv(const wxString& var) { return wxSetEnv(var, NULL); } | |
483 | ||
d6b9496a VZ |
484 | // ---------------------------------------------------------------------------- |
485 | // Network and username functions. | |
486 | // ---------------------------------------------------------------------------- | |
c801d85f | 487 | |
d6b9496a | 488 | // NB: "char *" functions are deprecated, use wxString ones! |
c801d85f KB |
489 | |
490 | // Get eMail address | |
bddd7a8d VZ |
491 | WXDLLIMPEXP_BASE bool wxGetEmailAddress(wxChar *buf, int maxSize); |
492 | WXDLLIMPEXP_BASE wxString wxGetEmailAddress(); | |
c801d85f KB |
493 | |
494 | // Get hostname. | |
bddd7a8d VZ |
495 | WXDLLIMPEXP_BASE bool wxGetHostName(wxChar *buf, int maxSize); |
496 | WXDLLIMPEXP_BASE wxString wxGetHostName(); | |
d6b9496a VZ |
497 | |
498 | // Get FQDN | |
bddd7a8d VZ |
499 | WXDLLIMPEXP_BASE wxString wxGetFullHostName(); |
500 | WXDLLIMPEXP_BASE bool wxGetFullHostName(wxChar *buf, int maxSize); | |
c801d85f | 501 | |
d6b9496a | 502 | // Get user ID e.g. jacs (this is known as login name under Unix) |
bddd7a8d VZ |
503 | WXDLLIMPEXP_BASE bool wxGetUserId(wxChar *buf, int maxSize); |
504 | WXDLLIMPEXP_BASE wxString wxGetUserId(); | |
c801d85f KB |
505 | |
506 | // Get user name e.g. Julian Smart | |
bddd7a8d VZ |
507 | WXDLLIMPEXP_BASE bool wxGetUserName(wxChar *buf, int maxSize); |
508 | WXDLLIMPEXP_BASE wxString wxGetUserName(); | |
d6b9496a VZ |
509 | |
510 | // Get current Home dir and copy to dest (returns pstr->c_str()) | |
bddd7a8d VZ |
511 | WXDLLIMPEXP_BASE wxString wxGetHomeDir(); |
512 | WXDLLIMPEXP_BASE const wxChar* wxGetHomeDir(wxString *pstr); | |
d6b9496a VZ |
513 | |
514 | // Get the user's home dir (caller must copy --- volatile) | |
515 | // returns NULL is no HOME dir is known | |
61ef57fc | 516 | #if defined(__UNIX__) && wxUSE_UNICODE |
bddd7a8d | 517 | WXDLLIMPEXP_BASE const wxMB2WXbuf wxGetUserHome(const wxString& user = wxEmptyString); |
61ef57fc | 518 | #else |
bddd7a8d | 519 | WXDLLIMPEXP_BASE wxChar* wxGetUserHome(const wxString& user = wxEmptyString); |
61ef57fc | 520 | #endif |
d6b9496a | 521 | |
7ba7c4e6 VZ |
522 | #if wxUSE_LONGLONG |
523 | typedef wxLongLong wxDiskspaceSize_t; | |
524 | #else | |
525 | typedef long wxDiskspaceSize_t; | |
526 | #endif | |
527 | ||
eadd7bd2 | 528 | // get number of total/free bytes on the disk where path belongs |
bddd7a8d | 529 | WXDLLIMPEXP_BASE bool wxGetDiskSpace(const wxString& path, |
7ba7c4e6 VZ |
530 | wxDiskspaceSize_t *pTotal = NULL, |
531 | wxDiskspaceSize_t *pFree = NULL); | |
eadd7bd2 | 532 | |
e90c1d2a VZ |
533 | #if wxUSE_GUI // GUI only things from now on |
534 | ||
d6b9496a | 535 | // ---------------------------------------------------------------------------- |
974e8d94 | 536 | // Menu accelerators related things |
d6b9496a | 537 | // ---------------------------------------------------------------------------- |
c801d85f | 538 | |
bc87fd68 | 539 | WXDLLEXPORT wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = (wxChar *) NULL); |
184b5d99 | 540 | WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str); |
c801d85f | 541 | |
974e8d94 VZ |
542 | #if wxUSE_ACCEL |
543 | class WXDLLEXPORT wxAcceleratorEntry; | |
544 | WXDLLEXPORT wxAcceleratorEntry *wxGetAccelFromString(const wxString& label); | |
545 | #endif // wxUSE_ACCEL | |
546 | ||
d6b9496a VZ |
547 | // ---------------------------------------------------------------------------- |
548 | // Window search | |
549 | // ---------------------------------------------------------------------------- | |
550 | ||
cb719f2e | 551 | // Returns menu item id or wxNOT_FOUND if none. |
184b5d99 | 552 | WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString); |
c801d85f | 553 | |
57591e0e JS |
554 | // Find the wxWindow at the given point. wxGenericFindWindowAtPoint |
555 | // is always present but may be less reliable than a native version. | |
556 | WXDLLEXPORT wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt); | |
59a12e90 JS |
557 | WXDLLEXPORT wxWindow* wxFindWindowAtPoint(const wxPoint& pt); |
558 | ||
146ba0fe VZ |
559 | // NB: this function is obsolete, use wxWindow::FindWindowByLabel() instead |
560 | // | |
561 | // Find the window/widget with the given title or label. | |
562 | // Pass a parent to begin the search from, or NULL to look through | |
563 | // all windows. | |
564 | WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL); | |
565 | ||
566 | // NB: this function is obsolete, use wxWindow::FindWindowByName() instead | |
567 | // | |
568 | // Find window by name, and if that fails, by label. | |
569 | WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL); | |
570 | ||
d6b9496a VZ |
571 | // ---------------------------------------------------------------------------- |
572 | // Message/event queue helpers | |
573 | // ---------------------------------------------------------------------------- | |
c801d85f | 574 | |
ead7ce10 | 575 | // Yield to other apps/messages and disable user input |
cb719f2e | 576 | WXDLLEXPORT bool wxSafeYield(wxWindow *win = NULL, bool onlyIfNeeded = false); |
ead7ce10 | 577 | |
95dee651 | 578 | // Enable or disable input to all top level windows |
cb719f2e | 579 | WXDLLEXPORT void wxEnableTopLevelWindows(bool enable = true); |
95dee651 | 580 | |
d6b9496a VZ |
581 | // Check whether this window wants to process messages, e.g. Stop button |
582 | // in long calculations. | |
583 | WXDLLEXPORT bool wxCheckForInterrupt(wxWindow *wnd); | |
584 | ||
585 | // Consume all events until no more left | |
586 | WXDLLEXPORT void wxFlushEvents(); | |
587 | ||
cd6ce4a9 VZ |
588 | // a class which disables all windows (except, may be, thegiven one) in its |
589 | // ctor and enables them back in its dtor | |
590 | class WXDLLEXPORT wxWindowDisabler | |
591 | { | |
592 | public: | |
593 | wxWindowDisabler(wxWindow *winToSkip = (wxWindow *)NULL); | |
594 | ~wxWindowDisabler(); | |
595 | ||
596 | private: | |
597 | wxWindowList *m_winDisabled; | |
c1cb4153 VZ |
598 | |
599 | DECLARE_NO_COPY_CLASS(wxWindowDisabler) | |
cd6ce4a9 VZ |
600 | }; |
601 | ||
d6b9496a VZ |
602 | // ---------------------------------------------------------------------------- |
603 | // Cursors | |
604 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
605 | |
606 | // Set the cursor to the busy cursor for all windows | |
607 | class WXDLLEXPORT wxCursor; | |
16cba29d | 608 | extern WXDLLEXPORT_DATA(wxCursor*) wxHOURGLASS_CURSOR; |
184b5d99 | 609 | WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR); |
e2a6f233 | 610 | |
c801d85f | 611 | // Restore cursor to normal |
afb74891 | 612 | WXDLLEXPORT void wxEndBusyCursor(); |
d6b9496a | 613 | |
cb719f2e | 614 | // true if we're between the above two calls |
afb74891 | 615 | WXDLLEXPORT bool wxIsBusy(); |
c801d85f | 616 | |
e2a6f233 JS |
617 | // Convenience class so we can just create a wxBusyCursor object on the stack |
618 | class WXDLLEXPORT wxBusyCursor | |
619 | { | |
afb74891 VZ |
620 | public: |
621 | wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR) | |
622 | { wxBeginBusyCursor(cursor); } | |
f6bcfd97 | 623 | ~wxBusyCursor() |
afb74891 | 624 | { wxEndBusyCursor(); } |
e2a6f233 | 625 | |
f6bcfd97 BP |
626 | // FIXME: These two methods are currently only implemented (and needed?) |
627 | // in wxGTK. BusyCursor handling should probably be moved to | |
628 | // common code since the wxGTK and wxMSW implementations are very | |
629 | // similar except for wxMSW using HCURSOR directly instead of | |
630 | // wxCursor.. -- RL. | |
631 | static const wxCursor &GetStoredCursor(); | |
632 | static const wxCursor GetBusyCursor(); | |
633 | }; | |
c801d85f | 634 | |
c801d85f | 635 | |
d6b9496a | 636 | // ---------------------------------------------------------------------------- |
c801d85f | 637 | // Reading and writing resources (eg WIN.INI, .Xdefaults) |
d6b9496a VZ |
638 | // ---------------------------------------------------------------------------- |
639 | ||
47d67540 | 640 | #if wxUSE_RESOURCES |
62448488 JS |
641 | WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = wxEmptyString); |
642 | WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = wxEmptyString); | |
643 | WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = wxEmptyString); | |
644 | WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = wxEmptyString); | |
645 | ||
9d2f3c71 | 646 | WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file = wxEmptyString); |
62448488 JS |
647 | WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = wxEmptyString); |
648 | WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = wxEmptyString); | |
649 | WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = wxEmptyString); | |
47d67540 | 650 | #endif // wxUSE_RESOURCES |
c801d85f | 651 | |
c801d85f KB |
652 | void WXDLLEXPORT wxGetMousePosition( int* x, int* y ); |
653 | ||
654 | // MSW only: get user-defined resource from the .res file. | |
655 | // Returns NULL or newly-allocated memory, so use delete[] to clean up. | |
2049ba38 | 656 | #ifdef __WXMSW__ |
16cba29d | 657 | extern WXDLLEXPORT const wxChar* wxUserResourceStr; |
373658eb | 658 | WXDLLEXPORT wxChar* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr); |
d6b9496a VZ |
659 | #endif // MSW |
660 | ||
661 | // ---------------------------------------------------------------------------- | |
662 | // Display and colorss (X only) | |
663 | // ---------------------------------------------------------------------------- | |
c801d85f | 664 | |
d111a89a VZ |
665 | #ifdef __WXGTK__ |
666 | void *wxGetDisplay(); | |
667 | #endif | |
668 | ||
c801d85f | 669 | #ifdef __X__ |
968eb2ef MW |
670 | WXDLLIMPEXP_CORE WXDisplay *wxGetDisplay(); |
671 | WXDLLIMPEXP_CORE bool wxSetDisplay(const wxString& display_name); | |
672 | WXDLLIMPEXP_CORE wxString wxGetDisplayName(); | |
d111a89a | 673 | #endif // X or GTK+ |
c801d85f KB |
674 | |
675 | #ifdef __X__ | |
676 | ||
338dd992 JJ |
677 | #ifdef __VMS__ // Xlib.h for VMS is not (yet) compatible with C++ |
678 | // The resulting warnings are switched off here | |
679 | #pragma message disable nosimpint | |
680 | #endif | |
7266b672 | 681 | // #include <X11/Xlib.h> |
338dd992 JJ |
682 | #ifdef __VMS__ |
683 | #pragma message enable nosimpint | |
684 | #endif | |
c801d85f | 685 | |
c801d85f KB |
686 | #endif //__X__ |
687 | ||
e90c1d2a VZ |
688 | #endif // wxUSE_GUI |
689 | ||
886dd7d2 VZ |
690 | // ---------------------------------------------------------------------------- |
691 | // wxYield(): these functions are obsolete, please use wxApp methods instead! | |
692 | // ---------------------------------------------------------------------------- | |
693 | ||
694 | // Yield to other apps/messages | |
bddd7a8d | 695 | WXDLLIMPEXP_BASE bool wxYield(); |
886dd7d2 VZ |
696 | |
697 | // Like wxYield, but fails silently if the yield is recursive. | |
bddd7a8d | 698 | WXDLLIMPEXP_BASE bool wxYieldIfNeeded(); |
886dd7d2 | 699 | |
f6bcfd97 | 700 | // ---------------------------------------------------------------------------- |
77ffb593 | 701 | // Error message functions used by wxWidgets (deprecated, use wxLog) |
f6bcfd97 BP |
702 | // ---------------------------------------------------------------------------- |
703 | ||
c801d85f | 704 | #endif |
34138703 | 705 | // _WX_UTILSH__ |