X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4feecbb929662fa002239fe7fc46d464b12f758e..cba4e486a4f8ab05674bac6ed8c6bfa58ab25131:/include/wx/dc.h?ds=sidebyside diff --git a/include/wx/dc.h b/include/wx/dc.h index aa5110066d..c6ff1fa3a2 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -29,7 +29,8 @@ #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 @@ -42,6 +43,10 @@ class WXDLLIMPEXP_FWD_CORE wxMemoryDC; class WXDLLIMPEXP_FWD_CORE wxPrinterDC; class WXDLLIMPEXP_FWD_CORE wxPrintData; +#if wxUSE_GRAPHICS_CONTEXT +class WXDLLIMPEXP_FWD_CORE wxGraphicsContext; +#endif + // Logical ops enum wxRasterOperationMode { @@ -114,6 +119,27 @@ enum wxMappingMode 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 //----------------------------------------------------------------------------- @@ -257,6 +283,8 @@ public: return NULL; } + virtual void* GetHandle() const { return NULL; } + // query dimension, colour deps, resolution virtual void DoGetSize(int *width, int *height) const = 0; @@ -375,6 +403,18 @@ public: 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, @@ -437,7 +477,7 @@ public: } virtual void SetLogicalScale(double x, double y); - virtual void GetLogicalScale(double *x, double *y) + virtual void GetLogicalScale(double *x, double *y) const { if ( x ) *x = m_logicalScaleX; if ( y ) *y = m_logicalScaleY; @@ -457,6 +497,20 @@ public: 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(); @@ -464,6 +518,19 @@ public: // 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 @@ -579,6 +646,13 @@ public: virtual int GetResolution() const { return -1; } +#if wxUSE_GRAPHICS_CONTEXT + virtual wxGraphicsContext* GetGraphicsContext() const + { return NULL; } + virtual void SetGraphicsContext( wxGraphicsContext* WXUNUSED(ctx) ) + {} +#endif + private: wxDC *m_owner; @@ -715,6 +789,9 @@ public: wxWindow *GetWindow() const { return m_pimpl->GetWindow(); } + void *GetHandle() const + { return m_pimpl->GetHandle(); } + bool IsOk() const { return m_pimpl && m_pimpl->IsOk(); } @@ -840,6 +917,15 @@ public: 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, @@ -939,7 +1025,7 @@ public: void SetLogicalScale(double x, double y) { m_pimpl->SetLogicalScale( x, y ); } - void GetLogicalScale(double *x, double *y) + void GetLogicalScale(double *x, double *y) const { m_pimpl->GetLogicalScale( x, y ); } void SetLogicalOrigin(wxCoord x, wxCoord y) @@ -959,6 +1045,20 @@ public: 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 ); } @@ -1199,9 +1299,63 @@ public: #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(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__ +#if wxUSE_GRAPHICS_CONTEXT + virtual wxGraphicsContext* GetGraphicsContext() const + { + return m_pimpl->GetGraphicsContext(); + } + virtual void SetGraphicsContext( wxGraphicsContext* ctx ) + { + m_pimpl->SetGraphicsContext(ctx); + } +#endif + protected: // ctor takes ownership of the pointer wxDC(wxDCImpl *pimpl) : m_pimpl(pimpl) { } @@ -1230,13 +1384,13 @@ public: ~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); } @@ -1264,7 +1418,7 @@ public: ~wxDCPenChanger() { - if ( m_penOld.Ok() ) + if ( m_penOld.IsOk() ) m_dc.SetPen(m_penOld); } @@ -1291,7 +1445,7 @@ public: ~wxDCBrushChanger() { - if ( m_brushOld.Ok() ) + if ( m_brushOld.IsOk() ) m_dc.SetBrush(m_brushOld); } @@ -1334,14 +1488,27 @@ private: 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); }