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