+static const EventTypeSpec eventList[] =
+{
+ { kEventClassControl , kEventControlHit } ,
+#ifdef __WXMAC_OSX__
+ { kEventClassControl , kEventControlHitTest } ,
+#endif
+} ;
+
+static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+
+ ControlRef controlRef ;
+
+ cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
+
+ switch( GetEventKind( event ) )
+ {
+ case kEventControlHit :
+ {
+ wxToolBarTool* tbartool = (wxToolBarTool*)data ;
+ if ( tbartool->CanBeToggled() )
+ {
+ ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle()));
+ }
+ ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ;
+ result = noErr;
+ }
+ break ;
+#ifdef __WXMAC_OSX__
+ case kEventControlHitTest :
+ {
+ HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation) ;
+ HIRect rect ;
+ HIViewGetBounds( controlRef , &rect ) ;
+
+ ControlPartCode pc = kControlNoPart ;
+ if ( CGRectContainsPoint( rect , pt ) )
+ pc = kControlButtonPart ;
+ cEvent.SetParameter( kEventParamControlPart , typeControlPartCode, pc ) ;
+ result = noErr ;
+ }
+ break ;
+#endif
+ default :
+ break ;
+ }
+ return result ;
+}
+
+pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ switch ( GetEventClass( event ) )
+ {
+ case kEventClassControl :
+ result = wxMacToolBarToolControlEventHandler( handler, event, data ) ;
+ break ;
+ default :
+ break ;
+ }
+ return result ;
+}
+
+DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )
+