1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/cursor.h"
22 #include "wx/os2/private.h"
25 #include "wx/apptrait.h"
50 static const wxChar WX_SECTION
[] = _T("wxWindows");
51 static const wxChar eHOSTNAME
[] = _T("HostName");
52 static const wxChar eUSERID
[] = _T("UserId");
53 static const wxChar eUSERNAME
[] = _T("UserName");
55 // For the following functions we SHOULD fill in support
56 // for Windows-NT (which I don't know) as I assume it begin
57 // a POSIX Unix (so claims MS) that it has some special
58 // functions beyond those provided by WinSock
60 // Get full hostname (eg. DoDo.BSn-Germany.crg.de)
69 unsigned long ulLevel
= 0;
70 unsigned char* zBuffer
= NULL
;
71 unsigned long ulBuffer
= 256;
72 unsigned long* pulTotalAvail
= NULL
;
74 NetBios32GetInfo( (const unsigned char*)zServer
75 ,(const unsigned char*)zComputer
81 strcpy(zBuf
, zServer
);
84 const wxChar
* zDefaultHost
= _T("noname");
86 if ((zSysname
= wxGetenv(_T("SYSTEM_NAME"))) == NULL
)
88 ULONG n
= ::PrfQueryProfileString( HINI_PROFILE
97 wxStrncpy(zBuf
, zSysname
, nMaxSize
- 1);
98 zBuf
[nMaxSize
] = _T('\0');
100 return *zBuf
? TRUE
: FALSE
;
103 // Get user ID e.g. jacs
109 #if defined(__VISAGECPP__)
111 // UPM procs return 0 on success
112 lrc
= U32ELOCU((unsigned char*)zBuf
, (unsigned long *)&nType
);
113 if (lrc
== 0) return TRUE
;
128 wxStrncpy(zBuf
, _T("Unknown User"), nMaxSize
);
136 , wxKillError
* peError
139 return((int)::DosKillProcess(0, (PID
)lPid
));
143 // Execute a program in an Interactive Shell
146 const wxString
& rCommand
149 wxChar
* zShell
= _T("CMD.EXE");
152 STARTDATA SData
= {0};
153 PSZ PgmTitle
= "Command Shell";
157 UCHAR achObjBuf
[256] = {0}; //error data if DosStart fails
160 SData
.Length
= sizeof(STARTDATA
);
161 SData
.Related
= SSF_RELATED_INDEPENDENT
;
162 SData
.FgBg
= SSF_FGBG_FORE
;
163 SData
.TraceOpt
= SSF_TRACEOPT_NONE
;
164 SData
.PgmTitle
= PgmTitle
;
165 SData
.PgmName
= zShell
;
167 sInputs
= "/C " + rCommand
;
168 SData
.PgmInputs
= (BYTE
*)sInputs
.c_str();
170 SData
.Environment
= 0;
171 SData
.InheritOpt
= SSF_INHERTOPT_SHELL
;
172 SData
.SessionType
= SSF_TYPE_WINDOWABLEVIO
;
175 SData
.PgmControl
= SSF_CONTROL_VISIBLE
| SSF_CONTROL_MAXIMIZE
;
178 SData
.InitXSize
= 200;
179 SData
.InitYSize
= 140;
181 SData
.ObjectBuffer
= (char*)achObjBuf
;
182 SData
.ObjectBuffLen
= (ULONG
)sizeof(achObjBuf
);
184 rc
= ::DosStartSession(&SData
, &ulSessID
, &vPid
);
185 if (rc
== 0 || rc
== 457) // NO_ERROR or SMG_START_IN_BACKGROUND
190 ::DosGetInfoBlocks(&ptib
, &ppib
);
192 ::DosWaitChild( DCWA_PROCESS
202 // Shutdown or reboot the PC
203 bool wxShutdown(wxShutdownFlags wFlags
)
209 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
210 long wxGetFreeMemory()
212 void* pMemptr
= NULL
;
217 lMemFlags
= PAG_FREE
;
218 rc
= ::DosQueryMem(pMemptr
, &lSize
, &lMemFlags
);
224 // ----------------------------------------------------------------------------
226 // ----------------------------------------------------------------------------
228 bool wxGetEnv(const wxString
& var
, wxString
*value
)
230 // wxGetenv is defined as getenv()
231 wxChar
*p
= wxGetenv(var
);
243 bool wxSetEnv(const wxString
& variable
, const wxChar
*value
)
245 #if defined(HAVE_SETENV)
246 return setenv(variable
.mb_str(), value
? wxString(value
).mb_str().data()
247 : NULL
, 1 /* overwrite */) == 0;
248 #elif defined(HAVE_PUTENV)
249 wxString s
= variable
;
251 s
<< _T('=') << value
;
254 const char *p
= s
.mb_str();
256 // the string will be free()d by libc
257 char *buf
= (char *)malloc(strlen(p
) + 1);
260 return putenv(buf
) == 0;
261 #else // no way to set an env var
267 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
268 static bool inTimer
= FALSE
;
270 class wxSleepTimer
: public wxTimer
280 static wxTimer
* wxTheSleepTimer
= NULL
;
283 unsigned long ulMilliseconds
286 ::DosSleep(ulMilliseconds
);
293 ::DosSleep(1000 * nSecs
);
296 // Consume all events until no more left
302 #if WXWIN_COMPATIBILITY_2_2
304 // Output a debug mess., in a system dependent fashion.
306 const wxChar
* zFmt
...
310 static wxChar zBuffer
[512];
312 if (!wxTheApp
->GetWantDebugOutput())
315 sprintf(zBuffer
, zFmt
, vAp
) ;
319 // Non-fatal error: pop up message box and (possibly) continue
322 , const wxString
& rTitle
325 wxBuffer
= new wxChar
[256];
326 wxSprintf(wxBuffer
, "%s\nContinue?", WXSTRINGCAST rMsg
);
327 if (::WinMessageBox( HWND_DESKTOP
330 ,(PSZ
)WXSTRINGCAST rTitle
332 ,MB_ICONEXCLAMATION
| MB_YESNO
338 // Fatal error: pop up message box and abort
341 , const wxString
& rTitle
346 ulRc
= ::WinMessageBox( HWND_DESKTOP
353 DosExit(EXIT_PROCESS
, ulRc
);
356 #endif // WXWIN_COMPATIBILITY_2_2
361 DosBeep(1000,1000); // 1kHz during 1 sec.
364 int wxGUIAppTraits::GetOSVersion(
369 ULONG ulSysInfo
[QSV_MAX
] = {0};
372 ulrc
= ::DosQuerySysInfo( 1L
375 ,sizeof(ULONG
) * QSV_MAX
379 *pMajorVsn
= ulSysInfo
[QSV_VERSION_MAJOR
];
380 *pMajorVsn
= *pMajorVsn
/10;
381 *pMinorVsn
= ulSysInfo
[QSV_VERSION_MINOR
];
382 return wxWINDOWS_OS2
;
384 return wxWINDOWS
; // error if we get here, return generic value
387 // Reading and writing resources (eg WIN.INI, .Xdefaults)
389 bool wxWriteResource(
390 const wxString
& rSection
391 , const wxString
& rEntry
392 , const wxString
& rValue
393 , const wxString
& rFile
401 hIni
= ::PrfOpenProfile(hab
, (PSZ
)WXSTRINGCAST rFile
);
404 return (::PrfWriteProfileString( hIni
405 ,(PSZ
)WXSTRINGCAST rSection
406 ,(PSZ
)WXSTRINGCAST rEntry
407 ,(PSZ
)WXSTRINGCAST rValue
412 return (::PrfWriteProfileString( HINI_PROFILE
413 ,(PSZ
)WXSTRINGCAST rSection
414 ,(PSZ
)WXSTRINGCAST rEntry
415 ,(PSZ
)WXSTRINGCAST rValue
420 bool wxWriteResource(
421 const wxString
& rSection
422 , const wxString
& rEntry
424 , const wxString
& rFile
429 wxSprintf(zBuf
, "%.4f", fValue
);
430 return wxWriteResource( rSection
437 bool wxWriteResource(
438 const wxString
& rSection
439 , const wxString
& rEntry
441 , const wxString
& rFile
446 wxSprintf(zBuf
, "%ld", lValue
);
447 return wxWriteResource( rSection
454 bool wxWriteResource(
455 const wxString
& rSection
456 , const wxString
& rEntry
458 , const wxString
& rFile
463 wxSprintf(zBuf
, "%d", lValue
);
464 return wxWriteResource( rSection
472 const wxString
& rSection
473 , const wxString
& rEntry
475 , const wxString
& rFile
480 wxChar zDefunkt
[] = _T("$$default");
485 hIni
= ::PrfOpenProfile(hab
, (PSZ
)WXSTRINGCAST rFile
);
488 ULONG n
= ::PrfQueryProfileString( hIni
489 ,(PSZ
)WXSTRINGCAST rSection
490 ,(PSZ
)WXSTRINGCAST rEntry
497 if (n
== 0L || wxStrcmp(zBuf
, zDefunkt
) == 0)
506 ULONG n
= ::PrfQueryProfileString( HINI_PROFILE
507 ,(PSZ
)WXSTRINGCAST rSection
508 ,(PSZ
)WXSTRINGCAST rEntry
515 if (n
== 0L || wxStrcmp(zBuf
, zDefunkt
) == 0)
519 strcpy((char*)*ppValue
, zBuf
);
524 const wxString
& rSection
525 , const wxString
& rEntry
527 , const wxString
& rFile
532 zStr
= new wxChar
[1000];
533 bool bSucc
= wxGetResource( rSection
541 *pValue
= (float)wxStrtod(zStr
, NULL
);
553 const wxString
& rSection
554 , const wxString
& rEntry
556 , const wxString
& rFile
561 zStr
= new wxChar
[1000];
562 bool bSucc
= wxGetResource( rSection
570 *pValue
= wxStrtol(zStr
, NULL
, 10);
582 const wxString
& rSection
583 , const wxString
& rEntry
585 , const wxString
& rFile
590 zStr
= new wxChar
[1000];
591 bool bSucc
= wxGetResource( rSection
599 *pValue
= (int)wxStrtol(zStr
, NULL
, 10);
609 #endif // wxUSE_RESOURCES
611 // ---------------------------------------------------------------------------
612 // helper functions for showing a "busy" cursor
613 // ---------------------------------------------------------------------------
615 HCURSOR gs_wxBusyCursor
= 0; // new, busy cursor
616 HCURSOR gs_wxBusyCursorOld
= 0; // old cursor
617 static int gs_wxBusyCursorCount
= 0;
619 // Set the cursor to the busy cursor for all windows
620 void wxBeginBusyCursor(
624 if ( gs_wxBusyCursorCount
++ == 0 )
626 gs_wxBusyCursor
= (HCURSOR
)pCursor
->GetHCURSOR();
627 ::WinSetPointer(HWND_DESKTOP
, (HPOINTER
)gs_wxBusyCursor
);
629 //else: nothing to do, already set
632 // Restore cursor to normal
633 void wxEndBusyCursor()
635 wxCHECK_RET( gs_wxBusyCursorCount
> 0
636 ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()")
639 if (--gs_wxBusyCursorCount
== 0)
641 ::WinSetPointer(HWND_DESKTOP
, (HPOINTER
)gs_wxBusyCursorOld
);
642 gs_wxBusyCursorOld
= 0;
646 // TRUE if we're between the above two calls
649 return (gs_wxBusyCursorCount
> 0);
652 // ---------------------------------------------------------------------------
653 const wxChar
* wxGetHomeDir(
657 wxString
& rStrDir
= *pStr
;
659 // OS/2 has no idea about home,
660 // so use the working directory instead?
662 // 256 was taken from os2def.h
664 # define MAX_PATH 256
670 ::DosQueryCurrentDir(0, zDirName
, &ulDirLen
);
672 return rStrDir
.c_str();
676 wxChar
* wxGetUserHome (
677 const wxString
& rUser
681 wxString
sUser1(rUser
);
683 wxBuffer
= new wxChar
[256];
685 if (sUser1
!= _T(""))
689 if (wxGetUserId( zTmp
690 ,sizeof(zTmp
)/sizeof(char)
693 // Guests belong in the temp dir
694 if (wxStricmp(zTmp
, _T("annonymous")) == 0)
696 if ((zHome
= wxGetenv(_T("TMP"))) != NULL
||
697 (zHome
= wxGetenv(_T("TMPDIR"))) != NULL
||
698 (zHome
= wxGetenv(_T("TEMP"))) != NULL
)
700 return *zHome
? zHome
: (wxChar
*)_T("\\");
702 if (wxStricmp(zTmp
, WXSTRINGCAST sUser1
) == 0)
707 if (sUser1
== _T(""))
709 if ((zHome
= wxGetenv(_T("HOME"))) != NULL
)
711 wxStrcpy(wxBuffer
, zHome
);
712 wxUnix2DosFilename(wxBuffer
);
713 wxStrcpy(zHome
, wxBuffer
);
719 return NULL
; // No home known!
722 // Check whether this window wants to process messages, e.g. Stop button
723 // in long calculations.
724 bool wxCheckForInterrupt(
732 HWND hwndFilter
= NULLHANDLE
;
733 HWND hwndWin
= (HWND
) pWnd
->GetHWND();
735 while(::WinPeekMsg(hab
, &vMsg
, hwndFilter
, 0, 0, PM_REMOVE
))
737 ::WinDispatchMsg(hab
, &vMsg
);
739 return TRUE
;//*** temporary?
743 wxFAIL_MSG(_T("pWnd==NULL !!!"));
744 return FALSE
;//*** temporary?
748 void wxGetMousePosition(
755 ::WinQueryPointerPos(HWND_DESKTOP
, &vPt
);
760 // Return TRUE if we have a colour display
761 bool wxColourDisplay()
768 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
769 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
770 ::DevQueryCaps(hdcScreen
, CAPS_COLORS
, 1L, &lColors
);
771 return(lColors
> 1L);
773 // I don't see how the PM display could not be color. Besides, this
774 // was leaking DCs and PSs!!! MN
779 // Returns depth of screen
786 static LONG nDepth
= 0;
788 // The screen colordepth ain't gonna change. No reason to query
791 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
792 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
793 ::DevQueryCaps(hdcScreen
, CAPS_COLOR_PLANES
, 1L, &lPlanes
);
794 ::DevQueryCaps(hdcScreen
, CAPS_COLOR_BITCOUNT
, 1L, &lBitsPerPixel
);
796 nDepth
= (int)(lPlanes
* lBitsPerPixel
);
797 ::DevCloseDC(hdcScreen
);
798 ::WinReleasePS(hpsScreen
);
803 // Get size of display
811 static LONG lWidth
= 0;
812 static LONG lHeight
= 0;
814 // The screen size ain't gonna change either so just cache the values
816 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
817 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
818 ::DevQueryCaps(hdcScreen
, CAPS_WIDTH
, 1L, &lWidth
);
819 ::DevQueryCaps(hdcScreen
, CAPS_HEIGHT
, 1L, &lHeight
);
820 ::DevCloseDC(hdcScreen
);
821 ::WinReleasePS(hpsScreen
);
823 *pWidth
= (int)lWidth
;
824 *pHeight
= (int)lHeight
;
827 void wxDisplaySizeMM(
835 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
836 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
839 ::DevQueryCaps( hdcScreen
840 ,CAPS_HORIZONTAL_RESOLUTION
845 ::DevQueryCaps( hdcScreen
846 ,CAPS_VERTICAL_RESOLUTION
850 ::DevCloseDC(hdcScreen
);
851 ::WinReleasePS(hpsScreen
);
854 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
856 // This is supposed to return desktop dimensions minus any window
857 // manager panels, menus, taskbars, etc. If there is a way to do that
858 // for this platform please fix this function, otherwise it defaults
859 // to the entire desktop.
862 wxDisplaySize(width
, height
);
870 return (::DosSetCurrentDir(WXSTRINGCAST rDir
));
873 // ---------------------------------------------------------------------------
874 // window information functions
875 // ---------------------------------------------------------------------------
877 wxString WXDLLEXPORT
wxGetWindowText(
882 long lLen
= ::WinQueryWindowTextLength((HWND
)hWnd
) + 1;
884 ::WinQueryWindowText((HWND
)hWnd
, lLen
, vStr
.GetWriteBuf((int)lLen
));
885 vStr
.UngetWriteBuf();
890 wxString WXDLLEXPORT
wxGetWindowClass(
895 int nLen
= 256; // some starting value
899 int nCount
= ::WinQueryClassName((HWND
)hWnd
, nLen
, vStr
.GetWriteBuf(nLen
));
901 vStr
.UngetWriteBuf();
904 // the class name might have been truncated, retry with larger
916 WXWORD WXDLLEXPORT
wxGetWindowId(
920 return ::WinQueryWindowUShort((HWND
)hWnd
, QWS_ID
);
923 wxString WXDLLEXPORT
wxPMErrorToStr(
930 // Remove the high order byte -- it is useless
932 vError
&= 0x0000ffff;
935 case PMERR_INVALID_HWND
:
936 sError
= wxT("Invalid window handle specified");
939 case PMERR_INVALID_FLAG
:
940 sError
= wxT("Invalid flag bit set");
943 case PMERR_NO_MSG_QUEUE
:
944 sError
= wxT("No message queue available");
947 case PMERR_INVALID_PARM
:
948 sError
= wxT("Parameter contained invalid data");
951 case PMERR_INVALID_PARAMETERS
:
952 sError
= wxT("Parameter value is out of range");
955 case PMERR_PARAMETER_OUT_OF_RANGE
:
956 sError
= wxT("Parameter value is out of range");
959 case PMERR_INVALID_INTEGER_ATOM
:
960 sError
= wxT("Not a valid atom");
963 case PMERR_INVALID_HATOMTBL
:
964 sError
= wxT("Atom table handle is invalid");
967 case PMERR_INVALID_ATOM_NAME
:
968 sError
= wxT("Not a valid atom name");
971 case PMERR_ATOM_NAME_NOT_FOUND
:
972 sError
= wxT("Valid name format, but cannot find name in atom table");
976 sError
= wxT("Unknown error");
979 } // end of wxPMErrorToStr
989 vPoint
[0].x
= rRect
.xLeft
;
990 vPoint
[0].y
= rRect
.yBottom
;
991 ::GpiMove(hPS
, &vPoint
[0]);
992 if (dwStyle
& wxSIMPLE_BORDER
||
993 dwStyle
& wxSTATIC_BORDER
)
995 vPoint
[1].x
= rRect
.xRight
- 1;
996 vPoint
[1].y
= rRect
.yTop
- 1;
1004 if (dwStyle
& wxSUNKEN_BORDER
)
1006 LINEBUNDLE vLineBundle
;
1008 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
1009 vLineBundle
.usMixMode
= FM_OVERPAINT
;
1010 vLineBundle
.fxWidth
= 2;
1011 vLineBundle
.lGeomWidth
= 2;
1012 vLineBundle
.usType
= LINETYPE_SOLID
;
1013 vLineBundle
.usEnd
= 0;
1014 vLineBundle
.usJoin
= 0;
1017 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
1021 vPoint
[1].x
= rRect
.xRight
- 1;
1022 vPoint
[1].y
= rRect
.yTop
- 1;
1029 vPoint
[0].x
= rRect
.xLeft
+ 1;
1030 vPoint
[0].y
= rRect
.yBottom
+ 1;
1031 ::GpiMove(hPS
, &vPoint
[0]);
1032 vPoint
[1].x
= rRect
.xRight
- 2;
1033 vPoint
[1].y
= rRect
.yTop
- 2;
1041 vLineBundle
.lColor
= 0x00000000; // BLACK
1042 vLineBundle
.usMixMode
= FM_OVERPAINT
;
1043 vLineBundle
.fxWidth
= 2;
1044 vLineBundle
.lGeomWidth
= 2;
1045 vLineBundle
.usType
= LINETYPE_SOLID
;
1046 vLineBundle
.usEnd
= 0;
1047 vLineBundle
.usJoin
= 0;
1050 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
1054 vPoint
[0].x
= rRect
.xLeft
+ 2;
1055 vPoint
[0].y
= rRect
.yBottom
+ 2;
1056 ::GpiMove(hPS
, &vPoint
[0]);
1057 vPoint
[1].x
= rRect
.xLeft
+ 2;
1058 vPoint
[1].y
= rRect
.yTop
- 3;
1059 ::GpiLine(hPS
, &vPoint
[1]);
1060 vPoint
[1].x
= rRect
.xRight
- 3;
1061 vPoint
[1].y
= rRect
.yTop
- 3;
1062 ::GpiLine(hPS
, &vPoint
[1]);
1064 vPoint
[0].x
= rRect
.xLeft
+ 3;
1065 vPoint
[0].y
= rRect
.yBottom
+ 3;
1066 ::GpiMove(hPS
, &vPoint
[0]);
1067 vPoint
[1].x
= rRect
.xLeft
+ 3;
1068 vPoint
[1].y
= rRect
.yTop
- 4;
1069 ::GpiLine(hPS
, &vPoint
[1]);
1070 vPoint
[1].x
= rRect
.xRight
- 4;
1071 vPoint
[1].y
= rRect
.yTop
- 4;
1072 ::GpiLine(hPS
, &vPoint
[1]);
1074 if (dwStyle
& wxDOUBLE_BORDER
)
1076 LINEBUNDLE vLineBundle
;
1078 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
1079 vLineBundle
.usMixMode
= FM_OVERPAINT
;
1080 vLineBundle
.fxWidth
= 2;
1081 vLineBundle
.lGeomWidth
= 2;
1082 vLineBundle
.usType
= LINETYPE_SOLID
;
1083 vLineBundle
.usEnd
= 0;
1084 vLineBundle
.usJoin
= 0;
1087 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
1091 vPoint
[1].x
= rRect
.xRight
- 1;
1092 vPoint
[1].y
= rRect
.yTop
- 1;
1099 vLineBundle
.lColor
= 0x00000000; // WHITE
1100 vLineBundle
.usMixMode
= FM_OVERPAINT
;
1101 vLineBundle
.fxWidth
= 2;
1102 vLineBundle
.lGeomWidth
= 2;
1103 vLineBundle
.usType
= LINETYPE_SOLID
;
1104 vLineBundle
.usEnd
= 0;
1105 vLineBundle
.usJoin
= 0;
1108 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
1112 vPoint
[0].x
= rRect
.xLeft
+ 2;
1113 vPoint
[0].y
= rRect
.yBottom
+ 2;
1114 ::GpiMove(hPS
, &vPoint
[0]);
1115 vPoint
[1].x
= rRect
.xRight
- 2;
1116 vPoint
[1].y
= rRect
.yTop
- 2;
1123 vLineBundle
.lColor
= 0x00FFFFFF; // BLACK
1124 vLineBundle
.usMixMode
= FM_OVERPAINT
;
1125 vLineBundle
.fxWidth
= 2;
1126 vLineBundle
.lGeomWidth
= 2;
1127 vLineBundle
.usType
= LINETYPE_SOLID
;
1128 vLineBundle
.usEnd
= 0;
1129 vLineBundle
.usJoin
= 0;
1132 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
1136 vPoint
[0].x
= rRect
.xLeft
+ 3;
1137 vPoint
[0].y
= rRect
.yBottom
+ 3;
1138 ::GpiMove(hPS
, &vPoint
[0]);
1139 vPoint
[1].x
= rRect
.xRight
- 3;
1140 vPoint
[1].y
= rRect
.yTop
- 3;
1148 if (dwStyle
& wxRAISED_BORDER
)
1150 LINEBUNDLE vLineBundle
;
1152 vLineBundle
.lColor
= 0x00000000; // BLACK
1153 vLineBundle
.usMixMode
= FM_OVERPAINT
;
1154 vLineBundle
.fxWidth
= 2;
1155 vLineBundle
.lGeomWidth
= 2;
1156 vLineBundle
.usType
= LINETYPE_SOLID
;
1157 vLineBundle
.usEnd
= 0;
1158 vLineBundle
.usJoin
= 0;
1161 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
1165 vPoint
[1].x
= rRect
.xRight
- 1;
1166 vPoint
[1].y
= rRect
.yTop
- 1;
1173 vPoint
[0].x
= rRect
.xLeft
+ 1;
1174 vPoint
[0].y
= rRect
.yBottom
+ 1;
1175 ::GpiMove(hPS
, &vPoint
[0]);
1176 vPoint
[1].x
= rRect
.xRight
- 2;
1177 vPoint
[1].y
= rRect
.yTop
- 2;
1185 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
1186 vLineBundle
.usMixMode
= FM_OVERPAINT
;
1187 vLineBundle
.fxWidth
= 2;
1188 vLineBundle
.lGeomWidth
= 2;
1189 vLineBundle
.usType
= LINETYPE_SOLID
;
1190 vLineBundle
.usEnd
= 0;
1191 vLineBundle
.usJoin
= 0;
1194 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
1198 vPoint
[0].x
= rRect
.xLeft
+ 2;
1199 vPoint
[0].y
= rRect
.yBottom
+ 2;
1200 ::GpiMove(hPS
, &vPoint
[0]);
1201 vPoint
[1].x
= rRect
.xLeft
+ 2;
1202 vPoint
[1].y
= rRect
.yTop
- 3;
1203 ::GpiLine(hPS
, &vPoint
[1]);
1204 vPoint
[1].x
= rRect
.xRight
- 3;
1205 vPoint
[1].y
= rRect
.yTop
- 3;
1206 ::GpiLine(hPS
, &vPoint
[1]);
1208 vPoint
[0].x
= rRect
.xLeft
+ 3;
1209 vPoint
[0].y
= rRect
.yBottom
+ 3;
1210 ::GpiMove(hPS
, &vPoint
[0]);
1211 vPoint
[1].x
= rRect
.xLeft
+ 3;
1212 vPoint
[1].y
= rRect
.yTop
- 4;
1213 ::GpiLine(hPS
, &vPoint
[1]);
1214 vPoint
[1].x
= rRect
.xRight
- 4;
1215 vPoint
[1].y
= rRect
.yTop
- 4;
1216 ::GpiLine(hPS
, &vPoint
[1]);
1218 } // end of wxDrawBorder
1222 , const wxFont
& rFont
1230 if (hWnd
== NULLHANDLE
)
1234 // The fonts available for Presentation Params are just a few
1235 // outline fonts, the rest are available to the GPI, so we must
1236 // map the families to one of these three
1238 switch(rFont
.GetFamily())
1241 strcpy(zFacename
, "Script");
1245 strcpy(zFacename
, "WarpSans");
1249 strcpy(zFacename
,"Times New Roman");
1253 strcpy(zFacename
, "Courier New");
1257 strcpy(zFacename
, "Courier New");
1263 strcpy(zFacename
, "Helvetica");
1267 switch(rFont
.GetWeight())
1276 case wxFONTWEIGHT_MAX
:
1277 strcpy(zWeight
, "Bold");
1281 switch(rFont
.GetStyle())
1285 strcpy(zStyle
, "Italic");
1292 sprintf(zFont
, "%d.%s", rFont
.GetPointSize(), zFacename
);
1293 if (zWeight
[0] != '\0')
1296 strcat(zFont
, zWeight
);
1298 if (zStyle
[0] != '\0')
1301 strcat(zFont
, zStyle
);
1303 ::WinSetPresParam(hWnd
, PP_FONTNAMESIZE
, strlen(zFont
) + 1, (PVOID
)zFont
);
1304 } // end of wxOS2SetFont
1306 // ---------------------------------------------------------------------------
1307 // Helper for taking a regular bitmap and giving it a disabled look
1308 // ---------------------------------------------------------------------------
1309 wxBitmap
wxDisableBitmap(
1310 const wxBitmap
& rBmp
1314 wxMask
* pMask
= rBmp
.GetMask();
1317 return(wxNullBitmap
);
1319 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1320 SIZEL vSize
= {0, 0};
1321 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1322 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1323 BITMAPINFOHEADER2 vHeader
;
1327 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
1328 HBITMAP hOldBitmap
= NULLHANDLE
;
1329 HBITMAP hOldMask
= NULLHANDLE
;
1330 HBITMAP hMask
= (HBITMAP
)rBmp
.GetMask()->GetMaskBitmap();
1331 unsigned char* pucBits
; // buffer that will contain the bitmap data
1332 unsigned char* pucData
; // pointer to use to traverse bitmap data
1333 unsigned char* pucBitsMask
; // buffer that will contain the mask data
1334 unsigned char* pucDataMask
; // pointer to use to traverse mask data
1336 LONG lScansSet
= 0L;
1337 bool bpp16
= (wxDisplayDepth() == 16);
1339 memset(&vHeader
, '\0', 16);
1342 memset(&vInfo
, '\0', 16);
1344 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1345 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1347 vInfo
.cBitCount
= 24; // Set to desired count going in
1350 // Create the buffers for data....all wxBitmaps are 24 bit internally
1352 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1353 int nSizeDWORD
= sizeof(DWORD
);
1354 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
1360 // Bitmap must be ina double-word alligned address so we may
1361 // have some padding to worry about
1363 if (nLineBoundary
> 0)
1365 nPadding
= nSizeDWORD
- nLineBoundary
;
1366 nBytesPerLine
+= nPadding
;
1368 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1369 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1370 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1371 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1374 // Extract the bitmap and mask data
1376 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1378 vError
= ::WinGetLastError(vHabmain
);
1379 sError
= wxPMErrorToStr(vError
);
1381 ::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
);
1382 vInfo
.cBitCount
= 24;
1383 if ((lScans
= ::GpiQueryBitmapBits( hPS
1385 ,(LONG
)rBmp
.GetHeight()
1390 vError
= ::WinGetLastError(vHabmain
);
1391 sError
= wxPMErrorToStr(vError
);
1393 if ((hOldMask
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
1395 vError
= ::WinGetLastError(vHabmain
);
1396 sError
= wxPMErrorToStr(vError
);
1398 ::GpiQueryBitmapInfoHeader(hMask
, &vHeader
);
1399 vInfo
.cBitCount
= 24;
1400 if ((lScans
= ::GpiQueryBitmapBits( hPS
1402 ,(LONG
)rBmp
.GetHeight()
1407 vError
= ::WinGetLastError(vHabmain
);
1408 sError
= wxPMErrorToStr(vError
);
1410 if (( hMask
= ::GpiSetBitmap(hPS
, hOldMask
)) == HBM_ERROR
)
1412 vError
= ::WinGetLastError(vHabmain
);
1413 sError
= wxPMErrorToStr(vError
);
1416 pucDataMask
= pucBitsMask
;
1419 // Get the mask value
1421 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1423 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1426 if (bpp16
&& *pucDataMask
== 0xF8) // 16 bit display gobblygook
1431 else if (*pucDataMask
== 0xFF) // set to grey
1438 *pucData
= ((unsigned char)(lColor
>> 16));
1443 if (bpp16
&& *(pucDataMask
+ 1) == 0xFC) // 16 bit display gobblygook
1448 else if (*(pucDataMask
+ 1) == 0xFF) // set to grey
1455 *pucData
= ((unsigned char)(lColor
>> 8));
1460 if (bpp16
&& *(pucDataMask
+ 2) == 0xF8) // 16 bit display gobblygook
1465 else if (*(pucDataMask
+ 2) == 0xFF) // set to grey
1472 *pucData
= ((unsigned char)lColor
);
1477 for (j
= 0; j
< nPadding
; j
++)
1485 // Create a new bitmap and set the modified bits
1487 wxBitmap
vNewBmp( rBmp
.GetWidth()
1491 HBITMAP hNewBmp
= (HBITMAP
)vNewBmp
.GetHBITMAP();
1493 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hNewBmp
)) == HBM_ERROR
)
1495 vError
= ::WinGetLastError(vHabmain
);
1496 sError
= wxPMErrorToStr(vError
);
1498 if ((lScansSet
= ::GpiSetBitmapBits( hPS
1500 ,(LONG
)rBmp
.GetHeight()
1506 vError
= ::WinGetLastError(vHabmain
);
1507 sError
= wxPMErrorToStr(vError
);
1511 pNewMask
= new wxMask(pMask
->GetMaskBitmap());
1512 vNewBmp
.SetMask(pNewMask
);
1514 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1515 ::GpiDestroyPS(hPS
);
1519 return(wxNullBitmap
);
1520 } // end of wxDisableBitmap
1522 COLORREF
wxColourToRGB(
1523 const wxColour
& rColor
1526 return(OS2RGB(rColor
.Red(), rColor
.Green(), rColor
.Blue()));
1527 } // end of wxColourToRGB