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