]>
Commit | Line | Data |
---|---|---|
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 | item1->SetAutoLayout(TRUE); | |
81 | ||
82 | wxBoxSizer* item3 = new wxBoxSizer(wxVERTICAL); | |
83 | item2->Add(item3, 1, wxGROW|wxALL, 5); | |
84 | ||
85 | wxStaticText* item4 = new wxStaticText(item1, wxID_STATIC, _("&Enter name, type and description for your custom property."), wxDefaultPosition, wxDefaultSize, 0); | |
86 | item3->Add(item4, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); | |
87 | ||
88 | wxStaticText* item5 = new wxStaticText(item1, wxID_STATIC, _("&Name:"), wxDefaultPosition, wxDefaultSize, 0); | |
89 | item3->Add(item5, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); | |
90 | ||
91 | wxTextCtrl* item6 = new wxTextCtrl(item1, ID_CUSTOMPROPERTYNAME, _(""), wxDefaultPosition, wxDefaultSize, 0); | |
92 | item3->Add(item6, 0, wxGROW|wxALL, 5); | |
93 | ||
94 | wxBoxSizer* item7 = new wxBoxSizer(wxHORIZONTAL); | |
95 | item3->Add(item7, 0, wxGROW, 5); | |
96 | ||
97 | wxBoxSizer* item8 = new wxBoxSizer(wxVERTICAL); | |
98 | item7->Add(item8, 1, wxGROW, 5); | |
99 | ||
100 | wxStaticText* item9 = new wxStaticText(item1, wxID_STATIC, _("&Data type:"), wxDefaultPosition, wxDefaultSize, 0); | |
101 | item8->Add(item9, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); | |
102 | ||
103 | wxString item10Strings[] = { | |
104 | _("string"), | |
105 | _("bool"), | |
106 | _("double"), | |
107 | _("long") | |
108 | }; | |
109 | wxChoice* item10 = new wxChoice(item1, ID_CUSTOMPROPERTYTYPE, wxDefaultPosition, wxDefaultSize, 4, item10Strings, 0); | |
110 | item10->SetStringSelection(_("string")); | |
111 | item8->Add(item10, 1, wxGROW|wxALL, 5); | |
112 | ||
113 | wxBoxSizer* item11 = new wxBoxSizer(wxVERTICAL); | |
114 | item7->Add(item11, 0, wxALIGN_CENTER_VERTICAL, 5); | |
115 | ||
116 | wxStaticText* item12 = new wxStaticText(item1, wxID_STATIC, _("&Editor type:"), wxDefaultPosition, wxDefaultSize, 0); | |
117 | item11->Add(item12, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); | |
118 | ||
119 | wxString item13Strings[] = { | |
120 | _("string"), | |
121 | _("choice"), | |
122 | _("bool"), | |
123 | _("float"), | |
124 | _("integer"), | |
125 | _("configitems") | |
126 | }; | |
127 | wxChoice* item13 = new wxChoice(item1, ID_CUSTOMPROPERTYEDITORTYPE, wxDefaultPosition, wxDefaultSize, 6, item13Strings, 0); | |
128 | item13->SetStringSelection(_("string")); | |
129 | item11->Add(item13, 1, wxGROW|wxALL, 5); | |
130 | ||
131 | wxStaticBox* item14Static = new wxStaticBox(item1, -1, _("Choices")); | |
132 | wxStaticBoxSizer* item14 = new wxStaticBoxSizer(item14Static, wxHORIZONTAL); | |
133 | item3->Add(item14, 0, wxGROW|wxALL, 5); | |
134 | ||
135 | wxString* item15Strings = NULL; | |
136 | wxListBox* item15 = new wxListBox(item1, ID_PROPERTY_CHOICES, wxDefaultPosition, wxDefaultSize, 0, item15Strings, wxLB_SINGLE); | |
137 | item14->Add(item15, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
138 | ||
139 | wxBoxSizer* item16 = new wxBoxSizer(wxVERTICAL); | |
140 | item14->Add(item16, 0, wxALIGN_CENTER_VERTICAL, 5); | |
141 | ||
142 | wxButton* item17 = new wxButton(item1, ID_PROPERTY_CHOICE_ADD, _("&Add..."), wxDefaultPosition, wxDefaultSize, 0); | |
143 | item16->Add(item17, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); | |
144 | ||
145 | wxButton* item18 = new wxButton(item1, ID_PROPERTY_CHOICE_REMOVE, _("&Remove"), wxDefaultPosition, wxDefaultSize, 0); | |
146 | item16->Add(item18, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); | |
147 | ||
148 | wxStaticText* item19 = new wxStaticText(item1, wxID_STATIC, _("&Description:"), wxDefaultPosition, wxDefaultSize, 0); | |
149 | item3->Add(item19, 0, wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE, 5); | |
150 | ||
151 | wxTextCtrl* item20 = new wxTextCtrl(item1, ID_CUSTOMPROPERTYDESCRIPTION, _(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_RICH); | |
152 | item3->Add(item20, 1, wxGROW|wxALL, 5); | |
153 | ||
154 | wxBoxSizer* item21 = new wxBoxSizer(wxHORIZONTAL); | |
155 | item3->Add(item21, 0, wxGROW|wxALL, 5); | |
156 | ||
157 | item21->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
158 | ||
159 | wxButton* item23 = new wxButton(item1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0); | |
160 | item21->Add(item23, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
161 | ||
162 | wxButton* item24 = new wxButton(item1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0); | |
163 | item21->Add(item24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
164 | ||
165 | wxButton* item25 = new wxButton(item1, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, 0); | |
166 | item21->Add(item25, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); | |
167 | ||
168 | GetSizer()->Fit(this); | |
169 | GetSizer()->SetSizeHints(this); | |
170 | Centre(); | |
171 | ////@end ctCustomPropertyDialog content construction | |
172 | ||
173 | // Add validators | |
174 | FindWindow(ID_CUSTOMPROPERTYNAME)->SetValidator(wxGenericValidator(& m_name)); | |
175 | FindWindow(ID_CUSTOMPROPERTYTYPE)->SetValidator(wxGenericValidator(& m_type)); | |
176 | FindWindow(ID_CUSTOMPROPERTYEDITORTYPE)->SetValidator(wxGenericValidator(& m_editorType)); | |
177 | FindWindow(ID_CUSTOMPROPERTYDESCRIPTION)->SetValidator(wxGenericValidator(& m_description)); | |
178 | } | |
179 | ||
180 | /*! | |
181 | * Should we show tooltips? | |
182 | */ | |
183 | ||
184 | bool ctCustomPropertyDialog::ShowToolTips() | |
185 | { | |
186 | return TRUE; | |
187 | } | |
188 | ||
189 | /*! | |
190 | * Update event handler for ID_PROPERTY_CHOICES | |
191 | */ | |
192 | ||
193 | void ctCustomPropertyDialog::OnUpdatePropertyChoices( wxUpdateUIEvent& event ) | |
194 | { | |
195 | wxChoice* choice = (wxChoice* ) FindWindow(ID_CUSTOMPROPERTYTYPE); | |
196 | event.Enable( choice->GetSelection() > -1 && choice->GetStringSelection() == wxT("choice") ); | |
197 | } | |
198 | ||
199 | /*! | |
200 | * Event handler for ID_PROPERTY_CHOICE_ADD | |
201 | */ | |
202 | ||
203 | void ctCustomPropertyDialog::OnPropertyChoiceAdd( wxCommandEvent& WXUNUSED(event) ) | |
204 | { | |
205 | wxChoice* choice = (wxChoice* ) FindWindow(ID_CUSTOMPROPERTYTYPE); | |
206 | if ( choice->GetSelection() > -1 && choice->GetStringSelection() == wxT("choice") ) | |
207 | { | |
208 | wxString str = wxGetTextFromUser(_T("New choice"), _("Add choice")); | |
209 | if (!str.IsEmpty()) | |
210 | { | |
211 | wxListBox* listBox = (wxListBox* ) FindWindow(ID_PROPERTY_CHOICES); | |
212 | listBox->Append(str); | |
213 | m_choices.Add(str); | |
214 | } | |
215 | } | |
216 | } | |
217 | ||
218 | /*! | |
219 | * Update event handler for ID_PROPERTY_CHOICE_ADD | |
220 | */ | |
221 | ||
222 | void ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd( wxUpdateUIEvent& event ) | |
223 | { | |
224 | wxChoice* choice = (wxChoice* ) FindWindow(ID_CUSTOMPROPERTYEDITORTYPE); | |
225 | event.Enable( choice->GetSelection() > -1 && choice->GetStringSelection() == wxT("choice") ); | |
226 | } | |
227 | ||
228 | /*! | |
229 | * Event handler for ID_PROPERTY_CHOICE_REMOVE | |
230 | */ | |
231 | ||
232 | void ctCustomPropertyDialog::OnPropertyChoiceRemove( wxCommandEvent& WXUNUSED(event) ) | |
233 | { | |
234 | /* wxChoice* choice = (wxChoice* ) */ FindWindow(ID_CUSTOMPROPERTYEDITORTYPE); | |
235 | wxListBox* listBox = (wxListBox* ) FindWindow(ID_PROPERTY_CHOICES); | |
236 | if (listBox->GetSelection() > -1) | |
237 | { | |
238 | listBox->Delete(listBox->GetSelection()); | |
239 | m_choices.RemoveAt(listBox->GetSelection()); | |
240 | } | |
241 | } | |
242 | ||
243 | /*! | |
244 | * Update event handler for ID_PROPERTY_CHOICE_REMOVE | |
245 | */ | |
246 | ||
247 | void ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove( wxUpdateUIEvent& event ) | |
248 | { | |
249 | wxChoice* choice = (wxChoice* ) FindWindow(ID_CUSTOMPROPERTYEDITORTYPE); | |
250 | wxListBox* listBox = (wxListBox* ) FindWindow(ID_PROPERTY_CHOICES); | |
251 | event.Enable( choice->GetSelection() > -1 && choice->GetStringSelection() == wxT("choice") && | |
252 | listBox->GetSelection() > -1 ); | |
253 | } | |
254 | ||
255 | void ctCustomPropertyDialog::SetChoices(const wxArrayString& choices) | |
256 | { | |
257 | wxListBox* listBox = (wxListBox* ) FindWindow(ID_PROPERTY_CHOICES); | |
258 | size_t i, len = choices.GetCount(); | |
259 | for (i = 0; i < len; i++) | |
260 | listBox->Append(m_choices[i]); | |
261 | } |