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