Refactor: extract menu event handling logic from wxMenu::SendEvent().

Make this logic available for reuse with the events of different kind, e.g.
wxMenuEvent in the upcoming commit.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78228 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-12-05 22:17:48 +00:00
parent d7653d9c0c
commit 693abd284f
2 changed files with 16 additions and 4 deletions

View File

@@ -388,6 +388,12 @@ protected:
static bool ms_locked; static bool ms_locked;
private:
// Helper of SendEvent(): sends the event to its intended recipients,
// returns true if it was processed.
static bool DoProcessEvent(wxMenuBase* menu, wxEvent& event, wxWindow* win);
wxDECLARE_NO_COPY_CLASS(wxMenuBase); wxDECLARE_NO_COPY_CLASS(wxMenuBase);
}; };

View File

@@ -641,14 +641,20 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source)
bool wxMenuBase::SendEvent(int itemid, int checked) bool wxMenuBase::SendEvent(int itemid, int checked)
{ {
wxCommandEvent event(wxEVT_MENU, itemid); wxCommandEvent event(wxEVT_MENU, itemid);
event.SetEventObject(this);
event.SetInt(checked); event.SetInt(checked);
wxWindow* const win = GetWindow(); return DoProcessEvent(this, event, GetWindow());
wxMenuBar* const mb = GetMenuBar(); }
/* static */
bool wxMenuBase::DoProcessEvent(wxMenuBase* menu, wxEvent& event, wxWindow* win)
{
event.SetEventObject(menu);
wxMenuBar* const mb = menu->GetMenuBar();
// Try the menu's event handler first // Try the menu's event handler first
wxEvtHandler *handler = GetEventHandler(); wxEvtHandler *handler = menu->GetEventHandler();
if ( handler ) if ( handler )
{ {
// Indicate to the event processing code that we're going to pass this // Indicate to the event processing code that we're going to pass this