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