#include <string.h>
#include <math.h>
+#include "wx/msw/private.h" // needs to be before #include <commdlg.h>
+
#if wxUSE_COMMON_DIALOGS
#if wxUSE_NORLANDER_HEADERS
#include <windows.h>
#include <print.h>
#endif
-#include "wx/msw/private.h"
-
- IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
+IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
// ---------------------------------------------------------------------------
// constants
}
else
{
- wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
+ // No, I think we should simply ignore this if printing on e.g.
+ // a printer DC.
+ // wxCHECK_RET( m_selectedBitmap.Ok(), wxT("this DC can't be cleared") );
+ if (!m_selectedBitmap.Ok())
+ return;
rect.left = 0; rect.top = 0;
rect.right = m_selectedBitmap.GetWidth();
void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle)
{
+ COLORREF old_textground = ::GetTextColor(GetHdc());
+ COLORREF old_background = ::GetBkColor(GetHdc());
+ if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE)
+ {
+
+ if (m_textForegroundColour.Ok())
+ { //just the oposite from what is expected see help on pattern brush
+ // 1 in mask becomes bk color
+ ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel() );
+ }
+ if (m_textBackgroundColour.Ok())
+ { //just the oposite from what is expected
+ // 0 in mask becomes text color
+ ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel() );
+ }
+
+ if (m_backgroundMode == wxTRANSPARENT)
+ SetBkMode(GetHdc(), TRANSPARENT);
+ else
+ SetBkMode(GetHdc(), OPAQUE);
+ }
+
// Do things less efficiently if we have offsets
if (xoffset != 0 || yoffset != 0)
{
(void)Polygon(GetHdc(), (POINT*) points, n);
SetPolyFillMode(GetHdc(),prev);
}
+
+ if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE)
+ {
+ ::SetBkMode(GetHdc(), TRANSPARENT);
+ ::SetTextColor(GetHdc(), old_textground);
+ ::SetBkColor(GetHdc(), old_background);
+ }
}
void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
+ COLORREF old_textground = ::GetTextColor(GetHdc());
+ COLORREF old_background = ::GetBkColor(GetHdc());
+ if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE)
+ {
+
+ if (m_textForegroundColour.Ok())
+ { //just the oposite from what is expected see help on pattern brush
+ // 1 in mask becomes bk color
+ ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel() );
+ }
+ if (m_textBackgroundColour.Ok())
+ { //just the oposite from what is expected
+ // 0 in mask becomes text color
+ ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel() );
+ }
+
+ if (m_backgroundMode == wxTRANSPARENT)
+ SetBkMode(GetHdc(), TRANSPARENT);
+ else
+ SetBkMode(GetHdc(), OPAQUE);
+ }
+
wxCoord x2 = x + width;
wxCoord y2 = y + height;
CalcBoundingBox(x, y);
CalcBoundingBox(x2, y2);
+
+ if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE)
+ {
+ ::SetBkMode(GetHdc(), TRANSPARENT);
+ ::SetTextColor(GetHdc(), old_textground);
+ ::SetBkColor(GetHdc(), old_background);
+ }
}
void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
{
-#if defined(__WIN32__) && !defined(__SC__) && !defined(__TWIN32__)
- ::DrawIconEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON(),
- icon.GetWidth(), icon.GetHeight(), 0, 0, DI_NORMAL);
-#else
- ::DrawIcon(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON());
-#endif
+ wxCHECK_RET( icon.Ok(), wxT("invalid icon in DrawIcon") );
+
+ ::DrawIcon(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), GetHiconOf(icon));
CalcBoundingBox(x, y);
- CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight());
+ CalcBoundingBox(x + icon.GetWidth(), y + icon.GetHeight());
}
void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
{
- if (!bmp.Ok())
- return;
+ wxCHECK_RET( bmp.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
- bool needsPixelCopy = false ;
- bool isPrinter = false ;
- if (IsKindOf(CLASSINFO(wxPrinterDC)) )
- {
- isPrinter = true ;
- if ( ::GetDeviceCaps((HDC) m_hDC, RASTERCAPS) & RC_STRETCHDIB )
- {
- }
- else
- {
- needsPixelCopy = true ;
- }
- }
- // If we're not drawing transparently, and not drawing to a printer,
- // optimize this function to use Windows functions.
- if (!useMask && !needsPixelCopy)
+ int width = bmp.GetWidth(),
+ height = bmp.GetHeight();
+
+ if ( !useMask )
{
- if ( isPrinter )
- {
- BITMAPINFO *info = (BITMAPINFO *) malloc( sizeof( BITMAPINFOHEADER ) + 256 * sizeof(RGBQUAD ) ) ;
- int iBitsSize = ((bmp.GetWidth() + 3 ) & ~3 ) * bmp.GetHeight() ;
-
- void* bits = malloc( iBitsSize ) ;
-
- memset( info , 0 , sizeof( BITMAPINFOHEADER ) ) ;
-
- info->bmiHeader.biSize = sizeof( BITMAPINFOHEADER ) ;
- info->bmiHeader.biWidth = bmp.GetWidth() ;
- info->bmiHeader.biHeight = bmp.GetHeight() ;
- info->bmiHeader.biPlanes = 1 ;
- info->bmiHeader.biBitCount = 8 ;
- info->bmiHeader.biCompression = BI_RGB ;
-
- HDC display = GetDC( NULL ) ;
- if ( GetDIBits( display , (HBITMAP) bmp.GetHBITMAP( ) , 0 , bmp.GetHeight() , bits , info , DIB_RGB_COLORS ) )
- {
- StretchDIBits( (HDC) m_hDC,
- x, y, bmp.GetWidth(), bmp.GetHeight() ,
- 0 , 0 ,bmp.GetWidth(), bmp.GetHeight() ,
- bits , info , DIB_RGB_COLORS , SRCCOPY ) ;
- }
- ReleaseDC( NULL , display ) ;
- free ( bits ) ;
- free( info ) ;
- }
- else
- {
- HDC cdc = GetHdc();
- HDC memdc = ::CreateCompatibleDC( cdc );
- HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( );
-
- wxASSERT_MSG( hbitmap, wxT("bitmap is ok but HBITMAP is NULL?") );
-
- ::SelectObject( memdc, hbitmap );
- ::BitBlt( cdc, x, y, bmp.GetWidth(), bmp.GetHeight(), memdc, 0, 0, SRCCOPY);
- ::DeleteDC( memdc );
+ HDC cdc = GetHdc();
+ HDC memdc = ::CreateCompatibleDC( cdc );
+ HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( );
+
+ wxASSERT_MSG( hbitmap, wxT("bitmap is ok but HBITMAP is NULL?") );
+
+ 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() );
+ }
+
+ ::SelectObject( memdc, hbitmap );
+ ::BitBlt( cdc, x, y, width, height, memdc, 0, 0, SRCCOPY);
+ ::DeleteDC( memdc );
+
+ ::SetTextColor(GetHdc(), old_textground);
+ ::SetBkColor(GetHdc(), old_background);
}
else
{
wxMemoryDC memDC;
memDC.SelectObject(bmp);
- /* Not sure if we need this. The mask should leave the
- * masked areas as per the original background of this DC.
- */
- /*
- // There might be transparent areas, so make these
- // the same colour as this DC
- memDC.SetBackground(* GetBackground());
- memDC.Clear();
- */
-
- Blit(x, y, bmp.GetWidth(), bmp.GetHeight(), & memDC, 0, 0, wxCOPY, useMask);
+ Blit(x, y, width, height, &memDC, 0, 0, wxCOPY, useMask);
memDC.SelectObject(wxNullBitmap);
}
if (m_backgroundMode == wxTRANSPARENT)
::SetBkMode(GetHdc(), TRANSPARENT);
else
- ::SetBkMode(GetHdc(), OPAQUE);
+ ::SetBkMode(GetHdc(), OPAQUE);
*/
}
// ---------------------------------------------------------------------------
// bit blit
// ---------------------------------------------------------------------------
-bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
- wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask)
+
+bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
+ wxCoord width, wxCoord height,
+ wxDC *source, wxCoord xsrc, wxCoord ysrc,
+ int rop, bool useMask)
{
- wxCoord xdest1 = xdest;
- wxCoord ydest1 = ydest;
- wxCoord xsrc1 = xsrc;
- wxCoord ysrc1 = ysrc;
+ wxMask *mask = NULL;
+ if ( useMask )
+ {
+ const wxBitmap& bmp = source->m_selectedBitmap;
+ mask = bmp.GetMask();
+
+ if ( !(bmp.Ok() && mask && mask->GetMaskBitmap()) )
+ {
+ // don't give assert here because this would break existing
+ // programs - just silently ignore useMask parameter
+ useMask = FALSE;
+ }
+ }
- // 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())
}
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())
+ 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;
+
+ if (useMask)
{
-
-#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))
+#ifdef __WIN32__
+ HBITMAP hbmpMask = wxInvertMask((HBITMAP)mask->GetMaskBitmap());
+
+ // we want the part of the image corresponding to the mask to be
+ // transparent, i.e. do PATCOPY there and apply dwRop elsewhere
+ const wxColour& colBg = m_backgroundBrush.GetColour();
+ HBRUSH hbrBg = (HBRUSH)::CreateSolidBrush(wxColourToRGB(colBg));
+ HBRUSH hbrOld = (HBRUSH)::SelectObject(GetHdc(), hbrBg);
+
+ success = ::MaskBlt(GetHdc(), xdest, ydest, width, height,
+ GetHdcOf(*source), xsrc, ysrc,
+ hbmpMask, 0, 0,
+ MAKEROP4(PATCOPY, dwRop)) != 0;
+
+ (void)::SelectObject(GetHdc(), hbrOld);
+ ::DeleteObject(hbrOld);
+ ::DeleteObject(hbmpMask);
+
+ if ( !success )
+#endif // Win32
{
- // Success
- }
- else
-#endif
- {
- // New code from Chris Breeze, 15/7/98
// Blit bitmap with mask
- if (IsKindOf(CLASSINFO(wxPrinterDC)))
+ // 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) )
{
- // 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);
+ wxLogLastError("BitBlt");
}
- else
+
+ // copy src to buffer using selected raster op
+ if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ GetHdcOf(*source), xsrc, ysrc, dwRop) )
+ {
+ wxLogLastError("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("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("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 )
{
- // 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);
+ wxLogLastError("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
+ else // no mask, just BitBlt() it
{
- // 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(), xdest, ydest,
+ (int)width, (int)height,
+ GetHdcOf(*source), xsrc, ysrc, dwRop) != 0;
+ if ( !success )
{
- success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC,
- xsrc1, ysrc1, dwRop) != 0);
+ wxLogLastError("BitBlt");
}
}
+
::SetTextColor(GetHdc(), old_textground);
::SetBkColor(GetHdc(), old_background);