return m_path ;
}
+// we always stock two context states, one at entry, the other one after
+// changing to HI Graphics orientation (this one is used for getting back clippings etc)
wxMacCGContext::wxMacCGContext( CGrafPtr port )
{
m_qdPort = port ;
- Rect bounds ;
- GetPortBounds( (CGrafPtr) port , &bounds ) ;
- OSStatus status = QDBeginCGContext( (CGrafPtr) port , &m_cgContext ) ;
-
- wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ;
- CGContextTranslateCTM( m_cgContext , 0 , bounds.bottom - bounds.top ) ;
- CGContextScaleCTM( m_cgContext , 1 , -1 ) ;
+ m_cgContext = NULL ;
}
wxMacCGContext::wxMacCGContext( CGContextRef cgcontext )
{
m_qdPort = NULL ;
m_cgContext = cgcontext ;
+ CGContextSaveGState( m_cgContext ) ;
+ CGContextSaveGState( m_cgContext ) ;
}
wxMacCGContext::wxMacCGContext()
wxMacCGContext::~wxMacCGContext()
{
+ if ( m_cgContext )
+ {
+ CGContextRestoreGState( m_cgContext ) ;
+ CGContextRestoreGState( m_cgContext ) ;
+ }
if ( m_qdPort )
QDEndCGContext( m_qdPort , &m_cgContext ) ;
}
CGContextRestoreGState( m_cgContext ) ;
}
-wxGraphicPath* wxMacCGContext::CreatePath() { return new wxMacCGPath() ; }
-CGContextRef wxMacCGContext::GetNativeContext() { return m_cgContext ; }
-void wxMacCGContext::SetNativeContext( CGContextRef cg ) { m_cgContext = cg ; }
+wxGraphicPath* wxMacCGContext::CreatePath()
+{
+ CGContextRef cg = GetNativeContext() ;
+ // make sure that we now have a real cgref, before doing
+ // anything with paths
+ return new wxMacCGPath() ;
+}
+
+// in case we only got a QDPort only create a cgref now
+
+CGContextRef wxMacCGContext::GetNativeContext()
+{
+ if( m_cgContext == NULL )
+ {
+ Rect bounds ;
+ GetPortBounds( (CGrafPtr) m_qdPort , &bounds ) ;
+ OSStatus status = QDBeginCGContext( (CGrafPtr) m_qdPort , &m_cgContext ) ;
+ CGContextSaveGState( m_cgContext ) ;
+
+ wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ;
+ CGContextTranslateCTM( m_cgContext , 0 , bounds.bottom - bounds.top ) ;
+ CGContextScaleCTM( m_cgContext , 1 , -1 ) ;
+
+ CGContextSaveGState( m_cgContext ) ;
+ SetPen( m_pen ) ;
+ SetBrush( m_brush ) ;
+ }
+ return m_cgContext ;
+}
+
+void wxMacCGContext::SetNativeContext( CGContextRef cg )
+{
+ wxASSERT( m_cgContext == NULL ) ;
+ m_cgContext = cg ;
+ CGContextSaveGState( m_cgContext ) ;
+}
void wxMacCGContext::SetPen( const wxPen &pen )
{
+ m_pen = pen ;
+ if ( m_cgContext == NULL )
+ return ;
bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
bool stroke = pen.GetStyle() != wxTRANSPARENT ;
-
+
#if 0
// we can benchmark performance, should go into a setting later
CGContextSetShouldAntialias( m_cgContext , false ) ;
}
void wxMacCGContext::SetBrush( const wxBrush &brush )
{
+ m_brush = brush ;
+ if ( m_cgContext == NULL )
+ return ;
+
bool fill = brush.GetStyle() != wxTRANSPARENT ;
bool stroke = m_pen.GetStyle() != wxTRANSPARENT ;
yy = YLOG2DEVMAC(y);
ww = XLOG2DEVREL(width);
hh = YLOG2DEVREL(height);
+
+ CGContextRef cgContext = dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ;
+ CGRect clipRect = CGRectMake( xx ,yy , ww, hh ) ;
+ CGContextClipToRect( cgContext , clipRect ) ;
+
// SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
// SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
if( m_clipping )
void wxDC::DestroyClippingRegion()
{
// CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
+ CGContextRef cgContext = dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ;
+ CGContextRestoreGState( cgContext );
+ CGContextSaveGState( cgContext );
+ SetPen( m_pen ) ;
+ SetBrush( m_brush ) ;
m_clipping = FALSE;
}
}
wxGraphicPath* path = m_graphicContext->CreatePath() ;
path->AddRectangle(xx ,yy , ww , hh ) ;
- path->CloseSubpath() ;
m_graphicContext->DrawPath( path ) ;
delete path ;
}
if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT)
{
- HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
+ HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
switch( m_backgroundBrush.MacGetBrushKind() )
{
case kwxMacBrushTheme :
break ;
case kwxMacBrushThemeBackground :
{
- HIThemeBackgroundDrawInfo drawInfo ;
- drawInfo.version = 0 ;
- drawInfo.state = kThemeStateActive ;
- drawInfo.kind = m_backgroundBrush.MacGetThemeBackground(NULL) ;
- HIThemeDrawBackground( &rect , &drawInfo, dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ,
- kHIThemeOrientationNormal) ;
-
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
+ if ( HIThemeDrawBackground )
+ {
+ HIThemeBackgroundDrawInfo drawInfo ;
+ drawInfo.version = 0 ;
+ drawInfo.state = kThemeStateActive ;
+ drawInfo.kind = m_backgroundBrush.MacGetThemeBackground(NULL) ;
+ if ( drawInfo.kind == kThemeBackgroundMetal )
+ HIThemeDrawBackground( &rect , &drawInfo, dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ,
+ kHIThemeOrientationNormal) ;
+ HIThemeApplyBackground( &rect , &drawInfo, dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ,
+ kHIThemeOrientationNormal) ;
+ }
+#endif
}
break ;
case kwxMacBrushColour :