1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property sheet test implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/deprecated/setup.h"
26 #error Please set wxUSE_PROPSHEET to 1 in contrib/include/wx/deprecated/setup.h and recompile.
33 wxPropertyValidatorRegistry myListValidatorRegistry
;
34 wxPropertyValidatorRegistry myFormValidatorRegistry
;
42 bool MyApp::OnInit(void)
46 // Create the main frame window
47 m_mainFrame
= new MyFrame(NULL
, _T("wxPropertySheet Demo"), wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME_STYLE
);
50 wxMenu
*file_menu
= new wxMenu
;
51 file_menu
->Append(PROPERTY_TEST_DIALOG_LIST
, _T("Test property list &dialog..."));
52 file_menu
->Append(PROPERTY_TEST_FRAME_LIST
, _T("Test property list &frame..."));
53 file_menu
->AppendSeparator();
54 file_menu
->Append(PROPERTY_TEST_DIALOG_FORM
, _T("Test property form d&ialog..."));
55 file_menu
->Append(PROPERTY_TEST_FRAME_FORM
, _T("Test property form f&rame..."));
56 file_menu
->AppendSeparator();
57 file_menu
->Append(PROPERTY_QUIT
, _T("E&xit"));
59 wxMenu
*help_menu
= new wxMenu
;
60 help_menu
->Append(PROPERTY_ABOUT
, _T("&About"));
62 wxMenuBar
*menu_bar
= new wxMenuBar
;
64 menu_bar
->Append(file_menu
, _T("&File"));
65 menu_bar
->Append(help_menu
, _T("&Help"));
67 // Associate the menu bar with the frame
68 m_mainFrame
->SetMenuBar(menu_bar
);
70 m_mainFrame
->Centre(wxBOTH
);
71 m_mainFrame
->Show(true);
73 SetTopWindow(m_mainFrame
);
78 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
79 EVT_CLOSE(MyFrame::OnCloseWindow
)
80 EVT_MENU(PROPERTY_QUIT
, MyFrame::OnQuit
)
81 EVT_MENU(PROPERTY_ABOUT
, MyFrame::OnAbout
)
82 EVT_MENU(PROPERTY_TEST_DIALOG_LIST
, MyFrame::OnDialogList
)
83 EVT_MENU(PROPERTY_TEST_FRAME_LIST
, MyFrame::OnFrameList
)
84 EVT_MENU(PROPERTY_TEST_DIALOG_FORM
, MyFrame::OnDialogForm
)
85 EVT_MENU(PROPERTY_TEST_FRAME_FORM
, MyFrame::OnFrameForm
)
88 // Define my frame constructor
89 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long type
):
90 wxFrame(frame
, wxID_ANY
, title
, pos
, size
, type
)
94 // Define the behaviour for the frame closing
95 // - must delete all frames except for the main one.
96 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
98 if (wxGetApp().m_childWindow
)
100 wxGetApp().m_childWindow
->Close(true);
106 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
111 void MyFrame::OnDialogList(wxCommandEvent
& WXUNUSED(event
))
113 wxGetApp().PropertyListTest(true);
116 void MyFrame::OnFrameList(wxCommandEvent
& WXUNUSED(event
))
118 wxGetApp().PropertyListTest(false);
121 void MyFrame::OnDialogForm(wxCommandEvent
& WXUNUSED(event
))
123 wxGetApp().PropertyFormTest(true);
126 void MyFrame::OnFrameForm(wxCommandEvent
& WXUNUSED(event
))
128 wxGetApp().PropertyFormTest(false);
131 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
133 (void)wxMessageBox(_T("Property Classes Demo\nAuthor: Julian Smart"), _T("About Property Classes Test"));
136 void MyApp::RegisterValidators(void)
138 myListValidatorRegistry
.RegisterValidator((wxString
)_T("real"), new wxRealListValidator
);
139 myListValidatorRegistry
.RegisterValidator((wxString
)_T("string"), new wxStringListValidator
);
140 myListValidatorRegistry
.RegisterValidator((wxString
)_T("integer"), new wxIntegerListValidator
);
141 myListValidatorRegistry
.RegisterValidator((wxString
)_T("bool"), new wxBoolListValidator
);
142 myListValidatorRegistry
.RegisterValidator((wxString
)_T("stringlist"), new wxListOfStringsListValidator
);
144 myFormValidatorRegistry
.RegisterValidator((wxString
)_T("real"), new wxRealFormValidator
);
145 myFormValidatorRegistry
.RegisterValidator((wxString
)_T("string"), new wxStringFormValidator
);
146 myFormValidatorRegistry
.RegisterValidator((wxString
)_T("integer"), new wxIntegerFormValidator
);
147 myFormValidatorRegistry
.RegisterValidator((wxString
)_T("bool"), new wxBoolFormValidator
);
150 void MyApp::PropertyListTest(bool useDialog
)
155 wxPropertySheet
*sheet
= new wxPropertySheet
;
157 sheet
->AddProperty(new wxProperty(_T("fred"), 1.0, _T("real")));
158 sheet
->AddProperty(new wxProperty(_T("tough choice"), true, _T("bool")));
159 sheet
->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerListValidator(-50, 50)));
160 sheet
->AddProperty(new wxProperty(_T("bill"), 25.0, _T("real"), new wxRealListValidator(0.0, 100.0)));
161 sheet
->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string")));
162 sheet
->AddProperty(new wxProperty(_T("bitmap"), _T("none"), _T("string"), new wxFilenameListValidator(_T("Select a bitmap file"), _T("*.bmp"))));
163 wxStringList
*strings
= new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL
);
164 sheet
->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringListValidator(strings
)));
166 wxStringList
*strings2
= new wxStringList(wxT("earth"), wxT("fire"), wxT("wind"), wxT("water"), NULL
);
167 sheet
->AddProperty(new wxProperty(_T("string list"), strings2
, _T("stringlist")));
169 wxPropertyListView
*view
= new wxPropertyListView
172 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
| wxPROP_BUTTON_CHECK_CROSS
173 | wxPROP_DYNAMIC_VALUE_FIELD
| wxPROP_PULLDOWN
| wxPROP_SHOWVALUES
176 PropListDialog
*propDialog
= NULL
;
177 PropListFrame
*propFrame
= NULL
;
180 propDialog
= new PropListDialog(view
, NULL
, _T("Property Sheet Test"),
181 wxDefaultPosition
, wxSize(400, 500));
182 m_childWindow
= propDialog
;
186 propFrame
= new PropListFrame(view
, NULL
, _T("Property Sheet Test"),
187 wxDefaultPosition
, wxSize(400, 500));
188 m_childWindow
= propFrame
;
191 view
->AddRegistry(&myListValidatorRegistry
);
195 view
->ShowView(sheet
, (wxPanel
*)propDialog
);
199 propFrame
->Initialize();
200 view
->ShowView(sheet
, propFrame
->GetPropertyPanel());
203 m_childWindow
->Centre(wxBOTH
);
204 m_childWindow
->Show(true);
207 void MyApp::PropertyFormTest(bool useDialog
)
212 wxPropertySheet
*sheet
= new wxPropertySheet
;
214 sheet
->AddProperty(new wxProperty(_T("fred"), 25.0, _T("real"), new wxRealFormValidator(0.0, 100.0)));
215 sheet
->AddProperty(new wxProperty(_T("tough choice"), true, _T("bool")));
216 sheet
->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerFormValidator(-50, 50)));
217 sheet
->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string")));
218 wxStringList
*strings
= new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL
);
219 sheet
->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringFormValidator(strings
)));
221 wxPropertyFormView
*view
= new wxPropertyFormView(NULL
);
223 wxDialog
*propDialog
= NULL
;
224 wxPropertyFormFrame
*propFrame
= NULL
;
228 propDialog
= new PropFormDialog(view
, NULL
, _T("Property Form Test"),
229 wxDefaultPosition
, wxSize(380, 250));
230 m_childWindow
= propDialog
;
234 propFrame
= new PropFormFrame(view
, NULL
, _T("Property Form Test"),
235 wxDefaultPosition
, wxSize(380, 250));
236 propFrame
->Initialize();
237 m_childWindow
= propFrame
;
240 // BCC32 does not like ?:
248 panel
= propFrame
->GetPropertyPanel() ;
251 wxLayoutConstraints
* c
;
256 c
= new wxLayoutConstraints
;
257 c
->left
.SameAs(m_childWindow
, wxLeft
, 4);
258 c
->right
.SameAs(m_childWindow
, wxRight
, 4);
259 c
->top
.SameAs(m_childWindow
, wxTop
, 4);
260 c
->bottom
.SameAs(m_childWindow
, wxBottom
, 40);
262 panel
->SetConstraints(c
);
266 // Add items to the panel
267 wxButton
*okButton
= new wxButton(panel
, wxID_OK
, _T("OK"), wxDefaultPosition
,
268 wxSize(80, 26), 0, wxDefaultValidator
, _T("ok"));
269 wxButton
*cancelButton
= new wxButton(panel
, wxID_CANCEL
, _T("Cancel"), wxDefaultPosition
,
270 wxSize(80, 26), 0, wxDefaultValidator
, _T("cancel"));
271 wxButton
*updateButton
= new wxButton(panel
, wxID_PROP_UPDATE
, _T("Update"), wxDefaultPosition
,
272 wxSize(80, 26), 0, wxDefaultValidator
, _T("update"));
273 wxButton
*revertButton
= new wxButton(panel
, wxID_PROP_REVERT
, _T("Revert"), wxDefaultPosition
,
274 wxSize(80, 26), 0, wxDefaultValidator
, _T("revert"));
276 c
= new wxLayoutConstraints
;
277 c
->right
.SameAs(panel
, wxRight
, 4);
278 c
->bottom
.SameAs(panel
, wxBottom
, 4);
281 revertButton
->SetConstraints(c
);
283 c
= new wxLayoutConstraints
;
284 c
->right
.SameAs(revertButton
, wxLeft
, 4);
285 c
->bottom
.SameAs(panel
, wxBottom
, 4);
288 updateButton
->SetConstraints(c
);
290 c
= new wxLayoutConstraints
;
291 c
->right
.SameAs(updateButton
, wxLeft
, 4);
292 c
->bottom
.SameAs(panel
, wxBottom
, 4);
295 cancelButton
->SetConstraints(c
);
297 c
= new wxLayoutConstraints
;
298 c
->right
.SameAs(cancelButton
, wxLeft
, 4);
299 c
->bottom
.SameAs(panel
, wxBottom
, 4);
302 okButton
->SetConstraints(c
);
304 // The name of this text item matches the "fred" property
305 wxTextCtrl
*text
= new wxTextCtrl(panel
, wxID_ANY
, _T("Fred"), wxDefaultPosition
,
306 wxSize( 200, wxDefaultCoord
), 0, wxDefaultValidator
, _T("fred"));
308 c
= new wxLayoutConstraints
;
309 c
->left
.SameAs(panel
, wxLeft
, 4);
310 c
->top
.SameAs(panel
, wxTop
, 4);
313 text
->SetConstraints(c
);
315 wxCheckBox
*checkBox
= new wxCheckBox(panel
, wxID_ANY
, _T("Yes or no"), wxDefaultPosition
,
316 wxDefaultSize
, 0, wxDefaultValidator
, _T("tough choice"));
318 c
= new wxLayoutConstraints
;
319 c
->left
.SameAs(text
, wxRight
, 20);
320 c
->top
.SameAs(panel
, wxTop
, 4);
323 checkBox
->SetConstraints(c
);
325 wxSlider
*slider
= new wxSlider(panel
, wxID_ANY
, -50, 50, 150, wxDefaultPosition
,
326 wxSize(200,10), 0, wxDefaultValidator
, _T("ian"));
328 c
= new wxLayoutConstraints
;
329 c
->left
.SameAs(panel
, wxLeft
, 4);
330 c
->top
.SameAs(text
, wxBottom
, 10);
333 slider
->SetConstraints(c
);
335 wxListBox
*listBox
= new wxListBox(panel
, wxID_ANY
, wxDefaultPosition
,
336 wxSize(200, 100), 0, NULL
, 0, wxDefaultValidator
, _T("constrained"));
338 c
= new wxLayoutConstraints
;
339 c
->left
.SameAs(panel
, wxLeft
, 4);
340 c
->top
.SameAs(slider
, wxBottom
, 10);
343 listBox
->SetConstraints(c
);
345 view
->AddRegistry(&myFormValidatorRegistry
);
347 panel
->SetAutoLayout(true);
349 view
->ShowView(sheet
, panel
);
350 view
->AssociateNames();
351 view
->TransferToDialog();
354 propDialog
->Layout();
360 m_childWindow
->Centre(wxBOTH
);
361 m_childWindow
->Show(true);
364 BEGIN_EVENT_TABLE(PropListFrame
, wxPropertyListFrame
)
365 EVT_CLOSE(PropListFrame::OnCloseWindow
)
368 void PropListFrame::OnCloseWindow(wxCloseEvent
& event
)
370 wxGetApp().m_childWindow
= NULL
;
372 wxPropertyListFrame::OnCloseWindow(event
);
375 BEGIN_EVENT_TABLE(PropListDialog
, wxPropertyListDialog
)
376 EVT_CLOSE(PropListDialog::OnCloseWindow
)
379 void PropListDialog::OnCloseWindow(wxCloseEvent
& event
)
381 wxGetApp().m_childWindow
= NULL
;
383 wxPropertyListDialog::OnCloseWindow(event
);
386 BEGIN_EVENT_TABLE(PropFormFrame
, wxPropertyFormFrame
)
387 EVT_CLOSE(PropFormFrame::OnCloseWindow
)
388 EVT_SIZE(PropFormFrame::OnSize
)
391 void PropFormFrame::OnCloseWindow(wxCloseEvent
& event
)
393 wxGetApp().m_childWindow
= NULL
;
395 wxPropertyFormFrame::OnCloseWindow(event
);
398 void PropFormFrame::OnSize(wxSizeEvent
& event
)
400 wxPropertyFormFrame::OnSize(event
);
401 GetPropertyPanel()->Layout();
404 BEGIN_EVENT_TABLE(PropFormDialog
, wxPropertyFormDialog
)
405 EVT_CLOSE(PropFormDialog::OnCloseWindow
)
408 void PropFormDialog::OnCloseWindow(wxCloseEvent
& event
)
410 wxGetApp().m_childWindow
= NULL
;
412 wxPropertyFormDialog::OnCloseWindow(event
);