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