]>
Commit | Line | Data |
---|---|---|
07831c16 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: proplist.cpp | |
3 | // Purpose: Property sheet test implementation | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "proplist_sample.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 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
7c9955d1 | 27 | #include "wx/deprecated/setup.h" |
07831c16 JS |
28 | |
29 | #if !wxUSE_PROPSHEET | |
7c9955d1 | 30 | #error Please set wxUSE_PROPSHEET to 1 in contrib/include/wx/deprecated/setup.h and recompile. |
07831c16 JS |
31 | #endif |
32 | ||
33 | #include "proplist.h" | |
34 | ||
35 | IMPLEMENT_APP(MyApp) | |
36 | ||
37 | wxPropertyValidatorRegistry myListValidatorRegistry; | |
38 | wxPropertyValidatorRegistry myFormValidatorRegistry; | |
39 | ||
40 | MyApp::MyApp(void) | |
41 | { | |
42 | m_childWindow = NULL; | |
43 | m_mainFrame = NULL; | |
44 | } | |
45 | ||
46 | bool MyApp::OnInit(void) | |
47 | { | |
48 | RegisterValidators(); | |
49 | ||
50 | // Create the main frame window | |
51 | m_mainFrame = new MyFrame(NULL, _T("wxPropertySheet Demo"), wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME_STYLE); | |
52 | ||
53 | // Make a menubar | |
54 | wxMenu *file_menu = new wxMenu; | |
55 | file_menu->Append(PROPERTY_TEST_DIALOG_LIST, _T("Test property list &dialog...")); | |
56 | file_menu->Append(PROPERTY_TEST_FRAME_LIST, _T("Test property list &frame...")); | |
57 | file_menu->AppendSeparator(); | |
58 | file_menu->Append(PROPERTY_TEST_DIALOG_FORM, _T("Test property form d&ialog...")); | |
59 | file_menu->Append(PROPERTY_TEST_FRAME_FORM, _T("Test property form f&rame...")); | |
60 | file_menu->AppendSeparator(); | |
61 | file_menu->Append(PROPERTY_QUIT, _T("E&xit")); | |
62 | ||
63 | wxMenu *help_menu = new wxMenu; | |
64 | help_menu->Append(PROPERTY_ABOUT, _T("&About")); | |
65 | ||
66 | wxMenuBar *menu_bar = new wxMenuBar; | |
67 | ||
68 | menu_bar->Append(file_menu, _T("&File")); | |
69 | menu_bar->Append(help_menu, _T("&Help")); | |
70 | ||
71 | // Associate the menu bar with the frame | |
72 | m_mainFrame->SetMenuBar(menu_bar); | |
73 | ||
74 | m_mainFrame->Centre(wxBOTH); | |
b5982058 | 75 | m_mainFrame->Show(true); |
07831c16 JS |
76 | |
77 | SetTopWindow(m_mainFrame); | |
dabbc6a5 | 78 | |
b5982058 | 79 | return true; |
07831c16 JS |
80 | } |
81 | ||
82 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
83 | EVT_CLOSE(MyFrame::OnCloseWindow) | |
84 | EVT_MENU(PROPERTY_QUIT, MyFrame::OnQuit) | |
85 | EVT_MENU(PROPERTY_ABOUT, MyFrame::OnAbout) | |
86 | EVT_MENU(PROPERTY_TEST_DIALOG_LIST, MyFrame::OnDialogList) | |
87 | EVT_MENU(PROPERTY_TEST_FRAME_LIST, MyFrame::OnFrameList) | |
88 | EVT_MENU(PROPERTY_TEST_DIALOG_FORM, MyFrame::OnDialogForm) | |
89 | EVT_MENU(PROPERTY_TEST_FRAME_FORM, MyFrame::OnFrameForm) | |
90 | END_EVENT_TABLE() | |
91 | ||
92 | // Define my frame constructor | |
93 | MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size, long type): | |
b5982058 | 94 | wxFrame(frame, wxID_ANY, title, pos, size, type) |
07831c16 JS |
95 | { |
96 | } | |
97 | ||
98 | // Define the behaviour for the frame closing | |
99 | // - must delete all frames except for the main one. | |
8552e6f0 | 100 | void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
07831c16 JS |
101 | { |
102 | if (wxGetApp().m_childWindow) | |
103 | { | |
b5982058 | 104 | wxGetApp().m_childWindow->Close(true); |
07831c16 JS |
105 | } |
106 | ||
107 | Destroy(); | |
108 | } | |
109 | ||
8552e6f0 | 110 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
07831c16 | 111 | { |
b5982058 | 112 | Close(true); |
07831c16 JS |
113 | } |
114 | ||
8552e6f0 | 115 | void MyFrame::OnDialogList(wxCommandEvent& WXUNUSED(event)) |
07831c16 | 116 | { |
b5982058 | 117 | wxGetApp().PropertyListTest(true); |
07831c16 JS |
118 | } |
119 | ||
8552e6f0 | 120 | void MyFrame::OnFrameList(wxCommandEvent& WXUNUSED(event)) |
07831c16 | 121 | { |
b5982058 | 122 | wxGetApp().PropertyListTest(false); |
07831c16 JS |
123 | } |
124 | ||
8552e6f0 | 125 | void MyFrame::OnDialogForm(wxCommandEvent& WXUNUSED(event)) |
07831c16 | 126 | { |
b5982058 | 127 | wxGetApp().PropertyFormTest(true); |
07831c16 JS |
128 | } |
129 | ||
8552e6f0 | 130 | void MyFrame::OnFrameForm(wxCommandEvent& WXUNUSED(event)) |
07831c16 | 131 | { |
b5982058 | 132 | wxGetApp().PropertyFormTest(false); |
07831c16 JS |
133 | } |
134 | ||
8552e6f0 | 135 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
07831c16 JS |
136 | { |
137 | (void)wxMessageBox(_T("Property Classes Demo\nAuthor: Julian Smart"), _T("About Property Classes Test")); | |
138 | } | |
139 | ||
140 | void MyApp::RegisterValidators(void) | |
141 | { | |
142 | myListValidatorRegistry.RegisterValidator((wxString)_T("real"), new wxRealListValidator); | |
143 | myListValidatorRegistry.RegisterValidator((wxString)_T("string"), new wxStringListValidator); | |
144 | myListValidatorRegistry.RegisterValidator((wxString)_T("integer"), new wxIntegerListValidator); | |
145 | myListValidatorRegistry.RegisterValidator((wxString)_T("bool"), new wxBoolListValidator); | |
146 | myListValidatorRegistry.RegisterValidator((wxString)_T("stringlist"), new wxListOfStringsListValidator); | |
147 | ||
148 | myFormValidatorRegistry.RegisterValidator((wxString)_T("real"), new wxRealFormValidator); | |
149 | myFormValidatorRegistry.RegisterValidator((wxString)_T("string"), new wxStringFormValidator); | |
150 | myFormValidatorRegistry.RegisterValidator((wxString)_T("integer"), new wxIntegerFormValidator); | |
151 | myFormValidatorRegistry.RegisterValidator((wxString)_T("bool"), new wxBoolFormValidator); | |
152 | } | |
153 | ||
154 | void MyApp::PropertyListTest(bool useDialog) | |
155 | { | |
156 | if (m_childWindow) | |
157 | return; | |
158 | ||
159 | wxPropertySheet *sheet = new wxPropertySheet; | |
160 | ||
161 | sheet->AddProperty(new wxProperty(_T("fred"), 1.0, _T("real"))); | |
b5982058 | 162 | sheet->AddProperty(new wxProperty(_T("tough choice"), true, _T("bool"))); |
07831c16 JS |
163 | sheet->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerListValidator(-50, 50))); |
164 | sheet->AddProperty(new wxProperty(_T("bill"), 25.0, _T("real"), new wxRealListValidator(0.0, 100.0))); | |
165 | sheet->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string"))); | |
166 | sheet->AddProperty(new wxProperty(_T("bitmap"), _T("none"), _T("string"), new wxFilenameListValidator(_T("Select a bitmap file"), _T("*.bmp")))); | |
167 | wxStringList *strings = new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL); | |
168 | sheet->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringListValidator(strings))); | |
169 | ||
170 | wxStringList *strings2 = new wxStringList(wxT("earth"), wxT("fire"), wxT("wind"), wxT("water"), NULL); | |
171 | sheet->AddProperty(new wxProperty(_T("string list"), strings2, _T("stringlist"))); | |
172 | ||
173 | wxPropertyListView *view = new wxPropertyListView | |
174 | ( | |
175 | NULL, | |
176 | wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS | |
b5982058 | 177 | | wxPROP_DYNAMIC_VALUE_FIELD | wxPROP_PULLDOWN | wxPROP_SHOWVALUES |
07831c16 JS |
178 | ); |
179 | ||
b5982058 VS |
180 | PropListDialog *propDialog = NULL; |
181 | PropListFrame *propFrame = NULL; | |
07831c16 JS |
182 | if (useDialog) |
183 | { | |
184 | propDialog = new PropListDialog(view, NULL, _T("Property Sheet Test"), | |
2a21ac15 | 185 | wxDefaultPosition, wxSize(400, 500)); |
07831c16 JS |
186 | m_childWindow = propDialog; |
187 | } | |
188 | else | |
189 | { | |
b5982058 VS |
190 | propFrame = new PropListFrame(view, NULL, _T("Property Sheet Test"), |
191 | wxDefaultPosition, wxSize(400, 500)); | |
07831c16 JS |
192 | m_childWindow = propFrame; |
193 | } | |
194 | ||
195 | view->AddRegistry(&myListValidatorRegistry); | |
196 | ||
197 | if (useDialog) | |
198 | { | |
199 | view->ShowView(sheet, (wxPanel *)propDialog); | |
07831c16 JS |
200 | } |
201 | else | |
202 | { | |
203 | propFrame->Initialize(); | |
204 | view->ShowView(sheet, propFrame->GetPropertyPanel()); | |
07831c16 | 205 | } |
b5982058 VS |
206 | |
207 | m_childWindow->Centre(wxBOTH); | |
208 | m_childWindow->Show(true); | |
07831c16 JS |
209 | } |
210 | ||
211 | void MyApp::PropertyFormTest(bool useDialog) | |
212 | { | |
213 | if (m_childWindow) | |
214 | return; | |
215 | ||
216 | wxPropertySheet *sheet = new wxPropertySheet; | |
217 | ||
218 | sheet->AddProperty(new wxProperty(_T("fred"), 25.0, _T("real"), new wxRealFormValidator(0.0, 100.0))); | |
b5982058 | 219 | sheet->AddProperty(new wxProperty(_T("tough choice"), true, _T("bool"))); |
07831c16 JS |
220 | sheet->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerFormValidator(-50, 50))); |
221 | sheet->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string"))); | |
222 | wxStringList *strings = new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL); | |
223 | sheet->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringFormValidator(strings))); | |
224 | ||
225 | wxPropertyFormView *view = new wxPropertyFormView(NULL); | |
226 | ||
227 | wxDialog *propDialog = NULL; | |
228 | wxPropertyFormFrame *propFrame = NULL; | |
229 | ||
230 | if (useDialog) | |
231 | { | |
232 | propDialog = new PropFormDialog(view, NULL, _T("Property Form Test"), | |
2a21ac15 | 233 | wxDefaultPosition, wxSize(380, 250)); |
07831c16 JS |
234 | m_childWindow = propDialog; |
235 | } | |
236 | else | |
237 | { | |
238 | propFrame = new PropFormFrame(view, NULL, _T("Property Form Test"), | |
b5982058 | 239 | wxDefaultPosition, wxSize(380, 250)); |
07831c16 JS |
240 | propFrame->Initialize(); |
241 | m_childWindow = propFrame; | |
242 | } | |
243 | ||
244 | // BCC32 does not like ?: | |
245 | wxWindow *panel ; | |
246 | if ( propDialog ) | |
247 | { | |
248 | panel = propDialog; | |
249 | } | |
250 | else | |
251 | { | |
252 | panel = propFrame->GetPropertyPanel() ; | |
253 | } | |
254 | ||
255 | wxLayoutConstraints* c; | |
256 | ||
257 | #if 0 | |
258 | if (!propDialog) | |
259 | { | |
260 | c = new wxLayoutConstraints; | |
261 | c->left.SameAs(m_childWindow, wxLeft, 4); | |
262 | c->right.SameAs(m_childWindow, wxRight, 4); | |
263 | c->top.SameAs(m_childWindow, wxTop, 4); | |
264 | c->bottom.SameAs(m_childWindow, wxBottom, 40); | |
265 | ||
266 | panel->SetConstraints(c); | |
267 | } | |
268 | #endif | |
dabbc6a5 | 269 | |
07831c16 | 270 | // Add items to the panel |
b5982058 | 271 | wxButton *okButton = new wxButton(panel, wxID_OK, _T("OK"), wxDefaultPosition, |
07831c16 | 272 | wxSize(80, 26), 0, wxDefaultValidator, _T("ok")); |
b5982058 | 273 | wxButton *cancelButton = new wxButton(panel, wxID_CANCEL, _T("Cancel"), wxDefaultPosition, |
07831c16 | 274 | wxSize(80, 26), 0, wxDefaultValidator, _T("cancel")); |
b5982058 | 275 | wxButton *updateButton = new wxButton(panel, wxID_PROP_UPDATE, _T("Update"), wxDefaultPosition, |
07831c16 | 276 | wxSize(80, 26), 0, wxDefaultValidator, _T("update")); |
b5982058 | 277 | wxButton *revertButton = new wxButton(panel, wxID_PROP_REVERT, _T("Revert"), wxDefaultPosition, |
07831c16 JS |
278 | wxSize(80, 26), 0, wxDefaultValidator, _T("revert")); |
279 | ||
280 | c = new wxLayoutConstraints; | |
281 | c->right.SameAs(panel, wxRight, 4); | |
282 | c->bottom.SameAs(panel, wxBottom, 4); | |
283 | c->height.AsIs(); | |
284 | c->width.AsIs(); | |
285 | revertButton->SetConstraints(c); | |
286 | ||
287 | c = new wxLayoutConstraints; | |
288 | c->right.SameAs(revertButton, wxLeft, 4); | |
289 | c->bottom.SameAs(panel, wxBottom, 4); | |
290 | c->height.AsIs(); | |
291 | c->width.AsIs(); | |
292 | updateButton->SetConstraints(c); | |
293 | ||
294 | c = new wxLayoutConstraints; | |
295 | c->right.SameAs(updateButton, wxLeft, 4); | |
296 | c->bottom.SameAs(panel, wxBottom, 4); | |
297 | c->height.AsIs(); | |
298 | c->width.AsIs(); | |
299 | cancelButton->SetConstraints(c); | |
300 | ||
301 | c = new wxLayoutConstraints; | |
302 | c->right.SameAs(cancelButton, wxLeft, 4); | |
303 | c->bottom.SameAs(panel, wxBottom, 4); | |
304 | c->height.AsIs(); | |
305 | c->width.AsIs(); | |
306 | okButton->SetConstraints(c); | |
307 | ||
308 | // The name of this text item matches the "fred" property | |
dabbc6a5 | 309 | wxTextCtrl *text = new wxTextCtrl(panel, wxID_ANY, _T("Fred"), wxDefaultPosition, |
422d0ff0 | 310 | wxSize( 200, wxDefaultCoord), 0, wxDefaultValidator, _T("fred")); |
07831c16 JS |
311 | |
312 | c = new wxLayoutConstraints; | |
313 | c->left.SameAs(panel, wxLeft, 4); | |
314 | c->top.SameAs(panel, wxTop, 4); | |
315 | c->height.AsIs(); | |
316 | c->width.AsIs(); | |
317 | text->SetConstraints(c); | |
318 | ||
b5982058 VS |
319 | wxCheckBox *checkBox = new wxCheckBox(panel, wxID_ANY, _T("Yes or no"), wxDefaultPosition, |
320 | wxDefaultSize, 0, wxDefaultValidator, _T("tough choice")); | |
07831c16 JS |
321 | |
322 | c = new wxLayoutConstraints; | |
323 | c->left.SameAs(text, wxRight, 20); | |
324 | c->top.SameAs(panel, wxTop, 4); | |
325 | c->height.AsIs(); | |
326 | c->width.AsIs(); | |
327 | checkBox->SetConstraints(c); | |
328 | ||
b5982058 | 329 | wxSlider *slider = new wxSlider(panel, wxID_ANY, -50, 50, 150, wxDefaultPosition, |
07831c16 JS |
330 | wxSize(200,10), 0, wxDefaultValidator, _T("ian")); |
331 | ||
332 | c = new wxLayoutConstraints; | |
333 | c->left.SameAs(panel, wxLeft, 4); | |
334 | c->top.SameAs(text, wxBottom, 10); | |
335 | c->height.AsIs(); | |
336 | c->width.AsIs(); | |
337 | slider->SetConstraints(c); | |
338 | ||
b5982058 | 339 | wxListBox *listBox = new wxListBox(panel, wxID_ANY, wxDefaultPosition, |
07831c16 JS |
340 | wxSize(200, 100), 0, NULL, 0, wxDefaultValidator, _T("constrained")); |
341 | ||
342 | c = new wxLayoutConstraints; | |
343 | c->left.SameAs(panel, wxLeft, 4); | |
344 | c->top.SameAs(slider, wxBottom, 10); | |
345 | c->height.AsIs(); | |
346 | c->width.AsIs(); | |
347 | listBox->SetConstraints(c); | |
348 | ||
349 | view->AddRegistry(&myFormValidatorRegistry); | |
350 | ||
b5982058 | 351 | panel->SetAutoLayout(true); |
07831c16 JS |
352 | |
353 | view->ShowView(sheet, panel); | |
354 | view->AssociateNames(); | |
355 | view->TransferToDialog(); | |
356 | ||
357 | if (useDialog) { | |
358 | propDialog->Layout(); | |
07831c16 JS |
359 | } |
360 | else | |
361 | { | |
362 | // panel->Layout(); | |
07831c16 | 363 | } |
b5982058 VS |
364 | m_childWindow->Centre(wxBOTH); |
365 | m_childWindow->Show(true); | |
07831c16 JS |
366 | } |
367 | ||
368 | BEGIN_EVENT_TABLE(PropListFrame, wxPropertyListFrame) | |
369 | EVT_CLOSE(PropListFrame::OnCloseWindow) | |
370 | END_EVENT_TABLE() | |
371 | ||
372 | void PropListFrame::OnCloseWindow(wxCloseEvent& event) | |
373 | { | |
374 | wxGetApp().m_childWindow = NULL; | |
375 | ||
376 | wxPropertyListFrame::OnCloseWindow(event); | |
377 | } | |
378 | ||
379 | BEGIN_EVENT_TABLE(PropListDialog, wxPropertyListDialog) | |
380 | EVT_CLOSE(PropListDialog::OnCloseWindow) | |
381 | END_EVENT_TABLE() | |
382 | ||
383 | void PropListDialog::OnCloseWindow(wxCloseEvent& event) | |
384 | { | |
385 | wxGetApp().m_childWindow = NULL; | |
386 | ||
387 | wxPropertyListDialog::OnCloseWindow(event); | |
388 | } | |
389 | ||
390 | BEGIN_EVENT_TABLE(PropFormFrame, wxPropertyFormFrame) | |
391 | EVT_CLOSE(PropFormFrame::OnCloseWindow) | |
392 | EVT_SIZE(PropFormFrame::OnSize) | |
393 | END_EVENT_TABLE() | |
394 | ||
395 | void PropFormFrame::OnCloseWindow(wxCloseEvent& event) | |
396 | { | |
397 | wxGetApp().m_childWindow = NULL; | |
398 | ||
399 | wxPropertyFormFrame::OnCloseWindow(event); | |
400 | } | |
401 | ||
402 | void PropFormFrame::OnSize(wxSizeEvent& event) | |
403 | { | |
404 | wxPropertyFormFrame::OnSize(event); | |
405 | GetPropertyPanel()->Layout(); | |
406 | } | |
407 | ||
408 | BEGIN_EVENT_TABLE(PropFormDialog, wxPropertyFormDialog) | |
409 | EVT_CLOSE(PropFormDialog::OnCloseWindow) | |
410 | END_EVENT_TABLE() | |
411 | ||
412 | void PropFormDialog::OnCloseWindow(wxCloseEvent& event) | |
413 | { | |
414 | wxGetApp().m_childWindow = NULL; | |
415 | ||
416 | wxPropertyFormDialog::OnCloseWindow(event); | |
417 | } | |
418 |