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