diff --git a/src/mac/carbon/graphics.cpp b/src/mac/carbon/graphics.cpp index 2c9c1dad3d..0119269f1c 100755 --- a/src/mac/carbon/graphics.cpp +++ b/src/mac/carbon/graphics.cpp @@ -1345,9 +1345,6 @@ void wxMacCoreGraphicsContext::Init() m_cgContext = NULL; m_releaseContext = false; m_windowRef = NULL; - - HIRect r = CGRectMake(0,0,0,0); - m_clipRgn.Set(HIShapeCreateWithRect(&r)); } wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer* renderer, CGContextRef cgcontext ) : wxGraphicsContext(renderer) @@ -1408,7 +1405,7 @@ void wxMacCoreGraphicsContext::EnsureIsValid() CGContextConcatCTM( m_cgContext, m_windowTransform ); CGContextSaveGState( m_cgContext ); m_releaseContext = true; - if ( !HIShapeIsEmpty(m_clipRgn) ) + if ( (HIShapeRef) m_clipRgn != NULL ) { // the clip region is in device coordinates, so we convert this again to user coordinates wxMacCFRefHolder hishape ; @@ -1416,7 +1413,17 @@ void wxMacCoreGraphicsContext::EnsureIsValid() CGPoint transformedOrigin = CGPointApplyAffineTransform( CGPointZero,m_windowTransform); HIShapeOffset( hishape, -transformedOrigin.x, -transformedOrigin.y ); HIShapeReplacePathInCGContext( hishape, m_cgContext ); - CGContextClip( m_cgContext ); + // if the shape is empty, HIShapeReplacePathInCGContext doesn't work + if ( HIShapeIsEmpty(hishape)) + { + CGRect empty = CGRectMake( 0,0,0,0 ); + CGContextClipToRect( m_cgContext, empty ); + } + else + { + HIShapeReplacePathInCGContext( hishape, m_cgContext ); + CGContextClip( m_cgContext ); + } } CGContextSaveGState( m_cgContext ); } @@ -1464,10 +1471,19 @@ void wxMacCoreGraphicsContext::Clip( const wxRegion ®ion ) { if( m_cgContext ) { - HIShapeRef shape = HIShapeCreateWithQDRgn( (RgnHandle) region.GetWXHRGN() ); - HIShapeReplacePathInCGContext( shape, m_cgContext ); - CGContextClip( m_cgContext ); - CFRelease( shape ); + wxMacCFRefHolder shape; + shape = HIShapeCreateWithQDRgn( (RgnHandle) region.GetWXHRGN() ); + // if the shape is empty, HIShapeReplacePathInCGContext doesn't work + if ( HIShapeIsEmpty(shape)) + { + CGRect empty = CGRectMake( 0,0,0,0 ); + CGContextClipToRect( m_cgContext, empty ); + } + else + { + HIShapeReplacePathInCGContext( shape, m_cgContext ); + CGContextClip( m_cgContext ); + } } else { @@ -1517,8 +1533,7 @@ void wxMacCoreGraphicsContext::ResetClip() } else { - HIRect r = CGRectMake(0,0,0,0); - m_clipRgn.Set(HIShapeCreateWithRect(&r)); + m_clipRgn.Release(); } }