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 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
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"
29 #include "wx/cshelp.h"
30 #include "wx/notebook.h"
31 #include "wx/valgen.h"
32 #include "configitemselector.h"
33 #include "configtooldoc.h"
34 #include "configtoolview.h"
35 #include "configitem.h"
36 #include "mainframe.h"
37 #include "wxconfigtool.h"
43 * ctConfigItemsSelector type definition
46 IMPLEMENT_CLASS( ctConfigItemsSelector
, wxDialog
)
49 * ctConfigItemsSelector event table definition
52 BEGIN_EVENT_TABLE( ctConfigItemsSelector
, wxDialog
)
54 ////@begin ctConfigItemsSelector event table entries
55 EVT_BUTTON( ID_CONFIG_ADD
, ctConfigItemsSelector::OnConfigAdd
)
56 EVT_UPDATE_UI( ID_CONFIG_ADD
, ctConfigItemsSelector::OnUpdateConfigAdd
)
58 EVT_BUTTON( ID_CONFIG_REMOVE
, ctConfigItemsSelector::OnConfigRemove
)
59 EVT_UPDATE_UI( ID_CONFIG_REMOVE
, ctConfigItemsSelector::OnUpdateConfigRemove
)
61 EVT_BUTTON( wxID_OK
, ctConfigItemsSelector::OnOk
)
63 ////@end ctConfigItemsSelector event table entries
68 * ctConfigItemsSelector constructor
71 ctConfigItemsSelector::ctConfigItemsSelector( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
)
73 wxDialog::Create( parent
, id
, caption
);
76 InitSourceConfigList();
80 * Control creation for ctConfigItemsSelector
83 void ctConfigItemsSelector::CreateControls()
85 ////@begin ctConfigItemsSelector content construction
87 ctConfigItemsSelector
* item1
= this;
89 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
90 item1
->SetSizer(item2
);
92 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
93 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
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);
98 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Available items:"), wxDefaultPosition
, wxDefaultSize
, 0);
99 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
101 wxString
* item6Strings
= NULL
;
102 wxListBox
* item6
= new wxListBox(item1
, ID_AVAILABLE_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultCoord
, 150), 0, item6Strings
, wxLB_SINGLE
|wxLB_SORT
);
103 item3
->Add(item6
, 1, wxGROW
|wxALL
, 5);
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);
108 wxBoxSizer
* item8
= new wxBoxSizer(wxHORIZONTAL
);
109 item3
->Add(item8
, 0, wxGROW
, 5);
111 wxString
* item9Strings
= NULL
;
112 wxListBox
* item9
= new wxListBox(item1
, ID_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultCoord
, 100), 0, item9Strings
, wxLB_SINGLE
);
113 item8
->Add(item9
, 1, wxGROW
|wxALL
, 5);
115 wxBoxSizer
* item10
= new wxBoxSizer(wxVERTICAL
);
116 item8
->Add(item10
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
118 wxButton
* item11
= new wxButton(item1
, ID_CONFIG_ADD
, _("A&dd"), wxDefaultPosition
, wxDefaultSize
, 0);
119 item10
->Add(item11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
121 wxButton
* item12
= new wxButton(item1
, ID_CONFIG_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
122 item10
->Add(item12
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
124 wxBoxSizer
* item13
= new wxBoxSizer(wxHORIZONTAL
);
125 item3
->Add(item13
, 0, wxGROW
, 5);
127 item13
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
129 wxButton
* item15
= new wxButton(item1
, wxID_OK
);
130 item15
->SetDefault();
131 item13
->Add(item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
133 wxButton
* item16
= new wxButton(item1
, wxID_CANCEL
);
134 item13
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
136 GetSizer()->Fit(this);
137 GetSizer()->SetSizeHints(this);
139 ////@end ctConfigItemsSelector content construction
143 * Event handler for ID_CONFIG_ADD
146 void ctConfigItemsSelector::OnConfigAdd( wxCommandEvent
& WXUNUSED(event
) )
148 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
149 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
152 if (masterList
->GetSelection() > -1)
154 wxString str
= masterList
->GetStringSelection();
155 if (m_configItems
.Index(str
) == wxNOT_FOUND
)
157 listBox
->Append(str
);
158 m_configItems
.Add(str
);
165 * Event handler for ID_CONFIG_REMOVE
168 void ctConfigItemsSelector::OnConfigRemove( wxCommandEvent
& WXUNUSED(event
) )
170 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
173 if (listBox
->GetSelection() > -1)
175 wxString str
= listBox
->GetStringSelection();
176 listBox
->Delete(listBox
->GetSelection());
177 m_configItems
.Remove(str
);
183 * Event handler for wxID_OK
186 void ctConfigItemsSelector::OnOk( wxCommandEvent
& event
)
188 // Replace with custom code
193 * Should we show tooltips?
196 bool ctConfigItemsSelector::ShowToolTips()
201 * Update event handler for ID_CONFIG_ADD
204 void ctConfigItemsSelector::OnUpdateConfigAdd( wxUpdateUIEvent
& event
)
206 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
207 event
.Enable(masterList
&& masterList
->GetSelection() != -1);
211 * Update event handler for ID_CONFIG_REMOVE
214 void ctConfigItemsSelector::OnUpdateConfigRemove( wxUpdateUIEvent
& event
)
216 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
217 event
.Enable(listBox
&& listBox
->GetSelection() != -1);
220 /// Initialise the master list
221 void ctConfigItemsSelector::InitSourceConfigList(ctConfigItem
* item
)
223 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
225 item
= wxGetApp().GetMainFrame()->GetDocument()->GetTopItem();
232 if (item
->GetType() == ctTypeGroup
)
234 else if (item
->GetType() == ctTypeCheckGroup
)
236 else if (item
->GetType() == ctTypeRadioGroup
)
238 else if (item
->GetType() == ctTypeString
)
240 else if (item
->GetType() == ctTypeBoolCheck
)
242 else if (item
->GetType() == ctTypeBoolRadio
)
244 else if (item
->GetType() == ctTypeInteger
)
248 masterList
->Append(item
->GetName());
251 wxObjectList::compatibility_iterator node
= item
->GetChildren().GetFirst();
254 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
255 InitSourceConfigList(child
);
257 node
= node
->GetNext();
261 /// Set the initial list
262 void ctConfigItemsSelector::SetConfigList(const wxArrayString
& items
)
264 m_configItems
= items
;
265 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
269 for (i
= 0; i
< items
.GetCount(); i
++)
270 listBox
->Append(items
[i
]);