+#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
+ {
+ // 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 we are printing, source colours are screen colours
+ // not printer colours and so we need copy the bitmap
+ // pixel by pixel.
+ if (IsKindOf(CLASSINFO(wxPrinterDC)))
+ {
+ HDC dc_src = (HDC) source->m_hDC;
+ RECT rect;
+ for (int y = 0; y < height; y++)
+ {
+ // This is Stefan Csomor's optimisation, where
+ // identical adjacent pixels are drawn together.
+ // We still need a faster way of drawing bitmaps,
+ // perhaps converting to a DIB first and using SetDIBitsToDevice.
+ for (int x = 0; x < width; x++)
+ {
+ COLORREF col = ::GetPixel(dc_src, x, y) ;
+ HBRUSH brush = ::CreateSolidBrush( col );
+
+ rect.left = xdest1 + x;
+ rect.top = ydest1 + y;
+ while( (x + 1 < width) && (::GetPixel(dc_src, x + 1, y) == col ) )
+ {
+ ++x ;
+ }
+ rect.right = xdest1 + x + 1;
+ rect.bottom = rect.top + 1;
+ ::FillRect((HDC) m_hDC, &rect, brush);
+ ::DeleteObject(brush);
+ }
+ }
+/*
+ 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;