OSDN Git Service

Avoid opening files during execution of other Ruby script
[molby/Molby.git] / wxSources / MyTextCtrl.cpp
1 /*
2  *  MyTextCtrl.cpp
3  *  Molby
4  *
5  *  Created by Toshi Nagata on 2014/09/21.
6  *  Copyright 2014 Toshi Nagata. All rights reserved.
7  *
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.
11  
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.
16  */
17
18 #include "MyTextCtrl.h"
19
20 IMPLEMENT_DYNAMIC_CLASS(MyTextCtrl, wxTextCtrl)
21
22 BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
23 EVT_KEY_UP(MyTextCtrl::OnKeyUp)
24 END_EVENT_TABLE()
25
26 const wxEventType myTextCtrl_EVT_PROCESS_ESCAPE = wxNewEventType();
27
28 MyTextCtrl::MyTextCtrl() : wxTextCtrl()
29 {}
30
31 MyTextCtrl::MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value,
32                                            const wxPoint &pos, const wxSize &size,
33                                            long style, const wxValidator &validator,
34                                            const wxString &name)
35                                                 : wxTextCtrl(parent, id, value, pos, size, style & ~(MyTextCtrl_Process_Escape), validator)
36 {
37         processEscape = (style & MyTextCtrl_Process_Escape) != 0;
38 }
39
40 MyTextCtrl::~MyTextCtrl()
41 {}
42
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)
46 void
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)) {
52                         return;
53                 }
54         }
55         event.Skip();
56         return;
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() )
61     {
62         switch ( event.GetKeyCode() )
63         {
64             case 'C':
65                 Copy();
66                 return;
67             case 'X':
68                 Cut();
69                 return;
70             case 'V':
71                 Paste();
72                 return;
73             default:
74                 break;
75         }
76     }
77     if ( event.GetKeyCode() == WXK_ESCAPE && IsMultiLine() )
78         return;
79     event.Skip();       
80 #else
81         //  Pass the event to the superclass handler
82         wxTextCtrl::OnKeyDown(event);
83 #endif
84 }