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