From 7063c559ec6f18cc1cb87805d291943969fbc1ca Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 4 Nov 2007 10:27:33 +0000 Subject: [PATCH] factoring common code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@49615 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/menu.cpp | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index b0d4629acf..4ec6ba27d4 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -554,6 +554,82 @@ void wxMenu::MacAfterDisplay( bool isSubMenu ) } } +wxInt32 wxMenu::MacHandleCommandProcess( wxMenuItem* item, int id, wxWindow* targetWindow ) +{ + OSStatus result = eventNotHandledErr ; + if (item->IsCheckable()) + item->Check( !item->IsChecked() ) ; + + if ( SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ) + result = noErr ; + else + { + if ( targetWindow != NULL ) + { + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , id); + event.SetEventObject(targetWindow); + event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); + + if ( targetWindow->GetEventHandler()->ProcessEvent(event) ) + result = noErr ; + } + } + return result; +} + +wxInt32 wxMenu::MacHandleCommandUpdateStatus( wxMenuItem* item, int id, wxWindow* targetWindow ) +{ + OSStatus result = eventNotHandledErr ; + wxUpdateUIEvent event(id); + event.SetEventObject( this ); + + bool processed = false; + + // Try the menu's event handler + { + wxEvtHandler *handler = GetEventHandler(); + if ( handler ) + processed = handler->ProcessEvent(event); + } + + // Try the window the menu was popped up from + // (and up through the hierarchy) + if ( !processed ) + { + const wxMenuBase *menu = this; + while ( menu ) + { + wxWindow *win = menu->GetInvokingWindow(); + if ( win ) + { + processed = win->GetEventHandler()->ProcessEvent(event); + break; + } + + menu = menu->GetParent(); + } + } + + if ( !processed && targetWindow != NULL) + { + processed = targetWindow->GetEventHandler()->ProcessEvent(event); + } + + if ( processed ) + { + // if anything changed, update the changed attribute + if (event.GetSetText()) + SetLabel(id, event.GetText()); + if (event.GetSetChecked()) + Check(id, event.GetChecked()); + if (event.GetSetEnabled()) + Enable(id, event.GetEnabled()); + + result = noErr ; + } + return result; +} + // Menu Bar /*