1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property sheet test implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "test.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
31 wxPropertyValidatorRegistry myListValidatorRegistry
;
32 wxPropertyValidatorRegistry myFormValidatorRegistry
;
40 bool MyApp::OnInit(void)
44 // Create the main frame window
45 m_mainFrame
= new MyFrame(NULL
, "wxPropertySheet Demo", wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME_STYLE
);
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");
57 wxMenu
*help_menu
= new wxMenu
;
58 help_menu
->Append(PROPERTY_ABOUT
, "&About");
60 wxMenuBar
*menu_bar
= new wxMenuBar
;
62 menu_bar
->Append(file_menu
, "&File");
63 menu_bar
->Append(help_menu
, "&Help");
65 // Associate the menu bar with the frame
66 m_mainFrame
->SetMenuBar(menu_bar
);
68 m_mainFrame
->Centre(wxBOTH
);
69 m_mainFrame
->Show(TRUE
);
71 SetTopWindow(m_mainFrame
);
76 BEGIN_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
)
86 // Define my frame constructor
87 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long type
):
88 wxFrame(frame
, -1, title
, pos
, size
, type
)
92 // Define the behaviour for the frame closing
93 // - must delete all frames except for the main one.
94 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
96 if (wxGetApp().m_childWindow
)
98 wxGetApp().m_childWindow
->Close(TRUE
);
104 void MyFrame::OnQuit(wxCommandEvent
& event
)
109 void MyFrame::OnDialogList(wxCommandEvent
& event
)
111 wxGetApp().PropertyListTest(TRUE
);
114 void MyFrame::OnFrameList(wxCommandEvent
& event
)
116 wxGetApp().PropertyListTest(FALSE
);
119 void MyFrame::OnDialogForm(wxCommandEvent
& event
)
121 wxGetApp().PropertyFormTest(TRUE
);
124 void MyFrame::OnFrameForm(wxCommandEvent
& event
)
126 wxGetApp().PropertyFormTest(FALSE
);
129 void MyFrame::OnAbout(wxCommandEvent
& event
)
131 (void)wxMessageBox("Property Classes Demo\nAuthor: Julian Smart", "About Property Classes Test");
134 void MyApp::RegisterValidators(void)
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
);
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
);
148 void MyApp::PropertyListTest(bool useDialog
)
153 wxPropertySheet
*sheet
= new wxPropertySheet
;
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
)));
164 wxStringList
*strings2
= new wxStringList("earth", "fire", "wind", "water", NULL
);
165 sheet
->AddProperty(new wxProperty("string list", strings2
, "stringlist"));
167 wxPropertyListView
*view
=
168 new wxPropertyListView(NULL
,
169 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
171 wxDialog
*propDialog
= NULL
;
172 wxPropertyListFrame
*propFrame
= NULL
;
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
;
181 propFrame
= new PropListFrame(view
, NULL
, "Property Sheet Test", wxPoint(-1, -1), wxSize(400, 500));
182 m_childWindow
= propFrame
;
185 view
->AddRegistry(&myListValidatorRegistry
);
189 view
->ShowView(sheet
, propDialog
);
190 propDialog
->Centre(wxBOTH
);
191 propDialog
->Show(TRUE
);
195 propFrame
->Initialize();
196 view
->ShowView(sheet
, propFrame
->GetPropertyPanel());
198 propFrame
->Centre(wxBOTH
);
199 propFrame
->Show(TRUE
);
203 void MyApp::PropertyFormTest(bool useDialog
)
208 wxPropertySheet
*sheet
= new wxPropertySheet
;
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
)));
217 wxPropertyFormView
*view
= new wxPropertyFormView(NULL
);
219 wxDialog
*propDialog
= NULL
;
220 wxPropertyFormFrame
*propFrame
= NULL
;
223 propDialog
= new PropFormDialog(view
, NULL
, "Property Form Test",
224 wxPoint(-1, -1), wxSize(380, 250), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
225 m_childWindow
= propDialog
;
229 propFrame
= new PropFormFrame(view
, NULL
, "Property Form Test", wxPoint(-1,
230 -1), wxSize(380, 250));
231 propFrame
->Initialize();
232 m_childWindow
= propFrame
;
235 wxPanel
*panel
= propDialog
? propDialog
: propFrame
->GetPropertyPanel();
236 wxLayoutConstraints
* c
;
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);
247 panel
->SetConstraints(c
);
251 // Add items to the panel
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");
261 c
= new wxLayoutConstraints
;
262 c
->right
.SameAs(panel
, wxRight
, 4);
263 c
->bottom
.SameAs(panel
, wxBottom
, 4);
266 revertButton
->SetConstraints(c
);
268 c
= new wxLayoutConstraints
;
269 c
->right
.SameAs(revertButton
, wxLeft
, 4);
270 c
->bottom
.SameAs(panel
, wxBottom
, 4);
273 updateButton
->SetConstraints(c
);
275 c
= new wxLayoutConstraints
;
276 c
->right
.SameAs(updateButton
, wxLeft
, 4);
277 c
->bottom
.SameAs(panel
, wxBottom
, 4);
280 cancelButton
->SetConstraints(c
);
282 c
= new wxLayoutConstraints
;
283 c
->right
.SameAs(cancelButton
, wxLeft
, 4);
284 c
->bottom
.SameAs(panel
, wxBottom
, 4);
287 okButton
->SetConstraints(c
);
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");
293 c
= new wxLayoutConstraints
;
294 c
->left
.SameAs(panel
, wxLeft
, 4);
295 c
->top
.SameAs(panel
, wxTop
, 4);
298 text
->SetConstraints(c
);
300 wxCheckBox
*checkBox
= new wxCheckBox(panel
, -1, "Yes or no", wxPoint(-1, -1),
301 wxSize(-1, -1), 0, wxDefaultValidator
, "tough choice");
303 c
= new wxLayoutConstraints
;
304 c
->left
.SameAs(text
, wxRight
, 20);
305 c
->top
.SameAs(panel
, wxTop
, 4);
308 checkBox
->SetConstraints(c
);
310 wxSlider
*slider
= new wxSlider(panel
, -1, -50, 50, 150, wxPoint(-1, -1),
311 wxSize(200,10), 0, wxDefaultValidator
, "ian");
313 c
= new wxLayoutConstraints
;
314 c
->left
.SameAs(panel
, wxLeft
, 4);
315 c
->top
.SameAs(text
, wxBottom
, 10);
318 slider
->SetConstraints(c
);
320 wxListBox
*listBox
= new wxListBox(panel
, -1, wxPoint(-1, -1), wxSize(200, 100),
321 0, NULL
, 0, wxDefaultValidator
, "constrained");
323 c
= new wxLayoutConstraints
;
324 c
->left
.SameAs(panel
, wxLeft
, 4);
325 c
->top
.SameAs(slider
, wxBottom
, 10);
328 listBox
->SetConstraints(c
);
330 view
->AddRegistry(&myFormValidatorRegistry
);
332 panel
->SetAutoLayout(TRUE
);
334 view
->ShowView(sheet
, panel
);
335 view
->AssociateNames();
336 view
->TransferToDialog();
339 propDialog
->Layout();
340 propDialog
->Centre(wxBOTH
);
341 propDialog
->Show(TRUE
);
344 propFrame
->Centre(wxBOTH
);
345 propFrame
->Show(TRUE
);
349 BEGIN_EVENT_TABLE(PropListFrame
, wxPropertyListFrame
)
350 EVT_CLOSE(PropListFrame::OnCloseWindow
)
353 void PropListFrame::OnCloseWindow(wxCloseEvent
& event
)
355 wxGetApp().m_childWindow
= NULL
;
357 wxPropertyListFrame::OnCloseWindow(event
);
360 BEGIN_EVENT_TABLE(PropListDialog
, wxPropertyListDialog
)
361 EVT_CLOSE(PropListDialog::OnCloseWindow
)
364 void PropListDialog::OnCloseWindow(wxCloseEvent
& event
)
366 wxGetApp().m_childWindow
= NULL
;
368 wxPropertyListDialog::OnCloseWindow(event
);
371 BEGIN_EVENT_TABLE(PropFormFrame
, wxPropertyFormFrame
)
372 EVT_CLOSE(PropFormFrame::OnCloseWindow
)
373 EVT_SIZE(PropFormFrame::OnSize
)
376 void PropFormFrame::OnCloseWindow(wxCloseEvent
& event
)
378 wxGetApp().m_childWindow
= NULL
;
380 wxPropertyFormFrame::OnCloseWindow(event
);
383 void PropFormFrame::OnSize(wxSizeEvent
& event
)
385 wxPropertyFormFrame::OnSize(event
);
386 GetPropertyPanel()->Layout();
389 BEGIN_EVENT_TABLE(PropFormDialog
, wxPropertyFormDialog
)
390 EVT_CLOSE(PropFormDialog::OnCloseWindow
)
393 void PropFormDialog::OnCloseWindow(wxCloseEvent
& event
)
395 wxGetApp().m_childWindow
= NULL
;
397 wxPropertyFormDialog::OnCloseWindow(event
);