3 * Config panel, used to specify parameters (for example clients, filesets... in restore)
5 * Nicolas Boichat, April 2004
10 Copyright (C) 2004-2005 Kern Sibbald
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 version 2 as amended with additional clauses defined in the
15 file LICENSE in the main source directory.
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 the file LICENSE for additional details.
24 #include "wxbconfigpanel.h"
26 #include <wx/arrimpl.cpp>
28 WX_DEFINE_OBJARRAY(wxbConfig);
30 /* Create a new config parameter */
31 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, wxString value) {
38 this->choicectrl = NULL;
39 this->textctrl = NULL;
40 this->statictext = NULL;
43 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, int n, wxString* values) {
47 this->values = new wxString[n];
48 for (int i = 0; i < n; i++) {
49 this->values[i] = values[i];
52 this->choicectrl = NULL;
53 this->textctrl = NULL;
54 this->statictext = NULL;
57 wxbConfigParam::~wxbConfigParam() {
58 if (values) delete[] values;
59 if (choicectrl) delete choicectrl;
60 if (textctrl) delete textctrl;
61 if (statictext) delete statictext;
64 void wxbConfigParam::AddControl(wxWindow* parent, wxSizer* sizer) {
65 sizer->Add(new wxStaticText(parent, -1, title + wxT(": "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 0, wxALIGN_CENTER_VERTICAL);
68 statictext = new wxStaticText(parent, -1, value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
69 sizer->Add(statictext, 1, wxEXPAND | wxADJUST_MINSIZE);
72 textctrl = new wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize);
73 sizer->Add(textctrl, 1, wxEXPAND | wxADJUST_MINSIZE);
76 #if defined __WXGTK20__ /* Choices are taller under GTK+-2.0 */
77 wxSize size = wxSize(150, 25);
79 wxSize size = wxSize(150, 20);
81 choicectrl = new wxChoice(parent, id, wxDefaultPosition, size, nvalues, values);
82 sizer->Add(choicectrl, 1, wxEXPAND);
87 wxString wxbConfigParam::GetTitle() {
91 wxString wxbConfigParam::GetValue() {
94 return (statictext != NULL) ? statictext->GetLabel() : wxString(wxT(""));
97 return (textctrl != NULL) ? textctrl->GetValue() : wxString(wxT(""));
100 return (choicectrl != NULL) ? choicectrl->GetStringSelection() : wxString(wxT(""));
106 void wxbConfigParam::SetValue(wxString str) {
110 statictext->SetLabel(str);
114 textctrl->SetValue(str);
119 for (k = 0; k < choicectrl->GetCount(); k++) {
120 if (str == choicectrl->GetString(k)) {
121 choicectrl->SetSelection(k);
125 if (k == choicectrl->GetCount()) { // Should never happen
126 choicectrl->Append(str);
127 choicectrl->SetSelection(k);
134 int wxbConfigParam::GetIndex() {
136 return choicectrl->GetSelection();
141 void wxbConfigParam::SetIndex(int ind) {
143 choicectrl->SetSelection(ind);
147 void wxbConfigParam::Clear() {
153 void wxbConfigParam::Add(wxString value) {
155 choicectrl->Append(value);
159 /* Creates a new config panel, config must be allocated with new */
160 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
161 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
163 this->config = config;
165 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
168 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
169 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
171 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
173 for (i = 0; i < config->GetCount(); i++) {
174 (*config)[i].AddControl(this, cfgSizer);
176 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
178 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
180 cfgOk = new wxButton(this, ok, wxT("OK"), wxDefaultPosition, wxSize(70, 25));
181 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
184 cfgApply = new wxButton(this, apply, wxT("Apply"), wxDefaultPosition, wxSize(70, 25));
185 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
191 cfgCancel = new wxButton(this, cancel, wxT("Cancel"), wxDefaultPosition, wxSize(70, 25));
192 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
194 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
197 mainSizer->SetSizeHints(this);
202 wxbConfigPanel::~wxbConfigPanel() {
206 void wxbConfigPanel::SetRowString(const wxChar* title, wxString value) {
208 if ((i = FindRow(title)) > -1) {
209 (*config)[i].SetValue(value);
213 wxString wxbConfigPanel::GetRowString(const wxChar* title) {
215 if ((i = FindRow(title)) > -1) {
216 return (*config)[i].GetValue();
221 void wxbConfigPanel::SetRowSelection(const wxChar* title, int ind) {
223 if ((i = FindRow(title)) > -1) {
224 (*config)[i].SetIndex(ind);
228 int wxbConfigPanel::GetRowSelection(const wxChar* title) {
230 if ((i = FindRow(title)) > -1) {
231 return (*config)[i].GetIndex();
236 void wxbConfigPanel::ClearRowChoices(const wxChar* title) {
238 if ((i = FindRow(title)) > -1) {
239 (*config)[i].Clear();
243 void wxbConfigPanel::AddRowChoice(const wxChar* title, wxString value) {
245 if ((i = FindRow(title)) > -1) {
246 (*config)[i].Add(value);
250 int wxbConfigPanel::FindRow(const wxChar* title) {
253 for (i = last; i < config->GetCount(); i++) {
254 if ((*config)[i].GetTitle() == title) {
260 for (i = 0; i < last; i++) {
261 if ((*config)[i].GetTitle() == title) {
271 void wxbConfigPanel::EnableApply(bool enable) {
272 cfgOk->Enable(!enable);
273 if (cfgApply) cfgApply->Enable(enable);