1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
30 #include "wx/cursor.h"
34 #include "wx/apptrait.h"
36 #include "wx/os2/private.h" // includes <windows.h>
38 // ============================================================================
40 // ============================================================================
42 // ----------------------------------------------------------------------------
43 // functions to work with .INI files
44 // ----------------------------------------------------------------------------
46 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
47 static bool inTimer
= false;
49 class wxSleepTimer
: public wxTimer
59 // Reading and writing resources (eg WIN.INI, .Xdefaults)
61 bool wxWriteResource( const wxString
& rSection
,
62 const wxString
& rEntry
,
63 const wxString
& rValue
,
64 const wxString
& rFile
)
71 hIni
= ::PrfOpenProfile(hab
, (PSZ
)WXSTRINGCAST rFile
);
74 return (::PrfWriteProfileString( hIni
75 ,(PSZ
)WXSTRINGCAST rSection
76 ,(PSZ
)WXSTRINGCAST rEntry
77 ,(PSZ
)WXSTRINGCAST rValue
82 return (::PrfWriteProfileString( HINI_PROFILE
83 ,(PSZ
)WXSTRINGCAST rSection
84 ,(PSZ
)WXSTRINGCAST rEntry
85 ,(PSZ
)WXSTRINGCAST rValue
91 const wxString
& rSection
92 , const wxString
& rEntry
94 , const wxString
& rFile
99 wxSprintf(zBuf
, "%.4f", fValue
);
100 return wxWriteResource( rSection
107 bool wxWriteResource(
108 const wxString
& rSection
109 , const wxString
& rEntry
111 , const wxString
& rFile
116 wxSprintf(zBuf
, "%ld", lValue
);
117 return wxWriteResource( rSection
124 bool wxWriteResource( const wxString
& rSection
,
125 const wxString
& rEntry
,
127 const wxString
& rFile
)
131 wxSprintf(zBuf
, "%d", lValue
);
132 return wxWriteResource( rSection
, rEntry
, zBuf
, rFile
);
135 bool wxGetResource( const wxString
& rSection
,
136 const wxString
& rEntry
,
138 const wxString
& rFile
)
142 wxChar zDefunkt
[] = _T("$$default");
147 hIni
= ::PrfOpenProfile(hab
, (PSZ
)WXSTRINGCAST rFile
);
150 ULONG n
= ::PrfQueryProfileString( hIni
151 ,(PSZ
)WXSTRINGCAST rSection
152 ,(PSZ
)WXSTRINGCAST rEntry
159 if (n
== 0L || wxStrcmp(zBuf
, zDefunkt
) == 0)
168 ULONG n
= ::PrfQueryProfileString( HINI_PROFILE
169 ,(PSZ
)WXSTRINGCAST rSection
170 ,(PSZ
)WXSTRINGCAST rEntry
177 if (n
== 0L || wxStrcmp(zBuf
, zDefunkt
) == 0)
181 strcpy((char*)*ppValue
, zBuf
);
185 bool wxGetResource( const wxString
& rSection
,
186 const wxString
& rEntry
,
188 const wxString
& rFile
)
192 zStr
= new wxChar
[1000];
193 bool bSucc
= wxGetResource( rSection
, rEntry
, (wxChar
**)&zStr
, rFile
);
197 *pValue
= (float)wxStrtod(zStr
, NULL
);
204 bool wxGetResource( const wxString
& rSection
,
205 const wxString
& rEntry
,
207 const wxString
& rFile
)
211 zStr
= new wxChar
[1000];
212 bool bSucc
= wxGetResource( rSection
, rEntry
, (wxChar
**)&zStr
, rFile
);
216 *pValue
= wxStrtol(zStr
, NULL
, 10);
223 bool wxGetResource( const wxString
& rSection
,
224 const wxString
& rEntry
,
226 const wxString
& rFile
)
230 zStr
= new wxChar
[1000];
231 bool bSucc
= wxGetResource( rSection
, rEntry
, (wxChar
**)&zStr
, rFile
);
235 *pValue
= (int)wxStrtol(zStr
, NULL
, 10);
241 #endif // wxUSE_RESOURCES
243 // ---------------------------------------------------------------------------
244 // helper functions for showing a "busy" cursor
245 // ---------------------------------------------------------------------------
247 HCURSOR gs_wxBusyCursor
= 0; // new, busy cursor
248 HCURSOR gs_wxBusyCursorOld
= 0; // old cursor
249 static int gs_wxBusyCursorCount
= 0;
251 // Set the cursor to the busy cursor for all windows
252 void wxBeginBusyCursor(const wxCursor
* pCursor
)
254 if ( gs_wxBusyCursorCount
++ == 0 )
256 gs_wxBusyCursor
= (HCURSOR
)pCursor
->GetHCURSOR();
257 ::WinSetPointer(HWND_DESKTOP
, (HPOINTER
)gs_wxBusyCursor
);
259 //else: nothing to do, already set
262 // Restore cursor to normal
263 void wxEndBusyCursor()
265 wxCHECK_RET( gs_wxBusyCursorCount
> 0
266 ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()")
269 if (--gs_wxBusyCursorCount
== 0)
271 ::WinSetPointer(HWND_DESKTOP
, (HPOINTER
)gs_wxBusyCursorOld
);
272 gs_wxBusyCursorOld
= 0;
276 // true if we're between the above two calls
279 return (gs_wxBusyCursorCount
> 0);
282 // Check whether this window wants to process messages, e.g. Stop button
283 // in long calculations.
284 bool wxCheckForInterrupt( wxWindow
* pWnd
)
290 HWND hwndFilter
= NULLHANDLE
;
292 while(::WinPeekMsg(hab
, &vMsg
, hwndFilter
, 0, 0, PM_REMOVE
))
294 ::WinDispatchMsg(hab
, &vMsg
);
296 return true;//*** temporary?
300 wxFAIL_MSG(_T("pWnd==NULL !!!"));
301 return false;//*** temporary?
305 // ----------------------------------------------------------------------------
307 // ----------------------------------------------------------------------------
309 // See also the wxGetMousePosition in window.cpp
310 // Deprecated: use wxPoint wxGetMousePosition() instead
311 void wxGetMousePosition(
318 ::WinQueryPointerPos(HWND_DESKTOP
, &vPt
);
323 // Return true if we have a colour display
324 bool wxColourDisplay()
331 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
332 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
333 ::DevQueryCaps(hdcScreen
, CAPS_COLORS
, 1L, &lColors
);
334 return(lColors
> 1L);
336 // I don't see how the PM display could not be color. Besides, this
337 // was leaking DCs and PSs!!! MN
342 // Returns depth of screen
349 static LONG nDepth
= 0;
351 // The screen colordepth ain't gonna change. No reason to query
354 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
355 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
356 ::DevQueryCaps(hdcScreen
, CAPS_COLOR_PLANES
, 1L, &lPlanes
);
357 ::DevQueryCaps(hdcScreen
, CAPS_COLOR_BITCOUNT
, 1L, &lBitsPerPixel
);
359 nDepth
= (int)(lPlanes
* lBitsPerPixel
);
360 ::DevCloseDC(hdcScreen
);
361 ::WinReleasePS(hpsScreen
);
366 // Get size of display
374 static LONG lWidth
= 0;
375 static LONG lHeight
= 0;
377 // The screen size ain't gonna change either so just cache the values
379 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
380 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
381 ::DevQueryCaps(hdcScreen
, CAPS_WIDTH
, 1L, &lWidth
);
382 ::DevQueryCaps(hdcScreen
, CAPS_HEIGHT
, 1L, &lHeight
);
383 ::DevCloseDC(hdcScreen
);
384 ::WinReleasePS(hpsScreen
);
387 *pWidth
= (int)lWidth
;
389 *pHeight
= (int)lHeight
;
392 void wxDisplaySizeMM(
400 hpsScreen
= ::WinGetScreenPS(HWND_DESKTOP
);
401 hdcScreen
= ::GpiQueryDevice(hpsScreen
);
404 ::DevQueryCaps( hdcScreen
405 ,CAPS_HORIZONTAL_RESOLUTION
410 ::DevQueryCaps( hdcScreen
411 ,CAPS_VERTICAL_RESOLUTION
415 ::DevCloseDC(hdcScreen
);
416 ::WinReleasePS(hpsScreen
);
419 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
421 // This is supposed to return desktop dimensions minus any window
422 // manager panels, menus, taskbars, etc. If there is a way to do that
423 // for this platform please fix this function, otherwise it defaults
424 // to the entire desktop.
427 wxDisplaySize(width
, height
);
430 void wxGUIAppTraits::InitializeGui(unsigned long &ulHab
)
432 ulHab
= ::WinInitialize(0);
435 void wxGUIAppTraits::TerminateGui(unsigned long ulHab
)
437 ::WinTerminate(ulHab
);
440 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
442 // TODO: how to get version of PM ?
447 // ---------------------------------------------------------------------------
448 // window information functions
449 // ---------------------------------------------------------------------------
451 wxString WXDLLEXPORT
wxGetWindowText( WXHWND hWnd
)
457 long lLen
= ::WinQueryWindowTextLength((HWND
)hWnd
) + 1;
458 ::WinQueryWindowText((HWND
)hWnd
, lLen
, (PSZ
)(wxChar
*)wxStringBuffer(vStr
, lLen
));
464 wxString WXDLLEXPORT
wxGetWindowClass( WXHWND hWnd
)
469 int nLen
= 256; // some starting value
473 int nCount
= ::WinQueryClassName((HWND
)hWnd
, nLen
, (PSZ
)(wxChar
*)wxStringBuffer(vStr
, nLen
));
477 // the class name might have been truncated, retry with larger
490 WXWORD WXDLLEXPORT
wxGetWindowId(
494 return ::WinQueryWindowUShort((HWND
)hWnd
, QWS_ID
);
505 vPoint
[0].x
= rRect
.xLeft
;
506 vPoint
[0].y
= rRect
.yBottom
;
507 ::GpiMove(hPS
, &vPoint
[0]);
508 if (dwStyle
& wxSIMPLE_BORDER
||
509 dwStyle
& wxSTATIC_BORDER
)
511 vPoint
[1].x
= rRect
.xRight
- 1;
512 vPoint
[1].y
= rRect
.yTop
- 1;
520 if (dwStyle
& wxSUNKEN_BORDER
)
522 LINEBUNDLE vLineBundle
;
524 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
525 vLineBundle
.usMixMode
= FM_OVERPAINT
;
526 vLineBundle
.fxWidth
= 2;
527 vLineBundle
.lGeomWidth
= 2;
528 vLineBundle
.usType
= LINETYPE_SOLID
;
529 vLineBundle
.usEnd
= 0;
530 vLineBundle
.usJoin
= 0;
533 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
537 vPoint
[1].x
= rRect
.xRight
- 1;
538 vPoint
[1].y
= rRect
.yTop
- 1;
545 vPoint
[0].x
= rRect
.xLeft
+ 1;
546 vPoint
[0].y
= rRect
.yBottom
+ 1;
547 ::GpiMove(hPS
, &vPoint
[0]);
548 vPoint
[1].x
= rRect
.xRight
- 2;
549 vPoint
[1].y
= rRect
.yTop
- 2;
557 vLineBundle
.lColor
= 0x00000000; // BLACK
558 vLineBundle
.usMixMode
= FM_OVERPAINT
;
559 vLineBundle
.fxWidth
= 2;
560 vLineBundle
.lGeomWidth
= 2;
561 vLineBundle
.usType
= LINETYPE_SOLID
;
562 vLineBundle
.usEnd
= 0;
563 vLineBundle
.usJoin
= 0;
566 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
570 vPoint
[0].x
= rRect
.xLeft
+ 2;
571 vPoint
[0].y
= rRect
.yBottom
+ 2;
572 ::GpiMove(hPS
, &vPoint
[0]);
573 vPoint
[1].x
= rRect
.xLeft
+ 2;
574 vPoint
[1].y
= rRect
.yTop
- 3;
575 ::GpiLine(hPS
, &vPoint
[1]);
576 vPoint
[1].x
= rRect
.xRight
- 3;
577 vPoint
[1].y
= rRect
.yTop
- 3;
578 ::GpiLine(hPS
, &vPoint
[1]);
580 vPoint
[0].x
= rRect
.xLeft
+ 3;
581 vPoint
[0].y
= rRect
.yBottom
+ 3;
582 ::GpiMove(hPS
, &vPoint
[0]);
583 vPoint
[1].x
= rRect
.xLeft
+ 3;
584 vPoint
[1].y
= rRect
.yTop
- 4;
585 ::GpiLine(hPS
, &vPoint
[1]);
586 vPoint
[1].x
= rRect
.xRight
- 4;
587 vPoint
[1].y
= rRect
.yTop
- 4;
588 ::GpiLine(hPS
, &vPoint
[1]);
590 if (dwStyle
& wxDOUBLE_BORDER
)
592 LINEBUNDLE vLineBundle
;
594 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
595 vLineBundle
.usMixMode
= FM_OVERPAINT
;
596 vLineBundle
.fxWidth
= 2;
597 vLineBundle
.lGeomWidth
= 2;
598 vLineBundle
.usType
= LINETYPE_SOLID
;
599 vLineBundle
.usEnd
= 0;
600 vLineBundle
.usJoin
= 0;
603 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
607 vPoint
[1].x
= rRect
.xRight
- 1;
608 vPoint
[1].y
= rRect
.yTop
- 1;
615 vLineBundle
.lColor
= 0x00000000; // WHITE
616 vLineBundle
.usMixMode
= FM_OVERPAINT
;
617 vLineBundle
.fxWidth
= 2;
618 vLineBundle
.lGeomWidth
= 2;
619 vLineBundle
.usType
= LINETYPE_SOLID
;
620 vLineBundle
.usEnd
= 0;
621 vLineBundle
.usJoin
= 0;
624 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
628 vPoint
[0].x
= rRect
.xLeft
+ 2;
629 vPoint
[0].y
= rRect
.yBottom
+ 2;
630 ::GpiMove(hPS
, &vPoint
[0]);
631 vPoint
[1].x
= rRect
.xRight
- 2;
632 vPoint
[1].y
= rRect
.yTop
- 2;
639 vLineBundle
.lColor
= 0x00FFFFFF; // BLACK
640 vLineBundle
.usMixMode
= FM_OVERPAINT
;
641 vLineBundle
.fxWidth
= 2;
642 vLineBundle
.lGeomWidth
= 2;
643 vLineBundle
.usType
= LINETYPE_SOLID
;
644 vLineBundle
.usEnd
= 0;
645 vLineBundle
.usJoin
= 0;
648 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
652 vPoint
[0].x
= rRect
.xLeft
+ 3;
653 vPoint
[0].y
= rRect
.yBottom
+ 3;
654 ::GpiMove(hPS
, &vPoint
[0]);
655 vPoint
[1].x
= rRect
.xRight
- 3;
656 vPoint
[1].y
= rRect
.yTop
- 3;
664 if (dwStyle
& wxRAISED_BORDER
)
666 LINEBUNDLE vLineBundle
;
668 vLineBundle
.lColor
= 0x00000000; // BLACK
669 vLineBundle
.usMixMode
= FM_OVERPAINT
;
670 vLineBundle
.fxWidth
= 2;
671 vLineBundle
.lGeomWidth
= 2;
672 vLineBundle
.usType
= LINETYPE_SOLID
;
673 vLineBundle
.usEnd
= 0;
674 vLineBundle
.usJoin
= 0;
677 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
681 vPoint
[1].x
= rRect
.xRight
- 1;
682 vPoint
[1].y
= rRect
.yTop
- 1;
689 vPoint
[0].x
= rRect
.xLeft
+ 1;
690 vPoint
[0].y
= rRect
.yBottom
+ 1;
691 ::GpiMove(hPS
, &vPoint
[0]);
692 vPoint
[1].x
= rRect
.xRight
- 2;
693 vPoint
[1].y
= rRect
.yTop
- 2;
701 vLineBundle
.lColor
= 0x00FFFFFF; // WHITE
702 vLineBundle
.usMixMode
= FM_OVERPAINT
;
703 vLineBundle
.fxWidth
= 2;
704 vLineBundle
.lGeomWidth
= 2;
705 vLineBundle
.usType
= LINETYPE_SOLID
;
706 vLineBundle
.usEnd
= 0;
707 vLineBundle
.usJoin
= 0;
710 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
714 vPoint
[0].x
= rRect
.xLeft
+ 2;
715 vPoint
[0].y
= rRect
.yBottom
+ 2;
716 ::GpiMove(hPS
, &vPoint
[0]);
717 vPoint
[1].x
= rRect
.xLeft
+ 2;
718 vPoint
[1].y
= rRect
.yTop
- 3;
719 ::GpiLine(hPS
, &vPoint
[1]);
720 vPoint
[1].x
= rRect
.xRight
- 3;
721 vPoint
[1].y
= rRect
.yTop
- 3;
722 ::GpiLine(hPS
, &vPoint
[1]);
724 vPoint
[0].x
= rRect
.xLeft
+ 3;
725 vPoint
[0].y
= rRect
.yBottom
+ 3;
726 ::GpiMove(hPS
, &vPoint
[0]);
727 vPoint
[1].x
= rRect
.xLeft
+ 3;
728 vPoint
[1].y
= rRect
.yTop
- 4;
729 ::GpiLine(hPS
, &vPoint
[1]);
730 vPoint
[1].x
= rRect
.xRight
- 4;
731 vPoint
[1].y
= rRect
.yTop
- 4;
732 ::GpiLine(hPS
, &vPoint
[1]);
734 } // end of wxDrawBorder
738 , const wxFont
& rFont
746 if (hWnd
== NULLHANDLE
)
750 // The fonts available for Presentation Params are just a few
751 // outline fonts, the rest are available to the GPI, so we must
752 // map the families to one of these three
754 switch(rFont
.GetFamily())
757 strcpy(zFacename
, "Script");
761 strcpy(zFacename
, "WarpSans");
765 strcpy(zFacename
,"Times New Roman");
769 strcpy(zFacename
, "Courier New");
773 strcpy(zFacename
, "Courier New");
779 strcpy(zFacename
, "Helvetica");
783 switch(rFont
.GetWeight())
792 case wxFONTWEIGHT_MAX
:
793 strcpy(zWeight
, "Bold");
797 switch(rFont
.GetStyle())
801 strcpy(zStyle
, "Italic");
808 sprintf(zFont
, "%d.%s", rFont
.GetPointSize(), zFacename
);
809 if (zWeight
[0] != '\0')
812 strcat(zFont
, zWeight
);
814 if (zStyle
[0] != '\0')
817 strcat(zFont
, zStyle
);
819 ::WinSetPresParam(hWnd
, PP_FONTNAMESIZE
, strlen(zFont
) + 1, (PVOID
)zFont
);
820 } // end of wxOS2SetFont
822 // ---------------------------------------------------------------------------
823 // Helper for taking a regular bitmap and giving it a disabled look
824 // ---------------------------------------------------------------------------
825 wxBitmap
wxDisableBitmap(
830 wxMask
* pMask
= rBmp
.GetMask();
833 return(wxNullBitmap
);
835 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
836 SIZEL vSize
= {0, 0};
837 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
838 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
839 BITMAPINFOHEADER2 vHeader
;
843 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
844 HBITMAP hOldBitmap
= NULLHANDLE
;
845 HBITMAP hOldMask
= NULLHANDLE
;
846 HBITMAP hMask
= (HBITMAP
)rBmp
.GetMask()->GetMaskBitmap();
847 unsigned char* pucBits
; // buffer that will contain the bitmap data
848 unsigned char* pucData
; // pointer to use to traverse bitmap data
849 unsigned char* pucBitsMask
; // buffer that will contain the mask data
850 unsigned char* pucDataMask
; // pointer to use to traverse mask data
853 bool bpp16
= (wxDisplayDepth() == 16);
855 memset(&vHeader
, '\0', 16);
858 memset(&vInfo
, '\0', 16);
860 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
861 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
863 vInfo
.cBitCount
= 24; // Set to desired count going in
866 // Create the buffers for data....all wxBitmaps are 24 bit internally
868 int nBytesPerLine
= rBmp
.GetWidth() * 3;
869 int nSizeDWORD
= sizeof(DWORD
);
870 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
876 // Bitmap must be in a double-word aligned address so we may
877 // have some padding to worry about
879 if (nLineBoundary
> 0)
881 nPadding
= nSizeDWORD
- nLineBoundary
;
882 nBytesPerLine
+= nPadding
;
884 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
885 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
886 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
887 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
890 // Extract the bitmap and mask data
892 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
894 vError
= ::WinGetLastError(vHabmain
);
895 sError
= wxPMErrorToStr(vError
);
897 ::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
);
898 vInfo
.cBitCount
= 24;
899 if ((lScans
= ::GpiQueryBitmapBits( hPS
901 ,(LONG
)rBmp
.GetHeight()
906 vError
= ::WinGetLastError(vHabmain
);
907 sError
= wxPMErrorToStr(vError
);
909 if ((hOldMask
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
911 vError
= ::WinGetLastError(vHabmain
);
912 sError
= wxPMErrorToStr(vError
);
914 ::GpiQueryBitmapInfoHeader(hMask
, &vHeader
);
915 vInfo
.cBitCount
= 24;
916 if ((lScans
= ::GpiQueryBitmapBits( hPS
918 ,(LONG
)rBmp
.GetHeight()
923 vError
= ::WinGetLastError(vHabmain
);
924 sError
= wxPMErrorToStr(vError
);
926 if (( hMask
= ::GpiSetBitmap(hPS
, hOldMask
)) == HBM_ERROR
)
928 vError
= ::WinGetLastError(vHabmain
);
929 sError
= wxPMErrorToStr(vError
);
932 pucDataMask
= pucBitsMask
;
935 // Get the mask value
937 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
939 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
942 if (bpp16
&& *pucDataMask
== 0xF8) // 16 bit display gobblygook
947 else if (*pucDataMask
== 0xFF) // set to grey
954 *pucData
= ((unsigned char)(lColor
>> 16));
959 if (bpp16
&& *(pucDataMask
+ 1) == 0xFC) // 16 bit display gobblygook
964 else if (*(pucDataMask
+ 1) == 0xFF) // set to grey
971 *pucData
= ((unsigned char)(lColor
>> 8));
976 if (bpp16
&& *(pucDataMask
+ 2) == 0xF8) // 16 bit display gobblygook
981 else if (*(pucDataMask
+ 2) == 0xFF) // set to grey
988 *pucData
= ((unsigned char)lColor
);
993 for (j
= 0; j
< nPadding
; j
++)
1001 // Create a new bitmap and set the modified bits
1003 wxBitmap
vNewBmp( rBmp
.GetWidth()
1007 HBITMAP hNewBmp
= (HBITMAP
)vNewBmp
.GetHBITMAP();
1009 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hNewBmp
)) == HBM_ERROR
)
1011 vError
= ::WinGetLastError(vHabmain
);
1012 sError
= wxPMErrorToStr(vError
);
1014 if ((lScansSet
= ::GpiSetBitmapBits( hPS
1016 ,(LONG
)rBmp
.GetHeight()
1022 vError
= ::WinGetLastError(vHabmain
);
1023 sError
= wxPMErrorToStr(vError
);
1027 pNewMask
= new wxMask(pMask
->GetMaskBitmap());
1028 vNewBmp
.SetMask(pNewMask
);
1030 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1031 ::GpiDestroyPS(hPS
);
1035 return(wxNullBitmap
);
1036 } // end of wxDisableBitmap
1038 COLORREF
wxColourToRGB(
1039 const wxColour
& rColor
1042 return(OS2RGB(rColor
.Red(), rColor
.Green(), rColor
.Blue()));
1043 } // end of wxColourToRGB