]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/custompropertydialog.cpp
Removed rules for copying the Mac resource file since they are no
[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 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
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"
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
70 ctCustomPropertyDialog::ctCustomPropertyDialog( wxWindow* parent, wxWindowID id, const wxString& caption)
71 {
72 m_type = wxT("string");
73
74 wxDialog::Create( parent, id, caption);
75
76 CreateControls();
77 }
78
79 /*!
80 * Control creation for ctCustomPropertyDialog
81 */
82
83 void ctCustomPropertyDialog::CreateControls()
84 {
85 ////@begin ctCustomPropertyDialog content construction
86
87 wxArrayString items;
88
89 ctCustomPropertyDialog* item1 = this;
90
91 wxBoxSizer* item2 = new wxBoxSizer(wxVERTICAL);
92 item1->SetSizer(item2);
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
103 m_customPropertyName = new wxTextCtrl(item1, wxID_ANY);
104 item3->Add(m_customPropertyName, 0, wxGROW|wxALL, 5);
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
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);
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
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);
140
141 wxStaticBox* item14Static = new wxStaticBox(item1, wxID_ANY, _("Choices"));
142 wxStaticBoxSizer* item14 = new wxStaticBoxSizer(item14Static, wxHORIZONTAL);
143 item3->Add(item14, 0, wxGROW|wxALL, 5);
144
145 wxString* item15Strings = NULL;
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);
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
161 m_customPropertyDescription = new wxTextCtrl(item1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_RICH);
162 item3->Add(m_customPropertyDescription, 1, wxGROW|wxALL, 5);
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);
170 item21->Add(item23, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
171
172 wxButton* item24 = new wxButton(item1, wxID_CANCEL);
173 item21->Add(item24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
174
175 wxButton* item25 = new wxButton(item1, wxID_HELP);
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
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));
188 }
189
190 /*!
191 * Should we show tooltips?
192 */
193
194 bool ctCustomPropertyDialog::ShowToolTips()
195 {
196 return true;
197 }
198
199 /*!
200 * Update event handler for ID_PROPERTY_CHOICES
201 */
202
203 void ctCustomPropertyDialog::OnUpdatePropertyChoices( wxUpdateUIEvent& event )
204 {
205 if(m_customPrototype)
206 event.Enable( m_customPrototype->GetSelection() > -1 && m_customPrototype->GetStringSelection() == wxT("choice") );
207 }
208
209 /*!
210 * Event handler for ID_PROPERTY_CHOICE_ADD
211 */
212
213 void ctCustomPropertyDialog::OnPropertyChoiceAdd( wxCommandEvent& WXUNUSED(event) )
214 {
215 if(m_customPrototype)
216 {
217 if ( m_customPropertyEditorType->GetSelection() > -1 && m_customPropertyEditorType->GetStringSelection() == wxT("choice") )
218 {
219 wxString str = wxGetTextFromUser(_T("New choice"), _("Add choice"));
220 if (!str.empty() && m_propertyChoices)
221 {
222 m_propertyChoices->Append(str);
223 m_choices.Add(str);
224 }
225 }
226 }
227 }
228
229 /*!
230 * Update event handler for ID_PROPERTY_CHOICE_ADD
231 */
232
233 void ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd( wxUpdateUIEvent& event )
234 {
235 if(m_customPropertyEditorType)
236 event.Enable( m_customPropertyEditorType->GetSelection() > -1 &&
237 m_customPropertyEditorType->GetStringSelection() == wxT("choice") );
238 }
239
240 /*!
241 * Event handler for ID_PROPERTY_CHOICE_REMOVE
242 */
243
244 void ctCustomPropertyDialog::OnPropertyChoiceRemove( wxCommandEvent& WXUNUSED(event) )
245 {
246 if (m_propertyChoices && m_propertyChoices->GetSelection() > -1)
247 {
248 m_propertyChoices->Delete(m_propertyChoices->GetSelection());
249 m_choices.RemoveAt(m_propertyChoices->GetSelection());
250 }
251 }
252
253 /*!
254 * Update event handler for ID_PROPERTY_CHOICE_REMOVE
255 */
256
257 void ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove( wxUpdateUIEvent& event )
258 {
259 if (m_customPropertyEditorType && m_propertyChoices)
260 event.Enable( m_customPropertyEditorType->GetSelection() > -1 &&
261 m_customPropertyEditorType->GetStringSelection() == wxT("choice") &&
262 m_propertyChoices->GetSelection() > -1 );
263 }
264
265 void ctCustomPropertyDialog::SetChoices(const wxArrayString& choices)
266 {
267 size_t i, len = choices.GetCount();
268 if (m_propertyChoices)
269 for (i = 0; i < len; i++)
270 m_propertyChoices->Append(m_choices[i]);
271 }