From adf3637476d90820920110f6d628e524f77ba0b0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 8 Apr 2019 19:59:23 +0100 Subject: [PATCH] Allow dialogs to veto mouse-warping when called from context menu. Fixes: lp:1745731 * https://bugs.launchpad.net/kicad/+bug/1745731 --- common/dialog_shim.cpp | 7 +++++++ common/kiway_holder.cpp | 6 ++++++ common/tool/tool_manager.cpp | 5 +++-- include/draw_frame.h | 2 +- include/kiway_player.h | 7 +++++++ include/tool/tool_manager.h | 8 ++++++++ 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/common/dialog_shim.cpp b/common/dialog_shim.cpp index 84bae6fe82..16d41a5edf 100644 --- a/common/dialog_shim.cpp +++ b/common/dialog_shim.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -92,6 +93,12 @@ DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& titl // Inherit units from parent m_units = kiwayHolder->GetUserUnits(); + // Don't mouse-warp after a dialog run from the context menu + TOOL_MANAGER* toolMgr = kiwayHolder->GetToolManager(); + + if( toolMgr ) + toolMgr->VetoContextMenuMouseWarp(); + // Set up the message bus SetKiway( this, &kiwayHolder->Kiway() ); } diff --git a/common/kiway_holder.cpp b/common/kiway_holder.cpp index 15e984b21b..15f19b8015 100644 --- a/common/kiway_holder.cpp +++ b/common/kiway_holder.cpp @@ -43,6 +43,12 @@ EDA_UNITS_T KIWAY_HOLDER::GetUserUnits() const } +TOOL_MANAGER* KIWAY_HOLDER::GetToolManager() const +{ + return nullptr; +} + + // this is not speed critical, hide it out of line. void KIWAY_HOLDER::SetKiway( wxWindow* aDest, KIWAY* aKiway ) { diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 3233d1cbe5..ffd43c208e 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -689,6 +689,7 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent ) } m_viewControls->ForceCursorPosition( true, m_menuCursor ); + m_warpMouseAfterContextMenu = true; // Display a copy of menu std::unique_ptr menu( m->Clone() ); @@ -703,8 +704,8 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent ) if( frame ) frame->PopupMenu( menu.get() ); - // Warp the cursor as long as the menu wasn't clicked out of - if( menu->GetSelected() >= 0 ) + // Warp the cursor if a menu item was selected + if( menu->GetSelected() >= 0 && m_warpMouseAfterContextMenu ) m_viewControls->WarpCursor( m_menuCursor, true, false ); // Otherwise notify the tool of a cancelled menu else diff --git a/include/draw_frame.h b/include/draw_frame.h index 3f34aaad55..3638d7d00f 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -938,7 +938,7 @@ public: /** * Return the tool manager instance, if any. */ - TOOL_MANAGER* GetToolManager() const { return m_toolManager; } + TOOL_MANAGER* GetToolManager() const override { return m_toolManager; } /** * A way to pass info to draw functions. the base class has no knowledge about diff --git a/include/kiway_player.h b/include/kiway_player.h index 4376d1fcd3..4d52fb0699 100644 --- a/include/kiway_player.h +++ b/include/kiway_player.h @@ -34,6 +34,7 @@ class KIWAY; class PROJECT; struct KIFACE; class KIFACE_I; +class TOOL_MANAGER; #define VTBL_ENTRY virtual @@ -78,6 +79,12 @@ public: */ VTBL_ENTRY EDA_UNITS_T GetUserUnits() const; + /** + * Function GetToolManager + * Return the tool manager instance, if any. + */ + VTBL_ENTRY TOOL_MANAGER* GetToolManager() const; + /** * Function SetKiway * diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 971dffa81e..a73a0ce214 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -372,6 +372,12 @@ public: */ const KIGFX::VC_SETTINGS& GetCurrentToolVC() const; + void VetoContextMenuMouseWarp() + { + m_warpMouseAfterContextMenu = false; + } + + private: typedef std::pair TRANSITION; @@ -531,6 +537,8 @@ private: /// Right click context menu position. VECTOR2D m_menuCursor; + bool m_warpMouseAfterContextMenu; + /// Flag indicating whether a context menu is currently displayed. bool m_menuActive;