+// ---------------------------------------------------------------------------
+// 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 )
+
+// ---------------------------------------------------------------------------
+// UserPane events for non OSX builds
+// ---------------------------------------------------------------------------
+
+static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
+ win->MacControlUserPaneDrawProc(part) ;
+}
+
+static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
+ return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
+}
+
+static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
+ return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
+}
+
+static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
+ win->MacControlUserPaneIdleProc() ;
+}
+
+static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
+ return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
+}
+
+static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
+ win->MacControlUserPaneActivateProc(activating) ;
+}
+
+static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
+ return win->MacControlUserPaneFocusProc(action) ;
+}
+
+static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
+ win->MacControlUserPaneBackgroundProc(info) ;
+}
+
+void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part)
+{
+ MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
+}
+
+wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
+{
+ return kControlNoPart ;
+}
+
+wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
+{
+ return kControlNoPart ;
+}
+
+void wxWindowMac::MacControlUserPaneIdleProc()
+{
+}
+
+wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
+{
+ return kControlNoPart ;
+}
+
+void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
+{
+}
+
+wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
+{
+ return kControlNoPart ;
+}
+
+void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
+{
+}
+
+ControlUserPaneDrawUPP gControlUserPaneDrawUPP = NULL ;
+ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP = NULL ;
+ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP = NULL ;
+ControlUserPaneIdleUPP gControlUserPaneIdleUPP = NULL ;
+ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP = NULL ;
+ControlUserPaneActivateUPP gControlUserPaneActivateUPP = NULL ;
+ControlUserPaneFocusUPP gControlUserPaneFocusUPP = NULL ;
+ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP = NULL ;