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
)
813 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
814 const wxString
& title
, const wxPoint
& pos
,
815 const wxSize
& size
, long style
, const wxString
& name
):
816 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
819 m_view
->AssociatePanel( ((wxPanel
*)this) );
820 m_view
->SetManagedWindow(this);
824 bool wxPropertyListDialog::OnClose(void)
828 SetReturnCode(wxID_CANCEL
);
837 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
839 SetReturnCode(wxID_CANCEL
);
843 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
846 if (item == m_view->GetPropertyScrollingList())
847 view->OnDoubleClick();
851 // Extend event processing to search the view's event table
852 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
854 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
855 return wxEvtHandler::ProcessEvent(event
);
864 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
866 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
867 EVT_SIZE(wxPropertyListPanel::OnSize
)
870 wxPropertyListPanel::~wxPropertyListPanel()
874 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
877 if (item == view->GetPropertyScrollingList())
878 view->OnDoubleClick();
882 // Extend event processing to search the view's event table
883 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
885 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
886 return wxEvtHandler::ProcessEvent(event
);
891 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
900 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
902 bool wxPropertyListFrame::OnClose(void)
907 m_propertyPanel
->SetView(NULL
);
916 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
918 return new wxPropertyListPanel(v
, parent
);
921 bool wxPropertyListFrame::Initialize(void)
923 m_propertyPanel
= OnCreatePanel(this, m_view
);
926 m_view
->AssociatePanel(m_propertyPanel
);
927 m_view
->SetManagedWindow(this);
928 m_propertyPanel
->SetAutoLayout(TRUE
);
936 * Property list specific validator
939 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
941 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
943 // view->GetValueText()->Show(TRUE);
945 OnDisplayValue(property
, view
, parentWindow
);
950 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
952 wxString
s(view
->GetValueList()->GetStringSelection());
955 view
->GetValueText()->SetValue(s
);
956 view
->RetrieveProperty(property
);
961 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
963 // view->GetValueText()->Show(TRUE);
964 wxString
str(property
->GetValue().GetStringRepresentation());
966 view
->GetValueText()->SetValue(str
);
970 // Called when TICK is pressed or focus is lost or view wants to update
971 // the property list.
972 // Does the transferance from the property editing area to the property itself
973 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
975 if (!view
->GetValueText())
980 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
982 if (view
->GetDetailedEditing())
983 view
->EndDetailedEditing();
985 view
->BeginDetailedEditing();
988 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
990 if (view
->GetConfirmButton())
991 view
->GetConfirmButton()->Enable(FALSE
);
992 if (view
->GetCancelButton())
993 view
->GetCancelButton()->Enable(FALSE
);
994 if (view
->GetEditButton())
995 view
->GetEditButton()->Enable(FALSE
);
1000 * Default validators
1003 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
1006 /// Real number validator
1008 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1010 if (m_realMin
== 0.0 && m_realMax
== 0.0)
1013 if (!view
->GetValueText())
1015 wxString
value(view
->GetValueText()->GetValue());
1018 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1021 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
1022 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1026 if (val
< m_realMin
|| val
> m_realMax
)
1029 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
1030 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1036 // Called when TICK is pressed or focus is lost or view wants to update
1037 // the property list.
1038 // Does the transferance from the property editing area to the property itself
1039 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1041 if (!view
->GetValueText())
1044 if (strlen(view
->GetValueText()->GetValue()) == 0)
1047 wxString
value(view
->GetValueText()->GetValue());
1048 float f
= (float)atof(value
.GetData());
1049 property
->GetValue() = f
;
1053 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1055 if (view
->GetConfirmButton())
1056 view
->GetConfirmButton()->Enable(TRUE
);
1057 if (view
->GetCancelButton())
1058 view
->GetCancelButton()->Enable(TRUE
);
1059 if (view
->GetEditButton())
1060 view
->GetEditButton()->Enable(FALSE
);
1061 if (view
->GetValueText())
1062 view
->GetValueText()->Enable(TRUE
);
1067 /// Integer validator
1069 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1071 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1073 if (m_integerMin
== 0 && m_integerMax
== 0)
1076 if (!view
->GetValueText())
1078 wxString
value(view
->GetValueText()->GetValue());
1081 if (!StringToLong(WXSTRINGCAST value
, &val
))
1084 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1085 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1088 if (val
< m_integerMin
|| val
> m_integerMax
)
1091 sprintf(buf
, "Value must be an integer between %ld and %ld!", m_integerMin
, m_integerMax
);
1092 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1098 // Called when TICK is pressed or focus is lost or view wants to update
1099 // the property list.
1100 // Does the transferance from the property editing area to the property itself
1101 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1103 if (!view
->GetValueText())
1106 if (strlen(view
->GetValueText()->GetValue()) == 0)
1109 wxString
value(view
->GetValueText()->GetValue());
1110 long val
= (long)atoi(value
.GetData());
1111 property
->GetValue() = (long)val
;
1115 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1117 if (view
->GetConfirmButton())
1118 view
->GetConfirmButton()->Enable(TRUE
);
1119 if (view
->GetCancelButton())
1120 view
->GetCancelButton()->Enable(TRUE
);
1121 if (view
->GetEditButton())
1122 view
->GetEditButton()->Enable(FALSE
);
1123 if (view
->GetValueText())
1124 view
->GetValueText()->Enable(TRUE
);
1129 /// boolean validator
1131 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1133 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1135 if (!view
->GetValueText())
1137 wxString
value(view
->GetValueText()->GetValue());
1138 if (value
!= "True" && value
!= "False")
1140 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1146 // Called when TICK is pressed or focus is lost or view wants to update
1147 // the property list.
1148 // Does the transferance from the property editing area to the property itself
1149 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1151 if (!view
->GetValueText())
1154 if (strlen(view
->GetValueText()->GetValue()) == 0)
1157 wxString
value(view
->GetValueText()->GetValue());
1158 bool boolValue
= FALSE
;
1159 if (value
== "True")
1163 property
->GetValue() = (bool)boolValue
;
1167 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1169 if (!view
->GetValueText())
1171 wxString
str(property
->GetValue().GetStringRepresentation());
1173 view
->GetValueText()->SetValue(str
);
1175 if (view
->GetValueList()->IsShown())
1177 view
->GetValueList()->SetStringSelection(str
);
1182 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1184 if (view
->GetConfirmButton())
1185 view
->GetConfirmButton()->Enable(FALSE
);
1186 if (view
->GetCancelButton())
1187 view
->GetCancelButton()->Enable(FALSE
);
1188 if (view
->GetEditButton())
1189 view
->GetEditButton()->Enable(TRUE
);
1190 if (view
->GetValueText())
1191 view
->GetValueText()->Enable(FALSE
);
1195 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1197 if (view
->GetValueList())
1199 view
->ShowListBoxControl(TRUE
);
1200 view
->GetValueList()->Enable(TRUE
);
1202 view
->GetValueList()->Append("True");
1203 view
->GetValueList()->Append("False");
1204 char *currentString
= copystring(view
->GetValueText()->GetValue());
1205 view
->GetValueList()->SetStringSelection(currentString
);
1206 delete[] currentString
;
1211 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1213 if (view
->GetValueList())
1215 view
->GetValueList()->Clear();
1216 view
->ShowListBoxControl(FALSE
);
1217 view
->GetValueList()->Enable(FALSE
);
1222 // Called when the property is double clicked. Extra functionality can be provided,
1223 // cycling through possible values.
1224 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1226 if (!view
->GetValueText())
1228 if (property
->GetValue().BoolValue())
1229 property
->GetValue() = (bool)FALSE
;
1231 property
->GetValue() = (bool)TRUE
;
1232 view
->DisplayProperty(property
);
1233 view
->UpdatePropertyDisplayInList(property
);
1234 view
->OnPropertyChanged(property
);
1239 /// String validator
1241 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1243 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1244 wxPropertyListValidator(flags
)
1247 // If no constraint, we just allow the string to be edited.
1248 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1249 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1252 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1257 if (!view
->GetValueText())
1259 wxString
value(view
->GetValueText()->GetValue());
1261 if (!m_strings
->Member(value
.GetData()))
1263 wxString
s("Value ");
1264 s
+= value
.GetData();
1265 s
+= " is not valid.";
1266 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1272 // Called when TICK is pressed or focus is lost or view wants to update
1273 // the property list.
1274 // Does the transferance from the property editing area to the property itself
1275 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1277 if (!view
->GetValueText())
1279 wxString
value(view
->GetValueText()->GetValue());
1280 property
->GetValue() = value
;
1284 // Called when TICK is pressed or focus is lost or view wants to update
1285 // the property list.
1286 // Does the transferance from the property editing area to the property itself
1287 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1289 if (!view
->GetValueText())
1291 wxString
str(property
->GetValue().GetStringRepresentation());
1292 view
->GetValueText()->SetValue(str
);
1293 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1295 view
->GetValueList()->SetStringSelection(str
);
1300 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1305 if (view
->GetEditButton())
1306 view
->GetEditButton()->Enable(FALSE
);
1307 if (view
->GetConfirmButton())
1308 view
->GetConfirmButton()->Enable(TRUE
);
1309 if (view
->GetCancelButton())
1310 view
->GetCancelButton()->Enable(TRUE
);
1311 if (view
->GetValueText())
1312 view
->GetValueText()->Enable(TRUE
);
1317 if (view
->GetValueText())
1318 view
->GetValueText()->Enable(FALSE
);
1320 if (view
->GetEditButton())
1321 view
->GetEditButton()->Enable(TRUE
);
1323 if (view
->GetConfirmButton())
1324 view
->GetConfirmButton()->Enable(FALSE
);
1325 if (view
->GetCancelButton())
1326 view
->GetCancelButton()->Enable(FALSE
);
1330 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1332 if (view
->GetValueList())
1334 view
->ShowListBoxControl(TRUE
);
1335 view
->GetValueList()->Enable(TRUE
);
1336 wxNode
*node
= m_strings
->First();
1339 char *s
= (char *)node
->Data();
1340 view
->GetValueList()->Append(s
);
1341 node
= node
->Next();
1343 char *currentString
= property
->GetValue().StringValue();
1344 view
->GetValueList()->SetStringSelection(currentString
);
1349 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1356 if (view
->GetValueList())
1358 view
->GetValueList()->Clear();
1359 view
->ShowListBoxControl(FALSE
);
1360 view
->GetValueList()->Enable(FALSE
);
1365 // Called when the property is double clicked. Extra functionality can be provided,
1366 // cycling through possible values.
1367 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1369 if (!view
->GetValueText())
1374 wxNode
*node
= m_strings
->First();
1375 char *currentString
= property
->GetValue().StringValue();
1378 char *s
= (char *)node
->Data();
1379 if (strcmp(s
, currentString
) == 0)
1381 char *nextString
= NULL
;
1383 nextString
= (char *)node
->Next()->Data();
1385 nextString
= (char *)m_strings
->First()->Data();
1386 property
->GetValue() = wxString(nextString
);
1387 view
->DisplayProperty(property
);
1388 view
->UpdatePropertyDisplayInList(property
);
1389 view
->OnPropertyChanged(property
);
1392 else node
= node
->Next();
1398 /// Filename validator
1400 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1402 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1403 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1407 wxFilenameListValidator::~wxFilenameListValidator(void)
1411 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1416 // Called when TICK is pressed or focus is lost or view wants to update
1417 // the property list.
1418 // Does the transferance from the property editing area to the property itself
1419 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1421 if (!view
->GetValueText())
1423 wxString
value(view
->GetValueText()->GetValue());
1424 property
->GetValue() = value
;
1428 // Called when TICK is pressed or focus is lost or view wants to update
1429 // the property list.
1430 // Does the transferance from the property editing area to the property itself
1431 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1433 if (!view
->GetValueText())
1435 wxString
str(property
->GetValue().GetStringRepresentation());
1436 view
->GetValueText()->SetValue(str
);
1440 // Called when the property is double clicked. Extra functionality can be provided,
1441 // cycling through possible values.
1442 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1444 if (!view
->GetValueText())
1446 OnEdit(property
, view
, parentWindow
);
1450 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1452 if (view
->GetConfirmButton())
1453 view
->GetConfirmButton()->Enable(TRUE
);
1454 if (view
->GetCancelButton())
1455 view
->GetCancelButton()->Enable(TRUE
);
1456 if (view
->GetEditButton())
1457 view
->GetEditButton()->Enable(TRUE
);
1458 if (view
->GetValueText())
1459 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1463 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1465 if (!view
->GetValueText())
1468 char *s
= wxFileSelector(
1469 m_filenameMessage
.GetData(),
1470 wxPathOnly(property
->GetValue().StringValue()),
1471 wxFileNameFromPath(property
->GetValue().StringValue()),
1473 m_filenameWildCard
.GetData(),
1478 property
->GetValue() = wxString(s
);
1479 view
->DisplayProperty(property
);
1480 view
->UpdatePropertyDisplayInList(property
);
1481 view
->OnPropertyChanged(property
);
1486 /// Colour validator
1488 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1490 wxColourListValidator::wxColourListValidator(long flags
):
1491 wxPropertyListValidator(flags
)
1495 wxColourListValidator::~wxColourListValidator(void)
1499 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1504 // Called when TICK is pressed or focus is lost or view wants to update
1505 // the property list.
1506 // Does the transferance from the property editing area to the property itself
1507 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1509 if (!view
->GetValueText())
1511 wxString
value(view
->GetValueText()->GetValue());
1513 property
->GetValue() = value
;
1517 // Called when TICK is pressed or focus is lost or view wants to update
1518 // the property list.
1519 // Does the transferance from the property editing area to the property itself
1520 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1522 if (!view
->GetValueText())
1524 wxString
str(property
->GetValue().GetStringRepresentation());
1525 view
->GetValueText()->SetValue(str
);
1529 // Called when the property is double clicked. Extra functionality can be provided,
1530 // cycling through possible values.
1531 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1533 if (!view
->GetValueText())
1535 OnEdit(property
, view
, parentWindow
);
1539 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1541 if (view
->GetConfirmButton())
1542 view
->GetConfirmButton()->Enable(TRUE
);
1543 if (view
->GetCancelButton())
1544 view
->GetCancelButton()->Enable(TRUE
);
1545 if (view
->GetEditButton())
1546 view
->GetEditButton()->Enable(TRUE
);
1547 if (view
->GetValueText())
1548 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1552 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1554 if (!view
->GetValueText())
1557 char *s
= property
->GetValue().StringValue();
1564 g
= wxHexToDec(s
+2);
1565 b
= wxHexToDec(s
+4);
1568 wxColour
col(r
,g
,b
);
1571 data
.SetChooseFull(TRUE
);
1572 data
.SetColour(col
);
1574 for (int i
= 0; i
< 16; i
++)
1576 wxColour
colour(i
*16, i
*16, i
*16);
1577 data
.SetCustomColour(i
, colour
);
1580 wxColourDialog
dialog(parentWindow
, &data
);
1581 if (dialog
.ShowModal() != wxID_CANCEL
)
1583 wxColourData retData
= dialog
.GetColourData();
1584 col
= retData
.GetColour();
1587 wxDecToHex(col
.Red(), buf
);
1588 wxDecToHex(col
.Green(), buf
+2);
1589 wxDecToHex(col
.Blue(), buf
+4);
1591 property
->GetValue() = wxString(buf
);
1592 view
->DisplayProperty(property
);
1593 view
->UpdatePropertyDisplayInList(property
);
1594 view
->OnPropertyChanged(property
);
1599 /// List of strings validator. For this we need more user interface than
1600 /// we get with a property list; so create a new dialog for editing the list.
1602 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1604 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1605 wxPropertyListValidator(flags
)
1609 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1611 // No constraints for an arbitrary, user-editable list of strings.
1615 // Called when TICK is pressed or focus is lost or view wants to update
1616 // the property list.
1617 // Does the transferance from the property editing area to the property itself.
1618 // In this case, the user cannot directly edit the string list.
1619 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1624 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1626 if (!view
->GetValueText())
1628 wxString
str(property
->GetValue().GetStringRepresentation());
1629 view
->GetValueText()->SetValue(str
);
1633 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1635 if (view
->GetEditButton())
1636 view
->GetEditButton()->Enable(TRUE
);
1637 if (view
->GetValueText())
1638 view
->GetValueText()->Enable(FALSE
);
1640 if (view
->GetConfirmButton())
1641 view
->GetConfirmButton()->Enable(FALSE
);
1642 if (view
->GetCancelButton())
1643 view
->GetCancelButton()->Enable(FALSE
);
1647 // Called when the property is double clicked. Extra functionality can be provided,
1648 // cycling through possible values.
1649 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1651 OnEdit(property
, view
, parentWindow
);
1655 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1657 // Convert property value to a list of strings for editing
1658 wxStringList
*stringList
= new wxStringList
;
1660 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1663 char *s
= expr
->StringValue();
1666 expr
= expr
->GetNext();
1669 wxString
title("Editing ");
1670 title
+= property
->GetName();
1672 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1674 wxPropertyValue
& oldValue
= property
->GetValue();
1675 oldValue
.ClearList();
1676 wxNode
*node
= stringList
->First();
1679 char *s
= (char *)node
->Data();
1680 oldValue
.Append(new wxPropertyValue(s
));
1682 node
= node
->Next();
1685 view
->DisplayProperty(property
);
1686 view
->UpdatePropertyDisplayInList(property
);
1687 view
->OnPropertyChanged(property
);
1692 class wxPropertyStringListEditorDialog
: public wxDialog
1695 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1696 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1697 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1698 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1700 m_stringList
= NULL
;
1701 m_stringText
= NULL
;
1703 sm_dialogCancelled
= FALSE
;
1704 m_currentSelection
= -1;
1706 ~wxPropertyStringListEditorDialog(void) {}
1708 void SaveCurrentSelection(void);
1709 void ShowCurrentSelection(void);
1711 void OnOK(wxCommandEvent
& event
);
1712 void OnCancel(wxCommandEvent
& event
);
1713 void OnAdd(wxCommandEvent
& event
);
1714 void OnDelete(wxCommandEvent
& event
);
1715 void OnStrings(wxCommandEvent
& event
);
1716 void OnText(wxCommandEvent
& event
);
1719 wxStringList
* m_stringList
;
1720 wxListBox
* m_listBox
;
1721 wxTextCtrl
* m_stringText
;
1722 static bool sm_dialogCancelled
;
1723 int m_currentSelection
;
1724 DECLARE_EVENT_TABLE()
1727 #define wxID_PROP_SL_ADD 3000
1728 #define wxID_PROP_SL_DELETE 3001
1729 #define wxID_PROP_SL_STRINGS 3002
1730 #define wxID_PROP_SL_TEXT 3003
1732 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1733 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1734 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1735 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1736 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1737 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1738 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1741 class wxPropertyStringListEditorText
: public wxTextCtrl
1744 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1745 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1746 long windowStyle
= 0, const wxString
& name
= "text"):
1747 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1750 void OnKillFocus(void)
1752 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1753 dialog
->SaveCurrentSelection();
1757 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1759 // Edit the string list.
1760 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1762 int largeButtonWidth
= 60;
1763 int largeButtonHeight
= 25;
1765 wxBeginBusyCursor();
1766 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1767 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1769 dialog
->m_stringList
= stringList
;
1771 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1772 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1774 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1775 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1776 wxSize(300, -1), wxPROCESS_ENTER
);
1777 dialog
->m_stringText
->Enable(FALSE
);
1779 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1780 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1781 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1782 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1784 okButton
->SetDefault();
1786 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1788 c
->top
.SameAs (dialog
, wxTop
, 2);
1789 c
->left
.SameAs (dialog
, wxLeft
, 2);
1790 c
->right
.SameAs (dialog
, wxRight
, 2);
1791 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1792 dialog
->m_listBox
->SetConstraints(c
);
1794 c
= new wxLayoutConstraints
;
1795 c
->left
.SameAs (dialog
, wxLeft
, 2);
1796 c
->right
.SameAs (dialog
, wxRight
, 2);
1797 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1799 dialog
->m_stringText
->SetConstraints(c
);
1801 c
= new wxLayoutConstraints
;
1802 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1803 c
->left
.SameAs (dialog
, wxLeft
, 2);
1806 addButton
->SetConstraints(c
);
1808 c
= new wxLayoutConstraints
;
1809 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1810 c
->left
.SameAs (addButton
, wxRight
, 2);
1813 deleteButton
->SetConstraints(c
);
1815 c
= new wxLayoutConstraints
;
1816 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1817 c
->right
.SameAs (dialog
, wxRight
, 2);
1820 cancelButton
->SetConstraints(c
);
1822 c
= new wxLayoutConstraints
;
1823 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1824 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1827 okButton
->SetConstraints(c
);
1829 wxNode
*node
= stringList
->First();
1832 char *str
= (char *)node
->Data();
1833 // Save node as client data for each listbox item
1834 dialog
->m_listBox
->Append(str
, (char *)node
);
1835 node
= node
->Next();
1838 dialog
->SetClientSize(310, 305);
1841 dialog
->Centre(wxBOTH
);
1843 if (dialog
->ShowModal() == wxID_CANCEL
)
1850 * String list editor callbacks
1854 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1856 int sel
= m_listBox
->GetSelection();
1859 m_currentSelection
= sel
;
1861 ShowCurrentSelection();
1865 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1867 int sel
= m_listBox
->GetSelection();
1871 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1875 m_listBox
->Delete(sel
);
1876 delete[] (char *)node
->Data();
1878 m_currentSelection
= -1;
1879 m_stringText
->SetValue("");
1882 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1884 SaveCurrentSelection();
1886 char *initialText
= "";
1887 wxNode
*node
= m_stringList
->Add(initialText
);
1888 m_listBox
->Append(initialText
, (char *)node
);
1889 m_currentSelection
= m_stringList
->Number() - 1;
1890 m_listBox
->SetSelection(m_currentSelection
);
1891 ShowCurrentSelection();
1892 m_stringText
->SetFocus();
1895 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1897 SaveCurrentSelection();
1902 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1904 sm_dialogCancelled
= TRUE
;
1905 EndModal(wxID_CANCEL
);
1909 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1911 if (event
.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND
)
1913 SaveCurrentSelection();
1917 bool wxPropertyStringListEditorDialog::OnClose(void)
1919 SaveCurrentSelection();
1923 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1925 if (m_currentSelection
== -1)
1928 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1932 wxString
txt(m_stringText
->GetValue());
1934 delete[] (char *)node
->Data();
1935 node
->SetData((wxObject
*)copystring(txt
));
1937 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1940 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1942 if (m_currentSelection
== -1)
1944 m_stringText
->SetValue("");
1947 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1948 char *txt
= (char *)node
->Data();
1949 m_stringText
->SetValue(txt
);
1950 m_stringText
->Enable(TRUE
);