Fix handling events from their items in submenu itself
This previously worked in wxGTK, but not in wxMSW and even under wxGTK it could be surprising that the submenu got the event, but its parent menu did not. Make things consistent between the platforms and send the event to the menu directly containing it first, but then also to its parent menu(s). Document the new behaviour and verify that it works as intended with a new unit test. Closes #18202.
This commit is contained in:
@@ -482,18 +482,20 @@ public:
|
||||
|
||||
@section menu_eventhandling Event handling
|
||||
|
||||
If the menu is part of a menubar, then wxMenuBar event processing is used.
|
||||
Event handlers for the commands generated by the menu items can be
|
||||
connected directly to the menu object itself using wxEvtHandler::Bind(). If
|
||||
this menu is a submenu of another one, the events from its items can also
|
||||
be processed in the parent menu and so on, recursively.
|
||||
|
||||
With a popup menu (see wxWindow::PopupMenu), there is a variety of ways to
|
||||
handle a menu selection event (@c wxEVT_MENU):
|
||||
- Provide @c EVT_MENU handlers in the window which pops up the menu, or in an
|
||||
ancestor of that window (the simplest method);
|
||||
- Derive a new class from wxMenu and define event table entries using the @c EVT_MENU macro;
|
||||
- Set a new event handler for wxMenu, through wxEvtHandler::SetNextHandler,
|
||||
specifying an object whose class has @c EVT_MENU entries;
|
||||
If the menu is part of a menu bar, then events can also be handled in
|
||||
wxMenuBar object.
|
||||
|
||||
Note that instead of static @c EVT_MENU macros you can also use dynamic
|
||||
connection; see @ref overview_events_bind.
|
||||
Finally, menu events can also be handled in the associated window, which is
|
||||
either the wxFrame associated with the menu bar this menu belongs to or the
|
||||
window for which wxWindow::PopupMenu() was called for the popup menus.
|
||||
|
||||
See @ref overview_events_bind for how to bind event handlers to the various
|
||||
objects.
|
||||
|
||||
@library{wxcore}
|
||||
@category{menus}
|
||||
|
Reference in New Issue
Block a user