]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "propform.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/deprecated/setup.h"
28 #include "wx/choice.h"
29 #include "wx/checkbox.h"
30 #include "wx/slider.h"
31 #include "wx/msgdlg.h"
34 #include "wx/deprecated/propform.h"
46 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormView
, wxPropertyView
)
48 BEGIN_EVENT_TABLE(wxPropertyFormView
, wxPropertyView
)
49 EVT_BUTTON(wxID_OK
, wxPropertyFormView::OnOk
)
50 EVT_BUTTON(wxID_CANCEL
, wxPropertyFormView::OnCancel
)
51 EVT_BUTTON(wxID_HELP
, wxPropertyFormView::OnHelp
)
52 EVT_BUTTON(wxID_PROP_REVERT
, wxPropertyFormView::OnRevert
)
53 EVT_BUTTON(wxID_PROP_UPDATE
, wxPropertyFormView::OnUpdate
)
56 bool wxPropertyFormView::sm_dialogCancelled
= false;
58 wxPropertyFormView::wxPropertyFormView(wxWindow
*propPanel
, long flags
):wxPropertyView(flags
)
60 m_propertyWindow
= propPanel
;
61 m_managedWindow
= NULL
;
63 m_windowCloseButton
= NULL
;
64 m_windowCancelButton
= NULL
;
65 m_windowHelpButton
= NULL
;
67 m_detailedEditing
= false;
70 wxPropertyFormView::~wxPropertyFormView(void)
74 void wxPropertyFormView::ShowView(wxPropertySheet
*ps
, wxWindow
*panel
)
78 AssociatePanel(panel
);
80 // UpdatePropertyList();
83 // Update this view of the viewed object, called e.g. by
85 bool wxPropertyFormView::OnUpdateView(void)
90 bool wxPropertyFormView::Check(void)
95 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
98 wxProperty
*prop
= (wxProperty
*)node
->GetData();
99 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
100 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
102 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
103 if (!formValidator
->OnCheckValue(prop
, this, m_propertyWindow
))
106 node
= node
->GetNext();
111 bool wxPropertyFormView::TransferToPropertySheet(void)
113 if (!m_propertySheet
)
116 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
119 wxProperty
*prop
= (wxProperty
*)node
->GetData();
120 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
121 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
123 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
124 formValidator
->OnRetrieveValue(prop
, this, m_propertyWindow
);
126 node
= node
->GetNext();
131 bool wxPropertyFormView::TransferToDialog(void)
133 if (!m_propertySheet
)
136 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
139 wxProperty
*prop
= (wxProperty
*)node
->GetData();
140 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
141 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
143 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
144 formValidator
->OnDisplayValue(prop
, this, m_propertyWindow
);
146 node
= node
->GetNext();
151 bool wxPropertyFormView::AssociateNames(void)
153 if (!m_propertySheet
|| !m_propertyWindow
)
156 wxWindowList::Node
*node
= m_propertyWindow
->GetChildren().GetFirst();
159 wxWindow
*win
= node
->GetData();
160 if ( win
->GetName() != wxEmptyString
)
162 wxProperty
*prop
= m_propertySheet
->GetProperty(win
->GetName());
164 prop
->SetWindow(win
);
166 node
= node
->GetNext();
172 bool wxPropertyFormView::OnClose(void)
174 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPropertyFormPanel
)))
176 ((wxPropertyFormPanel
*)m_propertyWindow
)->SetView(NULL
);
182 void wxPropertyFormView::OnOk(wxCommandEvent
& WXUNUSED(event
))
184 // Retrieve the value if any
188 sm_dialogCancelled
= false;
189 TransferToPropertySheet();
191 m_managedWindow
->Close(true);
194 void wxPropertyFormView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
196 sm_dialogCancelled
= true;
198 m_managedWindow
->Close(true);
201 void wxPropertyFormView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
205 void wxPropertyFormView::OnUpdate(wxCommandEvent
& WXUNUSED(event
))
208 TransferToPropertySheet();
211 void wxPropertyFormView::OnRevert(wxCommandEvent
& WXUNUSED(event
))
216 void wxPropertyFormView::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
218 if (!m_propertySheet
)
221 if (win
.GetName() == wxT(""))
224 if (wxStrcmp(win
.GetName(), wxT("ok")) == 0)
226 else if (wxStrcmp(win
.GetName(), wxT("cancel")) == 0)
228 else if (wxStrcmp(win
.GetName(), wxT("help")) == 0)
230 else if (wxStrcmp(win
.GetName(), wxT("update")) == 0)
232 else if (wxStrcmp(win
.GetName(), wxT("revert")) == 0)
236 // Find a validator to route the command to.
237 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
240 wxProperty
*prop
= (wxProperty
*)node
->GetData();
241 if (prop
->GetWindow() && (prop
->GetWindow() == &win
))
243 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
244 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
246 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
247 formValidator
->OnCommand(prop
, this, m_propertyWindow
, event
);
251 node
= node
->GetNext();
256 // Extend event processing to call OnCommand
257 bool wxPropertyFormView::ProcessEvent(wxEvent
& event
)
259 if (wxEvtHandler::ProcessEvent(event
))
261 else if (event
.IsCommandEvent() && !event
.IsKindOf(CLASSINFO(wxUpdateUIEvent
)) && event
.GetEventObject())
263 OnCommand(* ((wxWindow
*) event
.GetEventObject()), (wxCommandEvent
&) event
);
270 void wxPropertyFormView::OnDoubleClick(wxControl
*item
)
272 if (!m_propertySheet
)
275 // Find a validator to route the command to.
276 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
279 wxProperty
*prop
= (wxProperty
*)node
->GetData();
280 if (prop
->GetWindow() && ((wxControl
*)prop
->GetWindow() == item
))
282 wxPropertyValidator
*validator
= FindPropertyValidator(prop
);
283 if (validator
&& validator
->IsKindOf(CLASSINFO(wxPropertyFormValidator
)))
285 wxPropertyFormValidator
*formValidator
= (wxPropertyFormValidator
*)validator
;
286 formValidator
->OnDoubleClick(prop
, this, m_propertyWindow
);
290 node
= node
->GetNext();
295 * Property form dialog box
298 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormDialog
, wxDialog
)
300 BEGIN_EVENT_TABLE(wxPropertyFormDialog
, wxDialog
)
301 EVT_CLOSE(wxPropertyFormDialog::OnCloseWindow
)
304 wxPropertyFormDialog::wxPropertyFormDialog(wxPropertyFormView
*v
, wxWindow
*parent
, const wxString
& title
,
305 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
306 wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
309 m_view
->AssociatePanel(this);
310 m_view
->SetManagedWindow(this);
311 // SetAutoLayout(true);
314 void wxPropertyFormDialog::OnCloseWindow(wxCloseEvent
& event
)
326 void wxPropertyFormDialog::OnDefaultAction(wxControl
*item
)
328 m_view
->OnDoubleClick(item
);
331 void wxPropertyFormDialog::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
334 m_view
->OnCommand(win
, event
);
337 // Extend event processing to search the view's event table
338 bool wxPropertyFormDialog::ProcessEvent(wxEvent
& event
)
340 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
341 return wxEvtHandler::ProcessEvent(event
);
348 * Property form panel
351 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormPanel
, wxPanel
)
353 void wxPropertyFormPanel::OnDefaultAction(wxControl
*item
)
355 m_view
->OnDoubleClick(item
);
358 void wxPropertyFormPanel::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
360 m_view
->OnCommand(win
, event
);
363 // Extend event processing to search the view's event table
364 bool wxPropertyFormPanel::ProcessEvent(wxEvent
& event
)
366 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
367 return wxEvtHandler::ProcessEvent(event
);
376 IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormFrame
, wxFrame
)
378 BEGIN_EVENT_TABLE(wxPropertyFormFrame
, wxFrame
)
379 EVT_CLOSE(wxPropertyFormFrame::OnCloseWindow
)
382 void wxPropertyFormFrame::OnCloseWindow(wxCloseEvent
& event
)
384 if (m_view
&& m_view
->OnClose())
390 wxPanel
*wxPropertyFormFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyFormView
*v
)
392 return new wxPropertyFormPanel(v
, parent
);
395 bool wxPropertyFormFrame::Initialize(void)
397 m_propertyPanel
= OnCreatePanel(this, m_view
);
400 m_view
->AssociatePanel(m_propertyPanel
);
401 m_view
->SetManagedWindow(this);
409 * Property form specific validator
412 IMPLEMENT_ABSTRACT_CLASS(wxPropertyFormValidator
, wxPropertyValidator
)
419 IMPLEMENT_DYNAMIC_CLASS(wxRealFormValidator
, wxPropertyFormValidator
)
422 /// Real number form validator
424 bool wxRealFormValidator::OnCheckValue( wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
425 wxWindow
*parentWindow
)
427 if (m_realMin
== 0.0 && m_realMax
== 0.0)
430 // The item used for viewing the real number: should be a text item.
431 wxWindow
*m_propertyWindow
= property
->GetWindow();
432 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
435 wxString
value(((wxTextCtrl
*)m_propertyWindow
)->GetValue());
438 if (!StringToFloat(WXSTRINGCAST value
, &val
))
441 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), (const wxChar
*)value
);
442 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
446 if (val
< m_realMin
|| val
> m_realMax
)
449 wxSprintf(buf
, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin
, m_realMax
);
450 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
456 bool wxRealFormValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
457 wxWindow
*WXUNUSED(parentWindow
) )
459 // The item used for viewing the real number: should be a text item.
460 wxWindow
*m_propertyWindow
= property
->GetWindow();
461 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
464 wxString
value(((wxTextCtrl
*)m_propertyWindow
)->GetValue());
466 if (value
.Length() == 0)
469 float f
= (float)wxAtof((const wxChar
*)value
);
470 property
->GetValue() = f
;
474 bool wxRealFormValidator::OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
475 wxWindow
*WXUNUSED(parentWindow
) )
477 // The item used for viewing the real number: should be a text item.
478 wxWindow
*m_propertyWindow
= property
->GetWindow();
479 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
482 wxTextCtrl
*textItem
= (wxTextCtrl
*)m_propertyWindow
;
483 textItem
->SetValue(FloatToString(property
->GetValue().RealValue()));
488 /// Integer validator
490 IMPLEMENT_DYNAMIC_CLASS(wxIntegerFormValidator
, wxPropertyFormValidator
)
492 bool wxIntegerFormValidator::OnCheckValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
493 wxWindow
*parentWindow
)
495 if (m_integerMin
== 0.0 && m_integerMax
== 0.0)
498 // The item used for viewing the real number: should be a text item or a slider
499 wxWindow
*m_propertyWindow
= property
->GetWindow();
500 if (!m_propertyWindow
)
505 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
507 wxString
value(((wxTextCtrl
*)m_propertyWindow
)->GetValue());
509 if (!StringToLong(WXSTRINGCAST value
, &val
))
512 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), (const wxChar
*)value
);
513 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
517 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxSlider
)))
519 val
= (long)((wxSlider
*)m_propertyWindow
)->GetValue();
524 if (val
< m_integerMin
|| val
> m_integerMax
)
527 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
528 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
534 bool wxIntegerFormValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
535 wxWindow
*WXUNUSED(parentWindow
))
537 // The item used for viewing the real number: should be a text item or a slider
538 wxWindow
*m_propertyWindow
= property
->GetWindow();
539 if (!m_propertyWindow
)
542 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
544 wxString
value(((wxTextCtrl
*)m_propertyWindow
)->GetValue());
546 if (value
.Length() == 0)
549 long i
= wxAtol((const wxChar
*)value
);
550 property
->GetValue() = i
;
552 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxSlider
)))
554 property
->GetValue() = (long)((wxSlider
*)m_propertyWindow
)->GetValue();
562 bool wxIntegerFormValidator::OnDisplayValue( wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
563 wxWindow
*WXUNUSED(parentWindow
))
565 // The item used for viewing the real number: should be a text item or a slider
566 wxWindow
*m_propertyWindow
= property
->GetWindow();
567 if (!m_propertyWindow
)
570 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
572 wxTextCtrl
*textItem
= (wxTextCtrl
*)m_propertyWindow
;
573 textItem
->SetValue(LongToString(property
->GetValue().IntegerValue()));
575 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxSlider
)))
577 ((wxSlider
*)m_propertyWindow
)->SetValue((int)property
->GetValue().IntegerValue());
585 /// Boolean validator
587 IMPLEMENT_DYNAMIC_CLASS(wxBoolFormValidator
, wxPropertyFormValidator
)
589 bool wxBoolFormValidator::OnCheckValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
590 wxWindow
*WXUNUSED(parentWindow
))
592 // The item used for viewing the boolean: should be a checkbox
593 wxWindow
*m_propertyWindow
= property
->GetWindow();
594 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
600 bool wxBoolFormValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
601 wxWindow
*WXUNUSED(parentWindow
) )
603 // The item used for viewing the boolean: should be a checkbox.
604 wxWindow
*m_propertyWindow
= property
->GetWindow();
605 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
608 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
610 property
->GetValue() = (bool)checkBox
->GetValue();
614 bool wxBoolFormValidator::OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
615 wxWindow
*WXUNUSED(parentWindow
))
617 // The item used for viewing the boolean: should be a checkbox.
618 wxWindow
*m_propertyWindow
= property
->GetWindow();
619 if (!m_propertyWindow
|| !m_propertyWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
622 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
623 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
630 IMPLEMENT_DYNAMIC_CLASS(wxStringFormValidator
, wxPropertyFormValidator
)
632 wxStringFormValidator::wxStringFormValidator(wxStringList
*list
, long flags
):
633 wxPropertyFormValidator(flags
)
638 bool wxStringFormValidator::OnCheckValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
639 wxWindow
*parentWindow
)
644 // The item used for viewing the string: should be a text item, choice item or listbox.
645 wxWindow
*m_propertyWindow
= property
->GetWindow();
646 if (!m_propertyWindow
)
648 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
650 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
651 if (!m_strings
->Member(text
->GetValue()))
653 wxString
str( wxT("Value ") );
654 str
+= text
->GetValue();
655 str
+= wxT(" is not valid.");
656 wxMessageBox(str
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
662 // Any other item constrains the string value,
663 // so we don't have to check it.
668 bool wxStringFormValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
669 wxWindow
*WXUNUSED(parentWindow
) )
671 // The item used for viewing the string: should be a text item, choice item or listbox.
672 wxWindow
*m_propertyWindow
= property
->GetWindow();
673 if (!m_propertyWindow
)
675 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
677 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
678 property
->GetValue() = text
->GetValue();
680 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxListBox
)))
682 wxListBox
*lbox
= (wxListBox
*)m_propertyWindow
;
683 if (lbox
->GetSelection() > -1)
684 property
->GetValue() = lbox
->GetStringSelection();
687 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox)))
689 wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
691 if ((n = rbox->GetSelection()) > -1)
692 property->GetValue() = rbox->GetString(n);
695 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxChoice
)))
697 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
698 if (choice
->GetSelection() > -1)
699 property
->GetValue() = choice
->GetStringSelection();
706 bool wxStringFormValidator::OnDisplayValue(wxProperty
*property
, wxPropertyFormView
*WXUNUSED(view
),
707 wxWindow
*WXUNUSED(parentWindow
) )
709 // The item used for viewing the string: should be a text item, choice item or listbox.
710 wxWindow
*m_propertyWindow
= property
->GetWindow();
711 if (!m_propertyWindow
)
713 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)))
715 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
716 text
->SetValue(property
->GetValue().StringValue());
718 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxListBox
)))
720 wxListBox
*lbox
= (wxListBox
*)m_propertyWindow
;
721 if (lbox
->GetCount() == 0 && m_strings
)
723 // Try to initialize the listbox from 'strings'
724 wxStringList::Node
*node
= m_strings
->GetFirst();
727 wxChar
*s
= node
->GetData();
729 node
= node
->GetNext();
732 lbox
->SetStringSelection(property
->GetValue().StringValue());
735 else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox)))
737 wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
738 rbox->SetStringSelection(property->GetValue().StringValue());
741 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxChoice
)))
743 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
744 if (choice
->GetCount() == 0 && m_strings
)
746 // Try to initialize the choice item from 'strings'
747 // XView doesn't allow this kind of thing.
748 wxStringList::Node
*node
= m_strings
->GetFirst();
751 wxChar
*s
= node
->GetData();
753 node
= node
->GetNext();
756 choice
->SetStringSelection(property
->GetValue().StringValue());
763 #endif // wxUSE_PROPSHEET