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"
29 // A macro needed for some compilers (AIX) that need 'main' to be defined
30 // in the application itself.
35 wxPropertyValidatorRegistry myListValidatorRegistry
;
36 wxPropertyValidatorRegistry myFormValidatorRegistry
;
44 bool MyApp::OnInit(void)
48 // Create the main frame window
49 m_mainFrame
= new MyFrame(NULL
, "wxPropertySheet Demo", wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME_STYLE
);
52 wxMenu
*file_menu
= new wxMenu
;
53 file_menu
->Append(PROPERTY_TEST_DIALOG_LIST
, "Test property list &dialog...");
54 file_menu
->Append(PROPERTY_TEST_FRAME_LIST
, "Test property list &frame...");
55 file_menu
->AppendSeparator();
56 file_menu
->Append(PROPERTY_TEST_DIALOG_FORM
, "Test property form d&ialog...");
57 file_menu
->Append(PROPERTY_TEST_FRAME_FORM
, "Test property form f&rame...");
58 file_menu
->AppendSeparator();
59 file_menu
->Append(PROPERTY_QUIT
, "E&xit");
61 wxMenu
*help_menu
= new wxMenu
;
62 help_menu
->Append(PROPERTY_ABOUT
, "&About");
64 wxMenuBar
*menu_bar
= new wxMenuBar
;
66 menu_bar
->Append(file_menu
, "&File");
67 menu_bar
->Append(help_menu
, "&Help");
69 // Associate the menu bar with the frame
70 m_mainFrame
->SetMenuBar(menu_bar
);
72 m_mainFrame
->Centre(wxBOTH
);
73 m_mainFrame
->Show(TRUE
);
75 SetTopWindow(m_mainFrame
);
80 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
81 EVT_CLOSE(MyFrame::OnCloseWindow
)
82 EVT_MENU(PROPERTY_QUIT
, MyFrame::OnQuit
)
83 EVT_MENU(PROPERTY_ABOUT
, MyFrame::OnAbout
)
84 EVT_MENU(PROPERTY_TEST_DIALOG_LIST
, MyFrame::OnDialogList
)
85 EVT_MENU(PROPERTY_TEST_FRAME_LIST
, MyFrame::OnFrameList
)
86 EVT_MENU(PROPERTY_TEST_DIALOG_FORM
, MyFrame::OnDialogForm
)
87 EVT_MENU(PROPERTY_TEST_FRAME_FORM
, MyFrame::OnFrameForm
)
90 // Define my frame constructor
91 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long type
):
92 wxFrame(frame
, -1, title
, pos
, size
, type
)
96 // Define the behaviour for the frame closing
97 // - must delete all frames except for the main one.
98 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
100 if (wxGetApp().m_childWindow
)
102 wxGetApp().m_childWindow
->Close(TRUE
);
108 void MyFrame::OnQuit(wxCommandEvent
& event
)
113 void MyFrame::OnDialogList(wxCommandEvent
& event
)
115 wxGetApp().PropertyListTest(TRUE
);
118 void MyFrame::OnFrameList(wxCommandEvent
& event
)
120 wxGetApp().PropertyListTest(FALSE
);
123 void MyFrame::OnDialogForm(wxCommandEvent
& event
)
125 wxGetApp().PropertyFormTest(TRUE
);
128 void MyFrame::OnFrameForm(wxCommandEvent
& event
)
130 wxGetApp().PropertyFormTest(FALSE
);
133 void MyFrame::OnAbout(wxCommandEvent
& event
)
135 (void)wxMessageBox("Property Classes Demo\nAuthor: Julian Smart", "About Property Classes Test");
138 void MyApp::RegisterValidators(void)
140 myListValidatorRegistry
.RegisterValidator((wxString
)"real", new wxRealListValidator
);
141 myListValidatorRegistry
.RegisterValidator((wxString
)"string", new wxStringListValidator
);
142 myListValidatorRegistry
.RegisterValidator((wxString
)"integer", new wxIntegerListValidator
);
143 myListValidatorRegistry
.RegisterValidator((wxString
)"bool", new wxBoolListValidator
);
144 myListValidatorRegistry
.RegisterValidator((wxString
)"stringlist", new wxListOfStringsListValidator
);
146 myFormValidatorRegistry
.RegisterValidator((wxString
)"real", new wxRealFormValidator
);
147 myFormValidatorRegistry
.RegisterValidator((wxString
)"string", new wxStringFormValidator
);
148 myFormValidatorRegistry
.RegisterValidator((wxString
)"integer", new wxIntegerFormValidator
);
149 myFormValidatorRegistry
.RegisterValidator((wxString
)"bool", new wxBoolFormValidator
);
152 void MyApp::PropertyListTest(bool useDialog
)
157 wxPropertySheet
*sheet
= new wxPropertySheet
;
159 sheet
->AddProperty(new wxProperty("fred", 1.0, "real"));
160 sheet
->AddProperty(new wxProperty("tough choice", (bool)TRUE
, "bool"));
161 sheet
->AddProperty(new wxProperty("ian", (long)45, "integer", new wxIntegerListValidator(-50, 50)));
162 sheet
->AddProperty(new wxProperty("bill", 25.0, "real", new wxRealListValidator(0.0, 100.0)));
163 sheet
->AddProperty(new wxProperty("julian", "one", "string"));
164 sheet
->AddProperty(new wxProperty("bitmap", "none", "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp")));
165 wxStringList
*strings
= new wxStringList("one", "two", "three", NULL
);
166 sheet
->AddProperty(new wxProperty("constrained", "one", "string", new wxStringListValidator(strings
)));
168 wxStringList
*strings2
= new wxStringList("earth", "fire", "wind", "water", NULL
);
169 sheet
->AddProperty(new wxProperty("string list", strings2
, "stringlist"));
171 wxPropertyListView
*view
=
172 new wxPropertyListView(NULL
,
173 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
175 wxDialog
*propDialog
= NULL
;
176 wxPropertyListFrame
*propFrame
= NULL
;
179 propDialog
= new PropListDialog(view
, NULL
, "Property Sheet Test",
180 wxPoint(-1, -1), wxSize(400, 500), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODELESS
);
181 m_childWindow
= propDialog
;
185 propFrame
= new PropListFrame(view
, NULL
, "Property Sheet Test", wxPoint(-1, -1), wxSize(400, 500));
186 m_childWindow
= propFrame
;
189 view
->AddRegistry(&myListValidatorRegistry
);
193 view
->ShowView(sheet
, propDialog
);
194 propDialog
->Centre(wxBOTH
);
195 propDialog
->Show(TRUE
);
199 propFrame
->Initialize();
200 view
->ShowView(sheet
, propFrame
->GetPropertyPanel());
202 propFrame
->Centre(wxBOTH
);
203 propFrame
->Show(TRUE
);
207 void MyApp::PropertyFormTest(bool useDialog
)
213 wxPropertySheet
*sheet
= new wxPropertySheet
;
215 sheet
->AddProperty(new wxProperty("fred", 25.0, "real", new wxRealFormValidator(0.0, 100.0)));
216 sheet
->AddProperty(new wxProperty("tough choice", (bool)TRUE
, "bool"));
217 sheet
->AddProperty(new wxProperty("ian", (long)45, "integer", new wxIntegerFormValidator(-50, 50)));
218 sheet
->AddProperty(new wxProperty("julian", "one", "string"));
219 wxStringList
*strings
= new wxStringList("one", "two", "three", NULL
);
220 sheet
->AddProperty(new wxProperty("constrained", "one", "string", new wxStringFormValidator(strings
)));
222 wxPropertyFormView
*view
= new wxPropertyFormView(NULL
);
224 wxDialogBox
*propDialog
= NULL
;
225 wxPropertyFormFrame
*propFrame
= NULL
;
228 propDialog
= new PropFormDialog(view
, NULL
, "Property Form Test", wxPoint(-1, -1), wxSize(380, 250),
229 wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
230 m_childWindow
= propDialog
;
234 propFrame
= new PropFormFrame(view
, NULL
, "Property Form Test", wxPoint(-1, -1), wxSize(280, 250));
235 propFrame
->Initialize();
236 m_childWindow
= propFrame
;
239 wxPanel
*panel
= propDialog
? propDialog
: propFrame
->GetPropertyPanel();
240 panel
->SetLabelPosition(wxVERTICAL
);
242 // Add items to the panel
244 (void) new wxButton(panel
, -1, "OK", -1, -1, -1, -1, 0, "ok");
245 (void) new wxButton(panel
, -1, "Cancel", -1, -1, 80, -1, 0, "cancel");
246 (void) new wxButton(panel
, -1, "Update", -1, -1, 80, -1, 0, "update");
247 (void) new wxButton(panel
, -1, "Revert", -1, -1, -1, -1, 0, "revert");
250 // The name of this text item matches the "fred" property
251 (void) new wxText(panel
, -1, "Fred", "", -1, -1, 90, -1, 0, "fred");
252 (void) new wxCheckBox(panel
, -1, "Yes or no", -1, -1, -1, -1, 0, "tough choice");
253 (void) new wxSlider(panel
, -1, "Scale", 0, -50, 50, 150, -1, -1, wxHORIZONTAL
, "ian");
255 (void) new wxListBox(panel
, -1, "Constrained", wxSINGLE
, -1, -1, 100, 90, 0, NULL
, 0, "constrained");
257 view
->AddRegistry(&myFormValidatorRegistry
);
261 view
->ShowView(sheet
, propDialog
);
262 view
->AssociateNames();
263 view
->TransferToDialog();
264 propDialog
->Centre(wxBOTH
);
265 propDialog
->Show(TRUE
);
269 view
->ShowView(sheet
, propFrame
->GetPropertyPanel());
270 view
->AssociateNames();
271 view
->TransferToDialog();
272 propFrame
->Centre(wxBOTH
);
273 propFrame
->Show(TRUE
);
278 BEGIN_EVENT_TABLE(PropListFrame
, wxPropertyListFrame
)
279 EVT_CLOSE(PropListFrame::OnCloseWindow
)
282 void PropListFrame::OnCloseWindow(wxCloseEvent
& event
)
284 wxGetApp().m_childWindow
= NULL
;
286 wxPropertyListFrame::OnCloseWindow(event
);
289 BEGIN_EVENT_TABLE(PropListDialog
, wxPropertyListDialog
)
290 EVT_CLOSE(PropListDialog::OnCloseWindow
)
293 void PropListDialog::OnCloseWindow(wxCloseEvent
& event
)
295 wxGetApp().m_childWindow
= NULL
;
297 wxPropertyListDialog::OnCloseWindow(event
);
300 BEGIN_EVENT_TABLE(PropFormFrame
, wxPropertyFormFrame
)
301 EVT_CLOSE(PropFormFrame::OnCloseWindow
)
304 void PropFormFrame::OnCloseWindow(wxCloseEvent
& event
)
306 wxGetApp().m_childWindow
= NULL
;
308 wxPropertyFormFrame::OnCloseWindow(event
);
311 BEGIN_EVENT_TABLE(PropFormDialog
, wxPropertyFormDialog
)
312 EVT_CLOSE(PropFormDialog::OnCloseWindow
)
315 void PropFormDialog::OnCloseWindow(wxCloseEvent
& event
)
317 wxGetApp().m_childWindow
= NULL
;
319 wxPropertyFormDialog::OnCloseWindow(event
);