Browse Source

Don't remember the menu in the tool dispatcher

Remembering the menu in the tool dispatcher can lead to stale pointers
if we never receive the required menu open or close events. Since wx
3.1.3, we get a valid menu object for all three events, so just forward
the event to that menu unconditionally if the menu is one of our
ACTION_MENUs.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16844
newinvert
Ian McInerney 2 years ago
parent
commit
b588001b95
  1. 8
      common/tool/action_menu.cpp
  2. 24
      common/tool/tool_dispatcher.cpp

8
common/tool/action_menu.cpp

@ -402,14 +402,6 @@ void ACTION_MENU::OnIdle( wxIdleEvent& event )
void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
{
#ifdef __WXOSX__
if( aEvent.GetMenu() != this )
{
aEvent.Skip();
return;
}
#endif
OPT_TOOL_EVENT evt;
wxString menuText;
wxEventType type = aEvent.GetEventType();

24
common/tool/tool_dispatcher.cpp

@ -535,6 +535,23 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
}
else if( type == wxEVT_MENU_OPEN || type == wxEVT_MENU_CLOSE || type == wxEVT_MENU_HIGHLIGHT )
{
wxMenuEvent* tmp = dynamic_cast<wxMenuEvent*>( &aEvent );
// Something is amiss if the event has these types and isn't a menu event, so bail out on
// its processing
if( !tmp )
{
aEvent.Skip();
return;
}
wxMenuEvent& menuEvent = *tmp;
#if wxCHECK_VERSION( 3, 2, 0 )
// Forward the event to the menu for processing
if( ACTION_MENU* currentMenu = dynamic_cast<ACTION_MENU*>( menuEvent.GetMenu() ) )
currentMenu->OnMenuEvent( menuEvent );
#else
//
// wxWidgets has several issues that we have to work around:
//
@ -549,12 +566,6 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
// hotkey. So we keep track of menu highlighting so we can differentiate.
//
wxMenuEvent* tmp = dynamic_cast<wxMenuEvent*>( &aEvent );
wxCHECK( tmp, /* void */ );
wxMenuEvent& menuEvent = *tmp;
if( type == wxEVT_MENU_OPEN )
{
m_currentMenu = dynamic_cast<ACTION_MENU*>( menuEvent.GetMenu() );
@ -574,6 +585,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
m_currentMenu = nullptr;
}
#endif
aEvent.Skip();
}

Loading…
Cancel
Save