• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/amule/wxWidgets-2.8.12/contrib/samples/deprecated/proplist/
1/////////////////////////////////////////////////////////////////////////////
2// Name:        proplist.cpp
3// Purpose:     Property sheet test implementation
4// Author:      Julian Smart
5// Modified by:
6// Created:     04/01/98
7// RCS-ID:      $Id: proplist.cpp 35650 2005-09-23 12:56:45Z MR $
8// Copyright:   (c) Julian Smart
9// Licence:     wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
23#include "wx/deprecated/setup.h"
24
25#if !wxUSE_PROPSHEET
26#error Please set wxUSE_PROPSHEET to 1 in contrib/include/wx/deprecated/setup.h and recompile.
27#endif
28
29#include "proplist.h"
30
31IMPLEMENT_APP(MyApp)
32
33wxPropertyValidatorRegistry myListValidatorRegistry;
34wxPropertyValidatorRegistry myFormValidatorRegistry;
35
36MyApp::MyApp(void)
37{
38    m_childWindow = NULL;
39    m_mainFrame = NULL;
40}
41
42bool MyApp::OnInit(void)
43{
44  RegisterValidators();
45
46  // Create the main frame window
47  m_mainFrame = new MyFrame(NULL, _T("wxPropertySheet Demo"), wxPoint(0, 0), wxSize(300, 400), wxDEFAULT_FRAME_STYLE);
48
49  // Make a menubar
50  wxMenu *file_menu = new wxMenu;
51  file_menu->Append(PROPERTY_TEST_DIALOG_LIST, _T("Test property list &dialog..."));
52  file_menu->Append(PROPERTY_TEST_FRAME_LIST, _T("Test property list &frame..."));
53  file_menu->AppendSeparator();
54  file_menu->Append(PROPERTY_TEST_DIALOG_FORM, _T("Test property form d&ialog..."));
55  file_menu->Append(PROPERTY_TEST_FRAME_FORM, _T("Test property form f&rame..."));
56  file_menu->AppendSeparator();
57  file_menu->Append(PROPERTY_QUIT, _T("E&xit"));
58
59  wxMenu *help_menu = new wxMenu;
60  help_menu->Append(PROPERTY_ABOUT, _T("&About"));
61
62  wxMenuBar *menu_bar = new wxMenuBar;
63
64  menu_bar->Append(file_menu, _T("&File"));
65  menu_bar->Append(help_menu, _T("&Help"));
66
67  // Associate the menu bar with the frame
68  m_mainFrame->SetMenuBar(menu_bar);
69
70  m_mainFrame->Centre(wxBOTH);
71  m_mainFrame->Show(true);
72
73  SetTopWindow(m_mainFrame);
74
75  return true;
76}
77
78BEGIN_EVENT_TABLE(MyFrame, wxFrame)
79    EVT_CLOSE(MyFrame::OnCloseWindow)
80    EVT_MENU(PROPERTY_QUIT, MyFrame::OnQuit)
81    EVT_MENU(PROPERTY_ABOUT, MyFrame::OnAbout)
82    EVT_MENU(PROPERTY_TEST_DIALOG_LIST, MyFrame::OnDialogList)
83    EVT_MENU(PROPERTY_TEST_FRAME_LIST, MyFrame::OnFrameList)
84    EVT_MENU(PROPERTY_TEST_DIALOG_FORM, MyFrame::OnDialogForm)
85    EVT_MENU(PROPERTY_TEST_FRAME_FORM, MyFrame::OnFrameForm)
86END_EVENT_TABLE()
87
88// Define my frame constructor
89MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size, long type):
90  wxFrame(frame, wxID_ANY, title, pos, size, type)
91{
92}
93
94// Define the behaviour for the frame closing
95// - must delete all frames except for the main one.
96void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
97{
98    if (wxGetApp().m_childWindow)
99    {
100        wxGetApp().m_childWindow->Close(true);
101    }
102
103    Destroy();
104}
105
106void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
107{
108    Close(true);
109}
110
111void MyFrame::OnDialogList(wxCommandEvent& WXUNUSED(event))
112{
113    wxGetApp().PropertyListTest(true);
114}
115
116void MyFrame::OnFrameList(wxCommandEvent& WXUNUSED(event))
117{
118    wxGetApp().PropertyListTest(false);
119}
120
121void MyFrame::OnDialogForm(wxCommandEvent& WXUNUSED(event))
122{
123    wxGetApp().PropertyFormTest(true);
124}
125
126void MyFrame::OnFrameForm(wxCommandEvent& WXUNUSED(event))
127{
128    wxGetApp().PropertyFormTest(false);
129}
130
131void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
132{
133    (void)wxMessageBox(_T("Property Classes Demo\nAuthor: Julian Smart"), _T("About Property Classes Test"));
134}
135
136void MyApp::RegisterValidators(void)
137{
138  myListValidatorRegistry.RegisterValidator((wxString)_T("real"), new wxRealListValidator);
139  myListValidatorRegistry.RegisterValidator((wxString)_T("string"), new wxStringListValidator);
140  myListValidatorRegistry.RegisterValidator((wxString)_T("integer"), new wxIntegerListValidator);
141  myListValidatorRegistry.RegisterValidator((wxString)_T("bool"), new wxBoolListValidator);
142  myListValidatorRegistry.RegisterValidator((wxString)_T("stringlist"), new wxListOfStringsListValidator);
143
144  myFormValidatorRegistry.RegisterValidator((wxString)_T("real"), new wxRealFormValidator);
145  myFormValidatorRegistry.RegisterValidator((wxString)_T("string"), new wxStringFormValidator);
146  myFormValidatorRegistry.RegisterValidator((wxString)_T("integer"), new wxIntegerFormValidator);
147  myFormValidatorRegistry.RegisterValidator((wxString)_T("bool"), new wxBoolFormValidator);
148}
149
150void MyApp::PropertyListTest(bool useDialog)
151{
152    if (m_childWindow)
153        return;
154
155    wxPropertySheet *sheet = new wxPropertySheet;
156
157    sheet->AddProperty(new wxProperty(_T("fred"), 1.0, _T("real")));
158    sheet->AddProperty(new wxProperty(_T("tough choice"), true, _T("bool")));
159    sheet->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerListValidator(-50, 50)));
160    sheet->AddProperty(new wxProperty(_T("bill"), 25.0, _T("real"), new wxRealListValidator(0.0, 100.0)));
161    sheet->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string")));
162    sheet->AddProperty(new wxProperty(_T("bitmap"), _T("none"), _T("string"), new wxFilenameListValidator(_T("Select a bitmap file"), _T("*.bmp"))));
163    wxStringList *strings = new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL);
164    sheet->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringListValidator(strings)));
165
166    wxStringList *strings2 = new wxStringList(wxT("earth"), wxT("fire"), wxT("wind"), wxT("water"), NULL);
167    sheet->AddProperty(new wxProperty(_T("string list"), strings2, _T("stringlist")));
168
169    wxPropertyListView *view = new wxPropertyListView
170        (
171            NULL,
172            wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS
173            | wxPROP_DYNAMIC_VALUE_FIELD | wxPROP_PULLDOWN | wxPROP_SHOWVALUES
174        );
175
176    PropListDialog *propDialog = NULL;
177    PropListFrame *propFrame = NULL;
178    if (useDialog)
179    {
180        propDialog = new PropListDialog(view, NULL, _T("Property Sheet Test"),
181            wxDefaultPosition, wxSize(400, 500));
182        m_childWindow = propDialog;
183    }
184    else
185    {
186        propFrame = new PropListFrame(view, NULL, _T("Property Sheet Test"),
187            wxDefaultPosition, wxSize(400, 500));
188        m_childWindow = propFrame;
189    }
190
191    view->AddRegistry(&myListValidatorRegistry);
192
193    if (useDialog)
194    {
195        view->ShowView(sheet, (wxPanel *)propDialog);
196    }
197    else
198    {
199        propFrame->Initialize();
200        view->ShowView(sheet, propFrame->GetPropertyPanel());
201    }
202
203    m_childWindow->Centre(wxBOTH);
204    m_childWindow->Show(true);
205}
206
207void MyApp::PropertyFormTest(bool useDialog)
208{
209    if (m_childWindow)
210        return;
211
212    wxPropertySheet *sheet = new wxPropertySheet;
213
214    sheet->AddProperty(new wxProperty(_T("fred"), 25.0, _T("real"), new wxRealFormValidator(0.0, 100.0)));
215    sheet->AddProperty(new wxProperty(_T("tough choice"), true, _T("bool")));
216    sheet->AddProperty(new wxProperty(_T("ian"), (long)45, _T("integer"), new wxIntegerFormValidator(-50, 50)));
217    sheet->AddProperty(new wxProperty(_T("julian"), _T("one"), _T("string")));
218    wxStringList *strings = new wxStringList(wxT("one"), wxT("two"), wxT("three"), NULL);
219    sheet->AddProperty(new wxProperty(_T("constrained"), _T("one"), _T("string"), new wxStringFormValidator(strings)));
220
221    wxPropertyFormView *view = new wxPropertyFormView(NULL);
222
223    wxDialog *propDialog = NULL;
224    wxPropertyFormFrame *propFrame = NULL;
225
226    if (useDialog)
227    {
228        propDialog = new PropFormDialog(view, NULL, _T("Property Form Test"),
229            wxDefaultPosition, wxSize(380, 250));
230        m_childWindow = propDialog;
231    }
232    else
233    {
234        propFrame = new PropFormFrame(view, NULL, _T("Property Form Test"),
235            wxDefaultPosition, wxSize(380, 250));
236        propFrame->Initialize();
237        m_childWindow = propFrame;
238    }
239
240    // BCC32 does not like ?:
241    wxWindow *panel ;
242    if ( propDialog )
243    {
244        panel = propDialog;
245    }
246    else
247    {
248        panel = propFrame->GetPropertyPanel() ;
249    }
250
251    wxLayoutConstraints* c;
252
253#if 0
254    if (!propDialog)
255    {
256        c = new wxLayoutConstraints;
257        c->left.SameAs(m_childWindow, wxLeft, 4);
258        c->right.SameAs(m_childWindow, wxRight, 4);
259        c->top.SameAs(m_childWindow, wxTop, 4);
260        c->bottom.SameAs(m_childWindow, wxBottom, 40);
261
262        panel->SetConstraints(c);
263    }
264#endif
265
266    // Add items to the panel
267    wxButton *okButton = new wxButton(panel, wxID_OK, _T("OK"), wxDefaultPosition,
268        wxSize(80, 26), 0, wxDefaultValidator, _T("ok"));
269    wxButton *cancelButton = new wxButton(panel, wxID_CANCEL, _T("Cancel"),  wxDefaultPosition,
270        wxSize(80, 26), 0, wxDefaultValidator, _T("cancel"));
271    wxButton *updateButton = new wxButton(panel, wxID_PROP_UPDATE, _T("Update"),  wxDefaultPosition,
272        wxSize(80, 26), 0, wxDefaultValidator, _T("update"));
273    wxButton *revertButton = new wxButton(panel, wxID_PROP_REVERT, _T("Revert"),  wxDefaultPosition,
274        wxSize(80, 26), 0, wxDefaultValidator, _T("revert"));
275
276    c = new wxLayoutConstraints;
277    c->right.SameAs(panel, wxRight, 4);
278    c->bottom.SameAs(panel, wxBottom, 4);
279    c->height.AsIs();
280    c->width.AsIs();
281    revertButton->SetConstraints(c);
282
283    c = new wxLayoutConstraints;
284    c->right.SameAs(revertButton, wxLeft, 4);
285    c->bottom.SameAs(panel, wxBottom, 4);
286    c->height.AsIs();
287    c->width.AsIs();
288    updateButton->SetConstraints(c);
289
290    c = new wxLayoutConstraints;
291    c->right.SameAs(updateButton, wxLeft, 4);
292    c->bottom.SameAs(panel, wxBottom, 4);
293    c->height.AsIs();
294    c->width.AsIs();
295    cancelButton->SetConstraints(c);
296
297    c = new wxLayoutConstraints;
298    c->right.SameAs(cancelButton, wxLeft, 4);
299    c->bottom.SameAs(panel, wxBottom, 4);
300    c->height.AsIs();
301    c->width.AsIs();
302    okButton->SetConstraints(c);
303
304    // The name of this text item matches the "fred" property
305    wxTextCtrl *text = new wxTextCtrl(panel, wxID_ANY, _T("Fred"), wxDefaultPosition,
306        wxSize( 200, wxDefaultCoord), 0, wxDefaultValidator, _T("fred"));
307
308    c = new wxLayoutConstraints;
309    c->left.SameAs(panel, wxLeft, 4);
310    c->top.SameAs(panel, wxTop, 4);
311    c->height.AsIs();
312    c->width.AsIs();
313    text->SetConstraints(c);
314
315    wxCheckBox *checkBox = new wxCheckBox(panel, wxID_ANY, _T("Yes or no"), wxDefaultPosition,
316        wxDefaultSize, 0, wxDefaultValidator, _T("tough choice"));
317
318    c = new wxLayoutConstraints;
319    c->left.SameAs(text, wxRight, 20);
320    c->top.SameAs(panel, wxTop, 4);
321    c->height.AsIs();
322    c->width.AsIs();
323    checkBox->SetConstraints(c);
324
325    wxSlider *slider = new wxSlider(panel, wxID_ANY, -50, 50, 150, wxDefaultPosition,
326    wxSize(200,10), 0, wxDefaultValidator, _T("ian"));
327
328    c = new wxLayoutConstraints;
329    c->left.SameAs(panel, wxLeft, 4);
330    c->top.SameAs(text, wxBottom, 10);
331    c->height.AsIs();
332    c->width.AsIs();
333    slider->SetConstraints(c);
334
335    wxListBox *listBox = new wxListBox(panel, wxID_ANY, wxDefaultPosition,
336        wxSize(200, 100), 0, NULL, 0, wxDefaultValidator, _T("constrained"));
337
338    c = new wxLayoutConstraints;
339    c->left.SameAs(panel, wxLeft, 4);
340    c->top.SameAs(slider, wxBottom, 10);
341    c->height.AsIs();
342    c->width.AsIs();
343    listBox->SetConstraints(c);
344
345    view->AddRegistry(&myFormValidatorRegistry);
346
347    panel->SetAutoLayout(true);
348
349    view->ShowView(sheet, panel);
350    view->AssociateNames();
351    view->TransferToDialog();
352
353    if (useDialog) {
354        propDialog->Layout();
355    }
356    else
357    {
358        // panel->Layout();
359    }
360    m_childWindow->Centre(wxBOTH);
361    m_childWindow->Show(true);
362}
363
364BEGIN_EVENT_TABLE(PropListFrame, wxPropertyListFrame)
365    EVT_CLOSE(PropListFrame::OnCloseWindow)
366END_EVENT_TABLE()
367
368void PropListFrame::OnCloseWindow(wxCloseEvent& event)
369{
370    wxGetApp().m_childWindow = NULL;
371
372    wxPropertyListFrame::OnCloseWindow(event);
373}
374
375BEGIN_EVENT_TABLE(PropListDialog, wxPropertyListDialog)
376    EVT_CLOSE(PropListDialog::OnCloseWindow)
377END_EVENT_TABLE()
378
379void PropListDialog::OnCloseWindow(wxCloseEvent& event)
380{
381    wxGetApp().m_childWindow = NULL;
382
383    wxPropertyListDialog::OnCloseWindow(event);
384}
385
386BEGIN_EVENT_TABLE(PropFormFrame, wxPropertyFormFrame)
387    EVT_CLOSE(PropFormFrame::OnCloseWindow)
388    EVT_SIZE(PropFormFrame::OnSize)
389END_EVENT_TABLE()
390
391void PropFormFrame::OnCloseWindow(wxCloseEvent& event)
392{
393    wxGetApp().m_childWindow = NULL;
394
395    wxPropertyFormFrame::OnCloseWindow(event);
396}
397
398void PropFormFrame::OnSize(wxSizeEvent& event)
399{
400    wxPropertyFormFrame::OnSize(event);
401    GetPropertyPanel()->Layout();
402}
403
404BEGIN_EVENT_TABLE(PropFormDialog, wxPropertyFormDialog)
405    EVT_CLOSE(PropFormDialog::OnCloseWindow)
406END_EVENT_TABLE()
407
408void PropFormDialog::OnCloseWindow(wxCloseEvent& event)
409{
410    wxGetApp().m_childWindow = NULL;
411
412    wxPropertyFormDialog::OnCloseWindow(event);
413}
414
415