]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/custompropertydialog.cpp
Missing headers.
[wxWidgets.git] / utils / configtool / src / custompropertydialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: custompropertydialog.cpp
3 // Purpose: Custom property dialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2003-06-04
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "custompropertydialog.h"
14 #endif
15
16 #include <wx/wx.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>
24
25 #include "custompropertydialog.h"
26
27 ////@begin XPM images
28 ////@end XPM images
29
30 /*!
31 * ctCustomPropertyDialog type definition
32 */
33
34 IMPLEMENT_CLASS( ctCustomPropertyDialog, wxDialog )
35
36 /*!
37 * ctCustomPropertyDialog event table definition
38 */
39
40 BEGIN_EVENT_TABLE( ctCustomPropertyDialog, wxDialog )
41
42 ////@begin ctCustomPropertyDialog event table entries
43 EVT_UPDATE_UI( ID_PROPERTY_CHOICES, ctCustomPropertyDialog::OnUpdatePropertyChoices )
44
45 EVT_BUTTON( ID_PROPERTY_CHOICE_ADD, ctCustomPropertyDialog::OnPropertyChoiceAdd )
46 EVT_UPDATE_UI( ID_PROPERTY_CHOICE_ADD, ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd )
47
48 EVT_BUTTON( ID_PROPERTY_CHOICE_REMOVE, ctCustomPropertyDialog::OnPropertyChoiceRemove )
49 EVT_UPDATE_UI( ID_PROPERTY_CHOICE_REMOVE, ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove )
50
51 ////@end ctCustomPropertyDialog event table entries
52
53 END_EVENT_TABLE()
54
55 /*!
56 * ctCustomPropertyDialog constructor
57 */
58
59 ctCustomPropertyDialog::ctCustomPropertyDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
60 {
61 m_type = wxT("string");
62
63 wxDialog::Create( parent, id, caption, pos, size, style );
64
65 CreateControls();
66 }
67
68 /*!
69 * Control creation for ctCustomPropertyDialog
70 */
71
72 void ctCustomPropertyDialog::CreateControls()
73 {
74 ////@begin ctCustomPropertyDialog content construction
75
76 ctCustomPropertyDialog* item1 = this;
77
78 wxBoxSizer* item2 = new wxBoxSizer(wxVERTICAL);
79 item1->SetSizer(item2);
80
81 wxBoxSizer* item3 = new wxBoxSizer(wxVERTICAL);
82 item2->Add(item3, 1, wxGROW|wxALL, 5);
83
84 wxStaticText* item4 = new wxStaticText(item1, wxID_STATIC, _("&Enter name, type and description for your custom property."), wxDefaultPosition, wxDefaultSize, 0);
85 item3->Add(item4, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
86
87 wxStaticText* item5 = new wxStaticText(item1, wxID_STATIC, _("&Name:"), wxDefaultPosition, wxDefaultSize, 0);
88 item3->Add(item5, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
89
90 wxTextCtrl* item6 = new wxTextCtrl(item1, ID_CUSTOMPROPERTYNAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
91 item3->Add(item6, 0, wxGROW|wxALL, 5);
92
93 wxBoxSizer* item7 = new wxBoxSizer(wxHORIZONTAL);
94 item3->Add(item7, 0, wxGROW, 5);
95
96 wxBoxSizer* item8 = new wxBoxSizer(wxVERTICAL);
97 item7->Add(item8, 1, wxGROW, 5);
98
99 wxStaticText* item9 = new wxStaticText(item1, wxID_STATIC, _("&Data type:"), wxDefaultPosition, wxDefaultSize, 0);
100 item8->Add(item9, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
101
102 wxString item10Strings[] = {
103 _("string"),
104 _("bool"),
105 _("double"),
106 _("long")
107 };
108 wxChoice* item10 = new wxChoice(item1, ID_CUSTOMPROPERTYTYPE, wxDefaultPosition, wxDefaultSize, 4, item10Strings, 0);
109 item10->SetStringSelection(_("string"));
110 item8->Add(item10, 1, wxGROW|wxALL, 5);
111
112 wxBoxSizer* item11 = new wxBoxSizer(wxVERTICAL);
113 item7->Add(item11, 0, wxALIGN_CENTER_VERTICAL, 5);
114
115 wxStaticText* item12 = new wxStaticText(item1, wxID_STATIC, _("&Editor type:"), wxDefaultPosition, wxDefaultSize, 0);
116 item11->Add(item12, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
117
118 wxString item13Strings[] = {
119 _("string"),
120 _("choice"),
121 _("bool"),
122 _("float"),
123 _("integer"),
124 _("configitems")
125 };
126 wxChoice* item13 = new wxChoice(item1, ID_CUSTOMPROPERTYEDITORTYPE, wxDefaultPosition, wxDefaultSize, 6, item13Strings, 0);
127 item13->SetStringSelection(_("string"));
128 item11->Add(item13, 1, wxGROW|wxALL, 5);
129
130 wxStaticBox* item14Static = new wxStaticBox(item1, wxID_ANY, _("Choices"));
131 wxStaticBoxSizer* item14 = new wxStaticBoxSizer(item14Static, wxHORIZONTAL);
132 item3->Add(item14, 0, wxGROW|wxALL, 5);
133
134 wxString* item15Strings = NULL;
135 wxListBox* item15 = new wxListBox(item1, ID_PROPERTY_CHOICES, wxDefaultPosition, wxDefaultSize, 0, item15Strings, wxLB_SINGLE);
136 item14->Add(item15, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
137
138 wxBoxSizer* item16 = new wxBoxSizer(wxVERTICAL);
139 item14->Add(item16, 0, wxALIGN_CENTER_VERTICAL, 5);
140
141 wxButton* item17 = new wxButton(item1, ID_PROPERTY_CHOICE_ADD, _("&Add..."), wxDefaultPosition, wxDefaultSize, 0);
142 item16->Add(item17, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
143
144 wxButton* item18 = new wxButton(item1, ID_PROPERTY_CHOICE_REMOVE, _("&Remove"), wxDefaultPosition, wxDefaultSize, 0);
145 item16->Add(item18, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
146
147 wxStaticText* item19 = new wxStaticText(item1, wxID_STATIC, _("&Description:"), wxDefaultPosition, wxDefaultSize, 0);
148 item3->Add(item19, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5);
149
150 wxTextCtrl* item20 = new wxTextCtrl(item1, ID_CUSTOMPROPERTYDESCRIPTION, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_RICH);
151 item3->Add(item20, 1, wxGROW|wxALL, 5);
152
153 wxBoxSizer* item21 = new wxBoxSizer(wxHORIZONTAL);
154 item3->Add(item21, 0, wxGROW|wxALL, 5);
155
156 item21->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
157
158 wxButton* item23 = new wxButton(item1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0);
159 item21->Add(item23, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
160
161 wxButton* item24 = new wxButton(item1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0);
162 item21->Add(item24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
163
164 wxButton* item25 = new wxButton(item1, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, 0);
165 item21->Add(item25, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
166
167 GetSizer()->Fit(this);
168 GetSizer()->SetSizeHints(this);
169 Centre();
170 ////@end ctCustomPropertyDialog content construction
171
172 // Add validators
173 FindWindow(ID_CUSTOMPROPERTYNAME)->SetValidator(wxGenericValidator(& m_name));
174 FindWindow(ID_CUSTOMPROPERTYTYPE)->SetValidator(wxGenericValidator(& m_type));
175 FindWindow(ID_CUSTOMPROPERTYEDITORTYPE)->SetValidator(wxGenericValidator(& m_editorType));
176 FindWindow(ID_CUSTOMPROPERTYDESCRIPTION)->SetValidator(wxGenericValidator(& m_description));
177 }
178
179 /*!
180 * Should we show tooltips?
181 */
182
183 bool ctCustomPropertyDialog::ShowToolTips()
184 {
185 return true;
186 }
187
188 /*!
189 * Update event handler for ID_PROPERTY_CHOICES
190 */
191
192 void ctCustomPropertyDialog::OnUpdatePropertyChoices( wxUpdateUIEvent& event )
193 {
194 wxChoice* choice = (wxChoice* ) FindWindow(ID_CUSTOMPROPERTYTYPE);
195 event.Enable( choice->GetSelection() > -1 && choice->GetStringSelection() == wxT("choice") );
196 }
197
198 /*!
199 * Event handler for ID_PROPERTY_CHOICE_ADD
200 */
201
202 void ctCustomPropertyDialog::OnPropertyChoiceAdd( wxCommandEvent& WXUNUSED(event) )
203 {
204 wxChoice* choice = (wxChoice* ) FindWindow(ID_CUSTOMPROPERTYTYPE);
205 if ( choice->GetSelection() > -1 && choice->GetStringSelection() == wxT("choice") )
206 {
207 wxString str = wxGetTextFromUser(_T("New choice"), _("Add choice"));
208 if (!str.IsEmpty())
209 {
210 wxListBox* listBox = (wxListBox* ) FindWindow(ID_PROPERTY_CHOICES);
211 listBox->Append(str);
212 m_choices.Add(str);
213 }
214 }
215 }
216
217 /*!
218 * Update event handler for ID_PROPERTY_CHOICE_ADD
219 */
220
221 void ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd( wxUpdateUIEvent& event )
222 {
223 wxChoice* choice = (wxChoice* ) FindWindow(ID_CUSTOMPROPERTYEDITORTYPE);
224 event.Enable( choice->GetSelection() > -1 && choice->GetStringSelection() == wxT("choice") );
225 }
226
227 /*!
228 * Event handler for ID_PROPERTY_CHOICE_REMOVE
229 */
230
231 void ctCustomPropertyDialog::OnPropertyChoiceRemove( wxCommandEvent& WXUNUSED(event) )
232 {
233 /* wxChoice* choice = (wxChoice* ) */ FindWindow(ID_CUSTOMPROPERTYEDITORTYPE);
234 wxListBox* listBox = (wxListBox* ) FindWindow(ID_PROPERTY_CHOICES);
235 if (listBox->GetSelection() > -1)
236 {
237 listBox->Delete(listBox->GetSelection());
238 m_choices.RemoveAt(listBox->GetSelection());
239 }
240 }
241
242 /*!
243 * Update event handler for ID_PROPERTY_CHOICE_REMOVE
244 */
245
246 void ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove( wxUpdateUIEvent& event )
247 {
248 wxChoice* choice = (wxChoice* ) FindWindow(ID_CUSTOMPROPERTYEDITORTYPE);
249 wxListBox* listBox = (wxListBox* ) FindWindow(ID_PROPERTY_CHOICES);
250 event.Enable( choice->GetSelection() > -1 && choice->GetStringSelection() == wxT("choice") &&
251 listBox->GetSelection() > -1 );
252 }
253
254 void ctCustomPropertyDialog::SetChoices(const wxArrayString& choices)
255 {
256 wxListBox* listBox = (wxListBox* ) FindWindow(ID_PROPERTY_CHOICES);
257 size_t i, len = choices.GetCount();
258 for (i = 0; i < len; i++)
259 listBox->Append(m_choices[i]);
260 }