3 * Config panel, used to specify parameters (for example clients, filesets... in restore)
5 * Nicolas Boichat, April 2004
10 Copyright (C) 2004 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "wxbconfigpanel.h"
29 #include <wx/arrimpl.cpp>
31 WX_DEFINE_OBJARRAY(wxbConfig);
33 /* Create a new config parameter */
34 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, wxString value) {
41 this->choicectrl = NULL;
42 this->textctrl = NULL;
43 this->statictext = NULL;
46 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, int n, wxString* values) {
50 this->values = new wxString[n];
51 for (int i = 0; i < n; i++) {
52 this->values[i] = values[i];
55 this->choicectrl = NULL;
56 this->textctrl = NULL;
57 this->statictext = NULL;
60 wxbConfigParam::~wxbConfigParam() {
61 if (values) delete[] values;
62 if (choicectrl) delete choicectrl;
63 if (textctrl) delete textctrl;
64 if (statictext) delete statictext;
67 void wxbConfigParam::AddControl(wxWindow* parent, wxSizer* sizer) {
68 sizer->Add(new wxStaticText(parent, -1, title + ": ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
71 statictext = new wxStaticText(parent, -1, value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
72 sizer->Add(statictext, 1, wxEXPAND | wxADJUST_MINSIZE);
75 textctrl = new wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize);
76 sizer->Add(textctrl, 1, wxEXPAND | wxADJUST_MINSIZE);
79 choicectrl = new wxChoice(parent, id, wxDefaultPosition, wxSize(150, 20), nvalues, values);
80 sizer->Add(choicectrl, 1, wxEXPAND);
85 wxString wxbConfigParam::GetTitle() {
89 wxString wxbConfigParam::GetValue() {
92 return (statictext != NULL) ? statictext->GetLabel() : wxString("");
95 return (textctrl != NULL) ? textctrl->GetValue() : wxString("");
98 return (choicectrl != NULL) ? choicectrl->GetStringSelection() : wxString("");
104 void wxbConfigParam::SetValue(wxString str) {
108 statictext->SetLabel(str);
112 textctrl->SetValue(str);
117 for (k = 0; k < choicectrl->GetCount(); k++) {
118 if (str == choicectrl->GetString(k)) {
119 choicectrl->SetSelection(k);
123 if (k == choicectrl->GetCount()) { // Should never happen
124 choicectrl->Append(str);
125 choicectrl->SetSelection(k);
132 int wxbConfigParam::GetIndex() {
134 return choicectrl->GetSelection();
139 void wxbConfigParam::SetIndex(int ind) {
141 choicectrl->SetSelection(ind);
145 void wxbConfigParam::Clear() {
151 void wxbConfigParam::Add(wxString value) {
153 choicectrl->Append(value);
157 /* Creates a new config panel, config must be allocated with new */
158 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
159 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
161 this->config = config;
163 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
166 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
167 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
169 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
171 for (i = 0; i < config->GetCount(); i++) {
172 (*config)[i].AddControl(this, cfgSizer);
174 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
176 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
178 cfgOk = new wxButton(this, ok, "OK", wxDefaultPosition, wxSize(70, 25));
179 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
182 cfgApply = new wxButton(this, apply, "Apply", wxDefaultPosition, wxSize(70, 25));
183 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
189 cfgCancel = new wxButton(this, cancel, "Cancel", wxDefaultPosition, wxSize(70, 25));
190 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
192 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
195 mainSizer->SetSizeHints(this);
200 wxbConfigPanel::~wxbConfigPanel() {
204 void wxbConfigPanel::SetRowString(const char* title, wxString value) {
206 if ((i = FindRow(title)) > -1) {
207 (*config)[i].SetValue(value);
211 wxString wxbConfigPanel::GetRowString(const char* title) {
213 if ((i = FindRow(title)) > -1) {
214 return (*config)[i].GetValue();
219 void wxbConfigPanel::SetRowSelection(const char* title, int ind) {
221 if ((i = FindRow(title)) > -1) {
222 (*config)[i].SetIndex(ind);
226 int wxbConfigPanel::GetRowSelection(const char* title) {
228 if ((i = FindRow(title)) > -1) {
229 return (*config)[i].GetIndex();
234 void wxbConfigPanel::ClearRowChoices(const char* title) {
236 if ((i = FindRow(title)) > -1) {
237 (*config)[i].Clear();
241 void wxbConfigPanel::AddRowChoice(const char* title, wxString value) {
243 if ((i = FindRow(title)) > -1) {
244 (*config)[i].Add(value);
248 int wxbConfigPanel::FindRow(const char* title) {
251 for (i = last; i < config->GetCount(); i++) {
252 if ((*config)[i].GetTitle() == title) {
258 for (i = 0; i < last; i++) {
259 if ((*config)[i].GetTitle() == title) {
269 void wxbConfigPanel::EnableApply(bool enable) {
270 cfgOk->Enable(!enable);
271 if (cfgApply) cfgApply->Enable(enable);