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"
29 #error Please set wxUSE_PROPSHEET to 1 in include/wx/msw/setup.h and recompile.
36 wxPropertyValidatorRegistry myListValidatorRegistry
;
37 wxPropertyValidatorRegistry myFormValidatorRegistry
;
45 bool MyApp::OnInit(void)
49 // Create the main frame window
50 m_mainFrame
= new MyFrame(NULL
, "wxPropertySheet Demo", wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME_STYLE
);
53 wxMenu
*file_menu
= new wxMenu
;
54 file_menu
->Append(PROPERTY_TEST_DIALOG_LIST
, "Test property list &dialog...");
55 file_menu
->Append(PROPERTY_TEST_FRAME_LIST
, "Test property list &frame...");
56 file_menu
->AppendSeparator();
57 file_menu
->Append(PROPERTY_TEST_DIALOG_FORM
, "Test property form d&ialog...");
58 file_menu
->Append(PROPERTY_TEST_FRAME_FORM
, "Test property form f&rame...");
59 file_menu
->AppendSeparator();
60 file_menu
->Append(PROPERTY_QUIT
, "E&xit");
62 wxMenu
*help_menu
= new wxMenu
;
63 help_menu
->Append(PROPERTY_ABOUT
, "&About");
65 wxMenuBar
*menu_bar
= new wxMenuBar
;
67 menu_bar
->Append(file_menu
, "&File");
68 menu_bar
->Append(help_menu
, "&Help");
70 // Associate the menu bar with the frame
71 m_mainFrame
->SetMenuBar(menu_bar
);
73 m_mainFrame
->Centre(wxBOTH
);
74 m_mainFrame
->Show(TRUE
);
76 SetTopWindow(m_mainFrame
);
81 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
82 EVT_CLOSE(MyFrame::OnCloseWindow
)
83 EVT_MENU(PROPERTY_QUIT
, MyFrame::OnQuit
)
84 EVT_MENU(PROPERTY_ABOUT
, MyFrame::OnAbout
)
85 EVT_MENU(PROPERTY_TEST_DIALOG_LIST
, MyFrame::OnDialogList
)
86 EVT_MENU(PROPERTY_TEST_FRAME_LIST
, MyFrame::OnFrameList
)
87 EVT_MENU(PROPERTY_TEST_DIALOG_FORM
, MyFrame::OnDialogForm
)
88 EVT_MENU(PROPERTY_TEST_FRAME_FORM
, MyFrame::OnFrameForm
)
91 // Define my frame constructor
92 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long type
):
93 wxFrame(frame
, -1, title
, pos
, size
, type
)
97 // Define the behaviour for the frame closing
98 // - must delete all frames except for the main one.
99 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
101 if (wxGetApp().m_childWindow
)
103 wxGetApp().m_childWindow
->Close(TRUE
);
109 void MyFrame::OnQuit(wxCommandEvent
& event
)
114 void MyFrame::OnDialogList(wxCommandEvent
& event
)
116 wxGetApp().PropertyListTest(TRUE
);
119 void MyFrame::OnFrameList(wxCommandEvent
& event
)
121 wxGetApp().PropertyListTest(FALSE
);
124 void MyFrame::OnDialogForm(wxCommandEvent
& event
)
126 wxGetApp().PropertyFormTest(TRUE
);
129 void MyFrame::OnFrameForm(wxCommandEvent
& event
)
131 wxGetApp().PropertyFormTest(FALSE
);
134 void MyFrame::OnAbout(wxCommandEvent
& event
)
136 (void)wxMessageBox("Property Classes Demo\nAuthor: Julian Smart", "About Property Classes Test");
139 void MyApp::RegisterValidators(void)
141 myListValidatorRegistry
.RegisterValidator((wxString
)"real", new wxRealListValidator
);
142 myListValidatorRegistry
.RegisterValidator((wxString
)"string", new wxStringListValidator
);
143 myListValidatorRegistry
.RegisterValidator((wxString
)"integer", new wxIntegerListValidator
);
144 myListValidatorRegistry
.RegisterValidator((wxString
)"bool", new wxBoolListValidator
);
145 myListValidatorRegistry
.RegisterValidator((wxString
)"stringlist", new wxListOfStringsListValidator
);
147 myFormValidatorRegistry
.RegisterValidator((wxString
)"real", new wxRealFormValidator
);
148 myFormValidatorRegistry
.RegisterValidator((wxString
)"string", new wxStringFormValidator
);
149 myFormValidatorRegistry
.RegisterValidator((wxString
)"integer", new wxIntegerFormValidator
);
150 myFormValidatorRegistry
.RegisterValidator((wxString
)"bool", new wxBoolFormValidator
);
153 void MyApp::PropertyListTest(bool useDialog
)
158 wxPropertySheet
*sheet
= new wxPropertySheet
;
160 sheet
->AddProperty(new wxProperty("fred", 1.0, "real"));
161 sheet
->AddProperty(new wxProperty("tough choice", (bool)TRUE
, "bool"));
162 sheet
->AddProperty(new wxProperty("ian", (long)45, "integer", new wxIntegerListValidator(-50, 50)));
163 sheet
->AddProperty(new wxProperty("bill", 25.0, "real", new wxRealListValidator(0.0, 100.0)));
164 sheet
->AddProperty(new wxProperty("julian", "one", "string"));
165 sheet
->AddProperty(new wxProperty("bitmap", "none", "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp")));
166 wxStringList
*strings
= new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL
);
167 sheet
->AddProperty(new wxProperty("constrained", "one", "string", new wxStringListValidator(strings
)));
169 wxStringList
*strings2
= new wxStringList(wxT("earth"), wxT("fire"), wxT("wind"), wxT("water"), NULL
);
170 sheet
->AddProperty(new wxProperty("string list", strings2
, "stringlist"));
172 wxPropertyListView
*view
=
173 new wxPropertyListView(NULL
,
174 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
|
175 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
177 wxDialog
*propDialog
= NULL
;
178 wxPropertyListFrame
*propFrame
= NULL
;
181 propDialog
= new PropListDialog(view
, NULL
, "Property Sheet Test",
182 wxPoint(-1, -1), wxSize(400, 500), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODELESS
);
183 m_childWindow
= propDialog
;
187 propFrame
= new PropListFrame(view
, NULL
, "Property Sheet Test", wxPoint(-1, -1), wxSize(400, 500));
188 m_childWindow
= propFrame
;
191 view
->AddRegistry(&myListValidatorRegistry
);
195 view
->ShowView(sheet
, (wxPanel
*)propDialog
);
196 propDialog
->Centre(wxBOTH
);
197 propDialog
->Show(TRUE
);
201 propFrame
->Initialize();
202 view
->ShowView(sheet
, propFrame
->GetPropertyPanel());
204 propFrame
->Centre(wxBOTH
);
205 propFrame
->Show(TRUE
);
209 void MyApp::PropertyFormTest(bool useDialog
)
214 wxPropertySheet
*sheet
= new wxPropertySheet
;
216 sheet
->AddProperty(new wxProperty("fred", 25.0, "real", new wxRealFormValidator(0.0, 100.0)));
217 sheet
->AddProperty(new wxProperty("tough choice", (bool)TRUE
, "bool"));
218 sheet
->AddProperty(new wxProperty("ian", (long)45, "integer", new wxIntegerFormValidator(-50, 50)));
219 sheet
->AddProperty(new wxProperty("julian", "one", "string"));
220 wxStringList
*strings
= new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL
);
221 sheet
->AddProperty(new wxProperty("constrained", "one", "string", new wxStringFormValidator(strings
)));
223 wxPropertyFormView
*view
= new wxPropertyFormView(NULL
);
225 wxDialog
*propDialog
= NULL
;
226 wxPropertyFormFrame
*propFrame
= NULL
;
229 propDialog
= new PropFormDialog(view
, NULL
, "Property Form Test",
230 wxPoint(-1, -1), wxSize(380, 250), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
231 m_childWindow
= propDialog
;
235 propFrame
= new PropFormFrame(view
, NULL
, "Property Form Test", wxPoint(-1,
236 -1), wxSize(380, 250));
237 propFrame
->Initialize();
238 m_childWindow
= propFrame
;
241 wxWindow
*panel
= propDialog
? propDialog
: propFrame
->GetPropertyPanel();
242 wxLayoutConstraints
* c
;
247 c
= new wxLayoutConstraints
;
248 c
->left
.SameAs(m_childWindow
, wxLeft
, 4);
249 c
->right
.SameAs(m_childWindow
, wxRight
, 4);
250 c
->top
.SameAs(m_childWindow
, wxTop
, 4);
251 c
->bottom
.SameAs(m_childWindow
, wxBottom
, 40);
253 panel
->SetConstraints(c
);
257 // Add items to the panel
258 wxButton
*okButton
= new wxButton(panel
, wxID_OK
, "OK", wxPoint(-1, -1),
259 wxSize(80, 26), 0, wxDefaultValidator
, "ok");
260 wxButton
*cancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1),
261 wxSize(80, 26), 0, wxDefaultValidator
, "cancel");
262 wxButton
*updateButton
= new wxButton(panel
, wxID_PROP_UPDATE
, "Update", wxPoint(-1, -1),
263 wxSize(80, 26), 0, wxDefaultValidator
, "update");
264 wxButton
*revertButton
= new wxButton(panel
, wxID_PROP_REVERT
, "Revert", wxPoint(-1, -1),
265 wxSize(80, 26), 0, wxDefaultValidator
, "revert");
267 c
= new wxLayoutConstraints
;
268 c
->right
.SameAs(panel
, wxRight
, 4);
269 c
->bottom
.SameAs(panel
, wxBottom
, 4);
272 revertButton
->SetConstraints(c
);
274 c
= new wxLayoutConstraints
;
275 c
->right
.SameAs(revertButton
, wxLeft
, 4);
276 c
->bottom
.SameAs(panel
, wxBottom
, 4);
279 updateButton
->SetConstraints(c
);
281 c
= new wxLayoutConstraints
;
282 c
->right
.SameAs(updateButton
, wxLeft
, 4);
283 c
->bottom
.SameAs(panel
, wxBottom
, 4);
286 cancelButton
->SetConstraints(c
);
288 c
= new wxLayoutConstraints
;
289 c
->right
.SameAs(cancelButton
, wxLeft
, 4);
290 c
->bottom
.SameAs(panel
, wxBottom
, 4);
293 okButton
->SetConstraints(c
);
295 // The name of this text item matches the "fred" property
296 wxTextCtrl
*text
= new wxTextCtrl(panel
, -1, "Fred", wxPoint(-1, -1), wxSize(
297 200, -1), 0, wxDefaultValidator
, "fred");
299 c
= new wxLayoutConstraints
;
300 c
->left
.SameAs(panel
, wxLeft
, 4);
301 c
->top
.SameAs(panel
, wxTop
, 4);
304 text
->SetConstraints(c
);
306 wxCheckBox
*checkBox
= new wxCheckBox(panel
, -1, "Yes or no", wxPoint(-1, -1),
307 wxSize(-1, -1), 0, wxDefaultValidator
, "tough choice");
309 c
= new wxLayoutConstraints
;
310 c
->left
.SameAs(text
, wxRight
, 20);
311 c
->top
.SameAs(panel
, wxTop
, 4);
314 checkBox
->SetConstraints(c
);
316 wxSlider
*slider
= new wxSlider(panel
, -1, -50, 50, 150, wxPoint(-1, -1),
317 wxSize(200,10), 0, wxDefaultValidator
, "ian");
319 c
= new wxLayoutConstraints
;
320 c
->left
.SameAs(panel
, wxLeft
, 4);
321 c
->top
.SameAs(text
, wxBottom
, 10);
324 slider
->SetConstraints(c
);
326 wxListBox
*listBox
= new wxListBox(panel
, -1, wxPoint(-1, -1), wxSize(200, 100),
327 0, NULL
, 0, wxDefaultValidator
, "constrained");
329 c
= new wxLayoutConstraints
;
330 c
->left
.SameAs(panel
, wxLeft
, 4);
331 c
->top
.SameAs(slider
, wxBottom
, 10);
334 listBox
->SetConstraints(c
);
336 view
->AddRegistry(&myFormValidatorRegistry
);
338 panel
->SetAutoLayout(TRUE
);
340 view
->ShowView(sheet
, panel
);
341 view
->AssociateNames();
342 view
->TransferToDialog();
345 propDialog
->Layout();
346 propDialog
->Centre(wxBOTH
);
347 propDialog
->Show(TRUE
);
350 propFrame
->Centre(wxBOTH
);
351 propFrame
->Show(TRUE
);
355 BEGIN_EVENT_TABLE(PropListFrame
, wxPropertyListFrame
)
356 EVT_CLOSE(PropListFrame::OnCloseWindow
)
359 void PropListFrame::OnCloseWindow(wxCloseEvent
& event
)
361 wxGetApp().m_childWindow
= NULL
;
363 wxPropertyListFrame::OnCloseWindow(event
);
366 BEGIN_EVENT_TABLE(PropListDialog
, wxPropertyListDialog
)
367 EVT_CLOSE(PropListDialog::OnCloseWindow
)
370 void PropListDialog::OnCloseWindow(wxCloseEvent
& event
)
372 wxGetApp().m_childWindow
= NULL
;
374 wxPropertyListDialog::OnCloseWindow(event
);
377 BEGIN_EVENT_TABLE(PropFormFrame
, wxPropertyFormFrame
)
378 EVT_CLOSE(PropFormFrame::OnCloseWindow
)
379 EVT_SIZE(PropFormFrame::OnSize
)
382 void PropFormFrame::OnCloseWindow(wxCloseEvent
& event
)
384 wxGetApp().m_childWindow
= NULL
;
386 wxPropertyFormFrame::OnCloseWindow(event
);
389 void PropFormFrame::OnSize(wxSizeEvent
& event
)
391 wxPropertyFormFrame::OnSize(event
);
392 GetPropertyPanel()->Layout();
395 BEGIN_EVENT_TABLE(PropFormDialog
, wxPropertyFormDialog
)
396 EVT_CLOSE(PropFormDialog::OnCloseWindow
)
399 void PropFormDialog::OnCloseWindow(wxCloseEvent
& event
)
401 wxGetApp().m_childWindow
= NULL
;
403 wxPropertyFormDialog::OnCloseWindow(event
);