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"
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>
25 #include "configitemselector.h"
26 #include "configtooldoc.h"
27 #include "configtoolview.h"
28 #include "configitem.h"
29 #include "mainframe.h"
30 #include "wxconfigtool.h"
36 * ctConfigItemsSelector type definition
39 IMPLEMENT_CLASS( ctConfigItemsSelector
, wxDialog
)
42 * ctConfigItemsSelector event table definition
45 BEGIN_EVENT_TABLE( ctConfigItemsSelector
, wxDialog
)
47 ////@begin ctConfigItemsSelector event table entries
48 EVT_BUTTON( ID_CONFIG_ADD
, ctConfigItemsSelector::OnConfigAdd
)
49 EVT_UPDATE_UI( ID_CONFIG_ADD
, ctConfigItemsSelector::OnUpdateConfigAdd
)
51 EVT_BUTTON( ID_CONFIG_REMOVE
, ctConfigItemsSelector::OnConfigRemove
)
52 EVT_UPDATE_UI( ID_CONFIG_REMOVE
, ctConfigItemsSelector::OnUpdateConfigRemove
)
54 EVT_BUTTON( wxID_OK
, ctConfigItemsSelector::OnOk
)
56 ////@end ctConfigItemsSelector event table entries
61 * ctConfigItemsSelector constructor
64 ctConfigItemsSelector::ctConfigItemsSelector( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
66 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
69 InitSourceConfigList();
73 * Control creation for ctConfigItemsSelector
76 void ctConfigItemsSelector::CreateControls()
78 ////@begin ctConfigItemsSelector content construction
80 ctConfigItemsSelector
* item1
= this;
82 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
83 item1
->SetSizer(item2
);
85 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
86 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
88 wxStaticText
* item4
= new wxStaticText(item1
, wxID_STATIC
, _("Please edit the list of configuration items by selecting from the\nlist below."), wxDefaultPosition
, wxDefaultSize
, 0);
89 item3
->Add(item4
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
91 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Available items:"), wxDefaultPosition
, wxDefaultSize
, 0);
92 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
94 wxString
* item6Strings
= NULL
;
95 wxListBox
* item6
= new wxListBox(item1
, ID_AVAILABLE_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultSize
.x
, 150), 0, item6Strings
, wxLB_SINGLE
|wxLB_SORT
);
96 item3
->Add(item6
, 1, wxGROW
|wxALL
, 5);
98 wxStaticText
* item7
= new wxStaticText(item1
, wxID_STATIC
, _("&List of configuration items:"), wxDefaultPosition
, wxDefaultSize
, 0);
99 item3
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
101 wxBoxSizer
* item8
= new wxBoxSizer(wxHORIZONTAL
);
102 item3
->Add(item8
, 0, wxGROW
, 5);
104 wxString
* item9Strings
= NULL
;
105 wxListBox
* item9
= new wxListBox(item1
, ID_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultSize
.x
, 100), 0, item9Strings
, wxLB_SINGLE
);
106 item8
->Add(item9
, 1, wxGROW
|wxALL
, 5);
108 wxBoxSizer
* item10
= new wxBoxSizer(wxVERTICAL
);
109 item8
->Add(item10
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
111 wxButton
* item11
= new wxButton(item1
, ID_CONFIG_ADD
, _("A&dd"), wxDefaultPosition
, wxDefaultSize
, 0);
112 item10
->Add(item11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
114 wxButton
* item12
= new wxButton(item1
, ID_CONFIG_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
115 item10
->Add(item12
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
117 wxBoxSizer
* item13
= new wxBoxSizer(wxHORIZONTAL
);
118 item3
->Add(item13
, 0, wxGROW
, 5);
120 item13
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
122 wxButton
* item15
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
123 item15
->SetDefault();
124 item13
->Add(item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
126 wxButton
* item16
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
127 item13
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
129 GetSizer()->Fit(this);
130 GetSizer()->SetSizeHints(this);
132 ////@end ctConfigItemsSelector content construction
136 * Event handler for ID_CONFIG_ADD
139 void ctConfigItemsSelector::OnConfigAdd( wxCommandEvent
& WXUNUSED(event
) )
141 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
142 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
145 if (masterList
->GetSelection() > -1)
147 wxString str
= masterList
->GetStringSelection();
148 if (m_configItems
.Index(str
) == wxNOT_FOUND
)
150 listBox
->Append(str
);
151 m_configItems
.Add(str
);
158 * Event handler for ID_CONFIG_REMOVE
161 void ctConfigItemsSelector::OnConfigRemove( wxCommandEvent
& WXUNUSED(event
) )
163 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
166 if (listBox
->GetSelection() > -1)
168 wxString str
= listBox
->GetStringSelection();
169 listBox
->Delete(listBox
->GetSelection());
170 m_configItems
.Remove(str
);
176 * Event handler for wxID_OK
179 void ctConfigItemsSelector::OnOk( wxCommandEvent
& event
)
181 // Replace with custom code
186 * Should we show tooltips?
189 bool ctConfigItemsSelector::ShowToolTips()
194 * Update event handler for ID_CONFIG_ADD
197 void ctConfigItemsSelector::OnUpdateConfigAdd( wxUpdateUIEvent
& event
)
199 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
200 event
.Enable(masterList
&& masterList
->GetSelection() != -1);
204 * Update event handler for ID_CONFIG_REMOVE
207 void ctConfigItemsSelector::OnUpdateConfigRemove( wxUpdateUIEvent
& event
)
209 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
210 event
.Enable(listBox
&& listBox
->GetSelection() != -1);
213 /// Initialise the master list
214 void ctConfigItemsSelector::InitSourceConfigList(ctConfigItem
* item
)
216 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
218 item
= wxGetApp().GetMainFrame()->GetDocument()->GetTopItem();
225 if (item
->GetType() == ctTypeGroup
)
227 else if (item
->GetType() == ctTypeCheckGroup
)
229 else if (item
->GetType() == ctTypeRadioGroup
)
231 else if (item
->GetType() == ctTypeString
)
233 else if (item
->GetType() == ctTypeBoolCheck
)
235 else if (item
->GetType() == ctTypeBoolRadio
)
237 else if (item
->GetType() == ctTypeInteger
)
241 masterList
->Append(item
->GetName());
244 wxNode
* node
= item
->GetChildren().GetFirst();
247 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
248 InitSourceConfigList(child
);
250 node
= node
->GetNext();
254 /// Set the initial list
255 void ctConfigItemsSelector::SetConfigList(const wxArrayString
& items
)
257 m_configItems
= items
;
258 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
262 for (i
= 0; i
< items
.GetCount(); i
++)
263 listBox
->Append(items
[i
]);