fix (with a test) for wxMenu::UpdateUI bug (the handler defined in the menu class was never used)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@8046 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -77,6 +77,7 @@ public:
|
|||||||
void OnRightDown(wxMouseEvent& event);
|
void OnRightDown(wxMouseEvent& event);
|
||||||
|
|
||||||
void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event);
|
void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event);
|
||||||
|
void OnUpdatePopup(wxUpdateUIEvent& event) { event.Enable(FALSE); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxMenu *CreateDummyMenu(wxString *title);
|
wxMenu *CreateDummyMenu(wxString *title);
|
||||||
@@ -109,6 +110,17 @@ private:
|
|||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MyPopupMenu : public wxMenu
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyPopupMenu(const wxString& title) : wxMenu(title) { }
|
||||||
|
|
||||||
|
void OnUpdateUI(wxUpdateUIEvent& event) { event.Enable(FALSE); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -145,6 +157,8 @@ enum
|
|||||||
|
|
||||||
Menu_Popup_ToBeDeleted = 2000,
|
Menu_Popup_ToBeDeleted = 2000,
|
||||||
Menu_Popup_ToBeGreyed,
|
Menu_Popup_ToBeGreyed,
|
||||||
|
Menu_Popup_ToBeGreyed2,
|
||||||
|
Menu_Popup_ToBeGreyed3,
|
||||||
Menu_Popup_ToBeChecked,
|
Menu_Popup_ToBeChecked,
|
||||||
Menu_Popup_Submenu,
|
Menu_Popup_Submenu,
|
||||||
|
|
||||||
@@ -182,6 +196,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
|
|
||||||
EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI)
|
EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI)
|
||||||
|
|
||||||
|
EVT_UPDATE_UI(Menu_Popup_ToBeGreyed3, MyFrame::OnUpdatePopup)
|
||||||
|
|
||||||
EVT_RIGHT_DOWN(MyFrame::OnRightDown)
|
EVT_RIGHT_DOWN(MyFrame::OnRightDown)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
@@ -189,6 +205,10 @@ BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler)
|
|||||||
EVT_MENU(-1, MyEvtHandler::OnMenuEvent)
|
EVT_MENU(-1, MyEvtHandler::OnMenuEvent)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(MyPopupMenu, wxMenu)
|
||||||
|
EVT_UPDATE_UI(Menu_Popup_ToBeGreyed2, MyPopupMenu::OnUpdateUI)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -618,7 +638,7 @@ void MyFrame::OnGetMenuItemInfo(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
void MyFrame::OnRightDown(wxMouseEvent &event )
|
void MyFrame::OnRightDown(wxMouseEvent &event )
|
||||||
{
|
{
|
||||||
wxMenu menu("Test popup");
|
MyPopupMenu menu("Test popup");
|
||||||
|
|
||||||
menu.Append(Menu_Help_About, "&About");
|
menu.Append(Menu_Help_About, "&About");
|
||||||
menu.Append(Menu_Popup_Submenu, "Submenu", CreateDummyMenu(NULL));
|
menu.Append(Menu_Popup_Submenu, "Submenu", CreateDummyMenu(NULL));
|
||||||
@@ -626,6 +646,10 @@ void MyFrame::OnRightDown(wxMouseEvent &event )
|
|||||||
menu.Append(Menu_Popup_ToBeChecked, "To be checked", "", TRUE);
|
menu.Append(Menu_Popup_ToBeChecked, "To be checked", "", TRUE);
|
||||||
menu.Append(Menu_Popup_ToBeGreyed, "To be greyed");
|
menu.Append(Menu_Popup_ToBeGreyed, "To be greyed");
|
||||||
menu.AppendSeparator();
|
menu.AppendSeparator();
|
||||||
|
// VZ: don't search for the word autogreyed in the dictionary...
|
||||||
|
menu.Append(Menu_Popup_ToBeGreyed2, "To be autogreyed");
|
||||||
|
menu.Append(Menu_Popup_ToBeGreyed3, "This one too");
|
||||||
|
menu.AppendSeparator();
|
||||||
menu.Append(Menu_File_Quit, "E&xit");
|
menu.Append(Menu_File_Quit, "E&xit");
|
||||||
|
|
||||||
menu.Delete(Menu_Popup_ToBeDeleted);
|
menu.Delete(Menu_Popup_ToBeDeleted);
|
||||||
|
@@ -346,10 +346,10 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source)
|
|||||||
{
|
{
|
||||||
if ( !source && GetInvokingWindow() )
|
if ( !source && GetInvokingWindow() )
|
||||||
source = GetInvokingWindow()->GetEventHandler();
|
source = GetInvokingWindow()->GetEventHandler();
|
||||||
|
|
||||||
|
wxEvtHandler *self = GetEventHandler();
|
||||||
if ( !source )
|
if ( !source )
|
||||||
source = GetEventHandler();
|
source = self;
|
||||||
if ( !source )
|
|
||||||
source = this;
|
|
||||||
|
|
||||||
wxMenuItemList::Node* node = GetMenuItems().GetFirst();
|
wxMenuItemList::Node* node = GetMenuItems().GetFirst();
|
||||||
while ( node )
|
while ( node )
|
||||||
@@ -361,7 +361,16 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source)
|
|||||||
wxUpdateUIEvent event(id);
|
wxUpdateUIEvent event(id);
|
||||||
event.SetEventObject( source );
|
event.SetEventObject( source );
|
||||||
|
|
||||||
if ( source->ProcessEvent(event) )
|
// let the invoking window process the event and fall back to the
|
||||||
|
// menu itself if it didn't
|
||||||
|
bool processed = source->ProcessEvent(event);
|
||||||
|
if ( !processed && source != self )
|
||||||
|
{
|
||||||
|
event.SetEventObject( self );
|
||||||
|
processed = self->ProcessEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( processed )
|
||||||
{
|
{
|
||||||
// if anything changed, update the chanegd attribute
|
// if anything changed, update the chanegd attribute
|
||||||
if (event.GetSetText())
|
if (event.GetSetText())
|
||||||
|
Reference in New Issue
Block a user