]> git.saurik.com Git - wxWidgets.git/blob - utils/wxprop/src/test.cpp
missing functions implemented in wxMSW tree ctrl (custom sorting,
[wxWidgets.git] / utils / wxprop / src / test.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: test.cpp
3 // Purpose: Property sheet test implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "test.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "test.h"
28
29 // A macro needed for some compilers (AIX) that need 'main' to be defined
30 // in the application itself.
31 IMPLEMENT_WXWIN_MAIN
32
33 IMPLEMENT_APP(MyApp)
34
35 wxPropertyValidatorRegistry myListValidatorRegistry;
36 wxPropertyValidatorRegistry myFormValidatorRegistry;
37
38 MyApp::MyApp(void)
39 {
40 m_childWindow = NULL;
41 m_mainFrame = NULL;
42 }
43
44 bool MyApp::OnInit(void)
45 {
46 RegisterValidators();
47
48 // Create the main frame window
49 m_mainFrame = new MyFrame(NULL, "wxPropertySheet Demo", wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME);
50
51 // Make a menubar
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");
60
61 wxMenu *help_menu = new wxMenu;
62 help_menu->Append(PROPERTY_ABOUT, "&About");
63
64 wxMenuBar *menu_bar = new wxMenuBar;
65
66 menu_bar->Append(file_menu, "&File");
67 menu_bar->Append(help_menu, "&Help");
68
69 // Associate the menu bar with the frame
70 m_mainFrame->SetMenuBar(menu_bar);
71
72 m_mainFrame->Centre(wxBOTH);
73 m_mainFrame->Show(TRUE);
74
75 SetTopWindow(m_mainFrame);
76
77 return TRUE;
78 }
79
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)
88 END_EVENT_TABLE()
89
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)
93 {
94 }
95
96 // Define the behaviour for the frame closing
97 // - must delete all frames except for the main one.
98 void MyFrame::OnCloseWindow(wxCloseEvent& event)
99 {
100 if (wxGetApp().m_childWindow)
101 {
102 wxGetApp().m_childWindow->Close(TRUE);
103 }
104
105 Destroy();
106 }
107
108 void MyFrame::OnQuit(wxCommandEvent& event)
109 {
110 Close(TRUE);
111 }
112
113 void MyFrame::OnDialogList(wxCommandEvent& event)
114 {
115 wxGetApp().PropertyListTest(TRUE);
116 }
117
118 void MyFrame::OnFrameList(wxCommandEvent& event)
119 {
120 wxGetApp().PropertyListTest(FALSE);
121 }
122
123 void MyFrame::OnDialogForm(wxCommandEvent& event)
124 {
125 wxGetApp().PropertyFormTest(TRUE);
126 }
127
128 void MyFrame::OnFrameForm(wxCommandEvent& event)
129 {
130 wxGetApp().PropertyFormTest(FALSE);
131 }
132
133 void MyFrame::OnAbout(wxCommandEvent& event)
134 {
135 (void)wxMessageBox("Property Classes Demo\nAuthor: Julian Smart", "About Property Classes Test");
136 }
137
138 void MyApp::RegisterValidators(void)
139 {
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);
145
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);
150 }
151
152 void MyApp::PropertyListTest(bool useDialog)
153 {
154 if (m_childWindow)
155 return;
156
157 wxPropertySheet *sheet = new wxPropertySheet;
158
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)));
167
168 wxStringList *strings2 = new wxStringList("earth", "fire", "wind", "water", NULL);
169 sheet->AddProperty(new wxProperty("string list", strings2, "stringlist"));
170
171 wxPropertyListView *view =
172 new wxPropertyListView(NULL,
173 wxPROP_BUTTON_CHECK_CROSS|wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES);
174
175 wxDialog *propDialog = NULL;
176 wxPropertyListFrame *propFrame = NULL;
177 if (useDialog)
178 {
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;
182 }
183 else
184 {
185 propFrame = new PropListFrame(view, NULL, "Property Sheet Test", wxPoint(-1, -1), wxSize(400, 500));
186 m_childWindow = propFrame;
187 }
188
189 view->AddRegistry(&myListValidatorRegistry);
190
191 if (useDialog)
192 {
193 view->ShowView(sheet, propDialog);
194 propDialog->Centre(wxBOTH);
195 propDialog->Show(TRUE);
196 }
197 else
198 {
199 propFrame->Initialize();
200 view->ShowView(sheet, propFrame->GetPropertyPanel());
201
202 propFrame->Centre(wxBOTH);
203 propFrame->Show(TRUE);
204 }
205 }
206
207 void MyApp::PropertyFormTest(bool useDialog)
208 {
209 if (m_childWindow)
210 return;
211
212 #if 0
213 wxPropertySheet *sheet = new wxPropertySheet;
214
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)));
221
222 wxPropertyFormView *view = new wxPropertyFormView(NULL);
223
224 wxDialogBox *propDialog = NULL;
225 wxPropertyFormFrame *propFrame = NULL;
226 if (useDialog)
227 {
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;
231 }
232 else
233 {
234 propFrame = new PropFormFrame(view, NULL, "Property Form Test", wxPoint(-1, -1), wxSize(280, 250));
235 propFrame->Initialize();
236 m_childWindow = propFrame;
237 }
238
239 wxPanel *panel = propDialog ? propDialog : propFrame->GetPropertyPanel();
240 panel->SetLabelPosition(wxVERTICAL);
241
242 // Add items to the panel
243
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");
248 panel->NewLine();
249
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");
254 panel->NewLine();
255 (void) new wxListBox(panel, -1, "Constrained", wxSINGLE, -1, -1, 100, 90, 0, NULL, 0, "constrained");
256
257 view->AddRegistry(&myFormValidatorRegistry);
258
259 if (useDialog)
260 {
261 view->ShowView(sheet, propDialog);
262 view->AssociateNames();
263 view->TransferToDialog();
264 propDialog->Centre(wxBOTH);
265 propDialog->Show(TRUE);
266 }
267 else
268 {
269 view->ShowView(sheet, propFrame->GetPropertyPanel());
270 view->AssociateNames();
271 view->TransferToDialog();
272 propFrame->Centre(wxBOTH);
273 propFrame->Show(TRUE);
274 }
275 #endif
276 }
277
278 BEGIN_EVENT_TABLE(PropListFrame, wxPropertyListFrame)
279 EVT_CLOSE(PropListFrame::OnCloseWindow)
280 END_EVENT_TABLE()
281
282 void PropListFrame::OnCloseWindow(wxCloseEvent& event)
283 {
284 wxGetApp().m_childWindow = NULL;
285
286 wxPropertyListFrame::OnCloseWindow(event);
287 }
288
289 BEGIN_EVENT_TABLE(PropListDialog, wxPropertyListDialog)
290 EVT_CLOSE(PropListDialog::OnCloseWindow)
291 END_EVENT_TABLE()
292
293 void PropListDialog::OnCloseWindow(wxCloseEvent& event)
294 {
295 wxGetApp().m_childWindow = NULL;
296
297 wxPropertyListDialog::OnCloseWindow(event);
298 }
299
300 BEGIN_EVENT_TABLE(PropFormFrame, wxPropertyFormFrame)
301 EVT_CLOSE(PropFormFrame::OnCloseWindow)
302 END_EVENT_TABLE()
303
304 void PropFormFrame::OnCloseWindow(wxCloseEvent& event)
305 {
306 wxGetApp().m_childWindow = NULL;
307
308 wxPropertyFormFrame::OnCloseWindow(event);
309 }
310
311 BEGIN_EVENT_TABLE(PropFormDialog, wxPropertyFormDialog)
312 EVT_CLOSE(PropFormDialog::OnCloseWindow)
313 END_EVENT_TABLE()
314
315 void PropFormDialog::OnCloseWindow(wxCloseEvent& event)
316 {
317 wxGetApp().m_childWindow = NULL;
318
319 wxPropertyFormDialog::OnCloseWindow(event);
320 }
321