| 1 |
#include "TextSpecifierPanel.h" |
| 2 |
|
| 3 |
#include <wx/textctrl.h> |
| 4 |
#include "../../Component.h" |
| 5 |
|
| 6 |
namespace objectives |
| 7 |
{ |
| 8 |
|
| 9 |
namespace ce |
| 10 |
{ |
| 11 |
|
| 12 |
// Constructor |
| 13 |
TextSpecifierPanel::TextSpecifierPanel() : |
| 14 |
_entry(nullptr) |
| 15 |
{} |
| 16 |
|
| 17 |
TextSpecifierPanel::TextSpecifierPanel(wxWindow* parent) : |
| 18 |
_entry(new wxTextCtrl(parent, wxID_ANY)) |
| 19 |
{ |
| 20 |
_entry->Connect(wxEVT_TEXT, wxCommandEventHandler(TextSpecifierPanel::onEntryChanged), nullptr, this); |
| 21 |
} |
| 22 |
|
| 23 |
TextSpecifierPanel::~TextSpecifierPanel() |
| 24 |
{ |
| 25 |
delete _entry; |
| 26 |
_entry = nullptr; |
| 27 |
} |
| 28 |
|
| 29 |
wxWindow* TextSpecifierPanel::getWidget() |
| 30 |
{ |
| 31 |
if (_entry == nullptr) |
| 32 |
{ |
| 33 |
throw std::runtime_error("Cannot pack a SpecifierPanel created by its default constructor."); |
| 34 |
} |
| 35 |
|
| 36 |
return _entry; |
| 37 |
} |
| 38 |
|
| 39 |
// Set the displayed value |
| 40 |
void TextSpecifierPanel::setValue(const std::string& value) |
| 41 |
{ |
| 42 |
assert(_entry != nullptr); |
| 43 |
_entry->SetValue(value); |
| 44 |
} |
| 45 |
|
| 46 |
// Get the edited value |
| 47 |
std::string TextSpecifierPanel::getValue() const |
| 48 |
{ |
| 49 |
assert(_entry != nullptr); |
| 50 |
return _entry->GetValue().ToStdString(); |
| 51 |
} |
| 52 |
|
| 53 |
void TextSpecifierPanel::onEntryChanged(wxCommandEvent& ev) |
| 54 |
{ |
| 55 |
if (_valueChanged) |
| 56 |
{ |
| 57 |
_valueChanged(); // usually points to the abstract ComponentEditor::writeToComponent |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
} // namespace ce |
| 62 |
|
| 63 |
} // namespace objectives |