+// ---------------------------------------------------------------------------
+// Carbon Events
+// ---------------------------------------------------------------------------
+
+extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
+pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ;
+
+static const EventTypeSpec eventList[] =
+{
+#if TARGET_API_MAC_OSX
+ { kEventClassControl , kEventControlDraw } ,
+ { kEventClassControl , kEventControlVisibilityChanged } ,
+ { kEventClassControl , kEventControlEnabledStateChanged } ,
+ { kEventClassControl , kEventControlHiliteChanged } ,
+// { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
+// { kEventClassControl , kEventControlBoundsChanged } ,
+
+ {}
+#else
+ {}
+#endif
+} ;
+
+static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+
+ ControlRef controlRef ;
+ wxWindowMac* thisWindow = (wxWindowMac*) data ;
+
+ cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
+
+ switch( GetEventKind( event ) )
+ {
+ case kEventControlDraw :
+ {
+ RgnHandle updateRgn = NULL ;
+
+ wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
+ if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
+ {
+ updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
+ }
+ else
+ {
+ // unfortunately this update region may be incorrect (tree ctrl sample )
+ // so we have to reset it
+ updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
+ }
+ // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
+
+#if 0 // in case we would need a coregraphics compliant background erase first
+ CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
+ if ( thisWindow->MacIsUserPane() )
+ {
+ HIRect bounds;
+ err = HIViewGetBounds( controlRef, &bounds );
+ CGContextSetRGBFillColor( cgContext, 1 , 1 , 1 , 1 );
+// CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 );
+ CGContextFillRect( cgContext, bounds );
+ }
+#endif
+ if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
+ result = noErr ;
+ else
+ result = eventNotHandledErr;
+ }
+ break ;
+ case kEventControlVisibilityChanged :
+ thisWindow->MacVisibilityChanged() ;
+ break ;
+ case kEventControlEnabledStateChanged :
+ thisWindow->MacEnabledStateChanged() ;
+ break ;
+ case kEventControlHiliteChanged :
+ thisWindow->MacHiliteChanged() ;
+ break ;
+ default :
+ break ;
+ }
+ return result ;
+}
+
+pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ switch ( GetEventClass( event ) )
+ {
+ case kEventClassControl :
+ result = wxMacWindowControlEventHandler( handler, event, data ) ;
+ break ;
+ default :
+ break ;
+ }
+ return result ;
+}
+
+DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )