diff --git a/contrib/src/stc/ScintillaWX.cpp b/contrib/src/stc/ScintillaWX.cpp index 05709cb689..41b3a5a06d 100644 --- a/contrib/src/stc/ScintillaWX.cpp +++ b/contrib/src/stc/ScintillaWX.cpp @@ -760,17 +760,15 @@ void ScintillaWX::DoAddChar(int key) { } -#ifdef __WXMAC__ -int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, bool* consumed) { -#else -int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool WXUNUSED(meta), bool* consumed) { -#endif -#if defined(__WXGTK__) || defined(__WXMAC__) - // Ctrl chars (A-Z) end up with the wrong keycode on wxGTK - // TODO: Check this, it shouldn't be true any longer. +int ScintillaWX::DoKeyDown(const wxKeyEvent& evt, bool* consumed) +{ + int key = evt.GetKeyCode(); + bool shift = evt.ShiftDown(), + ctrl = evt.ControlDown(), + alt = evt.AltDown(); + if (ctrl && key >= 1 && key <= 26) key += 'A' - 1; -#endif switch (key) { case WXK_DOWN: key = SCK_DOWN; break; @@ -802,7 +800,7 @@ int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool WXUNU } #ifdef __WXMAC__ - if ( meta ) { + if ( evt.MetaDown() ) { // check for a few common Mac Meta-key combos and remap them to Ctrl // for Scintilla switch ( key ) { diff --git a/contrib/src/stc/ScintillaWX.h b/contrib/src/stc/ScintillaWX.h index a902db5ed6..db80889e77 100644 --- a/contrib/src/stc/ScintillaWX.h +++ b/contrib/src/stc/ScintillaWX.h @@ -141,7 +141,7 @@ public: void DoMiddleButtonUp(Point pt); void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll); void DoAddChar(int key); - int DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, bool* consumed); + int DoKeyDown(const wxKeyEvent& event, bool* consumed); void DoTick() { Tick(); } void DoOnIdle(wxIdleEvent& evt); diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp index 3117711387..b3b3cd2765 100644 --- a/contrib/src/stc/stc.cpp +++ b/contrib/src/stc/stc.cpp @@ -2752,7 +2752,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { - // On (some?) non-US keyboards the AltGr key is required to enter some + // On (some?) non-US PC keyboards the AltGr key is required to enter some // common characters. It comes to us as both Alt and Ctrl down so we need // to let the char through in that case, otherwise if only ctrl or only // alt let's skip it. @@ -2767,32 +2767,38 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { #endif bool skip = ((ctrl || alt) && ! (ctrl && alt)); - int key = evt.GetKeyCode(); + if (!m_lastKeyDownConsumed && !skip) { +#if wxUSE_UNICODE + int key = evt.GetUnicodeKey(); + bool keyOk = true; -// printf("OnChar key:%d consumed:%d ctrl:%d alt:%d skip:%d\n", -// key, m_lastKeyDownConsumed, ctrl, alt, skip); - - if ( (key <= WXK_START || key > WXK_COMMAND) && - !m_lastKeyDownConsumed && !skip) { - m_swx->DoAddChar(key); - return; + // if the unicode key code is not really a unicode character (it may + // be a function key or etc., the platforms appear to always give us a + // small value in this case) then fallback to the ascii key code but + // don't do anything for function keys or etc. + if (key <= 255) { + key = evt.GetKeyCode(); + keyOk = (key <= 255); + } + if (keyOk) { + m_swx->DoAddChar(key); + return; + } +#else + int key = evt.GetKeyCode(); + if (key <= WXK_START || key > WXK_COMMAND) { + m_swx->DoAddChar(key); + return; + } +#endif } + evt.Skip(); } void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { - int key = evt.GetKeyCode(); - bool shift = evt.ShiftDown(), - ctrl = evt.ControlDown(), - alt = evt.AltDown(), - meta = evt.MetaDown(); - - int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, meta, &m_lastKeyDownConsumed); - -// printf("KeyDn key:%d shift:%d ctrl:%d alt:%d processed:%d consumed:%d\n", -// key, shift, ctrl, alt, processed, m_lastKeyDownConsumed); - + int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed); if (!processed && !m_lastKeyDownConsumed) evt.Skip(); } diff --git a/contrib/src/stc/stc.cpp.in b/contrib/src/stc/stc.cpp.in index 702062aa61..9d5b1f19b2 100644 --- a/contrib/src/stc/stc.cpp.in +++ b/contrib/src/stc/stc.cpp.in @@ -526,7 +526,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { - // On (some?) non-US keyboards the AltGr key is required to enter some + // On (some?) non-US PC keyboards the AltGr key is required to enter some // common characters. It comes to us as both Alt and Ctrl down so we need // to let the char through in that case, otherwise if only ctrl or only // alt let's skip it. @@ -541,32 +541,38 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { #endif bool skip = ((ctrl || alt) && ! (ctrl && alt)); - int key = evt.GetKeyCode(); + if (!m_lastKeyDownConsumed && !skip) { +#if wxUSE_UNICODE + int key = evt.GetUnicodeKey(); + bool keyOk = true; -// printf("OnChar key:%%d consumed:%%d ctrl:%%d alt:%%d skip:%%d\n", -// key, m_lastKeyDownConsumed, ctrl, alt, skip); - - if ( (key <= WXK_START || key > WXK_COMMAND) && - !m_lastKeyDownConsumed && !skip) { - m_swx->DoAddChar(key); - return; + // if the unicode key code is not really a unicode character (it may + // be a function key or etc., the platforms appear to always give us a + // small value in this case) then fallback to the ascii key code but + // don't do anything for function keys or etc. + if (key <= 255) { + key = evt.GetKeyCode(); + keyOk = (key <= 255); + } + if (keyOk) { + m_swx->DoAddChar(key); + return; + } +#else + int key = evt.GetKeyCode(); + if (key <= WXK_START || key > WXK_COMMAND) { + m_swx->DoAddChar(key); + return; + } +#endif } + evt.Skip(); } void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { - int key = evt.GetKeyCode(); - bool shift = evt.ShiftDown(), - ctrl = evt.ControlDown(), - alt = evt.AltDown(), - meta = evt.MetaDown(); - - int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, meta, &m_lastKeyDownConsumed); - -// printf("KeyDn key:%%d shift:%%d ctrl:%%d alt:%%d processed:%%d consumed:%%d\n", -// key, shift, ctrl, alt, processed, m_lastKeyDownConsumed); - + int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed); if (!processed && !m_lastKeyDownConsumed) evt.Skip(); } diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 05709cb689..41b3a5a06d 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -760,17 +760,15 @@ void ScintillaWX::DoAddChar(int key) { } -#ifdef __WXMAC__ -int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, bool* consumed) { -#else -int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool WXUNUSED(meta), bool* consumed) { -#endif -#if defined(__WXGTK__) || defined(__WXMAC__) - // Ctrl chars (A-Z) end up with the wrong keycode on wxGTK - // TODO: Check this, it shouldn't be true any longer. +int ScintillaWX::DoKeyDown(const wxKeyEvent& evt, bool* consumed) +{ + int key = evt.GetKeyCode(); + bool shift = evt.ShiftDown(), + ctrl = evt.ControlDown(), + alt = evt.AltDown(); + if (ctrl && key >= 1 && key <= 26) key += 'A' - 1; -#endif switch (key) { case WXK_DOWN: key = SCK_DOWN; break; @@ -802,7 +800,7 @@ int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool WXUNU } #ifdef __WXMAC__ - if ( meta ) { + if ( evt.MetaDown() ) { // check for a few common Mac Meta-key combos and remap them to Ctrl // for Scintilla switch ( key ) { diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index a902db5ed6..db80889e77 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -141,7 +141,7 @@ public: void DoMiddleButtonUp(Point pt); void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll); void DoAddChar(int key); - int DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, bool* consumed); + int DoKeyDown(const wxKeyEvent& event, bool* consumed); void DoTick() { Tick(); } void DoOnIdle(wxIdleEvent& evt); diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 3117711387..b3b3cd2765 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -2752,7 +2752,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { - // On (some?) non-US keyboards the AltGr key is required to enter some + // On (some?) non-US PC keyboards the AltGr key is required to enter some // common characters. It comes to us as both Alt and Ctrl down so we need // to let the char through in that case, otherwise if only ctrl or only // alt let's skip it. @@ -2767,32 +2767,38 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { #endif bool skip = ((ctrl || alt) && ! (ctrl && alt)); - int key = evt.GetKeyCode(); + if (!m_lastKeyDownConsumed && !skip) { +#if wxUSE_UNICODE + int key = evt.GetUnicodeKey(); + bool keyOk = true; -// printf("OnChar key:%d consumed:%d ctrl:%d alt:%d skip:%d\n", -// key, m_lastKeyDownConsumed, ctrl, alt, skip); - - if ( (key <= WXK_START || key > WXK_COMMAND) && - !m_lastKeyDownConsumed && !skip) { - m_swx->DoAddChar(key); - return; + // if the unicode key code is not really a unicode character (it may + // be a function key or etc., the platforms appear to always give us a + // small value in this case) then fallback to the ascii key code but + // don't do anything for function keys or etc. + if (key <= 255) { + key = evt.GetKeyCode(); + keyOk = (key <= 255); + } + if (keyOk) { + m_swx->DoAddChar(key); + return; + } +#else + int key = evt.GetKeyCode(); + if (key <= WXK_START || key > WXK_COMMAND) { + m_swx->DoAddChar(key); + return; + } +#endif } + evt.Skip(); } void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { - int key = evt.GetKeyCode(); - bool shift = evt.ShiftDown(), - ctrl = evt.ControlDown(), - alt = evt.AltDown(), - meta = evt.MetaDown(); - - int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, meta, &m_lastKeyDownConsumed); - -// printf("KeyDn key:%d shift:%d ctrl:%d alt:%d processed:%d consumed:%d\n", -// key, shift, ctrl, alt, processed, m_lastKeyDownConsumed); - + int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed); if (!processed && !m_lastKeyDownConsumed) evt.Skip(); } diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 702062aa61..9d5b1f19b2 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -526,7 +526,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { - // On (some?) non-US keyboards the AltGr key is required to enter some + // On (some?) non-US PC keyboards the AltGr key is required to enter some // common characters. It comes to us as both Alt and Ctrl down so we need // to let the char through in that case, otherwise if only ctrl or only // alt let's skip it. @@ -541,32 +541,38 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { #endif bool skip = ((ctrl || alt) && ! (ctrl && alt)); - int key = evt.GetKeyCode(); + if (!m_lastKeyDownConsumed && !skip) { +#if wxUSE_UNICODE + int key = evt.GetUnicodeKey(); + bool keyOk = true; -// printf("OnChar key:%%d consumed:%%d ctrl:%%d alt:%%d skip:%%d\n", -// key, m_lastKeyDownConsumed, ctrl, alt, skip); - - if ( (key <= WXK_START || key > WXK_COMMAND) && - !m_lastKeyDownConsumed && !skip) { - m_swx->DoAddChar(key); - return; + // if the unicode key code is not really a unicode character (it may + // be a function key or etc., the platforms appear to always give us a + // small value in this case) then fallback to the ascii key code but + // don't do anything for function keys or etc. + if (key <= 255) { + key = evt.GetKeyCode(); + keyOk = (key <= 255); + } + if (keyOk) { + m_swx->DoAddChar(key); + return; + } +#else + int key = evt.GetKeyCode(); + if (key <= WXK_START || key > WXK_COMMAND) { + m_swx->DoAddChar(key); + return; + } +#endif } + evt.Skip(); } void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { - int key = evt.GetKeyCode(); - bool shift = evt.ShiftDown(), - ctrl = evt.ControlDown(), - alt = evt.AltDown(), - meta = evt.MetaDown(); - - int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, meta, &m_lastKeyDownConsumed); - -// printf("KeyDn key:%%d shift:%%d ctrl:%%d alt:%%d processed:%%d consumed:%%d\n", -// key, shift, ctrl, alt, processed, m_lastKeyDownConsumed); - + int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed); if (!processed && !m_lastKeyDownConsumed) evt.Skip(); }