X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8bf30fe9b0b40d1a6f54608588121212c2c4e037..d7926e0b761b782b82f9ef01ff542251b2ef5ae7:/src/msw/dc.cpp?ds=inline diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 86e1a772cf..0f31dee21b 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -40,7 +40,9 @@ #include "wx/icon.h" #endif +#include "wx/sysopt.h" #include "wx/dcprint.h" +#include "wx/module.h" #include #include @@ -263,43 +265,78 @@ void wxDC::SelectOldObjects(WXHDC dc) // clipping // --------------------------------------------------------------------------- -#define DO_SET_CLIPPING_BOX() \ -{ \ - RECT rect; \ - \ - GetClipBox(GetHdc(), &rect); \ - \ - m_clipX1 = (wxCoord) XDEV2LOG(rect.left); \ - m_clipY1 = (wxCoord) YDEV2LOG(rect.top); \ - m_clipX2 = (wxCoord) XDEV2LOG(rect.right); \ - m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \ +void wxDC::UpdateClipBox() +{ +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + + RECT rect; + GetClipBox(GetHdc(), &rect); + + m_clipX1 = (wxCoord) XDEV2LOG(rect.left); + m_clipY1 = (wxCoord) YDEV2LOG(rect.top); + m_clipX2 = (wxCoord) XDEV2LOG(rect.right); + m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); } -void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch) +void wxDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_clipping = TRUE; - IntersectClipRect(GetHdc(), XLOG2DEV(cx), YLOG2DEV(cy), - XLOG2DEV(cx + cw), YLOG2DEV(cy + ch)); - DO_SET_CLIPPING_BOX() + + // the region coords are always the device ones, so do the translation + // manually + // + // FIXME: possible +/-1 error here, to check! + HRGN hrgn = ::CreateRectRgn(LogicalToDeviceX(x), + LogicalToDeviceY(y), + LogicalToDeviceX(x + w), + LogicalToDeviceY(y + h)); + if ( !hrgn ) + { + wxLogLastError(_T("CreateRectRgn")); + } + else + { + if ( ::SelectClipRgn(GetHdc(), hrgn) == ERROR ) + { + wxLogLastError(_T("SelectClipRgn")); + } + DeleteObject(hrgn); + + UpdateClipBox(); + } } void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) { - wxCHECK_RET( region.GetHRGN(), wxT("invalid clipping region") ); +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + + wxCHECK_RET( GetHrgnOf(region), wxT("invalid clipping region") ); m_clipping = TRUE; #ifdef __WIN16__ - SelectClipRgn(GetHdc(), (HRGN) region.GetHRGN()); -#else - ExtSelectClipRgn(GetHdc(), (HRGN) region.GetHRGN(), RGN_AND); -#endif + SelectClipRgn(GetHdc(), GetHrgnOf(region)); +#else // Win32 + ExtSelectClipRgn(GetHdc(), GetHrgnOf(region), RGN_AND); +#endif // Win16/32 - DO_SET_CLIPPING_BOX() + UpdateClipBox(); } void wxDC::DestroyClippingRegion() { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + if (m_clipping && m_hDC) { // TODO: this should restore the previous clipping region, @@ -309,6 +346,7 @@ void wxDC::DestroyClippingRegion() SelectClipRgn(GetHdc(), rgn); DeleteObject(rgn); } + m_clipping = FALSE; } @@ -323,14 +361,23 @@ bool wxDC::CanDrawBitmap() const bool wxDC::CanGetTextExtent() const { +#ifdef __WXMICROWIN__ + // TODO Extend MicroWindows' GetDeviceCaps function + return TRUE; +#else // What sort of display is it? int technology = ::GetDeviceCaps(GetHdc(), TECHNOLOGY); return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER); +#endif } int wxDC::GetDepth() const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return 16; +#endif + return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL); } @@ -340,6 +387,10 @@ int wxDC::GetDepth() const void wxDC::Clear() { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + RECT rect; if ( m_canvas ) { @@ -374,6 +425,10 @@ void wxDC::Clear() void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), col.GetPixel(), style == wxFLOOD_SURFACE ? FLOODFILLSURFACE @@ -399,6 +454,10 @@ void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return FALSE; +#endif + wxCHECK_MSG( col, FALSE, _T("NULL colour parameter in wxDC::GetPixel") ); // get the color of the pixel @@ -411,6 +470,10 @@ bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const void wxDC::DoCrossHair(wxCoord x, wxCoord y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxCoord x1 = x-VIEWPORT_EXTENT; wxCoord y1 = y-VIEWPORT_EXTENT; wxCoord x2 = x+VIEWPORT_EXTENT; @@ -428,6 +491,10 @@ void wxDC::DoCrossHair(wxCoord x, wxCoord y) void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL); (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2)); @@ -445,6 +512,10 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling double dx = xc - x1; @@ -493,10 +564,14 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, wxCoord width, wxCoord height) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxCoord x2 = x1 + width, y2 = y1 + height; -#if defined(__WIN32__) && !defined(__SC__) +#if defined(__WIN32__) && !defined(__SC__) && !defined(__WXMICROWIN__) RECT rect; rect.left = x1; rect.top = y1; @@ -512,9 +587,9 @@ void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, HPEN hBrushOld = (HPEN)::SelectObject(GetHdc(), whiteBrush); ::SetROP2(GetHdc(), R2_COPYPEN); Rectangle(GetHdc(), x1, y1, x2, y2); - MoveTo(GetHdc(), x1, y1); + MoveToEx(GetHdc(), x1, y1, NULL); LineTo(GetHdc(), x2, y2); - MoveTo(GetHdc(), x2, y1); + MoveToEx(GetHdc(), x2, y1, NULL); LineTo(GetHdc(), x1, y2); ::SelectObject(GetHdc(), hPenOld); ::SelectObject(GetHdc(), hBrushOld); @@ -527,6 +602,10 @@ void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, void wxDC::DoDrawPoint(wxCoord x, wxCoord y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + COLORREF color = 0x00ffffff; if (m_pen.Ok()) { @@ -540,6 +619,10 @@ void wxDC::DoDrawPoint(wxCoord x, wxCoord y) void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling // Do things less efficiently if we have offsets @@ -573,6 +656,10 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffs void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) { @@ -600,6 +687,10 @@ void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = x + width; @@ -637,6 +728,10 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling // Now, a negative radius value is interpreted to mean @@ -673,6 +768,10 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord h void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = (x+width); @@ -687,6 +786,10 @@ void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = x + w; @@ -730,6 +833,10 @@ void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,d void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxCHECK_RET( icon.Ok(), wxT("invalid icon in DrawIcon") ); #ifdef __WIN32__ @@ -744,6 +851,10 @@ void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxCHECK_RET( bmp.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") ); int width = bmp.GetWidth(), @@ -768,16 +879,25 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask if ( useMask ) { #ifdef __WIN32__ - HDC hdcMem = ::CreateCompatibleDC(GetHdc()); - ::SelectObject(hdcMem, GetHbitmapOf(bmp)); - // use MaskBlt() with ROP which doesn't do anything to dst in the mask // points - bool ok = ::MaskBlt(GetHdc(), x, y, width, height, + // On some systems, MaskBlt succeeds yet is much much slower + // than the wxWindows fall-back implementation. So we need + // to be able to switch this on and off at runtime. + bool ok = FALSE; +#if wxUSE_SYSTEM_OPTIONS + if (wxSystemOptions::GetOptionInt(wxT("no-maskblt")) == 0) +#endif + { + HDC hdcMem = ::CreateCompatibleDC(GetHdc()); + ::SelectObject(hdcMem, GetHbitmapOf(bmp)); + + ok = ::MaskBlt(GetHdc(), x, y, width, height, hdcMem, 0, 0, hbmpMask, 0, 0, MAKEROP4(SRCCOPY, DSTCOPY)) != 0; - ::DeleteDC(hdcMem); + ::DeleteDC(hdcMem); + } if ( !ok ) #endif // Win32 @@ -822,6 +942,10 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + DrawAnyText(text, x, y); // update the bounding box @@ -834,6 +958,10 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + // prepare for drawing the text if ( m_textForegroundColour.Ok() ) SetTextColor(GetHdc(), m_textForegroundColour.GetPixel()); @@ -866,6 +994,10 @@ void wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + // we test that we have some font because otherwise we should still use the // "else" part below to avoid that DrawRotatedText(angle = 180) and // DrawRotatedText(angle = 0) use different fonts (we can't use the default @@ -874,6 +1006,7 @@ void wxDC::DoDrawRotatedText(const wxString& text, { DoDrawText(text, x, y); } +#ifndef __WXMICROWIN__ else { // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so @@ -924,6 +1057,7 @@ void wxDC::DoDrawRotatedText(const wxString& text, CalcBoundingBox(x, y); CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); } +#endif } // --------------------------------------------------------------------------- @@ -932,6 +1066,10 @@ void wxDC::DoDrawRotatedText(const wxString& text, void wxDC::SetPalette(const wxPalette& palette) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldPalette) @@ -967,6 +1105,10 @@ void wxDC::SetPalette(const wxPalette& palette) void wxDC::SetFont(const wxFont& the_font) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldFont) @@ -998,6 +1140,10 @@ void wxDC::SetFont(const wxFont& the_font) void wxDC::SetPen(const wxPen& pen) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldPen) @@ -1028,6 +1174,10 @@ void wxDC::SetPen(const wxPen& pen) void wxDC::SetBrush(const wxBrush& brush) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldBrush) @@ -1075,6 +1225,10 @@ void wxDC::SetBrush(const wxBrush& brush) void wxDC::SetBackground(const wxBrush& brush) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_backgroundBrush = brush; if (!m_backgroundBrush.Ok()) @@ -1116,6 +1270,10 @@ void wxDC::SetBackground(const wxBrush& brush) void wxDC::SetBackgroundMode(int mode) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_backgroundMode = mode; // SetBackgroundColour now only refers to text background @@ -1132,6 +1290,10 @@ void wxDC::SetBackgroundMode(int mode) void wxDC::SetLogicalFunction(int function) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_logicalFunction = function; SetRop(m_hDC); @@ -1171,7 +1333,7 @@ void wxDC::SetRop(WXHDC dc) SetROP2(GetHdc(), rop); } -bool wxDC::StartDoc(const wxString& message) +bool wxDC::StartDoc(const wxString& WXUNUSED(message)) { // We might be previewing, so return TRUE to let it continue. return TRUE; @@ -1195,6 +1357,10 @@ void wxDC::EndPage() wxCoord wxDC::GetCharHeight() const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return 0; +#endif + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1204,6 +1370,10 @@ wxCoord wxDC::GetCharHeight() const wxCoord wxDC::GetCharWidth() const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return 0; +#endif + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1215,6 +1385,17 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, wxFont *font) const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) + { + if (x) *x = 0; + if (y) *y = 0; + if (descent) *descent = 0; + if (externalLeading) *externalLeading = 0; + return; + } +#endif + HFONT hfontOld; if ( font ) { @@ -1246,6 +1427,10 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, void wxDC::SetMapMode(int mode) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_mappingMode = mode; int pixel_width = 0; @@ -1314,6 +1499,10 @@ void wxDC::SetMapMode(int mode) void wxDC::SetUserScale(double x, double y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_userScaleX = x; m_userScaleY = y; @@ -1322,6 +1511,10 @@ void wxDC::SetUserScale(double x, double y) void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_signX = xLeftRight ? 1 : -1; m_signY = yBottomUp ? -1 : 1; @@ -1330,6 +1523,10 @@ void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) void wxDC::SetSystemScale(double x, double y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_scaleX = x; m_scaleY = y; @@ -1338,6 +1535,10 @@ void wxDC::SetSystemScale(double x, double y) void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_logicalOriginX = x; m_logicalOriginY = y; @@ -1346,6 +1547,10 @@ void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y) void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_deviceOriginX = x; m_deviceOriginY = y; @@ -1407,8 +1612,13 @@ wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, - int rop, bool useMask) + int rop, bool useMask, + wxCoord xsrcMask, wxCoord ysrcMask) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return FALSE; +#endif + wxMask *mask = NULL; if ( useMask ) { @@ -1423,6 +1633,11 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, } } + if (xsrcMask == -1 && ysrcMask == -1) + { + xsrcMask = xsrc; ysrcMask = ysrc; + } + COLORREF old_textground = ::GetTextColor(GetHdc()); COLORREF old_background = ::GetBkColor(GetHdc()); if (m_textForegroundColour.Ok()) @@ -1458,7 +1673,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, return FALSE; } - bool success; + bool success = FALSE; if (useMask) { @@ -1467,22 +1682,53 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, // 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, + + // On some systems, MaskBlt succeeds yet is much much slower + // than the wxWindows fall-back implementation. So we need + // to be able to switch this on and off at runtime. +#if wxUSE_SYSTEM_OPTIONS + if (wxSystemOptions::GetOptionInt(wxT("no-maskblt")) == 0) +#endif + { + success = ::MaskBlt(GetHdc(), xdest, ydest, width, height, GetHdcOf(*source), xsrc, ysrc, - (HBITMAP)mask->GetMaskBitmap(), xsrc, ysrc, + (HBITMAP)mask->GetMaskBitmap(), xsrcMask, ysrcMask, MAKEROP4(dwRop, DSTCOPY)) != 0; + } if ( !success ) #endif // Win32 { // Blit bitmap with mask + HDC dc_mask ; + HDC dc_buffer ; + HBITMAP buffer_bmap ; - // 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); +#if wxUSE_DC_CACHEING + if (TRUE) + { + // create a temp buffer bitmap and DCs to access it and the mask + wxDCCacheEntry* dcCacheEntry1 = FindDCInCache(NULL, source->GetHDC()); + dc_mask = (HDC) dcCacheEntry1->m_dc; + + wxDCCacheEntry* dcCacheEntry2 = FindDCInCache(dcCacheEntry1, GetHDC()); + dc_buffer = (HDC) dcCacheEntry2->m_dc; + + wxDCCacheEntry* bitmapCacheEntry = FindBitmapInCache(GetHDC(), + width, height); + + buffer_bmap = (HBITMAP) bitmapCacheEntry->m_bitmap; + } + else +#endif + { + // create a temp buffer bitmap and DCs to access it and the mask + dc_mask = ::CreateCompatibleDC(GetHdcOf(*source)); + dc_buffer = ::CreateCompatibleDC(GetHdc()); + 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, @@ -1502,7 +1748,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, 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) ) + dc_mask, xsrcMask, ysrcMask, SRCAND) ) { wxLogLastError(wxT("BitBlt")); } @@ -1511,7 +1757,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, ::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) ) + dc_mask, xsrcMask, ysrcMask, SRCAND) ) { wxLogLastError(wxT("BitBlt")); } @@ -1529,10 +1775,15 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, // tidy up temporary DCs and bitmap ::SelectObject(dc_mask, 0); - ::DeleteDC(dc_mask); ::SelectObject(dc_buffer, 0); - ::DeleteDC(dc_buffer); - ::DeleteObject(buffer_bmap); + +#if !wxUSE_DC_CACHEING + { + ::DeleteDC(dc_mask); + ::DeleteDC(dc_buffer); + ::DeleteObject(buffer_bmap); + } +#endif } } else // no mask, just BitBlt() it @@ -1553,18 +1804,30 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, void wxDC::DoGetSize(int *w, int *h) const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES); if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES); } void wxDC::DoGetSizeMM(int *w, int *h) const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE); if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE); } wxSize wxDC::GetPPI() const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return wxSize(); +#endif + int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); @@ -1574,6 +1837,10 @@ wxSize wxDC::GetPPI() const // For use by wxWindows only, unless custom units are required. void wxDC::SetLogicalScale(double x, double y) { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + m_logicalScaleX = x; m_logicalScaleY = y; } @@ -1583,6 +1850,10 @@ void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, float *descent, float *externalLeading, wxFont *theFont, bool use16bit) const { +#ifdef __WXMICROWIN__ + if (!GetHDC()) return; +#endif + wxCoord x1, y1, descent1, externalLeading1; GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); *x = x1; *y = y1; @@ -1593,4 +1864,141 @@ void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, } #endif +#if wxUSE_DC_CACHEING + +/* + * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will + * improve it in due course, either using arrays, or simply storing pointers to one + * entry for the bitmap, and two for the DCs. -- JACS + */ + +wxList wxDC::sm_bitmapCache; +wxList wxDC::sm_dcCache; + +wxDCCacheEntry::wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth) +{ + m_bitmap = hBitmap; + m_dc = 0; + m_width = w; + m_height = h; + m_depth = depth; +} + +wxDCCacheEntry::wxDCCacheEntry(WXHDC hDC, int depth) +{ + m_bitmap = 0; + m_dc = hDC; + m_width = 0; + m_height = 0; + m_depth = depth; +} + +wxDCCacheEntry::~wxDCCacheEntry() +{ + if (m_bitmap) + ::DeleteObject((HBITMAP) m_bitmap); + if (m_dc) + ::DeleteDC((HDC) m_dc); +} + +wxDCCacheEntry* wxDC::FindBitmapInCache(WXHDC dc, int w, int h) +{ + int depth = ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL); + wxNode* node = sm_bitmapCache.First(); + while (node) + { + wxDCCacheEntry* entry = (wxDCCacheEntry*) node->Data(); + + if (entry->m_depth == depth) + { + if (entry->m_width < w || entry->m_height < h) + { + ::DeleteObject((HBITMAP) entry->m_bitmap); + entry->m_bitmap = (WXHBITMAP) ::CreateCompatibleBitmap((HDC) dc, w, h); + if ( !entry->m_bitmap) + { + wxLogLastError(wxT("CreateCompatibleBitmap")); + } + entry->m_width = w; entry->m_height = h; + return entry; + } + return entry; + } + + node = node->Next(); + } + WXHBITMAP hBitmap = (WXHBITMAP) ::CreateCompatibleBitmap((HDC) dc, w, h); + if ( !hBitmap) + { + wxLogLastError(wxT("CreateCompatibleBitmap")); + } + wxDCCacheEntry* entry = new wxDCCacheEntry(hBitmap, w, h, depth); + AddToBitmapCache(entry); + return entry; +} + +wxDCCacheEntry* wxDC::FindDCInCache(wxDCCacheEntry* notThis, WXHDC dc) +{ + int depth = ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL); + wxNode* node = sm_dcCache.First(); + while (node) + { + wxDCCacheEntry* entry = (wxDCCacheEntry*) node->Data(); + + // Don't return the same one as we already have + if (!notThis || (notThis != entry)) + { + if (entry->m_depth == depth) + { + return entry; + } + } + + node = node->Next(); + } + WXHDC hDC = (WXHDC) ::CreateCompatibleDC((HDC) dc); + if ( !hDC) + { + wxLogLastError(wxT("CreateCompatibleDC")); + } + wxDCCacheEntry* entry = new wxDCCacheEntry(hDC, depth); + AddToDCCache(entry); + return entry; +} + +void wxDC::AddToBitmapCache(wxDCCacheEntry* entry) +{ + sm_bitmapCache.Append(entry); +} + +void wxDC::AddToDCCache(wxDCCacheEntry* entry) +{ + sm_dcCache.Append(entry); +} + +void wxDC::ClearCache() +{ + sm_bitmapCache.DeleteContents(TRUE); + sm_bitmapCache.Clear(); + sm_bitmapCache.DeleteContents(FALSE); + sm_dcCache.DeleteContents(TRUE); + sm_dcCache.Clear(); + sm_dcCache.DeleteContents(FALSE); +} + +// Clean up cache at app exit +class wxDCModule : public wxModule +{ +public: + virtual bool OnInit() { return TRUE; } + virtual void OnExit() { wxDC::ClearCache(); } + +private: + DECLARE_DYNAMIC_CLASS(wxDCModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule) + +#endif + // wxUSE_DC_CACHEING