| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: configitemselector.cpp |
| 3 | // Purpose: Selector for one or more config items |
| 4 | // Author: Julian Smart |
| 5 | // Modified by: |
| 6 | // Created: 2003-06-04 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Julian Smart |
| 9 | // Licence: |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifdef __GNUG__ |
| 13 | #pragma implementation "configitemselector.h" |
| 14 | #endif |
| 15 | |
| 16 | #include <wx/wx.h> |
| 17 | #include <wx/cshelp.h> |
| 18 | #include <wx/statline.h> |
| 19 | #include <wx/splitter.h> |
| 20 | #include <wx/scrolwin.h> |
| 21 | #include <wx/spinctrl.h> |
| 22 | #include <wx/spinbutt.h> |
| 23 | #include <wx/valgen.h> |
| 24 | |
| 25 | #include "configitemselector.h" |
| 26 | #include "configtooldoc.h" |
| 27 | #include "configtoolview.h" |
| 28 | #include "configitem.h" |
| 29 | #include "mainframe.h" |
| 30 | #include "wxconfigtool.h" |
| 31 | |
| 32 | ////@begin XPM images |
| 33 | ////@end XPM images |
| 34 | |
| 35 | /*! |
| 36 | * ctConfigItemsSelector type definition |
| 37 | */ |
| 38 | |
| 39 | IMPLEMENT_CLASS( ctConfigItemsSelector, wxDialog ) |
| 40 | |
| 41 | /*! |
| 42 | * ctConfigItemsSelector event table definition |
| 43 | */ |
| 44 | |
| 45 | BEGIN_EVENT_TABLE( ctConfigItemsSelector, wxDialog ) |
| 46 | |
| 47 | ////@begin ctConfigItemsSelector event table entries |
| 48 | EVT_BUTTON( ID_CONFIG_ADD, ctConfigItemsSelector::OnConfigAdd ) |
| 49 | EVT_UPDATE_UI( ID_CONFIG_ADD, ctConfigItemsSelector::OnUpdateConfigAdd ) |
| 50 | |
| 51 | EVT_BUTTON( ID_CONFIG_REMOVE, ctConfigItemsSelector::OnConfigRemove ) |
| 52 | EVT_UPDATE_UI( ID_CONFIG_REMOVE, ctConfigItemsSelector::OnUpdateConfigRemove ) |
| 53 | |
| 54 | EVT_BUTTON( wxID_OK, ctConfigItemsSelector::OnOk ) |
| 55 | |
| 56 | ////@end ctConfigItemsSelector event table entries |
| 57 | |
| 58 | END_EVENT_TABLE() |
| 59 | |
| 60 | /*! |
| 61 | * ctConfigItemsSelector constructor |
| 62 | */ |
| 63 | |
| 64 | ctConfigItemsSelector::ctConfigItemsSelector( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) |
| 65 | { |
| 66 | wxDialog::Create( parent, id, caption, pos, size, style ); |
| 67 | |
| 68 | CreateControls(); |
| 69 | InitSourceConfigList(); |
| 70 | } |
| 71 | |
| 72 | /*! |
| 73 | * Control creation for ctConfigItemsSelector |
| 74 | */ |
| 75 | |
| 76 | void ctConfigItemsSelector::CreateControls() |
| 77 | { |
| 78 | ////@begin ctConfigItemsSelector content construction |
| 79 | |
| 80 | ctConfigItemsSelector* item1 = this; |
| 81 | |
| 82 | wxBoxSizer* item2 = new wxBoxSizer(wxVERTICAL); |
| 83 | item1->SetSizer(item2); |
| 84 | item1->SetAutoLayout(TRUE); |
| 85 | |
| 86 | wxBoxSizer* item3 = new wxBoxSizer(wxVERTICAL); |
| 87 | item2->Add(item3, 1, wxGROW|wxALL, 5); |
| 88 | |
| 89 | wxStaticText* item4 = new wxStaticText(item1, wxID_STATIC, _("Please edit the list of configuration items by selecting from the\nlist below."), wxDefaultPosition, wxDefaultSize, 0); |
| 90 | item3->Add(item4, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); |
| 91 | |
| 92 | wxStaticText* item5 = new wxStaticText(item1, wxID_STATIC, _("&Available items:"), wxDefaultPosition, wxDefaultSize, 0); |
| 93 | item3->Add(item5, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); |
| 94 | |
| 95 | wxString* item6Strings = NULL; |
| 96 | wxListBox* item6 = new wxListBox(item1, ID_AVAILABLE_CONFIG_ITEMS, wxDefaultPosition, wxSize(-1, 150), 0, item6Strings, wxLB_SINGLE|wxLB_SORT); |
| 97 | item3->Add(item6, 1, wxGROW|wxALL, 5); |
| 98 | |
| 99 | wxStaticText* item7 = new wxStaticText(item1, wxID_STATIC, _("&List of configuration items:"), wxDefaultPosition, wxDefaultSize, 0); |
| 100 | item3->Add(item7, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); |
| 101 | |
| 102 | wxBoxSizer* item8 = new wxBoxSizer(wxHORIZONTAL); |
| 103 | item3->Add(item8, 0, wxGROW, 5); |
| 104 | |
| 105 | wxString* item9Strings = NULL; |
| 106 | wxListBox* item9 = new wxListBox(item1, ID_CONFIG_ITEMS, wxDefaultPosition, wxSize(-1, 100), 0, item9Strings, wxLB_SINGLE); |
| 107 | item8->Add(item9, 1, wxGROW|wxALL, 5); |
| 108 | |
| 109 | wxBoxSizer* item10 = new wxBoxSizer(wxVERTICAL); |
| 110 | item8->Add(item10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
| 111 | |
| 112 | wxButton* item11 = new wxButton(item1, ID_CONFIG_ADD, _("A&dd"), wxDefaultPosition, wxDefaultSize, 0); |
| 113 | item10->Add(item11, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); |
| 114 | |
| 115 | wxButton* item12 = new wxButton(item1, ID_CONFIG_REMOVE, _("&Remove"), wxDefaultPosition, wxDefaultSize, 0); |
| 116 | item10->Add(item12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); |
| 117 | |
| 118 | wxBoxSizer* item13 = new wxBoxSizer(wxHORIZONTAL); |
| 119 | item3->Add(item13, 0, wxGROW, 5); |
| 120 | |
| 121 | item13->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
| 122 | |
| 123 | wxButton* item15 = new wxButton(item1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0); |
| 124 | item15->SetDefault(); |
| 125 | item13->Add(item15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
| 126 | |
| 127 | wxButton* item16 = new wxButton(item1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0); |
| 128 | item13->Add(item16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
| 129 | |
| 130 | GetSizer()->Fit(this); |
| 131 | GetSizer()->SetSizeHints(this); |
| 132 | Centre(); |
| 133 | ////@end ctConfigItemsSelector content construction |
| 134 | } |
| 135 | |
| 136 | /*! |
| 137 | * Event handler for ID_CONFIG_ADD |
| 138 | */ |
| 139 | |
| 140 | void ctConfigItemsSelector::OnConfigAdd( wxCommandEvent& WXUNUSED(event) ) |
| 141 | { |
| 142 | wxListBox* masterList = wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS), wxListBox); |
| 143 | wxListBox* listBox = wxDynamicCast(FindWindow(ID_CONFIG_ITEMS), wxListBox); |
| 144 | if (masterList) |
| 145 | { |
| 146 | if (masterList->GetSelection() > -1) |
| 147 | { |
| 148 | wxString str = masterList->GetStringSelection(); |
| 149 | if (m_configItems.Index(str) == wxNOT_FOUND) |
| 150 | { |
| 151 | listBox->Append(str); |
| 152 | m_configItems.Add(str); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /*! |
| 159 | * Event handler for ID_CONFIG_REMOVE |
| 160 | */ |
| 161 | |
| 162 | void ctConfigItemsSelector::OnConfigRemove( wxCommandEvent& WXUNUSED(event) ) |
| 163 | { |
| 164 | wxListBox* listBox = wxDynamicCast(FindWindow(ID_CONFIG_ITEMS), wxListBox); |
| 165 | if (listBox) |
| 166 | { |
| 167 | if (listBox->GetSelection() > -1) |
| 168 | { |
| 169 | wxString str = listBox->GetStringSelection(); |
| 170 | listBox->Delete(listBox->GetSelection()); |
| 171 | m_configItems.Remove(str); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /*! |
| 177 | * Event handler for wxID_OK |
| 178 | */ |
| 179 | |
| 180 | void ctConfigItemsSelector::OnOk( wxCommandEvent& event ) |
| 181 | { |
| 182 | // Replace with custom code |
| 183 | event.Skip(); |
| 184 | } |
| 185 | |
| 186 | /*! |
| 187 | * Should we show tooltips? |
| 188 | */ |
| 189 | |
| 190 | bool ctConfigItemsSelector::ShowToolTips() |
| 191 | { |
| 192 | return TRUE; |
| 193 | } |
| 194 | /*! |
| 195 | * Update event handler for ID_CONFIG_ADD |
| 196 | */ |
| 197 | |
| 198 | void ctConfigItemsSelector::OnUpdateConfigAdd( wxUpdateUIEvent& event ) |
| 199 | { |
| 200 | wxListBox* masterList = wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS), wxListBox); |
| 201 | event.Enable(masterList && masterList->GetSelection() != -1); |
| 202 | } |
| 203 | |
| 204 | /*! |
| 205 | * Update event handler for ID_CONFIG_REMOVE |
| 206 | */ |
| 207 | |
| 208 | void ctConfigItemsSelector::OnUpdateConfigRemove( wxUpdateUIEvent& event ) |
| 209 | { |
| 210 | wxListBox* listBox = wxDynamicCast(FindWindow(ID_CONFIG_ITEMS), wxListBox); |
| 211 | event.Enable(listBox && listBox->GetSelection() != -1); |
| 212 | } |
| 213 | |
| 214 | /// Initialise the master list |
| 215 | void ctConfigItemsSelector::InitSourceConfigList(ctConfigItem* item) |
| 216 | { |
| 217 | wxListBox* masterList = wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS), wxListBox); |
| 218 | if (!item) |
| 219 | item = wxGetApp().GetMainFrame()->GetDocument()->GetTopItem(); |
| 220 | |
| 221 | if (!item) |
| 222 | return; |
| 223 | |
| 224 | bool addIt = FALSE; |
| 225 | |
| 226 | if (item->GetType() == ctTypeGroup) |
| 227 | addIt = FALSE; |
| 228 | else if (item->GetType() == ctTypeCheckGroup) |
| 229 | addIt = TRUE; |
| 230 | else if (item->GetType() == ctTypeRadioGroup) |
| 231 | addIt = TRUE; |
| 232 | else if (item->GetType() == ctTypeString) |
| 233 | addIt = TRUE; |
| 234 | else if (item->GetType() == ctTypeBoolCheck) |
| 235 | addIt = TRUE; |
| 236 | else if (item->GetType() == ctTypeBoolRadio) |
| 237 | addIt = TRUE; |
| 238 | else if (item->GetType() == ctTypeInteger) |
| 239 | addIt = TRUE; |
| 240 | if (addIt) |
| 241 | { |
| 242 | masterList->Append(item->GetName()); |
| 243 | } |
| 244 | |
| 245 | wxNode* node = item->GetChildren().GetFirst(); |
| 246 | while (node) |
| 247 | { |
| 248 | ctConfigItem* child = (ctConfigItem*) node->GetData(); |
| 249 | InitSourceConfigList(child); |
| 250 | |
| 251 | node = node->Next(); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /// Set the initial list |
| 256 | void ctConfigItemsSelector::SetConfigList(const wxArrayString& items) |
| 257 | { |
| 258 | m_configItems = items; |
| 259 | wxListBox* listBox = wxDynamicCast(FindWindow(ID_CONFIG_ITEMS), wxListBox); |
| 260 | listBox->Clear(); |
| 261 | |
| 262 | size_t i; |
| 263 | for (i = 0; i < items.GetCount(); i++) |
| 264 | listBox->Append(items[i]); |
| 265 | } |
| 266 | |