#include "wx/icon.h"
#endif
+#include "wx/settings.h"
#include "wx/dcprint.h"
#include <string.h>
// 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()
+{
+ 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)
{
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"));
+ }
+
+ UpdateClipBox();
+ }
}
void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
{
- wxCHECK_RET( region.GetHRGN(), wxT("invalid clipping region") );
+ 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()
SelectClipRgn(GetHdc(), rgn);
DeleteObject(rgn);
}
+
m_clipping = FALSE;
}
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
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;
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 (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
+ {
+ 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
{
DoDrawText(text, x, y);
}
+#ifndef __WXMICROWIN__
else
{
// NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
CalcBoundingBox(x, y);
CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
}
+#endif
}
// ---------------------------------------------------------------------------
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;
void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
wxCoord *descent, wxCoord *externalLeading,
- wxFont *theFont) const
+ wxFont *font) const
{
- wxFont *fontToUse = (wxFont*) theFont;
- if (!fontToUse)
- fontToUse = (wxFont*) &m_font;
+ HFONT hfontOld;
+ if ( font )
+ {
+ wxASSERT_MSG( font->Ok(), _T("invalid font in wxDC::GetTextExtent") );
+
+ hfontOld = (HFONT)::SelectObject(GetHdc(), GetHfontOf(*font));
+ }
+ else // don't change the font
+ {
+ hfontOld = 0;
+ }
SIZE sizeRect;
TEXTMETRIC tm;
- GetTextExtentPoint(GetHdc(), WXSTRINGCAST string, wxStrlen(WXSTRINGCAST string), &sizeRect);
+ GetTextExtentPoint(GetHdc(), string, string.length(), &sizeRect);
GetTextMetrics(GetHdc(), &tm);
if (x) *x = XDEV2LOGREL(sizeRect.cx);
if (y) *y = YDEV2LOGREL(sizeRect.cy);
if (descent) *descent = tm.tmDescent;
if (externalLeading) *externalLeading = tm.tmExternalLeading;
+
+ if ( hfontOld )
+ {
+ ::SelectObject(GetHdc(), hfontOld);
+ }
}
void wxDC::SetMapMode(int mode)
return FALSE;
}
- bool success;
+ bool success = FALSE;
if (useMask)
{
// 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 (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
+ {
+ success = ::MaskBlt(GetHdc(), xdest, ydest, width, height,
GetHdcOf(*source), xsrc, ysrc,
(HBITMAP)mask->GetMaskBitmap(), xsrc, ysrc,
MAKEROP4(dwRop, DSTCOPY)) != 0;
+ }
if ( !success )
#endif // Win32