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 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/statline.h"
26 #include "wx/splitter.h"
27 #include "wx/scrolwin.h"
28 #include "wx/spinctrl.h"
29 #include "wx/spinbutt.h"
33 #include "wx/cshelp.h"
34 #include "wx/notebook.h"
35 #include "wx/valgen.h"
36 #include "configitemselector.h"
37 #include "configtooldoc.h"
38 #include "configtoolview.h"
39 #include "configitem.h"
40 #include "mainframe.h"
41 #include "wxconfigtool.h"
47 * ctConfigItemsSelector type definition
50 IMPLEMENT_CLASS( ctConfigItemsSelector
, wxDialog
)
53 * ctConfigItemsSelector event table definition
56 BEGIN_EVENT_TABLE( ctConfigItemsSelector
, wxDialog
)
58 ////@begin ctConfigItemsSelector event table entries
59 EVT_BUTTON( ID_CONFIG_ADD
, ctConfigItemsSelector::OnConfigAdd
)
60 EVT_UPDATE_UI( ID_CONFIG_ADD
, ctConfigItemsSelector::OnUpdateConfigAdd
)
62 EVT_BUTTON( ID_CONFIG_REMOVE
, ctConfigItemsSelector::OnConfigRemove
)
63 EVT_UPDATE_UI( ID_CONFIG_REMOVE
, ctConfigItemsSelector::OnUpdateConfigRemove
)
65 EVT_BUTTON( wxID_OK
, ctConfigItemsSelector::OnOk
)
67 ////@end ctConfigItemsSelector event table entries
72 * ctConfigItemsSelector constructor
75 ctConfigItemsSelector::ctConfigItemsSelector( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
)
77 wxDialog::Create( parent
, id
, caption
);
80 InitSourceConfigList();
84 * Control creation for ctConfigItemsSelector
87 void ctConfigItemsSelector::CreateControls()
89 ////@begin ctConfigItemsSelector content construction
91 ctConfigItemsSelector
* item1
= this;
93 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
94 item1
->SetSizer(item2
);
96 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
97 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
99 wxStaticText
* item4
= new wxStaticText(item1
, wxID_STATIC
, _("Please edit the list of configuration items by selecting from the\nlist below."), wxDefaultPosition
, wxDefaultSize
, 0);
100 item3
->Add(item4
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
102 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Available items:"), wxDefaultPosition
, wxDefaultSize
, 0);
103 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
105 wxString
* item6Strings
= NULL
;
106 wxListBox
* item6
= new wxListBox(item1
, ID_AVAILABLE_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultCoord
, 150), 0, item6Strings
, wxLB_SINGLE
|wxLB_SORT
);
107 item3
->Add(item6
, 1, wxGROW
|wxALL
, 5);
109 wxStaticText
* item7
= new wxStaticText(item1
, wxID_STATIC
, _("&List of configuration items:"), wxDefaultPosition
, wxDefaultSize
, 0);
110 item3
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
112 wxBoxSizer
* item8
= new wxBoxSizer(wxHORIZONTAL
);
113 item3
->Add(item8
, 0, wxGROW
, 5);
115 wxString
* item9Strings
= NULL
;
116 wxListBox
* item9
= new wxListBox(item1
, ID_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultCoord
, 100), 0, item9Strings
, wxLB_SINGLE
);
117 item8
->Add(item9
, 1, wxGROW
|wxALL
, 5);
119 wxBoxSizer
* item10
= new wxBoxSizer(wxVERTICAL
);
120 item8
->Add(item10
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
122 wxButton
* item11
= new wxButton(item1
, ID_CONFIG_ADD
, _("A&dd"), wxDefaultPosition
, wxDefaultSize
, 0);
123 item10
->Add(item11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
125 wxButton
* item12
= new wxButton(item1
, ID_CONFIG_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
126 item10
->Add(item12
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
128 wxBoxSizer
* item13
= new wxBoxSizer(wxHORIZONTAL
);
129 item3
->Add(item13
, 0, wxGROW
, 5);
131 item13
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
133 wxButton
* item15
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
134 item15
->SetDefault();
135 item13
->Add(item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
137 wxButton
* item16
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
138 item13
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
140 GetSizer()->Fit(this);
141 GetSizer()->SetSizeHints(this);
143 ////@end ctConfigItemsSelector content construction
147 * Event handler for ID_CONFIG_ADD
150 void ctConfigItemsSelector::OnConfigAdd( wxCommandEvent
& WXUNUSED(event
) )
152 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
153 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
156 if (masterList
->GetSelection() > -1)
158 wxString str
= masterList
->GetStringSelection();
159 if (m_configItems
.Index(str
) == wxNOT_FOUND
)
161 listBox
->Append(str
);
162 m_configItems
.Add(str
);
169 * Event handler for ID_CONFIG_REMOVE
172 void ctConfigItemsSelector::OnConfigRemove( wxCommandEvent
& WXUNUSED(event
) )
174 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
177 if (listBox
->GetSelection() > -1)
179 wxString str
= listBox
->GetStringSelection();
180 listBox
->Delete(listBox
->GetSelection());
181 m_configItems
.Remove(str
);
187 * Event handler for wxID_OK
190 void ctConfigItemsSelector::OnOk( wxCommandEvent
& event
)
192 // Replace with custom code
197 * Should we show tooltips?
200 bool ctConfigItemsSelector::ShowToolTips()
205 * Update event handler for ID_CONFIG_ADD
208 void ctConfigItemsSelector::OnUpdateConfigAdd( wxUpdateUIEvent
& event
)
210 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
211 event
.Enable(masterList
&& masterList
->GetSelection() != -1);
215 * Update event handler for ID_CONFIG_REMOVE
218 void ctConfigItemsSelector::OnUpdateConfigRemove( wxUpdateUIEvent
& event
)
220 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
221 event
.Enable(listBox
&& listBox
->GetSelection() != -1);
224 /// Initialise the master list
225 void ctConfigItemsSelector::InitSourceConfigList(ctConfigItem
* item
)
227 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
229 item
= wxGetApp().GetMainFrame()->GetDocument()->GetTopItem();
236 if (item
->GetType() == ctTypeGroup
)
238 else if (item
->GetType() == ctTypeCheckGroup
)
240 else if (item
->GetType() == ctTypeRadioGroup
)
242 else if (item
->GetType() == ctTypeString
)
244 else if (item
->GetType() == ctTypeBoolCheck
)
246 else if (item
->GetType() == ctTypeBoolRadio
)
248 else if (item
->GetType() == ctTypeInteger
)
252 masterList
->Append(item
->GetName());
255 wxObjectList::compatibility_iterator node
= item
->GetChildren().GetFirst();
258 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
259 InitSourceConfigList(child
);
261 node
= node
->GetNext();
265 /// Set the initial list
266 void ctConfigItemsSelector::SetConfigList(const wxArrayString
& items
)
268 m_configItems
= items
;
269 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
273 for (i
= 0; i
< items
.GetCount(); i
++)
274 listBox
->Append(items
[i
]);