1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "proplist.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
33 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
36 #include <strstream.h>
42 #include "wx/window.h"
45 #include "wx/colordlg.h"
49 * Property text edit control
52 IMPLEMENT_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
54 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
55 const wxWindowID id
, const wxString
& value
,
56 const wxPoint
& pos
, const wxSize
& size
,
57 long style
, const wxString
& name
):
58 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
63 void wxPropertyTextEdit::OnSetFocus(void)
67 void wxPropertyTextEdit::OnKillFocus(void)
75 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
77 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
78 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
79 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
80 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
81 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
82 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
83 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
84 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
85 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
86 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxPropertyListView::OnPropertyDoubleClick
)
87 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
90 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
91 wxBitmap
*wxPropertyListView::sm_tickBitmap
= NULL
;
92 wxBitmap
*wxPropertyListView::sm_crossBitmap
= NULL
;
94 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
96 m_propertyScrollingList
= NULL
;
100 m_confirmButton
= NULL
;
101 m_cancelButton
= NULL
;
102 m_propertyWindow
= propPanel
;
103 m_managedWindow
= NULL
;
105 m_windowCloseButton
= NULL
;
106 m_windowCancelButton
= NULL
;
107 m_windowHelpButton
= NULL
;
109 m_detailedEditing
= FALSE
;
112 wxPropertyListView::~wxPropertyListView(void)
118 delete m_crossBitmap;
122 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
124 m_propertySheet
= ps
;
126 AssociatePanel(panel
);
129 UpdatePropertyList();
133 // Update this view of the viewed object, called e.g. by
134 // the object itself.
135 bool wxPropertyListView::OnUpdateView(void)
140 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
142 if (!m_propertyScrollingList
|| !m_propertySheet
)
145 m_propertyScrollingList
->Clear();
148 m_valueList
->Clear();
149 m_valueText
->SetValue("");
151 wxNode
*node
= m_propertySheet
->GetProperties().First();
153 // Should sort them... later...
156 wxProperty
*property
= (wxProperty
*)node
->Data();
157 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
158 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
160 m_propertyScrollingList
->Append(paddedString
.GetData(), (char *)property
);
166 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
168 if (!m_propertyScrollingList
|| !m_propertySheet
)
171 int currentlySelected
= m_propertyScrollingList
->GetSelection();
173 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
174 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
175 int sel
= FindListIndexForProperty(property
);
179 // Don't update the listbox unnecessarily because it can cause
182 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
183 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
186 // UpdatePropertyList(FALSE);
189 // TODO: why is this necessary?
191 if (currentlySelected
> -1)
192 m_propertyScrollingList
->SetSelection(currentlySelected
);
198 // Find the wxListBox index corresponding to this property
199 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
201 int n
= m_propertyScrollingList
->Number();
202 for (int i
= 0; i
< n
; i
++)
204 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
210 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
212 wxString
theString(name
);
215 int padWith
= nameWidth
- theString
.Length();
219 if (GetFlags() & wxPROP_SHOWVALUES
)
221 // Want to pad with spaces
222 theString
.Append(' ', padWith
);
229 // Select and show string representation in validator the given
230 // property. NULL resets to show no property.
231 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
233 if (m_currentProperty
)
235 EndShowingProperty(m_currentProperty
);
236 m_currentProperty
= NULL
;
239 m_valueList
->Clear();
240 m_valueText
->SetValue("");
244 m_currentProperty
= property
;
245 BeginShowingProperty(property
);
249 int sel
= FindListIndexForProperty(property
);
251 m_propertyScrollingList
->SetSelection(sel
);
256 // Find appropriate validator and load property into value controls
257 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
259 m_currentValidator
= FindPropertyValidator(property
);
260 if (!m_currentValidator
)
263 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
266 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
268 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
269 DisplayProperty(property
);
273 // Find appropriate validator and unload property from value controls
274 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
276 if (!m_currentValidator
)
279 RetrieveProperty(property
);
281 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
284 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
286 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
287 if (m_detailedEditing
)
289 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
290 m_detailedEditing
= FALSE
;
295 void wxPropertyListView::BeginDetailedEditing(void)
297 if (!m_currentValidator
)
299 if (!m_currentProperty
)
301 if (m_detailedEditing
)
303 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
305 if (!m_currentProperty
->IsEnabled())
308 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
310 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
311 m_detailedEditing
= TRUE
;
314 void wxPropertyListView::EndDetailedEditing(void)
316 if (!m_currentValidator
)
318 if (!m_currentProperty
)
321 RetrieveProperty(m_currentProperty
);
323 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
326 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
328 if (m_detailedEditing
)
330 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
331 m_detailedEditing
= FALSE
;
335 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
337 if (!m_currentValidator
)
340 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
341 m_valueText
->SetEditable(FALSE
);
343 m_valueText
->SetEditable(TRUE
);
345 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
348 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
350 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
354 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
356 if (!m_currentValidator
)
358 if (!property
->IsEnabled())
361 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
364 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
366 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
368 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
370 UpdatePropertyDisplayInList(property
);
371 OnPropertyChanged(property
);
376 // Revert to old value
377 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
383 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
388 // Called by the listbox callback
389 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
391 int sel
= m_propertyScrollingList
->GetSelection();
394 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
395 if (newSel
&& newSel
!= m_currentProperty
)
397 ShowProperty(newSel
, FALSE
);
402 bool wxPropertyListView::CreateControls(void)
404 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
406 int largeButtonWidth
= 60;
407 int largeButtonHeight
= 25;
409 int smallButtonWidth
= 25;
410 int smallButtonHeight
= 20;
412 // XView must be allowed to choose its own sized buttons
414 largeButtonWidth
= -1;
415 largeButtonHeight
= -1;
417 smallButtonWidth
= -1;
418 smallButtonHeight
= -1;
427 wxWindow
*leftMostWindow
= panel
;
428 wxWindow
*topMostWindow
= panel
;
429 wxWindow
*rightMostWindow
= panel
;
431 wxSystemSettings settings
;
432 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
435 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
437 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
440 // May need to be changed in future to eliminate clashes with app.
441 panel
->SetClientData((char *)this);
443 // These buttons are at the bottom of the window, but create them now
444 // so the constraints are evaluated in the correct order
445 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
447 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
448 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
449 m_windowCloseButton
->SetDefault();
450 m_windowCloseButton
->SetFocus();
452 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
454 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
455 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
457 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
459 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
460 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
462 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
464 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
465 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
468 if (m_windowCloseButton
)
470 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
472 c1
->left
.SameAs (panel
, wxLeft
, 2);
473 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
476 m_windowCloseButton
->SetConstraints(c1
);
477 leftMostWindow
= m_windowCloseButton
;
479 if (m_windowCancelButton
)
481 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
483 c2
->right
.SameAs (panel
, wxRight
, 2);
484 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
487 m_windowCancelButton
->SetConstraints(c2
);
488 leftMostWindow
= m_windowCancelButton
;
490 if (m_windowHelpButton
)
492 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
493 if (leftMostWindow
== panel
)
494 c2
->left
.SameAs (panel
, wxLeft
, 2);
496 c2
->left
.RightOf (leftMostWindow
, 2);
498 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
501 m_windowHelpButton
->SetConstraints(c2
);
502 leftMostWindow
= m_windowHelpButton
;
505 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
511 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
512 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
513 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
526 if (tickBitmap && crossBitmap)
528 m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
529 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
530 m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
531 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
536 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
537 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
538 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
539 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
542 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
543 c
->left
.SameAs (panel
, wxLeft
, 2);
545 if (windowCloseButton)
546 c->top.Below (m_windowCloseButton, 2);
549 c
->top
.SameAs (panel
, wxTop
, 2);
554 m_cancelButton
->SetConstraints(c
);
556 c
= new wxLayoutConstraints
;
557 c
->left
.RightOf (m_cancelButton
, 2);
558 c
->top
.SameAs (m_cancelButton
, wxTop
, 0);
562 m_confirmButton
->SetConstraints(c
);
564 m_cancelButton
->Enable(FALSE
);
565 m_confirmButton
->Enable(FALSE
);
568 if (m_buttonFlags
& wxPROP_PULLDOWN
)
570 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
571 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
572 m_editButton
->Enable(FALSE
);
573 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
576 if (m_windowCloseButton)
577 c->top.Below (m_windowCloseButton, 2);
580 c
->top
.SameAs (panel
, wxTop
, 2);
582 c
->right
.SameAs (panel
, wxRight
, 2);
585 m_editButton
->SetConstraints(c
);
588 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
589 m_valueText
->Enable(FALSE
);
591 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
594 c
->left
.RightOf (m_confirmButton
, 2);
596 c
->left
.SameAs (panel
, wxLeft
, 2);
598 if (m_windowCloseButton)
599 c->top.Below (m_windowCloseButton, 2);
602 c
->top
.SameAs (panel
, wxTop
, 2);
605 c
->right
.LeftOf (m_editButton
, 2);
607 c
->right
.SameAs (panel
, wxRight
, 2);
610 m_valueText
->SetConstraints(c
);
612 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
613 m_valueList
->Show(FALSE
);
615 c
= new wxLayoutConstraints
;
617 c
->left
.SameAs (panel
, wxLeft
, 2);
618 c
->top
.Below (m_valueText
, 2);
619 c
->right
.SameAs (panel
, wxRight
, 2);
620 c
->height
.Absolute(60);
622 m_valueList
->SetConstraints(c
);
624 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
625 wxPoint(-1, -1), wxSize(300, 300));
626 m_propertyScrollingList
->SetFont(boringFont
);
628 c
= new wxLayoutConstraints
;
630 c
->left
.SameAs (panel
, wxLeft
, 2);
632 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
633 c
->top
.Below (m_valueText
, 2);
635 c
->top
.Below (m_valueList
, 2);
637 c
->right
.SameAs (panel
, wxRight
, 2);
639 if (m_windowCloseButton
)
640 c
->bottom
.Above (m_windowCloseButton
, -2);
642 c
->bottom
.SameAs (panel
, wxBottom
, 2);
644 m_propertyScrollingList
->SetConstraints(c
);
646 // Note: if this is called now, it causes a GPF.
653 void wxPropertyListView::ShowTextControl(bool show
)
656 m_valueText
->Show(show
);
659 void wxPropertyListView::ShowListBoxControl(bool show
)
663 m_valueList
->Show(show
);
664 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
666 wxLayoutConstraints
*constraints
= m_propertyScrollingList
->GetConstraints();
671 constraints
->top
.Below(m_valueList
, 2);
672 // Maintain back-pointer so when valueList is deleted,
673 // any reference to it from this window is removed.
674 m_valueList
->AddConstraintReference(m_propertyScrollingList
);
678 constraints
->top
.Below(m_valueText
, 2);
679 m_valueText
->AddConstraintReference(m_propertyScrollingList
);
681 m_propertyWindow
->Layout();
687 void wxPropertyListView::EnableCheck(bool show
)
690 m_confirmButton
->Enable(show
);
693 void wxPropertyListView::EnableCross(bool show
)
696 m_cancelButton
->Enable(show
);
699 bool wxPropertyListView::OnClose(void)
701 // Retrieve the value if any
702 wxCommandEvent event
;
709 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
711 if (m_currentProperty
&& m_currentValidator
)
713 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
716 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
718 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
722 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
724 // Retrieve the value if any
727 m_managedWindow
->Close(TRUE
);
730 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
732 // SetReturnCode(wxID_CANCEL);
733 m_managedWindow
->Close(TRUE
);
734 sm_dialogCancelled
= TRUE
;
737 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
741 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
743 if (m_currentProperty
)
745 RetrieveProperty(m_currentProperty
);
749 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
751 if (m_currentProperty
&& m_currentValidator
)
753 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
756 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
758 // Revert to old value
759 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
763 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
765 if (m_currentProperty
&& m_currentValidator
)
767 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
770 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
772 // Revert to old value
773 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
777 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
779 if (m_currentProperty
&& m_currentValidator
)
781 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
784 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
786 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
790 void wxPropertyListView::OnText(wxCommandEvent
& event
)
792 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
799 * Property dialog box
802 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
804 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
805 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
808 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
809 const wxString
& title
, const wxPoint
& pos
,
810 const wxSize
& size
, long style
, const wxString
& name
):
811 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
814 m_view
->AssociatePanel( ((wxPanel
*)this) );
815 m_view
->SetManagedWindow(this);
819 bool wxPropertyListDialog::OnClose(void)
823 SetReturnCode(wxID_CANCEL
);
832 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
834 SetReturnCode(wxID_CANCEL
);
838 void wxPropertyListDialog::OnDefaultAction(wxControl
*item
)
841 if (item == m_view->GetPropertyScrollingList())
842 view->OnDoubleClick();
846 // Extend event processing to search the view's event table
847 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
849 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
850 return wxEvtHandler::ProcessEvent(event
);
859 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
861 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
862 EVT_SIZE(wxPropertyListPanel::OnSize
)
865 wxPropertyListPanel::~wxPropertyListPanel()
869 void wxPropertyListPanel::OnDefaultAction(wxControl
*item
)
872 if (item == view->GetPropertyScrollingList())
873 view->OnDoubleClick();
877 // Extend event processing to search the view's event table
878 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
880 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
881 return wxEvtHandler::ProcessEvent(event
);
886 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
895 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
897 bool wxPropertyListFrame::OnClose(void)
902 m_propertyPanel
->SetView(NULL
);
911 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
913 return new wxPropertyListPanel(v
, parent
);
916 bool wxPropertyListFrame::Initialize(void)
918 m_propertyPanel
= OnCreatePanel(this, m_view
);
921 m_view
->AssociatePanel(m_propertyPanel
);
922 m_view
->SetManagedWindow(this);
923 m_propertyPanel
->SetAutoLayout(TRUE
);
931 * Property list specific validator
934 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
936 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
938 // view->GetValueText()->Show(TRUE);
940 OnDisplayValue(property
, view
, parentWindow
);
945 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
947 wxString
s(view
->GetValueList()->GetStringSelection());
950 view
->GetValueText()->SetValue(s
);
951 view
->RetrieveProperty(property
);
956 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
958 // view->GetValueText()->Show(TRUE);
959 wxString
str(property
->GetValue().GetStringRepresentation());
961 view
->GetValueText()->SetValue(str
);
965 // Called when TICK is pressed or focus is lost or view wants to update
966 // the property list.
967 // Does the transferance from the property editing area to the property itself
968 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
970 if (!view
->GetValueText())
975 void wxPropertyListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
977 if (view
->GetDetailedEditing())
978 view
->EndDetailedEditing();
980 view
->BeginDetailedEditing();
983 bool wxPropertyListValidator::OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
985 if (view
->GetConfirmButton())
986 view
->GetConfirmButton()->Enable(FALSE
);
987 if (view
->GetCancelButton())
988 view
->GetCancelButton()->Enable(FALSE
);
989 if (view
->GetEditButton())
990 view
->GetEditButton()->Enable(FALSE
);
998 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
1001 /// Real number validator
1003 bool wxRealListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1005 if (m_realMin
== 0.0 && m_realMax
== 0.0)
1008 if (!view
->GetValueText())
1010 wxString
value(view
->GetValueText()->GetValue());
1013 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1016 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
1017 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1021 if (val
< m_realMin
|| val
> m_realMax
)
1024 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
1025 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1031 // Called when TICK is pressed or focus is lost or view wants to update
1032 // the property list.
1033 // Does the transferance from the property editing area to the property itself
1034 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1036 if (!view
->GetValueText())
1039 if (strlen(view
->GetValueText()->GetValue()) == 0)
1042 wxString
value(view
->GetValueText()->GetValue());
1043 float f
= (float)atof(value
.GetData());
1044 property
->GetValue() = f
;
1048 bool wxRealListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1050 if (view
->GetConfirmButton())
1051 view
->GetConfirmButton()->Enable(TRUE
);
1052 if (view
->GetCancelButton())
1053 view
->GetCancelButton()->Enable(TRUE
);
1054 if (view
->GetEditButton())
1055 view
->GetEditButton()->Enable(FALSE
);
1056 if (view
->GetValueText())
1057 view
->GetValueText()->Enable(TRUE
);
1062 /// Integer validator
1064 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1066 bool wxIntegerListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1068 if (m_integerMin
== 0 && m_integerMax
== 0)
1071 if (!view
->GetValueText())
1073 wxString
value(view
->GetValueText()->GetValue());
1076 if (!StringToLong(WXSTRINGCAST value
, &val
))
1079 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1080 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1083 if (val
< m_integerMin
|| val
> m_integerMax
)
1086 sprintf(buf
, "Value must be an integer between %ld and %ld!", m_integerMin
, m_integerMax
);
1087 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1093 // Called when TICK is pressed or focus is lost or view wants to update
1094 // the property list.
1095 // Does the transferance from the property editing area to the property itself
1096 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1098 if (!view
->GetValueText())
1101 if (strlen(view
->GetValueText()->GetValue()) == 0)
1104 wxString
value(view
->GetValueText()->GetValue());
1105 long val
= (long)atoi(value
.GetData());
1106 property
->GetValue() = (long)val
;
1110 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1112 if (view
->GetConfirmButton())
1113 view
->GetConfirmButton()->Enable(TRUE
);
1114 if (view
->GetCancelButton())
1115 view
->GetCancelButton()->Enable(TRUE
);
1116 if (view
->GetEditButton())
1117 view
->GetEditButton()->Enable(FALSE
);
1118 if (view
->GetValueText())
1119 view
->GetValueText()->Enable(TRUE
);
1124 /// boolean validator
1126 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1128 bool wxBoolListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1130 if (!view
->GetValueText())
1132 wxString
value(view
->GetValueText()->GetValue());
1133 if (value
!= "True" && value
!= "False")
1135 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1141 // Called when TICK is pressed or focus is lost or view wants to update
1142 // the property list.
1143 // Does the transferance from the property editing area to the property itself
1144 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1146 if (!view
->GetValueText())
1149 if (strlen(view
->GetValueText()->GetValue()) == 0)
1152 wxString
value(view
->GetValueText()->GetValue());
1153 bool boolValue
= FALSE
;
1154 if (value
== "True")
1158 property
->GetValue() = (bool)boolValue
;
1162 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1164 if (!view
->GetValueText())
1166 wxString
str(property
->GetValue().GetStringRepresentation());
1168 view
->GetValueText()->SetValue(str
);
1170 if (view
->GetValueList()->IsShown())
1172 view
->GetValueList()->SetStringSelection(str
);
1177 bool wxBoolListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1179 if (view
->GetConfirmButton())
1180 view
->GetConfirmButton()->Enable(FALSE
);
1181 if (view
->GetCancelButton())
1182 view
->GetCancelButton()->Enable(FALSE
);
1183 if (view
->GetEditButton())
1184 view
->GetEditButton()->Enable(TRUE
);
1185 if (view
->GetValueText())
1186 view
->GetValueText()->Enable(FALSE
);
1190 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1192 if (view
->GetValueList())
1194 view
->ShowListBoxControl(TRUE
);
1195 view
->GetValueList()->Enable(TRUE
);
1197 view
->GetValueList()->Append("True");
1198 view
->GetValueList()->Append("False");
1199 char *currentString
= copystring(view
->GetValueText()->GetValue());
1200 view
->GetValueList()->SetStringSelection(currentString
);
1201 delete[] currentString
;
1206 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1208 if (view
->GetValueList())
1210 view
->GetValueList()->Clear();
1211 view
->ShowListBoxControl(FALSE
);
1212 view
->GetValueList()->Enable(FALSE
);
1217 // Called when the property is double clicked. Extra functionality can be provided,
1218 // cycling through possible values.
1219 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1221 if (!view
->GetValueText())
1223 if (property
->GetValue().BoolValue())
1224 property
->GetValue() = (bool)FALSE
;
1226 property
->GetValue() = (bool)TRUE
;
1227 view
->DisplayProperty(property
);
1228 view
->UpdatePropertyDisplayInList(property
);
1229 view
->OnPropertyChanged(property
);
1234 /// String validator
1236 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1238 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1239 wxPropertyListValidator(flags
)
1242 // If no constraint, we just allow the string to be edited.
1243 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1244 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1247 bool wxStringListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1252 if (!view
->GetValueText())
1254 wxString
value(view
->GetValueText()->GetValue());
1256 if (!m_strings
->Member(value
.GetData()))
1258 wxString
s("Value ");
1259 s
+= value
.GetData();
1260 s
+= " is not valid.";
1261 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1267 // Called when TICK is pressed or focus is lost or view wants to update
1268 // the property list.
1269 // Does the transferance from the property editing area to the property itself
1270 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1272 if (!view
->GetValueText())
1274 wxString
value(view
->GetValueText()->GetValue());
1275 property
->GetValue() = value
;
1279 // Called when TICK is pressed or focus is lost or view wants to update
1280 // the property list.
1281 // Does the transferance from the property editing area to the property itself
1282 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1284 if (!view
->GetValueText())
1286 wxString
str(property
->GetValue().GetStringRepresentation());
1287 view
->GetValueText()->SetValue(str
);
1288 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1290 view
->GetValueList()->SetStringSelection(str
);
1295 bool wxStringListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1300 if (view
->GetEditButton())
1301 view
->GetEditButton()->Enable(FALSE
);
1302 if (view
->GetConfirmButton())
1303 view
->GetConfirmButton()->Enable(TRUE
);
1304 if (view
->GetCancelButton())
1305 view
->GetCancelButton()->Enable(TRUE
);
1306 if (view
->GetValueText())
1307 view
->GetValueText()->Enable(TRUE
);
1312 if (view
->GetValueText())
1313 view
->GetValueText()->Enable(FALSE
);
1315 if (view
->GetEditButton())
1316 view
->GetEditButton()->Enable(TRUE
);
1318 if (view
->GetConfirmButton())
1319 view
->GetConfirmButton()->Enable(FALSE
);
1320 if (view
->GetCancelButton())
1321 view
->GetCancelButton()->Enable(FALSE
);
1325 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1327 if (view
->GetValueList())
1329 view
->ShowListBoxControl(TRUE
);
1330 view
->GetValueList()->Enable(TRUE
);
1331 wxNode
*node
= m_strings
->First();
1334 char *s
= (char *)node
->Data();
1335 view
->GetValueList()->Append(s
);
1336 node
= node
->Next();
1338 char *currentString
= property
->GetValue().StringValue();
1339 view
->GetValueList()->SetStringSelection(currentString
);
1344 bool wxStringListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1351 if (view
->GetValueList())
1353 view
->GetValueList()->Clear();
1354 view
->ShowListBoxControl(FALSE
);
1355 view
->GetValueList()->Enable(FALSE
);
1360 // Called when the property is double clicked. Extra functionality can be provided,
1361 // cycling through possible values.
1362 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1364 if (!view
->GetValueText())
1369 wxNode
*node
= m_strings
->First();
1370 char *currentString
= property
->GetValue().StringValue();
1373 char *s
= (char *)node
->Data();
1374 if (strcmp(s
, currentString
) == 0)
1376 char *nextString
= NULL
;
1378 nextString
= (char *)node
->Next()->Data();
1380 nextString
= (char *)m_strings
->First()->Data();
1381 property
->GetValue() = wxString(nextString
);
1382 view
->DisplayProperty(property
);
1383 view
->UpdatePropertyDisplayInList(property
);
1384 view
->OnPropertyChanged(property
);
1387 else node
= node
->Next();
1393 /// Filename validator
1395 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1397 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1398 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1402 wxFilenameListValidator::~wxFilenameListValidator(void)
1406 bool wxFilenameListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1411 // Called when TICK is pressed or focus is lost or view wants to update
1412 // the property list.
1413 // Does the transferance from the property editing area to the property itself
1414 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1416 if (!view
->GetValueText())
1418 wxString
value(view
->GetValueText()->GetValue());
1419 property
->GetValue() = value
;
1423 // Called when TICK is pressed or focus is lost or view wants to update
1424 // the property list.
1425 // Does the transferance from the property editing area to the property itself
1426 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1428 if (!view
->GetValueText())
1430 wxString
str(property
->GetValue().GetStringRepresentation());
1431 view
->GetValueText()->SetValue(str
);
1435 // Called when the property is double clicked. Extra functionality can be provided,
1436 // cycling through possible values.
1437 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1439 if (!view
->GetValueText())
1441 OnEdit(property
, view
, parentWindow
);
1445 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1447 if (view
->GetConfirmButton())
1448 view
->GetConfirmButton()->Enable(TRUE
);
1449 if (view
->GetCancelButton())
1450 view
->GetCancelButton()->Enable(TRUE
);
1451 if (view
->GetEditButton())
1452 view
->GetEditButton()->Enable(TRUE
);
1453 if (view
->GetValueText())
1454 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1458 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1460 if (!view
->GetValueText())
1463 char *s
= wxFileSelector(
1464 m_filenameMessage
.GetData(),
1465 wxPathOnly(property
->GetValue().StringValue()),
1466 wxFileNameFromPath(property
->GetValue().StringValue()),
1468 m_filenameWildCard
.GetData(),
1473 property
->GetValue() = wxString(s
);
1474 view
->DisplayProperty(property
);
1475 view
->UpdatePropertyDisplayInList(property
);
1476 view
->OnPropertyChanged(property
);
1481 /// Colour validator
1483 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1485 wxColourListValidator::wxColourListValidator(long flags
):
1486 wxPropertyListValidator(flags
)
1490 wxColourListValidator::~wxColourListValidator(void)
1494 bool wxColourListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1499 // Called when TICK is pressed or focus is lost or view wants to update
1500 // the property list.
1501 // Does the transferance from the property editing area to the property itself
1502 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1504 if (!view
->GetValueText())
1506 wxString
value(view
->GetValueText()->GetValue());
1508 property
->GetValue() = value
;
1512 // Called when TICK is pressed or focus is lost or view wants to update
1513 // the property list.
1514 // Does the transferance from the property editing area to the property itself
1515 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1517 if (!view
->GetValueText())
1519 wxString
str(property
->GetValue().GetStringRepresentation());
1520 view
->GetValueText()->SetValue(str
);
1524 // Called when the property is double clicked. Extra functionality can be provided,
1525 // cycling through possible values.
1526 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1528 if (!view
->GetValueText())
1530 OnEdit(property
, view
, parentWindow
);
1534 bool wxColourListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1536 if (view
->GetConfirmButton())
1537 view
->GetConfirmButton()->Enable(TRUE
);
1538 if (view
->GetCancelButton())
1539 view
->GetCancelButton()->Enable(TRUE
);
1540 if (view
->GetEditButton())
1541 view
->GetEditButton()->Enable(TRUE
);
1542 if (view
->GetValueText())
1543 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1547 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1549 if (!view
->GetValueText())
1552 char *s
= property
->GetValue().StringValue();
1559 g
= wxHexToDec(s
+2);
1560 b
= wxHexToDec(s
+4);
1563 wxColour
col(r
,g
,b
);
1566 data
.SetChooseFull(TRUE
);
1567 data
.SetColour(col
);
1569 for (int i
= 0; i
< 16; i
++)
1571 wxColour
colour(i
*16, i
*16, i
*16);
1572 data
.SetCustomColour(i
, colour
);
1575 wxColourDialog
dialog(parentWindow
, &data
);
1576 if (dialog
.ShowModal() != wxID_CANCEL
)
1578 wxColourData retData
= dialog
.GetColourData();
1579 col
= retData
.GetColour();
1582 wxDecToHex(col
.Red(), buf
);
1583 wxDecToHex(col
.Green(), buf
+2);
1584 wxDecToHex(col
.Blue(), buf
+4);
1586 property
->GetValue() = wxString(buf
);
1587 view
->DisplayProperty(property
);
1588 view
->UpdatePropertyDisplayInList(property
);
1589 view
->OnPropertyChanged(property
);
1594 /// List of strings validator. For this we need more user interface than
1595 /// we get with a property list; so create a new dialog for editing the list.
1597 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1599 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1600 wxPropertyListValidator(flags
)
1604 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1606 // No constraints for an arbitrary, user-editable list of strings.
1610 // Called when TICK is pressed or focus is lost or view wants to update
1611 // the property list.
1612 // Does the transferance from the property editing area to the property itself.
1613 // In this case, the user cannot directly edit the string list.
1614 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1619 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1621 if (!view
->GetValueText())
1623 wxString
str(property
->GetValue().GetStringRepresentation());
1624 view
->GetValueText()->SetValue(str
);
1628 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1630 if (view
->GetEditButton())
1631 view
->GetEditButton()->Enable(TRUE
);
1632 if (view
->GetValueText())
1633 view
->GetValueText()->Enable(FALSE
);
1635 if (view
->GetConfirmButton())
1636 view
->GetConfirmButton()->Enable(FALSE
);
1637 if (view
->GetCancelButton())
1638 view
->GetCancelButton()->Enable(FALSE
);
1642 // Called when the property is double clicked. Extra functionality can be provided,
1643 // cycling through possible values.
1644 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1646 OnEdit(property
, view
, parentWindow
);
1650 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1652 // Convert property value to a list of strings for editing
1653 wxStringList
*stringList
= new wxStringList
;
1655 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1658 char *s
= expr
->StringValue();
1661 expr
= expr
->GetNext();
1664 wxString
title("Editing ");
1665 title
+= property
->GetName();
1667 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1669 wxPropertyValue
& oldValue
= property
->GetValue();
1670 oldValue
.ClearList();
1671 wxNode
*node
= stringList
->First();
1674 char *s
= (char *)node
->Data();
1675 oldValue
.Append(new wxPropertyValue(s
));
1677 node
= node
->Next();
1680 view
->DisplayProperty(property
);
1681 view
->UpdatePropertyDisplayInList(property
);
1682 view
->OnPropertyChanged(property
);
1687 class wxPropertyStringListEditorDialog
: public wxDialog
1690 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1691 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1692 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1693 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1695 m_stringList
= NULL
;
1696 m_stringText
= NULL
;
1698 sm_dialogCancelled
= FALSE
;
1699 m_currentSelection
= -1;
1701 ~wxPropertyStringListEditorDialog(void) {}
1703 void SaveCurrentSelection(void);
1704 void ShowCurrentSelection(void);
1706 void OnOK(wxCommandEvent
& event
);
1707 void OnCancel(wxCommandEvent
& event
);
1708 void OnAdd(wxCommandEvent
& event
);
1709 void OnDelete(wxCommandEvent
& event
);
1710 void OnStrings(wxCommandEvent
& event
);
1711 void OnText(wxCommandEvent
& event
);
1714 wxStringList
* m_stringList
;
1715 wxListBox
* m_listBox
;
1716 wxTextCtrl
* m_stringText
;
1717 static bool sm_dialogCancelled
;
1718 int m_currentSelection
;
1719 DECLARE_EVENT_TABLE()
1722 #define wxID_PROP_SL_ADD 3000
1723 #define wxID_PROP_SL_DELETE 3001
1724 #define wxID_PROP_SL_STRINGS 3002
1725 #define wxID_PROP_SL_TEXT 3003
1727 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1728 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1729 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1730 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1731 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1732 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1733 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1736 class wxPropertyStringListEditorText
: public wxTextCtrl
1739 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1740 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1741 long windowStyle
= 0, const wxString
& name
= "text"):
1742 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1745 void OnKillFocus(void)
1747 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1748 dialog
->SaveCurrentSelection();
1752 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1754 // Edit the string list.
1755 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1757 int largeButtonWidth
= 60;
1758 int largeButtonHeight
= 25;
1760 wxBeginBusyCursor();
1761 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1762 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1764 dialog
->m_stringList
= stringList
;
1766 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1767 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1769 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1770 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1771 wxSize(300, -1), wxPROCESS_ENTER
);
1772 dialog
->m_stringText
->Enable(FALSE
);
1774 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1775 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1776 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1777 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1779 okButton
->SetDefault();
1781 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1783 c
->top
.SameAs (dialog
, wxTop
, 2);
1784 c
->left
.SameAs (dialog
, wxLeft
, 2);
1785 c
->right
.SameAs (dialog
, wxRight
, 2);
1786 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1787 dialog
->m_listBox
->SetConstraints(c
);
1789 c
= new wxLayoutConstraints
;
1790 c
->left
.SameAs (dialog
, wxLeft
, 2);
1791 c
->right
.SameAs (dialog
, wxRight
, 2);
1792 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1794 dialog
->m_stringText
->SetConstraints(c
);
1796 c
= new wxLayoutConstraints
;
1797 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1798 c
->left
.SameAs (dialog
, wxLeft
, 2);
1801 addButton
->SetConstraints(c
);
1803 c
= new wxLayoutConstraints
;
1804 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1805 c
->left
.SameAs (addButton
, wxRight
, 2);
1808 deleteButton
->SetConstraints(c
);
1810 c
= new wxLayoutConstraints
;
1811 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1812 c
->right
.SameAs (dialog
, wxRight
, 2);
1815 cancelButton
->SetConstraints(c
);
1817 c
= new wxLayoutConstraints
;
1818 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1819 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1822 okButton
->SetConstraints(c
);
1824 wxNode
*node
= stringList
->First();
1827 char *str
= (char *)node
->Data();
1828 // Save node as client data for each listbox item
1829 dialog
->m_listBox
->Append(str
, (char *)node
);
1830 node
= node
->Next();
1833 dialog
->SetClientSize(310, 305);
1836 dialog
->Centre(wxBOTH
);
1838 if (dialog
->ShowModal() == wxID_CANCEL
)
1845 * String list editor callbacks
1849 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1851 int sel
= m_listBox
->GetSelection();
1854 m_currentSelection
= sel
;
1856 ShowCurrentSelection();
1860 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1862 int sel
= m_listBox
->GetSelection();
1866 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1870 m_listBox
->Delete(sel
);
1871 delete[] (char *)node
->Data();
1873 m_currentSelection
= -1;
1874 m_stringText
->SetValue("");
1877 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1879 SaveCurrentSelection();
1881 char *initialText
= "";
1882 wxNode
*node
= m_stringList
->Add(initialText
);
1883 m_listBox
->Append(initialText
, (char *)node
);
1884 m_currentSelection
= m_stringList
->Number() - 1;
1885 m_listBox
->SetSelection(m_currentSelection
);
1886 ShowCurrentSelection();
1887 m_stringText
->SetFocus();
1890 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1892 SaveCurrentSelection();
1897 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1899 sm_dialogCancelled
= TRUE
;
1900 EndModal(wxID_CANCEL
);
1904 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1906 if (event
.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND
)
1908 SaveCurrentSelection();
1912 bool wxPropertyStringListEditorDialog::OnClose(void)
1914 SaveCurrentSelection();
1918 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1920 if (m_currentSelection
== -1)
1923 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1927 wxString
txt(m_stringText
->GetValue());
1929 delete[] (char *)node
->Data();
1930 node
->SetData((wxObject
*)copystring(txt
));
1932 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1935 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1937 if (m_currentSelection
== -1)
1939 m_stringText
->SetValue("");
1942 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1943 char *txt
= (char *)node
->Data();
1944 m_stringText
->SetValue(txt
);
1945 m_stringText
->Enable(TRUE
);