3 * Config panel, used to specify parameters (for example clients, filesets... in restore)
5 * Nicolas Boichat, April 2004
9 Copyright (C) 2004 Kern Sibbald and John Walker
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include "wxbconfigpanel.h"
28 #include <wx/arrimpl.cpp>
30 WX_DEFINE_OBJARRAY(wxbConfig);
32 /* Create a new config parameter */
33 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, wxString value) {
40 this->choicectrl = NULL;
41 this->textctrl = NULL;
42 this->statictext = NULL;
45 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, int n, wxString* values) {
49 this->values = new wxString[n];
50 for (int i = 0; i < n; i++) {
51 this->values[i] = values[i];
54 this->choicectrl = NULL;
55 this->textctrl = NULL;
56 this->statictext = NULL;
59 wxbConfigParam::~wxbConfigParam() {
60 if (values) delete[] values;
61 if (choicectrl) delete choicectrl;
62 if (textctrl) delete textctrl;
63 if (statictext) delete statictext;
66 void wxbConfigParam::AddControl(wxWindow* parent, wxSizer* sizer) {
67 sizer->Add(new wxStaticText(parent, -1, title + ": ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
70 statictext = new wxStaticText(parent, -1, value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
71 sizer->Add(statictext, 1, wxEXPAND | wxADJUST_MINSIZE);
74 textctrl = new wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize);
75 sizer->Add(textctrl, 1, wxEXPAND | wxADJUST_MINSIZE);
78 choicectrl = new wxChoice(parent, id, wxDefaultPosition, wxSize(150, 20), nvalues, values);
79 sizer->Add(choicectrl, 1, wxEXPAND);
84 wxString wxbConfigParam::GetTitle() {
88 wxString wxbConfigParam::GetValue() {
91 return (statictext != NULL) ? statictext->GetLabel() : wxString("");
94 return (textctrl != NULL) ? textctrl->GetValue() : wxString("");
97 return (choicectrl != NULL) ? choicectrl->GetStringSelection() : wxString("");
103 void wxbConfigParam::SetValue(wxString str) {
107 statictext->SetLabel(str);
111 textctrl->SetValue(str);
116 for (k = 0; k < choicectrl->GetCount(); k++) {
117 if (str == choicectrl->GetString(k)) {
118 choicectrl->SetSelection(k);
122 if (k == choicectrl->GetCount()) { // Should never happen
123 choicectrl->Append(str);
124 choicectrl->SetSelection(k);
131 int wxbConfigParam::GetIndex() {
133 return choicectrl->GetSelection();
138 void wxbConfigParam::SetIndex(int ind) {
140 choicectrl->SetSelection(ind);
144 void wxbConfigParam::Clear() {
150 void wxbConfigParam::Add(wxString value) {
152 choicectrl->Append(value);
156 /* Creates a new config panel, config must be allocated with new */
157 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
158 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
160 this->config = config;
162 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
165 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
166 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
168 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
170 for (i = 0; i < config->GetCount(); i++) {
171 (*config)[i].AddControl(this, cfgSizer);
173 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
175 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
177 cfgOk = new wxButton(this, ok, "OK", wxDefaultPosition, wxSize(70, 25));
178 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
181 cfgApply = new wxButton(this, apply, "Apply", wxDefaultPosition, wxSize(70, 25));
182 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
188 cfgCancel = new wxButton(this, cancel, "Cancel", wxDefaultPosition, wxSize(70, 25));
189 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
191 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
194 mainSizer->SetSizeHints(this);
199 wxbConfigPanel::~wxbConfigPanel() {
203 void wxbConfigPanel::SetRowString(const char* title, wxString value) {
205 if ((i = FindRow(title)) > -1) {
206 (*config)[i].SetValue(value);
210 wxString wxbConfigPanel::GetRowString(const char* title) {
212 if ((i = FindRow(title)) > -1) {
213 return (*config)[i].GetValue();
218 void wxbConfigPanel::SetRowSelection(const char* title, int ind) {
220 if ((i = FindRow(title)) > -1) {
221 (*config)[i].SetIndex(ind);
225 int wxbConfigPanel::GetRowSelection(const char* title) {
227 if ((i = FindRow(title)) > -1) {
228 return (*config)[i].GetIndex();
233 void wxbConfigPanel::ClearRowChoices(const char* title) {
235 if ((i = FindRow(title)) > -1) {
236 (*config)[i].Clear();
240 void wxbConfigPanel::AddRowChoice(const char* title, wxString value) {
242 if ((i = FindRow(title)) > -1) {
243 (*config)[i].Add(value);
247 int wxbConfigPanel::FindRow(const char* title) {
250 for (i = last; i < config->GetCount(); i++) {
251 if ((*config)[i].GetTitle() == title) {
257 for (i = 0; i < last; i++) {
258 if ((*config)[i].GetTitle() == title) {
268 void wxbConfigPanel::EnableApply(bool enable) {
269 cfgOk->Enable(!enable);
270 if (cfgApply) cfgApply->Enable(enable);