#include "wx/dynarray.h"
#include "wx/math.h"
#include "wx/image.h"
-#include "wx/cmndata.h"
+#include "wx/region.h"
+#include "wx/affinematrix2d.h"
#define wxUSE_NEW_DC 1
wxFLOOD_BORDER
};
-// Mapping modes (same values as used by Windows, don't change)
+// Mapping modes
enum wxMappingMode
{
wxMM_TEXT = 1,
+ wxMM_METRIC,
wxMM_LOMETRIC,
- wxMM_HIMETRIC,
- wxMM_LOENGLISH,
- wxMM_HIENGLISH,
wxMM_TWIPS,
- wxMM_ISOTROPIC,
- wxMM_ANISOTROPIC,
- wxMM_POINTS,
- wxMM_METRIC
+ wxMM_POINTS
};
+// Description of text characteristics.
+struct wxFontMetrics
+{
+ wxFontMetrics()
+ {
+ height =
+ ascent =
+ descent =
+ internalLeading =
+ externalLeading =
+ averageWidth = 0;
+ }
+
+ int height, // Total character height.
+ ascent, // Part of the height above the baseline.
+ descent, // Part of the height below the baseline.
+ internalLeading, // Intra-line spacing.
+ externalLeading, // Inter-line spacing.
+ averageWidth; // Average font width, a.k.a. "x-width".
+};
+
+#if WXWIN_COMPATIBILITY_2_8
+
//-----------------------------------------------------------------------------
// wxDrawObject helper class
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDrawObject
{
public:
-
- wxDrawObject()
+ wxDEPRECATED_CONSTRUCTOR(wxDrawObject)()
: m_isBBoxValid(false)
, m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
{ }
wxCoord m_minX, m_minY, m_maxX, m_maxY;
};
+#endif // WXWIN_COMPATIBILITY_2_8
+
//-----------------------------------------------------------------------------
// wxDCFactory
// logical functions
virtual void SetLogicalFunction(wxRasterOperationMode function) = 0;
- virtual wxRasterOperationMode GetLogicalFunction() const
+ virtual wxRasterOperationMode GetLogicalFunction() const
{ return m_logicalFunction; }
// text measurement
virtual wxCoord GetCharHeight() const = 0;
virtual wxCoord GetCharWidth() const = 0;
+
+ // The derived classes should really override DoGetFontMetrics() to return
+ // the correct values in the future but for now provide a default
+ // implementation in terms of DoGetTextExtent() to avoid breaking the
+ // compilation of all other ports as wxMSW is the only one to implement it.
+ virtual void DoGetFontMetrics(int *height,
+ int *ascent,
+ int *descent,
+ int *internalLeading,
+ int *externalLeading,
+ int *averageWidth) const;
+
virtual void DoGetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y,
wxCoord *descent = NULL,
if ( y ) *y = m_deviceOriginY;
}
+#if wxUSE_DC_TRANSFORM_MATRIX
+ // Transform matrix support is not available in most ports right now
+ // (currently only wxMSW provides it) so do nothing in these methods by
+ // default.
+ virtual bool CanUseTransformMatrix() const
+ { return false; }
+ virtual bool SetTransformMatrix(const wxAffineMatrix2D& WXUNUSED(matrix))
+ { return false; }
+ virtual wxAffineMatrix2D GetTransformMatrix() const
+ { return wxAffineMatrix2D(); }
+ virtual void ResetTransformMatrix()
+ { }
+#endif // wxUSE_DC_TRANSFORM_MATRIX
+
virtual void SetDeviceLocalOrigin( wxCoord x, wxCoord y );
virtual void ComputeScaleAndOrigin();
// this needs to overidden if the axis is inverted
virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
+#ifdef __WXMSW__
+ // Native Windows functions using the underlying HDC don't honour GDI+
+ // transformations which may be applied to it. Using this function we can
+ // transform the coordinates manually before passing them to such functions
+ // (as in e.g. wxRendererMSW code). It doesn't do anything if this is not a
+ // wxGCDC.
+ virtual wxRect MSWApplyGDIPlusTransform(const wxRect& r) const
+ {
+ return r;
+ }
+#endif // __WXMSW__
+
+
// ---------------------------------------------------------
// the actual drawing API
class WXDLLIMPEXP_CORE wxDC : public wxObject
{
public:
+ // copy attributes (font, colours and writing direction) from another DC
+ void CopyAttributes(const wxDC& dc);
+
virtual ~wxDC() { delete m_pimpl; }
wxDCImpl *GetImpl()
wxCoord GetCharWidth() const
{ return m_pimpl->GetCharWidth(); }
+ wxFontMetrics GetFontMetrics() const
+ {
+ wxFontMetrics fm;
+ m_pimpl->DoGetFontMetrics(&fm.height, &fm.ascent, &fm.descent,
+ &fm.internalLeading, &fm.externalLeading,
+ &fm.averageWidth);
+ return fm;
+ }
+
void GetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y,
wxCoord *descent = NULL,
void SetAxisOrientation(bool xLeftRight, bool yBottomUp)
{ m_pimpl->SetAxisOrientation(xLeftRight, yBottomUp); }
+#if wxUSE_DC_TRANSFORM_MATRIX
+ bool CanUseTransformMatrix() const
+ { return m_pimpl->CanUseTransformMatrix(); }
+
+ bool SetTransformMatrix(const wxAffineMatrix2D &matrix)
+ { return m_pimpl->SetTransformMatrix(matrix); }
+
+ wxAffineMatrix2D GetTransformMatrix() const
+ { return m_pimpl->GetTransformMatrix(); }
+
+ void ResetTransformMatrix()
+ { m_pimpl->ResetTransformMatrix(); }
+#endif // wxUSE_DC_TRANSFORM_MATRIX
+
// mostly internal
void SetDeviceLocalOrigin( wxCoord x, wxCoord y )
{ m_pimpl->SetDeviceLocalOrigin( x, y ); }
- // draw generic object
-
- void DrawObject(wxDrawObject* drawobject)
- {
- drawobject->Draw(*this);
- CalcBoundingBox(drawobject->MinX(),drawobject->MinY());
- CalcBoundingBox(drawobject->MaxX(),drawobject->MaxY());
- }
-
// -----------------------------------------------
// the actual drawing API
bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
wxDC *source, wxCoord xsrc, wxCoord ysrc,
- wxRasterOperationMode rop = wxCOPY, bool useMask = false,
+ wxRasterOperationMode rop = wxCOPY, bool useMask = false,
wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
{
return m_pimpl->DoBlit(xdest, ydest, width, height,
}
bool Blit(const wxPoint& destPt, const wxSize& sz,
wxDC *source, const wxPoint& srcPt,
- wxRasterOperationMode rop = wxCOPY, bool useMask = false,
+ wxRasterOperationMode rop = wxCOPY, bool useMask = false,
const wxPoint& srcPtMask = wxDefaultPosition)
{
return m_pimpl->DoBlit(destPt.x, destPt.y, sz.x, sz.y,
}
bool StretchBlit(const wxPoint& dstPt, const wxSize& dstSize,
wxDC *source, const wxPoint& srcPt, const wxSize& srcSize,
- wxRasterOperationMode rop = wxCOPY, bool useMask = false,
+ wxRasterOperationMode rop = wxCOPY, bool useMask = false,
const wxPoint& srcMaskPt = wxDefaultPosition)
{
return m_pimpl->DoStretchBlit(dstPt.x, dstPt.y, dstSize.x, dstSize.y,
wxDEPRECATED( void GetDeviceOrigin(long *x, long *y) const );
wxDEPRECATED( void GetClippingBox(long *x, long *y, long *w, long *h) const );
+ wxDEPRECATED( void DrawObject(wxDrawObject* drawobject) );
#endif // WXWIN_COMPATIBILITY_2_8
#ifdef __WXMSW__
+ // GetHDC() is the simplest way to retrieve an HDC From a wxDC but only
+ // works if this wxDC is GDI-based and fails for GDI+ contexts (and
+ // anything else without HDC, e.g. wxPostScriptDC)
WXHDC GetHDC() const;
+
+ // don't use these methods manually, use GetTempHDC() instead
+ virtual WXHDC AcquireHDC() { return GetHDC(); }
+ virtual void ReleaseHDC(WXHDC WXUNUSED(hdc)) { }
+
+ // helper class holding the result of GetTempHDC() with std::auto_ptr<>-like
+ // semantics, i.e. it is moved when copied
+ class TempHDC
+ {
+ public:
+ TempHDC(wxDC& dc)
+ : m_dc(dc),
+ m_hdc(dc.AcquireHDC())
+ {
+ }
+
+ TempHDC(const TempHDC& thdc)
+ : m_dc(thdc.m_dc),
+ m_hdc(thdc.m_hdc)
+ {
+ const_cast<TempHDC&>(thdc).m_hdc = 0;
+ }
+
+ ~TempHDC()
+ {
+ if ( m_hdc )
+ m_dc.ReleaseHDC(m_hdc);
+ }
+
+ WXHDC GetHDC() const { return m_hdc; }
+
+ private:
+ wxDC& m_dc;
+ WXHDC m_hdc;
+
+ wxDECLARE_NO_ASSIGN_CLASS(TempHDC);
+ };
+
+ // GetTempHDC() also works for wxGCDC (but still not for wxPostScriptDC &c)
+ TempHDC GetTempHDC() { return TempHDC(*this); }
#endif // __WXMSW__
protected:
private:
DECLARE_ABSTRACT_CLASS(wxDC)
- DECLARE_NO_COPY_CLASS(wxDC)
+ wxDECLARE_NO_COPY_CLASS(wxDC);
};
// ----------------------------------------------------------------------------
~wxDCTextColourChanger()
{
- if ( m_colFgOld.Ok() )
+ if ( m_colFgOld.IsOk() )
m_dc.SetTextForeground(m_colFgOld);
}
void Set(const wxColour& col)
{
- if ( !m_colFgOld.Ok() )
+ if ( !m_colFgOld.IsOk() )
m_colFgOld = m_dc.GetTextForeground();
m_dc.SetTextForeground(col);
}
wxColour m_colFgOld;
- DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
+ wxDECLARE_NO_COPY_CLASS(wxDCTextColourChanger);
};
// ----------------------------------------------------------------------------
~wxDCPenChanger()
{
- if ( m_penOld.Ok() )
+ if ( m_penOld.IsOk() )
m_dc.SetPen(m_penOld);
}
wxPen m_penOld;
- DECLARE_NO_COPY_CLASS(wxDCPenChanger)
+ wxDECLARE_NO_COPY_CLASS(wxDCPenChanger);
};
// ----------------------------------------------------------------------------
~wxDCBrushChanger()
{
- if ( m_brushOld.Ok() )
+ if ( m_brushOld.IsOk() )
m_dc.SetBrush(m_brushOld);
}
wxBrush m_brushOld;
- DECLARE_NO_COPY_CLASS(wxDCBrushChanger)
+ wxDECLARE_NO_COPY_CLASS(wxDCBrushChanger);
};
// ----------------------------------------------------------------------------
private:
wxDC& m_dc;
- DECLARE_NO_COPY_CLASS(wxDCClipper)
+ wxDECLARE_NO_COPY_CLASS(wxDCClipper);
};
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDCFontChanger
{
public:
- wxDCFontChanger(wxDC& dc, const wxFont& font) : m_dc(dc), m_fontOld(dc.GetFont())
+ wxDCFontChanger(wxDC& dc)
+ : m_dc(dc), m_fontOld()
+ {
+ }
+
+ wxDCFontChanger(wxDC& dc, const wxFont& font)
+ : m_dc(dc), m_fontOld(dc.GetFont())
+ {
+ m_dc.SetFont(font);
+ }
+
+ void Set(const wxFont& font)
{
+ if ( !m_fontOld.IsOk() )
+ m_fontOld = m_dc.GetFont();
m_dc.SetFont(font);
}
~wxDCFontChanger()
{
- if ( m_fontOld.Ok() )
+ if ( m_fontOld.IsOk() )
m_dc.SetFont(m_fontOld);
}
wxFont m_fontOld;
- DECLARE_NO_COPY_CLASS(wxDCFontChanger)
+ wxDECLARE_NO_COPY_CLASS(wxDCFontChanger);
};