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.
24 /* Windows debug builds set _DEBUG which is used by wxWidgets to select their
25 * debug memory allocator. Unfortunately it conflicts with Bacula's SmartAlloc.
26 * So we turn _DEBUG off since we aren't interested in things it enables.
32 #include "wxbconfigpanel.h"
33 #include <wx/arrimpl.cpp>
36 WX_DEFINE_OBJARRAY(wxbConfig);
38 /* Create a new config parameter */
39 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, wxString value) {
46 this->choicectrl = NULL;
47 this->textctrl = NULL;
48 this->statictext = NULL;
51 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, int n, wxString* values) {
55 this->values = new wxString[n];
56 for (int i = 0; i < n; i++) {
57 this->values[i] = values[i];
60 this->choicectrl = NULL;
61 this->textctrl = NULL;
62 this->statictext = NULL;
65 wxbConfigParam::~wxbConfigParam() {
66 if (values) delete[] values;
67 if (choicectrl) delete choicectrl;
68 if (textctrl) delete textctrl;
69 if (statictext) delete statictext;
72 void wxbConfigParam::AddControl(wxWindow* parent, wxSizer* sizer) {
73 sizer->Add(new wxStaticText(parent, -1, title + wxT(": "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 0, wxALIGN_CENTER_VERTICAL);
76 statictext = new wxStaticText(parent, -1, value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
77 sizer->Add(statictext, 1, wxEXPAND | wxADJUST_MINSIZE);
80 textctrl = new wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize);
81 sizer->Add(textctrl, 1, wxEXPAND | wxADJUST_MINSIZE);
84 #if defined __WXGTK20__ /* Choices are taller under GTK+-2.0 */
85 wxSize size = wxSize(150, 25);
87 wxSize size = wxSize(150, 20);
89 choicectrl = new wxChoice(parent, id, wxDefaultPosition, size, nvalues, values);
90 sizer->Add(choicectrl, 1, wxEXPAND);
95 wxString wxbConfigParam::GetTitle() {
99 wxString wxbConfigParam::GetValue() {
102 return (statictext != NULL) ? statictext->GetLabel() : wxString(wxT(""));
105 return (textctrl != NULL) ? textctrl->GetValue() : wxString(wxT(""));
108 return (choicectrl != NULL) ? choicectrl->GetStringSelection() : wxString(wxT(""));
114 void wxbConfigParam::SetValue(wxString str) {
118 statictext->SetLabel(str);
122 textctrl->SetValue(str);
127 for (k = 0; k < choicectrl->GetCount(); k++) {
128 if (str == choicectrl->GetString(k)) {
129 choicectrl->SetSelection(k);
133 if (k == choicectrl->GetCount()) { // Should never happen
134 choicectrl->Append(str);
135 choicectrl->SetSelection(k);
142 int wxbConfigParam::GetIndex() {
144 return choicectrl->GetSelection();
149 void wxbConfigParam::SetIndex(int ind) {
151 choicectrl->SetSelection(ind);
155 void wxbConfigParam::Clear() {
161 void wxbConfigParam::Add(wxString value) {
163 choicectrl->Append(value);
167 /* Creates a new config panel, config must be allocated with new */
168 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
169 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
171 this->config = config;
173 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
176 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
177 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
179 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
181 for (i = 0; i < config->GetCount(); i++) {
182 (*config)[i].AddControl(this, cfgSizer);
184 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
186 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
188 cfgOk = new wxButton(this, ok, _("OK"), wxDefaultPosition, wxSize(70, 25));
189 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
192 cfgApply = new wxButton(this, apply, _("Apply"), wxDefaultPosition, wxSize(70, 25));
193 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
199 cfgCancel = new wxButton(this, cancel, _("Cancel"), wxDefaultPosition, wxSize(70, 25));
200 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
202 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
205 mainSizer->SetSizeHints(this);
210 wxbConfigPanel::~wxbConfigPanel() {
214 void wxbConfigPanel::SetRowString(const wxChar* title, wxString value) {
216 if ((i = FindRow(title)) > -1) {
217 (*config)[i].SetValue(value);
221 wxString wxbConfigPanel::GetRowString(const wxChar* title) {
223 if ((i = FindRow(title)) > -1) {
224 return (*config)[i].GetValue();
229 void wxbConfigPanel::SetRowSelection(const wxChar* title, int ind) {
231 if ((i = FindRow(title)) > -1) {
232 (*config)[i].SetIndex(ind);
236 int wxbConfigPanel::GetRowSelection(const wxChar* title) {
238 if ((i = FindRow(title)) > -1) {
239 return (*config)[i].GetIndex();
244 void wxbConfigPanel::ClearRowChoices(const wxChar* title) {
246 if ((i = FindRow(title)) > -1) {
247 (*config)[i].Clear();
251 void wxbConfigPanel::AddRowChoice(const wxChar* title, wxString value) {
253 if ((i = FindRow(title)) > -1) {
254 (*config)[i].Add(value);
258 int wxbConfigPanel::FindRow(const wxChar* title) {
261 for (i = last; i < config->GetCount(); i++) {
262 if ((*config)[i].GetTitle() == title) {
268 for (i = 0; i < last; i++) {
269 if ((*config)[i].GetTitle() == title) {
279 void wxbConfigPanel::EnableApply(bool enable) {
280 cfgOk->Enable(!enable);
281 if (cfgApply) cfgApply->Enable(enable);