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