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