1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "proplist.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
33 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
36 #include <strstream.h>
42 #include "wx/window.h"
45 #include "wx/colordlg.h"
46 #include "wx/proplist.h"
49 * Property text edit control
52 IMPLEMENT_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
54 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
55 const wxWindowID id
, const wxString
& value
,
56 const wxPoint
& pos
, const wxSize
& size
,
57 long style
, const wxString
& name
):
58 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
63 void wxPropertyTextEdit::OnSetFocus(void)
67 void wxPropertyTextEdit::OnKillFocus(void)
75 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
77 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
78 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
79 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
80 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
81 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
82 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
83 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
84 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
85 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
86 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxPropertyListView::OnPropertyDoubleClick
)
87 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
90 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
91 wxBitmap
*wxPropertyListView::sm_tickBitmap
= NULL
;
92 wxBitmap
*wxPropertyListView::sm_crossBitmap
= NULL
;
94 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
96 m_propertyScrollingList
= NULL
;
100 m_confirmButton
= NULL
;
101 m_cancelButton
= NULL
;
102 m_propertyWindow
= propPanel
;
103 m_managedWindow
= NULL
;
105 m_windowCloseButton
= NULL
;
106 m_windowCancelButton
= NULL
;
107 m_windowHelpButton
= NULL
;
109 m_detailedEditing
= FALSE
;
112 wxPropertyListView::~wxPropertyListView(void)
118 delete m_crossBitmap;
122 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
124 m_propertySheet
= ps
;
126 AssociatePanel(panel
);
129 UpdatePropertyList();
133 // Update this view of the viewed object, called e.g. by
134 // the object itself.
135 bool wxPropertyListView::OnUpdateView(void)
140 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
142 if (!m_propertyScrollingList
|| !m_propertySheet
)
145 m_propertyScrollingList
->Clear();
148 m_valueList
->Clear();
149 m_valueText
->SetValue("");
151 wxNode
*node
= m_propertySheet
->GetProperties().First();
153 // Should sort them... later...
156 wxProperty
*property
= (wxProperty
*)node
->Data();
157 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
158 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
160 m_propertyScrollingList
->Append(paddedString
.GetData(), (char *)property
);
166 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
168 if (!m_propertyScrollingList
|| !m_propertySheet
)
172 int currentlySelected
= m_propertyScrollingList
->GetSelection();
175 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
176 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
177 int sel
= FindListIndexForProperty(property
);
181 // Don't update the listbox unnecessarily because it can cause
184 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
185 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
188 // UpdatePropertyList(FALSE);
191 // TODO: why is this necessary?
193 if (currentlySelected
> -1)
194 m_propertyScrollingList
->SetSelection(currentlySelected
);
200 // Find the wxListBox index corresponding to this property
201 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
203 int n
= m_propertyScrollingList
->Number();
204 for (int i
= 0; i
< n
; i
++)
206 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
212 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
214 wxString
theString(name
);
217 int padWith
= nameWidth
- theString
.Length();
221 if (GetFlags() & wxPROP_SHOWVALUES
)
223 // Want to pad with spaces
224 theString
.Append(' ', padWith
);
231 // Select and show string representation in validator the given
232 // property. NULL resets to show no property.
233 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
235 if (m_currentProperty
)
237 EndShowingProperty(m_currentProperty
);
238 m_currentProperty
= NULL
;
241 m_valueList
->Clear();
242 m_valueText
->SetValue("");
246 m_currentProperty
= property
;
247 BeginShowingProperty(property
);
251 int sel
= FindListIndexForProperty(property
);
253 m_propertyScrollingList
->SetSelection(sel
);
258 // Find appropriate validator and load property into value controls
259 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
261 m_currentValidator
= FindPropertyValidator(property
);
262 if (!m_currentValidator
)
265 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
268 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
270 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
271 DisplayProperty(property
);
275 // Find appropriate validator and unload property from value controls
276 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
278 if (!m_currentValidator
)
281 RetrieveProperty(property
);
283 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
286 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
288 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
289 if (m_detailedEditing
)
291 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
292 m_detailedEditing
= FALSE
;
297 void wxPropertyListView::BeginDetailedEditing(void)
299 if (!m_currentValidator
)
301 if (!m_currentProperty
)
303 if (m_detailedEditing
)
305 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
307 if (!m_currentProperty
->IsEnabled())
310 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
312 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
313 m_detailedEditing
= TRUE
;
316 void wxPropertyListView::EndDetailedEditing(void)
318 if (!m_currentValidator
)
320 if (!m_currentProperty
)
323 RetrieveProperty(m_currentProperty
);
325 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
328 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
330 if (m_detailedEditing
)
332 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
333 m_detailedEditing
= FALSE
;
337 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
339 if (!m_currentValidator
)
342 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
343 m_valueText
->SetEditable(FALSE
);
345 m_valueText
->SetEditable(TRUE
);
347 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
350 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
352 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
356 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
358 if (!m_currentValidator
)
360 if (!property
->IsEnabled())
363 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
366 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
368 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
370 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
372 UpdatePropertyDisplayInList(property
);
373 OnPropertyChanged(property
);
378 // Revert to old value
379 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
385 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
390 // Called by the listbox callback
391 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
393 int sel
= m_propertyScrollingList
->GetSelection();
396 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
397 if (newSel
&& newSel
!= m_currentProperty
)
399 ShowProperty(newSel
, FALSE
);
404 bool wxPropertyListView::CreateControls(void)
406 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
408 int largeButtonWidth
= 60;
409 int largeButtonHeight
= 25;
411 int smallButtonWidth
= 25;
412 int smallButtonHeight
= 20;
414 // XView must be allowed to choose its own sized buttons
416 largeButtonWidth
= -1;
417 largeButtonHeight
= -1;
419 smallButtonWidth
= -1;
420 smallButtonHeight
= -1;
429 wxWindow
*leftMostWindow
= panel
;
431 wxWindow *topMostWindow = panel;
432 wxWindow *rightMostWindow = panel;
435 wxSystemSettings settings
;
436 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
439 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
441 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
444 // May need to be changed in future to eliminate clashes with app.
445 // WHAT WAS THIS FOR?
446 // panel->SetClientData((char *)this);
448 // These buttons are at the bottom of the window, but create them now
449 // so the constraints are evaluated in the correct order
450 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
452 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
453 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
454 m_windowCloseButton
->SetDefault();
455 m_windowCloseButton
->SetFocus();
457 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
459 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
460 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
462 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
464 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
465 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
467 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
469 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
470 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
473 if (m_windowCloseButton
)
475 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
477 c1
->left
.SameAs (panel
, wxLeft
, 2);
478 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
481 m_windowCloseButton
->SetConstraints(c1
);
482 leftMostWindow
= m_windowCloseButton
;
484 if (m_windowCancelButton
)
486 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
488 c2
->right
.SameAs (panel
, wxRight
, 2);
489 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
492 m_windowCancelButton
->SetConstraints(c2
);
493 leftMostWindow
= m_windowCancelButton
;
495 if (m_windowHelpButton
)
497 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
498 if (leftMostWindow
== panel
)
499 c2
->left
.SameAs (panel
, wxLeft
, 2);
501 c2
->left
.RightOf (leftMostWindow
, 2);
503 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
506 m_windowHelpButton
->SetConstraints(c2
);
507 leftMostWindow
= m_windowHelpButton
;
510 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
516 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
517 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
518 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
531 if (tickBitmap && crossBitmap)
533 m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
534 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
535 m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
536 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
541 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
542 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
543 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
544 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
547 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
548 c
->left
.SameAs (panel
, wxLeft
, 2);
550 if (windowCloseButton)
551 c->top.Below (m_windowCloseButton, 2);
554 c
->top
.SameAs (panel
, wxTop
, 2);
559 m_cancelButton
->SetConstraints(c
);
561 c
= new wxLayoutConstraints
;
562 c
->left
.RightOf (m_cancelButton
, 2);
563 c
->top
.SameAs (m_cancelButton
, wxTop
, 0);
567 m_confirmButton
->SetConstraints(c
);
569 m_cancelButton
->Enable(FALSE
);
570 m_confirmButton
->Enable(FALSE
);
573 if (m_buttonFlags
& wxPROP_PULLDOWN
)
575 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
576 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
577 m_editButton
->Enable(FALSE
);
578 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
581 if (m_windowCloseButton)
582 c->top.Below (m_windowCloseButton, 2);
585 c
->top
.SameAs (panel
, wxTop
, 2);
587 c
->right
.SameAs (panel
, wxRight
, 2);
590 m_editButton
->SetConstraints(c
);
593 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
594 m_valueText
->Enable(FALSE
);
596 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
599 c
->left
.RightOf (m_confirmButton
, 2);
601 c
->left
.SameAs (panel
, wxLeft
, 2);
603 if (m_windowCloseButton)
604 c->top.Below (m_windowCloseButton, 2);
607 c
->top
.SameAs (panel
, wxTop
, 2);
610 c
->right
.LeftOf (m_editButton
, 2);
612 c
->right
.SameAs (panel
, wxRight
, 2);
615 m_valueText
->SetConstraints(c
);
617 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
618 m_valueList
->Show(FALSE
);
620 c
= new wxLayoutConstraints
;
622 c
->left
.SameAs (panel
, wxLeft
, 2);
623 c
->top
.Below (m_valueText
, 2);
624 c
->right
.SameAs (panel
, wxRight
, 2);
625 c
->height
.Absolute(60);
627 m_valueList
->SetConstraints(c
);
629 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
630 wxPoint(-1, -1), wxSize(300, 300));
631 m_propertyScrollingList
->SetFont(* boringFont
);
633 c
= new wxLayoutConstraints
;
635 c
->left
.SameAs (panel
, wxLeft
, 2);
637 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
638 c
->top
.Below (m_valueText
, 2);
640 c
->top
.Below (m_valueList
, 2);
642 c
->right
.SameAs (panel
, wxRight
, 2);
644 if (m_windowCloseButton
)
645 c
->bottom
.Above (m_windowCloseButton
, -2);
647 c
->bottom
.SameAs (panel
, wxBottom
, 2);
649 m_propertyScrollingList
->SetConstraints(c
);
651 // Note: if this is called now, it causes a GPF.
658 void wxPropertyListView::ShowTextControl(bool show
)
661 m_valueText
->Show(show
);
664 void wxPropertyListView::ShowListBoxControl(bool show
)
668 m_valueList
->Show(show
);
669 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
671 wxLayoutConstraints
*constraints
= m_propertyScrollingList
->GetConstraints();
676 constraints
->top
.Below(m_valueList
, 2);
677 // Maintain back-pointer so when valueList is deleted,
678 // any reference to it from this window is removed.
679 m_valueList
->AddConstraintReference(m_propertyScrollingList
);
683 constraints
->top
.Below(m_valueText
, 2);
684 m_valueText
->AddConstraintReference(m_propertyScrollingList
);
686 m_propertyWindow
->Layout();
692 void wxPropertyListView::EnableCheck(bool show
)
695 m_confirmButton
->Enable(show
);
698 void wxPropertyListView::EnableCross(bool show
)
701 m_cancelButton
->Enable(show
);
704 bool wxPropertyListView::OnClose(void)
706 // Retrieve the value if any
707 wxCommandEvent event
;
714 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
716 if (m_currentProperty
&& m_currentValidator
)
718 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
721 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
723 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
727 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
729 // Retrieve the value if any
732 m_managedWindow
->Close(TRUE
);
735 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
737 // SetReturnCode(wxID_CANCEL);
738 m_managedWindow
->Close(TRUE
);
739 sm_dialogCancelled
= TRUE
;
742 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
746 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
748 if (m_currentProperty
)
750 RetrieveProperty(m_currentProperty
);
754 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
756 if (m_currentProperty
&& m_currentValidator
)
758 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
761 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
763 // Revert to old value
764 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
768 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
770 if (m_currentProperty
&& m_currentValidator
)
772 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
775 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
777 // Revert to old value
778 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
782 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
784 if (m_currentProperty
&& m_currentValidator
)
786 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
789 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
791 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
795 void wxPropertyListView::OnText(wxCommandEvent
& event
)
797 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
804 * Property dialog box
807 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
809 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
810 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
811 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
814 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
815 const wxString
& title
, const wxPoint
& pos
,
816 const wxSize
& size
, long style
, const wxString
& name
):
817 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
820 m_view
->AssociatePanel( ((wxPanel
*)this) );
821 m_view
->SetManagedWindow(this);
825 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
829 SetReturnCode(wxID_CANCEL
);
840 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
842 SetReturnCode(wxID_CANCEL
);
846 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
849 if (item == m_view->GetPropertyScrollingList())
850 view->OnDoubleClick();
854 // Extend event processing to search the view's event table
855 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
857 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
858 return wxEvtHandler::ProcessEvent(event
);
867 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
869 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
870 EVT_SIZE(wxPropertyListPanel::OnSize
)
873 wxPropertyListPanel::~wxPropertyListPanel()
877 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
880 if (item == view->GetPropertyScrollingList())
881 view->OnDoubleClick();
885 // Extend event processing to search the view's event table
886 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
888 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
889 return wxEvtHandler::ProcessEvent(event
);
894 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
903 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
905 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
906 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
909 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
914 m_propertyPanel
->SetView(NULL
);
925 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
927 return new wxPropertyListPanel(v
, parent
);
930 bool wxPropertyListFrame::Initialize(void)
932 m_propertyPanel
= OnCreatePanel(this, m_view
);
935 m_view
->AssociatePanel(m_propertyPanel
);
936 m_view
->SetManagedWindow(this);
937 m_propertyPanel
->SetAutoLayout(TRUE
);
945 * Property list specific validator
948 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
950 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
952 // view->GetValueText()->Show(TRUE);
954 OnDisplayValue(property
, view
, parentWindow
);
959 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
961 wxString
s(view
->GetValueList()->GetStringSelection());
964 view
->GetValueText()->SetValue(s
);
965 view
->RetrieveProperty(property
);
970 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
972 // view->GetValueText()->Show(TRUE);
973 wxString
str(property
->GetValue().GetStringRepresentation());
975 view
->GetValueText()->SetValue(str
);
979 // Called when TICK is pressed or focus is lost or view wants to update
980 // the property list.
981 // Does the transferance from the property editing area to the property itself
982 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
984 if (!view
->GetValueText())
989 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
991 if (view
->GetDetailedEditing())
992 view
->EndDetailedEditing();
994 view
->BeginDetailedEditing();
997 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
999 if (view
->GetConfirmButton())
1000 view
->GetConfirmButton()->Enable(FALSE
);
1001 if (view
->GetCancelButton())
1002 view
->GetCancelButton()->Enable(FALSE
);
1003 if (view
->GetEditButton())
1004 view
->GetEditButton()->Enable(FALSE
);
1009 * Default validators
1012 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
1015 /// Real number validator
1017 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1019 if (m_realMin
== 0.0 && m_realMax
== 0.0)
1022 if (!view
->GetValueText())
1024 wxString
value(view
->GetValueText()->GetValue());
1027 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1030 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
1031 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1035 if (val
< m_realMin
|| val
> m_realMax
)
1038 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
1039 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1045 // Called when TICK is pressed or focus is lost or view wants to update
1046 // the property list.
1047 // Does the transferance from the property editing area to the property itself
1048 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1050 if (!view
->GetValueText())
1053 if (strlen(view
->GetValueText()->GetValue()) == 0)
1056 wxString
value(view
->GetValueText()->GetValue());
1057 float f
= (float)atof(value
.GetData());
1058 property
->GetValue() = f
;
1062 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1064 if (view
->GetConfirmButton())
1065 view
->GetConfirmButton()->Enable(TRUE
);
1066 if (view
->GetCancelButton())
1067 view
->GetCancelButton()->Enable(TRUE
);
1068 if (view
->GetEditButton())
1069 view
->GetEditButton()->Enable(FALSE
);
1070 if (view
->GetValueText())
1071 view
->GetValueText()->Enable(TRUE
);
1076 /// Integer validator
1078 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1080 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1082 if (m_integerMin
== 0 && m_integerMax
== 0)
1085 if (!view
->GetValueText())
1087 wxString
value(view
->GetValueText()->GetValue());
1090 if (!StringToLong(WXSTRINGCAST value
, &val
))
1093 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1094 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1097 if (val
< m_integerMin
|| val
> m_integerMax
)
1100 sprintf(buf
, "Value must be an integer between %ld and %ld!", m_integerMin
, m_integerMax
);
1101 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1107 // Called when TICK is pressed or focus is lost or view wants to update
1108 // the property list.
1109 // Does the transferance from the property editing area to the property itself
1110 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1112 if (!view
->GetValueText())
1115 if (strlen(view
->GetValueText()->GetValue()) == 0)
1118 wxString
value(view
->GetValueText()->GetValue());
1119 long val
= (long)atoi(value
.GetData());
1120 property
->GetValue() = (long)val
;
1124 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1126 if (view
->GetConfirmButton())
1127 view
->GetConfirmButton()->Enable(TRUE
);
1128 if (view
->GetCancelButton())
1129 view
->GetCancelButton()->Enable(TRUE
);
1130 if (view
->GetEditButton())
1131 view
->GetEditButton()->Enable(FALSE
);
1132 if (view
->GetValueText())
1133 view
->GetValueText()->Enable(TRUE
);
1138 /// boolean validator
1140 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1142 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1144 if (!view
->GetValueText())
1146 wxString
value(view
->GetValueText()->GetValue());
1147 if (value
!= "True" && value
!= "False")
1149 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1155 // Called when TICK is pressed or focus is lost or view wants to update
1156 // the property list.
1157 // Does the transferance from the property editing area to the property itself
1158 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1160 if (!view
->GetValueText())
1163 if (strlen(view
->GetValueText()->GetValue()) == 0)
1166 wxString
value(view
->GetValueText()->GetValue());
1167 bool boolValue
= FALSE
;
1168 if (value
== "True")
1172 property
->GetValue() = (bool)boolValue
;
1176 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1178 if (!view
->GetValueText())
1180 wxString
str(property
->GetValue().GetStringRepresentation());
1182 view
->GetValueText()->SetValue(str
);
1184 if (view
->GetValueList()->IsShown())
1186 view
->GetValueList()->SetStringSelection(str
);
1191 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1193 if (view
->GetConfirmButton())
1194 view
->GetConfirmButton()->Enable(FALSE
);
1195 if (view
->GetCancelButton())
1196 view
->GetCancelButton()->Enable(FALSE
);
1197 if (view
->GetEditButton())
1198 view
->GetEditButton()->Enable(TRUE
);
1199 if (view
->GetValueText())
1200 view
->GetValueText()->Enable(FALSE
);
1204 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1206 if (view
->GetValueList())
1208 view
->ShowListBoxControl(TRUE
);
1209 view
->GetValueList()->Enable(TRUE
);
1211 view
->GetValueList()->Append("True");
1212 view
->GetValueList()->Append("False");
1213 char *currentString
= copystring(view
->GetValueText()->GetValue());
1214 view
->GetValueList()->SetStringSelection(currentString
);
1215 delete[] currentString
;
1220 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1222 if (view
->GetValueList())
1224 view
->GetValueList()->Clear();
1225 view
->ShowListBoxControl(FALSE
);
1226 view
->GetValueList()->Enable(FALSE
);
1231 // Called when the property is double clicked. Extra functionality can be provided,
1232 // cycling through possible values.
1233 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1235 if (!view
->GetValueText())
1237 if (property
->GetValue().BoolValue())
1238 property
->GetValue() = (bool)FALSE
;
1240 property
->GetValue() = (bool)TRUE
;
1241 view
->DisplayProperty(property
);
1242 view
->UpdatePropertyDisplayInList(property
);
1243 view
->OnPropertyChanged(property
);
1248 /// String validator
1250 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1252 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1253 wxPropertyListValidator(flags
)
1256 // If no constraint, we just allow the string to be edited.
1257 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1258 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1261 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1266 if (!view
->GetValueText())
1268 wxString
value(view
->GetValueText()->GetValue());
1270 if (!m_strings
->Member(value
.GetData()))
1272 wxString
s("Value ");
1273 s
+= value
.GetData();
1274 s
+= " is not valid.";
1275 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1281 // Called when TICK is pressed or focus is lost or view wants to update
1282 // the property list.
1283 // Does the transferance from the property editing area to the property itself
1284 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1286 if (!view
->GetValueText())
1288 wxString
value(view
->GetValueText()->GetValue());
1289 property
->GetValue() = value
;
1293 // Called when TICK is pressed or focus is lost or view wants to update
1294 // the property list.
1295 // Does the transferance from the property editing area to the property itself
1296 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1298 if (!view
->GetValueText())
1300 wxString
str(property
->GetValue().GetStringRepresentation());
1301 view
->GetValueText()->SetValue(str
);
1302 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1304 view
->GetValueList()->SetStringSelection(str
);
1309 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1314 if (view
->GetEditButton())
1315 view
->GetEditButton()->Enable(FALSE
);
1316 if (view
->GetConfirmButton())
1317 view
->GetConfirmButton()->Enable(TRUE
);
1318 if (view
->GetCancelButton())
1319 view
->GetCancelButton()->Enable(TRUE
);
1320 if (view
->GetValueText())
1321 view
->GetValueText()->Enable(TRUE
);
1326 if (view
->GetValueText())
1327 view
->GetValueText()->Enable(FALSE
);
1329 if (view
->GetEditButton())
1330 view
->GetEditButton()->Enable(TRUE
);
1332 if (view
->GetConfirmButton())
1333 view
->GetConfirmButton()->Enable(FALSE
);
1334 if (view
->GetCancelButton())
1335 view
->GetCancelButton()->Enable(FALSE
);
1339 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1341 if (view
->GetValueList())
1343 view
->ShowListBoxControl(TRUE
);
1344 view
->GetValueList()->Enable(TRUE
);
1345 wxNode
*node
= m_strings
->First();
1348 char *s
= (char *)node
->Data();
1349 view
->GetValueList()->Append(s
);
1350 node
= node
->Next();
1352 char *currentString
= property
->GetValue().StringValue();
1353 view
->GetValueList()->SetStringSelection(currentString
);
1358 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1365 if (view
->GetValueList())
1367 view
->GetValueList()->Clear();
1368 view
->ShowListBoxControl(FALSE
);
1369 view
->GetValueList()->Enable(FALSE
);
1374 // Called when the property is double clicked. Extra functionality can be provided,
1375 // cycling through possible values.
1376 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1378 if (!view
->GetValueText())
1383 wxNode
*node
= m_strings
->First();
1384 char *currentString
= property
->GetValue().StringValue();
1387 char *s
= (char *)node
->Data();
1388 if (strcmp(s
, currentString
) == 0)
1390 char *nextString
= NULL
;
1392 nextString
= (char *)node
->Next()->Data();
1394 nextString
= (char *)m_strings
->First()->Data();
1395 property
->GetValue() = wxString(nextString
);
1396 view
->DisplayProperty(property
);
1397 view
->UpdatePropertyDisplayInList(property
);
1398 view
->OnPropertyChanged(property
);
1401 else node
= node
->Next();
1407 /// Filename validator
1409 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1411 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1412 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1416 wxFilenameListValidator::~wxFilenameListValidator(void)
1420 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1425 // Called when TICK is pressed or focus is lost or view wants to update
1426 // the property list.
1427 // Does the transferance from the property editing area to the property itself
1428 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1430 if (!view
->GetValueText())
1432 wxString
value(view
->GetValueText()->GetValue());
1433 property
->GetValue() = value
;
1437 // Called when TICK is pressed or focus is lost or view wants to update
1438 // the property list.
1439 // Does the transferance from the property editing area to the property itself
1440 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1442 if (!view
->GetValueText())
1444 wxString
str(property
->GetValue().GetStringRepresentation());
1445 view
->GetValueText()->SetValue(str
);
1449 // Called when the property is double clicked. Extra functionality can be provided,
1450 // cycling through possible values.
1451 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1453 if (!view
->GetValueText())
1455 OnEdit(property
, view
, parentWindow
);
1459 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1461 if (view
->GetConfirmButton())
1462 view
->GetConfirmButton()->Enable(TRUE
);
1463 if (view
->GetCancelButton())
1464 view
->GetCancelButton()->Enable(TRUE
);
1465 if (view
->GetEditButton())
1466 view
->GetEditButton()->Enable(TRUE
);
1467 if (view
->GetValueText())
1468 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1472 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1474 if (!view
->GetValueText())
1477 wxString s
= wxFileSelector(
1478 m_filenameMessage
.GetData(),
1479 wxPathOnly(property
->GetValue().StringValue()),
1480 wxFileNameFromPath(property
->GetValue().StringValue()),
1482 m_filenameWildCard
.GetData(),
1487 property
->GetValue() = s
;
1488 view
->DisplayProperty(property
);
1489 view
->UpdatePropertyDisplayInList(property
);
1490 view
->OnPropertyChanged(property
);
1495 /// Colour validator
1497 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1499 wxColourListValidator::wxColourListValidator(long flags
):
1500 wxPropertyListValidator(flags
)
1504 wxColourListValidator::~wxColourListValidator(void)
1508 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1513 // Called when TICK is pressed or focus is lost or view wants to update
1514 // the property list.
1515 // Does the transferance from the property editing area to the property itself
1516 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1518 if (!view
->GetValueText())
1520 wxString
value(view
->GetValueText()->GetValue());
1522 property
->GetValue() = value
;
1526 // Called when TICK is pressed or focus is lost or view wants to update
1527 // the property list.
1528 // Does the transferance from the property editing area to the property itself
1529 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1531 if (!view
->GetValueText())
1533 wxString
str(property
->GetValue().GetStringRepresentation());
1534 view
->GetValueText()->SetValue(str
);
1538 // Called when the property is double clicked. Extra functionality can be provided,
1539 // cycling through possible values.
1540 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1542 if (!view
->GetValueText())
1544 OnEdit(property
, view
, parentWindow
);
1548 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1550 if (view
->GetConfirmButton())
1551 view
->GetConfirmButton()->Enable(TRUE
);
1552 if (view
->GetCancelButton())
1553 view
->GetCancelButton()->Enable(TRUE
);
1554 if (view
->GetEditButton())
1555 view
->GetEditButton()->Enable(TRUE
);
1556 if (view
->GetValueText())
1557 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1561 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1563 if (!view
->GetValueText())
1566 char *s
= property
->GetValue().StringValue();
1573 g
= wxHexToDec(s
+2);
1574 b
= wxHexToDec(s
+4);
1577 wxColour
col(r
,g
,b
);
1580 data
.SetChooseFull(TRUE
);
1581 data
.SetColour(col
);
1583 for (int i
= 0; i
< 16; i
++)
1585 wxColour
colour(i
*16, i
*16, i
*16);
1586 data
.SetCustomColour(i
, colour
);
1589 wxColourDialog
dialog(parentWindow
, &data
);
1590 if (dialog
.ShowModal() != wxID_CANCEL
)
1592 wxColourData retData
= dialog
.GetColourData();
1593 col
= retData
.GetColour();
1596 wxDecToHex(col
.Red(), buf
);
1597 wxDecToHex(col
.Green(), buf
+2);
1598 wxDecToHex(col
.Blue(), buf
+4);
1600 property
->GetValue() = wxString(buf
);
1601 view
->DisplayProperty(property
);
1602 view
->UpdatePropertyDisplayInList(property
);
1603 view
->OnPropertyChanged(property
);
1608 /// List of strings validator. For this we need more user interface than
1609 /// we get with a property list; so create a new dialog for editing the list.
1611 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1613 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1614 wxPropertyListValidator(flags
)
1618 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1620 // No constraints for an arbitrary, user-editable list of strings.
1624 // Called when TICK is pressed or focus is lost or view wants to update
1625 // the property list.
1626 // Does the transferance from the property editing area to the property itself.
1627 // In this case, the user cannot directly edit the string list.
1628 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1633 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1635 if (!view
->GetValueText())
1637 wxString
str(property
->GetValue().GetStringRepresentation());
1638 view
->GetValueText()->SetValue(str
);
1642 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1644 if (view
->GetEditButton())
1645 view
->GetEditButton()->Enable(TRUE
);
1646 if (view
->GetValueText())
1647 view
->GetValueText()->Enable(FALSE
);
1649 if (view
->GetConfirmButton())
1650 view
->GetConfirmButton()->Enable(FALSE
);
1651 if (view
->GetCancelButton())
1652 view
->GetCancelButton()->Enable(FALSE
);
1656 // Called when the property is double clicked. Extra functionality can be provided,
1657 // cycling through possible values.
1658 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1660 OnEdit(property
, view
, parentWindow
);
1664 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1666 // Convert property value to a list of strings for editing
1667 wxStringList
*stringList
= new wxStringList
;
1669 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1672 char *s
= expr
->StringValue();
1675 expr
= expr
->GetNext();
1678 wxString
title("Editing ");
1679 title
+= property
->GetName();
1681 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1683 wxPropertyValue
& oldValue
= property
->GetValue();
1684 oldValue
.ClearList();
1685 wxNode
*node
= stringList
->First();
1688 char *s
= (char *)node
->Data();
1689 oldValue
.Append(new wxPropertyValue(s
));
1691 node
= node
->Next();
1694 view
->DisplayProperty(property
);
1695 view
->UpdatePropertyDisplayInList(property
);
1696 view
->OnPropertyChanged(property
);
1701 class wxPropertyStringListEditorDialog
: public wxDialog
1704 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1705 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1706 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1707 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1709 m_stringList
= NULL
;
1710 m_stringText
= NULL
;
1712 sm_dialogCancelled
= FALSE
;
1713 m_currentSelection
= -1;
1715 ~wxPropertyStringListEditorDialog(void) {}
1716 void OnCloseWindow(wxCloseEvent
& event
);
1717 void SaveCurrentSelection(void);
1718 void ShowCurrentSelection(void);
1720 void OnOK(wxCommandEvent
& event
);
1721 void OnCancel(wxCommandEvent
& event
);
1722 void OnAdd(wxCommandEvent
& event
);
1723 void OnDelete(wxCommandEvent
& event
);
1724 void OnStrings(wxCommandEvent
& event
);
1725 void OnText(wxCommandEvent
& event
);
1728 wxStringList
* m_stringList
;
1729 wxListBox
* m_listBox
;
1730 wxTextCtrl
* m_stringText
;
1731 static bool sm_dialogCancelled
;
1732 int m_currentSelection
;
1733 DECLARE_EVENT_TABLE()
1736 #define wxID_PROP_SL_ADD 3000
1737 #define wxID_PROP_SL_DELETE 3001
1738 #define wxID_PROP_SL_STRINGS 3002
1739 #define wxID_PROP_SL_TEXT 3003
1741 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1742 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1743 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1744 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1745 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1746 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1747 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1748 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1751 class wxPropertyStringListEditorText
: public wxTextCtrl
1754 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1755 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1756 long windowStyle
= 0, const wxString
& name
= "text"):
1757 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1760 void OnKillFocus(void)
1762 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1763 dialog
->SaveCurrentSelection();
1767 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1769 // Edit the string list.
1770 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1772 int largeButtonWidth
= 60;
1773 int largeButtonHeight
= 25;
1775 wxBeginBusyCursor();
1776 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1777 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1779 dialog
->m_stringList
= stringList
;
1781 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1782 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1784 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1785 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1786 wxSize(300, -1), wxPROCESS_ENTER
);
1787 dialog
->m_stringText
->Enable(FALSE
);
1789 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1790 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1791 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1792 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1794 okButton
->SetDefault();
1796 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1798 c
->top
.SameAs (dialog
, wxTop
, 2);
1799 c
->left
.SameAs (dialog
, wxLeft
, 2);
1800 c
->right
.SameAs (dialog
, wxRight
, 2);
1801 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1802 dialog
->m_listBox
->SetConstraints(c
);
1804 c
= new wxLayoutConstraints
;
1805 c
->left
.SameAs (dialog
, wxLeft
, 2);
1806 c
->right
.SameAs (dialog
, wxRight
, 2);
1807 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1809 dialog
->m_stringText
->SetConstraints(c
);
1811 c
= new wxLayoutConstraints
;
1812 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1813 c
->left
.SameAs (dialog
, wxLeft
, 2);
1816 addButton
->SetConstraints(c
);
1818 c
= new wxLayoutConstraints
;
1819 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1820 c
->left
.SameAs (addButton
, wxRight
, 2);
1823 deleteButton
->SetConstraints(c
);
1825 c
= new wxLayoutConstraints
;
1826 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1827 c
->right
.SameAs (dialog
, wxRight
, 2);
1830 cancelButton
->SetConstraints(c
);
1832 c
= new wxLayoutConstraints
;
1833 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1834 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1837 okButton
->SetConstraints(c
);
1839 wxNode
*node
= stringList
->First();
1842 char *str
= (char *)node
->Data();
1843 // Save node as client data for each listbox item
1844 dialog
->m_listBox
->Append(str
, (char *)node
);
1845 node
= node
->Next();
1848 dialog
->SetClientSize(310, 305);
1851 dialog
->Centre(wxBOTH
);
1853 if (dialog
->ShowModal() == wxID_CANCEL
)
1860 * String list editor callbacks
1864 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1866 int sel
= m_listBox
->GetSelection();
1869 m_currentSelection
= sel
;
1871 ShowCurrentSelection();
1875 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1877 int sel
= m_listBox
->GetSelection();
1881 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1885 m_listBox
->Delete(sel
);
1886 delete[] (char *)node
->Data();
1888 m_currentSelection
= -1;
1889 m_stringText
->SetValue("");
1892 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1894 SaveCurrentSelection();
1896 char *initialText
= "";
1897 wxNode
*node
= m_stringList
->Add(initialText
);
1898 m_listBox
->Append(initialText
, (char *)node
);
1899 m_currentSelection
= m_stringList
->Number() - 1;
1900 m_listBox
->SetSelection(m_currentSelection
);
1901 ShowCurrentSelection();
1902 m_stringText
->SetFocus();
1905 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1907 SaveCurrentSelection();
1913 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1915 sm_dialogCancelled
= TRUE
;
1916 EndModal(wxID_CANCEL
);
1921 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1923 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1925 SaveCurrentSelection();
1929 void wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& event
)
1931 SaveCurrentSelection();
1935 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1937 if (m_currentSelection
== -1)
1940 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1944 wxString
txt(m_stringText
->GetValue());
1946 delete[] (char *)node
->Data();
1947 node
->SetData((wxObject
*)copystring(txt
));
1949 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1952 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1954 if (m_currentSelection
== -1)
1956 m_stringText
->SetValue("");
1959 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1960 char *txt
= (char *)node
->Data();
1961 m_stringText
->SetValue(txt
);
1962 m_stringText
->Enable(TRUE
);