+ wxCoord xdest1 = xdest;
+ wxCoord ydest1 = ydest;
+ wxCoord xsrc1 = xsrc;
+ wxCoord ysrc1 = ysrc;
+
+ // Chris Breeze 18/5/98: use text foreground/background colours
+ // when blitting from 1-bit bitmaps
+ COLORREF old_textground = ::GetTextColor(GetHdc());
+ COLORREF old_background = ::GetBkColor(GetHdc());
+ if (m_textForegroundColour.Ok())
+ {
+ ::SetTextColor(GetHdc(), m_textForegroundColour.GetPixel() );
+ }
+ if (m_textBackgroundColour.Ok())
+ {
+ ::SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() );
+ }
+
+ DWORD dwRop = rop == wxCOPY ? SRCCOPY :
+ rop == wxCLEAR ? WHITENESS :
+ rop == wxSET ? BLACKNESS :
+ rop == wxINVERT ? DSTINVERT :
+ rop == wxAND ? MERGECOPY :
+ rop == wxOR ? MERGEPAINT :
+ rop == wxSRC_INVERT ? NOTSRCCOPY :
+ rop == wxXOR ? SRCINVERT :
+ rop == wxOR_REVERSE ? MERGEPAINT :
+ rop == wxAND_REVERSE ? SRCERASE :
+ rop == wxSRC_OR ? SRCPAINT :
+ rop == wxSRC_AND ? SRCAND :
+ SRCCOPY;
+
+ bool success = TRUE;
+ if (useMask && source->m_selectedBitmap.Ok() && source->m_selectedBitmap.GetMask())
+ {
+
+#if 0 // __WIN32__
+ // Not implemented under Win95 (or maybe a specific device?)
+ if (MaskBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
+ (HDC) source->m_hDC, xsrc1, ysrc1, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap(),
+ 0, 0, 0xAACC0020))
+ {
+ // Success
+ }
+ else
+#endif
+ {
+ // Old code
+#if 0
+ HDC dc_mask = CreateCompatibleDC((HDC) source->m_hDC);
+ ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
+ success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
+ dc_mask, xsrc1, ysrc1, 0x00220326 /* NOTSRCAND */) != 0);
+ success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
+ (HDC) source->m_hDC, xsrc1, ysrc1, SRCPAINT) != 0);
+ ::SelectObject(dc_mask, 0);
+ ::DeleteDC(dc_mask);
+#endif
+ // New code from Chris Breeze, 15/7/98
+ // Blit bitmap with mask
+
+ if (IsKindOf(CLASSINFO(wxPrinterDC)))
+ {
+ // If we are printing source colours are screen colours
+ // not printer colours and so we need copy the bitmap
+ // pixel by pixel.
+ RECT rect;
+ HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC);
+ HDC dc_src = (HDC) source->m_hDC;
+
+ ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
+ for (int x = 0; x < width; x++)
+ {
+ for (int y = 0; y < height; y++)
+ {
+ COLORREF cref = ::GetPixel(dc_mask, x, y);
+ if (cref)
+ {
+ HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y));
+ rect.left = xdest1 + x; rect.right = rect.left + 1;
+ rect.top = ydest1 + y; rect.bottom = rect.top + 1;
+ ::FillRect(GetHdc(), &rect, brush);
+ ::DeleteObject(brush);
+ }
+ }
+ }
+ ::SelectObject(dc_mask, 0);
+ ::DeleteDC(dc_mask);
+ }
+ else
+ {
+ // create a temp buffer bitmap and DCs to access it and the mask
+ HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC);
+ HDC dc_buffer = ::CreateCompatibleDC(GetHdc());
+ HBITMAP buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
+ ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
+ ::SelectObject(dc_buffer, buffer_bmap);
+
+ // copy dest to buffer
+ ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ GetHdc(), xdest1, ydest1, SRCCOPY);
+
+ // copy src to buffer using selected raster op
+ ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ (HDC) source->m_hDC, xsrc1, ysrc1, dwRop);
+
+ // set masked area in buffer to BLACK (pixel value 0)
+ COLORREF prevBkCol = ::SetBkColor(GetHdc(), RGB(255, 255, 255));
+ COLORREF prevCol = ::SetTextColor(GetHdc(), RGB(0, 0, 0));
+ ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ dc_mask, xsrc1, ysrc1, SRCAND);
+
+ // set unmasked area in dest to BLACK
+ ::SetBkColor(GetHdc(), RGB(0, 0, 0));
+ ::SetTextColor(GetHdc(), RGB(255, 255, 255));
+ ::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
+ dc_mask, xsrc1, ysrc1, SRCAND);
+ ::SetBkColor(GetHdc(), prevBkCol); // restore colours to original values
+ ::SetTextColor(GetHdc(), prevCol);
+
+ // OR buffer to dest
+ success = (::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
+ dc_buffer, 0, 0, SRCPAINT) != 0);
+
+ // tidy up temporary DCs and bitmap
+ ::SelectObject(dc_mask, 0);
+ ::DeleteDC(dc_mask);
+ ::SelectObject(dc_buffer, 0);
+ ::DeleteDC(dc_buffer);
+ ::DeleteObject(buffer_bmap);
+ }
+ }
+ }
+ else
+ {
+ if (IsKindOf(CLASSINFO(wxPrinterDC)))
+ {
+ // If we are printing, source colours are screen colours
+ // not printer colours and so we need copy the bitmap
+ // pixel by pixel.
+ HDC dc_src = (HDC) source->m_hDC;
+ RECT rect;
+ for (int x = 0; x < width; x++)
+ {
+ for (int y = 0; y < height; y++)
+ {
+ HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y));
+ rect.left = xdest1 + x; rect.right = rect.left + 1;
+ rect.top = ydest1 + y; rect.bottom = rect.top + 1;
+ ::FillRect(GetHdc(), &rect, brush);
+ ::DeleteObject(brush);
+ }
+ }
+ }
+ else
+ {
+ success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC,
+ xsrc1, ysrc1, dwRop) != 0);
+ }
+ }
+ ::SetTextColor(GetHdc(), old_textground);
+ ::SetBkColor(GetHdc(), old_background);
+
+ return success;