From 265dd232419333a141779e6616df094e4337268d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Oct 2011 21:56:40 +0000 Subject: [PATCH] Don't create a valid wxRegion when using default ctor in wxOSX. Default constructing a wxRegion created an object that unexpectedly passed IsOk() test in wxOSX. This was completely unexpected so don't do this and leave default constructed wxRegion invalid, as in the other ports. Update DoCombine() to be able to deal with the case of an invalid source region in a way consistent with the other ports. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69459 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/carbon/region.h | 2 +- src/osx/carbon/region.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/include/wx/osx/carbon/region.h b/include/wx/osx/carbon/region.h index 4701c91fac..685c39de66 100644 --- a/include/wx/osx/carbon/region.h +++ b/include/wx/osx/carbon/region.h @@ -17,12 +17,12 @@ class WXDLLIMPEXP_CORE wxRegion : public wxRegionWithCombine { public: + wxRegion() { } wxRegion(long x, long y, long w, long h); wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight); wxRegion(const wxRect& rect); wxRegion( WXHRGN hRegion ); wxRegion(size_t n, const wxPoint *points, wxPolygonFillMode fillStyle = wxODDEVEN_RULE ); - wxRegion(); #if wxUSE_IMAGE wxRegion(const wxBitmap& bmp) { diff --git a/src/osx/carbon/region.cpp b/src/osx/carbon/region.cpp index 6f703117da..ff12238509 100644 --- a/src/osx/carbon/region.cpp +++ b/src/osx/carbon/region.cpp @@ -68,14 +68,6 @@ public: // wxRegion //----------------------------------------------------------------------------- -/*! - * Create an empty region. - */ -wxRegion::wxRegion() -{ - m_refData = new wxRegionRefData(); -} - wxRegion::wxRegion(WXHRGN hRegion ) { wxCFRef< HIShapeRef > shape( (HIShapeRef) hRegion ); @@ -205,6 +197,30 @@ bool wxRegion::DoCombine(const wxRegion& region, wxRegionOp op) { wxCHECK_MSG( region.IsOk(), false, wxT("invalid wxRegion") ); + // Handle the special case of not initialized (e.g. default constructed) + // region as we can't use HIShape functions if we don't have any shape. + if ( !m_refData ) + { + switch ( op ) + { + case wxRGN_COPY: + case wxRGN_OR: + case wxRGN_XOR: + // These operations make sense with a null region. + *this = region; + return true; + + case wxRGN_AND: + case wxRGN_DIFF: + // Those ones don't really make sense so just leave this region + // empty/invalid. + return false; + } + + wxFAIL_MSG( wxT("Unknown region operation") ); + return false; + } + AllocExclusive(); switch (op) -- 2.45.2