1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: os2/utilsgui.cpp
3 // Purpose: Various utility functions only available in GUI
4 // Author: David Webster
6 // Created: 20.08.2003 (extracted from os2/utils.cpp)
8 // Copyright: (c) David Webster
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
31 #include "wx/cursor.h"
34 #include "wx/apptrait.h"
37 #include "wx/os2/private.h" // includes <windows.h>
39 // ============================================================================
41 // ============================================================================
43 // ----------------------------------------------------------------------------
44 // functions to work with .INI files
45 // ----------------------------------------------------------------------------
47 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
48 static bool inTimer
= FALSE
;
50 class wxSleepTimer
: public wxTimer
60 // Reading and writing resources (eg WIN.INI, .Xdefaults)
63 const wxString
& rSection
64 , const wxString
& rEntry
65 , const wxString
& rValue
66 , const wxString
& rFile
74 hIni
= ::PrfOpenProfile(hab
, (PSZ
)WXSTRINGCAST rFile
);
77 return (::PrfWriteProfileString( hIni
78 ,(PSZ
)WXSTRINGCAST rSection
79 ,(PSZ
)WXSTRINGCAST rEntry
80 ,(PSZ
)WXSTRINGCAST rValue
85 return (::PrfWriteProfileString( HINI_PROFILE
86 ,(PSZ
)WXSTRINGCAST rSection
87 ,(PSZ
)WXSTRINGCAST rEntry
88 ,(PSZ
)WXSTRINGCAST rValue
94 const wxString
& rSection
95 , const wxString
& rEntry
97 , const wxString
& rFile
102 wxSprintf(zBuf
, "%.4f", fValue
);
103 return wxWriteResource( rSection
110 bool wxWriteResource(
111 const wxString
& rSection
112 , const wxString
& rEntry
114 , const wxString
& rFile
119 wxSprintf(zBuf
, "%ld", lValue
);
120 return wxWriteResource( rSection
127 bool wxWriteResource(
128 const wxString
& rSection
129 , const wxString
& rEntry
131 , const wxString
& rFile
136 wxSprintf(zBuf
, "%d", lValue
);
137 return wxWriteResource( rSection
145 const wxString
& rSection
146 , const wxString
& rEntry
148 , const wxString
& rFile
153 wxChar zDefunkt
[] = _T("$$default");
158 hIni
= ::PrfOpenProfile(hab
, (PSZ
)WXSTRINGCAST rFile
);
161 ULONG n
= ::PrfQueryProfileString( hIni
162 ,(PSZ
)WXSTRINGCAST rSection
163 ,(PSZ
)WXSTRINGCAST rEntry
170 if (n
== 0L || wxStrcmp(zBuf
, zDefunkt
) == 0)
179 ULONG n
= ::PrfQueryProfileString( HINI_PROFILE
180 ,(PSZ
)WXSTRINGCAST rSection
181 ,(PSZ
)WXSTRINGCAST rEntry
188 if (n
== 0L || wxStrcmp(zBuf
, zDefunkt
) == 0)
192 strcpy((char*)*ppValue
, zBuf
);
197 const wxString
& rSection
198 , const wxString
& rEntry
200 , const wxString
& rFile
205 zStr
= new wxChar
[1000];
206 bool bSucc
= wxGetResource( rSection
214 *pValue
= (float)wxStrtod(zStr
, NULL
);
226 const wxString
& rSection
227 , const wxString
& rEntry
229 , const wxString
& rFile
234 zStr
= new wxChar
[1000];
235 bool bSucc
= wxGetResource( rSection
243 *pValue
= wxStrtol(zStr
, NULL
, 10);
255 const wxString
& rSection
256 , const wxString
& rEntry
258 , const wxString
& rFile
263 zStr
= new wxChar
[1000];
264 bool bSucc
= wxGetResource( rSection
272 *pValue
= (int)wxStrtol(zStr
, NULL
, 10);
282 #endif // wxUSE_RESOURCES
284 // ---------------------------------------------------------------------------
285 // helper functions for showing a "busy" cursor
286 // ---------------------------------------------------------------------------
288 HCURSOR gs_wxBusyCursor
= 0; // new, busy cursor
289 HCURSOR gs_wxBusyCursorOld
= 0; // old cursor
290 static int gs_wxBusyCursorCount
= 0;
292 // Set the cursor to the busy cursor for all windows
293 void wxBeginBusyCursor(
297 if ( gs_wxBusyCursorCount
++ == 0 )
299 gs_wxBusyCursor
= (HCURSOR
)pCursor
->GetHCURSOR();
300 ::WinSetPointer(HWND_DESKTOP
, (HPOINTER
)gs_wxBusyCursor
);
302 //else: nothing to do, already set
305 // Restore cursor to normal
306 void wxEndBusyCursor()
308 wxCHECK_RET( gs_wxBusyCursorCount
> 0
309 ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()")
312 if (--gs_wxBusyCursorCount
== 0)
314 ::WinSetPointer(HWND_DESKTOP
, (HPOINTER
)gs_wxBusyCursorOld
);
315 gs_wxBusyCursorOld
= 0;
319 // TRUE if we're between the above two calls
322 return (gs_wxBusyCursorCount
> 0);
325 // Check whether this window wants to process messages, e.g. Stop button
326 // in long calculations.
327 bool wxCheckForInterrupt(
335 HWND hwndFilter
= NULLHANDLE
;
337 while(::WinPeekMsg(hab
, &vMsg
, hwndFilter
, 0, 0, PM_REMOVE
))
339 ::WinDispatchMsg(hab
, &vMsg
);
341 return TRUE
;//*** temporary?
345 wxFAIL_MSG(_T("pWnd==NULL !!!"));
346 return FALSE
;//*** temporary?
350 // ----------------------------------------------------------------------------
352 // ----------------------------------------------------------------------------
354 // See also the wxGetMousePosition in window.cpp
355 // Deprecated: use wxPoint wxGetMousePosition() instead
356 void wxGetMousePosition(
363 ::WinQueryPointerPos(HWND_DESKTOP
, &vPt
);
368 // Return TRUE if we have a colour display
369 bool wxColourDisplay()
376 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
377 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
378 ::DevQueryCaps(hdcScreen
, CAPS_COLORS
, 1L, &lColors
);
379 return(lColors
> 1L);
381 // I don't see how the PM display could not be color. Besides, this
382 // was leaking DCs and PSs!!! MN
387 // Returns depth of screen
394 static LONG nDepth
= 0;
396 // The screen colordepth ain't gonna change. No reason to query
399 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
400 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
401 ::DevQueryCaps(hdcScreen
, CAPS_COLOR_PLANES
, 1L, &lPlanes
);
402 ::DevQueryCaps(hdcScreen
, CAPS_COLOR_BITCOUNT
, 1L, &lBitsPerPixel
);
404 nDepth
= (int)(lPlanes
* lBitsPerPixel
);
405 ::DevCloseDC(hdcScreen
);
406 ::WinReleasePS(hpsScreen
);
411 // Get size of display
419 static LONG lWidth
= 0;
420 static LONG lHeight
= 0;
422 // The screen size ain't gonna change either so just cache the values
424 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
425 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
426 ::DevQueryCaps(hdcScreen
, CAPS_WIDTH
, 1L, &lWidth
);
427 ::DevQueryCaps(hdcScreen
, CAPS_HEIGHT
, 1L, &lHeight
);
428 ::DevCloseDC(hdcScreen
);
429 ::WinReleasePS(hpsScreen
);
432 *pWidth
= (int)lWidth
;
434 *pHeight
= (int)lHeight
;
437 void wxDisplaySizeMM(
445 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
446 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
449 ::DevQueryCaps( hdcScreen
450 ,CAPS_HORIZONTAL_RESOLUTION
455 ::DevQueryCaps( hdcScreen
456 ,CAPS_VERTICAL_RESOLUTION
460 ::DevCloseDC(hdcScreen
);
461 ::WinReleasePS(hpsScreen
);
464 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
466 // This is supposed to return desktop dimensions minus any window
467 // manager panels, menus, taskbars, etc. If there is a way to do that
468 // for this platform please fix this function, otherwise it defaults
469 // to the entire desktop.
472 wxDisplaySize(width
, height
);
475 void wxGUIAppTraits::InitializeGui(unsigned long &ulHab
)
477 ulHab
= ::WinInitialize(0);
480 void wxGUIAppTraits::TerminateGui(unsigned long ulHab
)
482 ::WinTerminate(ulHab
);
485 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
487 static wxToolkitInfo vInfo
;
488 ULONG ulSysInfo
[QSV_MAX
] = {0};
491 vInfo
.shortName
= _T("PM");
492 vInfo
.name
= _T("wxOS2");
493 #ifdef __WXUNIVERSAL__
494 vInfo
.shortName
<< _T("univ");
495 vInfo
.name
<< _T("/wxUniversal");
497 ulrc
= ::DosQuerySysInfo( 1L
500 ,sizeof(ULONG
) * QSV_MAX
504 vInfo
.versionMajor
= ulSysInfo
[QSV_VERSION_MAJOR
] / 10;
505 vInfo
.versionMinor
= ulSysInfo
[QSV_VERSION_MINOR
];
511 // ---------------------------------------------------------------------------
512 // window information functions
513 // ---------------------------------------------------------------------------
515 wxString WXDLLEXPORT
wxGetWindowText(
523 long lLen
= ::WinQueryWindowTextLength((HWND
)hWnd
) + 1;
524 ::WinQueryWindowText((HWND
)hWnd
, lLen
, (PSZ
)(wxChar
*)wxStringBuffer(vStr
, lLen
));
530 wxString WXDLLEXPORT
wxGetWindowClass(
537 int nLen
= 256; // some starting value
541 int nCount
= ::WinQueryClassName((HWND
)hWnd
, nLen
, (PSZ
)(wxChar
*)wxStringBuffer(vStr
, nLen
));
545 // the class name might have been truncated, retry with larger
558 WXWORD WXDLLEXPORT
wxGetWindowId(
562 return ::WinQueryWindowUShort((HWND
)hWnd
, QWS_ID
);
573 vPoint
[0].x
= rRect
.xLeft
;
574 vPoint
[0].y
= rRect
.yBottom
;
575 ::GpiMove(hPS
, &vPoint
[0]);
576 if (dwStyle
& wxSIMPLE_BORDER
||
577 dwStyle
& wxSTATIC_BORDER
)
579 vPoint
[1].x
= rRect
.xRight
- 1;
580 vPoint
[1].y
= rRect
.yTop
- 1;
588 if (dwStyle
& wxSUNKEN_BORDER
)
590 LINEBUNDLE vLineBundle
;
592 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
593 vLineBundle
.usMixMode
= FM_OVERPAINT
;
594 vLineBundle
.fxWidth
= 2;
595 vLineBundle
.lGeomWidth
= 2;
596 vLineBundle
.usType
= LINETYPE_SOLID
;
597 vLineBundle
.usEnd
= 0;
598 vLineBundle
.usJoin
= 0;
601 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
605 vPoint
[1].x
= rRect
.xRight
- 1;
606 vPoint
[1].y
= rRect
.yTop
- 1;
613 vPoint
[0].x
= rRect
.xLeft
+ 1;
614 vPoint
[0].y
= rRect
.yBottom
+ 1;
615 ::GpiMove(hPS
, &vPoint
[0]);
616 vPoint
[1].x
= rRect
.xRight
- 2;
617 vPoint
[1].y
= rRect
.yTop
- 2;
625 vLineBundle
.lColor
= 0x00000000; // BLACK
626 vLineBundle
.usMixMode
= FM_OVERPAINT
;
627 vLineBundle
.fxWidth
= 2;
628 vLineBundle
.lGeomWidth
= 2;
629 vLineBundle
.usType
= LINETYPE_SOLID
;
630 vLineBundle
.usEnd
= 0;
631 vLineBundle
.usJoin
= 0;
634 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
638 vPoint
[0].x
= rRect
.xLeft
+ 2;
639 vPoint
[0].y
= rRect
.yBottom
+ 2;
640 ::GpiMove(hPS
, &vPoint
[0]);
641 vPoint
[1].x
= rRect
.xLeft
+ 2;
642 vPoint
[1].y
= rRect
.yTop
- 3;
643 ::GpiLine(hPS
, &vPoint
[1]);
644 vPoint
[1].x
= rRect
.xRight
- 3;
645 vPoint
[1].y
= rRect
.yTop
- 3;
646 ::GpiLine(hPS
, &vPoint
[1]);
648 vPoint
[0].x
= rRect
.xLeft
+ 3;
649 vPoint
[0].y
= rRect
.yBottom
+ 3;
650 ::GpiMove(hPS
, &vPoint
[0]);
651 vPoint
[1].x
= rRect
.xLeft
+ 3;
652 vPoint
[1].y
= rRect
.yTop
- 4;
653 ::GpiLine(hPS
, &vPoint
[1]);
654 vPoint
[1].x
= rRect
.xRight
- 4;
655 vPoint
[1].y
= rRect
.yTop
- 4;
656 ::GpiLine(hPS
, &vPoint
[1]);
658 if (dwStyle
& wxDOUBLE_BORDER
)
660 LINEBUNDLE vLineBundle
;
662 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
663 vLineBundle
.usMixMode
= FM_OVERPAINT
;
664 vLineBundle
.fxWidth
= 2;
665 vLineBundle
.lGeomWidth
= 2;
666 vLineBundle
.usType
= LINETYPE_SOLID
;
667 vLineBundle
.usEnd
= 0;
668 vLineBundle
.usJoin
= 0;
671 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
675 vPoint
[1].x
= rRect
.xRight
- 1;
676 vPoint
[1].y
= rRect
.yTop
- 1;
683 vLineBundle
.lColor
= 0x00000000; // WHITE
684 vLineBundle
.usMixMode
= FM_OVERPAINT
;
685 vLineBundle
.fxWidth
= 2;
686 vLineBundle
.lGeomWidth
= 2;
687 vLineBundle
.usType
= LINETYPE_SOLID
;
688 vLineBundle
.usEnd
= 0;
689 vLineBundle
.usJoin
= 0;
692 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
696 vPoint
[0].x
= rRect
.xLeft
+ 2;
697 vPoint
[0].y
= rRect
.yBottom
+ 2;
698 ::GpiMove(hPS
, &vPoint
[0]);
699 vPoint
[1].x
= rRect
.xRight
- 2;
700 vPoint
[1].y
= rRect
.yTop
- 2;
707 vLineBundle
.lColor
= 0x00FFFFFF; // BLACK
708 vLineBundle
.usMixMode
= FM_OVERPAINT
;
709 vLineBundle
.fxWidth
= 2;
710 vLineBundle
.lGeomWidth
= 2;
711 vLineBundle
.usType
= LINETYPE_SOLID
;
712 vLineBundle
.usEnd
= 0;
713 vLineBundle
.usJoin
= 0;
716 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
720 vPoint
[0].x
= rRect
.xLeft
+ 3;
721 vPoint
[0].y
= rRect
.yBottom
+ 3;
722 ::GpiMove(hPS
, &vPoint
[0]);
723 vPoint
[1].x
= rRect
.xRight
- 3;
724 vPoint
[1].y
= rRect
.yTop
- 3;
732 if (dwStyle
& wxRAISED_BORDER
)
734 LINEBUNDLE vLineBundle
;
736 vLineBundle
.lColor
= 0x00000000; // BLACK
737 vLineBundle
.usMixMode
= FM_OVERPAINT
;
738 vLineBundle
.fxWidth
= 2;
739 vLineBundle
.lGeomWidth
= 2;
740 vLineBundle
.usType
= LINETYPE_SOLID
;
741 vLineBundle
.usEnd
= 0;
742 vLineBundle
.usJoin
= 0;
745 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
749 vPoint
[1].x
= rRect
.xRight
- 1;
750 vPoint
[1].y
= rRect
.yTop
- 1;
757 vPoint
[0].x
= rRect
.xLeft
+ 1;
758 vPoint
[0].y
= rRect
.yBottom
+ 1;
759 ::GpiMove(hPS
, &vPoint
[0]);
760 vPoint
[1].x
= rRect
.xRight
- 2;
761 vPoint
[1].y
= rRect
.yTop
- 2;
769 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
770 vLineBundle
.usMixMode
= FM_OVERPAINT
;
771 vLineBundle
.fxWidth
= 2;
772 vLineBundle
.lGeomWidth
= 2;
773 vLineBundle
.usType
= LINETYPE_SOLID
;
774 vLineBundle
.usEnd
= 0;
775 vLineBundle
.usJoin
= 0;
778 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
782 vPoint
[0].x
= rRect
.xLeft
+ 2;
783 vPoint
[0].y
= rRect
.yBottom
+ 2;
784 ::GpiMove(hPS
, &vPoint
[0]);
785 vPoint
[1].x
= rRect
.xLeft
+ 2;
786 vPoint
[1].y
= rRect
.yTop
- 3;
787 ::GpiLine(hPS
, &vPoint
[1]);
788 vPoint
[1].x
= rRect
.xRight
- 3;
789 vPoint
[1].y
= rRect
.yTop
- 3;
790 ::GpiLine(hPS
, &vPoint
[1]);
792 vPoint
[0].x
= rRect
.xLeft
+ 3;
793 vPoint
[0].y
= rRect
.yBottom
+ 3;
794 ::GpiMove(hPS
, &vPoint
[0]);
795 vPoint
[1].x
= rRect
.xLeft
+ 3;
796 vPoint
[1].y
= rRect
.yTop
- 4;
797 ::GpiLine(hPS
, &vPoint
[1]);
798 vPoint
[1].x
= rRect
.xRight
- 4;
799 vPoint
[1].y
= rRect
.yTop
- 4;
800 ::GpiLine(hPS
, &vPoint
[1]);
802 } // end of wxDrawBorder
806 , const wxFont
& rFont
814 if (hWnd
== NULLHANDLE
)
818 // The fonts available for Presentation Params are just a few
819 // outline fonts, the rest are available to the GPI, so we must
820 // map the families to one of these three
822 switch(rFont
.GetFamily())
825 strcpy(zFacename
, "Script");
829 strcpy(zFacename
, "WarpSans");
833 strcpy(zFacename
,"Times New Roman");
837 strcpy(zFacename
, "Courier New");
841 strcpy(zFacename
, "Courier New");
847 strcpy(zFacename
, "Helvetica");
851 switch(rFont
.GetWeight())
860 case wxFONTWEIGHT_MAX
:
861 strcpy(zWeight
, "Bold");
865 switch(rFont
.GetStyle())
869 strcpy(zStyle
, "Italic");
876 sprintf(zFont
, "%d.%s", rFont
.GetPointSize(), zFacename
);
877 if (zWeight
[0] != '\0')
880 strcat(zFont
, zWeight
);
882 if (zStyle
[0] != '\0')
885 strcat(zFont
, zStyle
);
887 ::WinSetPresParam(hWnd
, PP_FONTNAMESIZE
, strlen(zFont
) + 1, (PVOID
)zFont
);
888 } // end of wxOS2SetFont
890 // ---------------------------------------------------------------------------
891 // Helper for taking a regular bitmap and giving it a disabled look
892 // ---------------------------------------------------------------------------
893 wxBitmap
wxDisableBitmap(
898 wxMask
* pMask
= rBmp
.GetMask();
901 return(wxNullBitmap
);
903 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
904 SIZEL vSize
= {0, 0};
905 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
906 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
907 BITMAPINFOHEADER2 vHeader
;
911 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
912 HBITMAP hOldBitmap
= NULLHANDLE
;
913 HBITMAP hOldMask
= NULLHANDLE
;
914 HBITMAP hMask
= (HBITMAP
)rBmp
.GetMask()->GetMaskBitmap();
915 unsigned char* pucBits
; // buffer that will contain the bitmap data
916 unsigned char* pucData
; // pointer to use to traverse bitmap data
917 unsigned char* pucBitsMask
; // buffer that will contain the mask data
918 unsigned char* pucDataMask
; // pointer to use to traverse mask data
921 bool bpp16
= (wxDisplayDepth() == 16);
923 memset(&vHeader
, '\0', 16);
926 memset(&vInfo
, '\0', 16);
928 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
929 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
931 vInfo
.cBitCount
= 24; // Set to desired count going in
934 // Create the buffers for data....all wxBitmaps are 24 bit internally
936 int nBytesPerLine
= rBmp
.GetWidth() * 3;
937 int nSizeDWORD
= sizeof(DWORD
);
938 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
944 // Bitmap must be in a double-word aligned address so we may
945 // have some padding to worry about
947 if (nLineBoundary
> 0)
949 nPadding
= nSizeDWORD
- nLineBoundary
;
950 nBytesPerLine
+= nPadding
;
952 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
953 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
954 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
955 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
958 // Extract the bitmap and mask data
960 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
962 vError
= ::WinGetLastError(vHabmain
);
963 sError
= wxPMErrorToStr(vError
);
965 ::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
);
966 vInfo
.cBitCount
= 24;
967 if ((lScans
= ::GpiQueryBitmapBits( hPS
969 ,(LONG
)rBmp
.GetHeight()
974 vError
= ::WinGetLastError(vHabmain
);
975 sError
= wxPMErrorToStr(vError
);
977 if ((hOldMask
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
979 vError
= ::WinGetLastError(vHabmain
);
980 sError
= wxPMErrorToStr(vError
);
982 ::GpiQueryBitmapInfoHeader(hMask
, &vHeader
);
983 vInfo
.cBitCount
= 24;
984 if ((lScans
= ::GpiQueryBitmapBits( hPS
986 ,(LONG
)rBmp
.GetHeight()
991 vError
= ::WinGetLastError(vHabmain
);
992 sError
= wxPMErrorToStr(vError
);
994 if (( hMask
= ::GpiSetBitmap(hPS
, hOldMask
)) == HBM_ERROR
)
996 vError
= ::WinGetLastError(vHabmain
);
997 sError
= wxPMErrorToStr(vError
);
1000 pucDataMask
= pucBitsMask
;
1003 // Get the mask value
1005 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1007 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1010 if (bpp16
&& *pucDataMask
== 0xF8) // 16 bit display gobblygook
1015 else if (*pucDataMask
== 0xFF) // set to grey
1022 *pucData
= ((unsigned char)(lColor
>> 16));
1027 if (bpp16
&& *(pucDataMask
+ 1) == 0xFC) // 16 bit display gobblygook
1032 else if (*(pucDataMask
+ 1) == 0xFF) // set to grey
1039 *pucData
= ((unsigned char)(lColor
>> 8));
1044 if (bpp16
&& *(pucDataMask
+ 2) == 0xF8) // 16 bit display gobblygook
1049 else if (*(pucDataMask
+ 2) == 0xFF) // set to grey
1056 *pucData
= ((unsigned char)lColor
);
1061 for (j
= 0; j
< nPadding
; j
++)
1069 // Create a new bitmap and set the modified bits
1071 wxBitmap
vNewBmp( rBmp
.GetWidth()
1075 HBITMAP hNewBmp
= (HBITMAP
)vNewBmp
.GetHBITMAP();
1077 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hNewBmp
)) == HBM_ERROR
)
1079 vError
= ::WinGetLastError(vHabmain
);
1080 sError
= wxPMErrorToStr(vError
);
1082 if ((lScansSet
= ::GpiSetBitmapBits( hPS
1084 ,(LONG
)rBmp
.GetHeight()
1090 vError
= ::WinGetLastError(vHabmain
);
1091 sError
= wxPMErrorToStr(vError
);
1095 pNewMask
= new wxMask(pMask
->GetMaskBitmap());
1096 vNewBmp
.SetMask(pNewMask
);
1098 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1099 ::GpiDestroyPS(hPS
);
1103 return(wxNullBitmap
);
1104 } // end of wxDisableBitmap
1106 COLORREF
wxColourToRGB(
1107 const wxColour
& rColor
1110 return(OS2RGB(rColor
.Red(), rColor
.Green(), rColor
.Blue()));
1111 } // end of wxColourToRGB