// 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;
- HRGN hrgn = ::CreateRectRgn(XLOG2DEV(cx), YLOG2DEV(cy),
- XLOG2DEV(cx + cw), YLOG2DEV(cy + ch));
+ // 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"));
{
wxLogLastError(_T("SelectClipRgn"));
}
+ DeleteObject(hrgn);
- DO_SET_CLIPPING_BOX()
+ 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,
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
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return 16;
+#endif
+
return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL);
}
void wxDC::Clear()
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
RECT rect;
if ( m_canvas )
{
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
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
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;
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));
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;
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;
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);
void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
COLORREF color = 0x00ffffff;
if (m_pen.Ok())
{
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
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)
{
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;
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
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);
// 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;
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__
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(),
void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
DrawAnyText(text, x, y);
// update the bounding box
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());
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
{
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
}
// ---------------------------------------------------------------------------
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)
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)
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)
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)
void wxDC::SetBackground(const wxBrush& brush)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_backgroundBrush = brush;
if (!m_backgroundBrush.Ok())
void wxDC::SetBackgroundMode(int mode)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_backgroundMode = mode;
// SetBackgroundColour now only refers to text background
void wxDC::SetLogicalFunction(int function)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_logicalFunction = function;
SetRop(m_hDC);
wxCoord wxDC::GetCharHeight() const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return 0;
+#endif
+
TEXTMETRIC lpTextMetric;
GetTextMetrics(GetHdc(), &lpTextMetric);
wxCoord wxDC::GetCharWidth() const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return 0;
+#endif
+
TEXTMETRIC lpTextMetric;
GetTextMetrics(GetHdc(), &lpTextMetric);
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 )
{
void wxDC::SetMapMode(int mode)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_mappingMode = mode;
int pixel_width = 0;
void wxDC::SetUserScale(double x, double y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_userScaleX = x;
m_userScaleY = y;
void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_signX = xLeftRight ? 1 : -1;
m_signY = yBottomUp ? -1 : 1;
void wxDC::SetSystemScale(double x, double y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_scaleX = x;
m_scaleY = y;
void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_logicalOriginX = x;
m_logicalOriginY = y;
void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_deviceOriginX = x;
m_deviceOriginY = y;
wxDC *source, wxCoord xsrc, wxCoord ysrc,
int rop, bool useMask)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return FALSE;
+#endif
+
wxMask *mask = NULL;
if ( useMask )
{
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);
// 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;
}
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;