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"
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(wxT("one"), wxT("two"), wxT("three"), NULL
);
162 sheet
->AddProperty(new wxProperty("constrained", "one", "string", new wxStringListValidator(strings
)));
164 wxStringList
*strings2
= new wxStringList(wxT("earth"), wxT("fire"), wxT("wind"), wxT("water"), NULL
);
165 sheet
->AddProperty(new wxProperty("string list", strings2
, "stringlist"));
167 wxPropertyListView
*view
=
168 new wxPropertyListView(NULL
,
169 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
|
170 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
172 wxDialog
*propDialog
= NULL
;
173 wxPropertyListFrame
*propFrame
= NULL
;
176 propDialog
= new PropListDialog(view
, NULL
, "Property Sheet Test",
177 wxPoint(-1, -1), wxSize(400, 500), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODELESS
);
178 m_childWindow
= propDialog
;
182 propFrame
= new PropListFrame(view
, NULL
, "Property Sheet Test", wxPoint(-1, -1), wxSize(400, 500));
183 m_childWindow
= propFrame
;
186 view
->AddRegistry(&myListValidatorRegistry
);
190 view
->ShowView(sheet
, propDialog
);
191 propDialog
->Centre(wxBOTH
);
192 propDialog
->Show(TRUE
);
196 propFrame
->Initialize();
197 view
->ShowView(sheet
, propFrame
->GetPropertyPanel());
199 propFrame
->Centre(wxBOTH
);
200 propFrame
->Show(TRUE
);
204 void MyApp::PropertyFormTest(bool useDialog
)
209 wxPropertySheet
*sheet
= new wxPropertySheet
;
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(wxT("one"), wxT("two"), wxT("three"), NULL
);
216 sheet
->AddProperty(new wxProperty("constrained", "one", "string", new wxStringFormValidator(strings
)));
218 wxPropertyFormView
*view
= new wxPropertyFormView(NULL
);
220 wxDialog
*propDialog
= NULL
;
221 wxPropertyFormFrame
*propFrame
= NULL
;
224 propDialog
= new PropFormDialog(view
, NULL
, "Property Form Test",
225 wxPoint(-1, -1), wxSize(380, 250), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
226 m_childWindow
= propDialog
;
230 propFrame
= new PropFormFrame(view
, NULL
, "Property Form Test", wxPoint(-1,
231 -1), wxSize(380, 250));
232 propFrame
->Initialize();
233 m_childWindow
= propFrame
;
236 wxPanel
*panel
= propDialog
? propDialog
: propFrame
->GetPropertyPanel();
237 wxLayoutConstraints
* c
;
242 c
= new wxLayoutConstraints
;
243 c
->left
.SameAs(m_childWindow
, wxLeft
, 4);
244 c
->right
.SameAs(m_childWindow
, wxRight
, 4);
245 c
->top
.SameAs(m_childWindow
, wxTop
, 4);
246 c
->bottom
.SameAs(m_childWindow
, wxBottom
, 40);
248 panel
->SetConstraints(c
);
252 // Add items to the panel
253 wxButton
*okButton
= new wxButton(panel
, wxID_OK
, "OK", wxPoint(-1, -1),
254 wxSize(80, 26), 0, wxDefaultValidator
, "ok");
255 wxButton
*cancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1),
256 wxSize(80, 26), 0, wxDefaultValidator
, "cancel");
257 wxButton
*updateButton
= new wxButton(panel
, wxID_PROP_UPDATE
, "Update", wxPoint(-1, -1),
258 wxSize(80, 26), 0, wxDefaultValidator
, "update");
259 wxButton
*revertButton
= new wxButton(panel
, wxID_PROP_REVERT
, "Revert", wxPoint(-1, -1),
260 wxSize(80, 26), 0, wxDefaultValidator
, "revert");
262 c
= new wxLayoutConstraints
;
263 c
->right
.SameAs(panel
, wxRight
, 4);
264 c
->bottom
.SameAs(panel
, wxBottom
, 4);
267 revertButton
->SetConstraints(c
);
269 c
= new wxLayoutConstraints
;
270 c
->right
.SameAs(revertButton
, wxLeft
, 4);
271 c
->bottom
.SameAs(panel
, wxBottom
, 4);
274 updateButton
->SetConstraints(c
);
276 c
= new wxLayoutConstraints
;
277 c
->right
.SameAs(updateButton
, wxLeft
, 4);
278 c
->bottom
.SameAs(panel
, wxBottom
, 4);
281 cancelButton
->SetConstraints(c
);
283 c
= new wxLayoutConstraints
;
284 c
->right
.SameAs(cancelButton
, wxLeft
, 4);
285 c
->bottom
.SameAs(panel
, wxBottom
, 4);
288 okButton
->SetConstraints(c
);
290 // The name of this text item matches the "fred" property
291 wxTextCtrl
*text
= new wxTextCtrl(panel
, -1, "Fred", wxPoint(-1, -1), wxSize(
292 200, -1), 0, wxDefaultValidator
, "fred");
294 c
= new wxLayoutConstraints
;
295 c
->left
.SameAs(panel
, wxLeft
, 4);
296 c
->top
.SameAs(panel
, wxTop
, 4);
299 text
->SetConstraints(c
);
301 wxCheckBox
*checkBox
= new wxCheckBox(panel
, -1, "Yes or no", wxPoint(-1, -1),
302 wxSize(-1, -1), 0, wxDefaultValidator
, "tough choice");
304 c
= new wxLayoutConstraints
;
305 c
->left
.SameAs(text
, wxRight
, 20);
306 c
->top
.SameAs(panel
, wxTop
, 4);
309 checkBox
->SetConstraints(c
);
311 wxSlider
*slider
= new wxSlider(panel
, -1, -50, 50, 150, wxPoint(-1, -1),
312 wxSize(200,10), 0, wxDefaultValidator
, "ian");
314 c
= new wxLayoutConstraints
;
315 c
->left
.SameAs(panel
, wxLeft
, 4);
316 c
->top
.SameAs(text
, wxBottom
, 10);
319 slider
->SetConstraints(c
);
321 wxListBox
*listBox
= new wxListBox(panel
, -1, wxPoint(-1, -1), wxSize(200, 100),
322 0, NULL
, 0, wxDefaultValidator
, "constrained");
324 c
= new wxLayoutConstraints
;
325 c
->left
.SameAs(panel
, wxLeft
, 4);
326 c
->top
.SameAs(slider
, wxBottom
, 10);
329 listBox
->SetConstraints(c
);
331 view
->AddRegistry(&myFormValidatorRegistry
);
333 panel
->SetAutoLayout(TRUE
);
335 view
->ShowView(sheet
, panel
);
336 view
->AssociateNames();
337 view
->TransferToDialog();
340 propDialog
->Layout();
341 propDialog
->Centre(wxBOTH
);
342 propDialog
->Show(TRUE
);
345 propFrame
->Centre(wxBOTH
);
346 propFrame
->Show(TRUE
);
350 BEGIN_EVENT_TABLE(PropListFrame
, wxPropertyListFrame
)
351 EVT_CLOSE(PropListFrame::OnCloseWindow
)
354 void PropListFrame::OnCloseWindow(wxCloseEvent
& event
)
356 wxGetApp().m_childWindow
= NULL
;
358 wxPropertyListFrame::OnCloseWindow(event
);
361 BEGIN_EVENT_TABLE(PropListDialog
, wxPropertyListDialog
)
362 EVT_CLOSE(PropListDialog::OnCloseWindow
)
365 void PropListDialog::OnCloseWindow(wxCloseEvent
& event
)
367 wxGetApp().m_childWindow
= NULL
;
369 wxPropertyListDialog::OnCloseWindow(event
);
372 BEGIN_EVENT_TABLE(PropFormFrame
, wxPropertyFormFrame
)
373 EVT_CLOSE(PropFormFrame::OnCloseWindow
)
374 EVT_SIZE(PropFormFrame::OnSize
)
377 void PropFormFrame::OnCloseWindow(wxCloseEvent
& event
)
379 wxGetApp().m_childWindow
= NULL
;
381 wxPropertyFormFrame::OnCloseWindow(event
);
384 void PropFormFrame::OnSize(wxSizeEvent
& event
)
386 wxPropertyFormFrame::OnSize(event
);
387 GetPropertyPanel()->Layout();
390 BEGIN_EVENT_TABLE(PropFormDialog
, wxPropertyFormDialog
)
391 EVT_CLOSE(PropFormDialog::OnCloseWindow
)
394 void PropFormDialog::OnCloseWindow(wxCloseEvent
& event
)
396 wxGetApp().m_childWindow
= NULL
;
398 wxPropertyFormDialog::OnCloseWindow(event
);