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