+ if ( m_releaseContext )
+ QDEndCGContext( GetWindowPort( m_windowRef ) , &m_cgContext);
+}
+
+void wxMacCoreGraphicsContext::EnsureIsValid()
+{
+ if ( !m_cgContext )
+ {
+ OSStatus status = QDBeginCGContext( GetWindowPort( m_windowRef ) , &m_cgContext );
+ wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") );
+ Rect bounds;
+ GetWindowBounds( m_windowRef, kWindowContentRgn, &bounds );
+ CGContextSaveGState( m_cgContext );
+ CGContextTranslateCTM( m_cgContext , 0 , bounds.bottom - bounds.top );
+ CGContextScaleCTM( m_cgContext , 1 , -1 );
+ CGContextTranslateCTM( m_cgContext, m_originX, m_originY );
+ CGContextSaveGState( m_cgContext );
+ m_releaseContext = true;
+ if ( !HIShapeIsEmpty(m_clipRgn) )
+ {
+ HIShapeReplacePathInCGContext( m_clipRgn, m_cgContext );
+ CGContextClip( m_cgContext );
+ }
+ }