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