#include <print.h>
#endif
+/* Quaternary raster codes */
+#ifndef MAKEROP4
+#define MAKEROP4(fore,back) (DWORD)((((back) << 8) & 0xFF000000) | (fore))
+#endif
+
IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
// ---------------------------------------------------------------------------
bool m_changed;
};
+// this class saves the old stretch blit mode during its life time
+class StretchBltModeChanger
+{
+public:
+ StretchBltModeChanger(HDC hdc, int mode)
+ : m_hdc(hdc)
+ {
+ m_modeOld = ::SetStretchBltMode(m_hdc, mode);
+ if ( !m_modeOld )
+ wxLogLastError(_T("SetStretchBltMode"));
+ }
+
+ ~StretchBltModeChanger()
+ {
+ if ( !::SetStretchBltMode(m_hdc, m_modeOld) )
+ wxLogLastError(_T("SetStretchBltMode"));
+ }
+
+private:
+ const HDC m_hdc;
+
+ int m_modeOld;
+};
+
// ===========================================================================
// implementation
// ===========================================================================
::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL);
}
-void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)
+bool wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)
{
#ifdef __WXMICROWIN__
- if (!GetHDC()) return;
+ if (!GetHDC()) return FALSE;
#endif
- if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
+ bool success = (0 != ::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
col.GetPixel(),
style == wxFLOOD_SURFACE ? FLOODFILLSURFACE
- : FLOODFILLBORDER) )
+ : FLOODFILLBORDER) ) ;
+ if (!success)
{
// quoting from the MSDN docs:
//
}
CalcBoundingBox(x, y);
+
+ return success;
}
bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
// "upper left" and "upper right"
CalcBoundingBox(x, y);
- CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
+ CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(h*sin(rad)));
// "bottom left" and "bottom right"
x += (wxCoord)(h*sin(rad));
y += (wxCoord)(h*cos(rad));
CalcBoundingBox(x, y);
- CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
+ CalcBoundingBox(x + wxCoord(h*sin(rad)), y + wxCoord(h*cos(rad)));
}
#endif
}
if (wxSystemOptions::GetOptionInt(wxT("no-maskblt")) == 0)
#endif
{
- success = ::MaskBlt(GetHdc(), xdest, ydest, width, height,
- GetHdcOf(*source), xsrc, ysrc,
- (HBITMAP)mask->GetMaskBitmap(), xsrcMask, ysrcMask,
- MAKEROP4(dwRop, DSTCOPY)) != 0;
+ success = ::MaskBlt
+ (
+ GetHdc(),
+ xdest, ydest, width, height,
+ GetHdcOf(*source),
+ xsrc, ysrc,
+ (HBITMAP)mask->GetMaskBitmap(),
+ xsrcMask, ysrcMask,
+ MAKEROP4(dwRop, DSTCOPY)
+ ) != 0;
}
if ( !success )
}
else // no mask, just BitBlt() it
{
- success = ::BitBlt(GetHdc(), xdest, ydest,
- (int)width, (int)height,
- GetHdcOf(*source), xsrc, ysrc, dwRop) != 0;
+ // use StretchBlt() if available
+ if ( ::GetDeviceCaps(GetHdc(), RASTERCAPS) & RC_STRETCHBLT )
+ {
+ StretchBltModeChanger changeMode(GetHdc(), COLORONCOLOR);
+
+ success = ::StretchBlt
+ (
+ GetHdc(),
+ xdest, ydest, width, height,
+ GetHdcOf(*source),
+ xsrc, ysrc, width, height,
+ dwRop
+ ) != 0;
+ }
+ else
+ {
+ success = ::BitBlt
+ (
+ GetHdc(),
+ xdest, ydest,
+ (int)width, (int)height,
+ GetHdcOf(*source),
+ xsrc, ysrc,
+ dwRop
+ ) != 0;
+ }
+
if ( !success )
{
- wxLogLastError(wxT("BitBlt"));
+ wxLogLastError(wxT("BitBlt/StretchBlt"));
}
}
+
::SetTextColor(GetHdc(), old_textground);
::SetBkColor(GetHdc(), old_background);
if (!GetHDC()) return;
#endif
- if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE);
- if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE);
+ // if we implement it in terms of DoGetSize() instead of directly using the
+ // results returned by GetDeviceCaps(HORZ/VERTSIZE) as was done before, it
+ // will also work for wxWindowDC and wxClientDC even though their size is
+ // not the same as the total size of the screen
+ int wPixels, hPixels;
+ DoGetSize(&wPixels, &hPixels);
+
+ if ( w )
+ {
+ int wTotal = ::GetDeviceCaps(GetHdc(), HORZRES);
+
+ wxCHECK_RET( wTotal, _T("0 width device?") );
+
+ *w = (wPixels * ::GetDeviceCaps(GetHdc(), HORZSIZE)) / wTotal;
+ }
+
+ if ( h )
+ {
+ int hTotal = ::GetDeviceCaps(GetHdc(), VERTRES);
+
+ wxCHECK_RET( hTotal, _T("0 height device?") );
+
+ *h = (hPixels * ::GetDeviceCaps(GetHdc(), VERTSIZE)) / hTotal;
+ }
}
wxSize wxDC::GetPPI() const
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);
+ sm_bitmapCache.DeleteContents(TRUE);
+ sm_bitmapCache.Clear();
+ sm_bitmapCache.DeleteContents(FALSE);
}
// Clean up cache at app exit