1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
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"
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
)
171 int currentlySelected
= m_propertyScrollingList
->GetSelection();
173 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
174 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
175 int sel
= FindListIndexForProperty(property
);
179 // Don't update the listbox unnecessarily because it can cause
182 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
183 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
186 // UpdatePropertyList(FALSE);
189 // TODO: why is this necessary?
191 if (currentlySelected
> -1)
192 m_propertyScrollingList
->SetSelection(currentlySelected
);
198 // Find the wxListBox index corresponding to this property
199 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
201 int n
= m_propertyScrollingList
->Number();
202 for (int i
= 0; i
< n
; i
++)
204 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
210 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
212 wxString
theString(name
);
215 int padWith
= nameWidth
- theString
.Length();
219 if (GetFlags() & wxPROP_SHOWVALUES
)
221 // Want to pad with spaces
222 theString
.Append(' ', padWith
);
229 // Select and show string representation in validator the given
230 // property. NULL resets to show no property.
231 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
233 if (m_currentProperty
)
235 EndShowingProperty(m_currentProperty
);
236 m_currentProperty
= NULL
;
239 m_valueList
->Clear();
240 m_valueText
->SetValue("");
244 m_currentProperty
= property
;
245 BeginShowingProperty(property
);
249 int sel
= FindListIndexForProperty(property
);
251 m_propertyScrollingList
->SetSelection(sel
);
256 // Find appropriate validator and load property into value controls
257 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
259 m_currentValidator
= FindPropertyValidator(property
);
260 if (!m_currentValidator
)
263 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
266 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
268 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
269 DisplayProperty(property
);
273 // Find appropriate validator and unload property from value controls
274 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
276 if (!m_currentValidator
)
279 RetrieveProperty(property
);
281 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
284 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
286 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
287 if (m_detailedEditing
)
289 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
290 m_detailedEditing
= FALSE
;
295 void wxPropertyListView::BeginDetailedEditing(void)
297 if (!m_currentValidator
)
299 if (!m_currentProperty
)
301 if (m_detailedEditing
)
303 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
305 if (!m_currentProperty
->IsEnabled())
308 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
310 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
311 m_detailedEditing
= TRUE
;
314 void wxPropertyListView::EndDetailedEditing(void)
316 if (!m_currentValidator
)
318 if (!m_currentProperty
)
321 RetrieveProperty(m_currentProperty
);
323 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
326 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
328 if (m_detailedEditing
)
330 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
331 m_detailedEditing
= FALSE
;
335 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
337 if (!m_currentValidator
)
340 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
341 m_valueText
->SetEditable(FALSE
);
343 m_valueText
->SetEditable(TRUE
);
345 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
348 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
350 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
354 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
356 if (!m_currentValidator
)
358 if (!property
->IsEnabled())
361 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
364 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
366 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
368 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
370 UpdatePropertyDisplayInList(property
);
371 OnPropertyChanged(property
);
376 // Revert to old value
377 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
383 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
388 // Called by the listbox callback
389 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
391 int sel
= m_propertyScrollingList
->GetSelection();
394 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
395 if (newSel
&& newSel
!= m_currentProperty
)
397 ShowProperty(newSel
, FALSE
);
402 bool wxPropertyListView::CreateControls(void)
404 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
406 int largeButtonWidth
= 60;
407 int largeButtonHeight
= 25;
409 int smallButtonWidth
= 25;
410 int smallButtonHeight
= 20;
412 // XView must be allowed to choose its own sized buttons
414 largeButtonWidth
= -1;
415 largeButtonHeight
= -1;
417 smallButtonWidth
= -1;
418 smallButtonHeight
= -1;
427 wxWindow
*leftMostWindow
= panel
;
428 wxWindow
*topMostWindow
= panel
;
429 wxWindow
*rightMostWindow
= panel
;
431 wxSystemSettings settings
;
432 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
435 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
437 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
440 // May need to be changed in future to eliminate clashes with app.
441 // WHAT WAS THIS FOR?
442 // panel->SetClientData((char *)this);
444 // These buttons are at the bottom of the window, but create them now
445 // so the constraints are evaluated in the correct order
446 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
448 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
449 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
450 m_windowCloseButton
->SetDefault();
451 m_windowCloseButton
->SetFocus();
453 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
455 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
456 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
458 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
460 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
461 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
463 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
465 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
466 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
469 if (m_windowCloseButton
)
471 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
473 c1
->left
.SameAs (panel
, wxLeft
, 2);
474 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
477 m_windowCloseButton
->SetConstraints(c1
);
478 leftMostWindow
= m_windowCloseButton
;
480 if (m_windowCancelButton
)
482 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
484 c2
->right
.SameAs (panel
, wxRight
, 2);
485 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
488 m_windowCancelButton
->SetConstraints(c2
);
489 leftMostWindow
= m_windowCancelButton
;
491 if (m_windowHelpButton
)
493 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
494 if (leftMostWindow
== panel
)
495 c2
->left
.SameAs (panel
, wxLeft
, 2);
497 c2
->left
.RightOf (leftMostWindow
, 2);
499 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
502 m_windowHelpButton
->SetConstraints(c2
);
503 leftMostWindow
= m_windowHelpButton
;
506 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
512 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
513 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
514 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
527 if (tickBitmap && crossBitmap)
529 m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
530 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
531 m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
532 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
537 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
538 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
539 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
540 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
543 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
544 c
->left
.SameAs (panel
, wxLeft
, 2);
546 if (windowCloseButton)
547 c->top.Below (m_windowCloseButton, 2);
550 c
->top
.SameAs (panel
, wxTop
, 2);
555 m_cancelButton
->SetConstraints(c
);
557 c
= new wxLayoutConstraints
;
558 c
->left
.RightOf (m_cancelButton
, 2);
559 c
->top
.SameAs (m_cancelButton
, wxTop
, 0);
563 m_confirmButton
->SetConstraints(c
);
565 m_cancelButton
->Enable(FALSE
);
566 m_confirmButton
->Enable(FALSE
);
569 if (m_buttonFlags
& wxPROP_PULLDOWN
)
571 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
572 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
573 m_editButton
->Enable(FALSE
);
574 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
577 if (m_windowCloseButton)
578 c->top.Below (m_windowCloseButton, 2);
581 c
->top
.SameAs (panel
, wxTop
, 2);
583 c
->right
.SameAs (panel
, wxRight
, 2);
586 m_editButton
->SetConstraints(c
);
589 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
590 m_valueText
->Enable(FALSE
);
592 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
595 c
->left
.RightOf (m_confirmButton
, 2);
597 c
->left
.SameAs (panel
, wxLeft
, 2);
599 if (m_windowCloseButton)
600 c->top.Below (m_windowCloseButton, 2);
603 c
->top
.SameAs (panel
, wxTop
, 2);
606 c
->right
.LeftOf (m_editButton
, 2);
608 c
->right
.SameAs (panel
, wxRight
, 2);
611 m_valueText
->SetConstraints(c
);
613 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
614 m_valueList
->Show(FALSE
);
616 c
= new wxLayoutConstraints
;
618 c
->left
.SameAs (panel
, wxLeft
, 2);
619 c
->top
.Below (m_valueText
, 2);
620 c
->right
.SameAs (panel
, wxRight
, 2);
621 c
->height
.Absolute(60);
623 m_valueList
->SetConstraints(c
);
625 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
626 wxPoint(-1, -1), wxSize(300, 300));
627 m_propertyScrollingList
->SetFont(* boringFont
);
629 c
= new wxLayoutConstraints
;
631 c
->left
.SameAs (panel
, wxLeft
, 2);
633 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
634 c
->top
.Below (m_valueText
, 2);
636 c
->top
.Below (m_valueList
, 2);
638 c
->right
.SameAs (panel
, wxRight
, 2);
640 if (m_windowCloseButton
)
641 c
->bottom
.Above (m_windowCloseButton
, -2);
643 c
->bottom
.SameAs (panel
, wxBottom
, 2);
645 m_propertyScrollingList
->SetConstraints(c
);
647 // Note: if this is called now, it causes a GPF.
654 void wxPropertyListView::ShowTextControl(bool show
)
657 m_valueText
->Show(show
);
660 void wxPropertyListView::ShowListBoxControl(bool show
)
664 m_valueList
->Show(show
);
665 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
667 wxLayoutConstraints
*constraints
= m_propertyScrollingList
->GetConstraints();
672 constraints
->top
.Below(m_valueList
, 2);
673 // Maintain back-pointer so when valueList is deleted,
674 // any reference to it from this window is removed.
675 m_valueList
->AddConstraintReference(m_propertyScrollingList
);
679 constraints
->top
.Below(m_valueText
, 2);
680 m_valueText
->AddConstraintReference(m_propertyScrollingList
);
682 m_propertyWindow
->Layout();
688 void wxPropertyListView::EnableCheck(bool show
)
691 m_confirmButton
->Enable(show
);
694 void wxPropertyListView::EnableCross(bool show
)
697 m_cancelButton
->Enable(show
);
700 bool wxPropertyListView::OnClose(void)
702 // Retrieve the value if any
703 wxCommandEvent event
;
710 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
712 if (m_currentProperty
&& m_currentValidator
)
714 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
717 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
719 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
723 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
725 // Retrieve the value if any
728 m_managedWindow
->Close(TRUE
);
731 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
733 // SetReturnCode(wxID_CANCEL);
734 m_managedWindow
->Close(TRUE
);
735 sm_dialogCancelled
= TRUE
;
738 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
742 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
744 if (m_currentProperty
)
746 RetrieveProperty(m_currentProperty
);
750 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
752 if (m_currentProperty
&& m_currentValidator
)
754 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
757 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
759 // Revert to old value
760 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
764 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
766 if (m_currentProperty
&& m_currentValidator
)
768 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
771 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
773 // Revert to old value
774 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
778 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
780 if (m_currentProperty
&& m_currentValidator
)
782 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
785 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
787 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
791 void wxPropertyListView::OnText(wxCommandEvent
& event
)
793 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
800 * Property dialog box
803 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
805 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
806 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
809 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
810 const wxString
& title
, const wxPoint
& pos
,
811 const wxSize
& size
, long style
, const wxString
& name
):
812 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
815 m_view
->AssociatePanel( ((wxPanel
*)this) );
816 m_view
->SetManagedWindow(this);
820 bool wxPropertyListDialog::OnClose(void)
824 SetReturnCode(wxID_CANCEL
);
833 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
835 SetReturnCode(wxID_CANCEL
);
839 void wxPropertyListDialog::OnDefaultAction(wxControl
*item
)
842 if (item == m_view->GetPropertyScrollingList())
843 view->OnDoubleClick();
847 // Extend event processing to search the view's event table
848 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
850 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
851 return wxEvtHandler::ProcessEvent(event
);
860 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
862 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
863 EVT_SIZE(wxPropertyListPanel::OnSize
)
866 wxPropertyListPanel::~wxPropertyListPanel()
870 void wxPropertyListPanel::OnDefaultAction(wxControl
*item
)
873 if (item == view->GetPropertyScrollingList())
874 view->OnDoubleClick();
878 // Extend event processing to search the view's event table
879 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
881 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
882 return wxEvtHandler::ProcessEvent(event
);
887 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
896 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
898 bool wxPropertyListFrame::OnClose(void)
903 m_propertyPanel
->SetView(NULL
);
912 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
914 return new wxPropertyListPanel(v
, parent
);
917 bool wxPropertyListFrame::Initialize(void)
919 m_propertyPanel
= OnCreatePanel(this, m_view
);
922 m_view
->AssociatePanel(m_propertyPanel
);
923 m_view
->SetManagedWindow(this);
924 m_propertyPanel
->SetAutoLayout(TRUE
);
932 * Property list specific validator
935 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
937 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
939 // view->GetValueText()->Show(TRUE);
941 OnDisplayValue(property
, view
, parentWindow
);
946 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
948 wxString
s(view
->GetValueList()->GetStringSelection());
951 view
->GetValueText()->SetValue(s
);
952 view
->RetrieveProperty(property
);
957 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
959 // view->GetValueText()->Show(TRUE);
960 wxString
str(property
->GetValue().GetStringRepresentation());
962 view
->GetValueText()->SetValue(str
);
966 // Called when TICK is pressed or focus is lost or view wants to update
967 // the property list.
968 // Does the transferance from the property editing area to the property itself
969 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
971 if (!view
->GetValueText())
976 void wxPropertyListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
978 if (view
->GetDetailedEditing())
979 view
->EndDetailedEditing();
981 view
->BeginDetailedEditing();
984 bool wxPropertyListValidator::OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
986 if (view
->GetConfirmButton())
987 view
->GetConfirmButton()->Enable(FALSE
);
988 if (view
->GetCancelButton())
989 view
->GetCancelButton()->Enable(FALSE
);
990 if (view
->GetEditButton())
991 view
->GetEditButton()->Enable(FALSE
);
999 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
1002 /// Real number validator
1004 bool wxRealListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1006 if (m_realMin
== 0.0 && m_realMax
== 0.0)
1009 if (!view
->GetValueText())
1011 wxString
value(view
->GetValueText()->GetValue());
1014 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1017 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
1018 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1022 if (val
< m_realMin
|| val
> m_realMax
)
1025 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
1026 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1032 // Called when TICK is pressed or focus is lost or view wants to update
1033 // the property list.
1034 // Does the transferance from the property editing area to the property itself
1035 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1037 if (!view
->GetValueText())
1040 if (strlen(view
->GetValueText()->GetValue()) == 0)
1043 wxString
value(view
->GetValueText()->GetValue());
1044 float f
= (float)atof(value
.GetData());
1045 property
->GetValue() = f
;
1049 bool wxRealListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1051 if (view
->GetConfirmButton())
1052 view
->GetConfirmButton()->Enable(TRUE
);
1053 if (view
->GetCancelButton())
1054 view
->GetCancelButton()->Enable(TRUE
);
1055 if (view
->GetEditButton())
1056 view
->GetEditButton()->Enable(FALSE
);
1057 if (view
->GetValueText())
1058 view
->GetValueText()->Enable(TRUE
);
1063 /// Integer validator
1065 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1067 bool wxIntegerListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1069 if (m_integerMin
== 0 && m_integerMax
== 0)
1072 if (!view
->GetValueText())
1074 wxString
value(view
->GetValueText()->GetValue());
1077 if (!StringToLong(WXSTRINGCAST value
, &val
))
1080 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1081 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1084 if (val
< m_integerMin
|| val
> m_integerMax
)
1087 sprintf(buf
, "Value must be an integer between %ld and %ld!", m_integerMin
, m_integerMax
);
1088 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1094 // Called when TICK is pressed or focus is lost or view wants to update
1095 // the property list.
1096 // Does the transferance from the property editing area to the property itself
1097 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1099 if (!view
->GetValueText())
1102 if (strlen(view
->GetValueText()->GetValue()) == 0)
1105 wxString
value(view
->GetValueText()->GetValue());
1106 long val
= (long)atoi(value
.GetData());
1107 property
->GetValue() = (long)val
;
1111 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1113 if (view
->GetConfirmButton())
1114 view
->GetConfirmButton()->Enable(TRUE
);
1115 if (view
->GetCancelButton())
1116 view
->GetCancelButton()->Enable(TRUE
);
1117 if (view
->GetEditButton())
1118 view
->GetEditButton()->Enable(FALSE
);
1119 if (view
->GetValueText())
1120 view
->GetValueText()->Enable(TRUE
);
1125 /// boolean validator
1127 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1129 bool wxBoolListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1131 if (!view
->GetValueText())
1133 wxString
value(view
->GetValueText()->GetValue());
1134 if (value
!= "True" && value
!= "False")
1136 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1142 // Called when TICK is pressed or focus is lost or view wants to update
1143 // the property list.
1144 // Does the transferance from the property editing area to the property itself
1145 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1147 if (!view
->GetValueText())
1150 if (strlen(view
->GetValueText()->GetValue()) == 0)
1153 wxString
value(view
->GetValueText()->GetValue());
1154 bool boolValue
= FALSE
;
1155 if (value
== "True")
1159 property
->GetValue() = (bool)boolValue
;
1163 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1165 if (!view
->GetValueText())
1167 wxString
str(property
->GetValue().GetStringRepresentation());
1169 view
->GetValueText()->SetValue(str
);
1171 if (view
->GetValueList()->IsShown())
1173 view
->GetValueList()->SetStringSelection(str
);
1178 bool wxBoolListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1180 if (view
->GetConfirmButton())
1181 view
->GetConfirmButton()->Enable(FALSE
);
1182 if (view
->GetCancelButton())
1183 view
->GetCancelButton()->Enable(FALSE
);
1184 if (view
->GetEditButton())
1185 view
->GetEditButton()->Enable(TRUE
);
1186 if (view
->GetValueText())
1187 view
->GetValueText()->Enable(FALSE
);
1191 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1193 if (view
->GetValueList())
1195 view
->ShowListBoxControl(TRUE
);
1196 view
->GetValueList()->Enable(TRUE
);
1198 view
->GetValueList()->Append("True");
1199 view
->GetValueList()->Append("False");
1200 char *currentString
= copystring(view
->GetValueText()->GetValue());
1201 view
->GetValueList()->SetStringSelection(currentString
);
1202 delete[] currentString
;
1207 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1209 if (view
->GetValueList())
1211 view
->GetValueList()->Clear();
1212 view
->ShowListBoxControl(FALSE
);
1213 view
->GetValueList()->Enable(FALSE
);
1218 // Called when the property is double clicked. Extra functionality can be provided,
1219 // cycling through possible values.
1220 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1222 if (!view
->GetValueText())
1224 if (property
->GetValue().BoolValue())
1225 property
->GetValue() = (bool)FALSE
;
1227 property
->GetValue() = (bool)TRUE
;
1228 view
->DisplayProperty(property
);
1229 view
->UpdatePropertyDisplayInList(property
);
1230 view
->OnPropertyChanged(property
);
1235 /// String validator
1237 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1239 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1240 wxPropertyListValidator(flags
)
1243 // If no constraint, we just allow the string to be edited.
1244 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1245 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1248 bool wxStringListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1253 if (!view
->GetValueText())
1255 wxString
value(view
->GetValueText()->GetValue());
1257 if (!m_strings
->Member(value
.GetData()))
1259 wxString
s("Value ");
1260 s
+= value
.GetData();
1261 s
+= " is not valid.";
1262 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1268 // Called when TICK is pressed or focus is lost or view wants to update
1269 // the property list.
1270 // Does the transferance from the property editing area to the property itself
1271 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1273 if (!view
->GetValueText())
1275 wxString
value(view
->GetValueText()->GetValue());
1276 property
->GetValue() = value
;
1280 // Called when TICK is pressed or focus is lost or view wants to update
1281 // the property list.
1282 // Does the transferance from the property editing area to the property itself
1283 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1285 if (!view
->GetValueText())
1287 wxString
str(property
->GetValue().GetStringRepresentation());
1288 view
->GetValueText()->SetValue(str
);
1289 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1291 view
->GetValueList()->SetStringSelection(str
);
1296 bool wxStringListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1301 if (view
->GetEditButton())
1302 view
->GetEditButton()->Enable(FALSE
);
1303 if (view
->GetConfirmButton())
1304 view
->GetConfirmButton()->Enable(TRUE
);
1305 if (view
->GetCancelButton())
1306 view
->GetCancelButton()->Enable(TRUE
);
1307 if (view
->GetValueText())
1308 view
->GetValueText()->Enable(TRUE
);
1313 if (view
->GetValueText())
1314 view
->GetValueText()->Enable(FALSE
);
1316 if (view
->GetEditButton())
1317 view
->GetEditButton()->Enable(TRUE
);
1319 if (view
->GetConfirmButton())
1320 view
->GetConfirmButton()->Enable(FALSE
);
1321 if (view
->GetCancelButton())
1322 view
->GetCancelButton()->Enable(FALSE
);
1326 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1328 if (view
->GetValueList())
1330 view
->ShowListBoxControl(TRUE
);
1331 view
->GetValueList()->Enable(TRUE
);
1332 wxNode
*node
= m_strings
->First();
1335 char *s
= (char *)node
->Data();
1336 view
->GetValueList()->Append(s
);
1337 node
= node
->Next();
1339 char *currentString
= property
->GetValue().StringValue();
1340 view
->GetValueList()->SetStringSelection(currentString
);
1345 bool wxStringListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1352 if (view
->GetValueList())
1354 view
->GetValueList()->Clear();
1355 view
->ShowListBoxControl(FALSE
);
1356 view
->GetValueList()->Enable(FALSE
);
1361 // Called when the property is double clicked. Extra functionality can be provided,
1362 // cycling through possible values.
1363 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1365 if (!view
->GetValueText())
1370 wxNode
*node
= m_strings
->First();
1371 char *currentString
= property
->GetValue().StringValue();
1374 char *s
= (char *)node
->Data();
1375 if (strcmp(s
, currentString
) == 0)
1377 char *nextString
= NULL
;
1379 nextString
= (char *)node
->Next()->Data();
1381 nextString
= (char *)m_strings
->First()->Data();
1382 property
->GetValue() = wxString(nextString
);
1383 view
->DisplayProperty(property
);
1384 view
->UpdatePropertyDisplayInList(property
);
1385 view
->OnPropertyChanged(property
);
1388 else node
= node
->Next();
1394 /// Filename validator
1396 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1398 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1399 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1403 wxFilenameListValidator::~wxFilenameListValidator(void)
1407 bool wxFilenameListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1412 // Called when TICK is pressed or focus is lost or view wants to update
1413 // the property list.
1414 // Does the transferance from the property editing area to the property itself
1415 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1417 if (!view
->GetValueText())
1419 wxString
value(view
->GetValueText()->GetValue());
1420 property
->GetValue() = value
;
1424 // Called when TICK is pressed or focus is lost or view wants to update
1425 // the property list.
1426 // Does the transferance from the property editing area to the property itself
1427 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1429 if (!view
->GetValueText())
1431 wxString
str(property
->GetValue().GetStringRepresentation());
1432 view
->GetValueText()->SetValue(str
);
1436 // Called when the property is double clicked. Extra functionality can be provided,
1437 // cycling through possible values.
1438 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1440 if (!view
->GetValueText())
1442 OnEdit(property
, view
, parentWindow
);
1446 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1448 if (view
->GetConfirmButton())
1449 view
->GetConfirmButton()->Enable(TRUE
);
1450 if (view
->GetCancelButton())
1451 view
->GetCancelButton()->Enable(TRUE
);
1452 if (view
->GetEditButton())
1453 view
->GetEditButton()->Enable(TRUE
);
1454 if (view
->GetValueText())
1455 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1459 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1461 if (!view
->GetValueText())
1464 char *s
= wxFileSelector(
1465 m_filenameMessage
.GetData(),
1466 wxPathOnly(property
->GetValue().StringValue()),
1467 wxFileNameFromPath(property
->GetValue().StringValue()),
1469 m_filenameWildCard
.GetData(),
1474 property
->GetValue() = wxString(s
);
1475 view
->DisplayProperty(property
);
1476 view
->UpdatePropertyDisplayInList(property
);
1477 view
->OnPropertyChanged(property
);
1482 /// Colour validator
1484 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1486 wxColourListValidator::wxColourListValidator(long flags
):
1487 wxPropertyListValidator(flags
)
1491 wxColourListValidator::~wxColourListValidator(void)
1495 bool wxColourListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1500 // Called when TICK is pressed or focus is lost or view wants to update
1501 // the property list.
1502 // Does the transferance from the property editing area to the property itself
1503 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1505 if (!view
->GetValueText())
1507 wxString
value(view
->GetValueText()->GetValue());
1509 property
->GetValue() = value
;
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::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1518 if (!view
->GetValueText())
1520 wxString
str(property
->GetValue().GetStringRepresentation());
1521 view
->GetValueText()->SetValue(str
);
1525 // Called when the property is double clicked. Extra functionality can be provided,
1526 // cycling through possible values.
1527 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1529 if (!view
->GetValueText())
1531 OnEdit(property
, view
, parentWindow
);
1535 bool wxColourListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1537 if (view
->GetConfirmButton())
1538 view
->GetConfirmButton()->Enable(TRUE
);
1539 if (view
->GetCancelButton())
1540 view
->GetCancelButton()->Enable(TRUE
);
1541 if (view
->GetEditButton())
1542 view
->GetEditButton()->Enable(TRUE
);
1543 if (view
->GetValueText())
1544 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1548 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1550 if (!view
->GetValueText())
1553 char *s
= property
->GetValue().StringValue();
1560 g
= wxHexToDec(s
+2);
1561 b
= wxHexToDec(s
+4);
1564 wxColour
col(r
,g
,b
);
1567 data
.SetChooseFull(TRUE
);
1568 data
.SetColour(col
);
1570 for (int i
= 0; i
< 16; i
++)
1572 wxColour
colour(i
*16, i
*16, i
*16);
1573 data
.SetCustomColour(i
, colour
);
1576 wxColourDialog
dialog(parentWindow
, &data
);
1577 if (dialog
.ShowModal() != wxID_CANCEL
)
1579 wxColourData retData
= dialog
.GetColourData();
1580 col
= retData
.GetColour();
1583 wxDecToHex(col
.Red(), buf
);
1584 wxDecToHex(col
.Green(), buf
+2);
1585 wxDecToHex(col
.Blue(), buf
+4);
1587 property
->GetValue() = wxString(buf
);
1588 view
->DisplayProperty(property
);
1589 view
->UpdatePropertyDisplayInList(property
);
1590 view
->OnPropertyChanged(property
);
1595 /// List of strings validator. For this we need more user interface than
1596 /// we get with a property list; so create a new dialog for editing the list.
1598 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1600 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1601 wxPropertyListValidator(flags
)
1605 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1607 // No constraints for an arbitrary, user-editable list of strings.
1611 // Called when TICK is pressed or focus is lost or view wants to update
1612 // the property list.
1613 // Does the transferance from the property editing area to the property itself.
1614 // In this case, the user cannot directly edit the string list.
1615 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1620 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1622 if (!view
->GetValueText())
1624 wxString
str(property
->GetValue().GetStringRepresentation());
1625 view
->GetValueText()->SetValue(str
);
1629 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1631 if (view
->GetEditButton())
1632 view
->GetEditButton()->Enable(TRUE
);
1633 if (view
->GetValueText())
1634 view
->GetValueText()->Enable(FALSE
);
1636 if (view
->GetConfirmButton())
1637 view
->GetConfirmButton()->Enable(FALSE
);
1638 if (view
->GetCancelButton())
1639 view
->GetCancelButton()->Enable(FALSE
);
1643 // Called when the property is double clicked. Extra functionality can be provided,
1644 // cycling through possible values.
1645 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1647 OnEdit(property
, view
, parentWindow
);
1651 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1653 // Convert property value to a list of strings for editing
1654 wxStringList
*stringList
= new wxStringList
;
1656 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1659 char *s
= expr
->StringValue();
1662 expr
= expr
->GetNext();
1665 wxString
title("Editing ");
1666 title
+= property
->GetName();
1668 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1670 wxPropertyValue
& oldValue
= property
->GetValue();
1671 oldValue
.ClearList();
1672 wxNode
*node
= stringList
->First();
1675 char *s
= (char *)node
->Data();
1676 oldValue
.Append(new wxPropertyValue(s
));
1678 node
= node
->Next();
1681 view
->DisplayProperty(property
);
1682 view
->UpdatePropertyDisplayInList(property
);
1683 view
->OnPropertyChanged(property
);
1688 class wxPropertyStringListEditorDialog
: public wxDialog
1691 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1692 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1693 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1694 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1696 m_stringList
= NULL
;
1697 m_stringText
= NULL
;
1699 sm_dialogCancelled
= FALSE
;
1700 m_currentSelection
= -1;
1702 ~wxPropertyStringListEditorDialog(void) {}
1704 void SaveCurrentSelection(void);
1705 void ShowCurrentSelection(void);
1707 void OnOK(wxCommandEvent
& event
);
1708 void OnCancel(wxCommandEvent
& event
);
1709 void OnAdd(wxCommandEvent
& event
);
1710 void OnDelete(wxCommandEvent
& event
);
1711 void OnStrings(wxCommandEvent
& event
);
1712 void OnText(wxCommandEvent
& event
);
1715 wxStringList
* m_stringList
;
1716 wxListBox
* m_listBox
;
1717 wxTextCtrl
* m_stringText
;
1718 static bool sm_dialogCancelled
;
1719 int m_currentSelection
;
1720 DECLARE_EVENT_TABLE()
1723 #define wxID_PROP_SL_ADD 3000
1724 #define wxID_PROP_SL_DELETE 3001
1725 #define wxID_PROP_SL_STRINGS 3002
1726 #define wxID_PROP_SL_TEXT 3003
1728 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1729 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1730 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1731 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1732 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1733 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1734 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1737 class wxPropertyStringListEditorText
: public wxTextCtrl
1740 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1741 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1742 long windowStyle
= 0, const wxString
& name
= "text"):
1743 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1746 void OnKillFocus(void)
1748 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1749 dialog
->SaveCurrentSelection();
1753 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1755 // Edit the string list.
1756 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1758 int largeButtonWidth
= 60;
1759 int largeButtonHeight
= 25;
1761 wxBeginBusyCursor();
1762 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1763 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1765 dialog
->m_stringList
= stringList
;
1767 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1768 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1770 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1771 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1772 wxSize(300, -1), wxPROCESS_ENTER
);
1773 dialog
->m_stringText
->Enable(FALSE
);
1775 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1776 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1777 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1778 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1780 okButton
->SetDefault();
1782 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1784 c
->top
.SameAs (dialog
, wxTop
, 2);
1785 c
->left
.SameAs (dialog
, wxLeft
, 2);
1786 c
->right
.SameAs (dialog
, wxRight
, 2);
1787 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1788 dialog
->m_listBox
->SetConstraints(c
);
1790 c
= new wxLayoutConstraints
;
1791 c
->left
.SameAs (dialog
, wxLeft
, 2);
1792 c
->right
.SameAs (dialog
, wxRight
, 2);
1793 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1795 dialog
->m_stringText
->SetConstraints(c
);
1797 c
= new wxLayoutConstraints
;
1798 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1799 c
->left
.SameAs (dialog
, wxLeft
, 2);
1802 addButton
->SetConstraints(c
);
1804 c
= new wxLayoutConstraints
;
1805 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1806 c
->left
.SameAs (addButton
, wxRight
, 2);
1809 deleteButton
->SetConstraints(c
);
1811 c
= new wxLayoutConstraints
;
1812 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1813 c
->right
.SameAs (dialog
, wxRight
, 2);
1816 cancelButton
->SetConstraints(c
);
1818 c
= new wxLayoutConstraints
;
1819 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1820 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1823 okButton
->SetConstraints(c
);
1825 wxNode
*node
= stringList
->First();
1828 char *str
= (char *)node
->Data();
1829 // Save node as client data for each listbox item
1830 dialog
->m_listBox
->Append(str
, (char *)node
);
1831 node
= node
->Next();
1834 dialog
->SetClientSize(310, 305);
1837 dialog
->Centre(wxBOTH
);
1839 if (dialog
->ShowModal() == wxID_CANCEL
)
1846 * String list editor callbacks
1850 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1852 int sel
= m_listBox
->GetSelection();
1855 m_currentSelection
= sel
;
1857 ShowCurrentSelection();
1861 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1863 int sel
= m_listBox
->GetSelection();
1867 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1871 m_listBox
->Delete(sel
);
1872 delete[] (char *)node
->Data();
1874 m_currentSelection
= -1;
1875 m_stringText
->SetValue("");
1878 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1880 SaveCurrentSelection();
1882 char *initialText
= "";
1883 wxNode
*node
= m_stringList
->Add(initialText
);
1884 m_listBox
->Append(initialText
, (char *)node
);
1885 m_currentSelection
= m_stringList
->Number() - 1;
1886 m_listBox
->SetSelection(m_currentSelection
);
1887 ShowCurrentSelection();
1888 m_stringText
->SetFocus();
1891 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1893 SaveCurrentSelection();
1898 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1900 sm_dialogCancelled
= TRUE
;
1901 EndModal(wxID_CANCEL
);
1905 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1907 if (event
.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND
)
1909 SaveCurrentSelection();
1913 bool wxPropertyStringListEditorDialog::OnClose(void)
1915 SaveCurrentSelection();
1919 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1921 if (m_currentSelection
== -1)
1924 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1928 wxString
txt(m_stringText
->GetValue());
1930 delete[] (char *)node
->Data();
1931 node
->SetData((wxObject
*)copystring(txt
));
1933 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1936 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1938 if (m_currentSelection
== -1)
1940 m_stringText
->SetValue("");
1943 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1944 char *txt
= (char *)node
->Data();
1945 m_stringText
->SetValue(txt
);
1946 m_stringText
->Enable(TRUE
);