From 332afcdb2f49bf30d1c8dd393eb0c3a37c667f26 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 14 Oct 2012 14:55:32 +0000 Subject: [PATCH] Make GetClippingBox() work for wxPrinterDC in wxGTK. GetClippingBox() implementation relies on wxDCImpl::m_clip[XY][12] being updated in DoSetClippingRegion() but this wasn't done here. Fix this by adding the code to do this to the base class version of this method and calling it from wxGtkPrinterDCImpl. Also, refactor wxGCDCImpl to reuse the same code instead of duplicating it. Closes #14697. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72674 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dc.h | 6 +++++- src/common/dcbase.cpp | 24 ++++++++++++++++++++++++ src/common/dcgraph.cpp | 16 +--------------- src/gtk/print.cpp | 2 ++ 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/include/wx/dc.h b/include/wx/dc.h index c6ff1fa3a2..34f58e2662 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -433,8 +433,12 @@ public: // clipping + // Note that this pure virtual method has an implementation that updates + // the values returned by DoGetClippingBox() and so can be called from the + // derived class overridden version if it makes sense (i.e. if the clipping + // box coordinates are not already updated in some other way). virtual void DoSetClippingRegion(wxCoord x, wxCoord y, - wxCoord width, wxCoord height) = 0; + wxCoord w, wxCoord h) = 0; // NB: this function works with device coordinates, not the logical ones! virtual void DoSetDeviceClippingRegion(const wxRegion& region) = 0; diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index 9a22d6b1c3..49fdb5f362 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -367,6 +367,30 @@ wxDCImpl::~wxDCImpl() { } +// ---------------------------------------------------------------------------- +// clipping +// ---------------------------------------------------------------------------- + +void wxDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) +{ + if ( m_clipping ) + { + m_clipX1 = wxMax( m_clipX1, x ); + m_clipY1 = wxMax( m_clipY1, y ); + m_clipX2 = wxMin( m_clipX2, (x + w) ); + m_clipY2 = wxMin( m_clipY2, (y + h) ); + } + else + { + m_clipping = true; + + m_clipX1 = x; + m_clipY1 = y; + m_clipX2 = x + w; + m_clipY2 = y + h; + } +} + // ---------------------------------------------------------------------------- // coordinate conversions and transforms // ---------------------------------------------------------------------------- diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 2388f3ec8c..2b9b2913a5 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -289,22 +289,8 @@ void wxGCDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") ); m_graphicContext->Clip( x, y, w, h ); - if ( m_clipping ) - { - m_clipX1 = wxMax( m_clipX1, x ); - m_clipY1 = wxMax( m_clipY1, y ); - m_clipX2 = wxMin( m_clipX2, (x + w) ); - m_clipY2 = wxMin( m_clipY2, (y + h) ); - } - else - { - m_clipping = true; - m_clipX1 = x; - m_clipY1 = y; - m_clipX2 = x + w; - m_clipY2 = y + h; - } + wxDCImpl::DoSetClippingRegion(x, y, w, h); } void wxGCDCImpl::DoSetDeviceClippingRegion( const wxRegion ®ion ) diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index f2f1b27f40..d3ffb65e26 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -2072,6 +2072,8 @@ void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width { cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height)); cairo_clip(m_cairo); + + wxDCImpl::DoSetClippingRegion(x, y, width, height); } void wxGtkPrinterDCImpl::DestroyClippingRegion() -- 2.45.2