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
));
149 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
155 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
157 if (!m_propertyScrollingList
|| !m_propertySheet
)
161 int currentlySelected
= m_propertyScrollingList
->GetSelection();
164 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
165 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
166 int sel
= FindListIndexForProperty(property
);
170 // Don't update the listbox unnecessarily because it can cause
173 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
174 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
177 // UpdatePropertyList(FALSE);
180 // TODO: why is this necessary?
182 if (currentlySelected
> -1)
183 m_propertyScrollingList
->SetSelection(currentlySelected
);
189 // Find the wxListBox index corresponding to this property
190 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
192 int n
= m_propertyScrollingList
->Number();
193 for (int i
= 0; i
< n
; i
++)
195 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
201 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
203 wxString
theString(name
);
206 int padWith
= nameWidth
- theString
.Length();
210 if (GetFlags() & wxPROP_SHOWVALUES
)
212 // Want to pad with spaces
213 theString
.Append(' ', padWith
);
220 // Select and show string representation in validator the given
221 // property. NULL resets to show no property.
222 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
224 if (m_currentProperty
)
226 EndShowingProperty(m_currentProperty
);
227 m_currentProperty
= NULL
;
230 m_valueList
->Clear();
231 m_valueText
->SetValue("");
235 m_currentProperty
= property
;
236 BeginShowingProperty(property
);
240 int sel
= FindListIndexForProperty(property
);
242 m_propertyScrollingList
->SetSelection(sel
);
247 // Find appropriate validator and load property into value controls
248 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
250 m_currentValidator
= FindPropertyValidator(property
);
251 if (!m_currentValidator
)
254 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
257 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
259 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
260 DisplayProperty(property
);
264 // Find appropriate validator and unload property from value controls
265 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
267 if (!m_currentValidator
)
270 RetrieveProperty(property
);
272 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
275 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
277 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
278 if (m_detailedEditing
)
280 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
281 m_detailedEditing
= FALSE
;
286 void wxPropertyListView::BeginDetailedEditing(void)
288 if (!m_currentValidator
)
290 if (!m_currentProperty
)
292 if (m_detailedEditing
)
294 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
296 if (!m_currentProperty
->IsEnabled())
299 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
301 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
302 m_detailedEditing
= TRUE
;
305 void wxPropertyListView::EndDetailedEditing(void)
307 if (!m_currentValidator
)
309 if (!m_currentProperty
)
312 RetrieveProperty(m_currentProperty
);
314 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
317 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
319 if (m_detailedEditing
)
321 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
322 m_detailedEditing
= FALSE
;
326 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
328 if (!m_currentValidator
)
331 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
332 m_valueText
->SetEditable(FALSE
);
334 m_valueText
->SetEditable(TRUE
);
336 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
339 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
341 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
345 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
347 if (!m_currentValidator
)
349 if (!property
->IsEnabled())
352 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
355 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
357 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
359 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
361 UpdatePropertyDisplayInList(property
);
362 OnPropertyChanged(property
);
367 // Revert to old value
368 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
374 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
379 // Called by the listbox callback
380 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
382 int sel
= m_propertyScrollingList
->GetSelection();
385 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
386 if (newSel
&& newSel
!= m_currentProperty
)
388 ShowProperty(newSel
, FALSE
);
393 bool wxPropertyListView::CreateControls(void)
395 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
397 int largeButtonWidth
= 60;
398 int largeButtonHeight
= 25;
400 int smallButtonWidth
= 25;
401 int smallButtonHeight
= 20;
403 // XView must be allowed to choose its own sized buttons
405 largeButtonWidth
= -1;
406 largeButtonHeight
= -1;
408 smallButtonWidth
= -1;
409 smallButtonHeight
= -1;
418 wxWindow
*leftMostWindow
= panel
;
420 wxWindow *topMostWindow = panel;
421 wxWindow *rightMostWindow = panel;
424 wxSystemSettings settings
;
425 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
428 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
430 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
433 // May need to be changed in future to eliminate clashes with app.
434 // WHAT WAS THIS FOR?
435 // panel->SetClientData((char *)this);
437 // These buttons are at the bottom of the window, but create them now
438 // so the constraints are evaluated in the correct order
439 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
441 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
442 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
443 m_windowCloseButton
->SetDefault();
444 m_windowCloseButton
->SetFocus();
446 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
448 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
449 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
451 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
453 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
454 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
456 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
458 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
459 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
462 if (m_windowCloseButton
)
464 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
466 c1
->left
.SameAs (panel
, wxLeft
, 2);
467 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
470 m_windowCloseButton
->SetConstraints(c1
);
471 leftMostWindow
= m_windowCloseButton
;
473 if (m_windowCancelButton
)
475 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
477 c2
->right
.SameAs (panel
, wxRight
, 2);
478 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
481 m_windowCancelButton
->SetConstraints(c2
);
482 leftMostWindow
= m_windowCancelButton
;
484 if (m_windowHelpButton
)
486 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
487 if (leftMostWindow
== panel
)
488 c2
->left
.SameAs (panel
, wxLeft
, 2);
490 c2
->left
.RightOf (leftMostWindow
, 2);
492 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
495 m_windowHelpButton
->SetConstraints(c2
);
496 leftMostWindow
= m_windowHelpButton
;
499 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
505 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
506 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
507 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
520 if (tickBitmap && crossBitmap)
522 m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
523 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
524 m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
525 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
530 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
531 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
532 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
533 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
536 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
537 c
->left
.SameAs (panel
, wxLeft
, 2);
539 if (windowCloseButton)
540 c->top.Below (m_windowCloseButton, 2);
543 c
->top
.SameAs (panel
, wxTop
, 2);
548 m_cancelButton
->SetConstraints(c
);
550 c
= new wxLayoutConstraints
;
551 c
->left
.RightOf (m_cancelButton
, 2);
552 c
->top
.SameAs (m_cancelButton
, wxTop
, 0);
556 m_confirmButton
->SetConstraints(c
);
558 m_cancelButton
->Enable(FALSE
);
559 m_confirmButton
->Enable(FALSE
);
562 if (m_buttonFlags
& wxPROP_PULLDOWN
)
564 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
565 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
566 m_editButton
->Enable(FALSE
);
567 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
570 if (m_windowCloseButton)
571 c->top.Below (m_windowCloseButton, 2);
574 c
->top
.SameAs (panel
, wxTop
, 2);
576 c
->right
.SameAs (panel
, wxRight
, 2);
579 m_editButton
->SetConstraints(c
);
582 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
583 m_valueText
->Enable(FALSE
);
585 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
588 c
->left
.RightOf (m_confirmButton
, 2);
590 c
->left
.SameAs (panel
, wxLeft
, 2);
592 if (m_windowCloseButton)
593 c->top.Below (m_windowCloseButton, 2);
596 c
->top
.SameAs (panel
, wxTop
, 2);
599 c
->right
.LeftOf (m_editButton
, 2);
601 c
->right
.SameAs (panel
, wxRight
, 2);
604 m_valueText
->SetConstraints(c
);
606 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
607 m_valueList
->Show(FALSE
);
609 c
= new wxLayoutConstraints
;
611 c
->left
.SameAs (panel
, wxLeft
, 2);
612 c
->top
.Below (m_valueText
, 2);
613 c
->right
.SameAs (panel
, wxRight
, 2);
614 c
->height
.Absolute(60);
616 m_valueList
->SetConstraints(c
);
618 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
619 wxPoint(-1, -1), wxSize(300, 300));
620 m_propertyScrollingList
->SetFont(* boringFont
);
622 c
= new wxLayoutConstraints
;
624 c
->left
.SameAs (panel
, wxLeft
, 2);
626 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
627 c
->top
.Below (m_valueText
, 2);
629 c
->top
.Below (m_valueList
, 2);
631 c
->right
.SameAs (panel
, wxRight
, 2);
633 if (m_windowCloseButton
)
634 c
->bottom
.Above (m_windowCloseButton
, -2);
636 c
->bottom
.SameAs (panel
, wxBottom
, 2);
638 m_propertyScrollingList
->SetConstraints(c
);
640 // Note: if this is called now, it causes a GPF.
647 void wxPropertyListView::ShowTextControl(bool show
)
650 m_valueText
->Show(show
);
653 void wxPropertyListView::ShowListBoxControl(bool show
)
657 m_valueList
->Show(show
);
658 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
660 wxLayoutConstraints
*constraints
= m_propertyScrollingList
->GetConstraints();
665 constraints
->top
.Below(m_valueList
, 2);
666 // Maintain back-pointer so when valueList is deleted,
667 // any reference to it from this window is removed.
668 m_valueList
->AddConstraintReference(m_propertyScrollingList
);
672 constraints
->top
.Below(m_valueText
, 2);
673 m_valueText
->AddConstraintReference(m_propertyScrollingList
);
675 m_propertyWindow
->Layout();
681 void wxPropertyListView::EnableCheck(bool show
)
684 m_confirmButton
->Enable(show
);
687 void wxPropertyListView::EnableCross(bool show
)
690 m_cancelButton
->Enable(show
);
693 bool wxPropertyListView::OnClose(void)
695 // Retrieve the value if any
696 wxCommandEvent event
;
703 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
705 if (m_currentProperty
&& m_currentValidator
)
707 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
710 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
712 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
716 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
718 // Retrieve the value if any
721 m_managedWindow
->Close(TRUE
);
724 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
726 // SetReturnCode(wxID_CANCEL);
727 m_managedWindow
->Close(TRUE
);
728 sm_dialogCancelled
= TRUE
;
731 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
735 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
737 if (m_currentProperty
)
739 RetrieveProperty(m_currentProperty
);
743 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
745 if (m_currentProperty
&& m_currentValidator
)
747 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
750 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
752 // Revert to old value
753 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
757 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
759 if (m_currentProperty
&& m_currentValidator
)
761 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
764 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
766 // Revert to old value
767 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
771 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
773 if (m_currentProperty
&& m_currentValidator
)
775 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
778 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
780 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
784 void wxPropertyListView::OnText(wxCommandEvent
& event
)
786 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
793 * Property dialog box
796 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
798 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
799 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
800 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
803 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
804 const wxString
& title
, const wxPoint
& pos
,
805 const wxSize
& size
, long style
, const wxString
& name
):
806 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
809 m_view
->AssociatePanel( ((wxPanel
*)this) );
810 m_view
->SetManagedWindow(this);
814 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
818 SetReturnCode(wxID_CANCEL
);
829 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
831 SetReturnCode(wxID_CANCEL
);
835 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
838 if (item == m_view->GetPropertyScrollingList())
839 view->OnDoubleClick();
843 // Extend event processing to search the view's event table
844 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
846 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
847 return wxEvtHandler::ProcessEvent(event
);
856 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
858 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
859 EVT_SIZE(wxPropertyListPanel::OnSize
)
862 wxPropertyListPanel::~wxPropertyListPanel()
866 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
869 if (item == view->GetPropertyScrollingList())
870 view->OnDoubleClick();
874 // Extend event processing to search the view's event table
875 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
877 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
878 return wxEvtHandler::ProcessEvent(event
);
883 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
892 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
894 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
895 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
898 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
903 m_propertyPanel
->SetView(NULL
);
914 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
916 return new wxPropertyListPanel(v
, parent
);
919 bool wxPropertyListFrame::Initialize(void)
921 m_propertyPanel
= OnCreatePanel(this, m_view
);
924 m_view
->AssociatePanel(m_propertyPanel
);
925 m_view
->SetManagedWindow(this);
926 m_propertyPanel
->SetAutoLayout(TRUE
);
934 * Property list specific validator
937 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
939 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
941 // view->GetValueText()->Show(TRUE);
943 OnDisplayValue(property
, view
, parentWindow
);
948 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
950 wxString
s(view
->GetValueList()->GetStringSelection());
953 view
->GetValueText()->SetValue(s
);
954 view
->RetrieveProperty(property
);
959 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
961 // view->GetValueText()->Show(TRUE);
962 wxString
str(property
->GetValue().GetStringRepresentation());
964 view
->GetValueText()->SetValue(str
);
968 // Called when TICK is pressed or focus is lost or view wants to update
969 // the property list.
970 // Does the transferance from the property editing area to the property itself
971 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
973 if (!view
->GetValueText())
978 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
980 if (view
->GetDetailedEditing())
981 view
->EndDetailedEditing();
983 view
->BeginDetailedEditing();
986 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
988 if (view
->GetConfirmButton())
989 view
->GetConfirmButton()->Enable(FALSE
);
990 if (view
->GetCancelButton())
991 view
->GetCancelButton()->Enable(FALSE
);
992 if (view
->GetEditButton())
993 view
->GetEditButton()->Enable(FALSE
);
1001 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
1004 /// Real number validator
1006 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1008 if (m_realMin
== 0.0 && m_realMax
== 0.0)
1011 if (!view
->GetValueText())
1013 wxString
value(view
->GetValueText()->GetValue());
1016 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1019 wxSprintf(buf
, _T("Value %s is not a valid real number!"), value
.GetData());
1020 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1024 if (val
< m_realMin
|| val
> m_realMax
)
1027 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
1028 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1034 // Called when TICK is pressed or focus is lost or view wants to update
1035 // the property list.
1036 // Does the transferance from the property editing area to the property itself
1037 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1039 if (!view
->GetValueText())
1042 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1045 wxString
value(view
->GetValueText()->GetValue());
1046 float f
= (float)wxAtof(value
.GetData());
1047 property
->GetValue() = f
;
1051 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1053 if (view
->GetConfirmButton())
1054 view
->GetConfirmButton()->Enable(TRUE
);
1055 if (view
->GetCancelButton())
1056 view
->GetCancelButton()->Enable(TRUE
);
1057 if (view
->GetEditButton())
1058 view
->GetEditButton()->Enable(FALSE
);
1059 if (view
->GetValueText())
1060 view
->GetValueText()->Enable(TRUE
);
1065 /// Integer validator
1067 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1069 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1071 if (m_integerMin
== 0 && m_integerMax
== 0)
1074 if (!view
->GetValueText())
1076 wxString
value(view
->GetValueText()->GetValue());
1079 if (!StringToLong(WXSTRINGCAST value
, &val
))
1082 wxSprintf(buf
, _T("Value %s is not a valid integer!"), value
.GetData());
1083 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1086 if (val
< m_integerMin
|| val
> m_integerMax
)
1089 wxSprintf(buf
, _T("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
1090 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1096 // Called when TICK is pressed or focus is lost or view wants to update
1097 // the property list.
1098 // Does the transferance from the property editing area to the property itself
1099 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1101 if (!view
->GetValueText())
1104 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1107 wxString
value(view
->GetValueText()->GetValue());
1108 long val
= (long)wxAtoi(value
.GetData());
1109 property
->GetValue() = (long)val
;
1113 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1115 if (view
->GetConfirmButton())
1116 view
->GetConfirmButton()->Enable(TRUE
);
1117 if (view
->GetCancelButton())
1118 view
->GetCancelButton()->Enable(TRUE
);
1119 if (view
->GetEditButton())
1120 view
->GetEditButton()->Enable(FALSE
);
1121 if (view
->GetValueText())
1122 view
->GetValueText()->Enable(TRUE
);
1127 /// boolean validator
1129 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1131 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1133 if (!view
->GetValueText())
1135 wxString
value(view
->GetValueText()->GetValue());
1136 if (value
!= _T("True") && value
!= _T("False"))
1138 wxMessageBox(_T("Value must be True or False!"), _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1144 // Called when TICK is pressed or focus is lost or view wants to update
1145 // the property list.
1146 // Does the transferance from the property editing area to the property itself
1147 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1149 if (!view
->GetValueText())
1152 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1155 wxString
value(view
->GetValueText()->GetValue());
1156 bool boolValue
= FALSE
;
1157 if (value
== _T("True"))
1161 property
->GetValue() = (bool)boolValue
;
1165 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1167 if (!view
->GetValueText())
1169 wxString
str(property
->GetValue().GetStringRepresentation());
1171 view
->GetValueText()->SetValue(str
);
1173 if (view
->GetValueList()->IsShown())
1175 view
->GetValueList()->SetStringSelection(str
);
1180 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1182 if (view
->GetConfirmButton())
1183 view
->GetConfirmButton()->Enable(FALSE
);
1184 if (view
->GetCancelButton())
1185 view
->GetCancelButton()->Enable(FALSE
);
1186 if (view
->GetEditButton())
1187 view
->GetEditButton()->Enable(TRUE
);
1188 if (view
->GetValueText())
1189 view
->GetValueText()->Enable(FALSE
);
1193 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1195 if (view
->GetValueList())
1197 view
->ShowListBoxControl(TRUE
);
1198 view
->GetValueList()->Enable(TRUE
);
1200 view
->GetValueList()->Append(_T("True"));
1201 view
->GetValueList()->Append(_T("False"));
1202 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1203 view
->GetValueList()->SetStringSelection(currentString
);
1204 delete[] currentString
;
1209 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1211 if (view
->GetValueList())
1213 view
->GetValueList()->Clear();
1214 view
->ShowListBoxControl(FALSE
);
1215 view
->GetValueList()->Enable(FALSE
);
1220 // Called when the property is double clicked. Extra functionality can be provided,
1221 // cycling through possible values.
1222 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1224 if (!view
->GetValueText())
1226 if (property
->GetValue().BoolValue())
1227 property
->GetValue() = (bool)FALSE
;
1229 property
->GetValue() = (bool)TRUE
;
1230 view
->DisplayProperty(property
);
1231 view
->UpdatePropertyDisplayInList(property
);
1232 view
->OnPropertyChanged(property
);
1237 /// String validator
1239 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1241 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1242 wxPropertyListValidator(flags
)
1245 // If no constraint, we just allow the string to be edited.
1246 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1247 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1250 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1255 if (!view
->GetValueText())
1257 wxString
value(view
->GetValueText()->GetValue());
1259 if (!m_strings
->Member(value
.GetData()))
1261 wxString
s("Value ");
1262 s
+= value
.GetData();
1263 s
+= " is not valid.";
1264 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1270 // Called when TICK is pressed or focus is lost or view wants to update
1271 // the property list.
1272 // Does the transferance from the property editing area to the property itself
1273 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1275 if (!view
->GetValueText())
1277 wxString
value(view
->GetValueText()->GetValue());
1278 property
->GetValue() = value
;
1282 // Called when TICK is pressed or focus is lost or view wants to update
1283 // the property list.
1284 // Does the transferance from the property editing area to the property itself
1285 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1287 if (!view
->GetValueText())
1289 wxString
str(property
->GetValue().GetStringRepresentation());
1290 view
->GetValueText()->SetValue(str
);
1291 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1293 view
->GetValueList()->SetStringSelection(str
);
1298 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1303 if (view
->GetEditButton())
1304 view
->GetEditButton()->Enable(FALSE
);
1305 if (view
->GetConfirmButton())
1306 view
->GetConfirmButton()->Enable(TRUE
);
1307 if (view
->GetCancelButton())
1308 view
->GetCancelButton()->Enable(TRUE
);
1309 if (view
->GetValueText())
1310 view
->GetValueText()->Enable(TRUE
);
1315 if (view
->GetValueText())
1316 view
->GetValueText()->Enable(FALSE
);
1318 if (view
->GetEditButton())
1319 view
->GetEditButton()->Enable(TRUE
);
1321 if (view
->GetConfirmButton())
1322 view
->GetConfirmButton()->Enable(FALSE
);
1323 if (view
->GetCancelButton())
1324 view
->GetCancelButton()->Enable(FALSE
);
1328 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1330 if (view
->GetValueList())
1332 view
->ShowListBoxControl(TRUE
);
1333 view
->GetValueList()->Enable(TRUE
);
1334 wxNode
*node
= m_strings
->First();
1337 wxChar
*s
= (wxChar
*)node
->Data();
1338 view
->GetValueList()->Append(s
);
1339 node
= node
->Next();
1341 wxChar
*currentString
= property
->GetValue().StringValue();
1342 view
->GetValueList()->SetStringSelection(currentString
);
1347 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1354 if (view
->GetValueList())
1356 view
->GetValueList()->Clear();
1357 view
->ShowListBoxControl(FALSE
);
1358 view
->GetValueList()->Enable(FALSE
);
1363 // Called when the property is double clicked. Extra functionality can be provided,
1364 // cycling through possible values.
1365 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1367 if (!view
->GetValueText())
1372 wxNode
*node
= m_strings
->First();
1373 wxChar
*currentString
= property
->GetValue().StringValue();
1376 wxChar
*s
= (wxChar
*)node
->Data();
1377 if (wxStrcmp(s
, currentString
) == 0)
1379 wxChar
*nextString
= NULL
;
1381 nextString
= (wxChar
*)node
->Next()->Data();
1383 nextString
= (wxChar
*)m_strings
->First()->Data();
1384 property
->GetValue() = wxString(nextString
);
1385 view
->DisplayProperty(property
);
1386 view
->UpdatePropertyDisplayInList(property
);
1387 view
->OnPropertyChanged(property
);
1390 else node
= node
->Next();
1396 /// Filename validator
1398 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1400 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1401 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1405 wxFilenameListValidator::~wxFilenameListValidator(void)
1409 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1414 // Called when TICK is pressed or focus is lost or view wants to update
1415 // the property list.
1416 // Does the transferance from the property editing area to the property itself
1417 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1419 if (!view
->GetValueText())
1421 wxString
value(view
->GetValueText()->GetValue());
1422 property
->GetValue() = value
;
1426 // Called when TICK is pressed or focus is lost or view wants to update
1427 // the property list.
1428 // Does the transferance from the property editing area to the property itself
1429 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1431 if (!view
->GetValueText())
1433 wxString
str(property
->GetValue().GetStringRepresentation());
1434 view
->GetValueText()->SetValue(str
);
1438 // Called when the property is double clicked. Extra functionality can be provided,
1439 // cycling through possible values.
1440 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1442 if (!view
->GetValueText())
1444 OnEdit(property
, view
, parentWindow
);
1448 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1450 if (view
->GetConfirmButton())
1451 view
->GetConfirmButton()->Enable(TRUE
);
1452 if (view
->GetCancelButton())
1453 view
->GetCancelButton()->Enable(TRUE
);
1454 if (view
->GetEditButton())
1455 view
->GetEditButton()->Enable(TRUE
);
1456 if (view
->GetValueText())
1457 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1461 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1463 if (!view
->GetValueText())
1466 wxString s
= wxFileSelector(
1467 m_filenameMessage
.GetData(),
1468 wxPathOnly(property
->GetValue().StringValue()),
1469 wxFileNameFromPath(property
->GetValue().StringValue()),
1471 m_filenameWildCard
.GetData(),
1476 property
->GetValue() = s
;
1477 view
->DisplayProperty(property
);
1478 view
->UpdatePropertyDisplayInList(property
);
1479 view
->OnPropertyChanged(property
);
1484 /// Colour validator
1486 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1488 wxColourListValidator::wxColourListValidator(long flags
):
1489 wxPropertyListValidator(flags
)
1493 wxColourListValidator::~wxColourListValidator(void)
1497 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1502 // Called when TICK is pressed or focus is lost or view wants to update
1503 // the property list.
1504 // Does the transferance from the property editing area to the property itself
1505 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1507 if (!view
->GetValueText())
1509 wxString
value(view
->GetValueText()->GetValue());
1511 property
->GetValue() = value
;
1515 // Called when TICK is pressed or focus is lost or view wants to update
1516 // the property list.
1517 // Does the transferance from the property editing area to the property itself
1518 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1520 if (!view
->GetValueText())
1522 wxString
str(property
->GetValue().GetStringRepresentation());
1523 view
->GetValueText()->SetValue(str
);
1527 // Called when the property is double clicked. Extra functionality can be provided,
1528 // cycling through possible values.
1529 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1531 if (!view
->GetValueText())
1533 OnEdit(property
, view
, parentWindow
);
1537 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1539 if (view
->GetConfirmButton())
1540 view
->GetConfirmButton()->Enable(TRUE
);
1541 if (view
->GetCancelButton())
1542 view
->GetCancelButton()->Enable(TRUE
);
1543 if (view
->GetEditButton())
1544 view
->GetEditButton()->Enable(TRUE
);
1545 if (view
->GetValueText())
1546 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1550 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1552 if (!view
->GetValueText())
1555 wxChar
*s
= property
->GetValue().StringValue();
1562 g
= wxHexToDec(s
+2);
1563 b
= wxHexToDec(s
+4);
1566 wxColour
col(r
,g
,b
);
1569 data
.SetChooseFull(TRUE
);
1570 data
.SetColour(col
);
1572 for (int i
= 0; i
< 16; i
++)
1574 wxColour
colour(i
*16, i
*16, i
*16);
1575 data
.SetCustomColour(i
, colour
);
1578 wxColourDialog
dialog(parentWindow
, &data
);
1579 if (dialog
.ShowModal() != wxID_CANCEL
)
1581 wxColourData retData
= dialog
.GetColourData();
1582 col
= retData
.GetColour();
1585 wxDecToHex(col
.Red(), buf
);
1586 wxDecToHex(col
.Green(), buf
+2);
1587 wxDecToHex(col
.Blue(), buf
+4);
1589 property
->GetValue() = wxString(buf
);
1590 view
->DisplayProperty(property
);
1591 view
->UpdatePropertyDisplayInList(property
);
1592 view
->OnPropertyChanged(property
);
1597 /// List of strings validator. For this we need more user interface than
1598 /// we get with a property list; so create a new dialog for editing the list.
1600 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1602 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1603 wxPropertyListValidator(flags
)
1607 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1609 // No constraints for an arbitrary, user-editable list of strings.
1613 // Called when TICK is pressed or focus is lost or view wants to update
1614 // the property list.
1615 // Does the transferance from the property editing area to the property itself.
1616 // In this case, the user cannot directly edit the string list.
1617 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1622 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1624 if (!view
->GetValueText())
1626 wxString
str(property
->GetValue().GetStringRepresentation());
1627 view
->GetValueText()->SetValue(str
);
1631 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1633 if (view
->GetEditButton())
1634 view
->GetEditButton()->Enable(TRUE
);
1635 if (view
->GetValueText())
1636 view
->GetValueText()->Enable(FALSE
);
1638 if (view
->GetConfirmButton())
1639 view
->GetConfirmButton()->Enable(FALSE
);
1640 if (view
->GetCancelButton())
1641 view
->GetCancelButton()->Enable(FALSE
);
1645 // Called when the property is double clicked. Extra functionality can be provided,
1646 // cycling through possible values.
1647 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1649 OnEdit(property
, view
, parentWindow
);
1653 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1655 // Convert property value to a list of strings for editing
1656 wxStringList
*stringList
= new wxStringList
;
1658 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1661 wxChar
*s
= expr
->StringValue();
1664 expr
= expr
->GetNext();
1667 wxString
title(_T("Editing "));
1668 title
+= property
->GetName();
1670 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1672 wxPropertyValue
& oldValue
= property
->GetValue();
1673 oldValue
.ClearList();
1674 wxNode
*node
= stringList
->First();
1677 wxChar
*s
= (wxChar
*)node
->Data();
1678 oldValue
.Append(new wxPropertyValue(s
));
1680 node
= node
->Next();
1683 view
->DisplayProperty(property
);
1684 view
->UpdatePropertyDisplayInList(property
);
1685 view
->OnPropertyChanged(property
);
1690 class wxPropertyStringListEditorDialog
: public wxDialog
1693 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1694 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1695 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1696 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1698 m_stringList
= NULL
;
1699 m_stringText
= NULL
;
1701 sm_dialogCancelled
= FALSE
;
1702 m_currentSelection
= -1;
1704 ~wxPropertyStringListEditorDialog(void) {}
1705 void OnCloseWindow(wxCloseEvent
& event
);
1706 void SaveCurrentSelection(void);
1707 void ShowCurrentSelection(void);
1709 void OnOK(wxCommandEvent
& event
);
1710 void OnCancel(wxCommandEvent
& event
);
1711 void OnAdd(wxCommandEvent
& event
);
1712 void OnDelete(wxCommandEvent
& event
);
1713 void OnStrings(wxCommandEvent
& event
);
1714 void OnText(wxCommandEvent
& event
);
1717 wxStringList
* m_stringList
;
1718 wxListBox
* m_listBox
;
1719 wxTextCtrl
* m_stringText
;
1720 static bool sm_dialogCancelled
;
1721 int m_currentSelection
;
1722 DECLARE_EVENT_TABLE()
1725 #define wxID_PROP_SL_ADD 3000
1726 #define wxID_PROP_SL_DELETE 3001
1727 #define wxID_PROP_SL_STRINGS 3002
1728 #define wxID_PROP_SL_TEXT 3003
1730 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1731 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1732 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1733 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1734 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1735 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1736 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1737 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1740 class wxPropertyStringListEditorText
: public wxTextCtrl
1743 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1744 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1745 long windowStyle
= 0, const wxString
& name
= "text"):
1746 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1749 void OnKillFocus(void)
1751 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1752 dialog
->SaveCurrentSelection();
1756 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1758 // Edit the string list.
1759 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1761 int largeButtonWidth
= 60;
1762 int largeButtonHeight
= 25;
1764 wxBeginBusyCursor();
1765 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1766 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1768 dialog
->m_stringList
= stringList
;
1770 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1771 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1773 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1774 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1775 wxSize(300, -1), wxPROCESS_ENTER
);
1776 dialog
->m_stringText
->Enable(FALSE
);
1778 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1779 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1780 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1781 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1783 okButton
->SetDefault();
1785 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1787 c
->top
.SameAs (dialog
, wxTop
, 2);
1788 c
->left
.SameAs (dialog
, wxLeft
, 2);
1789 c
->right
.SameAs (dialog
, wxRight
, 2);
1790 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1791 dialog
->m_listBox
->SetConstraints(c
);
1793 c
= new wxLayoutConstraints
;
1794 c
->left
.SameAs (dialog
, wxLeft
, 2);
1795 c
->right
.SameAs (dialog
, wxRight
, 2);
1796 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1798 dialog
->m_stringText
->SetConstraints(c
);
1800 c
= new wxLayoutConstraints
;
1801 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1802 c
->left
.SameAs (dialog
, wxLeft
, 2);
1805 addButton
->SetConstraints(c
);
1807 c
= new wxLayoutConstraints
;
1808 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1809 c
->left
.SameAs (addButton
, wxRight
, 2);
1812 deleteButton
->SetConstraints(c
);
1814 c
= new wxLayoutConstraints
;
1815 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1816 c
->right
.SameAs (dialog
, wxRight
, 2);
1819 cancelButton
->SetConstraints(c
);
1821 c
= new wxLayoutConstraints
;
1822 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1823 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1826 okButton
->SetConstraints(c
);
1828 wxNode
*node
= stringList
->First();
1831 char *str
= (char *)node
->Data();
1832 // Save node as client data for each listbox item
1833 dialog
->m_listBox
->Append(str
, (char *)node
);
1834 node
= node
->Next();
1837 dialog
->SetClientSize(310, 305);
1840 dialog
->Centre(wxBOTH
);
1842 if (dialog
->ShowModal() == wxID_CANCEL
)
1849 * String list editor callbacks
1853 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1855 int sel
= m_listBox
->GetSelection();
1858 m_currentSelection
= sel
;
1860 ShowCurrentSelection();
1864 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1866 int sel
= m_listBox
->GetSelection();
1870 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1874 m_listBox
->Delete(sel
);
1875 delete[] (wxChar
*)node
->Data();
1877 m_currentSelection
= -1;
1878 m_stringText
->SetValue("");
1881 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1883 SaveCurrentSelection();
1885 wxChar
*initialText
= _T("");
1886 wxNode
*node
= m_stringList
->Add(initialText
);
1887 m_listBox
->Append(initialText
, (void *)node
);
1888 m_currentSelection
= m_stringList
->Number() - 1;
1889 m_listBox
->SetSelection(m_currentSelection
);
1890 ShowCurrentSelection();
1891 m_stringText
->SetFocus();
1894 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1896 SaveCurrentSelection();
1902 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1904 sm_dialogCancelled
= TRUE
;
1905 EndModal(wxID_CANCEL
);
1910 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1912 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1914 SaveCurrentSelection();
1918 void wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& event
)
1920 SaveCurrentSelection();
1924 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1926 if (m_currentSelection
== -1)
1929 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1933 wxString
txt(m_stringText
->GetValue());
1935 delete[] (char *)node
->Data();
1936 node
->SetData((wxObject
*)copystring(txt
));
1938 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1941 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1943 if (m_currentSelection
== -1)
1945 m_stringText
->SetValue("");
1948 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1949 char *txt
= (char *)node
->Data();
1950 m_stringText
->SetValue(txt
);
1951 m_stringText
->Enable(TRUE
);