Change default tool behaviour to skip unhandled events.

The problem is that wxEVT_CHAR_HOOK doesn’t do the key translation
properly.  wxEVT_CHAR does, but we only get to that if we skip the
event at the end of the tool’s event processing loop, which most tools
don’t do.  (Selection tools, point editors, pickers, and a couple of
others do skip, which is probably why this didn’t get reported earlier.)

I played around with a couple of ways to fix wxEVT_CHAR_HOOK.  Most of
them don’t work, and the few egregious hacks I tried weren't cross-
platform.

So I’m changing it so that most tools now skip at the end of their
event loops.  I left out a couple that I felt were high risk (length
tuning, for instance).  But there’s still enough risk that I’m 100%
sure it will break something, I just haven’t a clue what.

Fixes: lp:1836903
* https://bugs.launchpad.net/kicad/+bug/1836903
This commit is contained in:
Jeff Young 2019-07-26 12:16:44 -06:00
parent 815602d1af
commit 77334628c4
16 changed files with 86 additions and 0 deletions

View File

@ -212,6 +212,9 @@ int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
{ {
m_menu.ShowContextMenu( m_selection ); m_menu.ShowContextMenu( m_selection );
} }
else
evt->SetPassEvent();
} }
view.SetVisible( &ruler, false ); view.SetVisible( &ruler, false );

View File

@ -219,6 +219,9 @@ int LIB_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
m_view->AddToPreview( item->Clone() ); m_view->AddToPreview( item->Clone() );
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is an item to be placed // Enable autopanning and cursor capture only when there is an item to be placed
getViewControls()->SetAutoPan( item != nullptr ); getViewControls()->SetAutoPan( item != nullptr );
getViewControls()->CaptureCursor( item != nullptr ); getViewControls()->CaptureCursor( item != nullptr );
@ -371,6 +374,9 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is a shape being drawn // Enable autopanning and cursor capture only when there is a shape being drawn
getViewControls()->SetAutoPan( item != nullptr ); getViewControls()->SetAutoPan( item != nullptr );
getViewControls()->CaptureCursor( item != nullptr ); getViewControls()->CaptureCursor( item != nullptr );
@ -428,6 +434,8 @@ int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
{ {
m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
} }
else
evt->SetPassEvent();
} }
return 0; return 0;

View File

@ -258,6 +258,8 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
break; // Finish break; // Finish
} }
else
evt->SetPassEvent();
} while( ( evt = Wait() ) ); // Assignment intentional; not equality test } while( ( evt = Wait() ) ); // Assignment intentional; not equality test

View File

@ -221,6 +221,8 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
m_view->ClearPreview(); m_view->ClearPreview();
m_view->AddToPreview( component->Clone() ); m_view->AddToPreview( component->Clone() );
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is a module to be placed // Enable autopanning and cursor capture only when there is a module to be placed
getViewControls()->SetAutoPan( component != nullptr ); getViewControls()->SetAutoPan( component != nullptr );
@ -372,6 +374,8 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
m_view->AddToPreview( image->Clone() ); m_view->AddToPreview( image->Clone() );
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is a module to be placed // Enable autopanning and cursor capture only when there is a module to be placed
getViewControls()->SetAutoPan( image != nullptr ); getViewControls()->SetAutoPan( image != nullptr );
@ -490,6 +494,8 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
m_view->ClearPreview(); m_view->ClearPreview();
m_view->AddToPreview( previewItem->Clone() ); m_view->AddToPreview( previewItem->Clone() );
} }
else
evt->SetPassEvent();
} }
delete previewItem; delete previewItem;
@ -678,6 +684,8 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
m_view->ClearPreview(); m_view->ClearPreview();
m_view->AddToPreview( item->Clone() ); m_view->AddToPreview( item->Clone() );
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is a module to be placed // Enable autopanning and cursor capture only when there is a module to be placed
getViewControls()->SetAutoPan( item != nullptr ); getViewControls()->SetAutoPan( item != nullptr );
@ -798,6 +806,8 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is a sheet to be placed // Enable autopanning and cursor capture only when there is a sheet to be placed
getViewControls()->SetAutoPan( sheet != nullptr ); getViewControls()->SetAutoPan( sheet != nullptr );

View File

@ -651,6 +651,8 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType,
aSegment = doUnfoldBus( net ); aSegment = doUnfoldBus( net );
} }
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is a segment to be placed // Enable autopanning and cursor capture only when there is a segment to be placed
getViewControls()->SetAutoPan( aSegment != nullptr ); getViewControls()->SetAutoPan( aSegment != nullptr );

View File

@ -409,6 +409,8 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{ {
break; // Finish break; // Finish
} }
else
evt->SetPassEvent();
controls->SetAutoPan( m_moveInProgress ); controls->SetAutoPan( m_moveInProgress );

View File

@ -678,6 +678,9 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
{ {
m_menu.ShowContextMenu( m_selection ); m_menu.ShowContextMenu( m_selection );
} }
else
evt->SetPassEvent();
} }
view.SetVisible( &ruler, false ); view.SetVisible( &ruler, false );

View File

@ -174,6 +174,8 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
item->SetPosition( item->GetPeer()->GetStartPosUi( 0 ) ); item->SetPosition( item->GetPeer()->GetStartPosUi( 0 ) );
getView()->Update( item ); getView()->Update( item );
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is an item to be placed // Enable autopanning and cursor capture only when there is an item to be placed
getViewControls()->SetAutoPan( item != nullptr ); getViewControls()->SetAutoPan( item != nullptr );
@ -274,6 +276,9 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is a shape being drawn // Enable autopanning and cursor capture only when there is a shape being drawn
getViewControls()->SetAutoPan( item != nullptr ); getViewControls()->SetAutoPan( item != nullptr );
getViewControls()->CaptureCursor( item != nullptr ); getViewControls()->CaptureCursor( item != nullptr );

View File

@ -220,6 +220,8 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
{ {
break; // Finish break; // Finish
} }
else
evt->SetPassEvent();
} while( ( evt = Wait() ) ); //Should be assignment not equality test } while( ( evt = Wait() ) ); //Should be assignment not equality test

View File

@ -954,6 +954,18 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
{ {
m_toolMgr->RunAction( PCB_ACTIONS::layerToggle, true ); m_toolMgr->RunAction( PCB_ACTIONS::layerToggle, true );
} }
else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
{
m_router->SwitchLayer( frame->GetActiveLayer() );
updateStartItem( *evt );
}
else if( evt->IsKeyPressed() )
{
// wxWidgets fails to correctly translate shifted keycodes on the wxEVT_CHAR_HOOK
// event so we need to process the wxEVT_CHAR event that will follow as long as we
// pass the event.
evt->SetPassEvent();
}
if( m_cancelled ) if( m_cancelled )
{ {

View File

@ -440,6 +440,9 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
// Calling 'Properties' action clears the selection, so we need to restore it // Calling 'Properties' action clears the selection, so we need to restore it
reselect = true; reselect = true;
} }
else
evt->SetPassEvent();
} }
frame()->SetMsgPanel( board() ); frame()->SetMsgPanel( board() );
@ -669,6 +672,8 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
else else
frame()->SetMsgPanel( board() ); frame()->SetMsgPanel( board() );
} }
else
evt->SetPassEvent();
} }
if( step != SET_ORIGIN ) if( step != SET_ORIGIN )
@ -816,6 +821,8 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
commit.Push( _( "Place a DXF_SVG drawing" ) ); commit.Push( _( "Place a DXF_SVG drawing" ) );
break; break;
} }
else
evt->SetPassEvent();
} }
preview.Clear(); preview.Clear();
@ -873,6 +880,8 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
m_frame->PopTool( tool ); m_frame->PopTool( tool );
break; break;
} }
else
evt->SetPassEvent();
} }
return 0; return 0;
@ -1110,6 +1119,8 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN
{ {
isLocalOriginSet = true; isLocalOriginSet = true;
} }
else
evt->SetPassEvent();
} }
if( !isLocalOriginSet ) // reset the relative coordinte if it was not set before if( !isLocalOriginSet ) // reset the relative coordinte if it was not set before
@ -1291,6 +1302,8 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT*& aGraphic, bo
{ {
arcManager.ToggleClockwise(); arcManager.ToggleClockwise();
} }
else
evt->SetPassEvent();
if( arcManager.IsComplete() ) if( arcManager.IsComplete() )
{ {
@ -1538,6 +1551,9 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
status.Hide(); status.Hide();
} }
} }
else
evt->SetPassEvent();
} // end while } // end while
m_controls->ForceCursorPosition( false ); m_controls->ForceCursorPosition( false );

View File

@ -473,6 +473,9 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
break; // Finish break; // Finish
} }
else
evt->SetPassEvent();
} while( ( evt = Wait() ) ); //Should be assignment not equality test } while( ( evt = Wait() ) ); //Should be assignment not equality test
m_lockedSelected = false; m_lockedSelected = false;
@ -1222,6 +1225,9 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
{ {
m_menu.ShowContextMenu(); m_menu.ShowContextMenu();
} }
else
evt->SetPassEvent();
} }
view.SetVisible( &ruler, false ); view.SetVisible( &ruler, false );

View File

@ -254,6 +254,9 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
{ {
m_menu.ShowContextMenu( selection() ); m_menu.ShowContextMenu( selection() );
} }
else
evt->SetPassEvent();
} }
controls.CaptureCursor( false ); controls.CaptureCursor( false );

View File

@ -488,6 +488,9 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
m_menu.ShowContextMenu( selection() ); m_menu.ShowContextMenu( selection() );
} }
else
evt->SetPassEvent();
// Prepare the next loop by updating the old cursor mouse position // Prepare the next loop by updating the old cursor mouse position
// to this last mouse cursor position // to this last mouse cursor position
oldCursorPos = getViewControls()->GetCursorPosition(); oldCursorPos = getViewControls()->GetCursorPosition();

View File

@ -759,6 +759,9 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
reselect = true; reselect = true;
} }
else
evt->SetPassEvent();
// Enable autopanning and cursor capture only when there is a module to be placed // Enable autopanning and cursor capture only when there is a module to be placed
controls->SetAutoPan( !!module ); controls->SetAutoPan( !!module );
controls->CaptureCursor( !!module ); controls->CaptureCursor( !!module );
@ -926,6 +929,9 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
view->Update( &preview ); view->Update( &preview );
} }
else
evt->SetPassEvent();
} }
preview.Clear(); preview.Clear();

View File

@ -207,6 +207,9 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool,
// Show a preview of the item // Show a preview of the item
view()->Update( &preview ); view()->Update( &preview );
} }
else
evt->SetPassEvent();
} }
view()->Remove( &preview ); view()->Remove( &preview );