hotkey management: enhancements in code to know if a hotkey was handled by an event or not.

No actual change in key management: in legacy it was partially existing, and not yet used in GAL mode.
This commit is contained in:
jean-pierre charras 2017-10-06 09:23:13 +02:00
parent 1164eaab72
commit 4905bbe500
8 changed files with 69 additions and 40 deletions

View File

@ -95,6 +95,8 @@ const wxChar EDA_DRAW_FRAME::CANVAS_TYPE_KEY[] = wxT( "canvas_type" );
static const wxString MaxUndoItemsEntry(wxT( "DevelMaxUndoItems" ) );
BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
EVT_CHAR_HOOK( EDA_DRAW_FRAME::OnCharHook )
EVT_MOUSEWHEEL( EDA_DRAW_FRAME::OnMouseEvent )
EVT_MENU_OPEN( EDA_DRAW_FRAME::OnMenuOpen )
EVT_ACTIVATE( EDA_DRAW_FRAME::OnActivate )
@ -227,6 +229,14 @@ EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
}
void EDA_DRAW_FRAME::OnCharHook( wxKeyEvent& event )
{
// Key events can be filtered here.
// Currently no filtering is made.
event.Skip();
}
void EDA_DRAW_FRAME::ReleaseFile()
{
m_file_checker = nullptr;
@ -1317,9 +1327,10 @@ void EDA_DRAW_FRAME::RefreshCrossHair( const wxPoint &aOldPos,
}
}
void EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
bool EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
bool aSnapToGrid )
{
bool key_handled = false;
// If requested snap the current position to the grid
if( aSnapToGrid )
@ -1344,6 +1355,7 @@ void EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
case WXK_LEFT:
case WXK_NUMPAD6:
case WXK_RIGHT:
key_handled = true;
{
/* Here's a tricky part: when doing cursor key movement, the
* 'previous' point should be taken from memory, *not* from the
@ -1399,6 +1411,7 @@ void EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
default: /* Can't happen since we entered the statement */
break;
}
m_canvas->MoveCursor( *aPos );
m_movingCursorWithKeyboard = true;
}
@ -1407,6 +1420,8 @@ void EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
default:
break;
}
return key_handled;
}

View File

@ -728,9 +728,9 @@ TOOL_MANAGER::ID_LIST::iterator TOOL_MANAGER::finishTool( TOOL_STATE* aState )
}
void TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent )
bool TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent )
{
processEvent( aEvent );
bool hotkey_handled = processEvent( aEvent );
if( TOOL_STATE* active = GetCurrentToolState() )
{
@ -742,6 +742,8 @@ void TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent )
EDA_DRAW_FRAME* f = static_cast<EDA_DRAW_FRAME*>( GetEditFrame() );
f->GetGalCanvas()->Refresh(); // fixme: ugly hack, provide a method in TOOL_DISPATCHER.
}
return hotkey_handled;
}
@ -859,11 +861,11 @@ void TOOL_MANAGER::popViewControls()
}
void TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent )
bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent )
{
// Early dispatch of events destined for the TOOL_MANAGER
if( !dispatchStandardEvents( aEvent ) )
return;
return true;
dispatchInternal( aEvent );
dispatchActivation( aEvent );
@ -876,6 +878,8 @@ void TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent )
m_eventQueue.pop_front();
processEvent( event );
}
return false;
}
bool TOOL_MANAGER::IsToolActive( TOOL_ID aId ) const

View File

@ -216,8 +216,6 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aF
bool SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
{
bool eventHandled = true;
// Filter out the 'fake' mouse motion after a keyboard movement
if( !aHotKey && m_movingCursorWithKeyboard )
{
@ -239,7 +237,7 @@ bool SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE
wxPoint pos = aPosition;
wxPoint oldpos = GetCrossHairPosition();
GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
// Update cursor position.
SetCrossHairPosition( pos, snapToGrid );
@ -248,23 +246,25 @@ bool SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE
if( aHotKey )
{
SCH_SCREEN* screen = GetScreen();
bool hk_handled;
if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
eventHandled = OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
hk_handled = OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
else
eventHandled = OnHotKey( aDC, aHotKey, aPosition, NULL );
hk_handled = OnHotKey( aDC, aHotKey, aPosition, NULL );
if( hk_handled )
keyHandled = true;
}
UpdateStatusBar(); /* Display cursor coordinates info */
return eventHandled;
return keyHandled;
}
bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
{
bool eventHandled = true;
// Filter out the 'fake' mouse motion after a keyboard movement
if( !aHotKey && m_movingCursorWithKeyboard )
{
@ -286,20 +286,20 @@ bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE
wxPoint pos = aPosition;
wxPoint oldpos = GetCrossHairPosition();
GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
// Update the cursor position.
SetCrossHairPosition( pos, snapToGrid );
RefreshCrossHair( oldpos, aPosition, aDC );
if( aHotKey )
if( aHotKey && OnHotKey( aDC, aHotKey, aPosition, NULL ) )
{
eventHandled = OnHotKey( aDC, aHotKey, aPosition, NULL );
keyHandled = true;
}
UpdateStatusBar();
return eventHandled;
return keyHandled;
}

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2010 <Jean-Pierre Charras>
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2017 <Jean-Pierre Charras>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -33,8 +33,6 @@
bool GERBVIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
{
bool eventHandled = true;
// Filter out the 'fake' mouse motion after a keyboard movement
if( !aHotKey && m_movingCursorWithKeyboard )
{
@ -44,14 +42,14 @@ bool GERBVIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE
wxPoint pos = aPosition;
wxPoint oldpos = GetCrossHairPosition();
GeneralControlKeyMovement( aHotKey, &pos, true );
bool eventHandled = GeneralControlKeyMovement( aHotKey, &pos, true );
SetCrossHairPosition( pos );
RefreshCrossHair( oldpos, aPosition, aDC );
if( aHotKey )
if( aHotKey && OnHotKey( aDC, aHotKey, aPosition ) )
{
eventHandled = OnHotKey( aDC, aHotKey, aPosition );
eventHandled = true;
}
UpdateStatusBar();

View File

@ -158,8 +158,13 @@ protected:
/**
* Function GeneralControlKeyMovement
* Handle the common part of GeneralControl dedicated to global
* cursor keys (i.e. cursor movement by keyboard) */
void GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, bool aSnapToGrid );
* cursor keys (i.e. cursor movement by keyboard)
* @param aHotKey is the hotkey code
* @param aPos is the position of the cursor (initial then new)
* @param aSnapToGrid = true to force the cursor position on grid
* @return true if the hotkey code is handled (captured).
*/
bool GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, bool aSnapToGrid );
/**
* Move and refresh the crosshair after movement and call the mouse capture function.
@ -194,6 +199,14 @@ public:
~EDA_DRAW_FRAME();
/** this function capture the key event before it is sent to the GUI.
* the basic frame does not capture this event.
* editor frames should override this event function to capture and filter
* these keys when they are used as hotkeys, and skip it if the key is not
* used as hotkey (otherwise the key events will be not sent to menus)
*/
virtual void OnCharHook( wxKeyEvent& event );
/**
* Function LockFile
* marks a schematic file as being in use. Use ReleaseFile() to undo this.
@ -571,6 +584,7 @@ public:
* @param aDC A device context.
* @param aPosition The current cursor position in logical (drawing) units.
* @param aHotKey A key event used for application specific control if not zero.
* @return true if the hotkey code is handled (captured).
*/
virtual bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 )
{

View File

@ -227,8 +227,9 @@ public:
/**
* Propagates an event to tools that requested events of matching type(s).
* @param aEvent is the event to be processed.
* @return true if the event is a managed hotkey
*/
void ProcessEvent( const TOOL_EVENT& aEvent );
bool ProcessEvent( const TOOL_EVENT& aEvent );
/**
* Puts an event to the event queue to be processed at the end of event processing cycle.
@ -491,7 +492,8 @@ private:
void popViewControls();
///> Main function for event processing.
void processEvent( const TOOL_EVENT& aEvent );
///> @return true if a hotkey was handled
bool processEvent( const TOOL_EVENT& aEvent );
/// Index of registered tools current states, associated by tools' objects.
TOOL_STATE_MAP m_toolState;

View File

@ -276,8 +276,6 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode )
bool PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
{
bool eventHandled = true;
// Filter out the 'fake' mouse motion after a keyboard movement
if( !aHotKey && m_movingCursorWithKeyboard )
{
@ -295,7 +293,7 @@ bool PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE
wxPoint oldpos = GetCrossHairPosition();
wxPoint pos = aPosition;
GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
// Put cursor in new position, according to the zoom keys (if any).
SetCrossHairPosition( pos, snapToGrid );
@ -336,12 +334,12 @@ bool PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE
RefreshCrossHair( oldpos, aPosition, aDC );
if( aHotKey )
if( aHotKey && OnHotKey( aDC, aHotKey, aPosition ) )
{
eventHandled = OnHotKey( aDC, aHotKey, aPosition );
keyHandled = true;
}
UpdateStatusBar(); // Display new cursor coordinates
return eventHandled;
return keyHandled;
}

View File

@ -740,8 +740,6 @@ void FOOTPRINT_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event )
bool FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
{
bool eventHandled = true;
// Filter out the 'fake' mouse motion after a keyboard movement
if( !aHotKey && m_movingCursorWithKeyboard )
{
@ -759,19 +757,19 @@ bool FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition,
wxPoint oldpos = GetCrossHairPosition();
wxPoint pos = aPosition;
GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
SetCrossHairPosition( pos, snapToGrid );
RefreshCrossHair( oldpos, aPosition, aDC );
if( aHotKey )
if( aHotKey && OnHotKey( aDC, aHotKey, aPosition ) )
{
eventHandled = OnHotKey( aDC, aHotKey, aPosition );
keyHandled = true;
}
UpdateStatusBar();
return eventHandled;
return keyHandled;
}