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.
26 #include "wxbconfigpanel.h"
28 #include <wx/arrimpl.cpp>
30 WX_DEFINE_OBJARRAY(wxbConfig);
32 /* Create a new config parameter */
33 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, wxString value) {
40 this->choicectrl = NULL;
41 this->textctrl = NULL;
42 this->statictext = NULL;
45 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, int n, wxString* values) {
49 this->values = new wxString[n];
50 for (int i = 0; i < n; i++) {
51 this->values[i] = values[i];
54 this->choicectrl = NULL;
55 this->textctrl = NULL;
56 this->statictext = NULL;
59 wxbConfigParam::~wxbConfigParam() {
60 if (values) delete[] values;
61 if (choicectrl) delete choicectrl;
62 if (textctrl) delete textctrl;
63 if (statictext) delete statictext;
66 void wxbConfigParam::AddControl(wxWindow* parent, wxSizer* sizer) {
67 sizer->Add(new wxStaticText(parent, -1, title + wxT(": "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 0, wxALIGN_CENTER_VERTICAL);
70 statictext = new wxStaticText(parent, -1, value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
71 sizer->Add(statictext, 1, wxEXPAND | wxADJUST_MINSIZE);
74 textctrl = new wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize);
75 sizer->Add(textctrl, 1, wxEXPAND | wxADJUST_MINSIZE);
78 #if defined __WXGTK20__ /* Choices are taller under GTK+-2.0 */
79 wxSize size = wxSize(150, 25);
81 wxSize size = wxSize(150, 20);
83 choicectrl = new wxChoice(parent, id, wxDefaultPosition, size, nvalues, values);
84 sizer->Add(choicectrl, 1, wxEXPAND);
89 wxString wxbConfigParam::GetTitle() {
93 wxString wxbConfigParam::GetValue() {
96 return (statictext != NULL) ? statictext->GetLabel() : wxString(wxT(""));
99 return (textctrl != NULL) ? textctrl->GetValue() : wxString(wxT(""));
102 return (choicectrl != NULL) ? choicectrl->GetStringSelection() : wxString(wxT(""));
108 void wxbConfigParam::SetValue(wxString str) {
112 statictext->SetLabel(str);
116 textctrl->SetValue(str);
121 for (k = 0; k < choicectrl->GetCount(); k++) {
122 if (str == choicectrl->GetString(k)) {
123 choicectrl->SetSelection(k);
127 if (k == choicectrl->GetCount()) { // Should never happen
128 choicectrl->Append(str);
129 choicectrl->SetSelection(k);
136 int wxbConfigParam::GetIndex() {
138 return choicectrl->GetSelection();
143 void wxbConfigParam::SetIndex(int ind) {
145 choicectrl->SetSelection(ind);
149 void wxbConfigParam::Clear() {
155 void wxbConfigParam::Add(wxString value) {
157 choicectrl->Append(value);
161 /* Creates a new config panel, config must be allocated with new */
162 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
163 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
165 this->config = config;
167 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
170 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
171 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
173 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
175 for (i = 0; i < config->GetCount(); i++) {
176 (*config)[i].AddControl(this, cfgSizer);
178 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
180 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
182 cfgOk = new wxButton(this, ok, _("OK"), wxDefaultPosition, wxSize(70, 25));
183 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
186 cfgApply = new wxButton(this, apply, _("Apply"), wxDefaultPosition, wxSize(70, 25));
187 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
193 cfgCancel = new wxButton(this, cancel, _("Cancel"), wxDefaultPosition, wxSize(70, 25));
194 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
196 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
199 mainSizer->SetSizeHints(this);
204 wxbConfigPanel::~wxbConfigPanel() {
208 void wxbConfigPanel::SetRowString(const wxChar* title, wxString value) {
210 if ((i = FindRow(title)) > -1) {
211 (*config)[i].SetValue(value);
215 wxString wxbConfigPanel::GetRowString(const wxChar* title) {
217 if ((i = FindRow(title)) > -1) {
218 return (*config)[i].GetValue();
223 void wxbConfigPanel::SetRowSelection(const wxChar* title, int ind) {
225 if ((i = FindRow(title)) > -1) {
226 (*config)[i].SetIndex(ind);
230 int wxbConfigPanel::GetRowSelection(const wxChar* title) {
232 if ((i = FindRow(title)) > -1) {
233 return (*config)[i].GetIndex();
238 void wxbConfigPanel::ClearRowChoices(const wxChar* title) {
240 if ((i = FindRow(title)) > -1) {
241 (*config)[i].Clear();
245 void wxbConfigPanel::AddRowChoice(const wxChar* title, wxString value) {
247 if ((i = FindRow(title)) > -1) {
248 (*config)[i].Add(value);
252 int wxbConfigPanel::FindRow(const wxChar* title) {
255 for (i = last; i < config->GetCount(); i++) {
256 if ((*config)[i].GetTitle() == title) {
262 for (i = 0; i < last; i++) {
263 if ((*config)[i].GetTitle() == title) {
273 void wxbConfigPanel::EnableApply(bool enable) {
274 cfgOk->Enable(!enable);
275 if (cfgApply) cfgApply->Enable(enable);