+
+ {
+#if wxMAC_USE_CORE_GRAPHICS
+ bool created = false ;
+ CGContextRef cgContext = NULL ;
+ if ( cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) != noErr )
+ {
+ wxASSERT( thisWindow->GetPeer()->IsCompositing() == false ) ;
+
+ // this parameter is not provided on non-composited windows
+ created = true ;
+
+ // rest of the code expects this to be already transformed and clipped for local
+ CGrafPtr port = GetWindowPort( (WindowRef) thisWindow->MacGetTopLevelWindowRef() ) ;
+ Rect bounds ;
+ GetPortBounds( port , &bounds ) ;
+ CreateCGContextForPort( port , &cgContext ) ;
+
+ wxMacWindowToNative( thisWindow , updateRgn ) ;
+ OffsetRgn( updateRgn , controlBounds.left , controlBounds.top ) ;
+ ClipCGContextToRegion( cgContext , &bounds , updateRgn ) ;
+ wxMacNativeToWindow( thisWindow , updateRgn ) ;
+ OffsetRgn( updateRgn , -controlBounds.left , -controlBounds.top ) ;
+
+ CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
+ CGContextScaleCTM( cgContext , 1 , -1 ) ;
+
+ CGContextTranslateCTM( cgContext , controlBounds.left , controlBounds.top ) ;
+
+#if 0
+ CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
+ CGContextFillRect( cgContext ,
+ CGRectMake( 0 , 0 ,
+ controlBounds.right - controlBounds.left ,
+ controlBounds.bottom - controlBounds.top ) );
+#endif
+ }
+
+ thisWindow->MacSetCGContextRef( cgContext ) ;
+
+ {
+ wxMacCGContextStateSaver sg( cgContext ) ;
+#endif
+ if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
+ result = noErr ;
+
+#if wxMAC_USE_CORE_GRAPHICS
+ thisWindow->MacSetCGContextRef( NULL ) ;
+ }
+
+ if ( created )
+ CGContextRelease( cgContext ) ;
+#endif
+ }
+