Add bool return value for wxDC::GetClippingBox()

Determining whether there is an actual clipping region or not is not
that simple, as shown by the recent problems in wxDCClipper code, so
return a boolean value indicating this from GetClippingBox() directly,
instead of requiring the caller to find it out on their own.

This simplifies wxDCClipper code, as well as any other code calling
GetClippingBox(), at the price of some extra complexity in wxDCImpl
itself, which seems to be worth it.
This commit is contained in:
Vadim Zeitlin
2018-06-18 14:39:11 +02:00
parent 119dce5eb8
commit 350867939a
3 changed files with 111 additions and 28 deletions

View File

@@ -406,6 +406,61 @@ void wxDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
}
}
wxRect wxDCImpl::GetLogicalArea() const
{
const wxSize size = GetSize();
return wxRect(DeviceToLogicalX(0),
DeviceToLogicalY(0),
DeviceToLogicalXRel(size.x),
DeviceToLogicalYRel(size.y));
}
bool wxDCImpl::DoGetClippingRect(wxRect& rect) const
{
// Call the old function for compatibility.
DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height);
if ( rect != wxRect(-1, -1, 0, 0) )
{
// Custom overridden version of DoGetClippingBox() was called, we need
// to check if there is an actual clipping region or not. Normally the
// function is supposed to return the whole DC area (in logical
// coordinates) in this case, but also check that the clipping region
// is not empty because some implementations seem to do this instead.
return !rect.IsEmpty() && rect != GetLogicalArea();
}
if ( m_clipping )
{
rect = wxRect(m_clipX1,
m_clipY1,
m_clipX2 - m_clipX1,
m_clipY2 - m_clipY1);
return true;
}
else // No active clipping region.
{
rect = GetLogicalArea();
return false;
}
}
void wxDCImpl::DoGetClippingBox(wxCoord *x, wxCoord *y,
wxCoord *w, wxCoord *h) const
{
// Dummy implementation just to allow DoGetClippingRect() above to
// determine if this version was called or not.
if ( x )
*x = -1;
if ( y )
*y = -1;
if ( w )
*w = 0;
if ( h )
*h = 0;
}
// ----------------------------------------------------------------------------
// coordinate conversions and transforms
// ----------------------------------------------------------------------------