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