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