3 * Config panel, used to specify parameters (for example clients, filesets... in restore)
5 * Nicolas Boichat, April 2004
10 Copyright (C) 2004-2006 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.
25 #include "wxbconfigpanel.h"
26 #include <wx/arrimpl.cpp>
29 WX_DEFINE_OBJARRAY(wxbConfig);
31 /* Create a new config parameter */
32 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, wxString value) {
39 this->choicectrl = NULL;
40 this->textctrl = NULL;
41 this->statictext = NULL;
44 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, int n, wxString* values) {
48 this->values = new wxString[n];
49 for (int i = 0; i < n; i++) {
50 this->values[i] = values[i];
53 this->choicectrl = NULL;
54 this->textctrl = NULL;
55 this->statictext = NULL;
58 wxbConfigParam::~wxbConfigParam() {
59 if (values) delete[] values;
60 if (choicectrl) delete choicectrl;
61 if (textctrl) delete textctrl;
62 if (statictext) delete statictext;
65 void wxbConfigParam::AddControl(wxWindow* parent, wxSizer* sizer) {
66 sizer->Add(new wxStaticText(parent, -1, title + wxT(": "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 0, wxALIGN_CENTER_VERTICAL);
69 statictext = new wxStaticText(parent, -1, value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
70 sizer->Add(statictext, 1, wxEXPAND | wxADJUST_MINSIZE);
73 textctrl = new wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize);
74 sizer->Add(textctrl, 1, wxEXPAND | wxADJUST_MINSIZE);
77 #if defined __WXGTK20__ /* Choices are taller under GTK+-2.0 */
78 wxSize size = wxSize(150, 25);
80 wxSize size = wxSize(150, 20);
82 choicectrl = new wxChoice(parent, id, wxDefaultPosition, size, nvalues, values);
83 sizer->Add(choicectrl, 1, wxEXPAND);
88 wxString wxbConfigParam::GetTitle() {
92 wxString wxbConfigParam::GetValue() {
95 return (statictext != NULL) ? statictext->GetLabel() : wxString(wxT(""));
98 return (textctrl != NULL) ? textctrl->GetValue() : wxString(wxT(""));
101 return (choicectrl != NULL) ? choicectrl->GetStringSelection() : wxString(wxT(""));
107 void wxbConfigParam::SetValue(wxString str) {
111 statictext->SetLabel(str);
115 textctrl->SetValue(str);
120 for (k = 0; k < choicectrl->GetCount(); k++) {
121 if (str == choicectrl->GetString(k)) {
122 choicectrl->SetSelection(k);
126 if (k == choicectrl->GetCount()) { // Should never happen
127 choicectrl->Append(str);
128 choicectrl->SetSelection(k);
135 int wxbConfigParam::GetIndex() {
137 return choicectrl->GetSelection();
142 void wxbConfigParam::SetIndex(int ind) {
144 choicectrl->SetSelection(ind);
148 void wxbConfigParam::Clear() {
154 void wxbConfigParam::Add(wxString value) {
156 choicectrl->Append(value);
160 /* Creates a new config panel, config must be allocated with new */
161 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
162 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
164 this->config = config;
166 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
169 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
170 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
172 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
174 for (i = 0; i < config->GetCount(); i++) {
175 (*config)[i].AddControl(this, cfgSizer);
177 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
179 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
181 cfgOk = new wxButton(this, ok, _("OK"), wxDefaultPosition, wxSize(70, 25));
182 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
185 cfgApply = new wxButton(this, apply, _("Apply"), wxDefaultPosition, wxSize(70, 25));
186 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
192 cfgCancel = new wxButton(this, cancel, _("Cancel"), wxDefaultPosition, wxSize(70, 25));
193 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
195 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
198 mainSizer->SetSizeHints(this);
203 wxbConfigPanel::~wxbConfigPanel() {
207 void wxbConfigPanel::SetRowString(const wxChar* title, wxString value) {
209 if ((i = FindRow(title)) > -1) {
210 (*config)[i].SetValue(value);
214 wxString wxbConfigPanel::GetRowString(const wxChar* title) {
216 if ((i = FindRow(title)) > -1) {
217 return (*config)[i].GetValue();
222 void wxbConfigPanel::SetRowSelection(const wxChar* title, int ind) {
224 if ((i = FindRow(title)) > -1) {
225 (*config)[i].SetIndex(ind);
229 int wxbConfigPanel::GetRowSelection(const wxChar* title) {
231 if ((i = FindRow(title)) > -1) {
232 return (*config)[i].GetIndex();
237 void wxbConfigPanel::ClearRowChoices(const wxChar* title) {
239 if ((i = FindRow(title)) > -1) {
240 (*config)[i].Clear();
244 void wxbConfigPanel::AddRowChoice(const wxChar* title, wxString value) {
246 if ((i = FindRow(title)) > -1) {
247 (*config)[i].Add(value);
251 int wxbConfigPanel::FindRow(const wxChar* title) {
254 for (i = last; i < config->GetCount(); i++) {
255 if ((*config)[i].GetTitle() == title) {
261 for (i = 0; i < last; i++) {
262 if ((*config)[i].GetTitle() == title) {
272 void wxbConfigPanel::EnableApply(bool enable) {
273 cfgOk->Enable(!enable);
274 if (cfgApply) cfgApply->Enable(enable);