1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configitemselector.cpp
3 // Purpose: Selector for one or more config items
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "configitemselector.h"
16 #include "wx/wxprec.h"
26 #include <wx/cshelp.h>
27 #include <wx/statline.h>
28 #include <wx/splitter.h>
29 #include <wx/scrolwin.h>
30 #include <wx/spinctrl.h>
31 #include <wx/spinbutt.h>
32 #include <wx/valgen.h>
33 #include <wx/notebook.h>
35 #include "configitemselector.h"
36 #include "configtooldoc.h"
37 #include "configtoolview.h"
38 #include "configitem.h"
39 #include "mainframe.h"
40 #include "wxconfigtool.h"
46 * ctConfigItemsSelector type definition
49 IMPLEMENT_CLASS( ctConfigItemsSelector
, wxDialog
)
52 * ctConfigItemsSelector event table definition
55 BEGIN_EVENT_TABLE( ctConfigItemsSelector
, wxDialog
)
57 ////@begin ctConfigItemsSelector event table entries
58 EVT_BUTTON( ID_CONFIG_ADD
, ctConfigItemsSelector::OnConfigAdd
)
59 EVT_UPDATE_UI( ID_CONFIG_ADD
, ctConfigItemsSelector::OnUpdateConfigAdd
)
61 EVT_BUTTON( ID_CONFIG_REMOVE
, ctConfigItemsSelector::OnConfigRemove
)
62 EVT_UPDATE_UI( ID_CONFIG_REMOVE
, ctConfigItemsSelector::OnUpdateConfigRemove
)
64 EVT_BUTTON( wxID_OK
, ctConfigItemsSelector::OnOk
)
66 ////@end ctConfigItemsSelector event table entries
71 * ctConfigItemsSelector constructor
74 ctConfigItemsSelector::ctConfigItemsSelector( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
76 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
79 InitSourceConfigList();
83 * Control creation for ctConfigItemsSelector
86 void ctConfigItemsSelector::CreateControls()
88 ////@begin ctConfigItemsSelector content construction
90 ctConfigItemsSelector
* item1
= this;
92 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
93 item1
->SetSizer(item2
);
95 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
96 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
98 wxStaticText
* item4
= new wxStaticText(item1
, wxID_STATIC
, _("Please edit the list of configuration items by selecting from the\nlist below."), wxDefaultPosition
, wxDefaultSize
, 0);
99 item3
->Add(item4
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
101 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Available items:"), wxDefaultPosition
, wxDefaultSize
, 0);
102 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
104 wxString
* item6Strings
= NULL
;
105 wxListBox
* item6
= new wxListBox(item1
, ID_AVAILABLE_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultSize
.x
, 150), 0, item6Strings
, wxLB_SINGLE
|wxLB_SORT
);
106 item3
->Add(item6
, 1, wxGROW
|wxALL
, 5);
108 wxStaticText
* item7
= new wxStaticText(item1
, wxID_STATIC
, _("&List of configuration items:"), wxDefaultPosition
, wxDefaultSize
, 0);
109 item3
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
111 wxBoxSizer
* item8
= new wxBoxSizer(wxHORIZONTAL
);
112 item3
->Add(item8
, 0, wxGROW
, 5);
114 wxString
* item9Strings
= NULL
;
115 wxListBox
* item9
= new wxListBox(item1
, ID_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultSize
.x
, 100), 0, item9Strings
, wxLB_SINGLE
);
116 item8
->Add(item9
, 1, wxGROW
|wxALL
, 5);
118 wxBoxSizer
* item10
= new wxBoxSizer(wxVERTICAL
);
119 item8
->Add(item10
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
121 wxButton
* item11
= new wxButton(item1
, ID_CONFIG_ADD
, _("A&dd"), wxDefaultPosition
, wxDefaultSize
, 0);
122 item10
->Add(item11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
124 wxButton
* item12
= new wxButton(item1
, ID_CONFIG_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
125 item10
->Add(item12
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
127 wxBoxSizer
* item13
= new wxBoxSizer(wxHORIZONTAL
);
128 item3
->Add(item13
, 0, wxGROW
, 5);
130 item13
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
132 wxButton
* item15
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
133 item15
->SetDefault();
134 item13
->Add(item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
136 wxButton
* item16
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
137 item13
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
139 GetSizer()->Fit(this);
140 GetSizer()->SetSizeHints(this);
142 ////@end ctConfigItemsSelector content construction
146 * Event handler for ID_CONFIG_ADD
149 void ctConfigItemsSelector::OnConfigAdd( wxCommandEvent
& WXUNUSED(event
) )
151 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
152 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
155 if (masterList
->GetSelection() > -1)
157 wxString str
= masterList
->GetStringSelection();
158 if (m_configItems
.Index(str
) == wxNOT_FOUND
)
160 listBox
->Append(str
);
161 m_configItems
.Add(str
);
168 * Event handler for ID_CONFIG_REMOVE
171 void ctConfigItemsSelector::OnConfigRemove( wxCommandEvent
& WXUNUSED(event
) )
173 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
176 if (listBox
->GetSelection() > -1)
178 wxString str
= listBox
->GetStringSelection();
179 listBox
->Delete(listBox
->GetSelection());
180 m_configItems
.Remove(str
);
186 * Event handler for wxID_OK
189 void ctConfigItemsSelector::OnOk( wxCommandEvent
& event
)
191 // Replace with custom code
196 * Should we show tooltips?
199 bool ctConfigItemsSelector::ShowToolTips()
204 * Update event handler for ID_CONFIG_ADD
207 void ctConfigItemsSelector::OnUpdateConfigAdd( wxUpdateUIEvent
& event
)
209 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
210 event
.Enable(masterList
&& masterList
->GetSelection() != -1);
214 * Update event handler for ID_CONFIG_REMOVE
217 void ctConfigItemsSelector::OnUpdateConfigRemove( wxUpdateUIEvent
& event
)
219 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
220 event
.Enable(listBox
&& listBox
->GetSelection() != -1);
223 /// Initialise the master list
224 void ctConfigItemsSelector::InitSourceConfigList(ctConfigItem
* item
)
226 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
228 item
= wxGetApp().GetMainFrame()->GetDocument()->GetTopItem();
235 if (item
->GetType() == ctTypeGroup
)
237 else if (item
->GetType() == ctTypeCheckGroup
)
239 else if (item
->GetType() == ctTypeRadioGroup
)
241 else if (item
->GetType() == ctTypeString
)
243 else if (item
->GetType() == ctTypeBoolCheck
)
245 else if (item
->GetType() == ctTypeBoolRadio
)
247 else if (item
->GetType() == ctTypeInteger
)
251 masterList
->Append(item
->GetName());
254 wxNode
* node
= item
->GetChildren().GetFirst();
257 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
258 InitSourceConfigList(child
);
260 node
= node
->GetNext();
264 /// Set the initial list
265 void ctConfigItemsSelector::SetConfigList(const wxArrayString
& items
)
267 m_configItems
= items
;
268 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
272 for (i
= 0; i
< items
.GetCount(); i
++)
273 listBox
->Append(items
[i
]);