| 1 |
#include "text_editor.h" |
| 2 |
#include <event_notifier.h> |
| 3 |
|
| 4 |
const wxEventType wxEVT_CMD_TEXT_EDITOR = ::wxNewEventType(); |
| 5 |
|
| 6 |
TextEditor::TextEditor(wxWindow* parent) |
| 7 |
: TextEditorBaseClass(parent) |
| 8 |
{ |
| 9 |
Hide(); |
| 10 |
} |
| 11 |
|
| 12 |
TextEditor::~TextEditor() {} |
| 13 |
|
| 14 |
void TextEditor::OnKeyDown(wxKeyEvent& event) |
| 15 |
{ |
| 16 |
if(event.GetKeyCode() == WXK_ESCAPE) { |
| 17 |
Hide(); |
| 18 |
} else { |
| 19 |
event.Skip(); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
void TextEditor::OnKillFocus(wxFocusEvent& event) |
| 24 |
{ |
| 25 |
event.Skip(); |
| 26 |
Hide(); |
| 27 |
wxCommandEvent evt(wxEVT_CMD_TEXT_EDITOR); |
| 28 |
evt.SetString(m_textCtrl->GetValue()); |
| 29 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 30 |
} |
| 31 |
|
| 32 |
void TextEditor::OnTextEnter(wxCommandEvent& event) |
| 33 |
{ |
| 34 |
Hide(); |
| 35 |
wxCommandEvent evt(wxEVT_CMD_TEXT_EDITOR); |
| 36 |
evt.SetString(m_textCtrl->GetValue()); |
| 37 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 38 |
} |
| 39 |
|
| 40 |
void TextEditor::SetValue(const wxString& value) { m_textCtrl->ChangeValue(value); } |
| 41 |
|
| 42 |
void TextEditor::MoveTo(const wxRect& rect) |
| 43 |
{ |
| 44 |
wxSize sz = rect.GetSize(); |
| 45 |
sz.IncBy(1, 1); |
| 46 |
SetSize(sz); |
| 47 |
Move(rect.GetTopLeft()); |
| 48 |
Show(); |
| 49 |
m_textCtrl->SelectAll(); |
| 50 |
m_textCtrl->SetFocus(); |
| 51 |
} |