fixed calling Union() or Offset() on a previously Clear()ed region, also removed some duplicate code (bug 560302 and more)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15663 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-05-25 14:23:36 +00:00
parent 7e25f59e48
commit 3317223b08

View File

@@ -66,6 +66,7 @@ public:
}; };
#define M_REGION (((wxRegionRefData*)m_refData)->m_region) #define M_REGION (((wxRegionRefData*)m_refData)->m_region)
#define M_REGION_OF(rgn) (((wxRegionRefData*)(rgn.m_refData))->m_region)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxRegion // wxRegion
@@ -146,6 +147,8 @@ void wxRegion::Clear()
bool wxRegion::Offset(wxCoord x, wxCoord y) bool wxRegion::Offset(wxCoord x, wxCoord y)
{ {
wxCHECK_MSG( M_REGION, FALSE, _T("invalid wxRegion") );
if ( !x && !y ) if ( !x && !y )
{ {
// nothing to do // nothing to do
@@ -164,62 +167,85 @@ bool wxRegion::Offset(wxCoord x, wxCoord y)
return TRUE; return TRUE;
} }
// Combine rectangle (x, y, w, h) with this. // combine another region with this one
bool wxRegion::Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op) bool wxRegion::Combine(const wxRegion& rgn, wxRegionOp op)
{ {
AllocExclusive(); // we can't use the API functions if we don't have a valid region handle
if ( !m_refData )
HRGN rectRegion = ::CreateRectRgn(x, y, x + width, y + height); {
// combining with an empty/invalid region works differently depending
int mode = 0; // on the operation
switch ( op ) switch ( op )
{ {
case wxRGN_AND: mode = RGN_AND; break ;
case wxRGN_OR: mode = RGN_OR; break ;
case wxRGN_XOR: mode = RGN_XOR; break ;
case wxRGN_DIFF: mode = RGN_DIFF; break ;
case wxRGN_COPY: case wxRGN_COPY:
case wxRGN_OR:
case wxRGN_XOR:
*this = rgn;
break;
default: default:
mode = RGN_COPY; break ; wxFAIL_MSG( _T("unknown region operation") );
// fall through
case wxRGN_AND:
case wxRGN_DIFF:
// leave empty/invalid
return FALSE;
}
}
else // we have a valid region
{
int mode;
switch ( op )
{
case wxRGN_AND:
mode = RGN_AND;
break;
case wxRGN_OR:
mode = RGN_OR;
break;
case wxRGN_XOR:
mode = RGN_XOR;
break;
case wxRGN_DIFF:
mode = RGN_DIFF;
break;
default:
wxFAIL_MSG( _T("unknown region operation") );
// fall through
case wxRGN_COPY:
mode = RGN_COPY;
break;
} }
bool success = ::CombineRgn(M_REGION, M_REGION, rectRegion, mode) != ERROR; if ( ::CombineRgn(M_REGION, M_REGION, M_REGION_OF(rgn), mode) == ERROR )
if ( !success )
{ {
wxLogLastError(_T("CombineRgn")); wxLogLastError(_T("CombineRgn"));
}
::DeleteObject(rectRegion);
return success;
}
// Union /e region with this.
bool wxRegion::Combine(const wxRegion& region, wxRegionOp op)
{
if (region.Empty())
return FALSE; return FALSE;
}
AllocExclusive();
int mode = 0;
switch (op)
{
case wxRGN_AND: mode = RGN_AND; break ;
case wxRGN_OR: mode = RGN_OR; break ;
case wxRGN_XOR: mode = RGN_XOR; break ;
case wxRGN_DIFF: mode = RGN_DIFF; break ;
case wxRGN_COPY:
default:
mode = RGN_COPY; break ;
} }
return (ERROR != ::CombineRgn(M_REGION, M_REGION, ((wxRegionRefData*)region.m_refData)->m_region, mode)); return TRUE;
}
// Combine rectangle (x, y, w, h) with this.
bool wxRegion::Combine(wxCoord x, wxCoord y,
wxCoord width, wxCoord height,
wxRegionOp op)
{
return Combine(wxRegion(x, y, width, height), op);
} }
bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) bool wxRegion::Combine(const wxRect& rect, wxRegionOp op)
{ {
return Combine(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), op); return Combine(rect.GetLeft(), rect.GetTop(),
rect.GetWidth(), rect.GetHeight(), op);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------