1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "proplist.h"
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
31 #include "wx/deprecated/setup.h"
36 #include "wx/window.h"
38 #include "wx/button.h"
39 #include "wx/bmpbuttn.h"
40 #include "wx/textctrl.h"
41 #include "wx/listbox.h"
42 #include "wx/settings.h"
43 #include "wx/msgdlg.h"
44 #include "wx/filedlg.h"
48 #include "wx/module.h"
50 #include "wx/artprov.h"
52 #include "wx/colordlg.h"
53 #include "wx/deprecated/proplist.h"
60 static inline wxChar
* copystring(const wxChar
* s
)
61 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
63 // ----------------------------------------------------------------------------
64 // Property text edit control
65 // ----------------------------------------------------------------------------
67 IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
69 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
70 const wxWindowID id
, const wxString
& value
,
71 const wxPoint
& pos
, const wxSize
& size
,
72 long style
, const wxString
& name
):
73 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
78 void wxPropertyTextEdit::OnSetFocus()
82 void wxPropertyTextEdit::OnKillFocus()
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
92 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
94 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
95 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
96 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
97 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
98 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
99 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
100 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
101 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
102 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
103 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
104 wxPropertyListView::OnPropertyDoubleClick
)
105 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
108 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
110 m_propertyScrollingList
= NULL
;
114 m_confirmButton
= NULL
;
115 m_cancelButton
= NULL
;
116 m_propertyWindow
= propPanel
;
117 m_managedWindow
= NULL
;
119 m_windowCloseButton
= NULL
;
120 m_windowCancelButton
= NULL
;
121 m_windowHelpButton
= NULL
;
123 m_detailedEditing
= FALSE
;
126 wxPropertyListView::~wxPropertyListView()
130 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
132 m_propertySheet
= ps
;
134 AssociatePanel(panel
);
137 UpdatePropertyList();
141 // Update this view of the viewed object, called e.g. by
142 // the object itself.
143 bool wxPropertyListView::OnUpdateView()
148 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
150 if (!m_propertyScrollingList
|| !m_propertySheet
)
153 m_propertyScrollingList
->Clear();
156 m_valueList
->Clear();
157 m_valueText
->SetValue( wxT("") );
159 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
161 // Should sort them... later...
164 wxProperty
*property
= (wxProperty
*)node
->GetData();
165 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
166 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
167 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
168 node
= node
->GetNext();
173 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
175 if (!m_propertyScrollingList
|| !m_propertySheet
)
179 int currentlySelected
= m_propertyScrollingList
->GetSelection();
182 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
183 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
184 int sel
= FindListIndexForProperty(property
);
188 // Don't update the listbox unnecessarily because it can cause
191 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
192 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
195 // UpdatePropertyList(FALSE);
198 // TODO: why is this necessary?
200 if (currentlySelected
> -1)
201 m_propertyScrollingList
->SetSelection(currentlySelected
);
207 // Find the wxListBox index corresponding to this property
208 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
210 int n
= m_propertyScrollingList
->GetCount();
211 for (int i
= 0; i
< n
; i
++)
213 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
219 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
221 wxString
theString(name
);
224 int padWith
= nameWidth
- theString
.Length();
228 if (GetFlags() & wxPROP_SHOWVALUES
)
230 // Want to pad with spaces
231 theString
.Append( wxT(' '), padWith
);
238 // Select and show string representation in validator the given
239 // property. NULL resets to show no property.
240 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
242 if (m_currentProperty
)
244 EndShowingProperty(m_currentProperty
);
245 m_currentProperty
= NULL
;
248 m_valueList
->Clear();
249 m_valueText
->SetValue( wxT("") );
253 m_currentProperty
= property
;
254 BeginShowingProperty(property
);
258 int sel
= FindListIndexForProperty(property
);
260 m_propertyScrollingList
->SetSelection(sel
);
265 // Find appropriate validator and load property into value controls
266 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
268 m_currentValidator
= FindPropertyValidator(property
);
269 if (!m_currentValidator
)
272 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
275 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
277 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
278 DisplayProperty(property
);
282 // Find appropriate validator and unload property from value controls
283 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
285 if (!m_currentValidator
)
288 RetrieveProperty(property
);
290 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
293 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
295 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
296 if (m_detailedEditing
)
298 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
299 m_detailedEditing
= FALSE
;
304 void wxPropertyListView::BeginDetailedEditing()
306 if (!m_currentValidator
)
308 if (!m_currentProperty
)
310 if (m_detailedEditing
)
312 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
314 if (!m_currentProperty
->IsEnabled())
317 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
319 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
320 m_detailedEditing
= TRUE
;
323 void wxPropertyListView::EndDetailedEditing()
325 if (!m_currentValidator
)
327 if (!m_currentProperty
)
330 RetrieveProperty(m_currentProperty
);
332 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
335 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
337 if (m_detailedEditing
)
339 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
340 m_detailedEditing
= FALSE
;
344 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
346 if (!m_currentValidator
)
349 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
350 m_valueText
->SetEditable(FALSE
);
352 m_valueText
->SetEditable(TRUE
);
354 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
357 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
359 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
363 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
365 if (!m_currentValidator
)
367 if (!property
->IsEnabled())
370 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
373 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
375 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
377 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
379 UpdatePropertyDisplayInList(property
);
380 OnPropertyChanged(property
);
385 // Revert to old value
386 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
392 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
397 // Called by the listbox callback
398 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
400 int sel
= m_propertyScrollingList
->GetSelection();
403 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
404 if (newSel
&& newSel
!= m_currentProperty
)
406 ShowProperty(newSel
, FALSE
);
411 bool wxPropertyListView::CreateControls()
413 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
415 wxSize
largeButtonSize( 70, 25 );
416 wxSize
smallButtonSize( 23, 23 );
424 wxFont guiFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
428 wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
,
429 wxNORMAL
, wxNORMAL
, FALSE
, _T("Courier New"));
431 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
434 // May need to be changed in future to eliminate clashes with app.
435 // WHAT WAS THIS FOR?
436 // panel->SetClientData((char *)this);
438 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
440 // top row with optional buttons and input line
442 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
443 int buttonborder
= 3;
445 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
447 wxBitmap tickBitmap
= wxArtProvider::GetBitmap(wxART_TICK_MARK
);
448 wxBitmap crossBitmap
= wxArtProvider::GetBitmap(wxART_CROSS_MARK
);
450 if ( tickBitmap
.Ok() && crossBitmap
.Ok() )
452 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, tickBitmap
, wxPoint(-1, -1), smallButtonSize
);
453 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, crossBitmap
, wxPoint(-1, -1), smallButtonSize
);
457 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, _T(":-)"), wxPoint(-1, -1), smallButtonSize
);
458 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, _T("X"), wxPoint(-1, -1), smallButtonSize
);
461 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
462 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
465 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, _T(""),
466 wxPoint(-1, -1), wxSize(-1, smallButtonSize
.y
), wxPROCESS_ENTER
);
467 m_valueText
->Enable(FALSE
);
468 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
470 if (m_buttonFlags
& wxPROP_PULLDOWN
)
472 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, _T("..."), wxPoint(-1, -1), smallButtonSize
);
473 m_editButton
->Enable(FALSE
);
474 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
477 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
479 // middle section with two list boxes
481 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
483 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
484 m_valueList
->Show(FALSE
);
486 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxPoint(-1, -1), wxSize(100, 100));
487 m_propertyScrollingList
->SetFont(* boringFont
);
488 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
490 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
492 // bottom row with buttons
494 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
495 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
496 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
497 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
499 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
502 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
504 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxPoint(-1, -1), largeButtonSize
);
505 m_windowCloseButton
->SetDefault();
506 m_windowCloseButton
->SetFocus();
507 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
509 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
511 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxPoint(-1, -1), largeButtonSize
);
512 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
514 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
516 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxPoint(-1, -1), largeButtonSize
);
517 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
519 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
521 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxPoint(-1, -1), largeButtonSize
);
522 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
525 mainsizer
->Add( bottomsizer
, 0, wxALIGN_RIGHT
| wxEXPAND
);
528 panel
->SetSizer( mainsizer
);
533 void wxPropertyListView::ShowTextControl(bool show
)
536 m_valueText
->Show(show
);
539 void wxPropertyListView::ShowListBoxControl(bool show
)
541 if (!m_valueList
) return;
543 m_valueList
->Show(show
);
545 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
548 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
550 m_middleSizer
->Remove( 0 );
552 m_propertyWindow
->Layout();
556 void wxPropertyListView::EnableCheck(bool show
)
559 m_confirmButton
->Enable(show
);
562 void wxPropertyListView::EnableCross(bool show
)
565 m_cancelButton
->Enable(show
);
568 bool wxPropertyListView::OnClose()
570 // Retrieve the value if any
571 wxCommandEvent event
;
578 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
580 if (m_currentProperty
&& m_currentValidator
)
582 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
585 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
587 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
591 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
593 // Retrieve the value if any
596 m_managedWindow
->Close(TRUE
);
597 sm_dialogCancelled
= FALSE
;
600 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
602 // SetReturnCode(wxID_CANCEL);
603 m_managedWindow
->Close(TRUE
);
604 sm_dialogCancelled
= TRUE
;
607 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
611 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
613 if (m_currentProperty
)
615 RetrieveProperty(m_currentProperty
);
619 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
621 if (m_currentProperty
&& m_currentValidator
)
623 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
626 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
628 // Revert to old value
629 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
633 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
635 if (m_currentProperty
&& m_currentValidator
)
637 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
640 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
642 // Revert to old value
643 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
647 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
649 if (m_currentProperty
&& m_currentValidator
)
651 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
654 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
656 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
660 void wxPropertyListView::OnText(wxCommandEvent
& event
)
662 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
668 // ----------------------------------------------------------------------------
669 // Property dialog box
670 // ----------------------------------------------------------------------------
672 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog
, wxDialog
)
674 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
675 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
676 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
679 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
680 const wxString
& title
, const wxPoint
& pos
,
681 const wxSize
& size
, long style
, const wxString
& name
):
682 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
685 m_view
->AssociatePanel( ((wxPanel
*)this) );
686 m_view
->SetManagedWindow(this);
690 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
694 SetReturnCode(wxID_CANCEL
);
705 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
707 SetReturnCode(wxID_CANCEL
);
711 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
714 if (item == m_view->GetPropertyScrollingList())
715 view->OnDoubleClick();
719 // Extend event processing to search the view's event table
720 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
722 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
723 return wxEvtHandler::ProcessEvent(event
);
728 // ----------------------------------------------------------------------------
730 // ----------------------------------------------------------------------------
732 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel
, wxPanel
)
734 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
735 EVT_SIZE(wxPropertyListPanel::OnSize
)
738 wxPropertyListPanel::~wxPropertyListPanel()
742 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
745 if (item == view->GetPropertyScrollingList())
746 view->OnDoubleClick();
750 // Extend event processing to search the view's event table
751 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
753 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
754 return wxEvtHandler::ProcessEvent(event
);
759 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
764 // ----------------------------------------------------------------------------
766 // ----------------------------------------------------------------------------
768 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame
, wxFrame
)
770 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
771 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
774 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
779 m_propertyPanel
->SetView(NULL
);
790 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
792 return new wxPropertyListPanel(v
, parent
);
795 bool wxPropertyListFrame::Initialize()
797 m_propertyPanel
= OnCreatePanel(this, m_view
);
800 m_view
->AssociatePanel(m_propertyPanel
);
801 m_view
->SetManagedWindow(this);
802 m_propertyPanel
->SetAutoLayout(TRUE
);
809 // ----------------------------------------------------------------------------
810 // Property list specific validator
811 // ----------------------------------------------------------------------------
813 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
815 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
817 // view->GetValueText()->Show(TRUE);
819 OnDisplayValue(property
, view
, parentWindow
);
824 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
826 wxString
s(view
->GetValueList()->GetStringSelection());
829 view
->GetValueText()->SetValue(s
);
830 view
->RetrieveProperty(property
);
835 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
837 // view->GetValueText()->Show(TRUE);
838 wxString
str(property
->GetValue().GetStringRepresentation());
840 view
->GetValueText()->SetValue(str
);
844 // Called when TICK is pressed or focus is lost or view wants to update
845 // the property list.
846 // Does the transferance from the property editing area to the property itself
847 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
849 if (!view
->GetValueText())
854 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
856 if (view
->GetDetailedEditing())
857 view
->EndDetailedEditing();
859 view
->BeginDetailedEditing();
862 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
864 if (view
->GetConfirmButton())
865 view
->GetConfirmButton()->Enable(FALSE
);
866 if (view
->GetCancelButton())
867 view
->GetCancelButton()->Enable(FALSE
);
868 if (view
->GetEditButton())
869 view
->GetEditButton()->Enable(FALSE
);
873 // ----------------------------------------------------------------------------
874 // Default validators
875 // ----------------------------------------------------------------------------
877 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
880 /// Real number validator
882 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
884 if (m_realMin
== 0.0 && m_realMax
== 0.0)
887 if (!view
->GetValueText())
889 wxString
value(view
->GetValueText()->GetValue());
892 if (!StringToFloat(WXSTRINGCAST value
, &val
))
895 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), value
.GetData());
896 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
900 if (val
< m_realMin
|| val
> m_realMax
)
903 wxSprintf(buf
, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin
, m_realMax
);
904 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
910 // Called when TICK is pressed or focus is lost or view wants to update
911 // the property list.
912 // Does the transferance from the property editing area to the property itself
913 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
915 if (!view
->GetValueText())
918 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
921 wxString
value(view
->GetValueText()->GetValue());
922 float f
= (float)wxAtof(value
.GetData());
923 property
->GetValue() = f
;
927 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
929 if (view
->GetConfirmButton())
930 view
->GetConfirmButton()->Enable(TRUE
);
931 if (view
->GetCancelButton())
932 view
->GetCancelButton()->Enable(TRUE
);
933 if (view
->GetEditButton())
934 view
->GetEditButton()->Enable(FALSE
);
935 if (view
->GetValueText())
936 view
->GetValueText()->Enable(TRUE
);
941 /// Integer validator
943 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
945 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
947 if (m_integerMin
== 0 && m_integerMax
== 0)
950 if (!view
->GetValueText())
952 wxString
value(view
->GetValueText()->GetValue());
955 if (!StringToLong(WXSTRINGCAST value
, &val
))
958 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), value
.GetData());
959 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
962 if (val
< m_integerMin
|| val
> m_integerMax
)
965 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
966 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
972 // Called when TICK is pressed or focus is lost or view wants to update
973 // the property list.
974 // Does the transferance from the property editing area to the property itself
975 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
977 if (!view
->GetValueText())
980 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
983 wxString
value(view
->GetValueText()->GetValue());
984 long val
= (long)wxAtoi(value
.GetData());
985 property
->GetValue() = (long)val
;
989 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
991 if (view
->GetConfirmButton())
992 view
->GetConfirmButton()->Enable(TRUE
);
993 if (view
->GetCancelButton())
994 view
->GetCancelButton()->Enable(TRUE
);
995 if (view
->GetEditButton())
996 view
->GetEditButton()->Enable(FALSE
);
997 if (view
->GetValueText())
998 view
->GetValueText()->Enable(TRUE
);
1003 /// boolean validator
1005 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1007 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1009 if (!view
->GetValueText())
1011 wxString
value(view
->GetValueText()->GetValue());
1012 if (value
!= wxT("True") && value
!= wxT("False"))
1014 wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1020 // Called when TICK is pressed or focus is lost or view wants to update
1021 // the property list.
1022 // Does the transferance from the property editing area to the property itself
1023 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1025 if (!view
->GetValueText())
1028 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1031 wxString
value(view
->GetValueText()->GetValue());
1032 bool boolValue
= FALSE
;
1033 if (value
== wxT("True"))
1037 property
->GetValue() = (bool)boolValue
;
1041 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1043 if (!view
->GetValueText())
1045 wxString
str(property
->GetValue().GetStringRepresentation());
1047 view
->GetValueText()->SetValue(str
);
1049 if (view
->GetValueList()->IsShown())
1051 view
->GetValueList()->SetStringSelection(str
);
1056 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1058 if (view
->GetConfirmButton())
1059 view
->GetConfirmButton()->Enable(FALSE
);
1060 if (view
->GetCancelButton())
1061 view
->GetCancelButton()->Enable(FALSE
);
1062 if (view
->GetEditButton())
1063 view
->GetEditButton()->Enable(TRUE
);
1064 if (view
->GetValueText())
1065 view
->GetValueText()->Enable(FALSE
);
1069 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1071 if (view
->GetValueList())
1073 view
->ShowListBoxControl(TRUE
);
1074 view
->GetValueList()->Enable(TRUE
);
1076 view
->GetValueList()->Append(wxT("True"));
1077 view
->GetValueList()->Append(wxT("False"));
1078 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1079 view
->GetValueList()->SetStringSelection(currentString
);
1080 delete[] currentString
;
1085 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1087 if (view
->GetValueList())
1089 view
->GetValueList()->Clear();
1090 view
->ShowListBoxControl(FALSE
);
1091 view
->GetValueList()->Enable(FALSE
);
1096 // Called when the property is double clicked. Extra functionality can be provided,
1097 // cycling through possible values.
1098 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1100 if (!view
->GetValueText())
1102 if (property
->GetValue().BoolValue())
1103 property
->GetValue() = (bool)FALSE
;
1105 property
->GetValue() = (bool)TRUE
;
1106 view
->DisplayProperty(property
);
1107 view
->UpdatePropertyDisplayInList(property
);
1108 view
->OnPropertyChanged(property
);
1113 /// String validator
1115 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1117 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1118 wxPropertyListValidator(flags
)
1121 // If no constraint, we just allow the string to be edited.
1122 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1123 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1126 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1131 if (!view
->GetValueText())
1133 wxString
value(view
->GetValueText()->GetValue());
1135 if (!m_strings
->Member(value
.GetData()))
1137 wxString
str( wxT("Value ") );
1138 str
+= value
.GetData();
1139 str
+= wxT(" is not valid.");
1140 wxMessageBox( str
.GetData(), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1146 // Called when TICK is pressed or focus is lost or view wants to update
1147 // the property list.
1148 // Does the transferance from the property editing area to the property itself
1149 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1151 if (!view
->GetValueText())
1153 wxString
value(view
->GetValueText()->GetValue());
1154 property
->GetValue() = value
;
1158 // Called when TICK is pressed or focus is lost or view wants to update
1159 // the property list.
1160 // Does the transferance from the property editing area to the property itself
1161 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1163 if (!view
->GetValueText())
1165 wxString
str(property
->GetValue().GetStringRepresentation());
1166 view
->GetValueText()->SetValue(str
);
1167 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->GetCount() > 0)
1169 view
->GetValueList()->SetStringSelection(str
);
1174 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1179 if (view
->GetEditButton())
1180 view
->GetEditButton()->Enable(FALSE
);
1181 if (view
->GetConfirmButton())
1182 view
->GetConfirmButton()->Enable(TRUE
);
1183 if (view
->GetCancelButton())
1184 view
->GetCancelButton()->Enable(TRUE
);
1185 if (view
->GetValueText())
1186 view
->GetValueText()->Enable(TRUE
);
1191 if (view
->GetValueText())
1192 view
->GetValueText()->Enable(FALSE
);
1194 if (view
->GetEditButton())
1195 view
->GetEditButton()->Enable(TRUE
);
1197 if (view
->GetConfirmButton())
1198 view
->GetConfirmButton()->Enable(FALSE
);
1199 if (view
->GetCancelButton())
1200 view
->GetCancelButton()->Enable(FALSE
);
1204 bool wxStringListValidator::OnPrepareDetailControls( wxProperty
*property
,
1205 wxPropertyListView
*view
,
1206 wxWindow
*WXUNUSED(parentWindow
) )
1208 if (view
->GetValueList())
1210 view
->ShowListBoxControl(TRUE
);
1211 view
->GetValueList()->Enable(TRUE
);
1212 wxStringList::Node
*node
= m_strings
->GetFirst();
1215 wxChar
*s
= node
->GetData();
1216 view
->GetValueList()->Append(s
);
1217 node
= node
->GetNext();
1219 wxChar
*currentString
= property
->GetValue().StringValue();
1220 view
->GetValueList()->SetStringSelection(currentString
);
1225 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1232 if (view
->GetValueList())
1234 view
->GetValueList()->Clear();
1235 view
->ShowListBoxControl(FALSE
);
1236 view
->GetValueList()->Enable(FALSE
);
1241 // Called when the property is double clicked. Extra functionality can be provided,
1242 // cycling through possible values.
1243 bool wxStringListValidator::OnDoubleClick( wxProperty
*property
,
1244 wxPropertyListView
*view
,
1245 wxWindow
*WXUNUSED(parentWindow
) )
1247 if (!view
->GetValueText())
1252 wxStringList::Node
*node
= m_strings
->GetFirst();
1253 wxChar
*currentString
= property
->GetValue().StringValue();
1256 wxChar
*s
= node
->GetData();
1257 if (wxStrcmp(s
, currentString
) == 0)
1259 wxChar
*nextString
= NULL
;
1260 if (node
->GetNext())
1261 nextString
= node
->GetNext()->GetData();
1263 nextString
= m_strings
->GetFirst()->GetData();
1264 property
->GetValue() = wxString(nextString
);
1265 view
->DisplayProperty(property
);
1266 view
->UpdatePropertyDisplayInList(property
);
1267 view
->OnPropertyChanged(property
);
1270 else node
= node
->GetNext();
1276 /// Filename validator
1278 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1280 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1281 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1285 wxFilenameListValidator::~wxFilenameListValidator()
1289 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1294 // Called when TICK is pressed or focus is lost or view wants to update
1295 // the property list.
1296 // Does the transferance from the property editing area to the property itself
1297 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1299 if (!view
->GetValueText())
1301 wxString
value(view
->GetValueText()->GetValue());
1302 property
->GetValue() = value
;
1306 // Called when TICK is pressed or focus is lost or view wants to update
1307 // the property list.
1308 // Does the transferance from the property editing area to the property itself
1309 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1311 if (!view
->GetValueText())
1313 wxString
str(property
->GetValue().GetStringRepresentation());
1314 view
->GetValueText()->SetValue(str
);
1318 // Called when the property is double clicked. Extra functionality can be provided,
1319 // cycling through possible values.
1320 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1322 if (!view
->GetValueText())
1324 OnEdit(property
, view
, parentWindow
);
1328 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1330 if (view
->GetConfirmButton())
1331 view
->GetConfirmButton()->Enable(TRUE
);
1332 if (view
->GetCancelButton())
1333 view
->GetCancelButton()->Enable(TRUE
);
1334 if (view
->GetEditButton())
1335 view
->GetEditButton()->Enable(TRUE
);
1336 if (view
->GetValueText())
1337 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1341 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1343 if (!view
->GetValueText())
1346 wxString s
= wxFileSelector(
1347 m_filenameMessage
.GetData(),
1348 wxPathOnly(property
->GetValue().StringValue()),
1349 wxFileNameFromPath(property
->GetValue().StringValue()),
1351 m_filenameWildCard
.GetData(),
1356 property
->GetValue() = s
;
1357 view
->DisplayProperty(property
);
1358 view
->UpdatePropertyDisplayInList(property
);
1359 view
->OnPropertyChanged(property
);
1364 /// Colour validator
1366 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1368 wxColourListValidator::wxColourListValidator(long flags
):
1369 wxPropertyListValidator(flags
)
1373 wxColourListValidator::~wxColourListValidator()
1377 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1382 // Called when TICK is pressed or focus is lost or view wants to update
1383 // the property list.
1384 // Does the transferance from the property editing area to the property itself
1385 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1387 if (!view
->GetValueText())
1389 wxString
value(view
->GetValueText()->GetValue());
1391 property
->GetValue() = value
;
1395 // Called when TICK is pressed or focus is lost or view wants to update
1396 // the property list.
1397 // Does the transferance from the property editing area to the property itself
1398 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1400 if (!view
->GetValueText())
1402 wxString
str(property
->GetValue().GetStringRepresentation());
1403 view
->GetValueText()->SetValue(str
);
1407 // Called when the property is double clicked. Extra functionality can be provided,
1408 // cycling through possible values.
1409 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1411 if (!view
->GetValueText())
1413 OnEdit(property
, view
, parentWindow
);
1417 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1419 if (view
->GetConfirmButton())
1420 view
->GetConfirmButton()->Enable(TRUE
);
1421 if (view
->GetCancelButton())
1422 view
->GetCancelButton()->Enable(TRUE
);
1423 if (view
->GetEditButton())
1424 view
->GetEditButton()->Enable(TRUE
);
1425 if (view
->GetValueText())
1426 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1430 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1432 if (!view
->GetValueText())
1435 wxChar
*s
= property
->GetValue().StringValue();
1442 g
= wxHexToDec(s
+2);
1443 b
= wxHexToDec(s
+4);
1446 wxColour
col(r
,g
,b
);
1449 data
.SetChooseFull(TRUE
);
1450 data
.SetColour(col
);
1452 for (int i
= 0; i
< 16; i
++)
1454 wxColour
colour(i
*16, i
*16, i
*16);
1455 data
.SetCustomColour(i
, colour
);
1458 wxColourDialog
dialog(parentWindow
, &data
);
1459 if (dialog
.ShowModal() != wxID_CANCEL
)
1461 wxColourData retData
= dialog
.GetColourData();
1462 col
= retData
.GetColour();
1465 wxDecToHex(col
.Red(), buf
);
1466 wxDecToHex(col
.Green(), buf
+2);
1467 wxDecToHex(col
.Blue(), buf
+4);
1469 property
->GetValue() = wxString(buf
);
1470 view
->DisplayProperty(property
);
1471 view
->UpdatePropertyDisplayInList(property
);
1472 view
->OnPropertyChanged(property
);
1477 /// List of strings validator. For this we need more user interface than
1478 /// we get with a property list; so create a new dialog for editing the list.
1480 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1482 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1483 wxPropertyListValidator(flags
)
1487 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1489 // No constraints for an arbitrary, user-editable list of strings.
1493 // Called when TICK is pressed or focus is lost or view wants to update
1494 // the property list.
1495 // Does the transferance from the property editing area to the property itself.
1496 // In this case, the user cannot directly edit the string list.
1497 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1502 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1504 if (!view
->GetValueText())
1506 wxString
str(property
->GetValue().GetStringRepresentation());
1507 view
->GetValueText()->SetValue(str
);
1511 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1513 if (view
->GetEditButton())
1514 view
->GetEditButton()->Enable(TRUE
);
1515 if (view
->GetValueText())
1516 view
->GetValueText()->Enable(FALSE
);
1518 if (view
->GetConfirmButton())
1519 view
->GetConfirmButton()->Enable(FALSE
);
1520 if (view
->GetCancelButton())
1521 view
->GetCancelButton()->Enable(FALSE
);
1525 // Called when the property is double clicked. Extra functionality can be provided,
1526 // cycling through possible values.
1527 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1529 OnEdit(property
, view
, parentWindow
);
1533 void wxListOfStringsListValidator::OnEdit( wxProperty
*property
,
1534 wxPropertyListView
*view
,
1535 wxWindow
*parentWindow
)
1537 // Convert property value to a list of strings for editing
1538 wxStringList
*stringList
= new wxStringList
;
1540 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1543 wxChar
*s
= expr
->StringValue();
1546 expr
= expr
->GetNext();
1549 wxString
title(wxT("Editing "));
1550 title
+= property
->GetName();
1552 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1554 wxPropertyValue
& oldValue
= property
->GetValue();
1555 oldValue
.ClearList();
1556 wxStringList::Node
*node
= stringList
->GetFirst();
1559 wxChar
*s
= node
->GetData();
1560 oldValue
.Append(new wxPropertyValue(s
));
1562 node
= node
->GetNext();
1565 view
->DisplayProperty(property
);
1566 view
->UpdatePropertyDisplayInList(property
);
1567 view
->OnPropertyChanged(property
);
1572 class wxPropertyStringListEditorDialog
: public wxDialog
1575 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1576 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1577 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= wxT("stringEditorDialogBox")):
1578 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1580 m_stringList
= NULL
;
1581 m_stringText
= NULL
;
1583 sm_dialogCancelled
= FALSE
;
1584 m_currentSelection
= -1;
1586 ~wxPropertyStringListEditorDialog(void) {}
1587 void OnCloseWindow(wxCloseEvent
& event
);
1588 void SaveCurrentSelection(void);
1589 void ShowCurrentSelection(void);
1591 void OnOK(wxCommandEvent
& event
);
1592 void OnCancel(wxCommandEvent
& event
);
1593 void OnAdd(wxCommandEvent
& event
);
1594 void OnDelete(wxCommandEvent
& event
);
1595 void OnStrings(wxCommandEvent
& event
);
1596 void OnText(wxCommandEvent
& event
);
1599 wxStringList
* m_stringList
;
1600 wxListBox
* m_listBox
;
1601 wxTextCtrl
* m_stringText
;
1602 static bool sm_dialogCancelled
;
1603 int m_currentSelection
;
1604 DECLARE_EVENT_TABLE()
1607 #define wxID_PROP_SL_ADD 3000
1608 #define wxID_PROP_SL_DELETE 3001
1609 #define wxID_PROP_SL_STRINGS 3002
1610 #define wxID_PROP_SL_TEXT 3003
1612 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1613 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1614 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1615 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1616 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1617 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1618 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1619 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1622 class wxPropertyStringListEditorText
: public wxTextCtrl
1625 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1626 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1627 long windowStyle
= 0, const wxString
& name
= wxT("text")):
1628 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1633 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1634 dialog
->SaveCurrentSelection();
1638 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1640 // Edit the string list.
1641 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1643 int largeButtonWidth
= 60;
1644 int largeButtonHeight
= 25;
1646 wxBeginBusyCursor();
1647 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1648 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1650 dialog
->m_stringList
= stringList
;
1652 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1653 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1655 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1656 wxID_PROP_SL_TEXT
, wxT(""), wxPoint(5, 240),
1657 wxSize(300, -1), wxPROCESS_ENTER
);
1658 dialog
->m_stringText
->Enable(FALSE
);
1660 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, wxT("Add"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1661 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, wxT("Delete"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1662 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, wxT("Cancel"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1663 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, wxT("OK"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1666 okButton
->SetDefault();
1669 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1671 c
->top
.SameAs (dialog
, wxTop
, 2);
1672 c
->left
.SameAs (dialog
, wxLeft
, 2);
1673 c
->right
.SameAs (dialog
, wxRight
, 2);
1674 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1675 dialog
->m_listBox
->SetConstraints(c
);
1677 c
= new wxLayoutConstraints
;
1678 c
->left
.SameAs (dialog
, wxLeft
, 2);
1679 c
->right
.SameAs (dialog
, wxRight
, 2);
1680 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1682 dialog
->m_stringText
->SetConstraints(c
);
1684 c
= new wxLayoutConstraints
;
1685 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1686 c
->left
.SameAs (dialog
, wxLeft
, 2);
1689 addButton
->SetConstraints(c
);
1691 c
= new wxLayoutConstraints
;
1692 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1693 c
->left
.SameAs (addButton
, wxRight
, 2);
1696 deleteButton
->SetConstraints(c
);
1698 c
= new wxLayoutConstraints
;
1699 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1700 c
->right
.SameAs (dialog
, wxRight
, 2);
1703 cancelButton
->SetConstraints(c
);
1705 c
= new wxLayoutConstraints
;
1706 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1707 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1710 okButton
->SetConstraints(c
);
1712 wxStringList::Node
*node
= stringList
->GetFirst();
1715 wxChar
*str
= node
->GetData();
1716 // Save node as client data for each listbox item
1717 dialog
->m_listBox
->Append(str
, (wxChar
*)node
);
1718 node
= node
->GetNext();
1721 dialog
->SetClientSize(310, 305);
1724 dialog
->Centre(wxBOTH
);
1726 if (dialog
->ShowModal() == wxID_CANCEL
)
1733 * String list editor callbacks
1737 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1739 int sel
= m_listBox
->GetSelection();
1742 m_currentSelection
= sel
;
1744 ShowCurrentSelection();
1748 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1750 int sel
= m_listBox
->GetSelection();
1754 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1758 m_listBox
->Delete(sel
);
1759 delete[] (wxChar
*)node
->GetData();
1761 m_currentSelection
= -1;
1762 m_stringText
->SetValue(_T(""));
1765 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1767 SaveCurrentSelection();
1769 wxString initialText
;
1770 wxNode
*node
= m_stringList
->Add(initialText
);
1771 m_listBox
->Append(initialText
, (void *)node
);
1772 m_currentSelection
= m_stringList
->GetCount() - 1;
1773 m_listBox
->SetSelection(m_currentSelection
);
1774 ShowCurrentSelection();
1775 m_stringText
->SetFocus();
1778 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1780 SaveCurrentSelection();
1786 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1788 sm_dialogCancelled
= TRUE
;
1789 EndModal(wxID_CANCEL
);
1794 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1796 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1798 SaveCurrentSelection();
1803 wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
1805 SaveCurrentSelection();
1810 void wxPropertyStringListEditorDialog::SaveCurrentSelection()
1812 if (m_currentSelection
== -1)
1815 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1819 wxString
txt(m_stringText
->GetValue());
1820 if (node
->GetData())
1821 delete[] (wxChar
*)node
->GetData();
1822 node
->SetData((wxObject
*)wxStrdup(txt
));
1824 m_listBox
->SetString(m_currentSelection
, (wxChar
*)node
->GetData());
1827 void wxPropertyStringListEditorDialog::ShowCurrentSelection()
1829 if (m_currentSelection
== -1)
1831 m_stringText
->SetValue(wxT(""));
1834 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1835 wxChar
*txt
= (wxChar
*)node
->GetData();
1836 m_stringText
->SetValue(txt
);
1837 m_stringText
->Enable(TRUE
);
1841 #endif // wxUSE_PROPSHEET