Make m_passEvent event-specific rather than global.

If a tool called something like clearSelection while processing a
MOUSE_CLICK, the SELECTION_TOOL will pass the clearSelection
COMMAND_EVENT because it handles it as a transition, not as an
event. Because m_passEvent is effectively global, the tool manager
would then interpret that as passing the MOUSE_CLICK and we'd end
up processing the click by multiple tools.
This commit is contained in:
Jeff Young 2019-06-16 12:06:49 +01:00
parent 6d335f2a82
commit e4fbd003e0
15 changed files with 30 additions and 48 deletions

View File

@ -195,7 +195,6 @@ TOOL_MANAGER::TOOL_MANAGER() :
m_view( NULL ),
m_viewControls( NULL ),
m_frame( NULL ),
m_passEvent( false ),
m_menuActive( false ),
m_menuOwner( -1 ),
m_activeState( nullptr )
@ -543,9 +542,6 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
{
if( st->waitEvents.Matches( aEvent ) )
{
// By default only messages are passed further
m_passEvent = ( aEvent.Category() == TC_MESSAGE );
// got matching event? clear wait list and wake up the coroutine
st->wakeupEvent = aEvent;
st->pendingWait = false;
@ -560,9 +556,8 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
it = finishTool( st );
}
// If the tool did not request to propagate
// the event to other tools, we should stop it now
if( !m_passEvent )
// If the tool did not request the event be passed to other tools, we're done
if( !aEvent.PassEvent() )
break;
}
}

View File

@ -60,7 +60,7 @@ int ZOOM_TOOL::Main( const TOOL_EVENT& aEvent )
}
else
m_toolMgr->PassEvent();
evt->SetPassEvent();
}
// Exit zoom tool

View File

@ -99,7 +99,7 @@ int CVPCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
}
else
m_toolMgr->PassEvent();
evt->SetPassEvent();
}
// This tool is supposed to be active forever

View File

@ -107,7 +107,7 @@ int EE_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
}
else
{
m_toolMgr->PassEvent();
evt->SetPassEvent();
}
}

View File

@ -327,9 +327,7 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
}
else
{
m_toolMgr->PassEvent();
}
evt->SetPassEvent();
controls->SetAutoPan( inDrag );
controls->CaptureCursor( inDrag );

View File

@ -342,11 +342,6 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
// Single click? Select single object
if( evt->IsClick( BUT_LEFT ) )
{
// JEY TODO: this is a hack, but I can't figure out why it's needed to
// keep from getting the first click when running the Place Symbol tool.
if( m_frame->GetCurrentToolName() != EE_ACTIONS::selectionTool.GetName() )
continue;
if( evt->Modifier( MD_CTRL ) && dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
{
m_toolMgr->RunAction( EE_ACTIONS::highlightNet, true );
@ -461,7 +456,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
}
else
m_toolMgr->PassEvent();
evt->SetPassEvent();
}
// This tool is supposed to be active forever

View File

@ -247,7 +247,7 @@ int GERBVIEW_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
}
else
m_toolMgr->PassEvent();
evt->SetPassEvent();
}
// This tool is supposed to be active forever

View File

@ -186,6 +186,9 @@ public:
m_param( aParameter )
{
m_hasPosition = ( aCategory == TC_MOUSE || aCategory == TC_COMMAND );
// By default only MESSAGEs are passed to multiple recipients
m_passEvent = ( aCategory == TC_MESSAGE );
}
TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, int aExtraParam,
@ -216,6 +219,9 @@ public:
m_modifiers = aExtraParam & MD_MODIFIER_MASK;
}
// By default only MESSAGEs are passed to multiple recipients
m_passEvent = ( aCategory == TC_MESSAGE );
m_hasPosition = ( aCategory == TC_MOUSE || aCategory == TC_COMMAND );
}
@ -233,6 +239,9 @@ public:
if( aCategory == TC_COMMAND || aCategory == TC_MESSAGE )
m_commandStr = aExtraParam;
// By default only MESSAGEs are passed to multiple recipients
m_passEvent = ( aCategory == TC_MESSAGE );
m_hasPosition = ( aCategory == TC_MOUSE || aCategory == TC_COMMAND );
}
@ -242,6 +251,12 @@ public:
///> Returns more specific information about the type of an event.
TOOL_ACTIONS Action() const { return m_actions; }
///> These give a tool a method of informing the TOOL_MANAGER that a particular event should
///> be passed on to subsequent tools on the stack. Defaults to true for TC_MESSAGES; false
///> for everything else.
bool PassEvent() const { return m_passEvent; }
void SetPassEvent() { m_passEvent = true; }
///> Returns if it this event has a valid position (true for mouse events and context-menu
///> or hotkey-based command events)
bool HasPosition() const { return m_hasPosition; }
@ -456,6 +471,7 @@ private:
TOOL_EVENT_CATEGORY m_category;
TOOL_ACTIONS m_actions;
TOOL_ACTION_SCOPE m_scope;
bool m_passEvent;
bool m_hasPosition;
///> Difference between mouse cursor position and

View File

@ -334,14 +334,6 @@ public:
void ScheduleContextMenu( TOOL_BASE* aTool, ACTION_MENU* aMenu,
CONTEXT_MENU_TRIGGER aTrigger );
/**
* Allows a tool to pass the already handled event to the next tool on the stack.
*/
void PassEvent()
{
m_passEvent = true;
}
/**
* Stores an information to the system clipboard.
* @param aText is the information to be stored.
@ -524,9 +516,6 @@ private:
/// Queue that stores events to be processed at the end of the event processing cycle.
std::list<TOOL_EVENT> m_eventQueue;
/// Flag saying if the currently processed event should be passed to other tools.
bool m_passEvent;
/// Right click context menu position.
VECTOR2D m_menuCursor;

View File

@ -134,9 +134,7 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
// m_menu.ShowContextMenu();
}
else
{
m_toolMgr->PassEvent();
}
evt->SetPassEvent();
}
if( m_finalizeHandler )

View File

@ -227,9 +227,7 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
}
else
{
m_toolMgr->PassEvent();
}
evt->SetPassEvent();
controls->SetAutoPan( inDrag );
controls->CaptureCursor( inDrag );

View File

@ -217,7 +217,7 @@ int PL_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
}
else
m_toolMgr->PassEvent();
evt->SetPassEvent();
}
// This tool is supposed to be active forever

View File

@ -116,7 +116,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
}
else
m_toolMgr->PassEvent();
evt->SetPassEvent();
}
if( m_finalizeHandler )

View File

@ -408,9 +408,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
}
else
{
m_toolMgr->PassEvent();
}
evt->SetPassEvent();
}
if( m_editPoints )

View File

@ -278,11 +278,6 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
// Single click? Select single object
if( evt->IsClick( BUT_LEFT ) )
{
// JEY TODO: this is a hack, but I can't figure out why it's needed to
// keep from getting end-of-segment clicks when running the Draw Lines tool.
if( m_frame->GetToolId() != ID_NO_TOOL_SELECTED )
continue;
if( evt->Modifier( MD_CTRL ) && !m_editModules )
{
m_toolMgr->RunAction( PCB_ACTIONS::highlightNet, true );
@ -377,7 +372,7 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
}
else
m_toolMgr->PassEvent();
evt->SetPassEvent();
}
// This tool is supposed to be active forever