]> git.saurik.com Git - wxWidgets.git/commitdiff
Pass menu events to the handler in the associated menu bar.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 4 May 2013 23:59:32 +0000 (23:59 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 4 May 2013 23:59:32 +0000 (23:59 +0000)
We handled the menu events in the menu itself and the associated window, but
not in the menu bar that the menu belonged to. This was unexpected, so allow
handling the events in the menu bar itself too.

Closes #15095.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73922 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/common/menucmn.cpp
tests/events/propagation.cpp

index 916824f6d7c584fa8095f98a48b6716421d4e3da..2dec0578205159ccf4a00ca2bb0a7faa422f41eb 100644 (file)
@@ -654,6 +654,7 @@ All (GUI):
 - Add wxTextEntryDialog::SetMaxLength() (derEine).
 - Fix maximum width support in wxGridCellTextEditor (derEine).
 - Add more convenient wxFont(wxFontInfo) ctor.
+- Pass menu events to the handler in the associated wxMenuBar.
 
 wxGTK:
 
index 55daa81c38e5c041e688f56f640f9abb2e52d5fa..7230bb103ded730ff8a3b8b74b460b3e1cead896 100644 (file)
@@ -643,7 +643,8 @@ bool wxMenuBase::SendEvent(int itemid, int checked)
     event.SetEventObject(this);
     event.SetInt(checked);
 
-    wxWindow * const win = GetWindow();
+    wxWindow* const win = GetWindow();
+    wxMenuBar* const mb = GetMenuBar();
 
     // Try the menu's event handler first
     wxEvtHandler *handler = GetEventHandler();
@@ -653,16 +654,21 @@ bool wxMenuBase::SendEvent(int itemid, int checked)
         // event to another handler if it's not processed here to prevent it
         // from passing the event to wxTheApp: this will be done below if we do
         // have the associated window.
-        if ( win )
+        if ( win || mb )
             event.SetWillBeProcessedAgain();
 
         if ( handler->SafelyProcessEvent(event) )
             return true;
     }
 
-    // Try the window the menu was popped up from or its menu bar belongs to
-    if ( win && win->HandleWindowEvent(event) )
-        return true;
+    // If this menu is part of the menu bar, process the event there: this will
+    // also propagate it upwards to the window containing the menu bar.
+    if ( mb )
+        return mb->HandleWindowEvent(event);
+
+    // Try the window the menu was popped up from.
+    if ( win )
+        return win->HandleWindowEvent(event);
 
     // Not processed.
     return false;
index d0d2230ddaa38f2961e0f7ebbc0be9ca147a0b49..14457f7464b858ef9ec11c23769f93163e797dde 100644 (file)
@@ -400,10 +400,18 @@ void EventPropagationTestCase::MenuEvent()
     CheckMenuEvent( menu, "aomA" );
 
 
+    // Test that the event handler associated with the menu bar gets the event.
+    TestMenuEvtHandler hb('b'); // 'b' for "menu Bar"
+    mb->PushEventHandler(&hb);
+    wxON_BLOCK_EXIT_OBJ1( *mb, wxWindow::PopEventHandler, false );
+
+    CheckMenuEvent( menu, "aomobA" );
+
+
     // Also test that the window to which the menu belongs gets the event.
     TestMenuEvtHandler hw('w'); // 'w' for "Window"
     frame->PushEventHandler(&hw);
     wxON_BLOCK_EXIT_OBJ1( *frame, wxWindow::PopEventHandler, false );
 
-    CheckMenuEvent( menu, "aomowA" );
+    CheckMenuEvent( menu, "aomobowA" );
 }