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
)
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("one", "two", "three", NULL
);
216 sheet
->AddProperty(new wxProperty("constrained", "one", "string", new wxStringFormValidator(strings
)));
218 wxPropertyFormView
*view
= new wxPropertyFormView(NULL
);
220 wxDialogBox
*propDialog
= NULL
;
221 wxPropertyFormFrame
*propFrame
= NULL
;
224 propDialog
= new PropFormDialog(view
, NULL
, "Property Form Test", wxPoint(-1, -1), wxSize(380, 250),
225 wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
226 m_childWindow
= propDialog
;
230 propFrame
= new PropFormFrame(view
, NULL
, "Property Form Test", wxPoint(-1, -1), wxSize(280, 250));
231 propFrame
->Initialize();
232 m_childWindow
= propFrame
;
235 wxPanel
*panel
= propDialog
? propDialog
: propFrame
->GetPropertyPanel();
236 panel
->SetLabelPosition(wxVERTICAL
);
238 // Add items to the panel
240 (void) new wxButton(panel
, -1, "OK", -1, -1, -1, -1, 0, "ok");
241 (void) new wxButton(panel
, -1, "Cancel", -1, -1, 80, -1, 0, "cancel");
242 (void) new wxButton(panel
, -1, "Update", -1, -1, 80, -1, 0, "update");
243 (void) new wxButton(panel
, -1, "Revert", -1, -1, -1, -1, 0, "revert");
246 // The name of this text item matches the "fred" property
247 (void) new wxText(panel
, -1, "Fred", "", -1, -1, 90, -1, 0, "fred");
248 (void) new wxCheckBox(panel
, -1, "Yes or no", -1, -1, -1, -1, 0, "tough choice");
249 (void) new wxSlider(panel
, -1, "Scale", 0, -50, 50, 150, -1, -1, wxHORIZONTAL
, "ian");
251 (void) new wxListBox(panel
, -1, "Constrained", wxSINGLE
, -1, -1, 100, 90, 0, NULL
, 0, "constrained");
253 view
->AddRegistry(&myFormValidatorRegistry
);
257 view
->ShowView(sheet
, propDialog
);
258 view
->AssociateNames();
259 view
->TransferToDialog();
260 propDialog
->Centre(wxBOTH
);
261 propDialog
->Show(TRUE
);
265 view
->ShowView(sheet
, propFrame
->GetPropertyPanel());
266 view
->AssociateNames();
267 view
->TransferToDialog();
268 propFrame
->Centre(wxBOTH
);
269 propFrame
->Show(TRUE
);
274 BEGIN_EVENT_TABLE(PropListFrame
, wxPropertyListFrame
)
275 EVT_CLOSE(PropListFrame::OnCloseWindow
)
278 void PropListFrame::OnCloseWindow(wxCloseEvent
& event
)
280 wxGetApp().m_childWindow
= NULL
;
282 wxPropertyListFrame::OnCloseWindow(event
);
285 BEGIN_EVENT_TABLE(PropListDialog
, wxPropertyListDialog
)
286 EVT_CLOSE(PropListDialog::OnCloseWindow
)
289 void PropListDialog::OnCloseWindow(wxCloseEvent
& event
)
291 wxGetApp().m_childWindow
= NULL
;
293 wxPropertyListDialog::OnCloseWindow(event
);
296 BEGIN_EVENT_TABLE(PropFormFrame
, wxPropertyFormFrame
)
297 EVT_CLOSE(PropFormFrame::OnCloseWindow
)
300 void PropFormFrame::OnCloseWindow(wxCloseEvent
& event
)
302 wxGetApp().m_childWindow
= NULL
;
304 wxPropertyFormFrame::OnCloseWindow(event
);
307 BEGIN_EVENT_TABLE(PropFormDialog
, wxPropertyFormDialog
)
308 EVT_CLOSE(PropFormDialog::OnCloseWindow
)
311 void PropFormDialog::OnCloseWindow(wxCloseEvent
& event
)
313 wxGetApp().m_childWindow
= NULL
;
315 wxPropertyFormDialog::OnCloseWindow(event
);