+bool wxDC::DoBlit(
+ wxCoord vXdest
+, wxCoord vYdest
+, wxCoord vWidth
+, wxCoord vHeight
+, wxDC* pSource
+, wxCoord vXsrc
+, wxCoord vYsrc
+, int nRop
+, bool bUseMask
+)
+{
+ wxMask* pMask = NULL;
+ CHARBUNDLE vCbnd;
+ COLORREF vOldTextColor;
+ COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
+
+ if (bUseMask)
+ {
+ const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
+
+ pMask = rBmp.GetMask();
+ if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
+ {
+ bUseMask = FALSE;
+ }
+ }
+
+ ::GpiQueryAttrs( m_hPS
+ ,PRIM_CHAR
+ ,CBB_COLOR
+ ,&vCbnd
+ );
+ vOldTextColor = (COLORREF)vCbnd.lColor;
+
+ if (m_textForegroundColour.Ok())
+ {
+ vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
+ ::GpiSetAttrs( m_hPS // presentation-space handle
+ ,PRIM_CHAR // Char primitive.
+ ,CBB_COLOR // sets color.
+ ,0
+ ,&vCbnd // buffer for attributes.
+ );
+ }
+ if (m_textBackgroundColour.Ok())
+ {
+ ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
+ }
+
+ LONG lRop = ROP_SRCCOPY;
+
+ switch (nRop)
+ {
+ case wxXOR: lRop = ROP_SRCINVERT; break;
+ case wxINVERT: lRop = ROP_DSTINVERT; break;
+ case wxOR_REVERSE: lRop = 0x00DD0228; break;
+ case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
+ case wxCLEAR: lRop = ROP_ZERO; break;
+ case wxSET: lRop = ROP_ONE; break;
+ case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
+ case wxAND: lRop = ROP_SRCAND; break;
+ case wxOR: lRop = ROP_SRCPAINT; break;
+ case wxEQUIV: lRop = 0x00990066; break;
+ case wxNAND: lRop = 0x007700E6; break;
+ case wxAND_INVERT: lRop = 0x00220326; break;
+ case wxCOPY: lRop = ROP_SRCCOPY; break;
+ case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
+ case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
+ case wxNOR: lRop = ROP_NOTSRCCOPY; break;
+ default:
+ wxFAIL_MSG( wxT("unsupported logical function") );
+ return FALSE;
+ }
+
+ bool bSuccess;
+
+ if (bUseMask)
+ {
+ //
+ // Blit bitmap with mask
+ //
+
+ //
+ // Create a temp buffer bitmap and DCs/PSs to access it and the mask
+ //
+ HDC hDCMask;
+ HDC hDCBuffer;
+ HPS hPSMask;
+ HPS hPSBuffer;
+ DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
+ BITMAPINFOHEADER2 vBmpHdr;
+ SIZEL vSize = {0, 0};
+ LONG rc;
+
+ hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
+ hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
+ hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
+ hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
+
+ memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
+ vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
+ vBmpHdr.cx = vWidth;
+ vBmpHdr.cy = vHeight;
+ vBmpHdr.cPlanes = 1;
+ vBmpHdr.cBitCount = 24;
+
+ HBITMAP hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
+ POINTL aPoint1[4] = { 0, 0
+ ,vWidth, vHeight
+ ,vXdest, vYdest
+ ,vXdest + vWidth, vYdest + vHeight
+ };
+ POINTL aPoint2[4] = { 0, 0
+ ,vWidth, vHeight
+ ,vXsrc, vYsrc
+ ,vXsrc + vWidth, vYsrc + vHeight
+ };
+ POINTL aPoint3[4] = { vXdest, vYdest
+ ,vXdest + vWidth, vYdest + vHeight
+ ,vXsrc, vYsrc
+ ,vXsrc + vWidth, vYsrc + vHeight
+ };
+ POINTL aPoint4[4] = { vXdest, vYdest
+ ,vXdest + vWidth, vYdest + vHeight
+ ,0, 0
+ ,vWidth, vHeight
+ };
+ ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
+ ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
+
+ //
+ // Copy dest to buffer
+ //
+ rc = ::GpiBitBlt( hPSBuffer
+ ,GetHPS()
+ ,4L
+ ,aPoint1
+ ,ROP_SRCCOPY
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Copy src to buffer using selected raster op
+ //
+ rc = ::GpiBitBlt( hPSBuffer
+ ,GetHPS()
+ ,4L
+ ,aPoint2
+ ,lRop
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Set masked area in buffer to BLACK (pixel value 0)
+ //
+ COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
+ COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
+
+ ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
+ ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
+
+ rc = ::GpiBitBlt( hPSBuffer
+ ,hPSMask
+ ,4L
+ ,aPoint2
+ ,ROP_SRCAND
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Set unmasked area in dest to BLACK
+ //
+ ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
+ ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
+ rc = ::GpiBitBlt( GetHPS()
+ ,hPSMask
+ ,4L
+ ,aPoint3
+ ,ROP_SRCAND
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Restore colours to original values
+ //
+ ::GpiSetBackColor(GetHPS(), vPrevBkCol);
+ ::GpiSetColor(GetHPS(), vPrevCol);
+
+ //
+ // OR buffer to dest
+ //
+ rc = ::GpiBitBlt( GetHPS()
+ ,hPSMask
+ ,4L
+ ,aPoint4
+ ,ROP_SRCPAINT
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ bSuccess = FALSE;
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Tidy up temporary DCs and bitmap
+ //
+ ::GpiSetBitmap(hPSMask, NULLHANDLE);
+ ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
+ ::GpiDestroyPS(hPSMask);
+ ::GpiDestroyPS(hPSBuffer);
+ ::DevCloseDC(hDCMask);
+ ::DevCloseDC(hDCBuffer);
+ ::GpiDeleteBitmap(hBufBitmap);
+ bSuccess = TRUE;
+ }
+ else // no mask, just BitBlt() it
+ {
+ POINTL aPoint[4] = { vXdest, vYdest
+ ,vXdest + vWidth, vYdest + vHeight
+ ,vXsrc, vYsrc
+ ,vXsrc + vWidth, vYsrc + vHeight
+ };
+
+ bSuccess = (::GpiBitBlt( m_hPS
+ ,pSource->GetHPS()
+ ,4L
+ ,aPoint
+ ,lRop
+ ,BBO_IGNORE
+ ) != GPI_ERROR);
+ if (!bSuccess )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+ }
+ vCbnd.lColor = (LONG)vOldTextColor;
+ ::GpiSetAttrs( m_hPS // presentation-space handle
+ ,PRIM_CHAR // Char primitive.
+ ,CBB_COLOR // sets color.
+ ,0
+ ,&vCbnd // buffer for attributes.
+ );
+ ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
+ return bSuccess;