NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
tableeditpanel.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2017 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "tableeditpanel.hpp"
20#include "../../kernel/core/datamanagement/container.hpp"
21
22#define ID_TABLEEDIT_OK 10101
23#define ID_TABLEEDIT_CANCEL 10102
24
25
26BEGIN_EVENT_TABLE(TablePanel, wxPanel)
27 EVT_CLOSE (TablePanel::OnClose)
29
30BEGIN_EVENT_TABLE(TableEditPanel, TablePanel)
31 EVT_BUTTON(ID_TABLEEDIT_OK, TableEditPanel::OnButtonOk)
32 EVT_BUTTON(ID_TABLEEDIT_CANCEL, TableEditPanel::OnButtonCancel)
33 EVT_CLOSE (TableEditPanel::OnClose)
35
36
47TablePanel::TablePanel(wxFrame* parent, wxWindowID id, wxStatusBar* statusbar, bool readOnly) : wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC | wxTAB_TRAVERSAL)
48{
49 finished = false;
50 m_terminal = nullptr;
51
52 vsizer = new wxBoxSizer(wxVERTICAL);
53 hsizer = new wxBoxSizer(wxHORIZONTAL);
54 m_commentField = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, -1),
55 wxTE_MULTILINE | wxTE_BESTWRAP | wxTE_RICH | wxBORDER_STATIC | (readOnly ? wxTE_READONLY : 0));
56 m_sourceField = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
57 wxTE_READONLY | wxBORDER_THEME);
58 m_lastSaveText = new wxStaticText(this, wxID_ANY, _guilang.get("GUI_TABLEPANEL_LASTSAVE"));
59
60 grid = new TableViewer(this, wxID_ANY, statusbar, this, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxBORDER_STATIC);
61 grid->SetTableReadOnly(readOnly);
62
63 vsizer->Add(new wxStaticText(this, wxID_ANY, _guilang.get("GUI_TABLEPANEL_DESCRIPTION")), 0, wxALIGN_LEFT | wxBOTTOM, 5);
64 vsizer->Add(m_commentField, 1, wxALIGN_CENTER_HORIZONTAL | wxEXPAND | wxBOTTOM, 5);
65 vsizer->Add(new wxStaticText(this, wxID_ANY, _guilang.get("GUI_TABLEPANEL_SOURCE")), 0, wxALIGN_LEFT | wxBOTTOM, 5);
66 vsizer->Add(m_sourceField, 0, wxALIGN_CENTER_HORIZONTAL | wxEXPAND | wxBOTTOM, 5);
67 vsizer->Add(m_lastSaveText, 0, wxALIGN_LEFT, 0);
68
69 hsizer->Add(vsizer, 0, wxEXPAND | wxALL, 5);
70 hsizer->Add(grid, 1, wxALIGN_CENTER_HORIZONTAL | wxEXPAND | wxALL, 5);
71
72 SetSizer(hsizer);
73 PostSizeEvent();
74}
75
76
86{
87 m_commentField->SetValue(meta.comment);
88 m_sourceField->SetValue(meta.source);
89 m_lastSaveText->SetLabel(_guilang.get("GUI_TABLEPANEL_LASTSAVE", toString(meta.lastSavedTime, GET_WITH_TEXT)));
90}
91
92
100std::string TablePanel::getComment() const
101{
102 return m_commentField->GetValue().ToStdString();
103}
104
105
115{
116 wxMenuBar* menuBar = static_cast<wxFrame*>(m_parent)->GetMenuBar();
117
118 if (!menuBar)
119 {
120 menuBar = new wxMenuBar();
121 static_cast<wxFrame*>(m_parent)->SetMenuBar(menuBar);
122 }
123
124 return menuBar;
125}
126
127
135{
136 return static_cast<wxFrame*>(m_parent);
137}
138
139
147void TablePanel::OnClose(wxCloseEvent& event)
148{
149 grid->finalize();
150
151 if (!finished)
152 {
153 finished = true;
154 m_parent->Close();
155 event.Skip();
156 }
157}
158
159
160
161
162
173TableEditPanel::TableEditPanel(wxFrame* parent, wxWindowID id, wxStatusBar* statusbar) : TablePanel(parent, id, statusbar, false)
174{
175 wxBoxSizer* buttonsizer = new wxBoxSizer(wxHORIZONTAL);
176
177 wxButton* button_ok = new wxButton(this, ID_TABLEEDIT_OK, _guilang.get("GUI_OPTIONS_OK"));
178 wxButton* button_cancel = new wxButton(this, ID_TABLEEDIT_CANCEL, _guilang.get("GUI_OPTIONS_CANCEL"));
179
180 buttonsizer->Add(button_ok, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
181 buttonsizer->Add(button_cancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT , 5);
182
183 vsizer->Prepend(buttonsizer, 0, wxALIGN_LEFT | wxEXPAND | wxBOTTOM, 5);
184 vsizer->Layout();
185}
186
187
195void TableEditPanel::OnButtonOk(wxCommandEvent& event)
196{
197 grid->finalize();
199 finished = true;
200 m_parent->Close();
201}
202
203
211void TableEditPanel::OnButtonCancel(wxCommandEvent& event)
212{
213 grid->finalize();
215 finished = true;
216 m_parent->Close();
217}
218
219
227void TableEditPanel::OnClose(wxCloseEvent& event)
228{
229 grid->finalize();
230
231 if (!finished)
232 {
234 finished = true;
235 m_parent->Close();
236 event.Skip();
237 }
238
239}
240
241
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
void passEditedTable(NumeRe::Table _table)
Passes a table (as a container) to the kernel.
Definition: terminal.cpp:245
void cancelTableEdit()
Definition: terminal.hpp:207
A table panel with editing functionalities. Creates APPLY and CANCEL buttons and provides their event...
void OnButtonOk(wxCommandEvent &event)
Event handler for the OK button.
void OnButtonCancel(wxCommandEvent &event)
Event handler for the CANCEL button.
void OnClose(wxCloseEvent &event)
Event handler for the CLOSE event.
TableEditPanel(wxFrame *parent, wxWindowID id, wxStatusBar *statusbar)
Constructor for the table edit panel, which creates also the buttons at the top of the window.
Generic table panel, which also contains all meta UI elements.
wxBoxSizer * vsizer
void OnClose(wxCloseEvent &event)
Event handler for the CLOSE event.
void update(const NumeRe::TableMetaData &meta)
Update the panel with the passed table meta data.
wxTextCtrl * m_sourceField
std::string getComment() const
Returns the comment listed in the documentation field.
wxFrame * getFrame()
Returns a pointer to the parent frame.
wxTextCtrl * m_commentField
NumeReTerminal * m_terminal
wxMenuBar * getMenuBar()
Returns a pointer to the menu bar of the parent frame. If no menu bar exists, a new one is created.
TableViewer * grid
wxStaticText * m_lastSaveText
This class is an adaption of the wxGrid class to present the tabular data in NumeRe's memory and enab...
Definition: tableviewer.hpp:42
NumeRe::Table GetData()
This member function returns the internal NumeRe::Table from the data provider object.
void finalize()
Ensure that the editors are all closed.
Language _guilang
@ GET_WITH_TEXT
Definition: stringtools.hpp:36
Encapsulating structure to gather all table meta data information.
Definition: table.hpp:32
__time64_t lastSavedTime
Definition: table.hpp:35
std::string source
Definition: table.hpp:34
std::string comment
Definition: table.hpp:33
std::string toString(int)
Converts an integer to a string without the Settings bloat.
#define ID_TABLEEDIT_OK
#define ID_TABLEEDIT_CANCEL
END_EVENT_TABLE()