From c3ef4d157195b4b4b983df348af5ce2ef31a7137 Mon Sep 17 00:00:00 2001 From: James Crook Date: Fri, 15 Jul 2016 12:15:29 +0100 Subject: [PATCH] Bug 1389 - Metadata Editor: First character entered in Genre field is not displayed. --- src/Tags.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/Tags.cpp b/src/Tags.cpp index 8648c56a8..756ee6b6c 100644 --- a/src/Tags.cpp +++ b/src/Tags.cpp @@ -615,6 +615,59 @@ public: wxGridCellChoiceEditor::SetSize(rect); } + + // Fix for Bug 1389 + // July 2016: ANSWER-ME: Does this need reporting upstream to wxWidgets? + virtual void StartingKey(wxKeyEvent& event) + { + // Lifted from wxGridCellTextEditor and adapted to combo. + + // [Below is comment from wxWidgets code] + // Since this is now happening in the EVT_CHAR event EmulateKeyPress is no + // longer an appropriate way to get the character into the text control. + // Do it ourselves instead. We know that if we get this far that we have + // a valid character, so not a whole lot of testing needs to be done. + + //The only difference to wxGridCellTextEditor. + //wxTextCtrl* tc = (wxTextCtrl *)m_control; + wxComboBox * tc = Combo(); + int ch; + + bool isPrintable; + + #if wxUSE_UNICODE + ch = event.GetUnicodeKey(); + if ( ch != WXK_NONE ) + isPrintable = true; + else + #endif // wxUSE_UNICODE + { + ch = event.GetKeyCode(); + isPrintable = ch >= WXK_SPACE && ch < WXK_START; + } + + switch (ch) + { + case WXK_DELETE: + // Delete the initial character when starting to edit with DELETE. + tc->Remove(0, 1); + break; + + case WXK_BACK: + // Delete the last character when starting to edit with BACKSPACE. + { + const long pos = tc->GetLastPosition(); + tc->Remove(pos - 1, pos); + } + break; + + default: + if ( isPrintable ) + tc->WriteText(static_cast(ch)); + break; + } + } + }; //