]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: utils.cpp | |
3 | // Purpose: Various utilities | |
45fcbf3b | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
45fcbf3b | 6 | // Created: 09/17/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
45fcbf3b DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows license | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
45fcbf3b DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/setup.h" | |
17 | #include "wx/utils.h" | |
18 | #include "wx/app.h" | |
19 | #include "wx/cursor.h" | |
20 | #endif //WX_PRECOMP | |
21 | ||
22 | #include "wx/os2/private.h" | |
23 | #include "wx/timer.h" | |
24 | #include "wx/intl.h" | |
25 | ||
0e320a79 | 26 | #include <ctype.h> |
06298235 SN |
27 | #ifdef __EMX__ |
28 | #include <dirent.h> | |
29 | #else | |
45fcbf3b | 30 | #include <direct.h> |
06298235 | 31 | #endif |
45fcbf3b DW |
32 | |
33 | #include "wx/log.h" | |
34 | ||
35 | #include <io.h> | |
0e320a79 DW |
36 | |
37 | #include <stdio.h> | |
38 | #include <stdlib.h> | |
39 | #include <string.h> | |
45fcbf3b | 40 | #include <errno.h> |
0e320a79 DW |
41 | #include <stdarg.h> |
42 | ||
d90895ac | 43 | #define PURE_32 |
468e327a | 44 | |
06298235 | 45 | #ifndef __EMX__ |
7cdc2f1e DW |
46 | #include <upm.h> |
47 | #include <netcons.h> | |
48 | #include <netbios.h> | |
06298235 | 49 | #endif |
45fcbf3b | 50 | |
86de7616 DW |
51 | static const wxChar WX_SECTION[] = _T("wxWindows"); |
52 | static const wxChar eHOSTNAME[] = _T("HostName"); | |
53 | static const wxChar eUSERID[] = _T("UserId"); | |
54 | static const wxChar eUSERNAME[] = _T("UserName"); | |
45fcbf3b DW |
55 | |
56 | // For the following functions we SHOULD fill in support | |
57 | // for Windows-NT (which I don't know) as I assume it begin | |
58 | // a POSIX Unix (so claims MS) that it has some special | |
59 | // functions beyond those provided by WinSock | |
60 | ||
0e320a79 | 61 | // Get full hostname (eg. DoDo.BSn-Germany.crg.de) |
10e5b930 DW |
62 | bool wxGetHostName( |
63 | wxChar* zBuf | |
64 | , int nMaxSize | |
65 | ) | |
0e320a79 | 66 | { |
d90895ac | 67 | #if wxUSE_NET_API |
10e5b930 DW |
68 | char zServer[256]; |
69 | char zComputer[256]; | |
909b4f08 | 70 | unsigned long ulLevel = 0; |
9dea36ef DW |
71 | unsigned char* zBuffer = NULL; |
72 | unsigned long ulBuffer = 256; | |
73 | unsigned long* pulTotalAvail = NULL; | |
10e5b930 | 74 | |
dde11e60 DW |
75 | NetBios32GetInfo( (const unsigned char*)zServer |
76 | ,(const unsigned char*)zComputer | |
909b4f08 | 77 | ,ulLevel |
dde11e60 | 78 | ,zBuffer |
909b4f08 DW |
79 | ,ulBuffer |
80 | ,pulTotalAvail | |
dde11e60 | 81 | ); |
10e5b930 | 82 | strcpy(zBuf, zServer); |
45fcbf3b | 83 | #else |
10e5b930 DW |
84 | wxChar* zSysname; |
85 | const wxChar* zDefaultHost = _T("noname"); | |
45fcbf3b | 86 | |
10e5b930 DW |
87 | if ((zSysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL) |
88 | { | |
89 | ULONG n = ::PrfQueryProfileString( HINI_PROFILE | |
90 | ,(PSZ)WX_SECTION | |
91 | ,(PSZ)eHOSTNAME | |
92 | ,(PSZ)zDefaultHost | |
93 | ,(void*)zBuf | |
94 | ,(ULONG)nMaxSize - 1 | |
95 | ); | |
96 | } | |
97 | else | |
98 | wxStrncpy(zBuf, zSysname, nMaxSize - 1); | |
99 | zBuf[nMaxSize] = _T('\0'); | |
45fcbf3b | 100 | #endif |
10e5b930 | 101 | return *zBuf ? TRUE : FALSE; |
0e320a79 DW |
102 | } |
103 | ||
104 | // Get user ID e.g. jacs | |
10e5b930 DW |
105 | bool wxGetUserId( |
106 | wxChar* zBuf | |
2bd5bbc9 | 107 | , int nType |
10e5b930 | 108 | ) |
0e320a79 | 109 | { |
06298235 | 110 | #ifndef __EMX__ |
2bd5bbc9 DW |
111 | long lrc; |
112 | // UPM procs return 0 on success | |
113 | lrc = U32ELOCU((unsigned char*)zBuf, (unsigned long *)&nType); | |
114 | if (lrc == 0) return TRUE; | |
06298235 | 115 | #endif |
2bd5bbc9 | 116 | return FALSE; |
0e320a79 DW |
117 | } |
118 | ||
10e5b930 DW |
119 | bool wxGetUserName( |
120 | wxChar* zBuf | |
121 | , int nMaxSize | |
122 | ) | |
0e320a79 | 123 | { |
45fcbf3b | 124 | #ifdef USE_NET_API |
10e5b930 DW |
125 | wxGetUserId( zBuf |
126 | ,nMaxSize | |
127 | ); | |
45fcbf3b | 128 | #else |
10e5b930 | 129 | wxStrncpy(zBuf, _T("Unknown User"), nMaxSize); |
45fcbf3b | 130 | #endif |
10e5b930 | 131 | return TRUE; |
0e320a79 DW |
132 | } |
133 | ||
10e5b930 DW |
134 | int wxKill( |
135 | long lPid | |
136 | , int nSig | |
137 | ) | |
0e320a79 | 138 | { |
10e5b930 | 139 | return((int)::DosKillProcess(0, (PID)lPid)); |
0e320a79 DW |
140 | } |
141 | ||
142 | // | |
143 | // Execute a program in an Interactive Shell | |
144 | // | |
10e5b930 DW |
145 | bool wxShell( |
146 | const wxString& rCommand | |
147 | ) | |
0e320a79 | 148 | { |
c5fb56c0 DW |
149 | wxChar* zShell = _T("CMD.EXE"); |
150 | wxString sInputs; | |
10e5b930 | 151 | wxChar zTmp[255]; |
c5fb56c0 DW |
152 | STARTDATA SData = {0}; |
153 | PSZ PgmTitle = "Command Shell"; | |
154 | APIRET rc; | |
155 | PID vPid = 0; | |
156 | ULONG ulSessID = 0; | |
157 | UCHAR achObjBuf[256] = {0}; //error data if DosStart fails | |
158 | RESULTCODES vResult; | |
159 | ||
160 | SData.Length = sizeof(STARTDATA); | |
161 | SData.Related = SSF_RELATED_INDEPENDENT; | |
162 | SData.FgBg = SSF_FGBG_FORE; | |
163 | SData.TraceOpt = SSF_TRACEOPT_NONE; | |
164 | SData.PgmTitle = PgmTitle; | |
165 | SData.PgmName = zShell; | |
166 | ||
909b4f08 | 167 | sInputs = "/C " + rCommand; |
9ac6ff7b | 168 | SData.PgmInputs = (BYTE*)sInputs.c_str(); |
c5fb56c0 DW |
169 | SData.TermQ = 0; |
170 | SData.Environment = 0; | |
171 | SData.InheritOpt = SSF_INHERTOPT_SHELL; | |
172 | SData.SessionType = SSF_TYPE_WINDOWABLEVIO; | |
173 | SData.IconFile = 0; | |
174 | SData.PgmHandle = 0; | |
175 | SData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE; | |
176 | SData.InitXPos = 30; | |
177 | SData.InitYPos = 40; | |
178 | SData.InitXSize = 200; | |
179 | SData.InitYSize = 140; | |
180 | SData.Reserved = 0; | |
181 | SData.ObjectBuffer = (char*)achObjBuf; | |
182 | SData.ObjectBuffLen = (ULONG)sizeof(achObjBuf); | |
183 | ||
184 | rc = ::DosStartSession(&SData, &ulSessID, &vPid); | |
9ac6ff7b | 185 | if (rc == 0 || rc == 457) // NO_ERROR or SMG_START_IN_BACKGROUND |
c5fb56c0 DW |
186 | { |
187 | PTIB ptib; | |
188 | PPIB ppib; | |
10e5b930 | 189 | |
c5fb56c0 | 190 | ::DosGetInfoBlocks(&ptib, &ppib); |
10e5b930 | 191 | |
c5fb56c0 DW |
192 | ::DosWaitChild( DCWA_PROCESS |
193 | ,DCWW_WAIT | |
194 | ,&vResult | |
195 | ,&ppib->pib_ulpid | |
196 | ,vPid | |
197 | ); | |
198 | } | |
199 | return (rc != 0); | |
0e320a79 DW |
200 | } |
201 | ||
202 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) | |
5d4b632b | 203 | long wxGetFreeMemory() |
0e320a79 | 204 | { |
9dea36ef | 205 | void* pMemptr = NULL; |
78d50441 DW |
206 | ULONG lSize; |
207 | ULONG lMemFlags; | |
208 | APIRET rc; | |
209 | ||
210 | lMemFlags = PAG_FREE; | |
10e5b930 | 211 | rc = ::DosQueryMem(pMemptr, &lSize, &lMemFlags); |
78d50441 DW |
212 | if (rc != 0) |
213 | return -1L; | |
214 | return (long)lSize; | |
45fcbf3b DW |
215 | } |
216 | ||
217 | // Sleep for nSecs seconds. Attempt a Windows implementation using timers. | |
218 | static bool inTimer = FALSE; | |
219 | ||
220 | class wxSleepTimer: public wxTimer | |
221 | { | |
10e5b930 DW |
222 | public: |
223 | inline void Notify() | |
224 | { | |
225 | inTimer = FALSE; | |
226 | Stop(); | |
227 | } | |
45fcbf3b DW |
228 | }; |
229 | ||
10e5b930 | 230 | static wxTimer* wxTheSleepTimer = NULL; |
45fcbf3b | 231 | |
10e5b930 DW |
232 | void wxUsleep( |
233 | unsigned long ulMilliseconds | |
234 | ) | |
45fcbf3b | 235 | { |
468e327a | 236 | ::DosSleep(ulMilliseconds/1000l); |
0e320a79 DW |
237 | } |
238 | ||
10e5b930 DW |
239 | void wxSleep( |
240 | int nSecs | |
241 | ) | |
0e320a79 | 242 | { |
10e5b930 | 243 | ::DosSleep(1000 * nSecs); |
0e320a79 DW |
244 | } |
245 | ||
246 | // Consume all events until no more left | |
247 | void wxFlushEvents() | |
248 | { | |
45fcbf3b | 249 | // wxYield(); |
0e320a79 DW |
250 | } |
251 | ||
45fcbf3b | 252 | // Output a debug mess., in a system dependent fashion. |
10e5b930 DW |
253 | void wxDebugMsg( |
254 | const wxChar* zFmt ... | |
255 | ) | |
256 | { | |
257 | va_list vAp; | |
258 | static wxChar zBuffer[512]; | |
259 | ||
260 | if (!wxTheApp->GetWantDebugOutput()) | |
261 | return ; | |
262 | va_start(vAp, zFmt); | |
263 | sprintf(zBuffer, zFmt, vAp) ; | |
264 | va_end(vAp); | |
0e320a79 DW |
265 | } |
266 | ||
267 | // Non-fatal error: pop up message box and (possibly) continue | |
10e5b930 DW |
268 | void wxError( |
269 | const wxString& rMsg | |
270 | , const wxString& rTitle | |
271 | ) | |
272 | { | |
13a4ea8d | 273 | wxBuffer = new wxChar[256]; |
10e5b930 DW |
274 | wxSprintf(wxBuffer, "%s\nContinue?", WXSTRINGCAST rMsg); |
275 | if (::WinMessageBox( HWND_DESKTOP | |
276 | ,NULL | |
277 | ,(PSZ)wxBuffer | |
278 | ,(PSZ)WXSTRINGCAST rTitle | |
279 | ,0 | |
280 | ,MB_ICONEXCLAMATION | MB_YESNO | |
281 | ) == MBID_YES) | |
13a4ea8d | 282 | delete[] wxBuffer; |
0e320a79 DW |
283 | wxExit(); |
284 | } | |
285 | ||
286 | // Fatal error: pop up message box and abort | |
10e5b930 DW |
287 | void wxFatalError( |
288 | const wxString& rMsg | |
289 | , const wxString& rTitle | |
290 | ) | |
291 | { | |
292 | unsigned long ulRc; | |
293 | ||
294 | ulRc = ::WinMessageBox( HWND_DESKTOP | |
295 | ,NULL | |
296 | ,WXSTRINGCAST rMsg | |
297 | ,WXSTRINGCAST rTitle | |
298 | ,0 | |
299 | ,MB_NOICON | MB_OK | |
300 | ); | |
301 | DosExit(EXIT_PROCESS, ulRc); | |
0e320a79 DW |
302 | } |
303 | ||
304 | // Emit a beeeeeep | |
305 | void wxBell() | |
306 | { | |
45fcbf3b | 307 | DosBeep(1000,1000); // 1kHz during 1 sec. |
0e320a79 DW |
308 | } |
309 | ||
45fcbf3b DW |
310 | // Chris Breeze 27/5/98: revised WIN32 code to |
311 | // detect WindowsNT correctly | |
10e5b930 DW |
312 | int wxGetOsVersion( |
313 | int* pMajorVsn | |
314 | , int* pMinorVsn | |
315 | ) | |
316 | { | |
317 | ULONG ulSysInfo[QSV_MAX] = {0}; | |
5d4b632b DW |
318 | APIRET ulrc; |
319 | ||
320 | ulrc = ::DosQuerySysInfo( 1L | |
321 | ,QSV_MAX | |
322 | ,(PVOID)ulSysInfo | |
323 | ,sizeof(ULONG) * QSV_MAX | |
324 | ); | |
325 | if (ulrc == 0L) | |
10e5b930 DW |
326 | { |
327 | *pMajorVsn = ulSysInfo[QSV_VERSION_MAJOR]; | |
5d4b632b | 328 | *pMajorVsn = *pMajorVsn/10; |
10e5b930 DW |
329 | *pMinorVsn = ulSysInfo[QSV_VERSION_MINOR]; |
330 | return wxWINDOWS_OS2; | |
331 | } | |
332 | return wxWINDOWS; // error if we get here, return generic value | |
0e320a79 DW |
333 | } |
334 | ||
335 | // Reading and writing resources (eg WIN.INI, .Xdefaults) | |
336 | #if wxUSE_RESOURCES | |
10e5b930 DW |
337 | bool wxWriteResource( |
338 | const wxString& rSection | |
339 | , const wxString& rEntry | |
340 | , const wxString& rValue | |
341 | , const wxString& rFile | |
342 | ) | |
0e320a79 | 343 | { |
9dea36ef DW |
344 | HAB hab = 0; |
345 | HINI hIni = 0; | |
78d50441 | 346 | |
10e5b930 | 347 | if (rFile != "") |
78d50441 | 348 | { |
10e5b930 | 349 | hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile); |
78d50441 DW |
350 | if (hIni != 0L) |
351 | { | |
352 | return (::PrfWriteProfileString( hIni | |
10e5b930 DW |
353 | ,(PSZ)WXSTRINGCAST rSection |
354 | ,(PSZ)WXSTRINGCAST rEntry | |
355 | ,(PSZ)WXSTRINGCAST rValue | |
78d50441 DW |
356 | )); |
357 | } | |
358 | } | |
359 | else | |
360 | return (::PrfWriteProfileString( HINI_PROFILE | |
10e5b930 DW |
361 | ,(PSZ)WXSTRINGCAST rSection |
362 | ,(PSZ)WXSTRINGCAST rEntry | |
363 | ,(PSZ)WXSTRINGCAST rValue | |
78d50441 | 364 | )); |
d90895ac | 365 | return FALSE; |
0e320a79 DW |
366 | } |
367 | ||
10e5b930 DW |
368 | bool wxWriteResource( |
369 | const wxString& rSection | |
370 | , const wxString& rEntry | |
371 | , float fValue | |
372 | , const wxString& rFile | |
373 | ) | |
374 | { | |
375 | wxChar zBuf[50]; | |
376 | ||
377 | wxSprintf(zBuf, "%.4f", fValue); | |
378 | return wxWriteResource( rSection | |
379 | ,rEntry | |
380 | ,zBuf | |
381 | ,rFile | |
382 | ); | |
0e320a79 DW |
383 | } |
384 | ||
1be7f92a DW |
385 | bool wxWriteResource( |
386 | const wxString& rSection | |
387 | , const wxString& rEntry | |
388 | , long lValue | |
389 | , const wxString& rFile | |
390 | ) | |
0e320a79 | 391 | { |
1be7f92a DW |
392 | wxChar zBuf[50]; |
393 | ||
394 | wxSprintf(zBuf, "%ld", lValue); | |
395 | return wxWriteResource( rSection | |
396 | ,rEntry | |
397 | ,zBuf | |
398 | ,rFile | |
399 | ); | |
0e320a79 DW |
400 | } |
401 | ||
1be7f92a DW |
402 | bool wxWriteResource( |
403 | const wxString& rSection | |
404 | , const wxString& rEntry | |
405 | , int lValue | |
406 | , const wxString& rFile | |
407 | ) | |
0e320a79 | 408 | { |
1be7f92a DW |
409 | wxChar zBuf[50]; |
410 | ||
411 | wxSprintf(zBuf, "%d", lValue); | |
412 | return wxWriteResource( rSection | |
413 | ,rEntry | |
414 | ,zBuf | |
415 | ,rFile | |
416 | ); | |
0e320a79 DW |
417 | } |
418 | ||
1be7f92a DW |
419 | bool wxGetResource( |
420 | const wxString& rSection | |
421 | , const wxString& rEntry | |
422 | , wxChar** ppValue | |
423 | , const wxString& rFile | |
424 | ) | |
0e320a79 | 425 | { |
9dea36ef DW |
426 | HAB hab = 0; |
427 | HINI hIni = 0; | |
e8fd750b DW |
428 | wxChar zDefunkt[] = _T("$$default"); |
429 | char zBuf[1000]; | |
78d50441 | 430 | |
1be7f92a | 431 | if (rFile != "") |
78d50441 | 432 | { |
1be7f92a | 433 | hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile); |
78d50441 DW |
434 | if (hIni != 0L) |
435 | { | |
436 | ULONG n = ::PrfQueryProfileString( hIni | |
1be7f92a DW |
437 | ,(PSZ)WXSTRINGCAST rSection |
438 | ,(PSZ)WXSTRINGCAST rEntry | |
439 | ,(PSZ)zDefunkt | |
e8fd750b | 440 | ,(PVOID)zBuf |
78d50441 DW |
441 | ,1000 |
442 | ); | |
e8fd750b | 443 | if (zBuf == NULL) |
78d50441 | 444 | return FALSE; |
e8fd750b DW |
445 | if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0) |
446 | return FALSE; | |
447 | zBuf[n-1] = '\0'; | |
78d50441 DW |
448 | } |
449 | else | |
450 | return FALSE; | |
451 | } | |
452 | else | |
453 | { | |
454 | ULONG n = ::PrfQueryProfileString( HINI_PROFILE | |
1be7f92a DW |
455 | ,(PSZ)WXSTRINGCAST rSection |
456 | ,(PSZ)WXSTRINGCAST rEntry | |
457 | ,(PSZ)zDefunkt | |
e8fd750b | 458 | ,(PVOID)zBuf |
78d50441 DW |
459 | ,1000 |
460 | ); | |
e8fd750b DW |
461 | if (zBuf == NULL) |
462 | return FALSE; | |
463 | if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0) | |
78d50441 | 464 | return FALSE; |
e8fd750b | 465 | zBuf[n-1] = '\0'; |
78d50441 | 466 | } |
e8fd750b | 467 | strcpy((char*)*ppValue, zBuf); |
78d50441 | 468 | return TRUE; |
d90895ac | 469 | } |
0e320a79 | 470 | |
1be7f92a DW |
471 | bool wxGetResource( |
472 | const wxString& rSection | |
473 | , const wxString& rEntry | |
474 | , float* pValue | |
475 | , const wxString& rFile | |
476 | ) | |
0e320a79 | 477 | { |
1be7f92a | 478 | wxChar* zStr = NULL; |
13a4ea8d DW |
479 | |
480 | zStr = new wxChar[1000]; | |
1be7f92a DW |
481 | bool bSucc = wxGetResource( rSection |
482 | ,rEntry | |
483 | ,(wxChar **)&zStr | |
484 | ,rFile | |
485 | ); | |
486 | ||
487 | if (bSucc) | |
488 | { | |
489 | *pValue = (float)wxStrtod(zStr, NULL); | |
490 | delete[] zStr; | |
491 | return TRUE; | |
492 | } | |
13a4ea8d DW |
493 | else |
494 | { | |
495 | delete[] zStr; | |
496 | return FALSE; | |
497 | } | |
0e320a79 DW |
498 | } |
499 | ||
1be7f92a DW |
500 | bool wxGetResource( |
501 | const wxString& rSection | |
502 | , const wxString& rEntry | |
503 | , long* pValue | |
504 | , const wxString& rFile | |
505 | ) | |
0e320a79 | 506 | { |
1be7f92a | 507 | wxChar* zStr = NULL; |
13a4ea8d DW |
508 | |
509 | zStr = new wxChar[1000]; | |
1be7f92a DW |
510 | bool bSucc = wxGetResource( rSection |
511 | ,rEntry | |
512 | ,(wxChar **)&zStr | |
513 | ,rFile | |
514 | ); | |
515 | ||
516 | if (bSucc) | |
517 | { | |
518 | *pValue = wxStrtol(zStr, NULL, 10); | |
519 | delete[] zStr; | |
520 | return TRUE; | |
521 | } | |
13a4ea8d DW |
522 | else |
523 | { | |
524 | delete[] zStr; | |
525 | return FALSE; | |
526 | } | |
0e320a79 DW |
527 | } |
528 | ||
1be7f92a DW |
529 | bool wxGetResource( |
530 | const wxString& rSection | |
531 | , const wxString& rEntry | |
532 | , int* pValue | |
533 | , const wxString& rFile | |
534 | ) | |
0e320a79 | 535 | { |
1be7f92a | 536 | wxChar* zStr = NULL; |
13a4ea8d DW |
537 | |
538 | zStr = new wxChar[1000]; | |
1be7f92a DW |
539 | bool bSucc = wxGetResource( rSection |
540 | ,rEntry | |
541 | ,(wxChar **)&zStr | |
542 | ,rFile | |
543 | ); | |
544 | ||
545 | if (bSucc) | |
546 | { | |
547 | *pValue = (int)wxStrtol(zStr, NULL, 10); | |
548 | delete[] zStr; | |
549 | return TRUE; | |
550 | } | |
13a4ea8d DW |
551 | else |
552 | { | |
553 | delete[] zStr; | |
554 | return FALSE; | |
555 | } | |
0e320a79 DW |
556 | } |
557 | #endif // wxUSE_RESOURCES | |
558 | ||
45fcbf3b DW |
559 | // --------------------------------------------------------------------------- |
560 | // helper functions for showing a "busy" cursor | |
561 | // --------------------------------------------------------------------------- | |
562 | ||
563 | HCURSOR gs_wxBusyCursor = 0; // new, busy cursor | |
564 | HCURSOR gs_wxBusyCursorOld = 0; // old cursor | |
565 | static int gs_wxBusyCursorCount = 0; | |
0e320a79 DW |
566 | |
567 | // Set the cursor to the busy cursor for all windows | |
1be7f92a DW |
568 | void wxBeginBusyCursor( |
569 | wxCursor* pCursor | |
570 | ) | |
0e320a79 | 571 | { |
45fcbf3b DW |
572 | if ( gs_wxBusyCursorCount++ == 0 ) |
573 | { | |
1be7f92a | 574 | gs_wxBusyCursor = (HCURSOR)pCursor->GetHCURSOR(); |
45fcbf3b DW |
575 | ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursor); |
576 | } | |
577 | //else: nothing to do, already set | |
0e320a79 DW |
578 | } |
579 | ||
580 | // Restore cursor to normal | |
581 | void wxEndBusyCursor() | |
582 | { | |
1be7f92a DW |
583 | wxCHECK_RET( gs_wxBusyCursorCount > 0 |
584 | ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()") | |
585 | ); | |
45fcbf3b | 586 | |
1be7f92a | 587 | if (--gs_wxBusyCursorCount == 0) |
45fcbf3b DW |
588 | { |
589 | ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursorOld); | |
590 | gs_wxBusyCursorOld = 0; | |
591 | } | |
0e320a79 DW |
592 | } |
593 | ||
594 | // TRUE if we're between the above two calls | |
595 | bool wxIsBusy() | |
596 | { | |
1be7f92a | 597 | return (gs_wxBusyCursorCount > 0); |
45fcbf3b DW |
598 | } |
599 | ||
600 | // --------------------------------------------------------------------------- | |
1be7f92a DW |
601 | const wxChar* wxGetHomeDir( |
602 | wxString* pStr | |
603 | ) | |
45fcbf3b | 604 | { |
1be7f92a | 605 | wxString& rStrDir = *pStr; |
0e320a79 | 606 | |
1be7f92a DW |
607 | // OS/2 has no idea about home, |
608 | // so use the working directory instead? | |
45fcbf3b | 609 | |
1be7f92a | 610 | // 256 was taken from os2def.h |
45fcbf3b DW |
611 | #ifndef MAX_PATH |
612 | # define MAX_PATH 256 | |
613 | #endif | |
614 | ||
1be7f92a DW |
615 | char zDirName[256]; |
616 | ULONG ulDirLen; | |
45fcbf3b | 617 | |
1be7f92a DW |
618 | ::DosQueryCurrentDir(0, zDirName, &ulDirLen); |
619 | rStrDir = zDirName; | |
620 | return rStrDir.c_str(); | |
45fcbf3b DW |
621 | } |
622 | ||
10e5b930 | 623 | // Hack for OS/2 |
1be7f92a DW |
624 | wxChar* wxGetUserHome ( |
625 | const wxString& rUser | |
626 | ) | |
627 | { | |
628 | wxChar* zHome; | |
629 | wxString sUser1(rUser); | |
630 | ||
13a4ea8d | 631 | wxBuffer = new wxChar[256]; |
06298235 | 632 | #ifndef __EMX__ |
1be7f92a | 633 | if (sUser1 != _T("")) |
45fcbf3b | 634 | { |
1be7f92a DW |
635 | wxChar zTmp[64]; |
636 | ||
637 | if (wxGetUserId( zTmp | |
638 | ,sizeof(zTmp)/sizeof(char) | |
639 | )) | |
640 | { | |
641 | // Guests belong in the temp dir | |
642 | if (wxStricmp(zTmp, _T("annonymous")) == 0) | |
643 | { | |
644 | if ((zHome = wxGetenv(_T("TMP"))) != NULL || | |
645 | (zHome = wxGetenv(_T("TMPDIR"))) != NULL || | |
646 | (zHome = wxGetenv(_T("TEMP"))) != NULL) | |
13a4ea8d | 647 | delete[] wxBuffer; |
1be7f92a DW |
648 | return *zHome ? zHome : (wxChar*)_T("\\"); |
649 | } | |
650 | if (wxStricmp(zTmp, WXSTRINGCAST sUser1) == 0) | |
651 | sUser1 = _T(""); | |
652 | } | |
45fcbf3b | 653 | } |
06298235 | 654 | #endif |
1be7f92a | 655 | if (sUser1 == _T("")) |
13a4ea8d | 656 | { |
1be7f92a DW |
657 | if ((zHome = wxGetenv(_T("HOME"))) != NULL) |
658 | { | |
659 | wxStrcpy(wxBuffer, zHome); | |
660 | Unix2DosFilename(wxBuffer); | |
13a4ea8d DW |
661 | wxStrcpy(zHome, wxBuffer); |
662 | delete[] wxBuffer; | |
663 | return zHome; | |
1be7f92a | 664 | } |
13a4ea8d DW |
665 | } |
666 | delete[] wxBuffer; | |
667 | return NULL; // No home known! | |
0e320a79 DW |
668 | } |
669 | ||
670 | // Check whether this window wants to process messages, e.g. Stop button | |
671 | // in long calculations. | |
1be7f92a DW |
672 | bool wxCheckForInterrupt( |
673 | wxWindow* pWnd | |
674 | ) | |
0e320a79 | 675 | { |
1be7f92a DW |
676 | if(pWnd) |
677 | { | |
678 | QMSG vMsg; | |
9dea36ef DW |
679 | HAB hab = 0; |
680 | HWND hwndFilter = NULLHANDLE; | |
1be7f92a | 681 | HWND hwndWin= (HWND) pWnd->GetHWND(); |
45fcbf3b | 682 | |
1be7f92a DW |
683 | while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE)) |
684 | { | |
685 | ::WinDispatchMsg(hab, &vMsg); | |
686 | } | |
687 | return TRUE;//*** temporary? | |
688 | } | |
689 | else | |
45fcbf3b | 690 | { |
1be7f92a DW |
691 | wxFAIL_MSG(_T("pWnd==NULL !!!")); |
692 | return FALSE;//*** temporary? | |
45fcbf3b | 693 | } |
45fcbf3b DW |
694 | } |
695 | ||
1be7f92a DW |
696 | void wxGetMousePosition( |
697 | int* pX | |
698 | , int* pY | |
699 | ) | |
0e320a79 | 700 | { |
1be7f92a DW |
701 | POINTL vPt; |
702 | ||
703 | ::WinQueryPointerPos(HWND_DESKTOP, &vPt); | |
704 | *pX = vPt.x; | |
705 | *pY = vPt.y; | |
0e320a79 DW |
706 | }; |
707 | ||
708 | // Return TRUE if we have a colour display | |
709 | bool wxColourDisplay() | |
710 | { | |
1be7f92a DW |
711 | HPS hpsScreen; |
712 | HDC hdcScreen; | |
713 | LONG lColors; | |
714 | ||
715 | hpsScreen = ::WinGetScreenPS(HWND_DESKTOP); | |
716 | hdcScreen = ::GpiQueryDevice(hpsScreen); | |
717 | ::DevQueryCaps(hdcScreen, CAPS_COLORS, 1L, &lColors); | |
718 | return(lColors > 1L); | |
0e320a79 DW |
719 | } |
720 | ||
721 | // Returns depth of screen | |
722 | int wxDisplayDepth() | |
723 | { | |
1be7f92a DW |
724 | HPS hpsScreen; |
725 | HDC hdcScreen; | |
726 | LONG lPlanes; | |
727 | LONG lBitsPerPixel; | |
728 | LONG nDepth; | |
729 | ||
730 | hpsScreen = ::WinGetScreenPS(HWND_DESKTOP); | |
731 | hdcScreen = ::GpiQueryDevice(hpsScreen); | |
732 | ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes); | |
733 | ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel); | |
734 | ||
735 | nDepth = (int)(lPlanes * lBitsPerPixel); | |
736 | DevCloseDC(hdcScreen); | |
d90895ac | 737 | return (nDepth); |
0e320a79 DW |
738 | } |
739 | ||
740 | // Get size of display | |
1be7f92a DW |
741 | void wxDisplaySize( |
742 | int* pWidth | |
743 | , int* pHeight | |
744 | ) | |
0e320a79 | 745 | { |
1be7f92a DW |
746 | HPS hpsScreen; |
747 | HDC hdcScreen; | |
892b89f3 DW |
748 | LONG lWidth; |
749 | LONG lHeight; | |
45fcbf3b | 750 | |
1be7f92a DW |
751 | hpsScreen = ::WinGetScreenPS(HWND_DESKTOP); |
752 | hdcScreen = ::GpiQueryDevice(hpsScreen); | |
892b89f3 DW |
753 | ::DevQueryCaps(hdcScreen, CAPS_WIDTH, 1L, &lWidth); |
754 | ::DevQueryCaps(hdcScreen, CAPS_HEIGHT, 1L, &lHeight); | |
1be7f92a | 755 | DevCloseDC(hdcScreen); |
892b89f3 DW |
756 | *pWidth = (int)lWidth; |
757 | *pHeight = (int)lHeight; | |
45fcbf3b DW |
758 | } |
759 | ||
1be7f92a DW |
760 | bool wxDirExists( |
761 | const wxString& rDir | |
762 | ) | |
45fcbf3b | 763 | { |
1be7f92a | 764 | return (::DosSetCurrentDir(WXSTRINGCAST rDir)); |
45fcbf3b DW |
765 | } |
766 | ||
767 | // --------------------------------------------------------------------------- | |
768 | // window information functions | |
769 | // --------------------------------------------------------------------------- | |
770 | ||
1be7f92a DW |
771 | wxString WXDLLEXPORT wxGetWindowText( |
772 | WXHWND hWnd | |
773 | ) | |
45fcbf3b | 774 | { |
1be7f92a DW |
775 | wxString vStr; |
776 | long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1; | |
777 | ||
778 | ::WinQueryWindowText((HWND)hWnd, lLen, vStr.GetWriteBuf((int)lLen)); | |
779 | vStr.UngetWriteBuf(); | |
45fcbf3b | 780 | |
1be7f92a | 781 | return vStr; |
45fcbf3b DW |
782 | } |
783 | ||
1be7f92a DW |
784 | wxString WXDLLEXPORT wxGetWindowClass( |
785 | WXHWND hWnd | |
786 | ) | |
45fcbf3b | 787 | { |
1be7f92a DW |
788 | wxString vStr; |
789 | int nLen = 256; // some starting value | |
45fcbf3b DW |
790 | |
791 | for ( ;; ) | |
792 | { | |
1be7f92a | 793 | int nCount = ::WinQueryClassName((HWND)hWnd, nLen, vStr.GetWriteBuf(nLen)); |
45fcbf3b | 794 | |
1be7f92a DW |
795 | vStr.UngetWriteBuf(); |
796 | if (nCount == nLen ) | |
45fcbf3b DW |
797 | { |
798 | // the class name might have been truncated, retry with larger | |
799 | // buffer | |
1be7f92a | 800 | nLen *= 2; |
45fcbf3b DW |
801 | } |
802 | else | |
803 | { | |
804 | break; | |
805 | } | |
806 | } | |
1be7f92a | 807 | return vStr; |
45fcbf3b DW |
808 | } |
809 | ||
1be7f92a DW |
810 | WXWORD WXDLLEXPORT wxGetWindowId( |
811 | WXHWND hWnd | |
812 | ) | |
45fcbf3b DW |
813 | { |
814 | return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID); | |
0e320a79 DW |
815 | } |
816 | ||
914589c2 DW |
817 | wxString WXDLLEXPORT wxPMErrorToStr( |
818 | ERRORID vError | |
819 | ) | |
820 | { | |
821 | wxString sError; | |
822 | ||
823 | // | |
824 | // Remove the high order byte -- it is useless | |
825 | // | |
826 | vError &= 0x0000ffff; | |
827 | switch(vError) | |
828 | { | |
829 | case PMERR_INVALID_HWND: | |
830 | sError = wxT("Invalid window handle specified"); | |
831 | break; | |
832 | ||
833 | case PMERR_INVALID_FLAG: | |
834 | sError = wxT("Invalid flag bit set"); | |
835 | break; | |
836 | ||
837 | case PMERR_NO_MSG_QUEUE: | |
838 | sError = wxT("No message queue available"); | |
839 | break; | |
840 | ||
841 | case PMERR_INVALID_PARM: | |
842 | sError = wxT("Parameter contained invalid data"); | |
843 | break; | |
844 | ||
845 | case PMERR_INVALID_PARAMETERS: | |
846 | sError = wxT("Parameter value is out of range"); | |
847 | break; | |
848 | ||
849 | case PMERR_PARAMETER_OUT_OF_RANGE: | |
850 | sError = wxT("Parameter value is out of range"); | |
851 | break; | |
852 | ||
853 | case PMERR_INVALID_INTEGER_ATOM: | |
854 | sError = wxT("Not a valid atom"); | |
855 | break; | |
856 | ||
857 | case PMERR_INVALID_HATOMTBL: | |
858 | sError = wxT("Atom table handle is invalid"); | |
859 | break; | |
860 | ||
861 | case PMERR_INVALID_ATOM_NAME: | |
862 | sError = wxT("Not a valid atom name"); | |
863 | break; | |
864 | ||
865 | case PMERR_ATOM_NAME_NOT_FOUND: | |
866 | sError = wxT("Valid name format, but cannot find name in atom table"); | |
867 | break; | |
868 | ||
869 | default: | |
870 | sError = wxT("Unknown error"); | |
871 | } | |
872 | return(sError); | |
873 | } // end of wxPMErrorToStr | |
874 | ||
875 |