X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e6c3d3e655c4637764f60eb28a3d7e7ed3d9732b..409521e45d44fc57df39efcb965701d378edcb20:/src/mac/carbon/region.cpp diff --git a/src/mac/carbon/region.cpp b/src/mac/carbon/region.cpp index b8147e5db8..901b72c08a 100644 --- a/src/mac/carbon/region.cpp +++ b/src/mac/carbon/region.cpp @@ -29,19 +29,33 @@ class WXDLLEXPORT wxRegionRefData : public wxGDIRefData { public: wxRegionRefData() - { m_macRgn = NewRgn(); } + { + m_macRgn.reset( HIShapeCreateMutable() ); + } + wxRegionRefData(HIShapeRef hRegion) + { + m_macRgn.reset( HIShapeCreateMutableCopy(hRegion) ); + } + + wxRegionRefData(long x, long y, long w, long h) + { + CGRect r = CGRectMake(x,y,w,h); + wxCFRef rect(HIShapeCreateWithRect(&r)); + m_macRgn.reset( HIShapeCreateMutableCopy(rect) ); + } + wxRegionRefData(const wxRegionRefData& data) : wxGDIRefData() { - m_macRgn = NewRgn(); - CopyRgn( data.m_macRgn , m_macRgn ); + m_macRgn.reset( HIShapeCreateMutableCopy(data.m_macRgn) ); } virtual ~wxRegionRefData() - { DisposeRgn( m_macRgn ); } + { + } - RgnHandle m_macRgn; + wxCFRef m_macRgn; }; #define M_REGION (((wxRegionRefData*)m_refData)->m_macRgn) @@ -56,38 +70,36 @@ public: */ wxRegion::wxRegion() { - m_refData = new wxRegionRefData; + m_refData = new wxRegionRefData(); } wxRegion::wxRegion(WXHRGN hRegion ) { - m_refData = new wxRegionRefData; - CopyRgn( (RgnHandle) hRegion , (RgnHandle) M_REGION ) ; + m_refData = new wxRegionRefData(hRegion); } wxRegion::wxRegion(long x, long y, long w, long h) { - m_refData = new wxRegionRefData; - SetRectRgn( (RgnHandle) M_REGION , x , y , x + w , y + h ) ; + m_refData = new wxRegionRefData(x , y , w , h ); } wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight) { - m_refData = new wxRegionRefData; - SetRectRgn( (RgnHandle) M_REGION , topLeft.x , topLeft.y , bottomRight.x , bottomRight.y ) ; + m_refData = new wxRegionRefData(topLeft.x , topLeft.y , + topLeft.x - bottomRight.x , + topLeft.y - bottomRight.y); } wxRegion::wxRegion(const wxRect& rect) { - m_refData = new wxRegionRefData; - SetRectRgn( (RgnHandle) M_REGION , rect.x , rect.y , rect.x + rect.width , rect.y + rect.height ) ; + m_refData = new wxRegionRefData(rect.x , rect.y , rect.width , rect.height); } wxRegion::wxRegion(size_t n, const wxPoint *points, int WXUNUSED(fillStyle)) { m_refData = new wxRegionRefData; -#ifndef __LP64__ +#if 0 // ndef __LP64__ // TODO : any APIs ? // OS X somehow does not collect the region invisibly as before, so sometimes things // get drawn on screen instead of just being combined into a region, therefore we allocate a temp gworld now @@ -153,7 +165,7 @@ bool wxRegion::DoOffset(wxCoord x, wxCoord y) // nothing to do return true; - OffsetRgn( M_REGION , x , y ) ; + HIShapeOffset( M_REGION , x , y ) ; return true ; } @@ -179,24 +191,29 @@ bool wxRegion::DoCombine(const wxRegion& region, wxRegionOp op) switch (op) { case wxRGN_AND: - SectRgn( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; + HIShapeIntersect( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; break ; case wxRGN_OR: - UnionRgn( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; + HIShapeUnion( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; break ; case wxRGN_XOR: - XorRgn( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; + { + // XOR is defined as the difference between union and intersection + wxCFRef< HIShapeRef > unionshape( HIShapeCreateUnion( M_REGION , OTHER_M_REGION(region) ) ); + wxCFRef< HIShapeRef > intersectionshape( HIShapeCreateIntersection( M_REGION , OTHER_M_REGION(region) ) ); + HIShapeDifference( unionshape, intersectionshape, M_REGION ); + } break ; case wxRGN_DIFF: - DiffRgn( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; + HIShapeDifference( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; break ; case wxRGN_COPY: default: - CopyRgn( OTHER_M_REGION(region) , M_REGION ) ; + M_REGION.reset( HIShapeCreateMutableCopy( OTHER_M_REGION(region) ) ); break ; } @@ -207,7 +224,7 @@ bool wxRegion::DoCombine(const wxRegion& region, wxRegionOp op) //# Information on region //----------------------------------------------------------------------------- -bool wxRegion::DoIsEqual(const wxRegion& region) const +bool wxRegion::DoIsEqual(const wxRegion& WXUNUSED(region)) const { wxFAIL_MSG( _T("not implemented") ); @@ -219,12 +236,12 @@ bool wxRegion::DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const { if (m_refData) { - Rect box ; - GetRegionBounds( M_REGION , &box ) ; - x = box.left ; - y = box.top ; - w = box.right - box.left ; - h = box.bottom - box.top ; + CGRect box ; + HIShapeGetBounds( M_REGION , &box ) ; + x = box.origin.x ; + y = box.origin.y ; + w = box.size.width ; + h = box.size.height ; return true; } @@ -240,7 +257,7 @@ bool wxRegion::DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const bool wxRegion::IsEmpty() const { if ( m_refData ) - return EmptyRgn( M_REGION ) ; + return HIShapeIsEmpty( M_REGION ) ; else return true ; } @@ -260,8 +277,8 @@ wxRegionContain wxRegion::DoContainsPoint(wxCoord x, wxCoord y) const if (!m_refData) return wxOutRegion; - Point p = { y , x } ; - if (PtInRgn( p , M_REGION ) ) + CGPoint p = { y , x } ; + if (HIShapeContainsPoint( M_REGION , &p ) ) return wxInRegion; return wxOutRegion; @@ -273,8 +290,13 @@ wxRegionContain wxRegion::DoContainsRect(const wxRect& r) const if (!m_refData) return wxOutRegion; - Rect rect = { r.y , r.x , r.y + r.height , r.x + r.width } ; - if (RectInRgn( &rect , M_REGION ) ) + CGRect rect = CGRectMake(r.x,r.y,r.width,r.height); + wxCFRef rectshape(HIShapeCreateWithRect(&rect)); + wxCFRef intersect(HIShapeCreateIntersection(rectshape,M_REGION)); + CGRect bounds; + HIShapeGetBounds(intersect, &bounds); + + if ( HIShapeIsRectangular(intersect) && CGRectEqualToRect(rect,bounds) ) return wxInRegion; else return wxOutRegion; @@ -357,8 +379,9 @@ wxRegionIterator::wxRegionIterator(const wxRegion& region) * Reset iterator for a new /e region. */ +#ifndef __LP64__ OSStatus wxMacRegionToRectsCounterCallback( - UInt16 message, RgnHandle region, const Rect *rect, void *data ) + UInt16 message, RgnHandle WXUNUSED(region), const Rect *WXUNUSED(rect), void *data ) { long *m_numRects = (long*) data ; if ( message == kQDRegionToRectsMsgInit ) @@ -381,7 +404,7 @@ public : }; OSStatus wxMacRegionToRectsSetterCallback( - UInt16 message, RgnHandle region, const Rect *rect, void *data ) + UInt16 message, RgnHandle WXUNUSED(region), const Rect *rect, void *data ) { if (message == kQDRegionToRectsMsgParse) { @@ -391,6 +414,7 @@ OSStatus wxMacRegionToRectsSetterCallback( return noErr; } +#endif void wxRegionIterator::Reset(const wxRegion& region) { @@ -409,39 +433,34 @@ void wxRegionIterator::Reset(const wxRegion& region) } else { - RegionToRectsUPP proc = -#ifdef __MACH__ - (RegionToRectsUPP) wxMacRegionToRectsCounterCallback; +#ifdef __LP64__ + // copying this to a path and dissecting the path would be an option + m_numRects = 1; + m_rects = new wxRect[m_numRects]; + m_rects[0] = m_region.GetBox(); + #else - NewRegionToRectsUPP( wxMacRegionToRectsCounterCallback ); -#endif + RegionToRectsUPP proc = (RegionToRectsUPP) wxMacRegionToRectsCounterCallback; OSStatus err = noErr; - err = QDRegionToRects (OTHER_M_REGION( region ) , kQDParseRegionFromTopLeft, proc, (void*)&m_numRects); + RgnHandle rgn = NewRgn(); + HIShapeGetAsQDRgn(OTHER_M_REGION(region), rgn); + + err = QDRegionToRects (rgn, kQDParseRegionFromTopLeft, proc, (void*)&m_numRects); if (err == noErr) { -#ifndef __MACH__ - DisposeRegionToRectsUPP (proc); -#endif - proc = -#ifdef __MACH__ - (RegionToRectsUPP) wxMacRegionToRectsSetterCallback; -#else - NewRegionToRectsUPP (wxMacRegionToRectsSetterCallback); -#endif + proc = (RegionToRectsUPP) wxMacRegionToRectsSetterCallback; m_rects = new wxRect[m_numRects]; RegionToRectsCallbackData data ; data.m_rects = m_rects ; data.m_current = 0 ; - QDRegionToRects( OTHER_M_REGION( region ) , kQDParseRegionFromTopLeft, proc, (void*)&data ); + QDRegionToRects( rgn , kQDParseRegionFromTopLeft, proc, (void*)&data ); } else { m_numRects = 0; } - -#ifndef __MACH__ - DisposeRegionToRectsUPP( proc ); + DisposeRgn( rgn ); #endif } }