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