+//----------------------------------------------------------------------
+// Carbon Event Handler
+//----------------------------------------------------------------------
+
+#if TARGET_CARBON
+
+ static const EventTypeSpec eventList[] =
+ {
+ { kEventClassCommand, kEventProcessCommand } ,
+ { kEventClassCommand, kEventCommandUpdateStatus } ,
+ { kEventClassApplication , kEventAppActivated } ,
+ { kEventClassApplication , kEventAppDeactivated } ,
+ } ;
+
+static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ HICommand command ;
+
+ GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL,
+ sizeof( HICommand ), NULL, &command );
+
+ MenuCommand id = command.commandID ;
+ if ( id == kHICommandPreferences )
+ id = wxApp::s_macPreferencesMenuItemId ;
+
+ wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
+ wxMenu* menu = NULL ;
+ wxMenuItem* item = NULL ;
+
+ if ( mbar )
+ item = mbar->FindItem( id , &menu ) ;
+
+ if ( item == NULL || menu == NULL || mbar == NULL )
+ return result ;
+
+ switch( GetEventKind( event ) )
+ {
+ case kEventProcessCommand :
+ {
+ if (item->IsCheckable())
+ {
+ item->Check( !item->IsChecked() ) ;
+ }
+
+ menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
+ result = noErr ;
+ }
+ break ;
+ case kEventCommandUpdateStatus:
+ // eventually trigger an updateui round
+ result = noErr ;
+ break ;
+ default :
+ break ;
+ }
+
+ return result ;
+}
+
+static pascal OSStatus ApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+ switch ( GetEventKind( event ) )
+ {
+ case kEventAppActivated :
+ {
+ wxTheApp->MacResume( true ) ;
+ result = noErr ;
+ }
+ break ;
+ case kEventAppDeactivated :
+ {
+ wxTheApp->MacSuspend( true ) ;
+ result = noErr ;
+ }
+ break ;
+ default :
+ break ;
+ }
+ return result ;
+}
+
+pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+ switch( GetEventClass( event ) )
+ {
+ case kEventClassCommand :
+ result = CommandEventHandler( handler , event , data ) ;
+ break ;
+ case kEventClassApplication :
+ result = ApplicationEventHandler( handler , event , data ) ;
+ break ;
+
+ default :
+ break ;
+ }
+
+ return result ;
+}
+
+DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler )
+
+#endif
+