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 + wxT(": "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 0, wxALIGN_CENTER_VERTICAL);
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 #if defined __WXGTK20__ /* Choices are taller under GTK+-2.0 */
80 wxSize size = wxSize(150, 25);
82 wxSize size = wxSize(150, 20);
84 choicectrl = new wxChoice(parent, id, wxDefaultPosition, size, nvalues, values);
85 sizer->Add(choicectrl, 1, wxEXPAND);
90 wxString wxbConfigParam::GetTitle() {
94 wxString wxbConfigParam::GetValue() {
97 return (statictext != NULL) ? statictext->GetLabel() : wxString(wxT(""));
100 return (textctrl != NULL) ? textctrl->GetValue() : wxString(wxT(""));
103 return (choicectrl != NULL) ? choicectrl->GetStringSelection() : wxString(wxT(""));
109 void wxbConfigParam::SetValue(wxString str) {
113 statictext->SetLabel(str);
117 textctrl->SetValue(str);
122 for (k = 0; k < choicectrl->GetCount(); k++) {
123 if (str == choicectrl->GetString(k)) {
124 choicectrl->SetSelection(k);
128 if (k == choicectrl->GetCount()) { // Should never happen
129 choicectrl->Append(str);
130 choicectrl->SetSelection(k);
137 int wxbConfigParam::GetIndex() {
139 return choicectrl->GetSelection();
144 void wxbConfigParam::SetIndex(int ind) {
146 choicectrl->SetSelection(ind);
150 void wxbConfigParam::Clear() {
156 void wxbConfigParam::Add(wxString value) {
158 choicectrl->Append(value);
162 /* Creates a new config panel, config must be allocated with new */
163 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
164 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
166 this->config = config;
168 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
171 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
172 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
174 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
176 for (i = 0; i < config->GetCount(); i++) {
177 (*config)[i].AddControl(this, cfgSizer);
179 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
181 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
183 cfgOk = new wxButton(this, ok, wxT("OK"), wxDefaultPosition, wxSize(70, 25));
184 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
187 cfgApply = new wxButton(this, apply, wxT("Apply"), wxDefaultPosition, wxSize(70, 25));
188 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
194 cfgCancel = new wxButton(this, cancel, wxT("Cancel"), wxDefaultPosition, wxSize(70, 25));
195 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
197 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
200 mainSizer->SetSizeHints(this);
205 wxbConfigPanel::~wxbConfigPanel() {
209 void wxbConfigPanel::SetRowString(const wxChar* title, wxString value) {
211 if ((i = FindRow(title)) > -1) {
212 (*config)[i].SetValue(value);
216 wxString wxbConfigPanel::GetRowString(const wxChar* title) {
218 if ((i = FindRow(title)) > -1) {
219 return (*config)[i].GetValue();
224 void wxbConfigPanel::SetRowSelection(const wxChar* title, int ind) {
226 if ((i = FindRow(title)) > -1) {
227 (*config)[i].SetIndex(ind);
231 int wxbConfigPanel::GetRowSelection(const wxChar* title) {
233 if ((i = FindRow(title)) > -1) {
234 return (*config)[i].GetIndex();
239 void wxbConfigPanel::ClearRowChoices(const wxChar* title) {
241 if ((i = FindRow(title)) > -1) {
242 (*config)[i].Clear();
246 void wxbConfigPanel::AddRowChoice(const wxChar* title, wxString value) {
248 if ((i = FindRow(title)) > -1) {
249 (*config)[i].Add(value);
253 int wxbConfigPanel::FindRow(const wxChar* title) {
256 for (i = last; i < config->GetCount(); i++) {
257 if ((*config)[i].GetTitle() == title) {
263 for (i = 0; i < last; i++) {
264 if ((*config)[i].GetTitle() == title) {
274 void wxbConfigPanel::EnableApply(bool enable) {
275 cfgOk->Enable(!enable);
276 if (cfgApply) cfgApply->Enable(enable);