]> git.saurik.com Git - wxWidgets.git/blame - samples/proplist/test.cpp
added wxImage::CanRead
[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
208#if 0
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
220 wxDialogBox *propDialog = NULL;
221 wxPropertyFormFrame *propFrame = NULL;
222 if (useDialog)
223 {
224 propDialog = new PropFormDialog(view, NULL, "Property Form Test", wxPoint(-1, -1), wxSize(380, 250),
225 wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL);
226 m_childWindow = propDialog;
227 }
228 else
229 {
230 propFrame = new PropFormFrame(view, NULL, "Property Form Test", wxPoint(-1, -1), wxSize(280, 250));
231 propFrame->Initialize();
232 m_childWindow = propFrame;
233 }
234
235 wxPanel *panel = propDialog ? propDialog : propFrame->GetPropertyPanel();
236 panel->SetLabelPosition(wxVERTICAL);
237
238 // Add items to the panel
239
240 (void) new wxButton(panel, -1, "OK", -1, -1, -1, -1, 0, "ok");
241 (void) new wxButton(panel, -1, "Cancel", -1, -1, 80, -1, 0, "cancel");
242 (void) new wxButton(panel, -1, "Update", -1, -1, 80, -1, 0, "update");
243 (void) new wxButton(panel, -1, "Revert", -1, -1, -1, -1, 0, "revert");
244 panel->NewLine();
245
246 // The name of this text item matches the "fred" property
247 (void) new wxText(panel, -1, "Fred", "", -1, -1, 90, -1, 0, "fred");
248 (void) new wxCheckBox(panel, -1, "Yes or no", -1, -1, -1, -1, 0, "tough choice");
249 (void) new wxSlider(panel, -1, "Scale", 0, -50, 50, 150, -1, -1, wxHORIZONTAL, "ian");
250 panel->NewLine();
251 (void) new wxListBox(panel, -1, "Constrained", wxSINGLE, -1, -1, 100, 90, 0, NULL, 0, "constrained");
252
253 view->AddRegistry(&myFormValidatorRegistry);
254
255 if (useDialog)
256 {
257 view->ShowView(sheet, propDialog);
258 view->AssociateNames();
259 view->TransferToDialog();
260 propDialog->Centre(wxBOTH);
261 propDialog->Show(TRUE);
262 }
263 else
264 {
265 view->ShowView(sheet, propFrame->GetPropertyPanel());
266 view->AssociateNames();
267 view->TransferToDialog();
268 propFrame->Centre(wxBOTH);
269 propFrame->Show(TRUE);
270 }
271#endif
272}
273
274BEGIN_EVENT_TABLE(PropListFrame, wxPropertyListFrame)
275 EVT_CLOSE(PropListFrame::OnCloseWindow)
276END_EVENT_TABLE()
277
278void PropListFrame::OnCloseWindow(wxCloseEvent& event)
279{
280 wxGetApp().m_childWindow = NULL;
281
282 wxPropertyListFrame::OnCloseWindow(event);
283}
284
285BEGIN_EVENT_TABLE(PropListDialog, wxPropertyListDialog)
286 EVT_CLOSE(PropListDialog::OnCloseWindow)
287END_EVENT_TABLE()
288
289void PropListDialog::OnCloseWindow(wxCloseEvent& event)
290{
291 wxGetApp().m_childWindow = NULL;
292
293 wxPropertyListDialog::OnCloseWindow(event);
294}
295
296BEGIN_EVENT_TABLE(PropFormFrame, wxPropertyFormFrame)
297 EVT_CLOSE(PropFormFrame::OnCloseWindow)
298END_EVENT_TABLE()
299
300void PropFormFrame::OnCloseWindow(wxCloseEvent& event)
301{
302 wxGetApp().m_childWindow = NULL;
303
304 wxPropertyFormFrame::OnCloseWindow(event);
305}
306
307BEGIN_EVENT_TABLE(PropFormDialog, wxPropertyFormDialog)
308 EVT_CLOSE(PropFormDialog::OnCloseWindow)
309END_EVENT_TABLE()
310
311void PropFormDialog::OnCloseWindow(wxCloseEvent& event)
312{
313 wxGetApp().m_childWindow = NULL;
314
315 wxPropertyFormDialog::OnCloseWindow(event);
316}
317