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