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