Commit 3f8d9da3 authored by Maciej Suminski's avatar Maciej Suminski

Key events are handled by wxEVT_CHAR instead of wxEVT_KEY_[UP|DOWN]. Fixed...

Key events are handled by wxEVT_CHAR instead of wxEVT_KEY_[UP|DOWN]. Fixed issue of chars that require modifiers (e.g. ? is Shift+/ on US keyboard layout).
parent 50b202fe
......@@ -83,8 +83,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
Connect( wxEVT_MIDDLE_DCLICK, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_MOUSEWHEEL, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) );
Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_CHAR, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
Connect( KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE,
wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
......
......@@ -115,10 +115,22 @@ void ACTION_MANAGER::RunAction( const TOOL_ACTION* aAction ) const
bool ACTION_MANAGER::RunHotKey( int aHotKey ) const
{
HOTKEY_LIST::const_iterator it = m_actionHotKeys.find( aHotKey );
int key = std::toupper( aHotKey & ~MD_MODIFIER_MASK );
int mod = aHotKey & MD_MODIFIER_MASK;
HOTKEY_LIST::const_iterator it = m_actionHotKeys.find( key | mod );
// If no luck, try without modifier, to handle keys that require a modifier
// e.g. to get ? you need to press Shift+/ without US keyboard layout
// Hardcoding ? as Shift+/ is a bad idea, as on another layout you may need to press a
// different combination
if( it == m_actionHotKeys.end() )
return false; // no appropriate action found for the hotkey
{
it = m_actionHotKeys.find( key );
if( it == m_actionHotKeys.end() )
return false; // no appropriate action found for the hotkey
}
const std::list<TOOL_ACTION*>& actions = it->second;
......
......@@ -243,23 +243,26 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
}
// Keyboard handling
else if( type == wxEVT_KEY_UP || type == wxEVT_KEY_DOWN )
else if( type == wxEVT_CHAR )
{
wxKeyEvent* ke = static_cast<wxKeyEvent*>( &aEvent );
int key = ke->GetKeyCode();
int mods = decodeModifiers<wxKeyEvent>( ke );
if( type == wxEVT_KEY_UP )
if( mods & MD_CTRL )
{
evt = TOOL_EVENT( TC_KEYBOARD, TA_KEY_UP, key | mods );
// wxWidgets have a quirk related to Ctrl+letter hot keys handled by CHAR_EVT
// http://docs.wxwidgets.org/trunk/classwx_key_event.html:
// "char events for ASCII letters in this case carry codes corresponding to the ASCII
// value of Ctrl-Latter, i.e. 1 for Ctrl-A, 2 for Ctrl-B and so on until 26 for Ctrl-Z."
if( key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
key += 'A' - 1;
}
if( key == WXK_ESCAPE ) // ESC is the special key for cancelling tools
evt = TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL );
else
{
if( key == WXK_ESCAPE ) // ESC is the special key for cancelling tools
evt = TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL );
else
evt = TOOL_EVENT( TC_KEYBOARD, TA_KEY_DOWN, key | mods );
}
evt = TOOL_EVENT( TC_KEYBOARD, TA_KEY_PRESSED, key | mods );
}
if( evt )
......
......@@ -81,8 +81,7 @@ const std::string TOOL_EVENT::Format() const
{ TA_MOUSE_DRAG, "drag" },
{ TA_MOUSE_MOTION, "motion" },
{ TA_MOUSE_WHEEL, "wheel" },
{ TA_KEY_UP, "key-up" },
{ TA_KEY_DOWN, "key-down" },
{ TA_KEY_PRESSED, "key-pressed" },
{ TA_VIEW_REFRESH, "view-refresh" },
{ TA_VIEW_ZOOM, "view-zoom" },
{ TA_VIEW_PAN, "view-pan" },
......
......@@ -417,7 +417,7 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
bool TOOL_MANAGER::dispatchStandardEvents( TOOL_EVENT& aEvent )
{
if( aEvent.Action() == TA_KEY_UP )
if( aEvent.Action() == TA_KEY_PRESSED )
{
// Check if there is a hotkey associated
if( m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ) )
......
......@@ -64,36 +64,35 @@ enum TOOL_ACTIONS
TA_MOUSE_WHEEL = 0x0040,
TA_MOUSE = 0x007f,
TA_KEY_UP = 0x0080,
TA_KEY_DOWN = 0x0100,
TA_KEYBOARD = TA_KEY_UP | TA_KEY_DOWN,
TA_KEY_PRESSED = 0x0080,
TA_KEYBOARD = TA_KEY_PRESSED,
// View related events
TA_VIEW_REFRESH = 0x0200,
TA_VIEW_ZOOM = 0x0400,
TA_VIEW_PAN = 0x0800,
TA_VIEW_DIRTY = 0x1000,
TA_VIEW = 0x1e00,
TA_VIEW_REFRESH = 0x0100,
TA_VIEW_ZOOM = 0x0200,
TA_VIEW_PAN = 0x0400,
TA_VIEW_DIRTY = 0x0800,
TA_VIEW = 0x0f00,
TA_CHANGE_LAYER = 0x2000,
TA_CHANGE_LAYER = 0x1000,
// Tool cancel event. Issued automagically when the user hits escape or selects End Tool from
// the context menu.
TA_CANCEL_TOOL = 0x4000,
TA_CANCEL_TOOL = 0x2000,
// Context menu update. Issued whenever context menu is open and the user hovers the mouse
// over one of choices. Used in dynamic highligting in disambiguation menu
TA_CONTEXT_MENU_UPDATE = 0x8000,
TA_CONTEXT_MENU_UPDATE = 0x4000,
// Context menu choice. Sent if the user picked something from the context menu or
// closed it without selecting anything.
TA_CONTEXT_MENU_CHOICE = 0x10000,
TA_CONTEXT_MENU_CHOICE = 0x8000,
// This event is sent *before* undo/redo command is performed.
TA_UNDO_REDO = 0x20000,
TA_UNDO_REDO = 0x10000,
// Tool action (allows to control tools)
TA_ACTION = 0x40000,
TA_ACTION = 0x20000,
TA_ANY = 0xffffffff
};
......@@ -277,14 +276,9 @@ public:
return m_keyCode;
}
bool IsKeyUp() const
bool IsKeyPressed() const
{
return m_actions == TA_KEY_UP;
}
bool IsKeyDown() const
{
return m_actions == TA_KEY_DOWN;
return m_actions == TA_KEY_PRESSED;
}
void SetMouseDragOrigin( const VECTOR2D& aP )
......
......@@ -45,11 +45,11 @@
using namespace KIGFX;
using boost::optional;
static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'G' );
static TOOL_ACTION ACT_PlaceVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, 'V' );
static TOOL_ACTION ACT_OpenRouteOptions( "pcbnew.InteractiveRouter.OpenRouterOptions", AS_CONTEXT, 'T' );
static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, '/' );
static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END );
//static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'G' );
//static TOOL_ACTION ACT_PlaceVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, 'V' );
//static TOOL_ACTION ACT_OpenRouteOptions( "pcbnew.InteractiveRouter.OpenRouterOptions", AS_CONTEXT, 'T' );
//static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, '/' );
//static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END );
ROUTER_TOOL::ROUTER_TOOL() :
TOOL_INTERACTIVE( "pcbnew.InteractiveRouter" )
......@@ -367,9 +367,9 @@ void ROUTER_TOOL::startRouting()
m_router->Move( m_endSnapPoint, m_endItem );
}
else if( evt->IsKeyUp() )
else if( evt->IsKeyPressed() )
{
switch( evt->KeyCode() )
switch( std::toupper( evt->KeyCode() ) )
{
case 'V':
{
......
......@@ -148,11 +148,11 @@ TOOL_ACTION COMMON_ACTIONS::highContrastMode( "pcbnew.highContrastMode",
"", "" );
TOOL_ACTION COMMON_ACTIONS::highContrastInc( "pcbnew.highContrastInc",
AS_GLOBAL, MD_SHIFT + '.', // shift+. == >
AS_GLOBAL, '>',
"", "" );
TOOL_ACTION COMMON_ACTIONS::highContrastDec( "pcbnew.highContrastDec",
AS_GLOBAL, MD_SHIFT + 60, // shift+, == <
AS_GLOBAL, '<',
"", "" );
......@@ -198,11 +198,11 @@ TOOL_ACTION COMMON_ACTIONS::layerPrev( "pcbnew.layerPrev",
"", "" );
TOOL_ACTION COMMON_ACTIONS::layerAlphaInc( "pcbnew.layerAlphaInc",
AS_GLOBAL, MD_SHIFT + ']', // shift+] == }
AS_GLOBAL, '}',
"", "" );
TOOL_ACTION COMMON_ACTIONS::layerAlphaDec( "pcbnew.layerAlphaDec",
AS_GLOBAL, MD_SHIFT + '[', // shift+[ == {
AS_GLOBAL, '{',
"", "" );
......@@ -252,7 +252,7 @@ TOOL_ACTION COMMON_ACTIONS::switchUnits( "pcbnew.switchUnits",
"", "" );
TOOL_ACTION COMMON_ACTIONS::showHelp( "pcbnew.showHelp",
AS_GLOBAL, MD_SHIFT + '/', // shift+/ == ?
AS_GLOBAL, '?',
"", "" );
......
......@@ -135,7 +135,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
break;
}
else if( evt->IsKeyUp() && step != SET_ORIGIN )
else if( evt->IsKeyPressed() && step != SET_ORIGIN )
{
int width = arc->GetWidth();
......@@ -427,7 +427,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
break;
}
else if( evt->IsKeyUp() && step != SET_ORIGIN )
else if( evt->IsKeyPressed() && step != SET_ORIGIN )
{
width = dimension->GetWidth();
......@@ -603,7 +603,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
if( evt->IsCancel() )
break;
else if( evt->IsKeyUp() )
else if( evt->IsKeyPressed() )
{
int width = target->GetWidth();
......@@ -822,7 +822,7 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
m_controls->SetAutoPan( false );
}
else if( graphic && evt->IsKeyUp() )
else if( graphic && evt->IsKeyPressed() )
{
int width = graphic->GetWidth();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment