1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "proplist.h"
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
31 #include "wx/deprecated/setup.h"
36 #include "wx/window.h"
38 #include "wx/button.h"
39 #include "wx/bmpbuttn.h"
40 #include "wx/textctrl.h"
41 #include "wx/listbox.h"
42 #include "wx/settings.h"
43 #include "wx/msgdlg.h"
44 #include "wx/filedlg.h"
48 #include "wx/module.h"
50 #include "wx/artprov.h"
52 #include "wx/colordlg.h"
53 #include "wx/deprecated/proplist.h"
60 #if !WXWIN_COMPATIBILITY_2_4
61 static inline wxChar
* copystring(const wxChar
* s
)
62 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
65 // ----------------------------------------------------------------------------
66 // Property text edit control
67 // ----------------------------------------------------------------------------
69 IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
71 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
72 const wxWindowID id
, const wxString
& value
,
73 const wxPoint
& pos
, const wxSize
& size
,
74 long style
, const wxString
& name
):
75 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
80 void wxPropertyTextEdit::OnSetFocus()
84 void wxPropertyTextEdit::OnKillFocus()
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
94 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
96 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
97 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
98 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
99 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
100 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
101 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
102 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
103 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
104 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
105 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
106 wxPropertyListView::OnPropertyDoubleClick
)
107 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
110 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
112 m_propertyScrollingList
= NULL
;
116 m_confirmButton
= NULL
;
117 m_cancelButton
= NULL
;
118 m_propertyWindow
= propPanel
;
119 m_managedWindow
= NULL
;
121 m_windowCloseButton
= NULL
;
122 m_windowCancelButton
= NULL
;
123 m_windowHelpButton
= NULL
;
125 m_detailedEditing
= FALSE
;
128 wxPropertyListView::~wxPropertyListView()
132 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
134 m_propertySheet
= ps
;
136 AssociatePanel(panel
);
139 UpdatePropertyList();
143 // Update this view of the viewed object, called e.g. by
144 // the object itself.
145 bool wxPropertyListView::OnUpdateView()
150 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
152 if (!m_propertyScrollingList
|| !m_propertySheet
)
155 m_propertyScrollingList
->Clear();
158 m_valueList
->Clear();
159 m_valueText
->SetValue( wxT("") );
161 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
163 // Should sort them... later...
166 wxProperty
*property
= (wxProperty
*)node
->GetData();
167 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
168 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
169 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
170 node
= node
->GetNext();
175 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
177 if (!m_propertyScrollingList
|| !m_propertySheet
)
181 int currentlySelected
= m_propertyScrollingList
->GetSelection();
184 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
185 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
186 int sel
= FindListIndexForProperty(property
);
190 // Don't update the listbox unnecessarily because it can cause
193 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
194 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
197 // UpdatePropertyList(FALSE);
200 // TODO: why is this necessary?
202 if (currentlySelected
> -1)
203 m_propertyScrollingList
->SetSelection(currentlySelected
);
209 // Find the wxListBox index corresponding to this property
210 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
212 int n
= m_propertyScrollingList
->GetCount();
213 for (int i
= 0; i
< n
; i
++)
215 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
221 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
223 wxString
theString(name
);
226 int padWith
= nameWidth
- theString
.Length();
230 if (GetFlags() & wxPROP_SHOWVALUES
)
232 // Want to pad with spaces
233 theString
.Append( wxT(' '), padWith
);
240 // Select and show string representation in validator the given
241 // property. NULL resets to show no property.
242 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
244 if (m_currentProperty
)
246 EndShowingProperty(m_currentProperty
);
247 m_currentProperty
= NULL
;
250 m_valueList
->Clear();
251 m_valueText
->SetValue( wxT("") );
255 m_currentProperty
= property
;
256 BeginShowingProperty(property
);
260 int sel
= FindListIndexForProperty(property
);
262 m_propertyScrollingList
->SetSelection(sel
);
267 // Find appropriate validator and load property into value controls
268 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
270 m_currentValidator
= FindPropertyValidator(property
);
271 if (!m_currentValidator
)
274 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
277 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
279 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
280 DisplayProperty(property
);
284 // Find appropriate validator and unload property from value controls
285 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
287 if (!m_currentValidator
)
290 RetrieveProperty(property
);
292 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
295 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
297 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
298 if (m_detailedEditing
)
300 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
301 m_detailedEditing
= FALSE
;
306 void wxPropertyListView::BeginDetailedEditing()
308 if (!m_currentValidator
)
310 if (!m_currentProperty
)
312 if (m_detailedEditing
)
314 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
316 if (!m_currentProperty
->IsEnabled())
319 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
321 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
322 m_detailedEditing
= TRUE
;
325 void wxPropertyListView::EndDetailedEditing()
327 if (!m_currentValidator
)
329 if (!m_currentProperty
)
332 RetrieveProperty(m_currentProperty
);
334 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
337 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
339 if (m_detailedEditing
)
341 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
342 m_detailedEditing
= FALSE
;
346 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
348 if (!m_currentValidator
)
351 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
352 m_valueText
->SetEditable(FALSE
);
354 m_valueText
->SetEditable(TRUE
);
356 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
359 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
361 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
365 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
367 if (!m_currentValidator
)
369 if (!property
->IsEnabled())
372 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
375 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
377 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
379 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
381 UpdatePropertyDisplayInList(property
);
382 OnPropertyChanged(property
);
387 // Revert to old value
388 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
394 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
399 // Called by the listbox callback
400 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
402 int sel
= m_propertyScrollingList
->GetSelection();
405 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
406 if (newSel
&& newSel
!= m_currentProperty
)
408 ShowProperty(newSel
, FALSE
);
413 bool wxPropertyListView::CreateControls()
415 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
417 wxSize
largeButtonSize( 70, 25 );
418 wxSize
smallButtonSize( 23, 23 );
426 wxFont guiFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
430 wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
,
431 wxNORMAL
, wxNORMAL
, FALSE
, _T("Courier New"));
433 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
436 // May need to be changed in future to eliminate clashes with app.
437 // WHAT WAS THIS FOR?
438 // panel->SetClientData((char *)this);
440 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
442 // top row with optional buttons and input line
444 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
445 int buttonborder
= 3;
447 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
449 wxBitmap tickBitmap
= wxArtProvider::GetBitmap(wxART_TICK_MARK
);
450 wxBitmap crossBitmap
= wxArtProvider::GetBitmap(wxART_CROSS_MARK
);
452 if ( tickBitmap
.Ok() && crossBitmap
.Ok() )
454 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, tickBitmap
, wxPoint(-1, -1), smallButtonSize
);
455 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, crossBitmap
, wxPoint(-1, -1), smallButtonSize
);
459 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, _T(":-)"), wxPoint(-1, -1), smallButtonSize
);
460 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, _T("X"), wxPoint(-1, -1), smallButtonSize
);
463 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
464 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
467 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, _T(""),
468 wxPoint(-1, -1), wxSize(-1, smallButtonSize
.y
), wxPROCESS_ENTER
);
469 m_valueText
->Enable(FALSE
);
470 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
472 if (m_buttonFlags
& wxPROP_PULLDOWN
)
474 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, _T("..."), wxPoint(-1, -1), smallButtonSize
);
475 m_editButton
->Enable(FALSE
);
476 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
479 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
481 // middle section with two list boxes
483 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
485 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
486 m_valueList
->Show(FALSE
);
488 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxPoint(-1, -1), wxSize(100, 100));
489 m_propertyScrollingList
->SetFont(* boringFont
);
490 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
492 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
494 // bottom row with buttons
496 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
497 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
498 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
499 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
501 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
504 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
506 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxPoint(-1, -1), largeButtonSize
);
507 m_windowCloseButton
->SetDefault();
508 m_windowCloseButton
->SetFocus();
509 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
511 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
513 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxPoint(-1, -1), largeButtonSize
);
514 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
516 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
518 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxPoint(-1, -1), largeButtonSize
);
519 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
521 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
523 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxPoint(-1, -1), largeButtonSize
);
524 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
527 mainsizer
->Add( bottomsizer
, 0, wxALIGN_RIGHT
| wxEXPAND
);
530 panel
->SetSizer( mainsizer
);
535 void wxPropertyListView::ShowTextControl(bool show
)
538 m_valueText
->Show(show
);
541 void wxPropertyListView::ShowListBoxControl(bool show
)
543 if (!m_valueList
) return;
545 m_valueList
->Show(show
);
547 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
550 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
552 m_middleSizer
->Remove( 0 );
554 m_propertyWindow
->Layout();
558 void wxPropertyListView::EnableCheck(bool show
)
561 m_confirmButton
->Enable(show
);
564 void wxPropertyListView::EnableCross(bool show
)
567 m_cancelButton
->Enable(show
);
570 bool wxPropertyListView::OnClose()
572 // Retrieve the value if any
573 wxCommandEvent event
;
580 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
582 if (m_currentProperty
&& m_currentValidator
)
584 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
587 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
589 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
593 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
595 // Retrieve the value if any
598 m_managedWindow
->Close(TRUE
);
599 sm_dialogCancelled
= FALSE
;
602 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
604 // SetReturnCode(wxID_CANCEL);
605 m_managedWindow
->Close(TRUE
);
606 sm_dialogCancelled
= TRUE
;
609 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
613 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
615 if (m_currentProperty
)
617 RetrieveProperty(m_currentProperty
);
621 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
623 if (m_currentProperty
&& m_currentValidator
)
625 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
628 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
630 // Revert to old value
631 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
635 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
637 if (m_currentProperty
&& m_currentValidator
)
639 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
642 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
644 // Revert to old value
645 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
649 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
651 if (m_currentProperty
&& m_currentValidator
)
653 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
656 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
658 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
662 void wxPropertyListView::OnText(wxCommandEvent
& event
)
664 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
670 // ----------------------------------------------------------------------------
671 // Property dialog box
672 // ----------------------------------------------------------------------------
674 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog
, wxDialog
)
676 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
677 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
678 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
681 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
682 const wxString
& title
, const wxPoint
& pos
,
683 const wxSize
& size
, long style
, const wxString
& name
):
684 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
687 m_view
->AssociatePanel( ((wxPanel
*)this) );
688 m_view
->SetManagedWindow(this);
692 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
696 SetReturnCode(wxID_CANCEL
);
707 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
709 SetReturnCode(wxID_CANCEL
);
713 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
716 if (item == m_view->GetPropertyScrollingList())
717 view->OnDoubleClick();
721 // Extend event processing to search the view's event table
722 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
724 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
725 return wxEvtHandler::ProcessEvent(event
);
730 // ----------------------------------------------------------------------------
732 // ----------------------------------------------------------------------------
734 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel
, wxPanel
)
736 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
737 EVT_SIZE(wxPropertyListPanel::OnSize
)
740 wxPropertyListPanel::~wxPropertyListPanel()
744 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
747 if (item == view->GetPropertyScrollingList())
748 view->OnDoubleClick();
752 // Extend event processing to search the view's event table
753 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
755 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
756 return wxEvtHandler::ProcessEvent(event
);
761 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
766 // ----------------------------------------------------------------------------
768 // ----------------------------------------------------------------------------
770 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame
, wxFrame
)
772 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
773 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
776 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
781 m_propertyPanel
->SetView(NULL
);
792 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
794 return new wxPropertyListPanel(v
, parent
);
797 bool wxPropertyListFrame::Initialize()
799 m_propertyPanel
= OnCreatePanel(this, m_view
);
802 m_view
->AssociatePanel(m_propertyPanel
);
803 m_view
->SetManagedWindow(this);
804 m_propertyPanel
->SetAutoLayout(TRUE
);
811 // ----------------------------------------------------------------------------
812 // Property list specific validator
813 // ----------------------------------------------------------------------------
815 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
817 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
819 // view->GetValueText()->Show(TRUE);
821 OnDisplayValue(property
, view
, parentWindow
);
826 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
828 wxString
s(view
->GetValueList()->GetStringSelection());
831 view
->GetValueText()->SetValue(s
);
832 view
->RetrieveProperty(property
);
837 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
839 // view->GetValueText()->Show(TRUE);
840 wxString
str(property
->GetValue().GetStringRepresentation());
842 view
->GetValueText()->SetValue(str
);
846 // Called when TICK is pressed or focus is lost or view wants to update
847 // the property list.
848 // Does the transferance from the property editing area to the property itself
849 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
851 if (!view
->GetValueText())
856 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
858 if (view
->GetDetailedEditing())
859 view
->EndDetailedEditing();
861 view
->BeginDetailedEditing();
864 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
866 if (view
->GetConfirmButton())
867 view
->GetConfirmButton()->Enable(FALSE
);
868 if (view
->GetCancelButton())
869 view
->GetCancelButton()->Enable(FALSE
);
870 if (view
->GetEditButton())
871 view
->GetEditButton()->Enable(FALSE
);
875 // ----------------------------------------------------------------------------
876 // Default validators
877 // ----------------------------------------------------------------------------
879 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
882 /// Real number validator
884 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
886 if (m_realMin
== 0.0 && m_realMax
== 0.0)
889 if (!view
->GetValueText())
891 wxString
value(view
->GetValueText()->GetValue());
894 if (!StringToFloat(WXSTRINGCAST value
, &val
))
897 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), value
.GetData());
898 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
902 if (val
< m_realMin
|| val
> m_realMax
)
905 wxSprintf(buf
, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin
, m_realMax
);
906 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
912 // Called when TICK is pressed or focus is lost or view wants to update
913 // the property list.
914 // Does the transferance from the property editing area to the property itself
915 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
917 if (!view
->GetValueText())
920 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
923 wxString
value(view
->GetValueText()->GetValue());
924 float f
= (float)wxAtof(value
.GetData());
925 property
->GetValue() = f
;
929 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
931 if (view
->GetConfirmButton())
932 view
->GetConfirmButton()->Enable(TRUE
);
933 if (view
->GetCancelButton())
934 view
->GetCancelButton()->Enable(TRUE
);
935 if (view
->GetEditButton())
936 view
->GetEditButton()->Enable(FALSE
);
937 if (view
->GetValueText())
938 view
->GetValueText()->Enable(TRUE
);
943 /// Integer validator
945 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
947 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
949 if (m_integerMin
== 0 && m_integerMax
== 0)
952 if (!view
->GetValueText())
954 wxString
value(view
->GetValueText()->GetValue());
957 if (!StringToLong(WXSTRINGCAST value
, &val
))
960 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), value
.GetData());
961 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
964 if (val
< m_integerMin
|| val
> m_integerMax
)
967 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
968 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
974 // Called when TICK is pressed or focus is lost or view wants to update
975 // the property list.
976 // Does the transferance from the property editing area to the property itself
977 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
979 if (!view
->GetValueText())
982 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
985 wxString
value(view
->GetValueText()->GetValue());
986 long val
= (long)wxAtoi(value
.GetData());
987 property
->GetValue() = (long)val
;
991 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
993 if (view
->GetConfirmButton())
994 view
->GetConfirmButton()->Enable(TRUE
);
995 if (view
->GetCancelButton())
996 view
->GetCancelButton()->Enable(TRUE
);
997 if (view
->GetEditButton())
998 view
->GetEditButton()->Enable(FALSE
);
999 if (view
->GetValueText())
1000 view
->GetValueText()->Enable(TRUE
);
1005 /// boolean validator
1007 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1009 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1011 if (!view
->GetValueText())
1013 wxString
value(view
->GetValueText()->GetValue());
1014 if (value
!= wxT("True") && value
!= wxT("False"))
1016 wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1022 // Called when TICK is pressed or focus is lost or view wants to update
1023 // the property list.
1024 // Does the transferance from the property editing area to the property itself
1025 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1027 if (!view
->GetValueText())
1030 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1033 wxString
value(view
->GetValueText()->GetValue());
1034 bool boolValue
= FALSE
;
1035 if (value
== wxT("True"))
1039 property
->GetValue() = (bool)boolValue
;
1043 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1045 if (!view
->GetValueText())
1047 wxString
str(property
->GetValue().GetStringRepresentation());
1049 view
->GetValueText()->SetValue(str
);
1051 if (view
->GetValueList()->IsShown())
1053 view
->GetValueList()->SetStringSelection(str
);
1058 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1060 if (view
->GetConfirmButton())
1061 view
->GetConfirmButton()->Enable(FALSE
);
1062 if (view
->GetCancelButton())
1063 view
->GetCancelButton()->Enable(FALSE
);
1064 if (view
->GetEditButton())
1065 view
->GetEditButton()->Enable(TRUE
);
1066 if (view
->GetValueText())
1067 view
->GetValueText()->Enable(FALSE
);
1071 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1073 if (view
->GetValueList())
1075 view
->ShowListBoxControl(TRUE
);
1076 view
->GetValueList()->Enable(TRUE
);
1078 view
->GetValueList()->Append(wxT("True"));
1079 view
->GetValueList()->Append(wxT("False"));
1080 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1081 view
->GetValueList()->SetStringSelection(currentString
);
1082 delete[] currentString
;
1087 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1089 if (view
->GetValueList())
1091 view
->GetValueList()->Clear();
1092 view
->ShowListBoxControl(FALSE
);
1093 view
->GetValueList()->Enable(FALSE
);
1098 // Called when the property is double clicked. Extra functionality can be provided,
1099 // cycling through possible values.
1100 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1102 if (!view
->GetValueText())
1104 if (property
->GetValue().BoolValue())
1105 property
->GetValue() = (bool)FALSE
;
1107 property
->GetValue() = (bool)TRUE
;
1108 view
->DisplayProperty(property
);
1109 view
->UpdatePropertyDisplayInList(property
);
1110 view
->OnPropertyChanged(property
);
1115 /// String validator
1117 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1119 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1120 wxPropertyListValidator(flags
)
1123 // If no constraint, we just allow the string to be edited.
1124 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1125 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1128 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1133 if (!view
->GetValueText())
1135 wxString
value(view
->GetValueText()->GetValue());
1137 if (!m_strings
->Member(value
.GetData()))
1139 wxString
str( wxT("Value ") );
1140 str
+= value
.GetData();
1141 str
+= wxT(" is not valid.");
1142 wxMessageBox( str
.GetData(), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1148 // Called when TICK is pressed or focus is lost or view wants to update
1149 // the property list.
1150 // Does the transferance from the property editing area to the property itself
1151 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1153 if (!view
->GetValueText())
1155 wxString
value(view
->GetValueText()->GetValue());
1156 property
->GetValue() = value
;
1160 // Called when TICK is pressed or focus is lost or view wants to update
1161 // the property list.
1162 // Does the transferance from the property editing area to the property itself
1163 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1165 if (!view
->GetValueText())
1167 wxString
str(property
->GetValue().GetStringRepresentation());
1168 view
->GetValueText()->SetValue(str
);
1169 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->GetCount() > 0)
1171 view
->GetValueList()->SetStringSelection(str
);
1176 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1181 if (view
->GetEditButton())
1182 view
->GetEditButton()->Enable(FALSE
);
1183 if (view
->GetConfirmButton())
1184 view
->GetConfirmButton()->Enable(TRUE
);
1185 if (view
->GetCancelButton())
1186 view
->GetCancelButton()->Enable(TRUE
);
1187 if (view
->GetValueText())
1188 view
->GetValueText()->Enable(TRUE
);
1193 if (view
->GetValueText())
1194 view
->GetValueText()->Enable(FALSE
);
1196 if (view
->GetEditButton())
1197 view
->GetEditButton()->Enable(TRUE
);
1199 if (view
->GetConfirmButton())
1200 view
->GetConfirmButton()->Enable(FALSE
);
1201 if (view
->GetCancelButton())
1202 view
->GetCancelButton()->Enable(FALSE
);
1206 bool wxStringListValidator::OnPrepareDetailControls( wxProperty
*property
,
1207 wxPropertyListView
*view
,
1208 wxWindow
*WXUNUSED(parentWindow
) )
1210 if (view
->GetValueList())
1212 view
->ShowListBoxControl(TRUE
);
1213 view
->GetValueList()->Enable(TRUE
);
1214 wxStringList::Node
*node
= m_strings
->GetFirst();
1217 wxChar
*s
= node
->GetData();
1218 view
->GetValueList()->Append(s
);
1219 node
= node
->GetNext();
1221 wxChar
*currentString
= property
->GetValue().StringValue();
1222 view
->GetValueList()->SetStringSelection(currentString
);
1227 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1234 if (view
->GetValueList())
1236 view
->GetValueList()->Clear();
1237 view
->ShowListBoxControl(FALSE
);
1238 view
->GetValueList()->Enable(FALSE
);
1243 // Called when the property is double clicked. Extra functionality can be provided,
1244 // cycling through possible values.
1245 bool wxStringListValidator::OnDoubleClick( wxProperty
*property
,
1246 wxPropertyListView
*view
,
1247 wxWindow
*WXUNUSED(parentWindow
) )
1249 if (!view
->GetValueText())
1254 wxStringList::Node
*node
= m_strings
->GetFirst();
1255 wxChar
*currentString
= property
->GetValue().StringValue();
1258 wxChar
*s
= node
->GetData();
1259 if (wxStrcmp(s
, currentString
) == 0)
1261 wxChar
*nextString
= NULL
;
1262 if (node
->GetNext())
1263 nextString
= node
->GetNext()->GetData();
1265 nextString
= m_strings
->GetFirst()->GetData();
1266 property
->GetValue() = wxString(nextString
);
1267 view
->DisplayProperty(property
);
1268 view
->UpdatePropertyDisplayInList(property
);
1269 view
->OnPropertyChanged(property
);
1272 else node
= node
->GetNext();
1278 /// Filename validator
1280 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1282 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1283 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1287 wxFilenameListValidator::~wxFilenameListValidator()
1291 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1296 // Called when TICK is pressed or focus is lost or view wants to update
1297 // the property list.
1298 // Does the transferance from the property editing area to the property itself
1299 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1301 if (!view
->GetValueText())
1303 wxString
value(view
->GetValueText()->GetValue());
1304 property
->GetValue() = value
;
1308 // Called when TICK is pressed or focus is lost or view wants to update
1309 // the property list.
1310 // Does the transferance from the property editing area to the property itself
1311 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1313 if (!view
->GetValueText())
1315 wxString
str(property
->GetValue().GetStringRepresentation());
1316 view
->GetValueText()->SetValue(str
);
1320 // Called when the property is double clicked. Extra functionality can be provided,
1321 // cycling through possible values.
1322 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1324 if (!view
->GetValueText())
1326 OnEdit(property
, view
, parentWindow
);
1330 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1332 if (view
->GetConfirmButton())
1333 view
->GetConfirmButton()->Enable(TRUE
);
1334 if (view
->GetCancelButton())
1335 view
->GetCancelButton()->Enable(TRUE
);
1336 if (view
->GetEditButton())
1337 view
->GetEditButton()->Enable(TRUE
);
1338 if (view
->GetValueText())
1339 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1343 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1345 if (!view
->GetValueText())
1348 wxString s
= wxFileSelector(
1349 m_filenameMessage
.GetData(),
1350 wxPathOnly(property
->GetValue().StringValue()),
1351 wxFileNameFromPath(property
->GetValue().StringValue()),
1353 m_filenameWildCard
.GetData(),
1358 property
->GetValue() = s
;
1359 view
->DisplayProperty(property
);
1360 view
->UpdatePropertyDisplayInList(property
);
1361 view
->OnPropertyChanged(property
);
1366 /// Colour validator
1368 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1370 wxColourListValidator::wxColourListValidator(long flags
):
1371 wxPropertyListValidator(flags
)
1375 wxColourListValidator::~wxColourListValidator()
1379 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1384 // Called when TICK is pressed or focus is lost or view wants to update
1385 // the property list.
1386 // Does the transferance from the property editing area to the property itself
1387 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1389 if (!view
->GetValueText())
1391 wxString
value(view
->GetValueText()->GetValue());
1393 property
->GetValue() = value
;
1397 // Called when TICK is pressed or focus is lost or view wants to update
1398 // the property list.
1399 // Does the transferance from the property editing area to the property itself
1400 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1402 if (!view
->GetValueText())
1404 wxString
str(property
->GetValue().GetStringRepresentation());
1405 view
->GetValueText()->SetValue(str
);
1409 // Called when the property is double clicked. Extra functionality can be provided,
1410 // cycling through possible values.
1411 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1413 if (!view
->GetValueText())
1415 OnEdit(property
, view
, parentWindow
);
1419 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1421 if (view
->GetConfirmButton())
1422 view
->GetConfirmButton()->Enable(TRUE
);
1423 if (view
->GetCancelButton())
1424 view
->GetCancelButton()->Enable(TRUE
);
1425 if (view
->GetEditButton())
1426 view
->GetEditButton()->Enable(TRUE
);
1427 if (view
->GetValueText())
1428 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1432 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1434 if (!view
->GetValueText())
1437 wxChar
*s
= property
->GetValue().StringValue();
1444 g
= wxHexToDec(s
+2);
1445 b
= wxHexToDec(s
+4);
1448 wxColour
col(r
,g
,b
);
1451 data
.SetChooseFull(TRUE
);
1452 data
.SetColour(col
);
1454 for (int i
= 0; i
< 16; i
++)
1456 wxColour
colour(i
*16, i
*16, i
*16);
1457 data
.SetCustomColour(i
, colour
);
1460 wxColourDialog
dialog(parentWindow
, &data
);
1461 if (dialog
.ShowModal() != wxID_CANCEL
)
1463 wxColourData retData
= dialog
.GetColourData();
1464 col
= retData
.GetColour();
1467 wxDecToHex(col
.Red(), buf
);
1468 wxDecToHex(col
.Green(), buf
+2);
1469 wxDecToHex(col
.Blue(), buf
+4);
1471 property
->GetValue() = wxString(buf
);
1472 view
->DisplayProperty(property
);
1473 view
->UpdatePropertyDisplayInList(property
);
1474 view
->OnPropertyChanged(property
);
1479 /// List of strings validator. For this we need more user interface than
1480 /// we get with a property list; so create a new dialog for editing the list.
1482 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1484 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1485 wxPropertyListValidator(flags
)
1489 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1491 // No constraints for an arbitrary, user-editable list of strings.
1495 // Called when TICK is pressed or focus is lost or view wants to update
1496 // the property list.
1497 // Does the transferance from the property editing area to the property itself.
1498 // In this case, the user cannot directly edit the string list.
1499 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1504 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1506 if (!view
->GetValueText())
1508 wxString
str(property
->GetValue().GetStringRepresentation());
1509 view
->GetValueText()->SetValue(str
);
1513 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1515 if (view
->GetEditButton())
1516 view
->GetEditButton()->Enable(TRUE
);
1517 if (view
->GetValueText())
1518 view
->GetValueText()->Enable(FALSE
);
1520 if (view
->GetConfirmButton())
1521 view
->GetConfirmButton()->Enable(FALSE
);
1522 if (view
->GetCancelButton())
1523 view
->GetCancelButton()->Enable(FALSE
);
1527 // Called when the property is double clicked. Extra functionality can be provided,
1528 // cycling through possible values.
1529 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1531 OnEdit(property
, view
, parentWindow
);
1535 void wxListOfStringsListValidator::OnEdit( wxProperty
*property
,
1536 wxPropertyListView
*view
,
1537 wxWindow
*parentWindow
)
1539 // Convert property value to a list of strings for editing
1540 wxStringList
*stringList
= new wxStringList
;
1542 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1545 wxChar
*s
= expr
->StringValue();
1548 expr
= expr
->GetNext();
1551 wxString
title(wxT("Editing "));
1552 title
+= property
->GetName();
1554 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1556 wxPropertyValue
& oldValue
= property
->GetValue();
1557 oldValue
.ClearList();
1558 wxStringList::Node
*node
= stringList
->GetFirst();
1561 wxChar
*s
= node
->GetData();
1562 oldValue
.Append(new wxPropertyValue(s
));
1564 node
= node
->GetNext();
1567 view
->DisplayProperty(property
);
1568 view
->UpdatePropertyDisplayInList(property
);
1569 view
->OnPropertyChanged(property
);
1574 class wxPropertyStringListEditorDialog
: public wxDialog
1577 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1578 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1579 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= wxT("stringEditorDialogBox")):
1580 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1582 m_stringList
= NULL
;
1583 m_stringText
= NULL
;
1585 sm_dialogCancelled
= FALSE
;
1586 m_currentSelection
= -1;
1588 ~wxPropertyStringListEditorDialog(void) {}
1589 void OnCloseWindow(wxCloseEvent
& event
);
1590 void SaveCurrentSelection(void);
1591 void ShowCurrentSelection(void);
1593 void OnOK(wxCommandEvent
& event
);
1594 void OnCancel(wxCommandEvent
& event
);
1595 void OnAdd(wxCommandEvent
& event
);
1596 void OnDelete(wxCommandEvent
& event
);
1597 void OnStrings(wxCommandEvent
& event
);
1598 void OnText(wxCommandEvent
& event
);
1601 wxStringList
* m_stringList
;
1602 wxListBox
* m_listBox
;
1603 wxTextCtrl
* m_stringText
;
1604 static bool sm_dialogCancelled
;
1605 int m_currentSelection
;
1606 DECLARE_EVENT_TABLE()
1609 #define wxID_PROP_SL_ADD 3000
1610 #define wxID_PROP_SL_DELETE 3001
1611 #define wxID_PROP_SL_STRINGS 3002
1612 #define wxID_PROP_SL_TEXT 3003
1614 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1615 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1616 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1617 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1618 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1619 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1620 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1621 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1624 class wxPropertyStringListEditorText
: public wxTextCtrl
1627 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1628 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1629 long windowStyle
= 0, const wxString
& name
= wxT("text")):
1630 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1635 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1636 dialog
->SaveCurrentSelection();
1640 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1642 // Edit the string list.
1643 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1645 int largeButtonWidth
= 60;
1646 int largeButtonHeight
= 25;
1648 wxBeginBusyCursor();
1649 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1650 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1652 dialog
->m_stringList
= stringList
;
1654 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1655 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1657 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1658 wxID_PROP_SL_TEXT
, wxT(""), wxPoint(5, 240),
1659 wxSize(300, -1), wxPROCESS_ENTER
);
1660 dialog
->m_stringText
->Enable(FALSE
);
1662 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, wxT("Add"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1663 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, wxT("Delete"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1664 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, wxT("Cancel"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1665 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, wxT("OK"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1668 okButton
->SetDefault();
1671 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1673 c
->top
.SameAs (dialog
, wxTop
, 2);
1674 c
->left
.SameAs (dialog
, wxLeft
, 2);
1675 c
->right
.SameAs (dialog
, wxRight
, 2);
1676 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1677 dialog
->m_listBox
->SetConstraints(c
);
1679 c
= new wxLayoutConstraints
;
1680 c
->left
.SameAs (dialog
, wxLeft
, 2);
1681 c
->right
.SameAs (dialog
, wxRight
, 2);
1682 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1684 dialog
->m_stringText
->SetConstraints(c
);
1686 c
= new wxLayoutConstraints
;
1687 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1688 c
->left
.SameAs (dialog
, wxLeft
, 2);
1691 addButton
->SetConstraints(c
);
1693 c
= new wxLayoutConstraints
;
1694 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1695 c
->left
.SameAs (addButton
, wxRight
, 2);
1698 deleteButton
->SetConstraints(c
);
1700 c
= new wxLayoutConstraints
;
1701 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1702 c
->right
.SameAs (dialog
, wxRight
, 2);
1705 cancelButton
->SetConstraints(c
);
1707 c
= new wxLayoutConstraints
;
1708 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1709 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1712 okButton
->SetConstraints(c
);
1714 wxStringList::Node
*node
= stringList
->GetFirst();
1717 wxChar
*str
= node
->GetData();
1718 // Save node as client data for each listbox item
1719 dialog
->m_listBox
->Append(str
, (wxChar
*)node
);
1720 node
= node
->GetNext();
1723 dialog
->SetClientSize(310, 305);
1726 dialog
->Centre(wxBOTH
);
1728 if (dialog
->ShowModal() == wxID_CANCEL
)
1735 * String list editor callbacks
1739 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1741 int sel
= m_listBox
->GetSelection();
1744 m_currentSelection
= sel
;
1746 ShowCurrentSelection();
1750 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1752 int sel
= m_listBox
->GetSelection();
1756 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1760 m_listBox
->Delete(sel
);
1761 delete[] (wxChar
*)node
->GetData();
1763 m_currentSelection
= -1;
1764 m_stringText
->SetValue(_T(""));
1767 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1769 SaveCurrentSelection();
1771 wxString initialText
;
1772 wxNode
*node
= m_stringList
->Add(initialText
);
1773 m_listBox
->Append(initialText
, (void *)node
);
1774 m_currentSelection
= m_stringList
->GetCount() - 1;
1775 m_listBox
->SetSelection(m_currentSelection
);
1776 ShowCurrentSelection();
1777 m_stringText
->SetFocus();
1780 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1782 SaveCurrentSelection();
1788 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1790 sm_dialogCancelled
= TRUE
;
1791 EndModal(wxID_CANCEL
);
1796 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1798 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1800 SaveCurrentSelection();
1805 wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
1807 SaveCurrentSelection();
1812 void wxPropertyStringListEditorDialog::SaveCurrentSelection()
1814 if (m_currentSelection
== -1)
1817 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1821 wxString
txt(m_stringText
->GetValue());
1822 if (node
->GetData())
1823 delete[] (wxChar
*)node
->GetData();
1824 node
->SetData((wxObject
*)wxStrdup(txt
));
1826 m_listBox
->SetString(m_currentSelection
, (wxChar
*)node
->GetData());
1829 void wxPropertyStringListEditorDialog::ShowCurrentSelection()
1831 if (m_currentSelection
== -1)
1833 m_stringText
->SetValue(wxT(""));
1836 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1837 wxChar
*txt
= (wxChar
*)node
->GetData();
1838 m_stringText
->SetValue(txt
);
1839 m_stringText
->Enable(TRUE
);
1843 #endif // wxUSE_PROPSHEET