1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property sheet test implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "proplist_sample.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/deprecated/setup.h"
30 #error Please set wxUSE_PROPSHEET to 1 in contrib/include/wx/deprecated/setup.h and recompile.
37 wxPropertyValidatorRegistry myListValidatorRegistry
;
38 wxPropertyValidatorRegistry myFormValidatorRegistry
;
46 bool MyApp::OnInit(void)
50 // Create the main frame window
51 m_mainFrame
= new MyFrame(NULL
, _T("wxPropertySheet Demo"), wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME_STYLE
);
54 wxMenu
*file_menu
= new wxMenu
;
55 file_menu
->Append(PROPERTY_TEST_DIALOG_LIST
, _T("Test property list &dialog..."));
56 file_menu
->Append(PROPERTY_TEST_FRAME_LIST
, _T("Test property list &frame..."));
57 file_menu
->AppendSeparator();
58 file_menu
->Append(PROPERTY_TEST_DIALOG_FORM
, _T("Test property form d&ialog..."));
59 file_menu
->Append(PROPERTY_TEST_FRAME_FORM
, _T("Test property form f&rame..."));
60 file_menu
->AppendSeparator();
61 file_menu
->Append(PROPERTY_QUIT
, _T("E&xit"));
63 wxMenu
*help_menu
= new wxMenu
;
64 help_menu
->Append(PROPERTY_ABOUT
, _T("&About"));
66 wxMenuBar
*menu_bar
= new wxMenuBar
;
68 menu_bar
->Append(file_menu
, _T("&File"));
69 menu_bar
->Append(help_menu
, _T("&Help"));
71 // Associate the menu bar with the frame
72 m_mainFrame
->SetMenuBar(menu_bar
);
74 m_mainFrame
->Centre(wxBOTH
);
75 m_mainFrame
->Show(TRUE
);
77 SetTopWindow(m_mainFrame
);
82 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
83 EVT_CLOSE(MyFrame::OnCloseWindow
)
84 EVT_MENU(PROPERTY_QUIT
, MyFrame::OnQuit
)
85 EVT_MENU(PROPERTY_ABOUT
, MyFrame::OnAbout
)
86 EVT_MENU(PROPERTY_TEST_DIALOG_LIST
, MyFrame::OnDialogList
)
87 EVT_MENU(PROPERTY_TEST_FRAME_LIST
, MyFrame::OnFrameList
)
88 EVT_MENU(PROPERTY_TEST_DIALOG_FORM
, MyFrame::OnDialogForm
)
89 EVT_MENU(PROPERTY_TEST_FRAME_FORM
, MyFrame::OnFrameForm
)
92 // Define my frame constructor
93 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long type
):
94 wxFrame(frame
, -1, title
, pos
, size
, type
)
98 // Define the behaviour for the frame closing
99 // - must delete all frames except for the main one.
100 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
102 if (wxGetApp().m_childWindow
)
104 wxGetApp().m_childWindow
->Close(TRUE
);
110 void MyFrame::OnQuit(wxCommandEvent
& event
)
115 void MyFrame::OnDialogList(wxCommandEvent
& event
)
117 wxGetApp().PropertyListTest(TRUE
);
120 void MyFrame::OnFrameList(wxCommandEvent
& event
)
122 wxGetApp().PropertyListTest(FALSE
);
125 void MyFrame::OnDialogForm(wxCommandEvent
& event
)
127 wxGetApp().PropertyFormTest(TRUE
);
130 void MyFrame::OnFrameForm(wxCommandEvent
& event
)
132 wxGetApp().PropertyFormTest(FALSE
);
135 void MyFrame::OnAbout(wxCommandEvent
& event
)
137 (void)wxMessageBox(_T("Property Classes Demo\nAuthor: Julian Smart"), _T("About Property Classes Test"));
140 void MyApp::RegisterValidators(void)
142 myListValidatorRegistry
.RegisterValidator((wxString
)_T("real"), new wxRealListValidator
);
143 myListValidatorRegistry
.RegisterValidator((wxString
)_T("string"), new wxStringListValidator
);
144 myListValidatorRegistry
.RegisterValidator((wxString
)_T("integer"), new wxIntegerListValidator
);
145 myListValidatorRegistry
.RegisterValidator((wxString
)_T("bool"), new wxBoolListValidator
);
146 myListValidatorRegistry
.RegisterValidator((wxString
)_T("stringlist"), new wxListOfStringsListValidator
);
148 myFormValidatorRegistry
.RegisterValidator((wxString
)_T("real"), new wxRealFormValidator
);
149 myFormValidatorRegistry
.RegisterValidator((wxString
)_T("string"), new wxStringFormValidator
);
150 myFormValidatorRegistry
.RegisterValidator((wxString
)_T("integer"), new wxIntegerFormValidator
);
151 myFormValidatorRegistry
.RegisterValidator((wxString
)_T("bool"), new wxBoolFormValidator
);
154 void MyApp::PropertyListTest(bool useDialog
)
159 wxPropertySheet
*sheet
= new wxPropertySheet
;
161 sheet
->AddProperty(new wxProperty(_T("fred"), 1.0, _T("real")));
162 sheet
->AddProperty(new wxProperty(_T("tough choice"), (bool)TRUE
, _T("bool")));
163 sheet
->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerListValidator(-50, 50)));
164 sheet
->AddProperty(new wxProperty(_T("bill"), 25.0, _T("real"), new wxRealListValidator(0.0, 100.0)));
165 sheet
->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string")));
166 sheet
->AddProperty(new wxProperty(_T("bitmap"), _T("none"), _T("string"), new wxFilenameListValidator(_T("Select a bitmap file"), _T("*.bmp"))));
167 wxStringList
*strings
= new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL
);
168 sheet
->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringListValidator(strings
)));
170 wxStringList
*strings2
= new wxStringList(wxT("earth"), wxT("fire"), wxT("wind"), wxT("water"), NULL
);
171 sheet
->AddProperty(new wxProperty(_T("string list"), strings2
, _T("stringlist")));
173 wxPropertyListView
*view
= new wxPropertyListView
176 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
| wxPROP_BUTTON_CHECK_CROSS
177 |wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
180 wxDialog
*propDialog
= NULL
;
181 wxPropertyListFrame
*propFrame
= NULL
;
184 propDialog
= new PropListDialog(view
, NULL
, _T("Property Sheet Test"),
185 wxPoint(-1, -1), wxSize(400, 500), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODELESS
);
186 m_childWindow
= propDialog
;
190 propFrame
= new PropListFrame(view
, NULL
, _T("Property Sheet Test"), wxPoint(-1, -1), wxSize(400, 500));
191 m_childWindow
= propFrame
;
194 view
->AddRegistry(&myListValidatorRegistry
);
198 view
->ShowView(sheet
, (wxPanel
*)propDialog
);
199 propDialog
->Centre(wxBOTH
);
200 propDialog
->Show(TRUE
);
204 propFrame
->Initialize();
205 view
->ShowView(sheet
, propFrame
->GetPropertyPanel());
207 propFrame
->Centre(wxBOTH
);
208 propFrame
->Show(TRUE
);
212 void MyApp::PropertyFormTest(bool useDialog
)
217 wxPropertySheet
*sheet
= new wxPropertySheet
;
219 sheet
->AddProperty(new wxProperty(_T("fred"), 25.0, _T("real"), new wxRealFormValidator(0.0, 100.0)));
220 sheet
->AddProperty(new wxProperty(_T("tough choice"), (bool)TRUE
, _T("bool")));
221 sheet
->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerFormValidator(-50, 50)));
222 sheet
->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string")));
223 wxStringList
*strings
= new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL
);
224 sheet
->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringFormValidator(strings
)));
226 wxPropertyFormView
*view
= new wxPropertyFormView(NULL
);
228 wxDialog
*propDialog
= NULL
;
229 wxPropertyFormFrame
*propFrame
= NULL
;
233 propDialog
= new PropFormDialog(view
, NULL
, _T("Property Form Test"),
234 wxPoint(-1, -1), wxSize(380, 250), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
235 m_childWindow
= propDialog
;
239 propFrame
= new PropFormFrame(view
, NULL
, _T("Property Form Test"),
240 wxPoint(-1, -1), wxSize(380, 250));
241 propFrame
->Initialize();
242 m_childWindow
= propFrame
;
245 // BCC32 does not like ?:
253 panel
= propFrame
->GetPropertyPanel() ;
256 wxLayoutConstraints
* c
;
261 c
= new wxLayoutConstraints
;
262 c
->left
.SameAs(m_childWindow
, wxLeft
, 4);
263 c
->right
.SameAs(m_childWindow
, wxRight
, 4);
264 c
->top
.SameAs(m_childWindow
, wxTop
, 4);
265 c
->bottom
.SameAs(m_childWindow
, wxBottom
, 40);
267 panel
->SetConstraints(c
);
271 // Add items to the panel
272 wxButton
*okButton
= new wxButton(panel
, wxID_OK
, _T("OK"), wxPoint(-1, -1),
273 wxSize(80, 26), 0, wxDefaultValidator
, _T("ok"));
274 wxButton
*cancelButton
= new wxButton(panel
, wxID_CANCEL
, _T("Cancel"), wxPoint(-1, -1),
275 wxSize(80, 26), 0, wxDefaultValidator
, _T("cancel"));
276 wxButton
*updateButton
= new wxButton(panel
, wxID_PROP_UPDATE
, _T("Update"), wxPoint(-1, -1),
277 wxSize(80, 26), 0, wxDefaultValidator
, _T("update"));
278 wxButton
*revertButton
= new wxButton(panel
, wxID_PROP_REVERT
, _T("Revert"), wxPoint(-1, -1),
279 wxSize(80, 26), 0, wxDefaultValidator
, _T("revert"));
281 c
= new wxLayoutConstraints
;
282 c
->right
.SameAs(panel
, wxRight
, 4);
283 c
->bottom
.SameAs(panel
, wxBottom
, 4);
286 revertButton
->SetConstraints(c
);
288 c
= new wxLayoutConstraints
;
289 c
->right
.SameAs(revertButton
, wxLeft
, 4);
290 c
->bottom
.SameAs(panel
, wxBottom
, 4);
293 updateButton
->SetConstraints(c
);
295 c
= new wxLayoutConstraints
;
296 c
->right
.SameAs(updateButton
, wxLeft
, 4);
297 c
->bottom
.SameAs(panel
, wxBottom
, 4);
300 cancelButton
->SetConstraints(c
);
302 c
= new wxLayoutConstraints
;
303 c
->right
.SameAs(cancelButton
, wxLeft
, 4);
304 c
->bottom
.SameAs(panel
, wxBottom
, 4);
307 okButton
->SetConstraints(c
);
309 // The name of this text item matches the "fred" property
310 wxTextCtrl
*text
= new wxTextCtrl(panel
, -1, _T("Fred"), wxPoint(-1, -1), wxSize(
311 200, -1), 0, wxDefaultValidator
, _T("fred"));
313 c
= new wxLayoutConstraints
;
314 c
->left
.SameAs(panel
, wxLeft
, 4);
315 c
->top
.SameAs(panel
, wxTop
, 4);
318 text
->SetConstraints(c
);
320 wxCheckBox
*checkBox
= new wxCheckBox(panel
, -1, _T("Yes or no"), wxPoint(-1, -1),
321 wxSize(-1, -1), 0, wxDefaultValidator
, _T("tough choice"));
323 c
= new wxLayoutConstraints
;
324 c
->left
.SameAs(text
, wxRight
, 20);
325 c
->top
.SameAs(panel
, wxTop
, 4);
328 checkBox
->SetConstraints(c
);
330 wxSlider
*slider
= new wxSlider(panel
, -1, -50, 50, 150, wxPoint(-1, -1),
331 wxSize(200,10), 0, wxDefaultValidator
, _T("ian"));
333 c
= new wxLayoutConstraints
;
334 c
->left
.SameAs(panel
, wxLeft
, 4);
335 c
->top
.SameAs(text
, wxBottom
, 10);
338 slider
->SetConstraints(c
);
340 wxListBox
*listBox
= new wxListBox(panel
, -1, wxPoint(-1, -1),
341 wxSize(200, 100), 0, NULL
, 0, wxDefaultValidator
, _T("constrained"));
343 c
= new wxLayoutConstraints
;
344 c
->left
.SameAs(panel
, wxLeft
, 4);
345 c
->top
.SameAs(slider
, wxBottom
, 10);
348 listBox
->SetConstraints(c
);
350 view
->AddRegistry(&myFormValidatorRegistry
);
352 panel
->SetAutoLayout(TRUE
);
354 view
->ShowView(sheet
, panel
);
355 view
->AssociateNames();
356 view
->TransferToDialog();
359 propDialog
->Layout();
360 propDialog
->Centre(wxBOTH
);
361 propDialog
->Show(TRUE
);
366 propFrame
->Centre(wxBOTH
);
367 propFrame
->Show(TRUE
);
371 BEGIN_EVENT_TABLE(PropListFrame
, wxPropertyListFrame
)
372 EVT_CLOSE(PropListFrame::OnCloseWindow
)
375 void PropListFrame::OnCloseWindow(wxCloseEvent
& event
)
377 wxGetApp().m_childWindow
= NULL
;
379 wxPropertyListFrame::OnCloseWindow(event
);
382 BEGIN_EVENT_TABLE(PropListDialog
, wxPropertyListDialog
)
383 EVT_CLOSE(PropListDialog::OnCloseWindow
)
386 void PropListDialog::OnCloseWindow(wxCloseEvent
& event
)
388 wxGetApp().m_childWindow
= NULL
;
390 wxPropertyListDialog::OnCloseWindow(event
);
393 BEGIN_EVENT_TABLE(PropFormFrame
, wxPropertyFormFrame
)
394 EVT_CLOSE(PropFormFrame::OnCloseWindow
)
395 EVT_SIZE(PropFormFrame::OnSize
)
398 void PropFormFrame::OnCloseWindow(wxCloseEvent
& event
)
400 wxGetApp().m_childWindow
= NULL
;
402 wxPropertyFormFrame::OnCloseWindow(event
);
405 void PropFormFrame::OnSize(wxSizeEvent
& event
)
407 wxPropertyFormFrame::OnSize(event
);
408 GetPropertyPanel()->Layout();
411 BEGIN_EVENT_TABLE(PropFormDialog
, wxPropertyFormDialog
)
412 EVT_CLOSE(PropFormDialog::OnCloseWindow
)
415 void PropFormDialog::OnCloseWindow(wxCloseEvent
& event
)
417 wxGetApp().m_childWindow
= NULL
;
419 wxPropertyFormDialog::OnCloseWindow(event
);