1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "proplist.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/colordlg.h"
28 #include "wx/proplist.h"
37 * Property text edit control
40 IMPLEMENT_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
42 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
43 const wxWindowID id
, const wxString
& value
,
44 const wxPoint
& pos
, const wxSize
& size
,
45 long style
, const wxString
& name
):
46 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
51 void wxPropertyTextEdit::OnSetFocus(void)
55 void wxPropertyTextEdit::OnKillFocus(void)
63 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
65 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
66 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
67 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
68 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
69 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
70 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
71 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
72 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
73 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
74 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
75 wxPropertyListView::OnPropertyDoubleClick
)
76 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
79 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
80 wxBitmap
*wxPropertyListView::sm_tickBitmap
= NULL
;
81 wxBitmap
*wxPropertyListView::sm_crossBitmap
= NULL
;
83 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
85 m_propertyScrollingList
= NULL
;
89 m_confirmButton
= NULL
;
90 m_cancelButton
= NULL
;
91 m_propertyWindow
= propPanel
;
92 m_managedWindow
= NULL
;
94 m_windowCloseButton
= NULL
;
95 m_windowCancelButton
= NULL
;
96 m_windowHelpButton
= NULL
;
98 m_detailedEditing
= FALSE
;
101 wxPropertyListView::~wxPropertyListView(void)
107 delete m_crossBitmap;
111 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
113 m_propertySheet
= ps
;
115 AssociatePanel(panel
);
118 UpdatePropertyList();
122 // Update this view of the viewed object, called e.g. by
123 // the object itself.
124 bool wxPropertyListView::OnUpdateView(void)
129 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
131 if (!m_propertyScrollingList
|| !m_propertySheet
)
134 m_propertyScrollingList
->Clear();
137 m_valueList
->Clear();
138 m_valueText
->SetValue("");
140 wxNode
*node
= m_propertySheet
->GetProperties().First();
142 // Should sort them... later...
145 wxProperty
*property
= (wxProperty
*)node
->Data();
146 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
147 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
148 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
154 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
156 if (!m_propertyScrollingList
|| !m_propertySheet
)
160 int currentlySelected
= m_propertyScrollingList
->GetSelection();
163 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
164 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
165 int sel
= FindListIndexForProperty(property
);
169 // Don't update the listbox unnecessarily because it can cause
172 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
173 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
176 // UpdatePropertyList(FALSE);
179 // TODO: why is this necessary?
181 if (currentlySelected
> -1)
182 m_propertyScrollingList
->SetSelection(currentlySelected
);
188 // Find the wxListBox index corresponding to this property
189 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
191 int n
= m_propertyScrollingList
->Number();
192 for (int i
= 0; i
< n
; i
++)
194 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
200 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
202 wxString
theString(name
);
205 int padWith
= nameWidth
- theString
.Length();
209 if (GetFlags() & wxPROP_SHOWVALUES
)
211 // Want to pad with spaces
212 theString
.Append(' ', padWith
);
219 // Select and show string representation in validator the given
220 // property. NULL resets to show no property.
221 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
223 if (m_currentProperty
)
225 EndShowingProperty(m_currentProperty
);
226 m_currentProperty
= NULL
;
229 m_valueList
->Clear();
230 m_valueText
->SetValue("");
234 m_currentProperty
= property
;
235 BeginShowingProperty(property
);
239 int sel
= FindListIndexForProperty(property
);
241 m_propertyScrollingList
->SetSelection(sel
);
246 // Find appropriate validator and load property into value controls
247 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
249 m_currentValidator
= FindPropertyValidator(property
);
250 if (!m_currentValidator
)
253 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
256 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
258 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
259 DisplayProperty(property
);
263 // Find appropriate validator and unload property from value controls
264 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
266 if (!m_currentValidator
)
269 RetrieveProperty(property
);
271 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
274 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
276 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
277 if (m_detailedEditing
)
279 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
280 m_detailedEditing
= FALSE
;
285 void wxPropertyListView::BeginDetailedEditing(void)
287 if (!m_currentValidator
)
289 if (!m_currentProperty
)
291 if (m_detailedEditing
)
293 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
295 if (!m_currentProperty
->IsEnabled())
298 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
300 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
301 m_detailedEditing
= TRUE
;
304 void wxPropertyListView::EndDetailedEditing(void)
306 if (!m_currentValidator
)
308 if (!m_currentProperty
)
311 RetrieveProperty(m_currentProperty
);
313 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
316 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
318 if (m_detailedEditing
)
320 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
321 m_detailedEditing
= FALSE
;
325 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
327 if (!m_currentValidator
)
330 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
331 m_valueText
->SetEditable(FALSE
);
333 m_valueText
->SetEditable(TRUE
);
335 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
338 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
340 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
344 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
346 if (!m_currentValidator
)
348 if (!property
->IsEnabled())
351 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
354 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
356 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
358 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
360 UpdatePropertyDisplayInList(property
);
361 OnPropertyChanged(property
);
366 // Revert to old value
367 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
373 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
378 // Called by the listbox callback
379 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
381 int sel
= m_propertyScrollingList
->GetSelection();
384 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
385 if (newSel
&& newSel
!= m_currentProperty
)
387 ShowProperty(newSel
, FALSE
);
392 bool wxPropertyListView::CreateControls(void)
394 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
396 int largeButtonWidth
= 60;
397 int largeButtonHeight
= 25;
399 int smallButtonWidth
= 25;
400 int smallButtonHeight
= 20;
402 // XView must be allowed to choose its own sized buttons
404 largeButtonWidth
= -1;
405 largeButtonHeight
= -1;
407 smallButtonWidth
= -1;
408 smallButtonHeight
= -1;
417 wxWindow
*leftMostWindow
= panel
;
419 wxWindow *topMostWindow = panel;
420 wxWindow *rightMostWindow = panel;
423 wxSystemSettings settings
;
424 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
427 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
429 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
432 // May need to be changed in future to eliminate clashes with app.
433 // WHAT WAS THIS FOR?
434 // panel->SetClientData((char *)this);
436 // These buttons are at the bottom of the window, but create them now
437 // so the constraints are evaluated in the correct order
438 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
440 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
441 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
442 m_windowCloseButton
->SetDefault();
443 m_windowCloseButton
->SetFocus();
445 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
447 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
448 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
450 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
452 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
453 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
455 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
457 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
458 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
461 if (m_windowCloseButton
)
463 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
465 c1
->left
.SameAs (panel
, wxLeft
, 2);
466 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
469 m_windowCloseButton
->SetConstraints(c1
);
470 leftMostWindow
= m_windowCloseButton
;
472 if (m_windowCancelButton
)
474 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
476 c2
->right
.SameAs (panel
, wxRight
, 2);
477 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
480 m_windowCancelButton
->SetConstraints(c2
);
481 leftMostWindow
= m_windowCancelButton
;
483 if (m_windowHelpButton
)
485 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
486 if (leftMostWindow
== panel
)
487 c2
->left
.SameAs (panel
, wxLeft
, 2);
489 c2
->left
.RightOf (leftMostWindow
, 2);
491 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
494 m_windowHelpButton
->SetConstraints(c2
);
495 leftMostWindow
= m_windowHelpButton
;
498 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
504 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
505 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
506 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
519 if (tickBitmap && crossBitmap)
521 m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
522 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
523 m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
524 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
529 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
530 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
531 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
532 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
535 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
536 c
->left
.SameAs (panel
, wxLeft
, 2);
538 if (windowCloseButton)
539 c->top.Below (m_windowCloseButton, 2);
542 c
->top
.SameAs (panel
, wxTop
, 2);
547 m_cancelButton
->SetConstraints(c
);
549 c
= new wxLayoutConstraints
;
550 c
->left
.RightOf (m_cancelButton
, 2);
551 c
->top
.SameAs (m_cancelButton
, wxTop
, 0);
555 m_confirmButton
->SetConstraints(c
);
557 m_cancelButton
->Enable(FALSE
);
558 m_confirmButton
->Enable(FALSE
);
561 if (m_buttonFlags
& wxPROP_PULLDOWN
)
563 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
564 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
565 m_editButton
->Enable(FALSE
);
566 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
569 if (m_windowCloseButton)
570 c->top.Below (m_windowCloseButton, 2);
573 c
->top
.SameAs (panel
, wxTop
, 2);
575 c
->right
.SameAs (panel
, wxRight
, 2);
578 m_editButton
->SetConstraints(c
);
581 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
582 m_valueText
->Enable(FALSE
);
584 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
587 c
->left
.RightOf (m_confirmButton
, 2);
589 c
->left
.SameAs (panel
, wxLeft
, 2);
591 if (m_windowCloseButton)
592 c->top.Below (m_windowCloseButton, 2);
595 c
->top
.SameAs (panel
, wxTop
, 2);
598 c
->right
.LeftOf (m_editButton
, 2);
600 c
->right
.SameAs (panel
, wxRight
, 2);
603 m_valueText
->SetConstraints(c
);
605 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
606 m_valueList
->Show(FALSE
);
608 c
= new wxLayoutConstraints
;
610 c
->left
.SameAs (panel
, wxLeft
, 2);
611 c
->top
.Below (m_valueText
, 2);
612 c
->right
.SameAs (panel
, wxRight
, 2);
613 c
->height
.Absolute(60);
615 m_valueList
->SetConstraints(c
);
617 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
618 wxPoint(-1, -1), wxSize(300, 300));
619 m_propertyScrollingList
->SetFont(* boringFont
);
621 c
= new wxLayoutConstraints
;
623 c
->left
.SameAs (panel
, wxLeft
, 2);
625 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
626 c
->top
.Below (m_valueText
, 2);
628 c
->top
.Below (m_valueList
, 2);
630 c
->right
.SameAs (panel
, wxRight
, 2);
632 if (m_windowCloseButton
)
633 c
->bottom
.Above (m_windowCloseButton
, -2);
635 c
->bottom
.SameAs (panel
, wxBottom
, 2);
637 m_propertyScrollingList
->SetConstraints(c
);
639 // Note: if this is called now, it causes a GPF.
646 void wxPropertyListView::ShowTextControl(bool show
)
649 m_valueText
->Show(show
);
652 void wxPropertyListView::ShowListBoxControl(bool show
)
656 m_valueList
->Show(show
);
657 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
659 wxLayoutConstraints
*constraints
= m_propertyScrollingList
->GetConstraints();
664 constraints
->top
.Below(m_valueList
, 2);
665 // Maintain back-pointer so when valueList is deleted,
666 // any reference to it from this window is removed.
667 m_valueList
->AddConstraintReference(m_propertyScrollingList
);
671 constraints
->top
.Below(m_valueText
, 2);
672 m_valueText
->AddConstraintReference(m_propertyScrollingList
);
674 m_propertyWindow
->Layout();
680 void wxPropertyListView::EnableCheck(bool show
)
683 m_confirmButton
->Enable(show
);
686 void wxPropertyListView::EnableCross(bool show
)
689 m_cancelButton
->Enable(show
);
692 bool wxPropertyListView::OnClose(void)
694 // Retrieve the value if any
695 wxCommandEvent event
;
702 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
704 if (m_currentProperty
&& m_currentValidator
)
706 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
709 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
711 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
715 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
717 // Retrieve the value if any
720 m_managedWindow
->Close(TRUE
);
723 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
725 // SetReturnCode(wxID_CANCEL);
726 m_managedWindow
->Close(TRUE
);
727 sm_dialogCancelled
= TRUE
;
730 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
734 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
736 if (m_currentProperty
)
738 RetrieveProperty(m_currentProperty
);
742 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
744 if (m_currentProperty
&& m_currentValidator
)
746 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
749 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
751 // Revert to old value
752 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
756 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
758 if (m_currentProperty
&& m_currentValidator
)
760 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
763 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
765 // Revert to old value
766 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
770 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
772 if (m_currentProperty
&& m_currentValidator
)
774 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
777 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
779 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
783 void wxPropertyListView::OnText(wxCommandEvent
& event
)
785 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
792 * Property dialog box
795 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
797 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
798 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
799 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
802 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
803 const wxString
& title
, const wxPoint
& pos
,
804 const wxSize
& size
, long style
, const wxString
& name
):
805 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
808 m_view
->AssociatePanel( ((wxPanel
*)this) );
809 m_view
->SetManagedWindow(this);
813 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
817 SetReturnCode(wxID_CANCEL
);
828 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
830 SetReturnCode(wxID_CANCEL
);
834 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(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
*WXUNUSED(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 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
894 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
897 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
902 m_propertyPanel
->SetView(NULL
);
913 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
915 return new wxPropertyListPanel(v
, parent
);
918 bool wxPropertyListFrame::Initialize(void)
920 m_propertyPanel
= OnCreatePanel(this, m_view
);
923 m_view
->AssociatePanel(m_propertyPanel
);
924 m_view
->SetManagedWindow(this);
925 m_propertyPanel
->SetAutoLayout(TRUE
);
933 * Property list specific validator
936 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
938 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
940 // view->GetValueText()->Show(TRUE);
942 OnDisplayValue(property
, view
, parentWindow
);
947 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
949 wxString
s(view
->GetValueList()->GetStringSelection());
952 view
->GetValueText()->SetValue(s
);
953 view
->RetrieveProperty(property
);
958 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
960 // view->GetValueText()->Show(TRUE);
961 wxString
str(property
->GetValue().GetStringRepresentation());
963 view
->GetValueText()->SetValue(str
);
967 // Called when TICK is pressed or focus is lost or view wants to update
968 // the property list.
969 // Does the transferance from the property editing area to the property itself
970 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
972 if (!view
->GetValueText())
977 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
979 if (view
->GetDetailedEditing())
980 view
->EndDetailedEditing();
982 view
->BeginDetailedEditing();
985 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
987 if (view
->GetConfirmButton())
988 view
->GetConfirmButton()->Enable(FALSE
);
989 if (view
->GetCancelButton())
990 view
->GetCancelButton()->Enable(FALSE
);
991 if (view
->GetEditButton())
992 view
->GetEditButton()->Enable(FALSE
);
1000 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
1003 /// Real number validator
1005 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1007 if (m_realMin
== 0.0 && m_realMax
== 0.0)
1010 if (!view
->GetValueText())
1012 wxString
value(view
->GetValueText()->GetValue());
1015 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1018 wxSprintf(buf
, _T("Value %s is not a valid real number!"), value
.GetData());
1019 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1023 if (val
< m_realMin
|| val
> m_realMax
)
1026 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
1027 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1033 // Called when TICK is pressed or focus is lost or view wants to update
1034 // the property list.
1035 // Does the transferance from the property editing area to the property itself
1036 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1038 if (!view
->GetValueText())
1041 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1044 wxString
value(view
->GetValueText()->GetValue());
1045 float f
= (float)wxAtof(value
.GetData());
1046 property
->GetValue() = f
;
1050 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1052 if (view
->GetConfirmButton())
1053 view
->GetConfirmButton()->Enable(TRUE
);
1054 if (view
->GetCancelButton())
1055 view
->GetCancelButton()->Enable(TRUE
);
1056 if (view
->GetEditButton())
1057 view
->GetEditButton()->Enable(FALSE
);
1058 if (view
->GetValueText())
1059 view
->GetValueText()->Enable(TRUE
);
1064 /// Integer validator
1066 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1068 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1070 if (m_integerMin
== 0 && m_integerMax
== 0)
1073 if (!view
->GetValueText())
1075 wxString
value(view
->GetValueText()->GetValue());
1078 if (!StringToLong(WXSTRINGCAST value
, &val
))
1081 wxSprintf(buf
, _T("Value %s is not a valid integer!"), value
.GetData());
1082 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1085 if (val
< m_integerMin
|| val
> m_integerMax
)
1088 wxSprintf(buf
, _T("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
1089 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1095 // Called when TICK is pressed or focus is lost or view wants to update
1096 // the property list.
1097 // Does the transferance from the property editing area to the property itself
1098 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1100 if (!view
->GetValueText())
1103 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1106 wxString
value(view
->GetValueText()->GetValue());
1107 long val
= (long)wxAtoi(value
.GetData());
1108 property
->GetValue() = (long)val
;
1112 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1114 if (view
->GetConfirmButton())
1115 view
->GetConfirmButton()->Enable(TRUE
);
1116 if (view
->GetCancelButton())
1117 view
->GetCancelButton()->Enable(TRUE
);
1118 if (view
->GetEditButton())
1119 view
->GetEditButton()->Enable(FALSE
);
1120 if (view
->GetValueText())
1121 view
->GetValueText()->Enable(TRUE
);
1126 /// boolean validator
1128 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1130 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1132 if (!view
->GetValueText())
1134 wxString
value(view
->GetValueText()->GetValue());
1135 if (value
!= _T("True") && value
!= _T("False"))
1137 wxMessageBox(_T("Value must be True or False!"), _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1143 // Called when TICK is pressed or focus is lost or view wants to update
1144 // the property list.
1145 // Does the transferance from the property editing area to the property itself
1146 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1148 if (!view
->GetValueText())
1151 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1154 wxString
value(view
->GetValueText()->GetValue());
1155 bool boolValue
= FALSE
;
1156 if (value
== _T("True"))
1160 property
->GetValue() = (bool)boolValue
;
1164 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1166 if (!view
->GetValueText())
1168 wxString
str(property
->GetValue().GetStringRepresentation());
1170 view
->GetValueText()->SetValue(str
);
1172 if (view
->GetValueList()->IsShown())
1174 view
->GetValueList()->SetStringSelection(str
);
1179 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1181 if (view
->GetConfirmButton())
1182 view
->GetConfirmButton()->Enable(FALSE
);
1183 if (view
->GetCancelButton())
1184 view
->GetCancelButton()->Enable(FALSE
);
1185 if (view
->GetEditButton())
1186 view
->GetEditButton()->Enable(TRUE
);
1187 if (view
->GetValueText())
1188 view
->GetValueText()->Enable(FALSE
);
1192 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1194 if (view
->GetValueList())
1196 view
->ShowListBoxControl(TRUE
);
1197 view
->GetValueList()->Enable(TRUE
);
1199 view
->GetValueList()->Append(_T("True"));
1200 view
->GetValueList()->Append(_T("False"));
1201 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1202 view
->GetValueList()->SetStringSelection(currentString
);
1203 delete[] currentString
;
1208 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1210 if (view
->GetValueList())
1212 view
->GetValueList()->Clear();
1213 view
->ShowListBoxControl(FALSE
);
1214 view
->GetValueList()->Enable(FALSE
);
1219 // Called when the property is double clicked. Extra functionality can be provided,
1220 // cycling through possible values.
1221 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1223 if (!view
->GetValueText())
1225 if (property
->GetValue().BoolValue())
1226 property
->GetValue() = (bool)FALSE
;
1228 property
->GetValue() = (bool)TRUE
;
1229 view
->DisplayProperty(property
);
1230 view
->UpdatePropertyDisplayInList(property
);
1231 view
->OnPropertyChanged(property
);
1236 /// String validator
1238 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1240 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1241 wxPropertyListValidator(flags
)
1244 // If no constraint, we just allow the string to be edited.
1245 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1246 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1249 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1254 if (!view
->GetValueText())
1256 wxString
value(view
->GetValueText()->GetValue());
1258 if (!m_strings
->Member(value
.GetData()))
1260 wxString
s("Value ");
1261 s
+= value
.GetData();
1262 s
+= " is not valid.";
1263 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1269 // Called when TICK is pressed or focus is lost or view wants to update
1270 // the property list.
1271 // Does the transferance from the property editing area to the property itself
1272 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1274 if (!view
->GetValueText())
1276 wxString
value(view
->GetValueText()->GetValue());
1277 property
->GetValue() = value
;
1281 // Called when TICK is pressed or focus is lost or view wants to update
1282 // the property list.
1283 // Does the transferance from the property editing area to the property itself
1284 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1286 if (!view
->GetValueText())
1288 wxString
str(property
->GetValue().GetStringRepresentation());
1289 view
->GetValueText()->SetValue(str
);
1290 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1292 view
->GetValueList()->SetStringSelection(str
);
1297 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1302 if (view
->GetEditButton())
1303 view
->GetEditButton()->Enable(FALSE
);
1304 if (view
->GetConfirmButton())
1305 view
->GetConfirmButton()->Enable(TRUE
);
1306 if (view
->GetCancelButton())
1307 view
->GetCancelButton()->Enable(TRUE
);
1308 if (view
->GetValueText())
1309 view
->GetValueText()->Enable(TRUE
);
1314 if (view
->GetValueText())
1315 view
->GetValueText()->Enable(FALSE
);
1317 if (view
->GetEditButton())
1318 view
->GetEditButton()->Enable(TRUE
);
1320 if (view
->GetConfirmButton())
1321 view
->GetConfirmButton()->Enable(FALSE
);
1322 if (view
->GetCancelButton())
1323 view
->GetCancelButton()->Enable(FALSE
);
1327 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1329 if (view
->GetValueList())
1331 view
->ShowListBoxControl(TRUE
);
1332 view
->GetValueList()->Enable(TRUE
);
1333 wxNode
*node
= m_strings
->First();
1336 wxChar
*s
= (wxChar
*)node
->Data();
1337 view
->GetValueList()->Append(s
);
1338 node
= node
->Next();
1340 wxChar
*currentString
= property
->GetValue().StringValue();
1341 view
->GetValueList()->SetStringSelection(currentString
);
1346 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1353 if (view
->GetValueList())
1355 view
->GetValueList()->Clear();
1356 view
->ShowListBoxControl(FALSE
);
1357 view
->GetValueList()->Enable(FALSE
);
1362 // Called when the property is double clicked. Extra functionality can be provided,
1363 // cycling through possible values.
1364 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1366 if (!view
->GetValueText())
1371 wxNode
*node
= m_strings
->First();
1372 wxChar
*currentString
= property
->GetValue().StringValue();
1375 wxChar
*s
= (wxChar
*)node
->Data();
1376 if (wxStrcmp(s
, currentString
) == 0)
1378 wxChar
*nextString
= NULL
;
1380 nextString
= (wxChar
*)node
->Next()->Data();
1382 nextString
= (wxChar
*)m_strings
->First()->Data();
1383 property
->GetValue() = wxString(nextString
);
1384 view
->DisplayProperty(property
);
1385 view
->UpdatePropertyDisplayInList(property
);
1386 view
->OnPropertyChanged(property
);
1389 else node
= node
->Next();
1395 /// Filename validator
1397 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1399 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1400 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1404 wxFilenameListValidator::~wxFilenameListValidator(void)
1408 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1413 // Called when TICK is pressed or focus is lost or view wants to update
1414 // the property list.
1415 // Does the transferance from the property editing area to the property itself
1416 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1418 if (!view
->GetValueText())
1420 wxString
value(view
->GetValueText()->GetValue());
1421 property
->GetValue() = value
;
1425 // Called when TICK is pressed or focus is lost or view wants to update
1426 // the property list.
1427 // Does the transferance from the property editing area to the property itself
1428 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1430 if (!view
->GetValueText())
1432 wxString
str(property
->GetValue().GetStringRepresentation());
1433 view
->GetValueText()->SetValue(str
);
1437 // Called when the property is double clicked. Extra functionality can be provided,
1438 // cycling through possible values.
1439 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1441 if (!view
->GetValueText())
1443 OnEdit(property
, view
, parentWindow
);
1447 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1449 if (view
->GetConfirmButton())
1450 view
->GetConfirmButton()->Enable(TRUE
);
1451 if (view
->GetCancelButton())
1452 view
->GetCancelButton()->Enable(TRUE
);
1453 if (view
->GetEditButton())
1454 view
->GetEditButton()->Enable(TRUE
);
1455 if (view
->GetValueText())
1456 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1460 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1462 if (!view
->GetValueText())
1465 wxString s
= wxFileSelector(
1466 m_filenameMessage
.GetData(),
1467 wxPathOnly(property
->GetValue().StringValue()),
1468 wxFileNameFromPath(property
->GetValue().StringValue()),
1470 m_filenameWildCard
.GetData(),
1475 property
->GetValue() = s
;
1476 view
->DisplayProperty(property
);
1477 view
->UpdatePropertyDisplayInList(property
);
1478 view
->OnPropertyChanged(property
);
1483 /// Colour validator
1485 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1487 wxColourListValidator::wxColourListValidator(long flags
):
1488 wxPropertyListValidator(flags
)
1492 wxColourListValidator::~wxColourListValidator(void)
1496 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1501 // Called when TICK is pressed or focus is lost or view wants to update
1502 // the property list.
1503 // Does the transferance from the property editing area to the property itself
1504 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1506 if (!view
->GetValueText())
1508 wxString
value(view
->GetValueText()->GetValue());
1510 property
->GetValue() = value
;
1514 // Called when TICK is pressed or focus is lost or view wants to update
1515 // the property list.
1516 // Does the transferance from the property editing area to the property itself
1517 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1519 if (!view
->GetValueText())
1521 wxString
str(property
->GetValue().GetStringRepresentation());
1522 view
->GetValueText()->SetValue(str
);
1526 // Called when the property is double clicked. Extra functionality can be provided,
1527 // cycling through possible values.
1528 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1530 if (!view
->GetValueText())
1532 OnEdit(property
, view
, parentWindow
);
1536 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1538 if (view
->GetConfirmButton())
1539 view
->GetConfirmButton()->Enable(TRUE
);
1540 if (view
->GetCancelButton())
1541 view
->GetCancelButton()->Enable(TRUE
);
1542 if (view
->GetEditButton())
1543 view
->GetEditButton()->Enable(TRUE
);
1544 if (view
->GetValueText())
1545 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1549 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1551 if (!view
->GetValueText())
1554 wxChar
*s
= property
->GetValue().StringValue();
1561 g
= wxHexToDec(s
+2);
1562 b
= wxHexToDec(s
+4);
1565 wxColour
col(r
,g
,b
);
1568 data
.SetChooseFull(TRUE
);
1569 data
.SetColour(col
);
1571 for (int i
= 0; i
< 16; i
++)
1573 wxColour
colour(i
*16, i
*16, i
*16);
1574 data
.SetCustomColour(i
, colour
);
1577 wxColourDialog
dialog(parentWindow
, &data
);
1578 if (dialog
.ShowModal() != wxID_CANCEL
)
1580 wxColourData retData
= dialog
.GetColourData();
1581 col
= retData
.GetColour();
1584 wxDecToHex(col
.Red(), buf
);
1585 wxDecToHex(col
.Green(), buf
+2);
1586 wxDecToHex(col
.Blue(), buf
+4);
1588 property
->GetValue() = wxString(buf
);
1589 view
->DisplayProperty(property
);
1590 view
->UpdatePropertyDisplayInList(property
);
1591 view
->OnPropertyChanged(property
);
1596 /// List of strings validator. For this we need more user interface than
1597 /// we get with a property list; so create a new dialog for editing the list.
1599 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1601 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1602 wxPropertyListValidator(flags
)
1606 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1608 // No constraints for an arbitrary, user-editable list of strings.
1612 // Called when TICK is pressed or focus is lost or view wants to update
1613 // the property list.
1614 // Does the transferance from the property editing area to the property itself.
1615 // In this case, the user cannot directly edit the string list.
1616 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1621 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1623 if (!view
->GetValueText())
1625 wxString
str(property
->GetValue().GetStringRepresentation());
1626 view
->GetValueText()->SetValue(str
);
1630 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1632 if (view
->GetEditButton())
1633 view
->GetEditButton()->Enable(TRUE
);
1634 if (view
->GetValueText())
1635 view
->GetValueText()->Enable(FALSE
);
1637 if (view
->GetConfirmButton())
1638 view
->GetConfirmButton()->Enable(FALSE
);
1639 if (view
->GetCancelButton())
1640 view
->GetCancelButton()->Enable(FALSE
);
1644 // Called when the property is double clicked. Extra functionality can be provided,
1645 // cycling through possible values.
1646 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1648 OnEdit(property
, view
, parentWindow
);
1652 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1654 // Convert property value to a list of strings for editing
1655 wxStringList
*stringList
= new wxStringList
;
1657 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1660 wxChar
*s
= expr
->StringValue();
1663 expr
= expr
->GetNext();
1666 wxString
title(_T("Editing "));
1667 title
+= property
->GetName();
1669 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1671 wxPropertyValue
& oldValue
= property
->GetValue();
1672 oldValue
.ClearList();
1673 wxNode
*node
= stringList
->First();
1676 wxChar
*s
= (wxChar
*)node
->Data();
1677 oldValue
.Append(new wxPropertyValue(s
));
1679 node
= node
->Next();
1682 view
->DisplayProperty(property
);
1683 view
->UpdatePropertyDisplayInList(property
);
1684 view
->OnPropertyChanged(property
);
1689 class wxPropertyStringListEditorDialog
: public wxDialog
1692 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1693 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1694 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1695 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1697 m_stringList
= NULL
;
1698 m_stringText
= NULL
;
1700 sm_dialogCancelled
= FALSE
;
1701 m_currentSelection
= -1;
1703 ~wxPropertyStringListEditorDialog(void) {}
1704 void OnCloseWindow(wxCloseEvent
& event
);
1705 void SaveCurrentSelection(void);
1706 void ShowCurrentSelection(void);
1708 void OnOK(wxCommandEvent
& event
);
1709 void OnCancel(wxCommandEvent
& event
);
1710 void OnAdd(wxCommandEvent
& event
);
1711 void OnDelete(wxCommandEvent
& event
);
1712 void OnStrings(wxCommandEvent
& event
);
1713 void OnText(wxCommandEvent
& event
);
1716 wxStringList
* m_stringList
;
1717 wxListBox
* m_listBox
;
1718 wxTextCtrl
* m_stringText
;
1719 static bool sm_dialogCancelled
;
1720 int m_currentSelection
;
1721 DECLARE_EVENT_TABLE()
1724 #define wxID_PROP_SL_ADD 3000
1725 #define wxID_PROP_SL_DELETE 3001
1726 #define wxID_PROP_SL_STRINGS 3002
1727 #define wxID_PROP_SL_TEXT 3003
1729 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1730 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1731 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1732 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1733 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1734 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1735 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1736 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1739 class wxPropertyStringListEditorText
: public wxTextCtrl
1742 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1743 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1744 long windowStyle
= 0, const wxString
& name
= "text"):
1745 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1748 void OnKillFocus(void)
1750 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1751 dialog
->SaveCurrentSelection();
1755 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1757 // Edit the string list.
1758 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1760 int largeButtonWidth
= 60;
1761 int largeButtonHeight
= 25;
1763 wxBeginBusyCursor();
1764 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1765 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1767 dialog
->m_stringList
= stringList
;
1769 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1770 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1772 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1773 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1774 wxSize(300, -1), wxPROCESS_ENTER
);
1775 dialog
->m_stringText
->Enable(FALSE
);
1777 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1778 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1779 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1780 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1782 okButton
->SetDefault();
1784 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1786 c
->top
.SameAs (dialog
, wxTop
, 2);
1787 c
->left
.SameAs (dialog
, wxLeft
, 2);
1788 c
->right
.SameAs (dialog
, wxRight
, 2);
1789 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1790 dialog
->m_listBox
->SetConstraints(c
);
1792 c
= new wxLayoutConstraints
;
1793 c
->left
.SameAs (dialog
, wxLeft
, 2);
1794 c
->right
.SameAs (dialog
, wxRight
, 2);
1795 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1797 dialog
->m_stringText
->SetConstraints(c
);
1799 c
= new wxLayoutConstraints
;
1800 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1801 c
->left
.SameAs (dialog
, wxLeft
, 2);
1804 addButton
->SetConstraints(c
);
1806 c
= new wxLayoutConstraints
;
1807 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1808 c
->left
.SameAs (addButton
, wxRight
, 2);
1811 deleteButton
->SetConstraints(c
);
1813 c
= new wxLayoutConstraints
;
1814 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1815 c
->right
.SameAs (dialog
, wxRight
, 2);
1818 cancelButton
->SetConstraints(c
);
1820 c
= new wxLayoutConstraints
;
1821 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1822 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1825 okButton
->SetConstraints(c
);
1827 wxNode
*node
= stringList
->First();
1830 char *str
= (char *)node
->Data();
1831 // Save node as client data for each listbox item
1832 dialog
->m_listBox
->Append(str
, (char *)node
);
1833 node
= node
->Next();
1836 dialog
->SetClientSize(310, 305);
1839 dialog
->Centre(wxBOTH
);
1841 if (dialog
->ShowModal() == wxID_CANCEL
)
1848 * String list editor callbacks
1852 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1854 int sel
= m_listBox
->GetSelection();
1857 m_currentSelection
= sel
;
1859 ShowCurrentSelection();
1863 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1865 int sel
= m_listBox
->GetSelection();
1869 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1873 m_listBox
->Delete(sel
);
1874 delete[] (wxChar
*)node
->Data();
1876 m_currentSelection
= -1;
1877 m_stringText
->SetValue("");
1880 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1882 SaveCurrentSelection();
1884 wxChar
*initialText
= _T("");
1885 wxNode
*node
= m_stringList
->Add(initialText
);
1886 m_listBox
->Append(initialText
, (void *)node
);
1887 m_currentSelection
= m_stringList
->Number() - 1;
1888 m_listBox
->SetSelection(m_currentSelection
);
1889 ShowCurrentSelection();
1890 m_stringText
->SetFocus();
1893 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1895 SaveCurrentSelection();
1901 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1903 sm_dialogCancelled
= TRUE
;
1904 EndModal(wxID_CANCEL
);
1909 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1911 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1913 SaveCurrentSelection();
1917 void wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& event
)
1919 SaveCurrentSelection();
1923 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1925 if (m_currentSelection
== -1)
1928 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1932 wxString
txt(m_stringText
->GetValue());
1934 delete[] (char *)node
->Data();
1935 node
->SetData((wxObject
*)copystring(txt
));
1937 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1940 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1942 if (m_currentSelection
== -1)
1944 m_stringText
->SetValue("");
1947 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1948 char *txt
= (char *)node
->Data();
1949 m_stringText
->SetValue(txt
);
1950 m_stringText
->Enable(TRUE
);