]> git.saurik.com Git - wxWidgets.git/blame - src/os2/utils.cpp
fix for last commit
[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>
06298235 29#endif
45fcbf3b
DW
30
31#include "wx/log.h"
32
33#include <io.h>
0e320a79
DW
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
45fcbf3b 38#include <errno.h>
0e320a79
DW
39#include <stdarg.h>
40
d90895ac 41#define PURE_32
468e327a 42
06298235 43#ifndef __EMX__
7cdc2f1e
DW
44#include <upm.h>
45#include <netcons.h>
46#include <netbios.h>
06298235 47#endif
45fcbf3b 48
86de7616
DW
49static const wxChar WX_SECTION[] = _T("wxWindows");
50static const wxChar eHOSTNAME[] = _T("HostName");
51static const wxChar eUSERID[] = _T("UserId");
52static const wxChar eUSERNAME[] = _T("UserName");
45fcbf3b
DW
53
54// For the following functions we SHOULD fill in support
55// for Windows-NT (which I don't know) as I assume it begin
56// a POSIX Unix (so claims MS) that it has some special
57// functions beyond those provided by WinSock
58
0e320a79 59// Get full hostname (eg. DoDo.BSn-Germany.crg.de)
10e5b930
DW
60bool wxGetHostName(
61 wxChar* zBuf
62, int nMaxSize
63)
0e320a79 64{
d90895ac 65#if wxUSE_NET_API
10e5b930
DW
66 char zServer[256];
67 char zComputer[256];
909b4f08 68 unsigned long ulLevel = 0;
9dea36ef
DW
69 unsigned char* zBuffer = NULL;
70 unsigned long ulBuffer = 256;
71 unsigned long* pulTotalAvail = NULL;
10e5b930 72
dde11e60
DW
73 NetBios32GetInfo( (const unsigned char*)zServer
74 ,(const unsigned char*)zComputer
909b4f08 75 ,ulLevel
dde11e60 76 ,zBuffer
909b4f08
DW
77 ,ulBuffer
78 ,pulTotalAvail
dde11e60 79 );
10e5b930 80 strcpy(zBuf, zServer);
45fcbf3b 81#else
10e5b930
DW
82 wxChar* zSysname;
83 const wxChar* zDefaultHost = _T("noname");
45fcbf3b 84
10e5b930
DW
85 if ((zSysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL)
86 {
87 ULONG n = ::PrfQueryProfileString( HINI_PROFILE
88 ,(PSZ)WX_SECTION
89 ,(PSZ)eHOSTNAME
90 ,(PSZ)zDefaultHost
91 ,(void*)zBuf
92 ,(ULONG)nMaxSize - 1
93 );
94 }
95 else
96 wxStrncpy(zBuf, zSysname, nMaxSize - 1);
97 zBuf[nMaxSize] = _T('\0');
45fcbf3b 98#endif
10e5b930 99 return *zBuf ? TRUE : FALSE;
0e320a79
DW
100}
101
102// Get user ID e.g. jacs
10e5b930
DW
103bool wxGetUserId(
104 wxChar* zBuf
2bd5bbc9 105, int nType
10e5b930 106)
0e320a79 107{
06298235 108#ifndef __EMX__
2bd5bbc9
DW
109 long lrc;
110 // UPM procs return 0 on success
111 lrc = U32ELOCU((unsigned char*)zBuf, (unsigned long *)&nType);
112 if (lrc == 0) return TRUE;
06298235 113#endif
2bd5bbc9 114 return FALSE;
0e320a79
DW
115}
116
10e5b930
DW
117bool wxGetUserName(
118 wxChar* zBuf
119, int nMaxSize
120)
0e320a79 121{
45fcbf3b 122#ifdef USE_NET_API
10e5b930
DW
123 wxGetUserId( zBuf
124 ,nMaxSize
125 );
45fcbf3b 126#else
10e5b930 127 wxStrncpy(zBuf, _T("Unknown User"), nMaxSize);
45fcbf3b 128#endif
10e5b930 129 return TRUE;
0e320a79
DW
130}
131
10e5b930
DW
132int wxKill(
133 long lPid
134, int nSig
135)
0e320a79 136{
10e5b930 137 return((int)::DosKillProcess(0, (PID)lPid));
0e320a79
DW
138}
139
140//
141// Execute a program in an Interactive Shell
142//
10e5b930
DW
143bool wxShell(
144 const wxString& rCommand
145)
0e320a79 146{
c5fb56c0
DW
147 wxChar* zShell = _T("CMD.EXE");
148 wxString sInputs;
10e5b930 149 wxChar zTmp[255];
c5fb56c0
DW
150 STARTDATA SData = {0};
151 PSZ PgmTitle = "Command Shell";
152 APIRET rc;
153 PID vPid = 0;
154 ULONG ulSessID = 0;
155 UCHAR achObjBuf[256] = {0}; //error data if DosStart fails
156 RESULTCODES vResult;
157
158 SData.Length = sizeof(STARTDATA);
159 SData.Related = SSF_RELATED_INDEPENDENT;
160 SData.FgBg = SSF_FGBG_FORE;
161 SData.TraceOpt = SSF_TRACEOPT_NONE;
162 SData.PgmTitle = PgmTitle;
163 SData.PgmName = zShell;
164
909b4f08 165 sInputs = "/C " + rCommand;
9ac6ff7b 166 SData.PgmInputs = (BYTE*)sInputs.c_str();
c5fb56c0
DW
167 SData.TermQ = 0;
168 SData.Environment = 0;
169 SData.InheritOpt = SSF_INHERTOPT_SHELL;
170 SData.SessionType = SSF_TYPE_WINDOWABLEVIO;
171 SData.IconFile = 0;
172 SData.PgmHandle = 0;
173 SData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE;
174 SData.InitXPos = 30;
175 SData.InitYPos = 40;
176 SData.InitXSize = 200;
177 SData.InitYSize = 140;
178 SData.Reserved = 0;
179 SData.ObjectBuffer = (char*)achObjBuf;
180 SData.ObjectBuffLen = (ULONG)sizeof(achObjBuf);
181
182 rc = ::DosStartSession(&SData, &ulSessID, &vPid);
9ac6ff7b 183 if (rc == 0 || rc == 457) // NO_ERROR or SMG_START_IN_BACKGROUND
c5fb56c0
DW
184 {
185 PTIB ptib;
186 PPIB ppib;
10e5b930 187
c5fb56c0 188 ::DosGetInfoBlocks(&ptib, &ppib);
10e5b930 189
c5fb56c0
DW
190 ::DosWaitChild( DCWA_PROCESS
191 ,DCWW_WAIT
192 ,&vResult
193 ,&ppib->pib_ulpid
194 ,vPid
195 );
196 }
197 return (rc != 0);
0e320a79
DW
198}
199
200// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
5d4b632b 201long wxGetFreeMemory()
0e320a79 202{
9dea36ef 203 void* pMemptr = NULL;
78d50441
DW
204 ULONG lSize;
205 ULONG lMemFlags;
206 APIRET rc;
207
208 lMemFlags = PAG_FREE;
10e5b930 209 rc = ::DosQueryMem(pMemptr, &lSize, &lMemFlags);
78d50441
DW
210 if (rc != 0)
211 return -1L;
212 return (long)lSize;
45fcbf3b
DW
213}
214
8269a903
SN
215// ----------------------------------------------------------------------------
216// env vars
217// ----------------------------------------------------------------------------
218
219bool wxGetEnv(const wxString& var, wxString *value)
220{
221 // wxGetenv is defined as getenv()
222 wxChar *p = wxGetenv(var);
223 if ( !p )
224 return FALSE;
225
226 if ( value )
227 {
228 *value = p;
229 }
230
231 return TRUE;
232}
233
234bool wxSetEnv(const wxString& variable, const wxChar *value)
235{
236#if defined(HAVE_SETENV)
237 return setenv(variable.mb_str(), value ? wxString(value).mb_str().data()
238 : NULL, 1 /* overwrite */) == 0;
239#elif defined(HAVE_PUTENV)
240 wxString s = variable;
241 if ( value )
242 s << _T('=') << value;
243
244 // transform to ANSI
245 const char *p = s.mb_str();
246
247 // the string will be free()d by libc
248 char *buf = (char *)malloc(strlen(p) + 1);
249 strcpy(buf, p);
250
251 return putenv(buf) == 0;
252#else // no way to set an env var
253 return FALSE;
254#endif
255}
256
257
45fcbf3b
DW
258// Sleep for nSecs seconds. Attempt a Windows implementation using timers.
259static bool inTimer = FALSE;
260
261class wxSleepTimer: public wxTimer
262{
10e5b930
DW
263public:
264 inline void Notify()
265 {
266 inTimer = FALSE;
267 Stop();
268 }
45fcbf3b
DW
269};
270
10e5b930 271static wxTimer* wxTheSleepTimer = NULL;
45fcbf3b 272
10e5b930
DW
273void wxUsleep(
274 unsigned long ulMilliseconds
275)
45fcbf3b 276{
468e327a 277 ::DosSleep(ulMilliseconds/1000l);
0e320a79
DW
278}
279
10e5b930
DW
280void wxSleep(
281 int nSecs
282)
0e320a79 283{
10e5b930 284 ::DosSleep(1000 * nSecs);
0e320a79
DW
285}
286
287// Consume all events until no more left
288void wxFlushEvents()
289{
45fcbf3b 290// wxYield();
0e320a79
DW
291}
292
45fcbf3b 293// Output a debug mess., in a system dependent fashion.
10e5b930
DW
294void wxDebugMsg(
295 const wxChar* zFmt ...
296)
297{
298 va_list vAp;
299 static wxChar zBuffer[512];
300
301 if (!wxTheApp->GetWantDebugOutput())
302 return ;
303 va_start(vAp, zFmt);
304 sprintf(zBuffer, zFmt, vAp) ;
305 va_end(vAp);
0e320a79
DW
306}
307
308// Non-fatal error: pop up message box and (possibly) continue
10e5b930
DW
309void wxError(
310 const wxString& rMsg
311, const wxString& rTitle
312)
313{
13a4ea8d 314 wxBuffer = new wxChar[256];
10e5b930
DW
315 wxSprintf(wxBuffer, "%s\nContinue?", WXSTRINGCAST rMsg);
316 if (::WinMessageBox( HWND_DESKTOP
317 ,NULL
318 ,(PSZ)wxBuffer
319 ,(PSZ)WXSTRINGCAST rTitle
320 ,0
321 ,MB_ICONEXCLAMATION | MB_YESNO
322 ) == MBID_YES)
13a4ea8d 323 delete[] wxBuffer;
0e320a79
DW
324 wxExit();
325}
326
327// Fatal error: pop up message box and abort
10e5b930
DW
328void wxFatalError(
329 const wxString& rMsg
330, const wxString& rTitle
331)
332{
333 unsigned long ulRc;
334
335 ulRc = ::WinMessageBox( HWND_DESKTOP
336 ,NULL
337 ,WXSTRINGCAST rMsg
338 ,WXSTRINGCAST rTitle
339 ,0
340 ,MB_NOICON | MB_OK
341 );
342 DosExit(EXIT_PROCESS, ulRc);
0e320a79
DW
343}
344
345// Emit a beeeeeep
346void wxBell()
347{
45fcbf3b 348 DosBeep(1000,1000); // 1kHz during 1 sec.
0e320a79
DW
349}
350
45fcbf3b
DW
351// Chris Breeze 27/5/98: revised WIN32 code to
352// detect WindowsNT correctly
10e5b930
DW
353int wxGetOsVersion(
354 int* pMajorVsn
355, int* pMinorVsn
356)
357{
358 ULONG ulSysInfo[QSV_MAX] = {0};
5d4b632b
DW
359 APIRET ulrc;
360
361 ulrc = ::DosQuerySysInfo( 1L
362 ,QSV_MAX
363 ,(PVOID)ulSysInfo
364 ,sizeof(ULONG) * QSV_MAX
365 );
366 if (ulrc == 0L)
10e5b930
DW
367 {
368 *pMajorVsn = ulSysInfo[QSV_VERSION_MAJOR];
5d4b632b 369 *pMajorVsn = *pMajorVsn/10;
10e5b930
DW
370 *pMinorVsn = ulSysInfo[QSV_VERSION_MINOR];
371 return wxWINDOWS_OS2;
372 }
373 return wxWINDOWS; // error if we get here, return generic value
0e320a79
DW
374}
375
376// Reading and writing resources (eg WIN.INI, .Xdefaults)
377#if wxUSE_RESOURCES
10e5b930
DW
378bool wxWriteResource(
379 const wxString& rSection
380, const wxString& rEntry
381, const wxString& rValue
382, const wxString& rFile
383)
0e320a79 384{
9dea36ef
DW
385 HAB hab = 0;
386 HINI hIni = 0;
78d50441 387
10e5b930 388 if (rFile != "")
78d50441 389 {
10e5b930 390 hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile);
78d50441
DW
391 if (hIni != 0L)
392 {
393 return (::PrfWriteProfileString( hIni
10e5b930
DW
394 ,(PSZ)WXSTRINGCAST rSection
395 ,(PSZ)WXSTRINGCAST rEntry
396 ,(PSZ)WXSTRINGCAST rValue
78d50441
DW
397 ));
398 }
399 }
400 else
401 return (::PrfWriteProfileString( HINI_PROFILE
10e5b930
DW
402 ,(PSZ)WXSTRINGCAST rSection
403 ,(PSZ)WXSTRINGCAST rEntry
404 ,(PSZ)WXSTRINGCAST rValue
78d50441 405 ));
d90895ac 406 return FALSE;
0e320a79
DW
407}
408
10e5b930
DW
409bool wxWriteResource(
410 const wxString& rSection
411, const wxString& rEntry
412, float fValue
413, const wxString& rFile
414)
415{
416 wxChar zBuf[50];
417
418 wxSprintf(zBuf, "%.4f", fValue);
419 return wxWriteResource( rSection
420 ,rEntry
421 ,zBuf
422 ,rFile
423 );
0e320a79
DW
424}
425
1be7f92a
DW
426bool wxWriteResource(
427 const wxString& rSection
428, const wxString& rEntry
429, long lValue
430, const wxString& rFile
431)
0e320a79 432{
1be7f92a
DW
433 wxChar zBuf[50];
434
435 wxSprintf(zBuf, "%ld", lValue);
436 return wxWriteResource( rSection
437 ,rEntry
438 ,zBuf
439 ,rFile
440 );
0e320a79
DW
441}
442
1be7f92a
DW
443bool wxWriteResource(
444 const wxString& rSection
445, const wxString& rEntry
446, int lValue
447, const wxString& rFile
448)
0e320a79 449{
1be7f92a
DW
450 wxChar zBuf[50];
451
452 wxSprintf(zBuf, "%d", lValue);
453 return wxWriteResource( rSection
454 ,rEntry
455 ,zBuf
456 ,rFile
457 );
0e320a79
DW
458}
459
1be7f92a
DW
460bool wxGetResource(
461 const wxString& rSection
462, const wxString& rEntry
463, wxChar** ppValue
464, const wxString& rFile
465)
0e320a79 466{
9dea36ef
DW
467 HAB hab = 0;
468 HINI hIni = 0;
e8fd750b
DW
469 wxChar zDefunkt[] = _T("$$default");
470 char zBuf[1000];
78d50441 471
1be7f92a 472 if (rFile != "")
78d50441 473 {
1be7f92a 474 hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile);
78d50441
DW
475 if (hIni != 0L)
476 {
477 ULONG n = ::PrfQueryProfileString( hIni
1be7f92a
DW
478 ,(PSZ)WXSTRINGCAST rSection
479 ,(PSZ)WXSTRINGCAST rEntry
480 ,(PSZ)zDefunkt
e8fd750b 481 ,(PVOID)zBuf
78d50441
DW
482 ,1000
483 );
e8fd750b 484 if (zBuf == NULL)
78d50441 485 return FALSE;
e8fd750b
DW
486 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
487 return FALSE;
488 zBuf[n-1] = '\0';
78d50441
DW
489 }
490 else
491 return FALSE;
492 }
493 else
494 {
495 ULONG n = ::PrfQueryProfileString( HINI_PROFILE
1be7f92a
DW
496 ,(PSZ)WXSTRINGCAST rSection
497 ,(PSZ)WXSTRINGCAST rEntry
498 ,(PSZ)zDefunkt
e8fd750b 499 ,(PVOID)zBuf
78d50441
DW
500 ,1000
501 );
e8fd750b
DW
502 if (zBuf == NULL)
503 return FALSE;
504 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
78d50441 505 return FALSE;
e8fd750b 506 zBuf[n-1] = '\0';
78d50441 507 }
e8fd750b 508 strcpy((char*)*ppValue, zBuf);
78d50441 509 return TRUE;
d90895ac 510}
0e320a79 511
1be7f92a
DW
512bool wxGetResource(
513 const wxString& rSection
514, const wxString& rEntry
515, float* pValue
516, const wxString& rFile
517)
0e320a79 518{
1be7f92a 519 wxChar* zStr = NULL;
13a4ea8d
DW
520
521 zStr = new wxChar[1000];
1be7f92a
DW
522 bool bSucc = wxGetResource( rSection
523 ,rEntry
524 ,(wxChar **)&zStr
525 ,rFile
526 );
527
528 if (bSucc)
529 {
530 *pValue = (float)wxStrtod(zStr, NULL);
531 delete[] zStr;
532 return TRUE;
533 }
13a4ea8d
DW
534 else
535 {
536 delete[] zStr;
537 return FALSE;
538 }
0e320a79
DW
539}
540
1be7f92a
DW
541bool wxGetResource(
542 const wxString& rSection
543, const wxString& rEntry
544, long* pValue
545, const wxString& rFile
546)
0e320a79 547{
1be7f92a 548 wxChar* zStr = NULL;
13a4ea8d
DW
549
550 zStr = new wxChar[1000];
1be7f92a
DW
551 bool bSucc = wxGetResource( rSection
552 ,rEntry
553 ,(wxChar **)&zStr
554 ,rFile
555 );
556
557 if (bSucc)
558 {
559 *pValue = wxStrtol(zStr, NULL, 10);
560 delete[] zStr;
561 return TRUE;
562 }
13a4ea8d
DW
563 else
564 {
565 delete[] zStr;
566 return FALSE;
567 }
0e320a79
DW
568}
569
1be7f92a
DW
570bool wxGetResource(
571 const wxString& rSection
572, const wxString& rEntry
573, int* pValue
574, const wxString& rFile
575)
0e320a79 576{
1be7f92a 577 wxChar* zStr = NULL;
13a4ea8d
DW
578
579 zStr = new wxChar[1000];
1be7f92a
DW
580 bool bSucc = wxGetResource( rSection
581 ,rEntry
582 ,(wxChar **)&zStr
583 ,rFile
584 );
585
586 if (bSucc)
587 {
588 *pValue = (int)wxStrtol(zStr, NULL, 10);
589 delete[] zStr;
590 return TRUE;
591 }
13a4ea8d
DW
592 else
593 {
594 delete[] zStr;
595 return FALSE;
596 }
0e320a79
DW
597}
598#endif // wxUSE_RESOURCES
599
45fcbf3b
DW
600// ---------------------------------------------------------------------------
601// helper functions for showing a "busy" cursor
602// ---------------------------------------------------------------------------
603
604HCURSOR gs_wxBusyCursor = 0; // new, busy cursor
605HCURSOR gs_wxBusyCursorOld = 0; // old cursor
606static int gs_wxBusyCursorCount = 0;
0e320a79
DW
607
608// Set the cursor to the busy cursor for all windows
1be7f92a
DW
609void wxBeginBusyCursor(
610 wxCursor* pCursor
611)
0e320a79 612{
45fcbf3b
DW
613 if ( gs_wxBusyCursorCount++ == 0 )
614 {
1be7f92a 615 gs_wxBusyCursor = (HCURSOR)pCursor->GetHCURSOR();
45fcbf3b
DW
616 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursor);
617 }
618 //else: nothing to do, already set
0e320a79
DW
619}
620
621// Restore cursor to normal
622void wxEndBusyCursor()
623{
1be7f92a
DW
624 wxCHECK_RET( gs_wxBusyCursorCount > 0
625 ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()")
626 );
45fcbf3b 627
1be7f92a 628 if (--gs_wxBusyCursorCount == 0)
45fcbf3b
DW
629 {
630 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursorOld);
631 gs_wxBusyCursorOld = 0;
632 }
0e320a79
DW
633}
634
635// TRUE if we're between the above two calls
636bool wxIsBusy()
637{
1be7f92a 638 return (gs_wxBusyCursorCount > 0);
45fcbf3b
DW
639}
640
641// ---------------------------------------------------------------------------
1be7f92a
DW
642const wxChar* wxGetHomeDir(
643 wxString* pStr
644)
45fcbf3b 645{
1be7f92a 646 wxString& rStrDir = *pStr;
0e320a79 647
1be7f92a
DW
648 // OS/2 has no idea about home,
649 // so use the working directory instead?
45fcbf3b 650
1be7f92a 651 // 256 was taken from os2def.h
45fcbf3b
DW
652#ifndef MAX_PATH
653# define MAX_PATH 256
654#endif
655
1be7f92a
DW
656 char zDirName[256];
657 ULONG ulDirLen;
45fcbf3b 658
1be7f92a
DW
659 ::DosQueryCurrentDir(0, zDirName, &ulDirLen);
660 rStrDir = zDirName;
661 return rStrDir.c_str();
45fcbf3b
DW
662}
663
10e5b930 664// Hack for OS/2
1be7f92a
DW
665wxChar* wxGetUserHome (
666 const wxString& rUser
667)
668{
669 wxChar* zHome;
670 wxString sUser1(rUser);
671
13a4ea8d 672 wxBuffer = new wxChar[256];
06298235 673#ifndef __EMX__
1be7f92a 674 if (sUser1 != _T(""))
45fcbf3b 675 {
1be7f92a
DW
676 wxChar zTmp[64];
677
678 if (wxGetUserId( zTmp
679 ,sizeof(zTmp)/sizeof(char)
680 ))
681 {
682 // Guests belong in the temp dir
683 if (wxStricmp(zTmp, _T("annonymous")) == 0)
684 {
685 if ((zHome = wxGetenv(_T("TMP"))) != NULL ||
686 (zHome = wxGetenv(_T("TMPDIR"))) != NULL ||
687 (zHome = wxGetenv(_T("TEMP"))) != NULL)
13a4ea8d 688 delete[] wxBuffer;
1be7f92a
DW
689 return *zHome ? zHome : (wxChar*)_T("\\");
690 }
691 if (wxStricmp(zTmp, WXSTRINGCAST sUser1) == 0)
692 sUser1 = _T("");
693 }
45fcbf3b 694 }
06298235 695#endif
1be7f92a 696 if (sUser1 == _T(""))
13a4ea8d 697 {
1be7f92a
DW
698 if ((zHome = wxGetenv(_T("HOME"))) != NULL)
699 {
700 wxStrcpy(wxBuffer, zHome);
701 Unix2DosFilename(wxBuffer);
13a4ea8d
DW
702 wxStrcpy(zHome, wxBuffer);
703 delete[] wxBuffer;
704 return zHome;
1be7f92a 705 }
13a4ea8d
DW
706 }
707 delete[] wxBuffer;
708 return NULL; // No home known!
0e320a79
DW
709}
710
711// Check whether this window wants to process messages, e.g. Stop button
712// in long calculations.
1be7f92a
DW
713bool wxCheckForInterrupt(
714 wxWindow* pWnd
715)
0e320a79 716{
1be7f92a
DW
717 if(pWnd)
718 {
719 QMSG vMsg;
9dea36ef
DW
720 HAB hab = 0;
721 HWND hwndFilter = NULLHANDLE;
1be7f92a 722 HWND hwndWin= (HWND) pWnd->GetHWND();
45fcbf3b 723
1be7f92a
DW
724 while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE))
725 {
726 ::WinDispatchMsg(hab, &vMsg);
727 }
728 return TRUE;//*** temporary?
729 }
730 else
45fcbf3b 731 {
1be7f92a
DW
732 wxFAIL_MSG(_T("pWnd==NULL !!!"));
733 return FALSE;//*** temporary?
45fcbf3b 734 }
45fcbf3b
DW
735}
736
1be7f92a
DW
737void wxGetMousePosition(
738 int* pX
739, int* pY
740)
0e320a79 741{
1be7f92a
DW
742 POINTL vPt;
743
744 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
745 *pX = vPt.x;
746 *pY = vPt.y;
0e320a79
DW
747};
748
749// Return TRUE if we have a colour display
750bool wxColourDisplay()
751{
1be7f92a
DW
752 HPS hpsScreen;
753 HDC hdcScreen;
754 LONG lColors;
755
756 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
757 hdcScreen = ::GpiQueryDevice(hpsScreen);
758 ::DevQueryCaps(hdcScreen, CAPS_COLORS, 1L, &lColors);
759 return(lColors > 1L);
0e320a79
DW
760}
761
762// Returns depth of screen
763int wxDisplayDepth()
764{
1be7f92a
DW
765 HPS hpsScreen;
766 HDC hdcScreen;
767 LONG lPlanes;
768 LONG lBitsPerPixel;
769 LONG nDepth;
770
771 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
772 hdcScreen = ::GpiQueryDevice(hpsScreen);
773 ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes);
774 ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel);
775
776 nDepth = (int)(lPlanes * lBitsPerPixel);
777 DevCloseDC(hdcScreen);
d90895ac 778 return (nDepth);
0e320a79
DW
779}
780
781// Get size of display
1be7f92a
DW
782void wxDisplaySize(
783 int* pWidth
784, int* pHeight
785)
0e320a79 786{
1be7f92a
DW
787 HPS hpsScreen;
788 HDC hdcScreen;
892b89f3
DW
789 LONG lWidth;
790 LONG lHeight;
45fcbf3b 791
1be7f92a
DW
792 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
793 hdcScreen = ::GpiQueryDevice(hpsScreen);
892b89f3
DW
794 ::DevQueryCaps(hdcScreen, CAPS_WIDTH, 1L, &lWidth);
795 ::DevQueryCaps(hdcScreen, CAPS_HEIGHT, 1L, &lHeight);
1be7f92a 796 DevCloseDC(hdcScreen);
892b89f3
DW
797 *pWidth = (int)lWidth;
798 *pHeight = (int)lHeight;
45fcbf3b
DW
799}
800
5b3ed311
DW
801void wxDisplaySizeMM(
802 int* pWidth
803, int* pHeight
804)
805{
806 HPS hpsScreen;
807 HDC hdcScreen;
808
809 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
810 hdcScreen = ::GpiQueryDevice(hpsScreen);
811
812 if (pWidth)
813 ::DevQueryCaps( hdcScreen
814 ,CAPS_HORIZONTAL_RESOLUTION
815 ,1L
816 ,(PLONG)pWidth
817 );
818 if (pHeight)
819 ::DevQueryCaps( hdcScreen
820 ,CAPS_VERTICAL_RESOLUTION
821 ,1L
822 ,(PLONG)pHeight
823 );
824}
825
ec5d7799
RD
826void wxClientDisplayRect(int *x, int *y, int *width, int *height)
827{
828 // This is supposed to return desktop dimensions minus any window
829 // manager panels, menus, taskbars, etc. If there is a way to do that
830 // for this platform please fix this function, otherwise it defaults
831 // to the entire desktop.
832 if (x) *x = 0;
833 if (y) *y = 0;
834 wxDisplaySize(width, height);
835}
836
837
1be7f92a
DW
838bool wxDirExists(
839 const wxString& rDir
840)
45fcbf3b 841{
1be7f92a 842 return (::DosSetCurrentDir(WXSTRINGCAST rDir));
45fcbf3b
DW
843}
844
845// ---------------------------------------------------------------------------
846// window information functions
847// ---------------------------------------------------------------------------
848
1be7f92a
DW
849wxString WXDLLEXPORT wxGetWindowText(
850 WXHWND hWnd
851)
45fcbf3b 852{
1be7f92a
DW
853 wxString vStr;
854 long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1;
855
856 ::WinQueryWindowText((HWND)hWnd, lLen, vStr.GetWriteBuf((int)lLen));
857 vStr.UngetWriteBuf();
45fcbf3b 858
1be7f92a 859 return vStr;
45fcbf3b
DW
860}
861
1be7f92a
DW
862wxString WXDLLEXPORT wxGetWindowClass(
863 WXHWND hWnd
864)
45fcbf3b 865{
1be7f92a
DW
866 wxString vStr;
867 int nLen = 256; // some starting value
45fcbf3b
DW
868
869 for ( ;; )
870 {
1be7f92a 871 int nCount = ::WinQueryClassName((HWND)hWnd, nLen, vStr.GetWriteBuf(nLen));
45fcbf3b 872
1be7f92a
DW
873 vStr.UngetWriteBuf();
874 if (nCount == nLen )
45fcbf3b
DW
875 {
876 // the class name might have been truncated, retry with larger
877 // buffer
1be7f92a 878 nLen *= 2;
45fcbf3b
DW
879 }
880 else
881 {
882 break;
883 }
884 }
1be7f92a 885 return vStr;
45fcbf3b
DW
886}
887
1be7f92a
DW
888WXWORD WXDLLEXPORT wxGetWindowId(
889 WXHWND hWnd
890)
45fcbf3b
DW
891{
892 return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID);
0e320a79
DW
893}
894
914589c2
DW
895wxString WXDLLEXPORT wxPMErrorToStr(
896 ERRORID vError
897)
898{
899 wxString sError;
900
901 //
902 // Remove the high order byte -- it is useless
903 //
904 vError &= 0x0000ffff;
905 switch(vError)
906 {
907 case PMERR_INVALID_HWND:
908 sError = wxT("Invalid window handle specified");
909 break;
910
911 case PMERR_INVALID_FLAG:
912 sError = wxT("Invalid flag bit set");
913 break;
914
915 case PMERR_NO_MSG_QUEUE:
916 sError = wxT("No message queue available");
917 break;
918
919 case PMERR_INVALID_PARM:
920 sError = wxT("Parameter contained invalid data");
921 break;
922
923 case PMERR_INVALID_PARAMETERS:
924 sError = wxT("Parameter value is out of range");
925 break;
926
927 case PMERR_PARAMETER_OUT_OF_RANGE:
928 sError = wxT("Parameter value is out of range");
929 break;
930
931 case PMERR_INVALID_INTEGER_ATOM:
932 sError = wxT("Not a valid atom");
933 break;
934
935 case PMERR_INVALID_HATOMTBL:
936 sError = wxT("Atom table handle is invalid");
937 break;
938
939 case PMERR_INVALID_ATOM_NAME:
940 sError = wxT("Not a valid atom name");
941 break;
942
943 case PMERR_ATOM_NAME_NOT_FOUND:
944 sError = wxT("Valid name format, but cannot find name in atom table");
945 break;
946
947 default:
948 sError = wxT("Unknown error");
949 }
950 return(sError);
951} // end of wxPMErrorToStr
952
008089f6
DW
953void wxDrawBorder(
954 HPS hPS
955, RECTL& rRect
956, WXDWORD dwStyle
957)
958{
959 POINTL vPoint[2];
960
961 vPoint[0].x = rRect.xLeft;
962 vPoint[0].y = rRect.yBottom;
963 ::GpiMove(hPS, &vPoint[0]);
964 if (dwStyle & wxSIMPLE_BORDER ||
965 dwStyle & wxSTATIC_BORDER)
966 {
ad7f3189
DW
967 vPoint[1].x = rRect.xRight - 1;
968 vPoint[1].y = rRect.yTop - 1;
008089f6
DW
969 ::GpiBox( hPS
970 ,DRO_OUTLINE
971 ,&vPoint[1]
972 ,0L
973 ,0L
974 );
975 }
976 if (dwStyle & wxSUNKEN_BORDER)
977 {
978 LINEBUNDLE vLineBundle;
979
ad7f3189 980 vLineBundle.lColor = 0x00FFFFFF; // WHITE
008089f6
DW
981 vLineBundle.usMixMode = FM_OVERPAINT;
982 vLineBundle.fxWidth = 2;
983 vLineBundle.lGeomWidth = 2;
984 vLineBundle.usType = LINETYPE_SOLID;
985 vLineBundle.usEnd = 0;
986 vLineBundle.usJoin = 0;
987 ::GpiSetAttrs( hPS
988 ,PRIM_LINE
989 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
990 ,0L
991 ,&vLineBundle
992 );
ad7f3189
DW
993 vPoint[1].x = rRect.xRight - 1;
994 vPoint[1].y = rRect.yTop - 1;
008089f6
DW
995 ::GpiBox( hPS
996 ,DRO_OUTLINE
997 ,&vPoint[1]
998 ,0L
999 ,0L
1000 );
ad7f3189
DW
1001 vPoint[0].x = rRect.xLeft + 1;
1002 vPoint[0].y = rRect.yBottom + 1;
1003 ::GpiMove(hPS, &vPoint[0]);
1004 vPoint[1].x = rRect.xRight - 2;
1005 vPoint[1].y = rRect.yTop - 2;
1006 ::GpiBox( hPS
1007 ,DRO_OUTLINE
1008 ,&vPoint[1]
1009 ,0L
1010 ,0L
1011 );
1012
008089f6
DW
1013 vLineBundle.lColor = 0x00000000; // BLACK
1014 vLineBundle.usMixMode = FM_OVERPAINT;
1015 vLineBundle.fxWidth = 2;
1016 vLineBundle.lGeomWidth = 2;
1017 vLineBundle.usType = LINETYPE_SOLID;
1018 vLineBundle.usEnd = 0;
1019 vLineBundle.usJoin = 0;
1020 ::GpiSetAttrs( hPS
1021 ,PRIM_LINE
1022 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
1023 ,0L
1024 ,&vLineBundle
1025 );
1026 vPoint[0].x = rRect.xLeft + 2;
1027 vPoint[0].y = rRect.yBottom + 2;
1028 ::GpiMove(hPS, &vPoint[0]);
1029 vPoint[1].x = rRect.xLeft + 2;
ad7f3189 1030 vPoint[1].y = rRect.yTop - 3;
008089f6 1031 ::GpiLine(hPS, &vPoint[1]);
ad7f3189
DW
1032 vPoint[1].x = rRect.xRight - 3;
1033 vPoint[1].y = rRect.yTop - 3;
1034 ::GpiLine(hPS, &vPoint[1]);
1035
1036 vPoint[0].x = rRect.xLeft + 3;
1037 vPoint[0].y = rRect.yBottom + 3;
1038 ::GpiMove(hPS, &vPoint[0]);
1039 vPoint[1].x = rRect.xLeft + 3;
1040 vPoint[1].y = rRect.yTop - 4;
1041 ::GpiLine(hPS, &vPoint[1]);
1042 vPoint[1].x = rRect.xRight - 4;
1043 vPoint[1].y = rRect.yTop - 4;
008089f6
DW
1044 ::GpiLine(hPS, &vPoint[1]);
1045 }
1046 if (dwStyle & wxDOUBLE_BORDER)
1047 {
ad7f3189
DW
1048 LINEBUNDLE vLineBundle;
1049
1050 vLineBundle.lColor = 0x00FFFFFF; // WHITE
1051 vLineBundle.usMixMode = FM_OVERPAINT;
1052 vLineBundle.fxWidth = 2;
1053 vLineBundle.lGeomWidth = 2;
1054 vLineBundle.usType = LINETYPE_SOLID;
1055 vLineBundle.usEnd = 0;
1056 vLineBundle.usJoin = 0;
1057 ::GpiSetAttrs( hPS
1058 ,PRIM_LINE
1059 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
1060 ,0L
1061 ,&vLineBundle
1062 );
1063 vPoint[1].x = rRect.xRight - 1;
1064 vPoint[1].y = rRect.yTop - 1;
1065 ::GpiBox( hPS
1066 ,DRO_OUTLINE
1067 ,&vPoint[1]
1068 ,0L
1069 ,0L
1070 );
1071 vLineBundle.lColor = 0x00000000; // WHITE
1072 vLineBundle.usMixMode = FM_OVERPAINT;
1073 vLineBundle.fxWidth = 2;
1074 vLineBundle.lGeomWidth = 2;
1075 vLineBundle.usType = LINETYPE_SOLID;
1076 vLineBundle.usEnd = 0;
1077 vLineBundle.usJoin = 0;
1078 ::GpiSetAttrs( hPS
1079 ,PRIM_LINE
1080 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
1081 ,0L
1082 ,&vLineBundle
1083 );
1084 vPoint[0].x = rRect.xLeft + 2;
1085 vPoint[0].y = rRect.yBottom + 2;
1086 ::GpiMove(hPS, &vPoint[0]);
1087 vPoint[1].x = rRect.xRight - 2;
1088 vPoint[1].y = rRect.yTop - 2;
1089 ::GpiBox( hPS
1090 ,DRO_OUTLINE
1091 ,&vPoint[1]
1092 ,0L
1093 ,0L
1094 );
1095 vLineBundle.lColor = 0x00FFFFFF; // BLACK
1096 vLineBundle.usMixMode = FM_OVERPAINT;
1097 vLineBundle.fxWidth = 2;
1098 vLineBundle.lGeomWidth = 2;
1099 vLineBundle.usType = LINETYPE_SOLID;
1100 vLineBundle.usEnd = 0;
1101 vLineBundle.usJoin = 0;
1102 ::GpiSetAttrs( hPS
1103 ,PRIM_LINE
1104 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
1105 ,0L
1106 ,&vLineBundle
1107 );
1108 vPoint[0].x = rRect.xLeft + 3;
1109 vPoint[0].y = rRect.yBottom + 3;
1110 ::GpiMove(hPS, &vPoint[0]);
1111 vPoint[1].x = rRect.xRight - 3;
1112 vPoint[1].y = rRect.yTop - 3;
1113 ::GpiBox( hPS
1114 ,DRO_OUTLINE
1115 ,&vPoint[1]
1116 ,0L
1117 ,0L
1118 );
008089f6
DW
1119 }
1120 if (dwStyle & wxRAISED_BORDER)
1121 {
ad7f3189
DW
1122 LINEBUNDLE vLineBundle;
1123
1124 vLineBundle.lColor = 0x00000000; // BLACK
1125 vLineBundle.usMixMode = FM_OVERPAINT;
1126 vLineBundle.fxWidth = 2;
1127 vLineBundle.lGeomWidth = 2;
1128 vLineBundle.usType = LINETYPE_SOLID;
1129 vLineBundle.usEnd = 0;
1130 vLineBundle.usJoin = 0;
1131 ::GpiSetAttrs( hPS
1132 ,PRIM_LINE
1133 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
1134 ,0L
1135 ,&vLineBundle
1136 );
1137 vPoint[1].x = rRect.xRight - 1;
1138 vPoint[1].y = rRect.yTop - 1;
1139 ::GpiBox( hPS
1140 ,DRO_OUTLINE
1141 ,&vPoint[1]
1142 ,0L
1143 ,0L
1144 );
1145 vPoint[0].x = rRect.xLeft + 1;
1146 vPoint[0].y = rRect.yBottom + 1;
1147 ::GpiMove(hPS, &vPoint[0]);
1148 vPoint[1].x = rRect.xRight - 2;
1149 vPoint[1].y = rRect.yTop - 2;
1150 ::GpiBox( hPS
1151 ,DRO_OUTLINE
1152 ,&vPoint[1]
1153 ,0L
1154 ,0L
1155 );
1156
1157 vLineBundle.lColor = 0x00FFFFFF; // WHITE
1158 vLineBundle.usMixMode = FM_OVERPAINT;
1159 vLineBundle.fxWidth = 2;
1160 vLineBundle.lGeomWidth = 2;
1161 vLineBundle.usType = LINETYPE_SOLID;
1162 vLineBundle.usEnd = 0;
1163 vLineBundle.usJoin = 0;
1164 ::GpiSetAttrs( hPS
1165 ,PRIM_LINE
1166 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
1167 ,0L
1168 ,&vLineBundle
1169 );
1170 vPoint[0].x = rRect.xLeft + 2;
1171 vPoint[0].y = rRect.yBottom + 2;
1172 ::GpiMove(hPS, &vPoint[0]);
1173 vPoint[1].x = rRect.xLeft + 2;
1174 vPoint[1].y = rRect.yTop - 3;
1175 ::GpiLine(hPS, &vPoint[1]);
1176 vPoint[1].x = rRect.xRight - 3;
1177 vPoint[1].y = rRect.yTop - 3;
1178 ::GpiLine(hPS, &vPoint[1]);
1179
1180 vPoint[0].x = rRect.xLeft + 3;
1181 vPoint[0].y = rRect.yBottom + 3;
1182 ::GpiMove(hPS, &vPoint[0]);
1183 vPoint[1].x = rRect.xLeft + 3;
1184 vPoint[1].y = rRect.yTop - 4;
1185 ::GpiLine(hPS, &vPoint[1]);
1186 vPoint[1].x = rRect.xRight - 4;
1187 vPoint[1].y = rRect.yTop - 4;
1188 ::GpiLine(hPS, &vPoint[1]);
008089f6
DW
1189 }
1190} // end of wxDrawBorder
914589c2 1191