]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/deprecated/propform.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property form classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/deprecated/setup.h"
24 #include "wx/choice.h"
25 #include "wx/checkbox.h"
26 #include "wx/slider.h"
27 #include "wx/msgdlg.h"
30 #include "wx/deprecated/propform.h"
42 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormView
, wxPropertyView
)
44 BEGIN_EVENT_TABLE(wxPropertyFormView
, wxPropertyView
)
45 EVT_BUTTON(wxID_OK
, wxPropertyFormView::OnOk
)
46 EVT_BUTTON(wxID_CANCEL
, wxPropertyFormView::OnCancel
)
47 EVT_BUTTON(wxID_HELP
, wxPropertyFormView::OnHelp
)
48 EVT_BUTTON(wxID_PROP_REVERT
, wxPropertyFormView::OnRevert
)
49 EVT_BUTTON(wxID_PROP_UPDATE
, wxPropertyFormView::OnUpdate
)
52 bool wxPropertyFormView::sm_dialogCancelled
= false;
54 wxPropertyFormView::wxPropertyFormView(wxWindow
*propPanel
, long flags
):wxPropertyView(flags
)
56 m_propertyWindow
= propPanel
;
57 m_managedWindow
= NULL
;
59 m_windowCloseButton
= NULL
;
60 m_windowCancelButton
= NULL
;
61 m_windowHelpButton
= NULL
;
63 m_detailedEditing
= false;
66 wxPropertyFormView::~wxPropertyFormView(void)
70 void wxPropertyFormView::ShowView(wxPropertySheet
*ps
, wxWindow
*panel
)
74 AssociatePanel(panel
);
76 // UpdatePropertyList();
79 // Update this view of the viewed object, called e.g. by
81 bool wxPropertyFormView::OnUpdateView(void)
86 bool wxPropertyFormView::Check(void)
91 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
94 wxProperty
*prop
= (wxProperty
*)node
->GetData();
95 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
96 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
98 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
99 if (!formValidator
->OnCheckValue(prop
, this, m_propertyWindow
))
102 node
= node
->GetNext();
107 bool wxPropertyFormView::TransferToPropertySheet(void)
109 if (!m_propertySheet
)
112 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
115 wxProperty
*prop
= (wxProperty
*)node
->GetData();
116 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
117 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
119 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
120 formValidator
->OnRetrieveValue(prop
, this, m_propertyWindow
);
122 node
= node
->GetNext();
127 bool wxPropertyFormView::TransferToDialog(void)
129 if (!m_propertySheet
)
132 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
135 wxProperty
*prop
= (wxProperty
*)node
->GetData();
136 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
137 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
139 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
140 formValidator
->OnDisplayValue(prop
, this, m_propertyWindow
);
142 node
= node
->GetNext();
147 bool wxPropertyFormView::AssociateNames(void)
149 if (!m_propertySheet
|| !m_propertyWindow
)
152 wxWindowList::Node
*node
= m_propertyWindow
->GetChildren().GetFirst();
155 wxWindow
*win
= node
->GetData();
156 if ( win
->GetName() != wxEmptyString
)
158 wxProperty
*prop
= m_propertySheet
->GetProperty(win
->GetName());
160 prop
->SetWindow(win
);
162 node
= node
->GetNext();
168 bool wxPropertyFormView::OnClose(void)
170 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPropertyFormPanel
)))
172 ((wxPropertyFormPanel
*)m_propertyWindow
)->SetView(NULL
);
178 void wxPropertyFormView::OnOk(wxCommandEvent
& WXUNUSED(event
))
180 // Retrieve the value if any
184 sm_dialogCancelled
= false;
185 TransferToPropertySheet();
187 m_managedWindow
->Close(true);
190 void wxPropertyFormView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
192 sm_dialogCancelled
= true;
194 m_managedWindow
->Close(true);
197 void wxPropertyFormView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
201 void wxPropertyFormView::OnUpdate(wxCommandEvent
& WXUNUSED(event
))
204 TransferToPropertySheet();
207 void wxPropertyFormView::OnRevert(wxCommandEvent
& WXUNUSED(event
))
212 void wxPropertyFormView::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
214 if (!m_propertySheet
)
217 if (win
.GetName().empty())
220 if (wxStrcmp(win
.GetName(), wxT("ok")) == 0)
222 else if (wxStrcmp(win
.GetName(), wxT("cancel")) == 0)
224 else if (wxStrcmp(win
.GetName(), wxT("help")) == 0)
226 else if (wxStrcmp(win
.GetName(), wxT("update")) == 0)
228 else if (wxStrcmp(win
.GetName(), wxT("revert")) == 0)
232 // Find a validator to route the command to.
233 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
236 wxProperty
*prop
= (wxProperty
*)node
->GetData();
237 if (prop
->GetWindow() && (prop
->GetWindow() == &win
))
239 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
240 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
242 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
243 formValidator
->OnCommand(prop
, this, m_propertyWindow
, event
);
247 node
= node
->GetNext();
252 // Extend event processing to call OnCommand
253 bool wxPropertyFormView::ProcessEvent(wxEvent
& event
)
255 if (wxEvtHandler::ProcessEvent(event
))
257 else if (event
.IsCommandEvent() && !event
.IsKindOf(CLASSINFO(wxUpdateUIEvent
)) && event
.GetEventObject())
259 OnCommand(* ((wxWindow
*) event
.GetEventObject()), (wxCommandEvent
&) event
);
266 void wxPropertyFormView::OnDoubleClick(wxControl
*item
)
268 if (!m_propertySheet
)
271 // Find a validator to route the command to.
272 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
275 wxProperty
*prop
= (wxProperty
*)node
->GetData();
276 if (prop
->GetWindow() && ((wxControl
*)prop
->GetWindow() == item
))
278 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
279 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
281 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
282 formValidator
->OnDoubleClick(prop
, this, m_propertyWindow
);
286 node
= node
->GetNext();
291 * Property form dialog box
294 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormDialog
, wxDialog
)
296 BEGIN_EVENT_TABLE(wxPropertyFormDialog
, wxDialog
)
297 EVT_CLOSE(wxPropertyFormDialog::OnCloseWindow
)
300 wxPropertyFormDialog::wxPropertyFormDialog(wxPropertyFormView
*v
, wxWindow
*parent
, const wxString
& title
,
301 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
302 wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
305 m_view
->AssociatePanel(this);
306 m_view
->SetManagedWindow(this);
307 // SetAutoLayout(true);
310 void wxPropertyFormDialog::OnCloseWindow(wxCloseEvent
& event
)
322 void wxPropertyFormDialog::OnDefaultAction(wxControl
*item
)
324 m_view
->OnDoubleClick(item
);
327 void wxPropertyFormDialog::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
330 m_view
->OnCommand(win
, event
);
333 // Extend event processing to search the view's event table
334 bool wxPropertyFormDialog::ProcessEvent(wxEvent
& event
)
336 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
337 return wxEvtHandler::ProcessEvent(event
);
344 * Property form panel
347 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormPanel
, wxPanel
)
349 void wxPropertyFormPanel::OnDefaultAction(wxControl
*item
)
351 m_view
->OnDoubleClick(item
);
354 void wxPropertyFormPanel::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
356 m_view
->OnCommand(win
, event
);
359 // Extend event processing to search the view's event table
360 bool wxPropertyFormPanel::ProcessEvent(wxEvent
& event
)
362 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
363 return wxEvtHandler::ProcessEvent(event
);
372 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormFrame
, wxFrame
)
374 BEGIN_EVENT_TABLE(wxPropertyFormFrame
, wxFrame
)
375 EVT_CLOSE(wxPropertyFormFrame::OnCloseWindow
)
378 void wxPropertyFormFrame::OnCloseWindow(wxCloseEvent
& event
)
380 if (m_view
&& m_view
->OnClose())
386 wxPanel
*wxPropertyFormFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyFormView
*v
)
388 return new wxPropertyFormPanel(v
, parent
);
391 bool wxPropertyFormFrame::Initialize(void)
393 m_propertyPanel
= OnCreatePanel(this, m_view
);
396 m_view
->AssociatePanel(m_propertyPanel
);
397 m_view
->SetManagedWindow(this);
405 * Property form specific validator
408 IMPLEMENT_ABSTRACT_CLASS(wxPropertyFormValidator
, wxPropertyValidator
)
415 IMPLEMENT_DYNAMIC_CLASS(wxRealFormValidator
, wxPropertyFormValidator
)
418 /// Real number form validator
420 bool wxRealFormValidator::OnCheckValue( wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
421 wxWindow
*parentWindow
)
423 if (m_realMin
== 0.0 && m_realMax
== 0.0)
426 // The item used for viewing the real number: should be a text item.
427 wxWindow
*m_propertyWindow
= property
->GetWindow();
428 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
431 wxString
value(((wxTextCtrl
*)m_propertyWindow
)->GetValue());
434 if (!StringToFloat(WXSTRINGCAST value
, &val
))
437 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), (const wxChar
*)value
);
438 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
442 if (val
< m_realMin
|| val
> m_realMax
)
445 wxSprintf(buf
, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin
, m_realMax
);
446 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
452 bool wxRealFormValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
453 wxWindow
*WXUNUSED(parentWindow
) )
455 // The item used for viewing the real number: should be a text item.
456 wxWindow
*m_propertyWindow
= property
->GetWindow();
457 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
460 wxString
value(((wxTextCtrl
*)m_propertyWindow
)->GetValue());
462 if (value
.Length() == 0)
465 float f
= (float)wxAtof((const wxChar
*)value
);
466 property
->GetValue() = f
;
470 bool wxRealFormValidator::OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
471 wxWindow
*WXUNUSED(parentWindow
) )
473 // The item used for viewing the real number: should be a text item.
474 wxWindow
*m_propertyWindow
= property
->GetWindow();
475 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
478 wxTextCtrl
*textItem
= (wxTextCtrl
*)m_propertyWindow
;
479 textItem
->SetValue(FloatToString(property
->GetValue().RealValue()));
484 /// Integer validator
486 IMPLEMENT_DYNAMIC_CLASS(wxIntegerFormValidator
, wxPropertyFormValidator
)
488 bool wxIntegerFormValidator::OnCheckValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
489 wxWindow
*parentWindow
)
491 if (m_integerMin
== 0.0 && m_integerMax
== 0.0)
494 // The item used for viewing the real number: should be a text item or a slider
495 wxWindow
*m_propertyWindow
= property
->GetWindow();
496 if (!m_propertyWindow
)
501 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
503 wxString
value(((wxTextCtrl
*)m_propertyWindow
)->GetValue());
505 if (!StringToLong(WXSTRINGCAST value
, &val
))
508 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), (const wxChar
*)value
);
509 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
513 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxSlider
)))
515 val
= (long)((wxSlider
*)m_propertyWindow
)->GetValue();
520 if (val
< m_integerMin
|| val
> m_integerMax
)
523 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
524 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
530 bool wxIntegerFormValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
531 wxWindow
*WXUNUSED(parentWindow
))
533 // The item used for viewing the real number: should be a text item or a slider
534 wxWindow
*m_propertyWindow
= property
->GetWindow();
535 if (!m_propertyWindow
)
538 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
540 wxString
value(((wxTextCtrl
*)m_propertyWindow
)->GetValue());
542 if (value
.Length() == 0)
545 long i
= wxAtol((const wxChar
*)value
);
546 property
->GetValue() = i
;
548 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxSlider
)))
550 property
->GetValue() = (long)((wxSlider
*)m_propertyWindow
)->GetValue();
558 bool wxIntegerFormValidator::OnDisplayValue( wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
559 wxWindow
*WXUNUSED(parentWindow
))
561 // The item used for viewing the real number: should be a text item or a slider
562 wxWindow
*m_propertyWindow
= property
->GetWindow();
563 if (!m_propertyWindow
)
566 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
568 wxTextCtrl
*textItem
= (wxTextCtrl
*)m_propertyWindow
;
569 textItem
->SetValue(LongToString(property
->GetValue().IntegerValue()));
571 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxSlider
)))
573 ((wxSlider
*)m_propertyWindow
)->SetValue((int)property
->GetValue().IntegerValue());
581 /// Boolean validator
583 IMPLEMENT_DYNAMIC_CLASS(wxBoolFormValidator
, wxPropertyFormValidator
)
585 bool wxBoolFormValidator::OnCheckValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
586 wxWindow
*WXUNUSED(parentWindow
))
588 // The item used for viewing the boolean: should be a checkbox
589 wxWindow
*m_propertyWindow
= property
->GetWindow();
590 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
596 bool wxBoolFormValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
597 wxWindow
*WXUNUSED(parentWindow
) )
599 // The item used for viewing the boolean: should be a checkbox.
600 wxWindow
*m_propertyWindow
= property
->GetWindow();
601 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
604 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
606 property
->GetValue() = (bool)checkBox
->GetValue();
610 bool wxBoolFormValidator::OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
611 wxWindow
*WXUNUSED(parentWindow
))
613 // The item used for viewing the boolean: should be a checkbox.
614 wxWindow
*m_propertyWindow
= property
->GetWindow();
615 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
618 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
619 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
626 IMPLEMENT_DYNAMIC_CLASS(wxStringFormValidator
, wxPropertyFormValidator
)
628 wxStringFormValidator::wxStringFormValidator(wxStringList
*list
, long flags
):
629 wxPropertyFormValidator(flags
)
634 bool wxStringFormValidator::OnCheckValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
635 wxWindow
*parentWindow
)
640 // The item used for viewing the string: should be a text item, choice item or listbox.
641 wxWindow
*m_propertyWindow
= property
->GetWindow();
642 if (!m_propertyWindow
)
644 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
646 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
647 if (!m_strings
->Member(text
->GetValue()))
649 wxString
str( wxT("Value ") );
650 str
+= text
->GetValue();
651 str
+= wxT(" is not valid.");
652 wxMessageBox(str
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
658 // Any other item constrains the string value,
659 // so we don't have to check it.
664 bool wxStringFormValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
665 wxWindow
*WXUNUSED(parentWindow
) )
667 // The item used for viewing the string: should be a text item, choice item or listbox.
668 wxWindow
*m_propertyWindow
= property
->GetWindow();
669 if (!m_propertyWindow
)
671 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
673 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
674 property
->GetValue() = text
->GetValue();
676 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxListBox
)))
678 wxListBox
*lbox
= (wxListBox
*)m_propertyWindow
;
679 if (lbox
->GetSelection() != wxNOT_FOUND
)
680 property
->GetValue() = lbox
->GetStringSelection();
683 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox)))
685 wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
687 if ((n = rbox->GetSelection()) != wxNOT_FOUND)
688 property->GetValue() = rbox->GetString(n);
691 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxChoice
)))
693 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
694 if (choice
->GetSelection() != wxNOT_FOUND
)
695 property
->GetValue() = choice
->GetStringSelection();
702 bool wxStringFormValidator::OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
703 wxWindow
*WXUNUSED(parentWindow
) )
705 // The item used for viewing the string: should be a text item, choice item or listbox.
706 wxWindow
*m_propertyWindow
= property
->GetWindow();
707 if (!m_propertyWindow
)
709 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
711 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
712 text
->SetValue(property
->GetValue().StringValue());
714 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxListBox
)))
716 wxListBox
*lbox
= (wxListBox
*)m_propertyWindow
;
717 if (lbox
->GetCount() == 0 && m_strings
)
719 // Try to initialize the listbox from 'strings'
720 wxStringList::Node
*node
= m_strings
->GetFirst();
723 wxChar
*s
= node
->GetData();
725 node
= node
->GetNext();
728 lbox
->SetStringSelection(property
->GetValue().StringValue());
731 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox)))
733 wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
734 rbox->SetStringSelection(property->GetValue().StringValue());
737 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxChoice
)))
739 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
740 if (choice
->GetCount() == 0 && m_strings
)
742 // Try to initialize the choice item from 'strings'
743 // XView doesn't allow this kind of thing.
744 wxStringList::Node
*node
= m_strings
->GetFirst();
747 wxChar
*s
= node
->GetData();
749 node
= node
->GetNext();
752 choice
->SetStringSelection(property
->GetValue().StringValue());
759 #endif // wxUSE_PROPSHEET