5 * Created by Toshi Nagata on 2014/09/21.
6 * Copyright 2014 Toshi Nagata. All rights reserved.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation version 2 of the License.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
18 #include "MyTextCtrl.h"
20 IMPLEMENT_DYNAMIC_CLASS(MyTextCtrl, wxTextCtrl)
22 BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
23 EVT_KEY_UP(MyTextCtrl::OnKeyUp)
26 const wxEventType myTextCtrl_EVT_PROCESS_ESCAPE = wxNewEventType();
28 MyTextCtrl::MyTextCtrl() : wxTextCtrl()
31 MyTextCtrl::MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value,
32 const wxPoint &pos, const wxSize &size,
33 long style, const wxValidator &validator,
35 : wxTextCtrl(parent, id, value, pos, size, style & ~(MyTextCtrl_Process_Escape), validator)
37 processEscape = (style & MyTextCtrl_Process_Escape) != 0;
40 MyTextCtrl::~MyTextCtrl()
43 // Call escape key handler on _releasing_ the ESC key
44 // Note: Overriding OnChar() function does not work!
45 // (Escape key is swallowed somewhere between OnKeyDown and OnChar)
47 MyTextCtrl::OnKeyUp(wxKeyEvent &event) {
48 if (processEscape && event.GetKeyCode() == WXK_ESCAPE) {
49 wxCommandEvent event(myTextCtrl_EVT_PROCESS_ESCAPE, m_windowId);
50 InitCommandEvent(event);
51 if (HandleWindowEvent(event)) {
57 #if defined(__WXMSW__)
58 // OnKeyDown() is private in WXMSW, so we cannot call the superclass handler.
59 // Here we copy the code in wxTextCtrl::OnKeyDown()
60 if ( event.GetModifiers() == wxMOD_CONTROL && IsRich() )
62 switch ( event.GetKeyCode() )
77 if ( event.GetKeyCode() == WXK_ESCAPE && IsMultiLine() )
81 // Pass the event to the superclass handler
82 wxTextCtrl::OnKeyDown(event);