X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0903bd055aef36924bd492c277eace3e6f48a599..6cef0db28018fd2644ee4e38af715872e5242459:/src/mac/carbon/region.cpp diff --git a/src/mac/carbon/region.cpp b/src/mac/carbon/region.cpp index 901b72c08a..d08fd4984c 100644 --- a/src/mac/carbon/region.cpp +++ b/src/mac/carbon/region.cpp @@ -29,22 +29,22 @@ class WXDLLEXPORT wxRegionRefData : public wxGDIRefData { public: wxRegionRefData() - { - m_macRgn.reset( HIShapeCreateMutable() ); + { + m_macRgn.reset( HIShapeCreateMutable() ); } - wxRegionRefData(HIShapeRef hRegion) - { - m_macRgn.reset( HIShapeCreateMutableCopy(hRegion) ); + wxRegionRefData(wxCFRef ®ion) + { + m_macRgn.reset( HIShapeCreateMutableCopy(region) ); } - + 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) ); + m_macRgn.reset( HIShapeCreateMutableCopy(rect) ); } - + wxRegionRefData(const wxRegionRefData& data) : wxGDIRefData() { @@ -52,7 +52,7 @@ public: } virtual ~wxRegionRefData() - { + { } wxCFRef m_macRgn; @@ -75,7 +75,8 @@ wxRegion::wxRegion() wxRegion::wxRegion(WXHRGN hRegion ) { - m_refData = new wxRegionRefData(hRegion); + wxCFRef< HIShapeRef > shape( (HIShapeRef) hRegion ); + m_refData = new wxRegionRefData(shape); } wxRegion::wxRegion(long x, long y, long w, long h) @@ -85,8 +86,8 @@ wxRegion::wxRegion(long x, long y, long w, long h) wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight) { - m_refData = new wxRegionRefData(topLeft.x , topLeft.y , - topLeft.x - bottomRight.x , + m_refData = new wxRegionRefData(topLeft.x , topLeft.y , + topLeft.x - bottomRight.x , topLeft.y - bottomRight.y); } @@ -97,9 +98,11 @@ wxRegion::wxRegion(const wxRect& rect) wxRegion::wxRegion(size_t n, const wxPoint *points, int WXUNUSED(fillStyle)) { - m_refData = new wxRegionRefData; + wxUnusedVar(n); + wxUnusedVar(points); + +#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 @@ -134,10 +137,21 @@ wxRegion::wxRegion(size_t n, const wxPoint *points, int WXUNUSED(fillStyle)) if ( x1 != x2 || y1 != y2 ) ::LineTo( x1, y1 ) ; - CloseRgn( M_REGION ) ; - + RgnHandle tempRgn = NewRgn(); + CloseRgn( tempRgn ) ; + ::SetGWorld( oldWorld, oldGDHandle ); + wxCFRef tempShape( HIShapeCreateWithQDRgn(tempRgn ) ); + m_refData = new wxRegionRefData(tempShape); + DisposeRgn( tempRgn ); + } + else + { + m_refData = new wxRegionRefData; } +#else + wxFAIL_MSG( "not implemented" ); + m_refData = NULL; #endif } @@ -146,6 +160,16 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } +wxGDIRefData *wxRegion::CreateGDIRefData() const +{ + return new wxRegionRefData; +} + +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxRegionRefData(*wx_static_cast(const wxRegionRefData *, data)); +} + //----------------------------------------------------------------------------- //# Modify region //----------------------------------------------------------------------------- @@ -165,7 +189,7 @@ bool wxRegion::DoOffset(wxCoord x, wxCoord y) // nothing to do return true; - HIShapeOffset( M_REGION , x , y ) ; + verify_noerr( HIShapeOffset( M_REGION , x , y ) ) ; return true ; } @@ -191,11 +215,11 @@ bool wxRegion::DoCombine(const wxRegion& region, wxRegionOp op) switch (op) { case wxRGN_AND: - HIShapeIntersect( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; + verify_noerr( HIShapeIntersect( M_REGION , OTHER_M_REGION(region) , M_REGION ) ); break ; case wxRGN_OR: - HIShapeUnion( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; + verify_noerr( HIShapeUnion( M_REGION , OTHER_M_REGION(region) , M_REGION ) ); break ; case wxRGN_XOR: @@ -203,12 +227,12 @@ bool wxRegion::DoCombine(const wxRegion& region, wxRegionOp op) // 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 ); + verify_noerr( HIShapeDifference( unionshape, intersectionshape, M_REGION ) ); } break ; case wxRGN_DIFF: - HIShapeDifference( M_REGION , OTHER_M_REGION(region) , M_REGION ) ; + verify_noerr( HIShapeDifference( M_REGION , OTHER_M_REGION(region) , M_REGION ) ) ; break ; case wxRGN_COPY: @@ -238,10 +262,10 @@ bool wxRegion::DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const { CGRect box ; HIShapeGetBounds( M_REGION , &box ) ; - x = box.origin.x ; - y = box.origin.y ; - w = box.size.width ; - h = box.size.height ; + x = wx_static_cast(int, box.origin.x); + y = wx_static_cast(int, box.origin.y); + w = wx_static_cast(int, box.size.width); + h = wx_static_cast(int, box.size.height); return true; } @@ -295,11 +319,13 @@ wxRegionContain wxRegion::DoContainsRect(const wxRect& r) const wxCFRef intersect(HIShapeCreateIntersection(rectshape,M_REGION)); CGRect bounds; HIShapeGetBounds(intersect, &bounds); - + if ( HIShapeIsRectangular(intersect) && CGRectEqualToRect(rect,bounds) ) return wxInRegion; - else + else if ( HIShapeIsEmpty( intersect ) ) return wxOutRegion; + else + return wxPartRegion; } /////////////////////////////////////////////////////////////////////////////// @@ -438,14 +464,14 @@ void wxRegionIterator::Reset(const wxRegion& region) m_numRects = 1; m_rects = new wxRect[m_numRects]; m_rects[0] = m_region.GetBox(); - + #else RegionToRectsUPP proc = (RegionToRectsUPP) wxMacRegionToRectsCounterCallback; OSStatus err = noErr; RgnHandle rgn = NewRgn(); HIShapeGetAsQDRgn(OTHER_M_REGION(region), rgn); - + err = QDRegionToRects (rgn, kQDParseRegionFromTopLeft, proc, (void*)&m_numRects); if (err == noErr) {