+ if (useMask)
+ {
+#ifdef __WIN32__
+ // we want the part of the image corresponding to the mask to be
+ // transparent, so use "DSTCOPY" ROP for the mask points (the usual
+ // meaning of fg and bg is inverted which corresponds to wxWin notion
+ // of the mask which is also contrary to the Windows one)
+ success = ::MaskBlt(GetHdc(), xdest, ydest, width, height,
+ GetHdcOf(*source), xsrc, ysrc,
+ (HBITMAP)mask->GetMaskBitmap(), xsrc, ysrc,
+ MAKEROP4(dwRop, DSTCOPY)) != 0;
+
+ if ( !success )
+#endif // Win32
+ {
+ // Blit bitmap with mask
+
+ // create a temp buffer bitmap and DCs to access it and the mask
+ HDC dc_mask = ::CreateCompatibleDC(GetHdcOf(*source));
+ HDC dc_buffer = ::CreateCompatibleDC(GetHdc());
+ HBITMAP buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
+ ::SelectObject(dc_mask, (HBITMAP) mask->GetMaskBitmap());
+ ::SelectObject(dc_buffer, buffer_bmap);
+
+ // copy dest to buffer
+ if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ GetHdc(), xdest, ydest, SRCCOPY) )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ // copy src to buffer using selected raster op
+ if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ GetHdcOf(*source), xsrc, ysrc, dwRop) )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ // 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));
+ if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ dc_mask, xsrc, ysrc, SRCAND) )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ // set unmasked area in dest to BLACK
+ ::SetBkColor(GetHdc(), RGB(0, 0, 0));
+ ::SetTextColor(GetHdc(), RGB(255, 255, 255));
+ if ( !::BitBlt(GetHdc(), xdest, ydest, (int)width, (int)height,
+ dc_mask, xsrc, ysrc, SRCAND) )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+ ::SetBkColor(GetHdc(), prevBkCol); // restore colours to original values
+ ::SetTextColor(GetHdc(), prevCol);
+
+ // OR buffer to dest
+ success = ::BitBlt(GetHdc(), xdest, ydest,
+ (int)width, (int)height,
+ dc_buffer, 0, 0, SRCPAINT) != 0;
+ if ( !success )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ // tidy up temporary DCs and bitmap
+ ::SelectObject(dc_mask, 0);
+ ::DeleteDC(dc_mask);
+ ::SelectObject(dc_buffer, 0);
+ ::DeleteDC(dc_buffer);
+ ::DeleteObject(buffer_bmap);
+ }
+ }
+ else // no mask, just BitBlt() it
+ {
+ success = ::BitBlt(GetHdc(), xdest, ydest,
+ (int)width, (int)height,
+ GetHdcOf(*source), xsrc, ysrc, dwRop) != 0;
+ if ( !success )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+ }
+ ::SetTextColor(GetHdc(), old_textground);
+ ::SetBkColor(GetHdc(), old_background);