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"
34 #include "wx/window.h"
36 #include "wx/button.h"
37 #include "wx/bmpbuttn.h"
38 #include "wx/textctrl.h"
39 #include "wx/listbox.h"
40 #include "wx/settings.h"
41 #include "wx/msgdlg.h"
42 #include "wx/filedlg.h"
46 #include "wx/module.h"
48 #include "wx/artprov.h"
50 #include "wx/colordlg.h"
51 #include "wx/proplist.h"
58 // ----------------------------------------------------------------------------
59 // Property text edit control
60 // ----------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
64 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
65 const wxWindowID id
, const wxString
& value
,
66 const wxPoint
& pos
, const wxSize
& size
,
67 long style
, const wxString
& name
):
68 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
73 void wxPropertyTextEdit::OnSetFocus()
77 void wxPropertyTextEdit::OnKillFocus()
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
87 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
89 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
90 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
91 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
92 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
93 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
94 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
95 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
96 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
97 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
98 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
99 wxPropertyListView::OnPropertyDoubleClick
)
100 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
103 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
105 m_propertyScrollingList
= NULL
;
109 m_confirmButton
= NULL
;
110 m_cancelButton
= NULL
;
111 m_propertyWindow
= propPanel
;
112 m_managedWindow
= NULL
;
114 m_windowCloseButton
= NULL
;
115 m_windowCancelButton
= NULL
;
116 m_windowHelpButton
= NULL
;
118 m_detailedEditing
= FALSE
;
121 wxPropertyListView::~wxPropertyListView()
125 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
127 m_propertySheet
= ps
;
129 AssociatePanel(panel
);
132 UpdatePropertyList();
136 // Update this view of the viewed object, called e.g. by
137 // the object itself.
138 bool wxPropertyListView::OnUpdateView()
143 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
145 if (!m_propertyScrollingList
|| !m_propertySheet
)
148 m_propertyScrollingList
->Clear();
151 m_valueList
->Clear();
152 m_valueText
->SetValue( wxT("") );
154 wxNode
*node
= m_propertySheet
->GetProperties().First();
156 // Should sort them... later...
159 wxProperty
*property
= (wxProperty
*)node
->Data();
160 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
161 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
162 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
168 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
170 if (!m_propertyScrollingList
|| !m_propertySheet
)
174 int currentlySelected
= m_propertyScrollingList
->GetSelection();
177 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
178 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
179 int sel
= FindListIndexForProperty(property
);
183 // Don't update the listbox unnecessarily because it can cause
186 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
187 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
190 // UpdatePropertyList(FALSE);
193 // TODO: why is this necessary?
195 if (currentlySelected
> -1)
196 m_propertyScrollingList
->SetSelection(currentlySelected
);
202 // Find the wxListBox index corresponding to this property
203 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
205 int n
= m_propertyScrollingList
->GetCount();
206 for (int i
= 0; i
< n
; i
++)
208 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
214 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
216 wxString
theString(name
);
219 int padWith
= nameWidth
- theString
.Length();
223 if (GetFlags() & wxPROP_SHOWVALUES
)
225 // Want to pad with spaces
226 theString
.Append( wxT(' '), padWith
);
233 // Select and show string representation in validator the given
234 // property. NULL resets to show no property.
235 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
237 if (m_currentProperty
)
239 EndShowingProperty(m_currentProperty
);
240 m_currentProperty
= NULL
;
243 m_valueList
->Clear();
244 m_valueText
->SetValue( wxT("") );
248 m_currentProperty
= property
;
249 BeginShowingProperty(property
);
253 int sel
= FindListIndexForProperty(property
);
255 m_propertyScrollingList
->SetSelection(sel
);
260 // Find appropriate validator and load property into value controls
261 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
263 m_currentValidator
= FindPropertyValidator(property
);
264 if (!m_currentValidator
)
267 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
270 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
272 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
273 DisplayProperty(property
);
277 // Find appropriate validator and unload property from value controls
278 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
280 if (!m_currentValidator
)
283 RetrieveProperty(property
);
285 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
288 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
290 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
291 if (m_detailedEditing
)
293 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
294 m_detailedEditing
= FALSE
;
299 void wxPropertyListView::BeginDetailedEditing()
301 if (!m_currentValidator
)
303 if (!m_currentProperty
)
305 if (m_detailedEditing
)
307 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
309 if (!m_currentProperty
->IsEnabled())
312 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
314 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
315 m_detailedEditing
= TRUE
;
318 void wxPropertyListView::EndDetailedEditing()
320 if (!m_currentValidator
)
322 if (!m_currentProperty
)
325 RetrieveProperty(m_currentProperty
);
327 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
330 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
332 if (m_detailedEditing
)
334 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
335 m_detailedEditing
= FALSE
;
339 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
341 if (!m_currentValidator
)
344 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
345 m_valueText
->SetEditable(FALSE
);
347 m_valueText
->SetEditable(TRUE
);
349 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
352 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
354 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
358 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
360 if (!m_currentValidator
)
362 if (!property
->IsEnabled())
365 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
368 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
370 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
372 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
374 UpdatePropertyDisplayInList(property
);
375 OnPropertyChanged(property
);
380 // Revert to old value
381 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
387 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
392 // Called by the listbox callback
393 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
395 int sel
= m_propertyScrollingList
->GetSelection();
398 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
399 if (newSel
&& newSel
!= m_currentProperty
)
401 ShowProperty(newSel
, FALSE
);
406 bool wxPropertyListView::CreateControls()
408 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
410 wxSize
largeButtonSize( 70, 25 );
411 wxSize
smallButtonSize( 23, 23 );
419 wxFont guiFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
423 wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
,
424 wxNORMAL
, wxNORMAL
, FALSE
, _T("Courier New"));
426 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
429 // May need to be changed in future to eliminate clashes with app.
430 // WHAT WAS THIS FOR?
431 // panel->SetClientData((char *)this);
433 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
435 // top row with optional buttons and input line
437 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
438 int buttonborder
= 3;
440 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
442 wxBitmap tickBitmap
= wxArtProvider::GetBitmap(wxART_TICK_MARK
);
443 wxBitmap crossBitmap
= wxArtProvider::GetBitmap(wxART_CROSS_MARK
);
445 if ( tickBitmap
.Ok() && crossBitmap
.Ok() )
447 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, tickBitmap
, wxPoint(-1, -1), smallButtonSize
);
448 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, crossBitmap
, wxPoint(-1, -1), smallButtonSize
);
452 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, _T(":-)"), wxPoint(-1, -1), smallButtonSize
);
453 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, _T("X"), wxPoint(-1, -1), smallButtonSize
);
456 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
457 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
460 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, _T(""),
461 wxPoint(-1, -1), wxSize(-1, smallButtonSize
.y
), wxPROCESS_ENTER
);
462 m_valueText
->Enable(FALSE
);
463 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
465 if (m_buttonFlags
& wxPROP_PULLDOWN
)
467 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, _T("..."), wxPoint(-1, -1), smallButtonSize
);
468 m_editButton
->Enable(FALSE
);
469 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
472 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
474 // middle section with two list boxes
476 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
478 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
479 m_valueList
->Show(FALSE
);
481 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxPoint(-1, -1), wxSize(100, 100));
482 m_propertyScrollingList
->SetFont(* boringFont
);
483 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
485 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
487 // bottom row with buttons
489 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
490 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
491 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
492 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
494 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
497 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
499 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxPoint(-1, -1), largeButtonSize
);
500 m_windowCloseButton
->SetDefault();
501 m_windowCloseButton
->SetFocus();
502 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
504 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
506 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxPoint(-1, -1), largeButtonSize
);
507 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
509 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
511 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxPoint(-1, -1), largeButtonSize
);
512 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
514 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
516 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxPoint(-1, -1), largeButtonSize
);
517 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
520 mainsizer
->Add( bottomsizer
, 0, wxALIGN_RIGHT
| wxEXPAND
);
523 panel
->SetSizer( mainsizer
);
528 void wxPropertyListView::ShowTextControl(bool show
)
531 m_valueText
->Show(show
);
534 void wxPropertyListView::ShowListBoxControl(bool show
)
536 if (!m_valueList
) return;
538 m_valueList
->Show(show
);
540 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
543 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
545 m_middleSizer
->Remove( 0 );
547 m_propertyWindow
->Layout();
551 void wxPropertyListView::EnableCheck(bool show
)
554 m_confirmButton
->Enable(show
);
557 void wxPropertyListView::EnableCross(bool show
)
560 m_cancelButton
->Enable(show
);
563 bool wxPropertyListView::OnClose()
565 // Retrieve the value if any
566 wxCommandEvent event
;
573 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
575 if (m_currentProperty
&& m_currentValidator
)
577 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
580 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
582 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
586 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
588 // Retrieve the value if any
591 m_managedWindow
->Close(TRUE
);
592 sm_dialogCancelled
= FALSE
;
595 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
597 // SetReturnCode(wxID_CANCEL);
598 m_managedWindow
->Close(TRUE
);
599 sm_dialogCancelled
= TRUE
;
602 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
606 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
608 if (m_currentProperty
)
610 RetrieveProperty(m_currentProperty
);
614 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
616 if (m_currentProperty
&& m_currentValidator
)
618 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
621 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
623 // Revert to old value
624 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
628 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
630 if (m_currentProperty
&& m_currentValidator
)
632 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
635 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
637 // Revert to old value
638 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
642 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
644 if (m_currentProperty
&& m_currentValidator
)
646 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
649 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
651 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
655 void wxPropertyListView::OnText(wxCommandEvent
& event
)
657 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
663 // ----------------------------------------------------------------------------
664 // Property dialog box
665 // ----------------------------------------------------------------------------
667 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog
, wxDialog
)
669 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
670 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
671 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
674 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
675 const wxString
& title
, const wxPoint
& pos
,
676 const wxSize
& size
, long style
, const wxString
& name
):
677 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
680 m_view
->AssociatePanel( ((wxPanel
*)this) );
681 m_view
->SetManagedWindow(this);
685 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
689 SetReturnCode(wxID_CANCEL
);
700 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
702 SetReturnCode(wxID_CANCEL
);
706 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
709 if (item == m_view->GetPropertyScrollingList())
710 view->OnDoubleClick();
714 // Extend event processing to search the view's event table
715 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
717 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
718 return wxEvtHandler::ProcessEvent(event
);
723 // ----------------------------------------------------------------------------
725 // ----------------------------------------------------------------------------
727 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel
, wxPanel
)
729 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
730 EVT_SIZE(wxPropertyListPanel::OnSize
)
733 wxPropertyListPanel::~wxPropertyListPanel()
737 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
740 if (item == view->GetPropertyScrollingList())
741 view->OnDoubleClick();
745 // Extend event processing to search the view's event table
746 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
748 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
749 return wxEvtHandler::ProcessEvent(event
);
754 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
759 // ----------------------------------------------------------------------------
761 // ----------------------------------------------------------------------------
763 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame
, wxFrame
)
765 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
766 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
769 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
774 m_propertyPanel
->SetView(NULL
);
785 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
787 return new wxPropertyListPanel(v
, parent
);
790 bool wxPropertyListFrame::Initialize()
792 m_propertyPanel
= OnCreatePanel(this, m_view
);
795 m_view
->AssociatePanel(m_propertyPanel
);
796 m_view
->SetManagedWindow(this);
797 m_propertyPanel
->SetAutoLayout(TRUE
);
804 // ----------------------------------------------------------------------------
805 // Property list specific validator
806 // ----------------------------------------------------------------------------
808 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
810 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
812 // view->GetValueText()->Show(TRUE);
814 OnDisplayValue(property
, view
, parentWindow
);
819 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
821 wxString
s(view
->GetValueList()->GetStringSelection());
824 view
->GetValueText()->SetValue(s
);
825 view
->RetrieveProperty(property
);
830 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
832 // view->GetValueText()->Show(TRUE);
833 wxString
str(property
->GetValue().GetStringRepresentation());
835 view
->GetValueText()->SetValue(str
);
839 // Called when TICK is pressed or focus is lost or view wants to update
840 // the property list.
841 // Does the transferance from the property editing area to the property itself
842 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
844 if (!view
->GetValueText())
849 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
851 if (view
->GetDetailedEditing())
852 view
->EndDetailedEditing();
854 view
->BeginDetailedEditing();
857 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
859 if (view
->GetConfirmButton())
860 view
->GetConfirmButton()->Enable(FALSE
);
861 if (view
->GetCancelButton())
862 view
->GetCancelButton()->Enable(FALSE
);
863 if (view
->GetEditButton())
864 view
->GetEditButton()->Enable(FALSE
);
868 // ----------------------------------------------------------------------------
869 // Default validators
870 // ----------------------------------------------------------------------------
872 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
875 /// Real number validator
877 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
879 if (m_realMin
== 0.0 && m_realMax
== 0.0)
882 if (!view
->GetValueText())
884 wxString
value(view
->GetValueText()->GetValue());
887 if (!StringToFloat(WXSTRINGCAST value
, &val
))
890 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), value
.GetData());
891 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
895 if (val
< m_realMin
|| val
> m_realMax
)
898 wxSprintf(buf
, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin
, m_realMax
);
899 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
905 // Called when TICK is pressed or focus is lost or view wants to update
906 // the property list.
907 // Does the transferance from the property editing area to the property itself
908 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
910 if (!view
->GetValueText())
913 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
916 wxString
value(view
->GetValueText()->GetValue());
917 float f
= (float)wxAtof(value
.GetData());
918 property
->GetValue() = f
;
922 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
924 if (view
->GetConfirmButton())
925 view
->GetConfirmButton()->Enable(TRUE
);
926 if (view
->GetCancelButton())
927 view
->GetCancelButton()->Enable(TRUE
);
928 if (view
->GetEditButton())
929 view
->GetEditButton()->Enable(FALSE
);
930 if (view
->GetValueText())
931 view
->GetValueText()->Enable(TRUE
);
936 /// Integer validator
938 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
940 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
942 if (m_integerMin
== 0 && m_integerMax
== 0)
945 if (!view
->GetValueText())
947 wxString
value(view
->GetValueText()->GetValue());
950 if (!StringToLong(WXSTRINGCAST value
, &val
))
953 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), value
.GetData());
954 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
957 if (val
< m_integerMin
|| val
> m_integerMax
)
960 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
961 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
967 // Called when TICK is pressed or focus is lost or view wants to update
968 // the property list.
969 // Does the transferance from the property editing area to the property itself
970 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
972 if (!view
->GetValueText())
975 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
978 wxString
value(view
->GetValueText()->GetValue());
979 long val
= (long)wxAtoi(value
.GetData());
980 property
->GetValue() = (long)val
;
984 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
986 if (view
->GetConfirmButton())
987 view
->GetConfirmButton()->Enable(TRUE
);
988 if (view
->GetCancelButton())
989 view
->GetCancelButton()->Enable(TRUE
);
990 if (view
->GetEditButton())
991 view
->GetEditButton()->Enable(FALSE
);
992 if (view
->GetValueText())
993 view
->GetValueText()->Enable(TRUE
);
998 /// boolean validator
1000 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1002 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1004 if (!view
->GetValueText())
1006 wxString
value(view
->GetValueText()->GetValue());
1007 if (value
!= wxT("True") && value
!= wxT("False"))
1009 wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1015 // Called when TICK is pressed or focus is lost or view wants to update
1016 // the property list.
1017 // Does the transferance from the property editing area to the property itself
1018 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1020 if (!view
->GetValueText())
1023 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1026 wxString
value(view
->GetValueText()->GetValue());
1027 bool boolValue
= FALSE
;
1028 if (value
== wxT("True"))
1032 property
->GetValue() = (bool)boolValue
;
1036 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1038 if (!view
->GetValueText())
1040 wxString
str(property
->GetValue().GetStringRepresentation());
1042 view
->GetValueText()->SetValue(str
);
1044 if (view
->GetValueList()->IsShown())
1046 view
->GetValueList()->SetStringSelection(str
);
1051 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1053 if (view
->GetConfirmButton())
1054 view
->GetConfirmButton()->Enable(FALSE
);
1055 if (view
->GetCancelButton())
1056 view
->GetCancelButton()->Enable(FALSE
);
1057 if (view
->GetEditButton())
1058 view
->GetEditButton()->Enable(TRUE
);
1059 if (view
->GetValueText())
1060 view
->GetValueText()->Enable(FALSE
);
1064 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1066 if (view
->GetValueList())
1068 view
->ShowListBoxControl(TRUE
);
1069 view
->GetValueList()->Enable(TRUE
);
1071 view
->GetValueList()->Append(wxT("True"));
1072 view
->GetValueList()->Append(wxT("False"));
1073 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1074 view
->GetValueList()->SetStringSelection(currentString
);
1075 delete[] currentString
;
1080 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1082 if (view
->GetValueList())
1084 view
->GetValueList()->Clear();
1085 view
->ShowListBoxControl(FALSE
);
1086 view
->GetValueList()->Enable(FALSE
);
1091 // Called when the property is double clicked. Extra functionality can be provided,
1092 // cycling through possible values.
1093 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1095 if (!view
->GetValueText())
1097 if (property
->GetValue().BoolValue())
1098 property
->GetValue() = (bool)FALSE
;
1100 property
->GetValue() = (bool)TRUE
;
1101 view
->DisplayProperty(property
);
1102 view
->UpdatePropertyDisplayInList(property
);
1103 view
->OnPropertyChanged(property
);
1108 /// String validator
1110 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1112 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1113 wxPropertyListValidator(flags
)
1116 // If no constraint, we just allow the string to be edited.
1117 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1118 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1121 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1126 if (!view
->GetValueText())
1128 wxString
value(view
->GetValueText()->GetValue());
1130 if (!m_strings
->Member(value
.GetData()))
1132 wxString
str( wxT("Value ") );
1133 str
+= value
.GetData();
1134 str
+= wxT(" is not valid.");
1135 wxMessageBox( str
.GetData(), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1141 // Called when TICK is pressed or focus is lost or view wants to update
1142 // the property list.
1143 // Does the transferance from the property editing area to the property itself
1144 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1146 if (!view
->GetValueText())
1148 wxString
value(view
->GetValueText()->GetValue());
1149 property
->GetValue() = value
;
1153 // Called when TICK is pressed or focus is lost or view wants to update
1154 // the property list.
1155 // Does the transferance from the property editing area to the property itself
1156 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1158 if (!view
->GetValueText())
1160 wxString
str(property
->GetValue().GetStringRepresentation());
1161 view
->GetValueText()->SetValue(str
);
1162 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->GetCount() > 0)
1164 view
->GetValueList()->SetStringSelection(str
);
1169 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1174 if (view
->GetEditButton())
1175 view
->GetEditButton()->Enable(FALSE
);
1176 if (view
->GetConfirmButton())
1177 view
->GetConfirmButton()->Enable(TRUE
);
1178 if (view
->GetCancelButton())
1179 view
->GetCancelButton()->Enable(TRUE
);
1180 if (view
->GetValueText())
1181 view
->GetValueText()->Enable(TRUE
);
1186 if (view
->GetValueText())
1187 view
->GetValueText()->Enable(FALSE
);
1189 if (view
->GetEditButton())
1190 view
->GetEditButton()->Enable(TRUE
);
1192 if (view
->GetConfirmButton())
1193 view
->GetConfirmButton()->Enable(FALSE
);
1194 if (view
->GetCancelButton())
1195 view
->GetCancelButton()->Enable(FALSE
);
1199 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1201 if (view
->GetValueList())
1203 view
->ShowListBoxControl(TRUE
);
1204 view
->GetValueList()->Enable(TRUE
);
1205 wxNode
*node
= m_strings
->First();
1208 wxChar
*s
= (wxChar
*)node
->Data();
1209 view
->GetValueList()->Append(s
);
1210 node
= node
->Next();
1212 wxChar
*currentString
= property
->GetValue().StringValue();
1213 view
->GetValueList()->SetStringSelection(currentString
);
1218 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1225 if (view
->GetValueList())
1227 view
->GetValueList()->Clear();
1228 view
->ShowListBoxControl(FALSE
);
1229 view
->GetValueList()->Enable(FALSE
);
1234 // Called when the property is double clicked. Extra functionality can be provided,
1235 // cycling through possible values.
1236 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1238 if (!view
->GetValueText())
1243 wxNode
*node
= m_strings
->First();
1244 wxChar
*currentString
= property
->GetValue().StringValue();
1247 wxChar
*s
= (wxChar
*)node
->Data();
1248 if (wxStrcmp(s
, currentString
) == 0)
1250 wxChar
*nextString
= NULL
;
1252 nextString
= (wxChar
*)node
->Next()->Data();
1254 nextString
= (wxChar
*)m_strings
->First()->Data();
1255 property
->GetValue() = wxString(nextString
);
1256 view
->DisplayProperty(property
);
1257 view
->UpdatePropertyDisplayInList(property
);
1258 view
->OnPropertyChanged(property
);
1261 else node
= node
->Next();
1267 /// Filename validator
1269 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1271 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1272 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1276 wxFilenameListValidator::~wxFilenameListValidator()
1280 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1285 // Called when TICK is pressed or focus is lost or view wants to update
1286 // the property list.
1287 // Does the transferance from the property editing area to the property itself
1288 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1290 if (!view
->GetValueText())
1292 wxString
value(view
->GetValueText()->GetValue());
1293 property
->GetValue() = value
;
1297 // Called when TICK is pressed or focus is lost or view wants to update
1298 // the property list.
1299 // Does the transferance from the property editing area to the property itself
1300 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1302 if (!view
->GetValueText())
1304 wxString
str(property
->GetValue().GetStringRepresentation());
1305 view
->GetValueText()->SetValue(str
);
1309 // Called when the property is double clicked. Extra functionality can be provided,
1310 // cycling through possible values.
1311 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1313 if (!view
->GetValueText())
1315 OnEdit(property
, view
, parentWindow
);
1319 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1321 if (view
->GetConfirmButton())
1322 view
->GetConfirmButton()->Enable(TRUE
);
1323 if (view
->GetCancelButton())
1324 view
->GetCancelButton()->Enable(TRUE
);
1325 if (view
->GetEditButton())
1326 view
->GetEditButton()->Enable(TRUE
);
1327 if (view
->GetValueText())
1328 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1332 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1334 if (!view
->GetValueText())
1337 wxString s
= wxFileSelector(
1338 m_filenameMessage
.GetData(),
1339 wxPathOnly(property
->GetValue().StringValue()),
1340 wxFileNameFromPath(property
->GetValue().StringValue()),
1342 m_filenameWildCard
.GetData(),
1347 property
->GetValue() = s
;
1348 view
->DisplayProperty(property
);
1349 view
->UpdatePropertyDisplayInList(property
);
1350 view
->OnPropertyChanged(property
);
1355 /// Colour validator
1357 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1359 wxColourListValidator::wxColourListValidator(long flags
):
1360 wxPropertyListValidator(flags
)
1364 wxColourListValidator::~wxColourListValidator()
1368 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1373 // Called when TICK is pressed or focus is lost or view wants to update
1374 // the property list.
1375 // Does the transferance from the property editing area to the property itself
1376 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1378 if (!view
->GetValueText())
1380 wxString
value(view
->GetValueText()->GetValue());
1382 property
->GetValue() = value
;
1386 // Called when TICK is pressed or focus is lost or view wants to update
1387 // the property list.
1388 // Does the transferance from the property editing area to the property itself
1389 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1391 if (!view
->GetValueText())
1393 wxString
str(property
->GetValue().GetStringRepresentation());
1394 view
->GetValueText()->SetValue(str
);
1398 // Called when the property is double clicked. Extra functionality can be provided,
1399 // cycling through possible values.
1400 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1402 if (!view
->GetValueText())
1404 OnEdit(property
, view
, parentWindow
);
1408 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1410 if (view
->GetConfirmButton())
1411 view
->GetConfirmButton()->Enable(TRUE
);
1412 if (view
->GetCancelButton())
1413 view
->GetCancelButton()->Enable(TRUE
);
1414 if (view
->GetEditButton())
1415 view
->GetEditButton()->Enable(TRUE
);
1416 if (view
->GetValueText())
1417 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1421 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1423 if (!view
->GetValueText())
1426 wxChar
*s
= property
->GetValue().StringValue();
1433 g
= wxHexToDec(s
+2);
1434 b
= wxHexToDec(s
+4);
1437 wxColour
col(r
,g
,b
);
1440 data
.SetChooseFull(TRUE
);
1441 data
.SetColour(col
);
1443 for (int i
= 0; i
< 16; i
++)
1445 wxColour
colour(i
*16, i
*16, i
*16);
1446 data
.SetCustomColour(i
, colour
);
1449 wxColourDialog
dialog(parentWindow
, &data
);
1450 if (dialog
.ShowModal() != wxID_CANCEL
)
1452 wxColourData retData
= dialog
.GetColourData();
1453 col
= retData
.GetColour();
1456 wxDecToHex(col
.Red(), buf
);
1457 wxDecToHex(col
.Green(), buf
+2);
1458 wxDecToHex(col
.Blue(), buf
+4);
1460 property
->GetValue() = wxString(buf
);
1461 view
->DisplayProperty(property
);
1462 view
->UpdatePropertyDisplayInList(property
);
1463 view
->OnPropertyChanged(property
);
1468 /// List of strings validator. For this we need more user interface than
1469 /// we get with a property list; so create a new dialog for editing the list.
1471 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1473 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1474 wxPropertyListValidator(flags
)
1478 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1480 // No constraints for an arbitrary, user-editable list of strings.
1484 // Called when TICK is pressed or focus is lost or view wants to update
1485 // the property list.
1486 // Does the transferance from the property editing area to the property itself.
1487 // In this case, the user cannot directly edit the string list.
1488 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1493 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1495 if (!view
->GetValueText())
1497 wxString
str(property
->GetValue().GetStringRepresentation());
1498 view
->GetValueText()->SetValue(str
);
1502 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1504 if (view
->GetEditButton())
1505 view
->GetEditButton()->Enable(TRUE
);
1506 if (view
->GetValueText())
1507 view
->GetValueText()->Enable(FALSE
);
1509 if (view
->GetConfirmButton())
1510 view
->GetConfirmButton()->Enable(FALSE
);
1511 if (view
->GetCancelButton())
1512 view
->GetCancelButton()->Enable(FALSE
);
1516 // Called when the property is double clicked. Extra functionality can be provided,
1517 // cycling through possible values.
1518 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1520 OnEdit(property
, view
, parentWindow
);
1524 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1526 // Convert property value to a list of strings for editing
1527 wxStringList
*stringList
= new wxStringList
;
1529 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1532 wxChar
*s
= expr
->StringValue();
1535 expr
= expr
->GetNext();
1538 wxString
title(wxT("Editing "));
1539 title
+= property
->GetName();
1541 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1543 wxPropertyValue
& oldValue
= property
->GetValue();
1544 oldValue
.ClearList();
1545 wxNode
*node
= stringList
->First();
1548 wxChar
*s
= (wxChar
*)node
->Data();
1549 oldValue
.Append(new wxPropertyValue(s
));
1551 node
= node
->Next();
1554 view
->DisplayProperty(property
);
1555 view
->UpdatePropertyDisplayInList(property
);
1556 view
->OnPropertyChanged(property
);
1561 class wxPropertyStringListEditorDialog
: public wxDialog
1564 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1565 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1566 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= wxT("stringEditorDialogBox")):
1567 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1569 m_stringList
= NULL
;
1570 m_stringText
= NULL
;
1572 sm_dialogCancelled
= FALSE
;
1573 m_currentSelection
= -1;
1575 ~wxPropertyStringListEditorDialog(void) {}
1576 void OnCloseWindow(wxCloseEvent
& event
);
1577 void SaveCurrentSelection(void);
1578 void ShowCurrentSelection(void);
1580 void OnOK(wxCommandEvent
& event
);
1581 void OnCancel(wxCommandEvent
& event
);
1582 void OnAdd(wxCommandEvent
& event
);
1583 void OnDelete(wxCommandEvent
& event
);
1584 void OnStrings(wxCommandEvent
& event
);
1585 void OnText(wxCommandEvent
& event
);
1588 wxStringList
* m_stringList
;
1589 wxListBox
* m_listBox
;
1590 wxTextCtrl
* m_stringText
;
1591 static bool sm_dialogCancelled
;
1592 int m_currentSelection
;
1593 DECLARE_EVENT_TABLE()
1596 #define wxID_PROP_SL_ADD 3000
1597 #define wxID_PROP_SL_DELETE 3001
1598 #define wxID_PROP_SL_STRINGS 3002
1599 #define wxID_PROP_SL_TEXT 3003
1601 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1602 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1603 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1604 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1605 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1606 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1607 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1608 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1611 class wxPropertyStringListEditorText
: public wxTextCtrl
1614 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1615 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1616 long windowStyle
= 0, const wxString
& name
= wxT("text")):
1617 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1622 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1623 dialog
->SaveCurrentSelection();
1627 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1629 // Edit the string list.
1630 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1632 int largeButtonWidth
= 60;
1633 int largeButtonHeight
= 25;
1635 wxBeginBusyCursor();
1636 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1637 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1639 dialog
->m_stringList
= stringList
;
1641 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1642 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1644 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1645 wxID_PROP_SL_TEXT
, wxT(""), wxPoint(5, 240),
1646 wxSize(300, -1), wxPROCESS_ENTER
);
1647 dialog
->m_stringText
->Enable(FALSE
);
1649 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, wxT("Add"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1650 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, wxT("Delete"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1651 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, wxT("Cancel"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1652 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, wxT("OK"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1655 okButton
->SetDefault();
1658 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1660 c
->top
.SameAs (dialog
, wxTop
, 2);
1661 c
->left
.SameAs (dialog
, wxLeft
, 2);
1662 c
->right
.SameAs (dialog
, wxRight
, 2);
1663 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1664 dialog
->m_listBox
->SetConstraints(c
);
1666 c
= new wxLayoutConstraints
;
1667 c
->left
.SameAs (dialog
, wxLeft
, 2);
1668 c
->right
.SameAs (dialog
, wxRight
, 2);
1669 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1671 dialog
->m_stringText
->SetConstraints(c
);
1673 c
= new wxLayoutConstraints
;
1674 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1675 c
->left
.SameAs (dialog
, wxLeft
, 2);
1678 addButton
->SetConstraints(c
);
1680 c
= new wxLayoutConstraints
;
1681 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1682 c
->left
.SameAs (addButton
, wxRight
, 2);
1685 deleteButton
->SetConstraints(c
);
1687 c
= new wxLayoutConstraints
;
1688 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1689 c
->right
.SameAs (dialog
, wxRight
, 2);
1692 cancelButton
->SetConstraints(c
);
1694 c
= new wxLayoutConstraints
;
1695 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1696 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1699 okButton
->SetConstraints(c
);
1701 wxNode
*node
= stringList
->First();
1704 wxChar
*str
= (wxChar
*)node
->Data();
1705 // Save node as client data for each listbox item
1706 dialog
->m_listBox
->Append(str
, (wxChar
*)node
);
1707 node
= node
->Next();
1710 dialog
->SetClientSize(310, 305);
1713 dialog
->Centre(wxBOTH
);
1715 if (dialog
->ShowModal() == wxID_CANCEL
)
1722 * String list editor callbacks
1726 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1728 int sel
= m_listBox
->GetSelection();
1731 m_currentSelection
= sel
;
1733 ShowCurrentSelection();
1737 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1739 int sel
= m_listBox
->GetSelection();
1743 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1747 m_listBox
->Delete(sel
);
1748 delete[] (wxChar
*)node
->Data();
1750 m_currentSelection
= -1;
1751 m_stringText
->SetValue(_T(""));
1754 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1756 SaveCurrentSelection();
1758 wxString initialText
;
1759 wxNode
*node
= m_stringList
->Add(initialText
);
1760 m_listBox
->Append(initialText
, (void *)node
);
1761 m_currentSelection
= m_stringList
->Number() - 1;
1762 m_listBox
->SetSelection(m_currentSelection
);
1763 ShowCurrentSelection();
1764 m_stringText
->SetFocus();
1767 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1769 SaveCurrentSelection();
1775 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1777 sm_dialogCancelled
= TRUE
;
1778 EndModal(wxID_CANCEL
);
1783 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1785 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1787 SaveCurrentSelection();
1792 wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
1794 SaveCurrentSelection();
1799 void wxPropertyStringListEditorDialog::SaveCurrentSelection()
1801 if (m_currentSelection
== -1)
1804 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1808 wxString
txt(m_stringText
->GetValue());
1810 delete[] (wxChar
*)node
->Data();
1811 node
->SetData((wxObject
*)wxStrdup(txt
));
1813 m_listBox
->SetString(m_currentSelection
, (wxChar
*)node
->Data());
1816 void wxPropertyStringListEditorDialog::ShowCurrentSelection()
1818 if (m_currentSelection
== -1)
1820 m_stringText
->SetValue(wxT(""));
1823 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1824 wxChar
*txt
= (wxChar
*)node
->Data();
1825 m_stringText
->SetValue(txt
);
1826 m_stringText
->Enable(TRUE
);
1830 #endif // wxUSE_PROPSHEET