]> git.saurik.com Git - wxWidgets.git/blame - samples/proplist/proplist.cpp
Compilation fix
[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
2f6c54eb 9// Licence: wxWindows license
e3a43801
JS
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
600683ca 50 m_mainFrame = new MyFrame(NULL, _T("wxPropertySheet Demo"), wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME_STYLE);
e3a43801
JS
51
52 // Make a menubar
53 wxMenu *file_menu = new wxMenu;
600683ca
MB
54 file_menu->Append(PROPERTY_TEST_DIALOG_LIST, _T("Test property list &dialog..."));
55 file_menu->Append(PROPERTY_TEST_FRAME_LIST, _T("Test property list &frame..."));
e3a43801 56 file_menu->AppendSeparator();
600683ca
MB
57 file_menu->Append(PROPERTY_TEST_DIALOG_FORM, _T("Test property form d&ialog..."));
58 file_menu->Append(PROPERTY_TEST_FRAME_FORM, _T("Test property form f&rame..."));
e3a43801 59 file_menu->AppendSeparator();
600683ca 60 file_menu->Append(PROPERTY_QUIT, _T("E&xit"));
e3a43801
JS
61
62 wxMenu *help_menu = new wxMenu;
600683ca 63 help_menu->Append(PROPERTY_ABOUT, _T("&About"));
e3a43801
JS
64
65 wxMenuBar *menu_bar = new wxMenuBar;
66
600683ca
MB
67 menu_bar->Append(file_menu, _T("&File"));
68 menu_bar->Append(help_menu, _T("&Help"));
e3a43801
JS
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{
600683ca 136 (void)wxMessageBox(_T("Property Classes Demo\nAuthor: Julian Smart"), _T("About Property Classes Test"));
e3a43801
JS
137}
138
139void MyApp::RegisterValidators(void)
140{
600683ca
MB
141 myListValidatorRegistry.RegisterValidator((wxString)_T("real"), new wxRealListValidator);
142 myListValidatorRegistry.RegisterValidator((wxString)_T("string"), new wxStringListValidator);
143 myListValidatorRegistry.RegisterValidator((wxString)_T("integer"), new wxIntegerListValidator);
144 myListValidatorRegistry.RegisterValidator((wxString)_T("bool"), new wxBoolListValidator);
145 myListValidatorRegistry.RegisterValidator((wxString)_T("stringlist"), new wxListOfStringsListValidator);
146
147 myFormValidatorRegistry.RegisterValidator((wxString)_T("real"), new wxRealFormValidator);
148 myFormValidatorRegistry.RegisterValidator((wxString)_T("string"), new wxStringFormValidator);
149 myFormValidatorRegistry.RegisterValidator((wxString)_T("integer"), new wxIntegerFormValidator);
150 myFormValidatorRegistry.RegisterValidator((wxString)_T("bool"), new wxBoolFormValidator);
e3a43801
JS
151}
152
153void MyApp::PropertyListTest(bool useDialog)
154{
2f6c54eb
VZ
155 if (m_childWindow)
156 return;
157
158 wxPropertySheet *sheet = new wxPropertySheet;
159
600683ca
MB
160 sheet->AddProperty(new wxProperty(_T("fred"), 1.0, _T("real")));
161 sheet->AddProperty(new wxProperty(_T("tough choice"), (bool)TRUE, _T("bool")));
162 sheet->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerListValidator(-50, 50)));
163 sheet->AddProperty(new wxProperty(_T("bill"), 25.0, _T("real"), new wxRealListValidator(0.0, 100.0)));
164 sheet->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string")));
165 sheet->AddProperty(new wxProperty(_T("bitmap"), _T("none"), _T("string"), new wxFilenameListValidator(_T("Select a bitmap file"), _T("*.bmp"))));
2f6c54eb 166 wxStringList *strings = new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL);
600683ca 167 sheet->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringListValidator(strings)));
2f6c54eb
VZ
168
169 wxStringList *strings2 = new wxStringList(wxT("earth"), wxT("fire"), wxT("wind"), wxT("water"), NULL);
600683ca 170 sheet->AddProperty(new wxProperty(_T("string list"), strings2, _T("stringlist")));
2f6c54eb
VZ
171
172 wxPropertyListView *view = new wxPropertyListView
173 (
174 NULL,
175 wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS
176 |wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES
177 );
178
179 wxDialog *propDialog = NULL;
180 wxPropertyListFrame *propFrame = NULL;
181 if (useDialog)
182 {
600683ca 183 propDialog = new PropListDialog(view, NULL, _T("Property Sheet Test"),
2f6c54eb
VZ
184 wxPoint(-1, -1), wxSize(400, 500), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODELESS);
185 m_childWindow = propDialog;
186 }
187 else
188 {
600683ca 189 propFrame = new PropListFrame(view, NULL, _T("Property Sheet Test"), wxPoint(-1, -1), wxSize(400, 500));
2f6c54eb
VZ
190 m_childWindow = propFrame;
191 }
192
193 view->AddRegistry(&myListValidatorRegistry);
194
195 if (useDialog)
196 {
197 view->ShowView(sheet, (wxPanel *)propDialog);
198 propDialog->Centre(wxBOTH);
199 propDialog->Show(TRUE);
200 }
201 else
202 {
203 propFrame->Initialize();
204 view->ShowView(sheet, propFrame->GetPropertyPanel());
205
206 propFrame->Centre(wxBOTH);
207 propFrame->Show(TRUE);
208 }
e3a43801
JS
209}
210
211void MyApp::PropertyFormTest(bool useDialog)
212{
2f6c54eb
VZ
213 if (m_childWindow)
214 return;
215
216 wxPropertySheet *sheet = new wxPropertySheet;
217
600683ca
MB
218 sheet->AddProperty(new wxProperty(_T("fred"), 25.0, _T("real"), new wxRealFormValidator(0.0, 100.0)));
219 sheet->AddProperty(new wxProperty(_T("tough choice"), (bool)TRUE, _T("bool")));
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")));
2f6c54eb 222 wxStringList *strings = new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL);
600683ca 223 sheet->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringFormValidator(strings)));
2f6c54eb
VZ
224
225 wxPropertyFormView *view = new wxPropertyFormView(NULL);
226
227 wxDialog *propDialog = NULL;
228 wxPropertyFormFrame *propFrame = NULL;
229
230 if (useDialog)
231 {
600683ca 232 propDialog = new PropFormDialog(view, NULL, _T("Property Form Test"),
2f6c54eb
VZ
233 wxPoint(-1, -1), wxSize(380, 250), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL);
234 m_childWindow = propDialog;
235 }
236 else
237 {
600683ca 238 propFrame = new PropFormFrame(view, NULL, _T("Property Form Test"),
2f6c54eb
VZ
239 wxPoint(-1, -1), wxSize(380, 250));
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;
1b9315eb
JS
256
257#if 0
2f6c54eb
VZ
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);
1b9315eb 265
2f6c54eb
VZ
266 panel->SetConstraints(c);
267 }
1b9315eb
JS
268#endif
269
2f6c54eb 270 // Add items to the panel
600683ca
MB
271 wxButton *okButton = new wxButton(panel, wxID_OK, _T("OK"), wxPoint(-1, -1),
272 wxSize(80, 26), 0, wxDefaultValidator, _T("ok"));
273 wxButton *cancelButton = new wxButton(panel, wxID_CANCEL, _T("Cancel"), wxPoint(-1, -1),
274 wxSize(80, 26), 0, wxDefaultValidator, _T("cancel"));
275 wxButton *updateButton = new wxButton(panel, wxID_PROP_UPDATE, _T("Update"), wxPoint(-1, -1),
276 wxSize(80, 26), 0, wxDefaultValidator, _T("update"));
277 wxButton *revertButton = new wxButton(panel, wxID_PROP_REVERT, _T("Revert"), wxPoint(-1, -1),
278 wxSize(80, 26), 0, wxDefaultValidator, _T("revert"));
2f6c54eb
VZ
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
600683ca
MB
309 wxTextCtrl *text = new wxTextCtrl(panel, -1, _T("Fred"), wxPoint(-1, -1), wxSize(
310 200, -1), 0, wxDefaultValidator, _T("fred"));
2f6c54eb
VZ
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
600683ca
MB
319 wxCheckBox *checkBox = new wxCheckBox(panel, -1, _T("Yes or no"), wxPoint(-1, -1),
320 wxSize(-1, -1), 0, wxDefaultValidator, _T("tough choice"));
2f6c54eb
VZ
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
1b9315eb 329 wxSlider *slider = new wxSlider(panel, -1, -50, 50, 150, wxPoint(-1, -1),
600683ca 330 wxSize(200,10), 0, wxDefaultValidator, _T("ian"));
1b9315eb 331
2f6c54eb
VZ
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
339 wxListBox *listBox = new wxListBox(panel, -1, wxPoint(-1, -1),
600683ca 340 wxSize(200, 100), 0, NULL, 0, wxDefaultValidator, _T("constrained"));
2f6c54eb
VZ
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
351 panel->SetAutoLayout(TRUE);
352
353 view->ShowView(sheet, panel);
354 view->AssociateNames();
355 view->TransferToDialog();
356
357 if (useDialog) {
358 propDialog->Layout();
359 propDialog->Centre(wxBOTH);
360 propDialog->Show(TRUE);
361 }
362 else
363 {
364 // panel->Layout();
365 propFrame->Centre(wxBOTH);
366 propFrame->Show(TRUE);
367 }
e3a43801
JS
368}
369
370BEGIN_EVENT_TABLE(PropListFrame, wxPropertyListFrame)
371 EVT_CLOSE(PropListFrame::OnCloseWindow)
372END_EVENT_TABLE()
373
374void PropListFrame::OnCloseWindow(wxCloseEvent& event)
375{
376 wxGetApp().m_childWindow = NULL;
377
378 wxPropertyListFrame::OnCloseWindow(event);
379}
380
381BEGIN_EVENT_TABLE(PropListDialog, wxPropertyListDialog)
382 EVT_CLOSE(PropListDialog::OnCloseWindow)
383END_EVENT_TABLE()
384
385void PropListDialog::OnCloseWindow(wxCloseEvent& event)
386{
387 wxGetApp().m_childWindow = NULL;
388
389 wxPropertyListDialog::OnCloseWindow(event);
390}
391
392BEGIN_EVENT_TABLE(PropFormFrame, wxPropertyFormFrame)
393 EVT_CLOSE(PropFormFrame::OnCloseWindow)
1b9315eb 394 EVT_SIZE(PropFormFrame::OnSize)
e3a43801
JS
395END_EVENT_TABLE()
396
397void PropFormFrame::OnCloseWindow(wxCloseEvent& event)
398{
399 wxGetApp().m_childWindow = NULL;
400
401 wxPropertyFormFrame::OnCloseWindow(event);
402}
403
1b9315eb
JS
404void PropFormFrame::OnSize(wxSizeEvent& event)
405{
406 wxPropertyFormFrame::OnSize(event);
407 GetPropertyPanel()->Layout();
408}
409
e3a43801
JS
410BEGIN_EVENT_TABLE(PropFormDialog, wxPropertyFormDialog)
411 EVT_CLOSE(PropFormDialog::OnCloseWindow)
412END_EVENT_TABLE()
413
414void PropFormDialog::OnCloseWindow(wxCloseEvent& event)
415{
416 wxGetApp().m_childWindow = NULL;
417
418 wxPropertyFormDialog::OnCloseWindow(event);
419}
420