]> git.saurik.com Git - wxWidgets.git/blame - src/generic/propform.cpp
Added a file
[wxWidgets.git] / src / generic / propform.cpp
CommitLineData
e3a43801
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: propform.cpp
3// Purpose: Property form classes
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
1e6feb95 9// Licence: wxWindows licence
e3a43801
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "propform.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
1e6feb95
VZ
23#if wxUSE_PROPSHEET
24
e3a43801 25#ifndef WX_PRECOMP
e3a43801
JS
26#endif
27
c693edf3
RR
28#include "wx/propform.h"
29
e3a43801
JS
30#include <ctype.h>
31#include <stdlib.h>
32#include <math.h>
33#include <string.h>
34
e3a43801
JS
35
36/*
f6bcfd97
BP
37* Property view
38*/
e3a43801
JS
39
40IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormView, wxPropertyView)
41
42BEGIN_EVENT_TABLE(wxPropertyFormView, wxPropertyView)
1e6feb95
VZ
43EVT_BUTTON(wxID_OK, wxPropertyFormView::OnOk)
44EVT_BUTTON(wxID_CANCEL, wxPropertyFormView::OnCancel)
45EVT_BUTTON(wxID_HELP, wxPropertyFormView::OnHelp)
46EVT_BUTTON(wxID_PROP_REVERT, wxPropertyFormView::OnRevert)
47EVT_BUTTON(wxID_PROP_UPDATE, wxPropertyFormView::OnUpdate)
e3a43801
JS
48END_EVENT_TABLE()
49
50bool wxPropertyFormView::sm_dialogCancelled = FALSE;
51
52wxPropertyFormView::wxPropertyFormView(wxWindow *propPanel, long flags):wxPropertyView(flags)
53{
f6bcfd97
BP
54 m_propertyWindow = propPanel;
55 m_managedWindow = NULL;
1e6feb95 56
f6bcfd97
BP
57 m_windowCloseButton = NULL;
58 m_windowCancelButton = NULL;
59 m_windowHelpButton = NULL;
1e6feb95 60
f6bcfd97 61 m_detailedEditing = FALSE;
e3a43801
JS
62}
63
64wxPropertyFormView::~wxPropertyFormView(void)
65{
66}
67
68void wxPropertyFormView::ShowView(wxPropertySheet *ps, wxWindow *panel)
69{
f6bcfd97 70 m_propertySheet = ps;
1e6feb95 71
f6bcfd97
BP
72 AssociatePanel(panel);
73 // CreateControls();
74 // UpdatePropertyList();
e3a43801
JS
75}
76
77// Update this view of the viewed object, called e.g. by
78// the object itself.
79bool wxPropertyFormView::OnUpdateView(void)
80{
f6bcfd97 81 return TRUE;
e3a43801
JS
82}
83
84bool wxPropertyFormView::Check(void)
85{
f6bcfd97
BP
86 if (!m_propertySheet)
87 return FALSE;
1e6feb95 88
f6bcfd97
BP
89 wxNode *node = m_propertySheet->GetProperties().First();
90 while (node)
e3a43801 91 {
f6bcfd97
BP
92 wxProperty *prop = (wxProperty *)node->Data();
93 wxPropertyValidator *validator = FindPropertyValidator(prop);
94 if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator)))
95 {
96 wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator;
97 if (!formValidator->OnCheckValue(prop, this, m_propertyWindow))
98 return FALSE;
99 }
100 node = node->Next();
e3a43801 101 }
f6bcfd97 102 return TRUE;
e3a43801
JS
103}
104
105bool wxPropertyFormView::TransferToPropertySheet(void)
106{
f6bcfd97
BP
107 if (!m_propertySheet)
108 return FALSE;
1e6feb95 109
f6bcfd97
BP
110 wxNode *node = m_propertySheet->GetProperties().First();
111 while (node)
e3a43801 112 {
f6bcfd97
BP
113 wxProperty *prop = (wxProperty *)node->Data();
114 wxPropertyValidator *validator = FindPropertyValidator(prop);
115 if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator)))
116 {
117 wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator;
118 formValidator->OnRetrieveValue(prop, this, m_propertyWindow);
119 }
120 node = node->Next();
e3a43801 121 }
f6bcfd97 122 return TRUE;
e3a43801
JS
123}
124
125bool wxPropertyFormView::TransferToDialog(void)
126{
f6bcfd97
BP
127 if (!m_propertySheet)
128 return FALSE;
1e6feb95 129
f6bcfd97
BP
130 wxNode *node = m_propertySheet->GetProperties().First();
131 while (node)
e3a43801 132 {
f6bcfd97
BP
133 wxProperty *prop = (wxProperty *)node->Data();
134 wxPropertyValidator *validator = FindPropertyValidator(prop);
135 if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator)))
136 {
137 wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator;
138 formValidator->OnDisplayValue(prop, this, m_propertyWindow);
139 }
140 node = node->Next();
e3a43801 141 }
f6bcfd97 142 return TRUE;
e3a43801
JS
143}
144
145bool wxPropertyFormView::AssociateNames(void)
146{
f6bcfd97
BP
147 if (!m_propertySheet || !m_propertyWindow)
148 return FALSE;
1e6feb95 149
f6bcfd97
BP
150 wxNode *node = m_propertyWindow->GetChildren().First();
151 while (node)
e3a43801 152 {
f6bcfd97
BP
153 wxWindow *win = (wxWindow *)node->Data();
154 if (win->GetName() != wxT(""))
155 {
156 wxProperty *prop = m_propertySheet->GetProperty(win->GetName());
157 if (prop)
158 prop->SetWindow(win);
159 }
160 node = node->Next();
e3a43801 161 }
f6bcfd97 162 return TRUE;
e3a43801
JS
163}
164
165
166bool wxPropertyFormView::OnClose(void)
167{
f6bcfd97
BP
168 if (m_propertyWindow->IsKindOf(CLASSINFO(wxPropertyFormPanel)))
169 {
170 ((wxPropertyFormPanel*)m_propertyWindow)->SetView(NULL);
171 }
172 delete this;
173 return TRUE;
e3a43801
JS
174}
175
176void wxPropertyFormView::OnOk(wxCommandEvent& WXUNUSED(event))
177{
f6bcfd97
BP
178 // Retrieve the value if any
179 if (!Check())
180 return;
1e6feb95 181
f6bcfd97
BP
182 sm_dialogCancelled = FALSE;
183 TransferToPropertySheet();
1e6feb95 184
f6bcfd97 185 m_managedWindow->Close(TRUE);
e3a43801
JS
186}
187
188void wxPropertyFormView::OnCancel(wxCommandEvent& WXUNUSED(event))
189{
f6bcfd97 190 sm_dialogCancelled = TRUE;
1e6feb95 191
f6bcfd97 192 m_managedWindow->Close(TRUE);
e3a43801
JS
193}
194
195void wxPropertyFormView::OnHelp(wxCommandEvent& WXUNUSED(event))
196{
197}
198
199void wxPropertyFormView::OnUpdate(wxCommandEvent& WXUNUSED(event))
200{
201 if (Check())
202 TransferToPropertySheet();
203}
204
205void wxPropertyFormView::OnRevert(wxCommandEvent& WXUNUSED(event))
206{
f6bcfd97 207 TransferToDialog();
e3a43801
JS
208}
209
210void wxPropertyFormView::OnCommand(wxWindow& win, wxCommandEvent& event)
211{
f6bcfd97
BP
212 if (!m_propertySheet)
213 return;
1e6feb95 214
f6bcfd97
BP
215 if (win.GetName() == wxT(""))
216 return;
1e6feb95 217
f6bcfd97
BP
218 if (wxStrcmp(win.GetName(), wxT("ok")) == 0)
219 OnOk(event);
220 else if (wxStrcmp(win.GetName(), wxT("cancel")) == 0)
221 OnCancel(event);
222 else if (wxStrcmp(win.GetName(), wxT("help")) == 0)
223 OnHelp(event);
224 else if (wxStrcmp(win.GetName(), wxT("update")) == 0)
225 OnUpdate(event);
226 else if (wxStrcmp(win.GetName(), wxT("revert")) == 0)
227 OnRevert(event);
228 else
e3a43801 229 {
f6bcfd97
BP
230 // Find a validator to route the command to.
231 wxNode *node = m_propertySheet->GetProperties().First();
232 while (node)
e3a43801 233 {
f6bcfd97
BP
234 wxProperty *prop = (wxProperty *)node->Data();
235 if (prop->GetWindow() && (prop->GetWindow() == &win))
236 {
237 wxPropertyValidator *validator = FindPropertyValidator(prop);
238 if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator)))
239 {
240 wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator;
241 formValidator->OnCommand(prop, this, m_propertyWindow, event);
242 return;
243 }
244 }
245 node = node->Next();
e3a43801 246 }
e3a43801 247 }
e3a43801
JS
248}
249
1b9315eb
JS
250// Extend event processing to call OnCommand
251bool wxPropertyFormView::ProcessEvent(wxEvent& event)
252{
253 if (wxEvtHandler::ProcessEvent(event))
254 return TRUE;
255 else if (event.IsCommandEvent() && !event.IsKindOf(CLASSINFO(wxUpdateUIEvent)) && event.GetEventObject())
256 {
257 OnCommand(* ((wxWindow*) event.GetEventObject()), (wxCommandEvent&) event);
258 return TRUE;
259 }
260 else
261 return FALSE;
262}
263
e3a43801
JS
264void wxPropertyFormView::OnDoubleClick(wxControl *item)
265{
f6bcfd97
BP
266 if (!m_propertySheet)
267 return;
1e6feb95 268
f6bcfd97
BP
269 // Find a validator to route the command to.
270 wxNode *node = m_propertySheet->GetProperties().First();
271 while (node)
e3a43801 272 {
f6bcfd97
BP
273 wxProperty *prop = (wxProperty *)node->Data();
274 if (prop->GetWindow() && ((wxControl *)prop->GetWindow() == item))
275 {
276 wxPropertyValidator *validator = FindPropertyValidator(prop);
277 if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator)))
278 {
279 wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator;
280 formValidator->OnDoubleClick(prop, this, m_propertyWindow);
281 return;
282 }
283 }
284 node = node->Next();
e3a43801 285 }
e3a43801
JS
286}
287
288/*
f6bcfd97
BP
289* Property form dialog box
290*/
291
292IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormDialog, wxDialog)
e3a43801 293
e3065973 294BEGIN_EVENT_TABLE(wxPropertyFormDialog, wxDialog)
f6bcfd97 295EVT_CLOSE(wxPropertyFormDialog::OnCloseWindow)
e3065973
JS
296END_EVENT_TABLE()
297
e3a43801 298wxPropertyFormDialog::wxPropertyFormDialog(wxPropertyFormView *v, wxWindow *parent, const wxString& title,
f6bcfd97
BP
299 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
300wxDialog(parent, -1, title, pos, size, style, name)
e3a43801 301{
f6bcfd97
BP
302 m_view = v;
303 m_view->AssociatePanel(this);
304 m_view->SetManagedWindow(this);
305 // SetAutoLayout(TRUE);
e3a43801
JS
306}
307
e3065973 308void wxPropertyFormDialog::OnCloseWindow(wxCloseEvent& event)
e3a43801 309{
f6bcfd97
BP
310 if (m_view)
311 {
312 m_view->OnClose();
313 m_view = NULL;
314 this->Destroy();
315 }
316 else
317 event.Veto();
e3a43801
JS
318}
319
320void wxPropertyFormDialog::OnDefaultAction(wxControl *item)
321{
f6bcfd97 322 m_view->OnDoubleClick(item);
e3a43801
JS
323}
324
325void wxPropertyFormDialog::OnCommand(wxWindow& win, wxCommandEvent& event)
326{
f6bcfd97
BP
327 if ( m_view )
328 m_view->OnCommand(win, event);
e3a43801
JS
329}
330
331// Extend event processing to search the view's event table
332bool wxPropertyFormDialog::ProcessEvent(wxEvent& event)
333{
f6bcfd97
BP
334 if ( !m_view || ! m_view->ProcessEvent(event) )
335 return wxEvtHandler::ProcessEvent(event);
336 else
337 return TRUE;
e3a43801
JS
338}
339
340
341/*
f6bcfd97
BP
342* Property form panel
343*/
344
345IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormPanel, wxPanel)
e3a43801
JS
346
347void wxPropertyFormPanel::OnDefaultAction(wxControl *item)
348{
f6bcfd97 349 m_view->OnDoubleClick(item);
e3a43801
JS
350}
351
352void wxPropertyFormPanel::OnCommand(wxWindow& win, wxCommandEvent& event)
353{
f6bcfd97 354 m_view->OnCommand(win, event);
e3a43801
JS
355}
356
357// Extend event processing to search the view's event table
358bool wxPropertyFormPanel::ProcessEvent(wxEvent& event)
359{
f6bcfd97
BP
360 if ( !m_view || ! m_view->ProcessEvent(event) )
361 return wxEvtHandler::ProcessEvent(event);
362 else
363 return TRUE;
e3a43801
JS
364}
365
366/*
f6bcfd97
BP
367* Property frame
368*/
369
370IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormFrame, wxFrame)
e3a43801 371
e3065973 372BEGIN_EVENT_TABLE(wxPropertyFormFrame, wxFrame)
f6bcfd97 373EVT_CLOSE(wxPropertyFormFrame::OnCloseWindow)
e3065973
JS
374END_EVENT_TABLE()
375
376void wxPropertyFormFrame::OnCloseWindow(wxCloseEvent& event)
e3a43801 377{
f6bcfd97
BP
378 if (m_view && m_view->OnClose())
379 this->Destroy();
380 else
381 event.Veto();
e3a43801
JS
382}
383
384wxPanel *wxPropertyFormFrame::OnCreatePanel(wxFrame *parent, wxPropertyFormView *v)
385{
f6bcfd97 386 return new wxPropertyFormPanel(v, parent);
e3a43801
JS
387}
388
389bool wxPropertyFormFrame::Initialize(void)
390{
f6bcfd97
BP
391 m_propertyPanel = OnCreatePanel(this, m_view);
392 if (m_propertyPanel)
393 {
394 m_view->AssociatePanel(m_propertyPanel);
395 m_view->SetManagedWindow(this);
396 return TRUE;
397 }
398 else
399 return FALSE;
e3a43801
JS
400}
401
f6bcfd97
BP
402/*
403* Property form specific validator
404*/
405
e3a43801
JS
406IMPLEMENT_ABSTRACT_CLASS(wxPropertyFormValidator, wxPropertyValidator)
407
408
409/*
f6bcfd97
BP
410* Default validators
411*/
e3a43801
JS
412
413IMPLEMENT_DYNAMIC_CLASS(wxRealFormValidator, wxPropertyFormValidator)
414
415///
416/// Real number form validator
1e6feb95
VZ
417///
418bool wxRealFormValidator::OnCheckValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 419 wxWindow *parentWindow)
e3a43801 420{
f6bcfd97
BP
421 if (m_realMin == 0.0 && m_realMax == 0.0)
422 return TRUE;
1e6feb95 423
f6bcfd97
BP
424 // The item used for viewing the real number: should be a text item.
425 wxWindow *m_propertyWindow = property->GetWindow();
426 if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
427 return FALSE;
1e6feb95 428
f6bcfd97 429 wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());
1e6feb95 430
f6bcfd97
BP
431 float val = 0.0;
432 if (!StringToFloat(WXSTRINGCAST value, &val))
433 {
434 wxChar buf[200];
435 wxSprintf(buf, wxT("Value %s is not a valid real number!"), (const wxChar *)value);
436 wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
437 return FALSE;
438 }
1e6feb95 439
f6bcfd97
BP
440 if (val < m_realMin || val > m_realMax)
441 {
442 wxChar buf[200];
443 wxSprintf(buf, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin, m_realMax);
444 wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
445 return FALSE;
446 }
447 return TRUE;
e3a43801
JS
448}
449
1e6feb95 450bool wxRealFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 451 wxWindow *WXUNUSED(parentWindow) )
e3a43801 452{
f6bcfd97
BP
453 // The item used for viewing the real number: should be a text item.
454 wxWindow *m_propertyWindow = property->GetWindow();
455 if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
456 return FALSE;
1e6feb95 457
f6bcfd97 458 wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());
1e6feb95 459
f6bcfd97
BP
460 if (value.Length() == 0)
461 return FALSE;
1e6feb95 462
f6bcfd97
BP
463 float f = (float)wxAtof((const wxChar *)value);
464 property->GetValue() = f;
465 return TRUE;
e3a43801
JS
466}
467
1e6feb95 468bool wxRealFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 469 wxWindow *WXUNUSED(parentWindow) )
e3a43801 470{
f6bcfd97
BP
471 // The item used for viewing the real number: should be a text item.
472 wxWindow *m_propertyWindow = property->GetWindow();
473 if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
474 return FALSE;
1e6feb95 475
f6bcfd97
BP
476 wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow;
477 textItem->SetValue(FloatToString(property->GetValue().RealValue()));
478 return TRUE;
e3a43801
JS
479}
480
481///
482/// Integer validator
1e6feb95 483///
e3a43801
JS
484IMPLEMENT_DYNAMIC_CLASS(wxIntegerFormValidator, wxPropertyFormValidator)
485
1e6feb95 486bool wxIntegerFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 487 wxWindow *parentWindow)
e3a43801 488{
f6bcfd97
BP
489 if (m_integerMin == 0.0 && m_integerMax == 0.0)
490 return TRUE;
1e6feb95 491
f6bcfd97
BP
492 // The item used for viewing the real number: should be a text item or a slider
493 wxWindow *m_propertyWindow = property->GetWindow();
494 if (!m_propertyWindow)
495 return FALSE;
1e6feb95 496
f6bcfd97 497 long val = 0;
1e6feb95 498
f6bcfd97
BP
499 if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
500 {
501 wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());
1e6feb95 502
f6bcfd97
BP
503 if (!StringToLong(WXSTRINGCAST value, &val))
504 {
505 wxChar buf[200];
506 wxSprintf(buf, wxT("Value %s is not a valid integer!"), (const wxChar *)value);
507 wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
508 return FALSE;
509 }
510 }
511 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider)))
e3a43801 512 {
f6bcfd97
BP
513 val = (long)((wxSlider *)m_propertyWindow)->GetValue();
514 }
515 else
516 return FALSE;
1e6feb95 517
f6bcfd97
BP
518 if (val < m_integerMin || val > m_integerMax)
519 {
520 char buf[200];
521 sprintf(buf, "Value must be an integer between %ld and %ld!", m_integerMin, m_integerMax);
522 wxMessageBox(buf, "Property value error", wxOK | wxICON_EXCLAMATION, parentWindow);
523 return FALSE;
e3a43801 524 }
f6bcfd97 525 return TRUE;
e3a43801
JS
526}
527
1e6feb95 528bool wxIntegerFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 529 wxWindow *WXUNUSED(parentWindow))
e3a43801 530{
f6bcfd97
BP
531 // The item used for viewing the real number: should be a text item or a slider
532 wxWindow *m_propertyWindow = property->GetWindow();
533 if (!m_propertyWindow)
534 return FALSE;
1e6feb95 535
f6bcfd97
BP
536 if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
537 {
538 wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());
1e6feb95 539
f6bcfd97
BP
540 if (value.Length() == 0)
541 return FALSE;
1e6feb95 542
f6bcfd97
BP
543 long i = wxAtol((const wxChar *)value);
544 property->GetValue() = i;
545 }
546 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider)))
547 {
548 property->GetValue() = (long)((wxSlider *)m_propertyWindow)->GetValue();
549 }
550 else
551 return FALSE;
1e6feb95 552
f6bcfd97 553 return TRUE;
e3a43801
JS
554}
555
1e6feb95 556bool wxIntegerFormValidator::OnDisplayValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 557 wxWindow *WXUNUSED(parentWindow))
e3a43801 558{
f6bcfd97
BP
559 // The item used for viewing the real number: should be a text item or a slider
560 wxWindow *m_propertyWindow = property->GetWindow();
561 if (!m_propertyWindow)
562 return FALSE;
1e6feb95 563
f6bcfd97
BP
564 if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
565 {
566 wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow;
567 textItem->SetValue(LongToString(property->GetValue().IntegerValue()));
568 }
569 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider)))
570 {
571 ((wxSlider *)m_propertyWindow)->SetValue((int)property->GetValue().IntegerValue());
572 }
573 else
574 return FALSE;
575 return TRUE;
e3a43801
JS
576}
577
578///
579/// Boolean validator
1e6feb95 580///
e3a43801
JS
581IMPLEMENT_DYNAMIC_CLASS(wxBoolFormValidator, wxPropertyFormValidator)
582
1e6feb95 583bool wxBoolFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 584 wxWindow *WXUNUSED(parentWindow))
e3a43801 585{
f6bcfd97
BP
586 // The item used for viewing the boolean: should be a checkbox
587 wxWindow *m_propertyWindow = property->GetWindow();
588 if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox)))
589 return FALSE;
1e6feb95 590
f6bcfd97 591 return TRUE;
e3a43801
JS
592}
593
1e6feb95 594bool wxBoolFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 595 wxWindow *WXUNUSED(parentWindow) )
e3a43801 596{
f6bcfd97
BP
597 // The item used for viewing the boolean: should be a checkbox.
598 wxWindow *m_propertyWindow = property->GetWindow();
599 if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox)))
600 return FALSE;
1e6feb95 601
f6bcfd97 602 wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow;
1e6feb95 603
f6bcfd97
BP
604 property->GetValue() = (bool)checkBox->GetValue();
605 return TRUE;
e3a43801
JS
606}
607
1e6feb95 608bool wxBoolFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 609 wxWindow *WXUNUSED(parentWindow))
e3a43801 610{
f6bcfd97
BP
611 // The item used for viewing the boolean: should be a checkbox.
612 wxWindow *m_propertyWindow = property->GetWindow();
613 if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox)))
614 return FALSE;
1e6feb95 615
f6bcfd97
BP
616 wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow;
617 checkBox->SetValue((bool)property->GetValue().BoolValue());
618 return TRUE;
e3a43801
JS
619}
620
621///
622/// String validator
1e6feb95 623///
e3a43801
JS
624IMPLEMENT_DYNAMIC_CLASS(wxStringFormValidator, wxPropertyFormValidator)
625
626wxStringFormValidator::wxStringFormValidator(wxStringList *list, long flags):
f6bcfd97 627wxPropertyFormValidator(flags)
e3a43801 628{
f6bcfd97 629 m_strings = list;
e3a43801
JS
630}
631
1e6feb95 632bool wxStringFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97 633 wxWindow *parentWindow )
e3a43801 634{
f6bcfd97
BP
635 if (!m_strings)
636 return TRUE;
1e6feb95 637
f6bcfd97
BP
638 // The item used for viewing the string: should be a text item, choice item or listbox.
639 wxWindow *m_propertyWindow = property->GetWindow();
640 if (!m_propertyWindow)
641 return FALSE;
642 if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
e3a43801 643 {
f6bcfd97
BP
644 wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow;
645 if (!m_strings->Member(text->GetValue()))
646 {
647 wxString s("Value ");
648 s += text->GetValue();
649 s += " is not valid.";
650 wxMessageBox(s, "Property value error", wxOK | wxICON_EXCLAMATION, parentWindow);
651 return FALSE;
652 }
e3a43801 653 }
f6bcfd97
BP
654 else
655 {
656 // Any other item constrains the string value,
657 // so we don't have to check it.
658 }
659 return TRUE;
e3a43801
JS
660}
661
1e6feb95 662bool wxStringFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97
BP
663 wxWindow *WXUNUSED(parentWindow) )
664{
665 // The item used for viewing the string: should be a text item, choice item or listbox.
666 wxWindow *m_propertyWindow = property->GetWindow();
667 if (!m_propertyWindow)
668 return FALSE;
669 if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
670 {
671 wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow;
672 property->GetValue() = text->GetValue();
673 }
674 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox)))
675 {
676 wxListBox *lbox = (wxListBox *)m_propertyWindow;
677 if (lbox->GetSelection() > -1)
678 property->GetValue() = lbox->GetStringSelection();
679 }
680 /*
681 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox)))
682 {
e3a43801
JS
683 wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
684 int n = 0;
685 if ((n = rbox->GetSelection()) > -1)
f6bcfd97
BP
686 property->GetValue() = rbox->GetString(n);
687 }
688 */
689 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice)))
690 {
691 wxChoice *choice = (wxChoice *)m_propertyWindow;
692 if (choice->GetSelection() > -1)
693 property->GetValue() = choice->GetStringSelection();
694 }
695 else
696 return FALSE;
697 return TRUE;
e3a43801
JS
698}
699
1e6feb95 700bool wxStringFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
f6bcfd97
BP
701 wxWindow *WXUNUSED(parentWindow) )
702{
703 // The item used for viewing the string: should be a text item, choice item or listbox.
704 wxWindow *m_propertyWindow = property->GetWindow();
705 if (!m_propertyWindow)
706 return FALSE;
707 if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
e3a43801 708 {
f6bcfd97
BP
709 wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow;
710 text->SetValue(property->GetValue().StringValue());
e3a43801 711 }
f6bcfd97
BP
712 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox)))
713 {
714 wxListBox *lbox = (wxListBox *)m_propertyWindow;
6326010c 715 if (lbox->GetCount() == 0 && m_strings)
f6bcfd97
BP
716 {
717 // Try to initialize the listbox from 'strings'
718 wxNode *node = m_strings->First();
719 while (node)
720 {
721 char *s = (char *)node->Data();
722 lbox->Append(s);
723 node = node->Next();
724 }
725 }
726 lbox->SetStringSelection(property->GetValue().StringValue());
727 }
728 /*
729 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox)))
730 {
e3a43801
JS
731 wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
732 rbox->SetStringSelection(property->GetValue().StringValue());
e3a43801 733 }
f6bcfd97
BP
734 */
735 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice)))
736 {
737 wxChoice *choice = (wxChoice *)m_propertyWindow;
738#ifndef __XVIEW__
6326010c 739 if (choice->GetCount() == 0 && m_strings)
f6bcfd97
BP
740 {
741 // Try to initialize the choice item from 'strings'
742 // XView doesn't allow this kind of thing.
743 wxNode *node = m_strings->First();
744 while (node)
745 {
746 char *s = (char *)node->Data();
747 choice->Append(s);
748 node = node->Next();
749 }
750 }
e3a43801 751#endif
f6bcfd97
BP
752 choice->SetStringSelection(property->GetValue().StringValue());
753 }
754 else
755 return FALSE;
756 return TRUE;
e3a43801
JS
757}
758
1e6feb95 759#endif // wxUSE_PROPSHEET