Switch to using DoGetClippingRect() instead of DoGetClippingBox()

The new method returns a boolean flag which indicates whether there is
any clipping region or not and so is preferable to using the old one and
checking its return value to determine this, which can't be done
reliably.
This commit is contained in:
Vadim Zeitlin
2018-06-18 23:57:05 +02:00
parent 43ce00b5bd
commit c5530b1abf
9 changed files with 54 additions and 44 deletions

View File

@@ -453,11 +453,15 @@ public:
// up to date.
virtual bool DoGetClippingRect(wxRect& rect) const;
#if WXWIN_COMPATIBILITY_3_0
// This method is kept for backwards compatibility but shouldn't be used
// nor overridden in the new code, implement DoGetClippingRect() above
// instead.
wxDEPRECATED_BUT_USED_INTERNALLY(
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
wxCoord *w, wxCoord *h) const;
wxCoord *w, wxCoord *h) const
);
#endif // WXWIN_COMPATIBILITY_3_0
virtual void DestroyClippingRegion() { ResetClipping(); }

View File

@@ -195,8 +195,7 @@ public:
virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE;
virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
wxCoord width, wxCoord height) wxOVERRIDE;
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
wxCoord *w, wxCoord *h) const wxOVERRIDE;
virtual bool DoGetClippingRect(wxRect& rect) const wxOVERRIDE;
virtual void DoGetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y,

View File

@@ -71,7 +71,7 @@ public:
virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const wxOVERRIDE;
virtual void DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) wxOVERRIDE;
virtual void DoSetDeviceClippingRegion( const wxRegion &region ) wxOVERRIDE;
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const wxOVERRIDE;
virtual bool DoGetClippingRect(wxRect& rect) const wxOVERRIDE;
virtual wxCoord GetCharWidth() const wxOVERRIDE;
virtual wxCoord GetCharHeight() const wxOVERRIDE;

View File

@@ -243,8 +243,7 @@ public:
virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
wxCoord width, wxCoord height) wxOVERRIDE;
virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE;
virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
wxCoord *w, wxCoord *h) const wxOVERRIDE;
virtual bool DoGetClippingRect(wxRect& rect) const wxOVERRIDE;
virtual void DoGetSizeMM(int* width, int* height) const wxOVERRIDE;

View File

@@ -414,6 +414,7 @@ wxRect wxDCImpl::GetLogicalArea() const
bool wxDCImpl::DoGetClippingRect(wxRect& rect) const
{
#if WXWIN_COMPATIBILITY_3_0
// Call the old function for compatibility.
DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height);
if ( rect != wxRect(-1, -1, 0, 0) )
@@ -425,6 +426,7 @@ bool wxDCImpl::DoGetClippingRect(wxRect& rect) const
// is not empty because some implementations seem to do this instead.
return !rect.IsEmpty() && rect != GetLogicalArea();
}
#endif // WXWIN_COMPATIBILITY_3_0
if ( m_clipping )
{
@@ -443,6 +445,7 @@ bool wxDCImpl::DoGetClippingRect(wxRect& rect) const
}
}
#if WXWIN_COMPATIBILITY_3_0
void wxDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y,
wxCoord *w, wxCoord *h) const
{
@@ -457,6 +460,7 @@ void wxDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y,
if ( h )
*h = 0;
}
#endif // WXWIN_COMPATIBILITY_3_0
// ----------------------------------------------------------------------------
// coordinate conversions and transforms
@@ -1370,12 +1374,12 @@ void wxDC::GetDeviceOrigin(long *x, long *y) const
void wxDC::GetClippingBox(long *x, long *y, long *w, long *h) const
{
wxCoord xx,yy,ww,hh;
m_pimpl->DoGetClippingBox(&xx, &yy, &ww, &hh);
if (x) *x = xx;
if (y) *y = yy;
if (w) *w = ww;
if (h) *h = hh;
wxRect r;
m_pimpl->DoGetClippingRect(r);
if (x) *x = r.x;
if (y) *y = r.y;
if (w) *w = r.width;
if (h) *h = r.height;
}
void wxDC::DrawObject(wxDrawObject* drawobject)

View File

@@ -282,6 +282,17 @@ void wxGCDCImpl::UpdateClipBox()
double x, y, w, h;
m_graphicContext->GetClipBox(&x, &y, &w, &h);
// We shouldn't reset m_clipping if the clipping region that we set happens
// to be empty (e.g. because its intersection with the previous clipping
// region was empty), but we should set it to true if we do have a valid
// clipping region and it was false which may happen if the clipping region
// set from the outside of wxWidgets code.
if ( !m_clipping )
{
if ( w != 0. && h != 0. )
m_clipping = true;
}
m_clipX1 = wxRound(x);
m_clipY1 = wxRound(y);
m_clipX2 = wxRound(x+w);
@@ -289,9 +300,9 @@ void wxGCDCImpl::UpdateClipBox()
m_isClipBoxValid = true;
}
void wxGCDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
bool wxGCDCImpl::DoGetClippingRect(wxRect& rect) const
{
wxCHECK_RET( IsOk(), wxS("wxGCDC::DoGetClippingRegion - invalid GC") );
wxCHECK_MSG( IsOk(), false, wxS("wxGCDC::DoGetClippingRegion - invalid GC") );
// Check if we should retrieve the clipping region possibly not set
// by SetClippingRegion() but modified by application: this can
// happen when we're associated with an existing graphics context using
@@ -303,14 +314,7 @@ void wxGCDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h
self->UpdateClipBox();
}
if ( x )
*x = m_clipX1;
if ( y )
*y = m_clipY1;
if ( w )
*w = m_clipX2 - m_clipX1;
if ( h )
*h = m_clipY2 - m_clipY1;
return wxDCImpl::DoGetClippingRect(rect);
}
void wxGCDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )

View File

@@ -1914,9 +1914,9 @@ void wxWindowDCImpl::UpdateClipBox()
m_isClipBoxValid = true;
}
void wxWindowDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
bool wxWindowDCImpl::DoGetClippingRect(wxRect& rect) const
{
wxCHECK_RET( IsOk(), wxS("invalid window dc") );
wxCHECK_MSG( IsOk(), false, wxS("invalid window dc") );
// Check if we should try to retrieve the clipping region possibly not set
// by our SetClippingRegion() but preset or modified by application: this
@@ -1928,14 +1928,7 @@ void wxWindowDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoor
self->UpdateClipBox();
}
if ( x )
*x = m_clipX1;
if ( y )
*y = m_clipY1;
if ( w )
*w = m_clipX2 - m_clipX1;
if ( h )
*h = m_clipY2 - m_clipY1;
return wxGTKDCImpl::DoGetClippingRect(rect);
}
void wxWindowDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )

View File

@@ -574,8 +574,7 @@ void wxMSWDCImpl::UpdateClipBox()
m_isClipBoxValid = true;
}
void
wxMSWDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
bool wxMSWDCImpl::DoGetClippingRect(wxRect& rect) const
{
// check if we should try to retrieve the clipping region possibly not set
// by our SetClippingRegion() but preset or modified by Windows: this
@@ -589,14 +588,22 @@ wxMSWDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) co
self->UpdateClipBox();
}
if ( x )
*x = m_clipX1;
if ( y )
*y = m_clipY1;
if ( w )
*w = m_clipX2 - m_clipX1;
if ( h )
*h = m_clipY2 - m_clipY1;
// Unfortunately we can't just call wxDCImpl::DoGetClippingRect() here
// because it wouldn't return the correct result if there is no clipping
// region and this DC has a world transform applied to it, as the base
// class version doesn't know anything about world transforms and wouldn't
// apply it to GetLogicalArea() that it returns in this case.
//
// We could solve this by overriding GetLogicalArea() in wxMSW and using
// DPtoLP() to perform the conversion correctly ourselves, but it's even
// simpler to just use the value returned by our UpdateClipBox() which is
// already correct in any case, so just do this instead.
rect = wxRect(m_clipX1,
m_clipY1,
m_clipX2 - m_clipX1,
m_clipY2 - m_clipY1);
return m_clipping;
}
// common part of DoSetClippingRegion() and DoSetDeviceClippingRegion()

View File

@@ -302,7 +302,7 @@ wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *window ) :
InitDC();
// the HDC can have a clipping box (which we didn't set), make sure our
// DoGetClippingBox() checks for it
// DoGetClippingRect() checks for it
m_clipping = true;
}