bool wxFrameBase::ProcessCommand(wxMenuItem *item)
{
- wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, item->GetId());
- commandEvent.SetEventObject(this);
+ wxCHECK_MSG( item, false, wxS("Menu item can't be NULL") );
if (!item->IsEnabled())
return true;
if ((item->GetKind() == wxITEM_RADIO) && item->IsChecked() )
return true;
+ int checked;
if (item->IsCheckable())
{
item->Toggle();
// use the new value
- commandEvent.SetInt(item->IsChecked());
+ checked = item->IsChecked();
}
else // Uncheckable item.
{
- commandEvent.SetInt(-1);
+ checked = -1;
}
- return HandleWindowEvent(commandEvent);
+ wxMenu* const menu = item->GetMenu();
+ wxCHECK_MSG( menu, false, wxS("Menu item should be attached to a menu") );
+
+ return menu->SendEvent(item->GetId(), checked);
}
#endif // wxUSE_MENUS
wxArrayString m_menuLabels;
+ // The menu containing the item with MenuTestCase_Bar id.
+ wxMenu* m_menuWithBar;
+
DECLARE_NO_COPY_CLASS(MenuTestCase)
};
PopulateMenu(helpMenu, "Helpmenu item ", itemcount);
helpMenu->Append(MenuTestCase_Bar, "Bar\tF1");
+ m_menuWithBar = helpMenu;
helpMenu->AppendSubMenu(subMenu, "Sub&menu", "Test a submenu");
// +2 for "Foo" and "Bar", +2 for the 2 submenus
const wxCommandEvent& ev = handler.GetEvent();
CPPUNIT_ASSERT_EQUAL( static_cast<int>(MenuTestCase_Bar), ev.GetId() );
+
+ wxObject* const src = ev.GetEventObject();
+ CPPUNIT_ASSERT( src );
+
+ CPPUNIT_ASSERT_EQUAL( "wxMenu",
+ wxString(src->GetClassInfo()->GetClassName()) );
+ CPPUNIT_ASSERT_EQUAL( static_cast<wxObject*>(m_menuWithBar),
+ src );
#endif // wxUSE_UIACTIONSIMULATOR
}