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
);
84 item1
->SetAutoLayout(true);
86 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
87 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
89 wxStaticText
* item4
= new wxStaticText(item1
, wxID_STATIC
, _("Please edit the list of configuration items by selecting from the\nlist below."), wxDefaultPosition
, wxDefaultSize
, 0);
90 item3
->Add(item4
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
92 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Available items:"), wxDefaultPosition
, wxDefaultSize
, 0);
93 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
95 wxString
* item6Strings
= NULL
;
96 wxListBox
* item6
= new wxListBox(item1
, ID_AVAILABLE_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultSize
.x
, 150), 0, item6Strings
, wxLB_SINGLE
|wxLB_SORT
);
97 item3
->Add(item6
, 1, wxGROW
|wxALL
, 5);
99 wxStaticText
* item7
= new wxStaticText(item1
, wxID_STATIC
, _("&List of configuration items:"), wxDefaultPosition
, wxDefaultSize
, 0);
100 item3
->Add(item7
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
102 wxBoxSizer
* item8
= new wxBoxSizer(wxHORIZONTAL
);
103 item3
->Add(item8
, 0, wxGROW
, 5);
105 wxString
* item9Strings
= NULL
;
106 wxListBox
* item9
= new wxListBox(item1
, ID_CONFIG_ITEMS
, wxDefaultPosition
, wxSize(wxDefaultSize
.x
, 100), 0, item9Strings
, wxLB_SINGLE
);
107 item8
->Add(item9
, 1, wxGROW
|wxALL
, 5);
109 wxBoxSizer
* item10
= new wxBoxSizer(wxVERTICAL
);
110 item8
->Add(item10
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
112 wxButton
* item11
= new wxButton(item1
, ID_CONFIG_ADD
, _("A&dd"), wxDefaultPosition
, wxDefaultSize
, 0);
113 item10
->Add(item11
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
115 wxButton
* item12
= new wxButton(item1
, ID_CONFIG_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
116 item10
->Add(item12
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
118 wxBoxSizer
* item13
= new wxBoxSizer(wxHORIZONTAL
);
119 item3
->Add(item13
, 0, wxGROW
, 5);
121 item13
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
123 wxButton
* item15
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
124 item15
->SetDefault();
125 item13
->Add(item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
127 wxButton
* item16
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
128 item13
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
130 GetSizer()->Fit(this);
131 GetSizer()->SetSizeHints(this);
133 ////@end ctConfigItemsSelector content construction
137 * Event handler for ID_CONFIG_ADD
140 void ctConfigItemsSelector::OnConfigAdd( wxCommandEvent
& WXUNUSED(event
) )
142 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
143 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
146 if (masterList
->GetSelection() > -1)
148 wxString str
= masterList
->GetStringSelection();
149 if (m_configItems
.Index(str
) == wxNOT_FOUND
)
151 listBox
->Append(str
);
152 m_configItems
.Add(str
);
159 * Event handler for ID_CONFIG_REMOVE
162 void ctConfigItemsSelector::OnConfigRemove( wxCommandEvent
& WXUNUSED(event
) )
164 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
167 if (listBox
->GetSelection() > -1)
169 wxString str
= listBox
->GetStringSelection();
170 listBox
->Delete(listBox
->GetSelection());
171 m_configItems
.Remove(str
);
177 * Event handler for wxID_OK
180 void ctConfigItemsSelector::OnOk( wxCommandEvent
& event
)
182 // Replace with custom code
187 * Should we show tooltips?
190 bool ctConfigItemsSelector::ShowToolTips()
195 * Update event handler for ID_CONFIG_ADD
198 void ctConfigItemsSelector::OnUpdateConfigAdd( wxUpdateUIEvent
& event
)
200 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
201 event
.Enable(masterList
&& masterList
->GetSelection() != -1);
205 * Update event handler for ID_CONFIG_REMOVE
208 void ctConfigItemsSelector::OnUpdateConfigRemove( wxUpdateUIEvent
& event
)
210 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
211 event
.Enable(listBox
&& listBox
->GetSelection() != -1);
214 /// Initialise the master list
215 void ctConfigItemsSelector::InitSourceConfigList(ctConfigItem
* item
)
217 wxListBox
* masterList
= wxDynamicCast(FindWindow(ID_AVAILABLE_CONFIG_ITEMS
), wxListBox
);
219 item
= wxGetApp().GetMainFrame()->GetDocument()->GetTopItem();
226 if (item
->GetType() == ctTypeGroup
)
228 else if (item
->GetType() == ctTypeCheckGroup
)
230 else if (item
->GetType() == ctTypeRadioGroup
)
232 else if (item
->GetType() == ctTypeString
)
234 else if (item
->GetType() == ctTypeBoolCheck
)
236 else if (item
->GetType() == ctTypeBoolRadio
)
238 else if (item
->GetType() == ctTypeInteger
)
242 masterList
->Append(item
->GetName());
245 wxNode
* node
= item
->GetChildren().GetFirst();
248 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
249 InitSourceConfigList(child
);
251 node
= node
->GetNext();
255 /// Set the initial list
256 void ctConfigItemsSelector::SetConfigList(const wxArrayString
& items
)
258 m_configItems
= items
;
259 wxListBox
* listBox
= wxDynamicCast(FindWindow(ID_CONFIG_ITEMS
), wxListBox
);
263 for (i
= 0; i
< items
.GetCount(); i
++)
264 listBox
->Append(items
[i
]);