]> git.saurik.com Git - wxWidgets.git/blame - samples/proplist/proplist.cpp
wxFileSelector should have file name only, not path, passed to 3rd arg
[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__
30b64191 13#pragma implementation "proplist.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
30b64191 27#include "proplist.h"
e3a43801 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,
cf1f0870 169 wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL |
e3a43801
JS
170 wxPROP_BUTTON_CHECK_CROSS|wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES);
171
172 wxDialog *propDialog = NULL;
173 wxPropertyListFrame *propFrame = NULL;
174 if (useDialog)
175 {
176 propDialog = new PropListDialog(view, NULL, "Property Sheet Test",
177 wxPoint(-1, -1), wxSize(400, 500), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODELESS);
178 m_childWindow = propDialog;
179 }
180 else
181 {
182 propFrame = new PropListFrame(view, NULL, "Property Sheet Test", wxPoint(-1, -1), wxSize(400, 500));
183 m_childWindow = propFrame;
184 }
185
186 view->AddRegistry(&myListValidatorRegistry);
187
188 if (useDialog)
189 {
190 view->ShowView(sheet, propDialog);
191 propDialog->Centre(wxBOTH);
192 propDialog->Show(TRUE);
193 }
194 else
195 {
196 propFrame->Initialize();
197 view->ShowView(sheet, propFrame->GetPropertyPanel());
198
199 propFrame->Centre(wxBOTH);
200 propFrame->Show(TRUE);
201 }
202}
203
204void MyApp::PropertyFormTest(bool useDialog)
205{
206 if (m_childWindow)
207 return;
208
e3a43801
JS
209 wxPropertySheet *sheet = new wxPropertySheet;
210
211 sheet->AddProperty(new wxProperty("fred", 25.0, "real", new wxRealFormValidator(0.0, 100.0)));
212 sheet->AddProperty(new wxProperty("tough choice", (bool)TRUE, "bool"));
213 sheet->AddProperty(new wxProperty("ian", (long)45, "integer", new wxIntegerFormValidator(-50, 50)));
214 sheet->AddProperty(new wxProperty("julian", "one", "string"));
215 wxStringList *strings = new wxStringList("one", "two", "three", NULL);
216 sheet->AddProperty(new wxProperty("constrained", "one", "string", new wxStringFormValidator(strings)));
217
218 wxPropertyFormView *view = new wxPropertyFormView(NULL);
219
1b9315eb 220 wxDialog *propDialog = NULL;
e3a43801
JS
221 wxPropertyFormFrame *propFrame = NULL;
222 if (useDialog)
223 {
1b9315eb
JS
224 propDialog = new PropFormDialog(view, NULL, "Property Form Test",
225 wxPoint(-1, -1), wxSize(380, 250), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL);
e3a43801
JS
226 m_childWindow = propDialog;
227 }
228 else
229 {
1b9315eb
JS
230 propFrame = new PropFormFrame(view, NULL, "Property Form Test", wxPoint(-1,
231 -1), wxSize(380, 250));
e3a43801
JS
232 propFrame->Initialize();
233 m_childWindow = propFrame;
234 }
235
236 wxPanel *panel = propDialog ? propDialog : propFrame->GetPropertyPanel();
1b9315eb
JS
237 wxLayoutConstraints* c;
238
239#if 0
240 if (!propDialog)
241 {
242 c = new wxLayoutConstraints;
243 c->left.SameAs(m_childWindow, wxLeft, 4);
244 c->right.SameAs(m_childWindow, wxRight, 4);
245 c->top.SameAs(m_childWindow, wxTop, 4);
246 c->bottom.SameAs(m_childWindow, wxBottom, 40);
247
248 panel->SetConstraints(c);
249 }
250#endif
251
e3a43801 252 // Add items to the panel
1b9315eb
JS
253 wxButton *okButton = new wxButton(panel, wxID_OK, "OK", wxPoint(-1, -1),
254 wxSize(80, 26), 0, wxDefaultValidator, "ok");
255 wxButton *cancelButton = new wxButton(panel, wxID_CANCEL, "Cancel", wxPoint(-1, -1),
256 wxSize(80, 26), 0, wxDefaultValidator, "cancel");
257 wxButton *updateButton = new wxButton(panel, wxID_PROP_UPDATE, "Update", wxPoint(-1, -1),
258 wxSize(80, 26), 0, wxDefaultValidator, "update");
259 wxButton *revertButton = new wxButton(panel, wxID_PROP_REVERT, "Revert", wxPoint(-1, -1),
260 wxSize(80, 26), 0, wxDefaultValidator, "revert");
261
262 c = new wxLayoutConstraints;
263 c->right.SameAs(panel, wxRight, 4);
264 c->bottom.SameAs(panel, wxBottom, 4);
265 c->height.AsIs();
266 c->width.AsIs();
267 revertButton->SetConstraints(c);
268
269 c = new wxLayoutConstraints;
270 c->right.SameAs(revertButton, wxLeft, 4);
271 c->bottom.SameAs(panel, wxBottom, 4);
272 c->height.AsIs();
273 c->width.AsIs();
274 updateButton->SetConstraints(c);
275
276 c = new wxLayoutConstraints;
277 c->right.SameAs(updateButton, wxLeft, 4);
278 c->bottom.SameAs(panel, wxBottom, 4);
279 c->height.AsIs();
280 c->width.AsIs();
281 cancelButton->SetConstraints(c);
282
283 c = new wxLayoutConstraints;
284 c->right.SameAs(cancelButton, wxLeft, 4);
285 c->bottom.SameAs(panel, wxBottom, 4);
286 c->height.AsIs();
287 c->width.AsIs();
288 okButton->SetConstraints(c);
289
290 // The name of this text item matches the "fred" property
291 wxTextCtrl *text = new wxTextCtrl(panel, -1, "Fred", wxPoint(-1, -1), wxSize(
292 200, -1), 0, wxDefaultValidator, "fred");
e3a43801 293
1b9315eb
JS
294 c = new wxLayoutConstraints;
295 c->left.SameAs(panel, wxLeft, 4);
296 c->top.SameAs(panel, wxTop, 4);
297 c->height.AsIs();
298 c->width.AsIs();
299 text->SetConstraints(c);
300
301 wxCheckBox *checkBox = new wxCheckBox(panel, -1, "Yes or no", wxPoint(-1, -1),
302 wxSize(-1, -1), 0, wxDefaultValidator, "tough choice");
303
304 c = new wxLayoutConstraints;
305 c->left.SameAs(text, wxRight, 20);
306 c->top.SameAs(panel, wxTop, 4);
307 c->height.AsIs();
308 c->width.AsIs();
309 checkBox->SetConstraints(c);
e3a43801 310
1b9315eb
JS
311 wxSlider *slider = new wxSlider(panel, -1, -50, 50, 150, wxPoint(-1, -1),
312 wxSize(200,10), 0, wxDefaultValidator, "ian");
313
314 c = new wxLayoutConstraints;
315 c->left.SameAs(panel, wxLeft, 4);
316 c->top.SameAs(text, wxBottom, 10);
317 c->height.AsIs();
318 c->width.AsIs();
319 slider->SetConstraints(c);
320
321 wxListBox *listBox = new wxListBox(panel, -1, wxPoint(-1, -1), wxSize(200, 100),
322 0, NULL, 0, wxDefaultValidator, "constrained");
323
324 c = new wxLayoutConstraints;
325 c->left.SameAs(panel, wxLeft, 4);
326 c->top.SameAs(slider, wxBottom, 10);
327 c->height.AsIs();
328 c->width.AsIs();
329 listBox->SetConstraints(c);
e3a43801
JS
330
331 view->AddRegistry(&myFormValidatorRegistry);
332
1b9315eb
JS
333 panel->SetAutoLayout(TRUE);
334
335 view->ShowView(sheet, panel);
336 view->AssociateNames();
337 view->TransferToDialog();
338
339 if (useDialog) {
340 propDialog->Layout();
e3a43801
JS
341 propDialog->Centre(wxBOTH);
342 propDialog->Show(TRUE);
1b9315eb
JS
343 } else {
344 // panel->Layout();
e3a43801
JS
345 propFrame->Centre(wxBOTH);
346 propFrame->Show(TRUE);
347 }
e3a43801
JS
348}
349
350BEGIN_EVENT_TABLE(PropListFrame, wxPropertyListFrame)
351 EVT_CLOSE(PropListFrame::OnCloseWindow)
352END_EVENT_TABLE()
353
354void PropListFrame::OnCloseWindow(wxCloseEvent& event)
355{
356 wxGetApp().m_childWindow = NULL;
357
358 wxPropertyListFrame::OnCloseWindow(event);
359}
360
361BEGIN_EVENT_TABLE(PropListDialog, wxPropertyListDialog)
362 EVT_CLOSE(PropListDialog::OnCloseWindow)
363END_EVENT_TABLE()
364
365void PropListDialog::OnCloseWindow(wxCloseEvent& event)
366{
367 wxGetApp().m_childWindow = NULL;
368
369 wxPropertyListDialog::OnCloseWindow(event);
370}
371
372BEGIN_EVENT_TABLE(PropFormFrame, wxPropertyFormFrame)
373 EVT_CLOSE(PropFormFrame::OnCloseWindow)
1b9315eb 374 EVT_SIZE(PropFormFrame::OnSize)
e3a43801
JS
375END_EVENT_TABLE()
376
377void PropFormFrame::OnCloseWindow(wxCloseEvent& event)
378{
379 wxGetApp().m_childWindow = NULL;
380
381 wxPropertyFormFrame::OnCloseWindow(event);
382}
383
1b9315eb
JS
384void PropFormFrame::OnSize(wxSizeEvent& event)
385{
386 wxPropertyFormFrame::OnSize(event);
387 GetPropertyPanel()->Layout();
388}
389
e3a43801
JS
390BEGIN_EVENT_TABLE(PropFormDialog, wxPropertyFormDialog)
391 EVT_CLOSE(PropFormDialog::OnCloseWindow)
392END_EVENT_TABLE()
393
394void PropFormDialog::OnCloseWindow(wxCloseEvent& event)
395{
396 wxGetApp().m_childWindow = NULL;
397
398 wxPropertyFormDialog::OnCloseWindow(event);
399}
400