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"
32 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
35 #include <strstream.h>
38 #include "wx/window.h"
41 #include "wx/colordlg.h"
45 * Property text edit control
48 IMPLEMENT_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
50 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
51 const wxWindowID id
, const wxString
& value
,
52 const wxPoint
& pos
, const wxSize
& size
,
53 long style
, const wxString
& name
):
54 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
59 void wxPropertyTextEdit::OnSetFocus(void)
63 void wxPropertyTextEdit::OnKillFocus(void)
71 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
73 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
74 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
75 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
76 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
77 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
78 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
79 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
80 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
81 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
82 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxPropertyListView::OnPropertyDoubleClick
)
83 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
86 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
87 wxBitmap
*wxPropertyListView::sm_tickBitmap
= NULL
;
88 wxBitmap
*wxPropertyListView::sm_crossBitmap
= NULL
;
90 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
92 m_propertyScrollingList
= NULL
;
96 m_confirmButton
= NULL
;
97 m_cancelButton
= NULL
;
98 m_propertyWindow
= propPanel
;
99 m_managedWindow
= NULL
;
101 m_windowCloseButton
= NULL
;
102 m_windowCancelButton
= NULL
;
103 m_windowHelpButton
= NULL
;
105 m_detailedEditing
= FALSE
;
108 wxPropertyListView::~wxPropertyListView(void)
114 delete m_crossBitmap;
118 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
120 m_propertySheet
= ps
;
122 AssociatePanel(panel
);
125 UpdatePropertyList();
129 // Update this view of the viewed object, called e.g. by
130 // the object itself.
131 bool wxPropertyListView::OnUpdateView(void)
136 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
138 if (!m_propertyScrollingList
|| !m_propertySheet
)
141 m_propertyScrollingList
->Clear();
144 m_valueList
->Clear();
145 m_valueText
->SetValue("");
147 wxNode
*node
= m_propertySheet
->GetProperties().First();
149 // Should sort them... later...
152 wxProperty
*property
= (wxProperty
*)node
->Data();
153 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
154 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
156 m_propertyScrollingList
->Append(paddedString
.GetData(), (char *)property
);
162 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
164 if (!m_propertyScrollingList
|| !m_propertySheet
)
167 int currentlySelected
= m_propertyScrollingList
->GetSelection();
169 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
170 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
171 int sel
= FindListIndexForProperty(property
);
175 // Don't update the listbox unnecessarily because it can cause
178 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
179 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
182 // UpdatePropertyList(FALSE);
185 // TODO: why is this necessary?
187 if (currentlySelected
> -1)
188 m_propertyScrollingList
->SetSelection(currentlySelected
);
194 // Find the wxListBox index corresponding to this property
195 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
197 int n
= m_propertyScrollingList
->Number();
198 for (int i
= 0; i
< n
; i
++)
200 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
206 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
208 wxString
theString(name
);
211 int padWith
= nameWidth
- theString
.Length();
215 if (GetFlags() & wxPROP_SHOWVALUES
)
217 // Want to pad with spaces
218 theString
.Append(' ', padWith
);
225 // Select and show string representation in validator the given
226 // property. NULL resets to show no property.
227 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
229 if (m_currentProperty
)
231 EndShowingProperty(m_currentProperty
);
232 m_currentProperty
= NULL
;
235 m_valueList
->Clear();
236 m_valueText
->SetValue("");
240 m_currentProperty
= property
;
241 BeginShowingProperty(property
);
245 int sel
= FindListIndexForProperty(property
);
247 m_propertyScrollingList
->SetSelection(sel
);
252 // Find appropriate validator and load property into value controls
253 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
255 m_currentValidator
= FindPropertyValidator(property
);
256 if (!m_currentValidator
)
259 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
262 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
264 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
265 DisplayProperty(property
);
269 // Find appropriate validator and unload property from value controls
270 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
272 if (!m_currentValidator
)
275 RetrieveProperty(property
);
277 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
280 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
282 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
283 if (m_detailedEditing
)
285 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
286 m_detailedEditing
= FALSE
;
291 void wxPropertyListView::BeginDetailedEditing(void)
293 if (!m_currentValidator
)
295 if (!m_currentProperty
)
297 if (m_detailedEditing
)
299 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
301 if (!m_currentProperty
->IsEnabled())
304 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
306 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
307 m_detailedEditing
= TRUE
;
310 void wxPropertyListView::EndDetailedEditing(void)
312 if (!m_currentValidator
)
314 if (!m_currentProperty
)
317 RetrieveProperty(m_currentProperty
);
319 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
322 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
324 if (m_detailedEditing
)
326 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
327 m_detailedEditing
= FALSE
;
331 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
333 if (!m_currentValidator
)
336 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
337 m_valueText
->SetEditable(FALSE
);
339 m_valueText
->SetEditable(TRUE
);
341 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
344 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
346 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
350 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
352 if (!m_currentValidator
)
354 if (!property
->IsEnabled())
357 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
360 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
362 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
364 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
366 UpdatePropertyDisplayInList(property
);
367 OnPropertyChanged(property
);
372 // Revert to old value
373 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
379 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
384 // Called by the listbox callback
385 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
387 int sel
= m_propertyScrollingList
->GetSelection();
390 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
391 if (newSel
&& newSel
!= m_currentProperty
)
393 ShowProperty(newSel
, FALSE
);
398 bool wxPropertyListView::CreateControls(void)
400 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
402 int largeButtonWidth
= 60;
403 int largeButtonHeight
= 25;
405 int smallButtonWidth
= 25;
406 int smallButtonHeight
= 20;
408 // XView must be allowed to choose its own sized buttons
410 largeButtonWidth
= -1;
411 largeButtonHeight
= -1;
413 smallButtonWidth
= -1;
414 smallButtonHeight
= -1;
423 wxWindow
*leftMostWindow
= panel
;
424 wxWindow
*topMostWindow
= panel
;
425 wxWindow
*rightMostWindow
= panel
;
427 wxSystemSettings settings
;
428 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
431 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
433 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
436 // May need to be changed in future to eliminate clashes with app.
437 panel
->SetClientData((char *)this);
439 // These buttons are at the bottom of the window, but create them now
440 // so the constraints are evaluated in the correct order
441 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
443 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
444 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
445 m_windowCloseButton
->SetDefault();
446 m_windowCloseButton
->SetFocus();
448 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
450 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
451 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
453 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
455 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
456 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
458 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
460 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
461 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
464 if (m_windowCloseButton
)
466 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
468 c1
->left
.SameAs (panel
, wxLeft
, 2);
469 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
472 m_windowCloseButton
->SetConstraints(c1
);
473 leftMostWindow
= m_windowCloseButton
;
475 if (m_windowCancelButton
)
477 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
479 c2
->right
.SameAs (panel
, wxRight
, 2);
480 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
483 m_windowCancelButton
->SetConstraints(c2
);
484 leftMostWindow
= m_windowCancelButton
;
486 if (m_windowHelpButton
)
488 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
489 if (leftMostWindow
== panel
)
490 c2
->left
.SameAs (panel
, wxLeft
, 2);
492 c2
->left
.RightOf (leftMostWindow
, 2);
494 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
497 m_windowHelpButton
->SetConstraints(c2
);
498 leftMostWindow
= m_windowHelpButton
;
501 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
507 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
508 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
509 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
522 if (tickBitmap && crossBitmap)
524 m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
525 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
526 m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
527 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
532 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
533 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
534 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
535 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
538 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
539 c
->left
.SameAs (panel
, wxLeft
, 2);
541 if (windowCloseButton)
542 c->top.Below (m_windowCloseButton, 2);
545 c
->top
.SameAs (panel
, wxTop
, 2);
550 m_cancelButton
->SetConstraints(c
);
552 c
= new wxLayoutConstraints
;
553 c
->left
.RightOf (m_cancelButton
, 2);
554 c
->top
.SameAs (m_cancelButton
, wxTop
, 0);
558 m_confirmButton
->SetConstraints(c
);
560 m_cancelButton
->Enable(FALSE
);
561 m_confirmButton
->Enable(FALSE
);
564 if (m_buttonFlags
& wxPROP_PULLDOWN
)
566 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
567 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
568 m_editButton
->Enable(FALSE
);
569 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
572 if (m_windowCloseButton)
573 c->top.Below (m_windowCloseButton, 2);
576 c
->top
.SameAs (panel
, wxTop
, 2);
578 c
->right
.SameAs (panel
, wxRight
, 2);
581 m_editButton
->SetConstraints(c
);
584 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
585 m_valueText
->Enable(FALSE
);
587 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
590 c
->left
.RightOf (m_confirmButton
, 2);
592 c
->left
.SameAs (panel
, wxLeft
, 2);
594 if (m_windowCloseButton)
595 c->top.Below (m_windowCloseButton, 2);
598 c
->top
.SameAs (panel
, wxTop
, 2);
601 c
->right
.LeftOf (m_editButton
, 2);
603 c
->right
.SameAs (panel
, wxRight
, 2);
606 m_valueText
->SetConstraints(c
);
608 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
609 m_valueList
->Show(FALSE
);
611 c
= new wxLayoutConstraints
;
613 c
->left
.SameAs (panel
, wxLeft
, 2);
614 c
->top
.Below (m_valueText
, 2);
615 c
->right
.SameAs (panel
, wxRight
, 2);
616 c
->height
.Absolute(60);
618 m_valueList
->SetConstraints(c
);
620 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
621 wxPoint(-1, -1), wxSize(300, 300));
622 m_propertyScrollingList
->SetFont(boringFont
);
624 c
= new wxLayoutConstraints
;
626 c
->left
.SameAs (panel
, wxLeft
, 2);
628 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
629 c
->top
.Below (m_valueText
, 2);
631 c
->top
.Below (m_valueList
, 2);
633 c
->right
.SameAs (panel
, wxRight
, 2);
635 if (m_windowCloseButton
)
636 c
->bottom
.Above (m_windowCloseButton
, -2);
638 c
->bottom
.SameAs (panel
, wxBottom
, 2);
640 m_propertyScrollingList
->SetConstraints(c
);
642 // Note: if this is called now, it causes a GPF.
649 void wxPropertyListView::ShowTextControl(bool show
)
652 m_valueText
->Show(show
);
655 void wxPropertyListView::ShowListBoxControl(bool show
)
659 m_valueList
->Show(show
);
660 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
662 wxLayoutConstraints
*constraints
= m_propertyScrollingList
->GetConstraints();
667 constraints
->top
.Below(m_valueList
, 2);
668 // Maintain back-pointer so when valueList is deleted,
669 // any reference to it from this window is removed.
670 m_valueList
->AddConstraintReference(m_propertyScrollingList
);
674 constraints
->top
.Below(m_valueText
, 2);
675 m_valueText
->AddConstraintReference(m_propertyScrollingList
);
677 m_propertyWindow
->Layout();
683 void wxPropertyListView::EnableCheck(bool show
)
686 m_confirmButton
->Enable(show
);
689 void wxPropertyListView::EnableCross(bool show
)
692 m_cancelButton
->Enable(show
);
695 bool wxPropertyListView::OnClose(void)
697 // Retrieve the value if any
698 wxCommandEvent event
;
705 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
707 if (m_currentProperty
&& m_currentValidator
)
709 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
712 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
714 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
718 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
720 // Retrieve the value if any
723 m_managedWindow
->Close(TRUE
);
726 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
728 // SetReturnCode(wxID_CANCEL);
729 m_managedWindow
->Close(TRUE
);
730 sm_dialogCancelled
= TRUE
;
733 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
737 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
739 if (m_currentProperty
)
741 RetrieveProperty(m_currentProperty
);
745 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
747 if (m_currentProperty
&& m_currentValidator
)
749 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
752 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
754 // Revert to old value
755 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
759 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
761 if (m_currentProperty
&& m_currentValidator
)
763 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
766 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
768 // Revert to old value
769 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
773 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
775 if (m_currentProperty
&& m_currentValidator
)
777 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
780 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
782 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
786 void wxPropertyListView::OnText(wxCommandEvent
& event
)
788 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
795 * Property dialog box
798 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
800 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
801 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
804 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
805 const wxString
& title
, const wxPoint
& pos
,
806 const wxSize
& size
, long style
, const wxString
& name
):
807 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
810 m_view
->AssociatePanel( ((wxPanel
*)this) );
811 m_view
->SetManagedWindow(this);
815 bool wxPropertyListDialog::OnClose(void)
819 SetReturnCode(wxID_CANCEL
);
828 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
830 SetReturnCode(wxID_CANCEL
);
834 void wxPropertyListDialog::OnDefaultAction(wxControl
*item
)
837 if (item == m_view->GetPropertyScrollingList())
838 view->OnDoubleClick();
842 // Extend event processing to search the view's event table
843 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
845 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
846 return wxEvtHandler::ProcessEvent(event
);
855 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
857 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
858 EVT_SIZE(wxPropertyListPanel::OnSize
)
861 wxPropertyListPanel::~wxPropertyListPanel()
865 void wxPropertyListPanel::OnDefaultAction(wxControl
*item
)
868 if (item == view->GetPropertyScrollingList())
869 view->OnDoubleClick();
873 // Extend event processing to search the view's event table
874 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
876 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
877 return wxEvtHandler::ProcessEvent(event
);
882 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
891 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
893 bool wxPropertyListFrame::OnClose(void)
898 m_propertyPanel
->SetView(NULL
);
907 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
909 return new wxPropertyListPanel(v
, parent
);
912 bool wxPropertyListFrame::Initialize(void)
914 m_propertyPanel
= OnCreatePanel(this, m_view
);
917 m_view
->AssociatePanel(m_propertyPanel
);
918 m_view
->SetManagedWindow(this);
919 m_propertyPanel
->SetAutoLayout(TRUE
);
927 * Property list specific validator
930 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
932 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
934 // view->GetValueText()->Show(TRUE);
936 OnDisplayValue(property
, view
, parentWindow
);
941 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
943 wxString
s(view
->GetValueList()->GetStringSelection());
946 view
->GetValueText()->SetValue(s
);
947 view
->RetrieveProperty(property
);
952 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
954 // view->GetValueText()->Show(TRUE);
955 wxString
str(property
->GetValue().GetStringRepresentation());
957 view
->GetValueText()->SetValue(str
);
961 // Called when TICK is pressed or focus is lost or view wants to update
962 // the property list.
963 // Does the transferance from the property editing area to the property itself
964 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
966 if (!view
->GetValueText())
971 void wxPropertyListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
973 if (view
->GetDetailedEditing())
974 view
->EndDetailedEditing();
976 view
->BeginDetailedEditing();
979 bool wxPropertyListValidator::OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
981 if (view
->GetConfirmButton())
982 view
->GetConfirmButton()->Enable(FALSE
);
983 if (view
->GetCancelButton())
984 view
->GetCancelButton()->Enable(FALSE
);
985 if (view
->GetEditButton())
986 view
->GetEditButton()->Enable(FALSE
);
994 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
997 /// Real number validator
999 bool wxRealListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1001 if (m_realMin
== 0.0 && m_realMax
== 0.0)
1004 if (!view
->GetValueText())
1006 wxString
value(view
->GetValueText()->GetValue());
1009 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1012 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
1013 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1017 if (val
< m_realMin
|| val
> m_realMax
)
1020 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
1021 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1027 // Called when TICK is pressed or focus is lost or view wants to update
1028 // the property list.
1029 // Does the transferance from the property editing area to the property itself
1030 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1032 if (!view
->GetValueText())
1035 if (strlen(view
->GetValueText()->GetValue()) == 0)
1038 wxString
value(view
->GetValueText()->GetValue());
1039 float f
= (float)atof(value
.GetData());
1040 property
->GetValue() = f
;
1044 bool wxRealListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1046 if (view
->GetConfirmButton())
1047 view
->GetConfirmButton()->Enable(TRUE
);
1048 if (view
->GetCancelButton())
1049 view
->GetCancelButton()->Enable(TRUE
);
1050 if (view
->GetEditButton())
1051 view
->GetEditButton()->Enable(FALSE
);
1052 if (view
->GetValueText())
1053 view
->GetValueText()->Enable(TRUE
);
1058 /// Integer validator
1060 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1062 bool wxIntegerListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1064 if (m_integerMin
== 0 && m_integerMax
== 0)
1067 if (!view
->GetValueText())
1069 wxString
value(view
->GetValueText()->GetValue());
1072 if (!StringToLong(WXSTRINGCAST value
, &val
))
1075 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1076 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1079 if (val
< m_integerMin
|| val
> m_integerMax
)
1082 sprintf(buf
, "Value must be an integer between %ld and %ld!", m_integerMin
, m_integerMax
);
1083 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1089 // Called when TICK is pressed or focus is lost or view wants to update
1090 // the property list.
1091 // Does the transferance from the property editing area to the property itself
1092 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1094 if (!view
->GetValueText())
1097 if (strlen(view
->GetValueText()->GetValue()) == 0)
1100 wxString
value(view
->GetValueText()->GetValue());
1101 long val
= (long)atoi(value
.GetData());
1102 property
->GetValue() = (long)val
;
1106 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1108 if (view
->GetConfirmButton())
1109 view
->GetConfirmButton()->Enable(TRUE
);
1110 if (view
->GetCancelButton())
1111 view
->GetCancelButton()->Enable(TRUE
);
1112 if (view
->GetEditButton())
1113 view
->GetEditButton()->Enable(FALSE
);
1114 if (view
->GetValueText())
1115 view
->GetValueText()->Enable(TRUE
);
1120 /// boolean validator
1122 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1124 bool wxBoolListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1126 if (!view
->GetValueText())
1128 wxString
value(view
->GetValueText()->GetValue());
1129 if (value
!= "True" && value
!= "False")
1131 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1137 // Called when TICK is pressed or focus is lost or view wants to update
1138 // the property list.
1139 // Does the transferance from the property editing area to the property itself
1140 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1142 if (!view
->GetValueText())
1145 if (strlen(view
->GetValueText()->GetValue()) == 0)
1148 wxString
value(view
->GetValueText()->GetValue());
1149 bool boolValue
= FALSE
;
1150 if (value
== "True")
1154 property
->GetValue() = (bool)boolValue
;
1158 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1160 if (!view
->GetValueText())
1162 wxString
str(property
->GetValue().GetStringRepresentation());
1164 view
->GetValueText()->SetValue(str
);
1166 if (view
->GetValueList()->IsShown())
1168 view
->GetValueList()->SetStringSelection(str
);
1173 bool wxBoolListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1175 if (view
->GetConfirmButton())
1176 view
->GetConfirmButton()->Enable(FALSE
);
1177 if (view
->GetCancelButton())
1178 view
->GetCancelButton()->Enable(FALSE
);
1179 if (view
->GetEditButton())
1180 view
->GetEditButton()->Enable(TRUE
);
1181 if (view
->GetValueText())
1182 view
->GetValueText()->Enable(FALSE
);
1186 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1188 if (view
->GetValueList())
1190 view
->ShowListBoxControl(TRUE
);
1191 view
->GetValueList()->Enable(TRUE
);
1193 view
->GetValueList()->Append("True");
1194 view
->GetValueList()->Append("False");
1195 char *currentString
= copystring(view
->GetValueText()->GetValue());
1196 view
->GetValueList()->SetStringSelection(currentString
);
1197 delete[] currentString
;
1202 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1204 if (view
->GetValueList())
1206 view
->GetValueList()->Clear();
1207 view
->ShowListBoxControl(FALSE
);
1208 view
->GetValueList()->Enable(FALSE
);
1213 // Called when the property is double clicked. Extra functionality can be provided,
1214 // cycling through possible values.
1215 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1217 if (!view
->GetValueText())
1219 if (property
->GetValue().BoolValue())
1220 property
->GetValue() = (bool)FALSE
;
1222 property
->GetValue() = (bool)TRUE
;
1223 view
->DisplayProperty(property
);
1224 view
->UpdatePropertyDisplayInList(property
);
1225 view
->OnPropertyChanged(property
);
1230 /// String validator
1232 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1234 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1235 wxPropertyListValidator(flags
)
1238 // If no constraint, we just allow the string to be edited.
1239 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1240 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1243 bool wxStringListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1248 if (!view
->GetValueText())
1250 wxString
value(view
->GetValueText()->GetValue());
1252 if (!m_strings
->Member(value
.GetData()))
1254 wxString
s("Value ");
1255 s
+= value
.GetData();
1256 s
+= " is not valid.";
1257 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1263 // Called when TICK is pressed or focus is lost or view wants to update
1264 // the property list.
1265 // Does the transferance from the property editing area to the property itself
1266 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1268 if (!view
->GetValueText())
1270 wxString
value(view
->GetValueText()->GetValue());
1271 property
->GetValue() = value
;
1275 // Called when TICK is pressed or focus is lost or view wants to update
1276 // the property list.
1277 // Does the transferance from the property editing area to the property itself
1278 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1280 if (!view
->GetValueText())
1282 wxString
str(property
->GetValue().GetStringRepresentation());
1283 view
->GetValueText()->SetValue(str
);
1284 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1286 view
->GetValueList()->SetStringSelection(str
);
1291 bool wxStringListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1296 if (view
->GetEditButton())
1297 view
->GetEditButton()->Enable(FALSE
);
1298 if (view
->GetConfirmButton())
1299 view
->GetConfirmButton()->Enable(TRUE
);
1300 if (view
->GetCancelButton())
1301 view
->GetCancelButton()->Enable(TRUE
);
1302 if (view
->GetValueText())
1303 view
->GetValueText()->Enable(TRUE
);
1308 if (view
->GetValueText())
1309 view
->GetValueText()->Enable(FALSE
);
1311 if (view
->GetEditButton())
1312 view
->GetEditButton()->Enable(TRUE
);
1314 if (view
->GetConfirmButton())
1315 view
->GetConfirmButton()->Enable(FALSE
);
1316 if (view
->GetCancelButton())
1317 view
->GetCancelButton()->Enable(FALSE
);
1321 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1323 if (view
->GetValueList())
1325 view
->ShowListBoxControl(TRUE
);
1326 view
->GetValueList()->Enable(TRUE
);
1327 wxNode
*node
= m_strings
->First();
1330 char *s
= (char *)node
->Data();
1331 view
->GetValueList()->Append(s
);
1332 node
= node
->Next();
1334 char *currentString
= property
->GetValue().StringValue();
1335 view
->GetValueList()->SetStringSelection(currentString
);
1340 bool wxStringListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1347 if (view
->GetValueList())
1349 view
->GetValueList()->Clear();
1350 view
->ShowListBoxControl(FALSE
);
1351 view
->GetValueList()->Enable(FALSE
);
1356 // Called when the property is double clicked. Extra functionality can be provided,
1357 // cycling through possible values.
1358 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1360 if (!view
->GetValueText())
1365 wxNode
*node
= m_strings
->First();
1366 char *currentString
= property
->GetValue().StringValue();
1369 char *s
= (char *)node
->Data();
1370 if (strcmp(s
, currentString
) == 0)
1372 char *nextString
= NULL
;
1374 nextString
= (char *)node
->Next()->Data();
1376 nextString
= (char *)m_strings
->First()->Data();
1377 property
->GetValue() = wxString(nextString
);
1378 view
->DisplayProperty(property
);
1379 view
->UpdatePropertyDisplayInList(property
);
1380 view
->OnPropertyChanged(property
);
1383 else node
= node
->Next();
1389 /// Filename validator
1391 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1393 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1394 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1398 wxFilenameListValidator::~wxFilenameListValidator(void)
1402 bool wxFilenameListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1407 // Called when TICK is pressed or focus is lost or view wants to update
1408 // the property list.
1409 // Does the transferance from the property editing area to the property itself
1410 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1412 if (!view
->GetValueText())
1414 wxString
value(view
->GetValueText()->GetValue());
1415 property
->GetValue() = value
;
1419 // Called when TICK is pressed or focus is lost or view wants to update
1420 // the property list.
1421 // Does the transferance from the property editing area to the property itself
1422 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1424 if (!view
->GetValueText())
1426 wxString
str(property
->GetValue().GetStringRepresentation());
1427 view
->GetValueText()->SetValue(str
);
1431 // Called when the property is double clicked. Extra functionality can be provided,
1432 // cycling through possible values.
1433 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1435 if (!view
->GetValueText())
1437 OnEdit(property
, view
, parentWindow
);
1441 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1443 if (view
->GetConfirmButton())
1444 view
->GetConfirmButton()->Enable(TRUE
);
1445 if (view
->GetCancelButton())
1446 view
->GetCancelButton()->Enable(TRUE
);
1447 if (view
->GetEditButton())
1448 view
->GetEditButton()->Enable(TRUE
);
1449 if (view
->GetValueText())
1450 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1454 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1456 if (!view
->GetValueText())
1459 char *s
= wxFileSelector(
1460 m_filenameMessage
.GetData(),
1461 wxPathOnly(property
->GetValue().StringValue()),
1462 wxFileNameFromPath(property
->GetValue().StringValue()),
1464 m_filenameWildCard
.GetData(),
1469 property
->GetValue() = wxString(s
);
1470 view
->DisplayProperty(property
);
1471 view
->UpdatePropertyDisplayInList(property
);
1472 view
->OnPropertyChanged(property
);
1477 /// Colour validator
1479 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1481 wxColourListValidator::wxColourListValidator(long flags
):
1482 wxPropertyListValidator(flags
)
1486 wxColourListValidator::~wxColourListValidator(void)
1490 bool wxColourListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1495 // Called when TICK is pressed or focus is lost or view wants to update
1496 // the property list.
1497 // Does the transferance from the property editing area to the property itself
1498 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1500 if (!view
->GetValueText())
1502 wxString
value(view
->GetValueText()->GetValue());
1504 property
->GetValue() = value
;
1508 // Called when TICK is pressed or focus is lost or view wants to update
1509 // the property list.
1510 // Does the transferance from the property editing area to the property itself
1511 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1513 if (!view
->GetValueText())
1515 wxString
str(property
->GetValue().GetStringRepresentation());
1516 view
->GetValueText()->SetValue(str
);
1520 // Called when the property is double clicked. Extra functionality can be provided,
1521 // cycling through possible values.
1522 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1524 if (!view
->GetValueText())
1526 OnEdit(property
, view
, parentWindow
);
1530 bool wxColourListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1532 if (view
->GetConfirmButton())
1533 view
->GetConfirmButton()->Enable(TRUE
);
1534 if (view
->GetCancelButton())
1535 view
->GetCancelButton()->Enable(TRUE
);
1536 if (view
->GetEditButton())
1537 view
->GetEditButton()->Enable(TRUE
);
1538 if (view
->GetValueText())
1539 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1543 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1545 if (!view
->GetValueText())
1548 char *s
= property
->GetValue().StringValue();
1555 g
= wxHexToDec(s
+2);
1556 b
= wxHexToDec(s
+4);
1559 wxColour
col(r
,g
,b
);
1562 data
.SetChooseFull(TRUE
);
1563 data
.SetColour(col
);
1565 for (int i
= 0; i
< 16; i
++)
1567 wxColour
colour(i
*16, i
*16, i
*16);
1568 data
.SetCustomColour(i
, colour
);
1571 wxColourDialog
dialog(parentWindow
, &data
);
1572 if (dialog
.ShowModal() != wxID_CANCEL
)
1574 wxColourData retData
= dialog
.GetColourData();
1575 col
= retData
.GetColour();
1578 wxDecToHex(col
.Red(), buf
);
1579 wxDecToHex(col
.Green(), buf
+2);
1580 wxDecToHex(col
.Blue(), buf
+4);
1582 property
->GetValue() = wxString(buf
);
1583 view
->DisplayProperty(property
);
1584 view
->UpdatePropertyDisplayInList(property
);
1585 view
->OnPropertyChanged(property
);
1590 /// List of strings validator. For this we need more user interface than
1591 /// we get with a property list; so create a new dialog for editing the list.
1593 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1595 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1596 wxPropertyListValidator(flags
)
1600 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1602 // No constraints for an arbitrary, user-editable list of strings.
1606 // Called when TICK is pressed or focus is lost or view wants to update
1607 // the property list.
1608 // Does the transferance from the property editing area to the property itself.
1609 // In this case, the user cannot directly edit the string list.
1610 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1615 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1617 if (!view
->GetValueText())
1619 wxString
str(property
->GetValue().GetStringRepresentation());
1620 view
->GetValueText()->SetValue(str
);
1624 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1626 if (view
->GetEditButton())
1627 view
->GetEditButton()->Enable(TRUE
);
1628 if (view
->GetValueText())
1629 view
->GetValueText()->Enable(FALSE
);
1631 if (view
->GetConfirmButton())
1632 view
->GetConfirmButton()->Enable(FALSE
);
1633 if (view
->GetCancelButton())
1634 view
->GetCancelButton()->Enable(FALSE
);
1638 // Called when the property is double clicked. Extra functionality can be provided,
1639 // cycling through possible values.
1640 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1642 OnEdit(property
, view
, parentWindow
);
1646 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1648 // Convert property value to a list of strings for editing
1649 wxStringList
*stringList
= new wxStringList
;
1651 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1654 char *s
= expr
->StringValue();
1657 expr
= expr
->GetNext();
1660 wxString
title("Editing ");
1661 title
+= property
->GetName();
1663 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1665 wxPropertyValue
& oldValue
= property
->GetValue();
1666 oldValue
.ClearList();
1667 wxNode
*node
= stringList
->First();
1670 char *s
= (char *)node
->Data();
1671 oldValue
.Append(new wxPropertyValue(s
));
1673 node
= node
->Next();
1676 view
->DisplayProperty(property
);
1677 view
->UpdatePropertyDisplayInList(property
);
1678 view
->OnPropertyChanged(property
);
1683 class wxPropertyStringListEditorDialog
: public wxDialog
1686 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1687 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1688 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1689 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1691 m_stringList
= NULL
;
1692 m_stringText
= NULL
;
1694 sm_dialogCancelled
= FALSE
;
1695 m_currentSelection
= -1;
1697 ~wxPropertyStringListEditorDialog(void) {}
1699 void SaveCurrentSelection(void);
1700 void ShowCurrentSelection(void);
1702 void OnOK(wxCommandEvent
& event
);
1703 void OnCancel(wxCommandEvent
& event
);
1704 void OnAdd(wxCommandEvent
& event
);
1705 void OnDelete(wxCommandEvent
& event
);
1706 void OnStrings(wxCommandEvent
& event
);
1707 void OnText(wxCommandEvent
& event
);
1710 wxStringList
* m_stringList
;
1711 wxListBox
* m_listBox
;
1712 wxTextCtrl
* m_stringText
;
1713 static bool sm_dialogCancelled
;
1714 int m_currentSelection
;
1715 DECLARE_EVENT_TABLE()
1718 #define wxID_PROP_SL_ADD 3000
1719 #define wxID_PROP_SL_DELETE 3001
1720 #define wxID_PROP_SL_STRINGS 3002
1721 #define wxID_PROP_SL_TEXT 3003
1723 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1724 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1725 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1726 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1727 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1728 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1729 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1732 class wxPropertyStringListEditorText
: public wxTextCtrl
1735 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1736 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1737 long windowStyle
= 0, const wxString
& name
= "text"):
1738 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1741 void OnKillFocus(void)
1743 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1744 dialog
->SaveCurrentSelection();
1748 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1750 // Edit the string list.
1751 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1753 int largeButtonWidth
= 60;
1754 int largeButtonHeight
= 25;
1756 wxBeginBusyCursor();
1757 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1758 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1760 dialog
->m_stringList
= stringList
;
1762 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1763 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1765 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1766 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1767 wxSize(300, -1), wxPROCESS_ENTER
);
1768 dialog
->m_stringText
->Enable(FALSE
);
1770 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1771 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1772 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1773 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1775 okButton
->SetDefault();
1777 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1779 c
->top
.SameAs (dialog
, wxTop
, 2);
1780 c
->left
.SameAs (dialog
, wxLeft
, 2);
1781 c
->right
.SameAs (dialog
, wxRight
, 2);
1782 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1783 dialog
->m_listBox
->SetConstraints(c
);
1785 c
= new wxLayoutConstraints
;
1786 c
->left
.SameAs (dialog
, wxLeft
, 2);
1787 c
->right
.SameAs (dialog
, wxRight
, 2);
1788 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1790 dialog
->m_stringText
->SetConstraints(c
);
1792 c
= new wxLayoutConstraints
;
1793 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1794 c
->left
.SameAs (dialog
, wxLeft
, 2);
1797 addButton
->SetConstraints(c
);
1799 c
= new wxLayoutConstraints
;
1800 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1801 c
->left
.SameAs (addButton
, wxRight
, 2);
1804 deleteButton
->SetConstraints(c
);
1806 c
= new wxLayoutConstraints
;
1807 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1808 c
->right
.SameAs (dialog
, wxRight
, 2);
1811 cancelButton
->SetConstraints(c
);
1813 c
= new wxLayoutConstraints
;
1814 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1815 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1818 okButton
->SetConstraints(c
);
1820 wxNode
*node
= stringList
->First();
1823 char *str
= (char *)node
->Data();
1824 // Save node as client data for each listbox item
1825 dialog
->m_listBox
->Append(str
, (char *)node
);
1826 node
= node
->Next();
1829 dialog
->SetClientSize(310, 305);
1832 dialog
->Centre(wxBOTH
);
1834 if (dialog
->ShowModal() == wxID_CANCEL
)
1841 * String list editor callbacks
1845 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1847 int sel
= m_listBox
->GetSelection();
1850 m_currentSelection
= sel
;
1852 ShowCurrentSelection();
1856 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1858 int sel
= m_listBox
->GetSelection();
1862 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1866 m_listBox
->Delete(sel
);
1867 delete[] (char *)node
->Data();
1869 m_currentSelection
= -1;
1870 m_stringText
->SetValue("");
1873 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1875 SaveCurrentSelection();
1877 char *initialText
= "";
1878 wxNode
*node
= m_stringList
->Add(initialText
);
1879 m_listBox
->Append(initialText
, (char *)node
);
1880 m_currentSelection
= m_stringList
->Number() - 1;
1881 m_listBox
->SetSelection(m_currentSelection
);
1882 ShowCurrentSelection();
1883 m_stringText
->SetFocus();
1886 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1888 SaveCurrentSelection();
1893 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1895 sm_dialogCancelled
= TRUE
;
1896 EndModal(wxID_CANCEL
);
1900 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1902 if (event
.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND
)
1904 SaveCurrentSelection();
1908 bool wxPropertyStringListEditorDialog::OnClose(void)
1910 SaveCurrentSelection();
1914 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1916 if (m_currentSelection
== -1)
1919 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1923 wxString
txt(m_stringText
->GetValue());
1925 delete[] (char *)node
->Data();
1926 node
->SetData((wxObject
*)copystring(txt
));
1928 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1931 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1933 if (m_currentSelection
== -1)
1935 m_stringText
->SetValue("");
1938 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1939 char *txt
= (char *)node
->Data();
1940 m_stringText
->SetValue(txt
);
1941 m_stringText
->Enable(TRUE
);