]> git.saurik.com Git - wxWidgets.git/blob - src/generic/propform.cpp
Added a file
[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 #if wxUSE_PROPSHEET
24
25 #ifndef WX_PRECOMP
26 #endif
27
28 #include "wx/propform.h"
29
30 #include <ctype.h>
31 #include <stdlib.h>
32 #include <math.h>
33 #include <string.h>
34
35
36 /*
37 * Property view
38 */
39
40 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormView, wxPropertyView)
41
42 BEGIN_EVENT_TABLE(wxPropertyFormView, wxPropertyView)
43 EVT_BUTTON(wxID_OK, wxPropertyFormView::OnOk)
44 EVT_BUTTON(wxID_CANCEL, wxPropertyFormView::OnCancel)
45 EVT_BUTTON(wxID_HELP, wxPropertyFormView::OnHelp)
46 EVT_BUTTON(wxID_PROP_REVERT, wxPropertyFormView::OnRevert)
47 EVT_BUTTON(wxID_PROP_UPDATE, wxPropertyFormView::OnUpdate)
48 END_EVENT_TABLE()
49
50 bool wxPropertyFormView::sm_dialogCancelled = FALSE;
51
52 wxPropertyFormView::wxPropertyFormView(wxWindow *propPanel, long flags):wxPropertyView(flags)
53 {
54 m_propertyWindow = propPanel;
55 m_managedWindow = NULL;
56
57 m_windowCloseButton = NULL;
58 m_windowCancelButton = NULL;
59 m_windowHelpButton = NULL;
60
61 m_detailedEditing = FALSE;
62 }
63
64 wxPropertyFormView::~wxPropertyFormView(void)
65 {
66 }
67
68 void wxPropertyFormView::ShowView(wxPropertySheet *ps, wxWindow *panel)
69 {
70 m_propertySheet = ps;
71
72 AssociatePanel(panel);
73 // CreateControls();
74 // UpdatePropertyList();
75 }
76
77 // Update this view of the viewed object, called e.g. by
78 // the object itself.
79 bool wxPropertyFormView::OnUpdateView(void)
80 {
81 return TRUE;
82 }
83
84 bool wxPropertyFormView::Check(void)
85 {
86 if (!m_propertySheet)
87 return FALSE;
88
89 wxNode *node = m_propertySheet->GetProperties().First();
90 while (node)
91 {
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();
101 }
102 return TRUE;
103 }
104
105 bool wxPropertyFormView::TransferToPropertySheet(void)
106 {
107 if (!m_propertySheet)
108 return FALSE;
109
110 wxNode *node = m_propertySheet->GetProperties().First();
111 while (node)
112 {
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();
121 }
122 return TRUE;
123 }
124
125 bool wxPropertyFormView::TransferToDialog(void)
126 {
127 if (!m_propertySheet)
128 return FALSE;
129
130 wxNode *node = m_propertySheet->GetProperties().First();
131 while (node)
132 {
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();
141 }
142 return TRUE;
143 }
144
145 bool wxPropertyFormView::AssociateNames(void)
146 {
147 if (!m_propertySheet || !m_propertyWindow)
148 return FALSE;
149
150 wxNode *node = m_propertyWindow->GetChildren().First();
151 while (node)
152 {
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();
161 }
162 return TRUE;
163 }
164
165
166 bool wxPropertyFormView::OnClose(void)
167 {
168 if (m_propertyWindow->IsKindOf(CLASSINFO(wxPropertyFormPanel)))
169 {
170 ((wxPropertyFormPanel*)m_propertyWindow)->SetView(NULL);
171 }
172 delete this;
173 return TRUE;
174 }
175
176 void wxPropertyFormView::OnOk(wxCommandEvent& WXUNUSED(event))
177 {
178 // Retrieve the value if any
179 if (!Check())
180 return;
181
182 sm_dialogCancelled = FALSE;
183 TransferToPropertySheet();
184
185 m_managedWindow->Close(TRUE);
186 }
187
188 void wxPropertyFormView::OnCancel(wxCommandEvent& WXUNUSED(event))
189 {
190 sm_dialogCancelled = TRUE;
191
192 m_managedWindow->Close(TRUE);
193 }
194
195 void wxPropertyFormView::OnHelp(wxCommandEvent& WXUNUSED(event))
196 {
197 }
198
199 void wxPropertyFormView::OnUpdate(wxCommandEvent& WXUNUSED(event))
200 {
201 if (Check())
202 TransferToPropertySheet();
203 }
204
205 void wxPropertyFormView::OnRevert(wxCommandEvent& WXUNUSED(event))
206 {
207 TransferToDialog();
208 }
209
210 void wxPropertyFormView::OnCommand(wxWindow& win, wxCommandEvent& event)
211 {
212 if (!m_propertySheet)
213 return;
214
215 if (win.GetName() == wxT(""))
216 return;
217
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
229 {
230 // Find a validator to route the command to.
231 wxNode *node = m_propertySheet->GetProperties().First();
232 while (node)
233 {
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();
246 }
247 }
248 }
249
250 // Extend event processing to call OnCommand
251 bool 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
264 void wxPropertyFormView::OnDoubleClick(wxControl *item)
265 {
266 if (!m_propertySheet)
267 return;
268
269 // Find a validator to route the command to.
270 wxNode *node = m_propertySheet->GetProperties().First();
271 while (node)
272 {
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();
285 }
286 }
287
288 /*
289 * Property form dialog box
290 */
291
292 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormDialog, wxDialog)
293
294 BEGIN_EVENT_TABLE(wxPropertyFormDialog, wxDialog)
295 EVT_CLOSE(wxPropertyFormDialog::OnCloseWindow)
296 END_EVENT_TABLE()
297
298 wxPropertyFormDialog::wxPropertyFormDialog(wxPropertyFormView *v, wxWindow *parent, const wxString& title,
299 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
300 wxDialog(parent, -1, title, pos, size, style, name)
301 {
302 m_view = v;
303 m_view->AssociatePanel(this);
304 m_view->SetManagedWindow(this);
305 // SetAutoLayout(TRUE);
306 }
307
308 void wxPropertyFormDialog::OnCloseWindow(wxCloseEvent& event)
309 {
310 if (m_view)
311 {
312 m_view->OnClose();
313 m_view = NULL;
314 this->Destroy();
315 }
316 else
317 event.Veto();
318 }
319
320 void wxPropertyFormDialog::OnDefaultAction(wxControl *item)
321 {
322 m_view->OnDoubleClick(item);
323 }
324
325 void wxPropertyFormDialog::OnCommand(wxWindow& win, wxCommandEvent& event)
326 {
327 if ( m_view )
328 m_view->OnCommand(win, event);
329 }
330
331 // Extend event processing to search the view's event table
332 bool wxPropertyFormDialog::ProcessEvent(wxEvent& event)
333 {
334 if ( !m_view || ! m_view->ProcessEvent(event) )
335 return wxEvtHandler::ProcessEvent(event);
336 else
337 return TRUE;
338 }
339
340
341 /*
342 * Property form panel
343 */
344
345 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormPanel, wxPanel)
346
347 void wxPropertyFormPanel::OnDefaultAction(wxControl *item)
348 {
349 m_view->OnDoubleClick(item);
350 }
351
352 void wxPropertyFormPanel::OnCommand(wxWindow& win, wxCommandEvent& event)
353 {
354 m_view->OnCommand(win, event);
355 }
356
357 // Extend event processing to search the view's event table
358 bool wxPropertyFormPanel::ProcessEvent(wxEvent& event)
359 {
360 if ( !m_view || ! m_view->ProcessEvent(event) )
361 return wxEvtHandler::ProcessEvent(event);
362 else
363 return TRUE;
364 }
365
366 /*
367 * Property frame
368 */
369
370 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormFrame, wxFrame)
371
372 BEGIN_EVENT_TABLE(wxPropertyFormFrame, wxFrame)
373 EVT_CLOSE(wxPropertyFormFrame::OnCloseWindow)
374 END_EVENT_TABLE()
375
376 void wxPropertyFormFrame::OnCloseWindow(wxCloseEvent& event)
377 {
378 if (m_view && m_view->OnClose())
379 this->Destroy();
380 else
381 event.Veto();
382 }
383
384 wxPanel *wxPropertyFormFrame::OnCreatePanel(wxFrame *parent, wxPropertyFormView *v)
385 {
386 return new wxPropertyFormPanel(v, parent);
387 }
388
389 bool wxPropertyFormFrame::Initialize(void)
390 {
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;
400 }
401
402 /*
403 * Property form specific validator
404 */
405
406 IMPLEMENT_ABSTRACT_CLASS(wxPropertyFormValidator, wxPropertyValidator)
407
408
409 /*
410 * Default validators
411 */
412
413 IMPLEMENT_DYNAMIC_CLASS(wxRealFormValidator, wxPropertyFormValidator)
414
415 ///
416 /// Real number form validator
417 ///
418 bool wxRealFormValidator::OnCheckValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view),
419 wxWindow *parentWindow)
420 {
421 if (m_realMin == 0.0 && m_realMax == 0.0)
422 return TRUE;
423
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;
428
429 wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());
430
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 }
439
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;
448 }
449
450 bool wxRealFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
451 wxWindow *WXUNUSED(parentWindow) )
452 {
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;
457
458 wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());
459
460 if (value.Length() == 0)
461 return FALSE;
462
463 float f = (float)wxAtof((const wxChar *)value);
464 property->GetValue() = f;
465 return TRUE;
466 }
467
468 bool wxRealFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
469 wxWindow *WXUNUSED(parentWindow) )
470 {
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;
475
476 wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow;
477 textItem->SetValue(FloatToString(property->GetValue().RealValue()));
478 return TRUE;
479 }
480
481 ///
482 /// Integer validator
483 ///
484 IMPLEMENT_DYNAMIC_CLASS(wxIntegerFormValidator, wxPropertyFormValidator)
485
486 bool wxIntegerFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
487 wxWindow *parentWindow)
488 {
489 if (m_integerMin == 0.0 && m_integerMax == 0.0)
490 return TRUE;
491
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;
496
497 long val = 0;
498
499 if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
500 {
501 wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());
502
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)))
512 {
513 val = (long)((wxSlider *)m_propertyWindow)->GetValue();
514 }
515 else
516 return FALSE;
517
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;
524 }
525 return TRUE;
526 }
527
528 bool wxIntegerFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
529 wxWindow *WXUNUSED(parentWindow))
530 {
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;
535
536 if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
537 {
538 wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());
539
540 if (value.Length() == 0)
541 return FALSE;
542
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;
552
553 return TRUE;
554 }
555
556 bool wxIntegerFormValidator::OnDisplayValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view),
557 wxWindow *WXUNUSED(parentWindow))
558 {
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;
563
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;
576 }
577
578 ///
579 /// Boolean validator
580 ///
581 IMPLEMENT_DYNAMIC_CLASS(wxBoolFormValidator, wxPropertyFormValidator)
582
583 bool wxBoolFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
584 wxWindow *WXUNUSED(parentWindow))
585 {
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;
590
591 return TRUE;
592 }
593
594 bool wxBoolFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
595 wxWindow *WXUNUSED(parentWindow) )
596 {
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;
601
602 wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow;
603
604 property->GetValue() = (bool)checkBox->GetValue();
605 return TRUE;
606 }
607
608 bool wxBoolFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
609 wxWindow *WXUNUSED(parentWindow))
610 {
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;
615
616 wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow;
617 checkBox->SetValue((bool)property->GetValue().BoolValue());
618 return TRUE;
619 }
620
621 ///
622 /// String validator
623 ///
624 IMPLEMENT_DYNAMIC_CLASS(wxStringFormValidator, wxPropertyFormValidator)
625
626 wxStringFormValidator::wxStringFormValidator(wxStringList *list, long flags):
627 wxPropertyFormValidator(flags)
628 {
629 m_strings = list;
630 }
631
632 bool wxStringFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
633 wxWindow *parentWindow )
634 {
635 if (!m_strings)
636 return TRUE;
637
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)))
643 {
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 }
653 }
654 else
655 {
656 // Any other item constrains the string value,
657 // so we don't have to check it.
658 }
659 return TRUE;
660 }
661
662 bool wxStringFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
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 {
683 wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
684 int n = 0;
685 if ((n = rbox->GetSelection()) > -1)
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;
698 }
699
700 bool wxStringFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
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)))
708 {
709 wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow;
710 text->SetValue(property->GetValue().StringValue());
711 }
712 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox)))
713 {
714 wxListBox *lbox = (wxListBox *)m_propertyWindow;
715 if (lbox->GetCount() == 0 && m_strings)
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 {
731 wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
732 rbox->SetStringSelection(property->GetValue().StringValue());
733 }
734 */
735 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice)))
736 {
737 wxChoice *choice = (wxChoice *)m_propertyWindow;
738 #ifndef __XVIEW__
739 if (choice->GetCount() == 0 && m_strings)
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 }
751 #endif
752 choice->SetStringSelection(property->GetValue().StringValue());
753 }
754 else
755 return FALSE;
756 return TRUE;
757 }
758
759 #endif // wxUSE_PROPSHEET