1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/deprecated/setup.h"
32 #include "wx/window.h"
34 #include "wx/button.h"
35 #include "wx/bmpbuttn.h"
36 #include "wx/textctrl.h"
37 #include "wx/listbox.h"
38 #include "wx/settings.h"
39 #include "wx/msgdlg.h"
40 #include "wx/filedlg.h"
44 #include "wx/module.h"
46 #include "wx/artprov.h"
48 #include "wx/colordlg.h"
49 #include "wx/deprecated/proplist.h"
56 #if !WXWIN_COMPATIBILITY_2_4
57 static inline wxChar
* copystring(const wxChar
* s
)
58 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
61 // ----------------------------------------------------------------------------
62 // Property text edit control
63 // ----------------------------------------------------------------------------
65 IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
67 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
68 const wxWindowID id
, const wxString
& value
,
69 const wxPoint
& pos
, const wxSize
& size
,
70 long style
, const wxString
& name
):
71 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
76 void wxPropertyTextEdit::OnSetFocus()
80 void wxPropertyTextEdit::OnKillFocus()
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 bool wxPropertyListView::sm_dialogCancelled
= false;
90 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
92 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
93 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
94 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
95 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
96 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
97 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
98 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
99 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
100 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
101 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
102 wxPropertyListView::OnPropertyDoubleClick
)
103 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
106 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
108 m_propertyScrollingList
= NULL
;
112 m_confirmButton
= NULL
;
113 m_cancelButton
= NULL
;
114 m_propertyWindow
= propPanel
;
115 m_managedWindow
= NULL
;
117 m_windowCloseButton
= NULL
;
118 m_windowCancelButton
= NULL
;
119 m_windowHelpButton
= NULL
;
121 m_detailedEditing
= false;
124 wxPropertyListView::~wxPropertyListView()
128 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
130 m_propertySheet
= ps
;
132 AssociatePanel(panel
);
135 UpdatePropertyList();
139 // Update this view of the viewed object, called e.g. by
140 // the object itself.
141 bool wxPropertyListView::OnUpdateView()
146 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
148 if (!m_propertyScrollingList
|| !m_propertySheet
)
151 m_propertyScrollingList
->Clear();
154 m_valueList
->Clear();
155 m_valueText
->SetValue(wxEmptyString
);
157 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
159 // Should sort them... later...
162 wxProperty
*property
= (wxProperty
*)node
->GetData();
163 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
164 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
165 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
166 node
= node
->GetNext();
171 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
173 if (!m_propertyScrollingList
|| !m_propertySheet
)
177 int currentlySelected
= m_propertyScrollingList
->GetSelection();
180 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
181 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
182 int sel
= FindListIndexForProperty(property
);
186 // Don't update the listbox unnecessarily because it can cause
189 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
190 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
193 // UpdatePropertyList(false);
196 // TODO: why is this necessary?
198 if (currentlySelected
> -1)
199 m_propertyScrollingList
->SetSelection(currentlySelected
);
205 // Find the wxListBox index corresponding to this property
206 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
208 int n
= m_propertyScrollingList
->GetCount();
209 for (int i
= 0; i
< n
; i
++)
211 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
217 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
219 wxString
theString(name
);
222 int padWith
= nameWidth
- theString
.Length();
226 if (GetFlags() & wxPROP_SHOWVALUES
)
228 // Want to pad with spaces
229 theString
.Append( wxT(' '), padWith
);
236 // Select and show string representation in validator the given
237 // property. NULL resets to show no property.
238 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
240 if (m_currentProperty
)
242 EndShowingProperty(m_currentProperty
);
243 m_currentProperty
= NULL
;
246 m_valueList
->Clear();
247 m_valueText
->SetValue(wxEmptyString
);
251 m_currentProperty
= property
;
252 BeginShowingProperty(property
);
256 int sel
= FindListIndexForProperty(property
);
257 if (sel
!= wxNOT_FOUND
)
258 m_propertyScrollingList
->SetSelection(sel
);
263 // Find appropriate validator and load property into value controls
264 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
266 m_currentValidator
= FindPropertyValidator(property
);
267 if (!m_currentValidator
)
270 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
273 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
275 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
276 DisplayProperty(property
);
280 // Find appropriate validator and unload property from value controls
281 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
283 if (!m_currentValidator
)
286 RetrieveProperty(property
);
288 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
291 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
293 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
294 if (m_detailedEditing
)
296 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
297 m_detailedEditing
= false;
302 void wxPropertyListView::BeginDetailedEditing()
304 if (!m_currentValidator
)
306 if (!m_currentProperty
)
308 if (m_detailedEditing
)
310 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
312 if (!m_currentProperty
->IsEnabled())
315 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
317 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
318 m_detailedEditing
= true;
321 void wxPropertyListView::EndDetailedEditing()
323 if (!m_currentValidator
)
325 if (!m_currentProperty
)
328 RetrieveProperty(m_currentProperty
);
330 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
333 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
335 if (m_detailedEditing
)
337 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
338 m_detailedEditing
= false;
342 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
344 if (!m_currentValidator
)
347 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
348 m_valueText
->SetEditable(false);
350 m_valueText
->SetEditable(true);
352 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
355 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
357 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
361 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
363 if (!m_currentValidator
)
365 if (!property
->IsEnabled())
368 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
371 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
373 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
375 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
377 UpdatePropertyDisplayInList(property
);
378 OnPropertyChanged(property
);
383 // Revert to old value
384 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
390 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
395 // Called by the listbox callback
396 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
398 int sel
= m_propertyScrollingList
->GetSelection();
399 if (sel
!= wxNOT_FOUND
)
401 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
402 if (newSel
&& newSel
!= m_currentProperty
)
404 ShowProperty(newSel
, false);
409 bool wxPropertyListView::CreateControls()
411 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
413 wxSize
largeButtonSize( 70, 25 );
414 wxSize
smallButtonSize( 23, 23 );
422 wxFont guiFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
426 wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
,
427 wxNORMAL
, wxNORMAL
, false, _T("Courier New"));
429 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
432 // May need to be changed in future to eliminate clashes with app.
433 // WHAT WAS THIS FOR?
434 // panel->SetClientData((char *)this);
436 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
438 // top row with optional buttons and input line
440 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
441 int buttonborder
= 3;
443 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
445 wxBitmap tickBitmap
= wxArtProvider::GetBitmap(wxART_TICK_MARK
);
446 wxBitmap crossBitmap
= wxArtProvider::GetBitmap(wxART_CROSS_MARK
);
448 if ( tickBitmap
.Ok() && crossBitmap
.Ok() )
450 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, tickBitmap
, wxDefaultPosition
, smallButtonSize
);
451 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, crossBitmap
, wxDefaultPosition
, smallButtonSize
);
455 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, _T(":-)"), wxDefaultPosition
, smallButtonSize
);
456 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, _T("X"), wxDefaultPosition
, smallButtonSize
);
459 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
460 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
463 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, wxEmptyString
,
464 wxDefaultPosition
, wxSize(wxDefaultCoord
, smallButtonSize
.y
), wxPROCESS_ENTER
);
465 m_valueText
->Disable();
466 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
468 if (m_buttonFlags
& wxPROP_PULLDOWN
)
470 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, _T("..."), wxDefaultPosition
, smallButtonSize
);
471 m_editButton
->Disable();
472 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
475 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
477 // middle section with two list boxes
479 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
481 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxDefaultPosition
, wxSize(wxDefaultCoord
, 60));
482 m_valueList
->Show(false);
484 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxDefaultPosition
, wxSize(100, 100));
485 m_propertyScrollingList
->SetFont(* boringFont
);
486 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
488 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
490 // bottom row with buttons
492 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
493 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
494 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
495 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
497 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
500 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
502 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxDefaultPosition
, largeButtonSize
);
503 m_windowCloseButton
->SetDefault();
504 m_windowCloseButton
->SetFocus();
505 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
507 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
509 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxDefaultPosition
, largeButtonSize
);
510 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
512 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
514 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, largeButtonSize
);
515 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
517 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
519 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxDefaultPosition
, largeButtonSize
);
520 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
523 mainsizer
->Add( bottomsizer
, 0, wxALIGN_RIGHT
| wxEXPAND
);
526 panel
->SetSizer( mainsizer
);
531 void wxPropertyListView::ShowTextControl(bool show
)
534 m_valueText
->Show(show
);
537 void wxPropertyListView::ShowListBoxControl(bool show
)
539 if (!m_valueList
) return;
541 m_valueList
->Show(show
);
543 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
546 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
548 m_middleSizer
->Remove( 0 );
550 m_propertyWindow
->Layout();
554 void wxPropertyListView::EnableCheck(bool show
)
557 m_confirmButton
->Enable(show
);
560 void wxPropertyListView::EnableCross(bool show
)
563 m_cancelButton
->Enable(show
);
566 bool wxPropertyListView::OnClose()
568 // Retrieve the value if any
569 wxCommandEvent event
;
576 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
578 if (m_currentProperty
&& m_currentValidator
)
580 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
583 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
585 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
589 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
591 // Retrieve the value if any
594 m_managedWindow
->Close(true);
595 sm_dialogCancelled
= false;
598 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
600 // SetReturnCode(wxID_CANCEL);
601 m_managedWindow
->Close(true);
602 sm_dialogCancelled
= true;
605 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
609 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
611 if (m_currentProperty
)
613 RetrieveProperty(m_currentProperty
);
617 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
619 if (m_currentProperty
&& m_currentValidator
)
621 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
624 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
626 // Revert to old value
627 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
631 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
633 if (m_currentProperty
&& m_currentValidator
)
635 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
638 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
640 // Revert to old value
641 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
645 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
647 if (m_currentProperty
&& m_currentValidator
)
649 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
652 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
654 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
658 void wxPropertyListView::OnText(wxCommandEvent
& event
)
660 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
666 // ----------------------------------------------------------------------------
667 // Property dialog box
668 // ----------------------------------------------------------------------------
670 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog
, wxDialog
)
672 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
673 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
674 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
677 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
678 const wxString
& title
, const wxPoint
& pos
,
679 const wxSize
& size
, long style
, const wxString
& name
):
680 wxDialog(parent
, wxID_ANY
, title
, pos
, size
, style
, name
)
683 m_view
->AssociatePanel( ((wxPanel
*)this) );
684 m_view
->SetManagedWindow(this);
688 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
692 SetReturnCode(wxID_CANCEL
);
703 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
705 SetReturnCode(wxID_CANCEL
);
709 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
712 if (item == m_view->GetPropertyScrollingList())
713 view->OnDoubleClick();
717 // Extend event processing to search the view's event table
718 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
720 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
721 return wxEvtHandler::ProcessEvent(event
);
726 // ----------------------------------------------------------------------------
728 // ----------------------------------------------------------------------------
730 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel
, wxPanel
)
732 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
733 EVT_SIZE(wxPropertyListPanel::OnSize
)
736 wxPropertyListPanel::~wxPropertyListPanel()
740 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
743 if (item == view->GetPropertyScrollingList())
744 view->OnDoubleClick();
748 // Extend event processing to search the view's event table
749 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
751 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
752 return wxEvtHandler::ProcessEvent(event
);
757 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
762 // ----------------------------------------------------------------------------
764 // ----------------------------------------------------------------------------
766 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame
, wxFrame
)
768 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
769 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
772 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
777 m_propertyPanel
->SetView(NULL
);
788 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
790 return new wxPropertyListPanel(v
, parent
);
793 bool wxPropertyListFrame::Initialize()
795 m_propertyPanel
= OnCreatePanel(this, m_view
);
798 m_view
->AssociatePanel(m_propertyPanel
);
799 m_view
->SetManagedWindow(this);
800 m_propertyPanel
->SetAutoLayout(true);
807 // ----------------------------------------------------------------------------
808 // Property list specific validator
809 // ----------------------------------------------------------------------------
811 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
813 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
815 // view->GetValueText()->Show(true);
817 OnDisplayValue(property
, view
, parentWindow
);
822 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
824 wxString
s(view
->GetValueList()->GetStringSelection());
827 view
->GetValueText()->SetValue(s
);
828 view
->RetrieveProperty(property
);
833 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
835 // view->GetValueText()->Show(true);
836 wxString
str(property
->GetValue().GetStringRepresentation());
838 view
->GetValueText()->SetValue(str
);
842 // Called when TICK is pressed or focus is lost or view wants to update
843 // the property list.
844 // Does the transferance from the property editing area to the property itself
845 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
847 if (!view
->GetValueText())
852 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
854 if (view
->GetDetailedEditing())
855 view
->EndDetailedEditing();
857 view
->BeginDetailedEditing();
860 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
862 if (view
->GetConfirmButton())
863 view
->GetConfirmButton()->Disable();
864 if (view
->GetCancelButton())
865 view
->GetCancelButton()->Disable();
866 if (view
->GetEditButton())
867 view
->GetEditButton()->Disable();
871 // ----------------------------------------------------------------------------
872 // Default validators
873 // ----------------------------------------------------------------------------
875 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
878 /// Real number validator
880 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
882 if (m_realMin
== 0.0 && m_realMax
== 0.0)
885 if (!view
->GetValueText())
887 wxString
value(view
->GetValueText()->GetValue());
890 if (!StringToFloat(WXSTRINGCAST value
, &val
))
893 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), value
.GetData());
894 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
898 if (val
< m_realMin
|| val
> m_realMax
)
901 wxSprintf(buf
, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin
, m_realMax
);
902 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
908 // Called when TICK is pressed or focus is lost or view wants to update
909 // the property list.
910 // Does the transferance from the property editing area to the property itself
911 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
913 if (!view
->GetValueText())
916 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
919 wxString
value(view
->GetValueText()->GetValue());
920 float f
= (float)wxAtof(value
.GetData());
921 property
->GetValue() = f
;
925 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
927 if (view
->GetConfirmButton())
928 view
->GetConfirmButton()->Enable();
929 if (view
->GetCancelButton())
930 view
->GetCancelButton()->Enable();
931 if (view
->GetEditButton())
932 view
->GetEditButton()->Disable();
933 if (view
->GetValueText())
934 view
->GetValueText()->Enable();
939 /// Integer validator
941 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
943 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
945 if (m_integerMin
== 0 && m_integerMax
== 0)
948 if (!view
->GetValueText())
950 wxString
value(view
->GetValueText()->GetValue());
953 if (!StringToLong(WXSTRINGCAST value
, &val
))
956 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), value
.GetData());
957 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
960 if (val
< m_integerMin
|| val
> m_integerMax
)
963 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
964 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
970 // Called when TICK is pressed or focus is lost or view wants to update
971 // the property list.
972 // Does the transferance from the property editing area to the property itself
973 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
975 if (!view
->GetValueText())
978 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
981 wxString
value(view
->GetValueText()->GetValue());
982 long val
= (long)wxAtoi(value
.GetData());
983 property
->GetValue() = (long)val
;
987 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
989 if (view
->GetConfirmButton())
990 view
->GetConfirmButton()->Enable();
991 if (view
->GetCancelButton())
992 view
->GetCancelButton()->Enable();
993 if (view
->GetEditButton())
994 view
->GetEditButton()->Disable();
995 if (view
->GetValueText())
996 view
->GetValueText()->Enable();
1001 /// boolean validator
1003 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1005 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1007 if (!view
->GetValueText())
1009 wxString
value(view
->GetValueText()->GetValue());
1010 if (value
!= wxT("True") && value
!= wxT("False"))
1012 wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1018 // Called when TICK is pressed or focus is lost or view wants to update
1019 // the property list.
1020 // Does the transferance from the property editing area to the property itself
1021 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1023 if (!view
->GetValueText())
1026 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1029 wxString
value(view
->GetValueText()->GetValue());
1030 bool boolValue
= (value
== wxT("True"));
1031 property
->GetValue() = boolValue
;
1035 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1037 if (!view
->GetValueText())
1039 wxString
str(property
->GetValue().GetStringRepresentation());
1041 view
->GetValueText()->SetValue(str
);
1043 if (view
->GetValueList()->IsShown())
1045 view
->GetValueList()->SetStringSelection(str
);
1050 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1052 if (view
->GetConfirmButton())
1053 view
->GetConfirmButton()->Disable();
1054 if (view
->GetCancelButton())
1055 view
->GetCancelButton()->Disable();
1056 if (view
->GetEditButton())
1057 view
->GetEditButton()->Enable();
1058 if (view
->GetValueText())
1059 view
->GetValueText()->Disable();
1063 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1065 if (view
->GetValueList())
1067 view
->ShowListBoxControl(true);
1068 view
->GetValueList()->Enable();
1070 view
->GetValueList()->Append(wxT("True"));
1071 view
->GetValueList()->Append(wxT("False"));
1072 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1073 view
->GetValueList()->SetStringSelection(currentString
);
1074 delete[] currentString
;
1079 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1081 if (view
->GetValueList())
1083 view
->GetValueList()->Clear();
1084 view
->ShowListBoxControl(false);
1085 view
->GetValueList()->Disable();
1090 // Called when the property is double clicked. Extra functionality can be provided,
1091 // cycling through possible values.
1092 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1094 if (!view
->GetValueText())
1096 if (property
->GetValue().BoolValue())
1097 property
->GetValue() = false;
1099 property
->GetValue() = true;
1100 view
->DisplayProperty(property
);
1101 view
->UpdatePropertyDisplayInList(property
);
1102 view
->OnPropertyChanged(property
);
1107 /// String validator
1109 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1111 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1112 wxPropertyListValidator(flags
)
1115 // If no constraint, we just allow the string to be edited.
1116 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1117 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1120 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1125 if (!view
->GetValueText())
1127 wxString
value(view
->GetValueText()->GetValue());
1129 if (!m_strings
->Member(value
.GetData()))
1131 wxString
str( wxT("Value ") );
1132 str
+= value
.GetData();
1133 str
+= wxT(" is not valid.");
1134 wxMessageBox( str
.GetData(), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1140 // Called when TICK is pressed or focus is lost or view wants to update
1141 // the property list.
1142 // Does the transferance from the property editing area to the property itself
1143 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1145 if (!view
->GetValueText())
1147 wxString
value(view
->GetValueText()->GetValue());
1148 property
->GetValue() = value
;
1152 // Called when TICK is pressed or focus is lost or view wants to update
1153 // the property list.
1154 // Does the transferance from the property editing area to the property itself
1155 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1157 if (!view
->GetValueText())
1159 wxString
str(property
->GetValue().GetStringRepresentation());
1160 view
->GetValueText()->SetValue(str
);
1161 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->GetCount() > 0)
1163 view
->GetValueList()->SetStringSelection(str
);
1168 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1173 if (view
->GetEditButton())
1174 view
->GetEditButton()->Disable();
1175 if (view
->GetConfirmButton())
1176 view
->GetConfirmButton()->Enable();
1177 if (view
->GetCancelButton())
1178 view
->GetCancelButton()->Enable();
1179 if (view
->GetValueText())
1180 view
->GetValueText()->Enable();
1185 if (view
->GetValueText())
1186 view
->GetValueText()->Disable();
1188 if (view
->GetEditButton())
1189 view
->GetEditButton()->Enable();
1191 if (view
->GetConfirmButton())
1192 view
->GetConfirmButton()->Disable();
1193 if (view
->GetCancelButton())
1194 view
->GetCancelButton()->Disable();
1198 bool wxStringListValidator::OnPrepareDetailControls( wxProperty
*property
,
1199 wxPropertyListView
*view
,
1200 wxWindow
*WXUNUSED(parentWindow
) )
1202 if (view
->GetValueList())
1204 view
->ShowListBoxControl(true);
1205 view
->GetValueList()->Enable();
1206 wxStringList::Node
*node
= m_strings
->GetFirst();
1209 wxChar
*s
= node
->GetData();
1210 view
->GetValueList()->Append(s
);
1211 node
= node
->GetNext();
1213 wxChar
*currentString
= property
->GetValue().StringValue();
1214 view
->GetValueList()->SetStringSelection(currentString
);
1219 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1226 if (view
->GetValueList())
1228 view
->GetValueList()->Clear();
1229 view
->ShowListBoxControl(false);
1230 view
->GetValueList()->Disable();
1235 // Called when the property is double clicked. Extra functionality can be provided,
1236 // cycling through possible values.
1237 bool wxStringListValidator::OnDoubleClick( wxProperty
*property
,
1238 wxPropertyListView
*view
,
1239 wxWindow
*WXUNUSED(parentWindow
) )
1241 if (!view
->GetValueText())
1246 wxStringList::Node
*node
= m_strings
->GetFirst();
1247 wxChar
*currentString
= property
->GetValue().StringValue();
1250 wxChar
*s
= node
->GetData();
1251 if (wxStrcmp(s
, currentString
) == 0)
1254 if (node
->GetNext())
1255 nextString
= node
->GetNext()->GetData();
1257 nextString
= m_strings
->GetFirst()->GetData();
1258 property
->GetValue() = wxString(nextString
);
1259 view
->DisplayProperty(property
);
1260 view
->UpdatePropertyDisplayInList(property
);
1261 view
->OnPropertyChanged(property
);
1264 else node
= node
->GetNext();
1270 /// Filename validator
1272 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1274 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1275 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1279 wxFilenameListValidator::~wxFilenameListValidator()
1283 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1288 // Called when TICK is pressed or focus is lost or view wants to update
1289 // the property list.
1290 // Does the transferance from the property editing area to the property itself
1291 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1293 if (!view
->GetValueText())
1295 wxString
value(view
->GetValueText()->GetValue());
1296 property
->GetValue() = value
;
1300 // Called when TICK is pressed or focus is lost or view wants to update
1301 // the property list.
1302 // Does the transferance from the property editing area to the property itself
1303 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1305 if (!view
->GetValueText())
1307 wxString
str(property
->GetValue().GetStringRepresentation());
1308 view
->GetValueText()->SetValue(str
);
1312 // Called when the property is double clicked. Extra functionality can be provided,
1313 // cycling through possible values.
1314 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1316 if (!view
->GetValueText())
1318 OnEdit(property
, view
, parentWindow
);
1322 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1324 if (view
->GetConfirmButton())
1325 view
->GetConfirmButton()->Enable();
1326 if (view
->GetCancelButton())
1327 view
->GetCancelButton()->Enable();
1328 if (view
->GetEditButton())
1329 view
->GetEditButton()->Enable();
1330 if (view
->GetValueText())
1331 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1335 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1337 if (!view
->GetValueText())
1341 wxString s
= wxFileSelector(
1342 m_filenameMessage
.GetData(),
1343 wxPathOnly(property
->GetValue().StringValue()),
1344 wxFileNameFromPath(property
->GetValue().StringValue()),
1346 m_filenameWildCard
.GetData(),
1351 property
->GetValue() = s
;
1352 view
->DisplayProperty(property
);
1353 view
->UpdatePropertyDisplayInList(property
);
1354 view
->OnPropertyChanged(property
);
1357 wxUnusedVar(property
);
1359 wxUnusedVar(parentWindow
);
1364 /// Colour validator
1366 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1368 wxColourListValidator::wxColourListValidator(long flags
):
1369 wxPropertyListValidator(flags
)
1373 wxColourListValidator::~wxColourListValidator()
1377 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1382 // Called when TICK is pressed or focus is lost or view wants to update
1383 // the property list.
1384 // Does the transferance from the property editing area to the property itself
1385 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1387 if (!view
->GetValueText())
1389 wxString
value(view
->GetValueText()->GetValue());
1391 property
->GetValue() = value
;
1395 // Called when TICK is pressed or focus is lost or view wants to update
1396 // the property list.
1397 // Does the transferance from the property editing area to the property itself
1398 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1400 if (!view
->GetValueText())
1402 wxString
str(property
->GetValue().GetStringRepresentation());
1403 view
->GetValueText()->SetValue(str
);
1407 // Called when the property is double clicked. Extra functionality can be provided,
1408 // cycling through possible values.
1409 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1411 if (!view
->GetValueText())
1413 OnEdit(property
, view
, parentWindow
);
1417 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1419 if (view
->GetConfirmButton())
1420 view
->GetConfirmButton()->Enable();
1422 if (view
->GetCancelButton())
1423 view
->GetCancelButton()->Enable();
1425 if (view
->GetEditButton())
1426 view
->GetEditButton()->Enable();
1428 if (view
->GetValueText())
1429 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1434 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1436 if (!view
->GetValueText())
1439 wxChar
*s
= property
->GetValue().StringValue();
1440 unsigned char r
= 0;
1441 unsigned char g
= 0;
1442 unsigned char b
= 0;
1445 r
= (unsigned char)wxHexToDec(s
);
1446 g
= (unsigned char)wxHexToDec(s
+2);
1447 b
= (unsigned char)wxHexToDec(s
+4);
1450 wxColour
col(r
,g
,b
);
1453 data
.SetChooseFull(true);
1454 data
.SetColour(col
);
1456 for (int i
= 0; i
< 16; i
++)
1458 wxColour
colour((unsigned char)(i
*16),
1459 (unsigned char)(i
*16),
1460 (unsigned char)(i
*16));
1461 data
.SetCustomColour(i
, colour
);
1464 wxColourDialog
dialog(parentWindow
, &data
);
1465 if (dialog
.ShowModal() != wxID_CANCEL
)
1467 wxColourData retData
= dialog
.GetColourData();
1468 col
= retData
.GetColour();
1471 wxDecToHex(col
.Red(), buf
);
1472 wxDecToHex(col
.Green(), buf
+2);
1473 wxDecToHex(col
.Blue(), buf
+4);
1475 property
->GetValue() = wxString(buf
);
1476 view
->DisplayProperty(property
);
1477 view
->UpdatePropertyDisplayInList(property
);
1478 view
->OnPropertyChanged(property
);
1483 /// List of strings validator. For this we need more user interface than
1484 /// we get with a property list; so create a new dialog for editing the list.
1486 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1488 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1489 wxPropertyListValidator(flags
)
1493 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1495 // No constraints for an arbitrary, user-editable list of strings.
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 // In this case, the user cannot directly edit the string list.
1503 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1508 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1510 if (!view
->GetValueText())
1512 wxString
str(property
->GetValue().GetStringRepresentation());
1513 view
->GetValueText()->SetValue(str
);
1517 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1519 if (view
->GetEditButton())
1520 view
->GetEditButton()->Enable();
1521 if (view
->GetValueText())
1522 view
->GetValueText()->Disable();
1524 if (view
->GetConfirmButton())
1525 view
->GetConfirmButton()->Disable();
1526 if (view
->GetCancelButton())
1527 view
->GetCancelButton()->Disable();
1531 // Called when the property is double clicked. Extra functionality can be provided,
1532 // cycling through possible values.
1533 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1535 OnEdit(property
, view
, parentWindow
);
1539 void wxListOfStringsListValidator::OnEdit( wxProperty
*property
,
1540 wxPropertyListView
*view
,
1541 wxWindow
*parentWindow
)
1543 // Convert property value to a list of strings for editing
1544 wxStringList
*stringList
= new wxStringList
;
1546 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1549 wxChar
*s
= expr
->StringValue();
1552 expr
= expr
->GetNext();
1555 wxString
title(wxT("Editing "));
1556 title
+= property
->GetName();
1558 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1560 wxPropertyValue
& oldValue
= property
->GetValue();
1561 oldValue
.ClearList();
1562 wxStringList::Node
*node
= stringList
->GetFirst();
1565 wxChar
*s
= node
->GetData();
1566 oldValue
.Append(new wxPropertyValue(s
));
1568 node
= node
->GetNext();
1571 view
->DisplayProperty(property
);
1572 view
->UpdatePropertyDisplayInList(property
);
1573 view
->OnPropertyChanged(property
);
1578 class wxPropertyStringListEditorDialog
: public wxDialog
1581 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1582 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1583 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= wxT("stringEditorDialogBox")):
1584 wxDialog(parent
, wxID_ANY
, title
, pos
, size
, windowStyle
, name
)
1586 m_stringList
= NULL
;
1587 m_stringText
= NULL
;
1589 sm_dialogCancelled
= false;
1590 m_currentSelection
= -1;
1592 ~wxPropertyStringListEditorDialog(void) {}
1593 void OnCloseWindow(wxCloseEvent
& event
);
1594 void SaveCurrentSelection(void);
1595 void ShowCurrentSelection(void);
1597 void OnOK(wxCommandEvent
& event
);
1598 void OnCancel(wxCommandEvent
& event
);
1599 void OnAdd(wxCommandEvent
& event
);
1600 void OnDelete(wxCommandEvent
& event
);
1601 void OnStrings(wxCommandEvent
& event
);
1602 void OnText(wxCommandEvent
& event
);
1605 wxStringList
* m_stringList
;
1606 wxListBox
* m_listBox
;
1607 wxTextCtrl
* m_stringText
;
1608 static bool sm_dialogCancelled
;
1609 int m_currentSelection
;
1610 DECLARE_EVENT_TABLE()
1613 #define wxID_PROP_SL_ADD 3000
1614 #define wxID_PROP_SL_DELETE 3001
1615 #define wxID_PROP_SL_STRINGS 3002
1616 #define wxID_PROP_SL_TEXT 3003
1618 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1619 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1620 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1621 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1622 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1623 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1624 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1625 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1628 class wxPropertyStringListEditorText
: public wxTextCtrl
1631 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1632 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1633 long windowStyle
= 0, const wxString
& name
= wxT("text")):
1634 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1639 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1640 dialog
->SaveCurrentSelection();
1644 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= false;
1646 // Edit the string list.
1647 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1649 int largeButtonWidth
= 60;
1650 int largeButtonHeight
= 25;
1652 wxBeginBusyCursor();
1653 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1654 title
, wxPoint(10, 10), wxSize(400, 400));
1656 dialog
->m_stringList
= stringList
;
1658 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1659 wxDefaultPosition
, wxDefaultSize
, 0, NULL
, wxLB_SINGLE
);
1661 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1662 wxID_PROP_SL_TEXT
, wxEmptyString
, wxPoint(5, 240),
1663 wxSize(300, wxDefaultCoord
), wxPROCESS_ENTER
);
1664 dialog
->m_stringText
->Disable();
1666 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, wxT("Add"), wxDefaultPosition
, wxSize(largeButtonWidth
, largeButtonHeight
));
1667 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, wxT("Delete"), wxDefaultPosition
, wxSize(largeButtonWidth
, largeButtonHeight
));
1668 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, wxT("Cancel"), wxDefaultPosition
, wxSize(largeButtonWidth
, largeButtonHeight
));
1669 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, wxT("OK"), wxDefaultPosition
, wxSize(largeButtonWidth
, largeButtonHeight
));
1672 okButton
->SetDefault();
1675 wxBoxSizer
*m_bottom_sizer
= new wxBoxSizer( wxHORIZONTAL
);
1676 m_bottom_sizer
->Add(addButton
, 0, wxALL
| wxALIGN_LEFT
, 2 );
1677 m_bottom_sizer
->Add(deleteButton
, 0, wxALL
| wxALIGN_LEFT
, 2 );
1678 m_bottom_sizer
->Add(1, 1, 1, wxEXPAND
| wxALL
);
1679 m_bottom_sizer
->Add(cancelButton
, 0, wxALL
| wxALIGN_RIGHT
, 2 );
1680 m_bottom_sizer
->Add(okButton
, 0, wxALL
| wxALIGN_RIGHT
, 2 );
1682 wxBoxSizer
*m_sizer
= new wxBoxSizer( wxVERTICAL
);
1683 m_sizer
->Add(dialog
->m_listBox
, 1, wxEXPAND
| wxALL
, 2 );
1684 m_sizer
->Add(dialog
->m_stringText
, 0, wxEXPAND
| wxALL
, 2 );
1685 m_sizer
->Add(m_bottom_sizer
, 0, wxEXPAND
| wxALL
, 0 );
1687 dialog
->SetSizer( m_sizer
);
1688 m_sizer
->SetSizeHints( dialog
);
1690 wxStringList::Node
*node
= stringList
->GetFirst();
1693 wxChar
*str
= node
->GetData();
1694 // Save node as client data for each listbox item
1695 dialog
->m_listBox
->Append(str
, (wxChar
*)node
);
1696 node
= node
->GetNext();
1699 dialog
->SetClientSize(310, 305);
1702 dialog
->Centre(wxBOTH
);
1704 if (dialog
->ShowModal() == wxID_CANCEL
)
1711 * String list editor callbacks
1715 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1717 int sel
= m_listBox
->GetSelection();
1718 if (sel
!= wxNOT_FOUND
)
1720 m_currentSelection
= sel
;
1722 ShowCurrentSelection();
1726 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1728 int sel
= m_listBox
->GetSelection();
1729 if (sel
== wxNOT_FOUND
)
1732 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1736 m_listBox
->Delete(sel
);
1737 delete[] (wxChar
*)node
->GetData();
1739 m_currentSelection
= -1;
1740 m_stringText
->SetValue(wxEmptyString
);
1743 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1745 SaveCurrentSelection();
1747 wxString initialText
;
1748 wxNode
*node
= m_stringList
->Add(initialText
);
1749 m_listBox
->Append(initialText
, (void *)node
);
1750 m_currentSelection
= m_stringList
->GetCount() - 1;
1751 m_listBox
->SetSelection(m_currentSelection
);
1752 ShowCurrentSelection();
1753 m_stringText
->SetFocus();
1756 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1758 SaveCurrentSelection();
1764 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1766 sm_dialogCancelled
= true;
1767 EndModal(wxID_CANCEL
);
1772 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1774 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1776 SaveCurrentSelection();
1781 wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
1783 SaveCurrentSelection();
1788 void wxPropertyStringListEditorDialog::SaveCurrentSelection()
1790 if (m_currentSelection
== -1)
1793 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1797 wxString
txt(m_stringText
->GetValue());
1798 if (node
->GetData())
1799 delete[] (wxChar
*)node
->GetData();
1800 node
->SetData((wxObject
*)wxStrdup(txt
));
1802 m_listBox
->SetString(m_currentSelection
, (wxChar
*)node
->GetData());
1805 void wxPropertyStringListEditorDialog::ShowCurrentSelection()
1807 if (m_currentSelection
== -1)
1809 m_stringText
->SetValue(wxEmptyString
);
1812 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1813 wxChar
*txt
= (wxChar
*)node
->GetData();
1814 m_stringText
->SetValue(txt
);
1815 m_stringText
->Enable();
1819 #endif // wxUSE_PROPSHEET