Fix keyboard layout handling issues in time edits. Closes #1630.
This commit is contained in:
parent
53a90d5f18
commit
91e4cd292e
2 changed files with 35 additions and 21 deletions
|
@ -79,6 +79,7 @@ TimeEdit::TimeEdit(wxWindow* parent, wxWindowID id, agi::Context *c, const std::
|
||||||
Bind(wxEVT_COMMAND_TEXT_UPDATED, &TimeEdit::OnModified, this);
|
Bind(wxEVT_COMMAND_TEXT_UPDATED, &TimeEdit::OnModified, this);
|
||||||
Bind(wxEVT_CONTEXT_MENU, &TimeEdit::OnContextMenu, this);
|
Bind(wxEVT_CONTEXT_MENU, &TimeEdit::OnContextMenu, this);
|
||||||
Bind(wxEVT_CHAR_HOOK, &TimeEdit::OnKeyDown, this);
|
Bind(wxEVT_CHAR_HOOK, &TimeEdit::OnKeyDown, this);
|
||||||
|
Bind(wxEVT_CHAR, &TimeEdit::OnChar, this);
|
||||||
Bind(wxEVT_KILL_FOCUS, &TimeEdit::OnFocusLost, this);
|
Bind(wxEVT_KILL_FOCUS, &TimeEdit::OnFocusLost, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +124,10 @@ void TimeEdit::UpdateText() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeEdit::OnKeyDown(wxKeyEvent &event) {
|
void TimeEdit::OnKeyDown(wxKeyEvent &event) {
|
||||||
int key = event.GetKeyCode();
|
int kc = event.GetKeyCode();
|
||||||
|
|
||||||
|
// Needs to be done here to trump user-defined hotkeys
|
||||||
|
int key = event.GetUnicodeKey();
|
||||||
if (event.CmdDown()) {
|
if (event.CmdDown()) {
|
||||||
if (key == 'C' || key == 'X')
|
if (key == 'C' || key == 'X')
|
||||||
CopyTime();
|
CopyTime();
|
||||||
|
@ -136,35 +140,44 @@ void TimeEdit::OnKeyDown(wxKeyEvent &event) {
|
||||||
|
|
||||||
// Shift-Insert would paste the stuff anyway
|
// Shift-Insert would paste the stuff anyway
|
||||||
// but no one updates the private "time" variable.
|
// but no one updates the private "time" variable.
|
||||||
if (event.ShiftDown() && key == WXK_INSERT) {
|
if (event.ShiftDown() && kc == WXK_INSERT) {
|
||||||
PasteTime();
|
PasteTime();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate numpad presses to normal numbers
|
if (byFrame || insert) {
|
||||||
if (key >= WXK_NUMPAD0 && key <= WXK_NUMPAD9)
|
|
||||||
key += '0' - WXK_NUMPAD0;
|
|
||||||
|
|
||||||
// If overwriting is disabled, we're in frame mode, or it's a key we
|
|
||||||
// don't care about just let the standard processing happen
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
if (byFrame) return;
|
return;
|
||||||
if (insert) return;
|
}
|
||||||
if ((key < '0' || key > '9') && key != WXK_BACK && key != WXK_DELETE && key != ';' && key != '.' && key != ',') return;
|
// Overwrite mode stuff
|
||||||
|
|
||||||
|
// On OS X backspace is reported as delete
|
||||||
|
#ifdef __APPLE__
|
||||||
|
if (kc == WXK_DELETE)
|
||||||
|
kc = WXK_BACK;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Back just moves cursor back one without deleting
|
||||||
|
if (kc == WXK_BACK) {
|
||||||
|
long start = GetInsertionPoint();
|
||||||
|
if (start > 0)
|
||||||
|
SetInsertionPoint(start - 1);
|
||||||
|
}
|
||||||
|
// Delete just does nothing
|
||||||
|
else if (kc != WXK_DELETE)
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeEdit::OnChar(wxKeyEvent &event) {
|
||||||
|
event.Skip();
|
||||||
|
if (byFrame || insert) return;
|
||||||
|
|
||||||
|
int key = event.GetUnicodeKey();
|
||||||
|
if ((key < '0' || key > '9') && key != ';' && key != '.' && key != ',') return;
|
||||||
|
|
||||||
event.Skip(false);
|
event.Skip(false);
|
||||||
|
|
||||||
// Delete does nothing
|
|
||||||
if (key == WXK_DELETE) return;
|
|
||||||
|
|
||||||
long start = GetInsertionPoint();
|
long start = GetInsertionPoint();
|
||||||
// Back just moves cursor back one without deleting
|
|
||||||
if (key == WXK_BACK) {
|
|
||||||
if (start > 0)
|
|
||||||
SetInsertionPoint(start - 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string text = from_wx(GetValue());
|
std::string text = from_wx(GetValue());
|
||||||
// Cursor is at the end so do nothing
|
// Cursor is at the end so do nothing
|
||||||
if (start >= (long)text.size()) return;
|
if (start >= (long)text.size()) return;
|
||||||
|
@ -174,7 +187,7 @@ void TimeEdit::OnKeyDown(wxKeyEvent &event) {
|
||||||
++start;
|
++start;
|
||||||
|
|
||||||
// : and . hop over punctuation but never insert anything
|
// : and . hop over punctuation but never insert anything
|
||||||
if (key == ';' || key == '.' || key == ',') {
|
if (key == ':' || key == ';' || key == '.' || key == ',') {
|
||||||
SetInsertionPoint(start);
|
SetInsertionPoint(start);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ class TimeEdit : public wxTextCtrl {
|
||||||
void OnFocusLost(wxFocusEvent &evt);
|
void OnFocusLost(wxFocusEvent &evt);
|
||||||
void OnInsertChanged(agi::OptionValue const& opt);
|
void OnInsertChanged(agi::OptionValue const& opt);
|
||||||
void OnKeyDown(wxKeyEvent &event);
|
void OnKeyDown(wxKeyEvent &event);
|
||||||
|
void OnChar(wxKeyEvent &event);
|
||||||
void OnModified(wxCommandEvent &event);
|
void OnModified(wxCommandEvent &event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue