From d22ea0e201c87735d9af8a046acc77dbc20d637b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 3 Oct 2019 21:36:11 +0100 Subject: [PATCH] Safety for frames which don't have an m_viewControls. --- common/tool/action_menu.cpp | 2 +- common/tool/tool_manager.cpp | 20 +++++++++++++++++++- include/tool/tool_manager.h | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index e40a7d928e..25cd988637 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -457,7 +457,7 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent ) if( type == wxEVT_COMMAND_MENU_SELECTED ) evt->SetMousePosition( g_menu_open_position ); else - evt->SetMousePosition( getToolManager()->GetViewControls()->GetMousePosition() ); + evt->SetMousePosition( getToolManager()->GetMousePosition() ); if( g_last_menu_highlighted_id == aEvent.GetId() && !m_isContextMenu ) evt->SetHasPosition( false ); diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index df3f14e83e..5d59660824 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -278,13 +278,31 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a } +VECTOR2D TOOL_MANAGER::GetMousePosition() +{ + if( m_viewControls ) + return m_viewControls->GetMousePosition(); + else + return wxGetMousePosition(); +} + + +VECTOR2D TOOL_MANAGER::GetCursorPosition() +{ + if( m_viewControls ) + return m_viewControls->GetCursorPosition(); + else + return wxGetMousePosition(); +} + + bool TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam ) { bool handled = false; TOOL_EVENT event = aAction.MakeEvent(); if( event.Category() == TC_COMMAND ) - event.SetMousePosition( m_viewControls->GetCursorPosition() ); + event.SetMousePosition( GetCursorPosition() ); // Allow to override the action parameter if( aParam ) diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 3d65afd25e..218e83f956 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -257,6 +257,9 @@ public: return m_viewControls; } + VECTOR2D GetMousePosition(); + VECTOR2D GetCursorPosition(); + inline EDA_ITEM* GetModel() const { return m_model;