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

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
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -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_MIDDLE_DCLICK,   wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
    Connect( wxEVT_MOUSEWHEEL,      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_CHAR_HOOK,       wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) );
    Connect( wxEVT_KEY_UP,          wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
    Connect( wxEVT_CHAR,            wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
    Connect( wxEVT_KEY_DOWN,        wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
    Connect( wxEVT_ENTER_WINDOW,    wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
    Connect( wxEVT_ENTER_WINDOW,    wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this );
    Connect( KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE,
    Connect( KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE,
             wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
             wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
+14 −2
Original line number Original line Diff line number Diff line
@@ -115,10 +115,22 @@ void ACTION_MANAGER::RunAction( const TOOL_ACTION* aAction ) const


bool ACTION_MANAGER::RunHotKey( int aHotKey ) 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() )
    {
        it = m_actionHotKeys.find( key );


        if( it == m_actionHotKeys.end() )
        if( it == m_actionHotKeys.end() )
            return false; // no appropriate action found for the hotkey
            return false; // no appropriate action found for the hotkey
    }


    const std::list<TOOL_ACTION*>& actions = it->second;
    const std::list<TOOL_ACTION*>& actions = it->second;


+12 −9
Original line number Original line Diff line number Diff line
@@ -243,23 +243,26 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
    }
    }


    // Keyboard handling
    // Keyboard handling
    else if( type == wxEVT_KEY_UP || type == wxEVT_KEY_DOWN )
    else if( type == wxEVT_CHAR )
    {
    {
        wxKeyEvent* ke = static_cast<wxKeyEvent*>( &aEvent );
        wxKeyEvent* ke = static_cast<wxKeyEvent*>( &aEvent );
        int key = ke->GetKeyCode();
        int key = ke->GetKeyCode();
        int mods = decodeModifiers<wxKeyEvent>( ke );
        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;
        }
        }
        else

        {
        if( key == WXK_ESCAPE ) // ESC is the special key for cancelling tools
        if( key == WXK_ESCAPE ) // ESC is the special key for cancelling tools
            evt = TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL );
            evt = TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL );
        else
        else
                evt = TOOL_EVENT( TC_KEYBOARD, TA_KEY_DOWN, key | mods );
            evt = TOOL_EVENT( TC_KEYBOARD, TA_KEY_PRESSED, key | mods );
        }
    }
    }


    if( evt )
    if( evt )
+1 −2
Original line number Original line Diff line number Diff line
@@ -81,8 +81,7 @@ const std::string TOOL_EVENT::Format() const
        { TA_MOUSE_DRAG,            "drag"                },
        { TA_MOUSE_DRAG,            "drag"                },
        { TA_MOUSE_MOTION,          "motion"              },
        { TA_MOUSE_MOTION,          "motion"              },
        { TA_MOUSE_WHEEL,           "wheel"               },
        { TA_MOUSE_WHEEL,           "wheel"               },
        { TA_KEY_UP,                "key-up"              },
        { TA_KEY_PRESSED,           "key-pressed"         },
        { TA_KEY_DOWN,              "key-down"            },
        { TA_VIEW_REFRESH,          "view-refresh"        },
        { TA_VIEW_REFRESH,          "view-refresh"        },
        { TA_VIEW_ZOOM,             "view-zoom"           },
        { TA_VIEW_ZOOM,             "view-zoom"           },
        { TA_VIEW_PAN,              "view-pan"            },
        { TA_VIEW_PAN,              "view-pan"            },
+1 −1
Original line number Original line Diff line number Diff line
@@ -417,7 +417,7 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )


bool TOOL_MANAGER::dispatchStandardEvents( 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
        // Check if there is a hotkey associated
        if( m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ) )
        if( m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ) )
Loading