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
This commit is contained in:
parent
e51ddc52b7
commit
b588001b95
|
@ -402,14 +402,6 @@ void ACTION_MENU::OnIdle( wxIdleEvent& event )
|
||||||
|
|
||||||
void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
|
void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
|
||||||
{
|
{
|
||||||
#ifdef __WXOSX__
|
|
||||||
if( aEvent.GetMenu() != this )
|
|
||||||
{
|
|
||||||
aEvent.Skip();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
OPT_TOOL_EVENT evt;
|
OPT_TOOL_EVENT evt;
|
||||||
wxString menuText;
|
wxString menuText;
|
||||||
wxEventType type = aEvent.GetEventType();
|
wxEventType type = aEvent.GetEventType();
|
||||||
|
|
|
@ -535,6 +535,23 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
|
||||||
}
|
}
|
||||||
else if( type == wxEVT_MENU_OPEN || type == wxEVT_MENU_CLOSE || type == wxEVT_MENU_HIGHLIGHT )
|
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:
|
// 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.
|
// 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 )
|
if( type == wxEVT_MENU_OPEN )
|
||||||
{
|
{
|
||||||
m_currentMenu = dynamic_cast<ACTION_MENU*>( menuEvent.GetMenu() );
|
m_currentMenu = dynamic_cast<ACTION_MENU*>( menuEvent.GetMenu() );
|
||||||
|
@ -574,6 +585,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
|
||||||
|
|
||||||
m_currentMenu = nullptr;
|
m_currentMenu = nullptr;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
aEvent.Skip();
|
aEvent.Skip();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue