Use the unicode character, if available in the event

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2005-02-04 18:48:09 +00:00
parent 0b6d471427
commit 5fd656d503
8 changed files with 122 additions and 102 deletions

View File

@ -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 ) {

View File

@ -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);

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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 ) {

View File

@ -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);

View File

@ -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();
}

View File

@ -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();
}