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(const wxKeyEvent& evt, bool* consumed)
int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, bool* consumed) { {
#else int key = evt.GetKeyCode();
int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool WXUNUSED(meta), bool* consumed) { bool shift = evt.ShiftDown(),
#endif ctrl = evt.ControlDown(),
#if defined(__WXGTK__) || defined(__WXMAC__) alt = evt.AltDown();
// Ctrl chars (A-Z) end up with the wrong keycode on wxGTK
// TODO: Check this, it shouldn't be true any longer.
if (ctrl && key >= 1 && key <= 26) if (ctrl && key >= 1 && key <= 26)
key += 'A' - 1; key += 'A' - 1;
#endif
switch (key) { switch (key) {
case WXK_DOWN: key = SCK_DOWN; break; 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__ #ifdef __WXMAC__
if ( meta ) { if ( evt.MetaDown() ) {
// check for a few common Mac Meta-key combos and remap them to Ctrl // check for a few common Mac Meta-key combos and remap them to Ctrl
// for Scintilla // for Scintilla
switch ( key ) { switch ( key ) {

View File

@ -141,7 +141,7 @@ public:
void DoMiddleButtonUp(Point pt); void DoMiddleButtonUp(Point pt);
void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll); void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll);
void DoAddChar(int key); 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 DoTick() { Tick(); }
void DoOnIdle(wxIdleEvent& evt); void DoOnIdle(wxIdleEvent& evt);

View File

@ -2752,7 +2752,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) {
void wxStyledTextCtrl::OnChar(wxKeyEvent& 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 // 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 // to let the char through in that case, otherwise if only ctrl or only
// alt let's skip it. // alt let's skip it.
@ -2767,32 +2767,38 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) {
#endif #endif
bool skip = ((ctrl || alt) && ! (ctrl && alt)); 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", // if the unicode key code is not really a unicode character (it may
// key, m_lastKeyDownConsumed, ctrl, alt, skip); // 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
if ( (key <= WXK_START || key > WXK_COMMAND) && // don't do anything for function keys or etc.
!m_lastKeyDownConsumed && !skip) { if (key <= 255) {
m_swx->DoAddChar(key); key = evt.GetKeyCode();
return; 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(); evt.Skip();
} }
void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
int key = evt.GetKeyCode(); int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed);
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);
if (!processed && !m_lastKeyDownConsumed) if (!processed && !m_lastKeyDownConsumed)
evt.Skip(); evt.Skip();
} }

View File

@ -526,7 +526,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) {
void wxStyledTextCtrl::OnChar(wxKeyEvent& 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 // 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 // to let the char through in that case, otherwise if only ctrl or only
// alt let's skip it. // alt let's skip it.
@ -541,32 +541,38 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) {
#endif #endif
bool skip = ((ctrl || alt) && ! (ctrl && alt)); 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", // if the unicode key code is not really a unicode character (it may
// key, m_lastKeyDownConsumed, ctrl, alt, skip); // 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
if ( (key <= WXK_START || key > WXK_COMMAND) && // don't do anything for function keys or etc.
!m_lastKeyDownConsumed && !skip) { if (key <= 255) {
m_swx->DoAddChar(key); key = evt.GetKeyCode();
return; 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(); evt.Skip();
} }
void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
int key = evt.GetKeyCode(); int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed);
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);
if (!processed && !m_lastKeyDownConsumed) if (!processed && !m_lastKeyDownConsumed)
evt.Skip(); evt.Skip();
} }

View File

@ -760,17 +760,15 @@ void ScintillaWX::DoAddChar(int key) {
} }
#ifdef __WXMAC__ int ScintillaWX::DoKeyDown(const wxKeyEvent& evt, bool* consumed)
int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, bool* consumed) { {
#else int key = evt.GetKeyCode();
int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool WXUNUSED(meta), bool* consumed) { bool shift = evt.ShiftDown(),
#endif ctrl = evt.ControlDown(),
#if defined(__WXGTK__) || defined(__WXMAC__) alt = evt.AltDown();
// Ctrl chars (A-Z) end up with the wrong keycode on wxGTK
// TODO: Check this, it shouldn't be true any longer.
if (ctrl && key >= 1 && key <= 26) if (ctrl && key >= 1 && key <= 26)
key += 'A' - 1; key += 'A' - 1;
#endif
switch (key) { switch (key) {
case WXK_DOWN: key = SCK_DOWN; break; 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__ #ifdef __WXMAC__
if ( meta ) { if ( evt.MetaDown() ) {
// check for a few common Mac Meta-key combos and remap them to Ctrl // check for a few common Mac Meta-key combos and remap them to Ctrl
// for Scintilla // for Scintilla
switch ( key ) { switch ( key ) {

View File

@ -141,7 +141,7 @@ public:
void DoMiddleButtonUp(Point pt); void DoMiddleButtonUp(Point pt);
void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll); void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll);
void DoAddChar(int key); 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 DoTick() { Tick(); }
void DoOnIdle(wxIdleEvent& evt); void DoOnIdle(wxIdleEvent& evt);

View File

@ -2752,7 +2752,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) {
void wxStyledTextCtrl::OnChar(wxKeyEvent& 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 // 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 // to let the char through in that case, otherwise if only ctrl or only
// alt let's skip it. // alt let's skip it.
@ -2767,32 +2767,38 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) {
#endif #endif
bool skip = ((ctrl || alt) && ! (ctrl && alt)); 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", // if the unicode key code is not really a unicode character (it may
// key, m_lastKeyDownConsumed, ctrl, alt, skip); // 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
if ( (key <= WXK_START || key > WXK_COMMAND) && // don't do anything for function keys or etc.
!m_lastKeyDownConsumed && !skip) { if (key <= 255) {
m_swx->DoAddChar(key); key = evt.GetKeyCode();
return; 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(); evt.Skip();
} }
void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
int key = evt.GetKeyCode(); int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed);
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);
if (!processed && !m_lastKeyDownConsumed) if (!processed && !m_lastKeyDownConsumed)
evt.Skip(); evt.Skip();
} }

View File

@ -526,7 +526,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) {
void wxStyledTextCtrl::OnChar(wxKeyEvent& 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 // 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 // to let the char through in that case, otherwise if only ctrl or only
// alt let's skip it. // alt let's skip it.
@ -541,32 +541,38 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) {
#endif #endif
bool skip = ((ctrl || alt) && ! (ctrl && alt)); 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", // if the unicode key code is not really a unicode character (it may
// key, m_lastKeyDownConsumed, ctrl, alt, skip); // 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
if ( (key <= WXK_START || key > WXK_COMMAND) && // don't do anything for function keys or etc.
!m_lastKeyDownConsumed && !skip) { if (key <= 255) {
m_swx->DoAddChar(key); key = evt.GetKeyCode();
return; 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(); evt.Skip();
} }
void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
int key = evt.GetKeyCode(); int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed);
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);
if (!processed && !m_lastKeyDownConsumed) if (!processed && !m_lastKeyDownConsumed)
evt.Skip(); evt.Skip();
} }