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 // ----------------------------------------------------------------------------
61 // Property text edit control
62 // ----------------------------------------------------------------------------
64 IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
66 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
67 const wxWindowID id
, const wxString
& value
,
68 const wxPoint
& pos
, const wxSize
& size
,
69 long style
, const wxString
& name
):
70 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
75 void wxPropertyTextEdit::OnSetFocus()
79 void wxPropertyTextEdit::OnKillFocus()
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
89 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
91 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
92 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
93 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
94 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
95 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
96 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
97 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
98 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
99 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
100 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
101 wxPropertyListView::OnPropertyDoubleClick
)
102 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
105 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
107 m_propertyScrollingList
= NULL
;
111 m_confirmButton
= NULL
;
112 m_cancelButton
= NULL
;
113 m_propertyWindow
= propPanel
;
114 m_managedWindow
= NULL
;
116 m_windowCloseButton
= NULL
;
117 m_windowCancelButton
= NULL
;
118 m_windowHelpButton
= NULL
;
120 m_detailedEditing
= FALSE
;
123 wxPropertyListView::~wxPropertyListView()
127 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
129 m_propertySheet
= ps
;
131 AssociatePanel(panel
);
134 UpdatePropertyList();
138 // Update this view of the viewed object, called e.g. by
139 // the object itself.
140 bool wxPropertyListView::OnUpdateView()
145 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
147 if (!m_propertyScrollingList
|| !m_propertySheet
)
150 m_propertyScrollingList
->Clear();
153 m_valueList
->Clear();
154 m_valueText
->SetValue( wxT("") );
156 wxNode
*node
= m_propertySheet
->GetProperties().GetFirst();
158 // Should sort them... later...
161 wxProperty
*property
= (wxProperty
*)node
->GetData();
162 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
163 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
164 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
165 node
= node
->GetNext();
170 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
172 if (!m_propertyScrollingList
|| !m_propertySheet
)
176 int currentlySelected
= m_propertyScrollingList
->GetSelection();
179 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
180 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
181 int sel
= FindListIndexForProperty(property
);
185 // Don't update the listbox unnecessarily because it can cause
188 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
189 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
192 // UpdatePropertyList(FALSE);
195 // TODO: why is this necessary?
197 if (currentlySelected
> -1)
198 m_propertyScrollingList
->SetSelection(currentlySelected
);
204 // Find the wxListBox index corresponding to this property
205 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
207 int n
= m_propertyScrollingList
->GetCount();
208 for (int i
= 0; i
< n
; i
++)
210 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
216 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
218 wxString
theString(name
);
221 int padWith
= nameWidth
- theString
.Length();
225 if (GetFlags() & wxPROP_SHOWVALUES
)
227 // Want to pad with spaces
228 theString
.Append( wxT(' '), padWith
);
235 // Select and show string representation in validator the given
236 // property. NULL resets to show no property.
237 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
239 if (m_currentProperty
)
241 EndShowingProperty(m_currentProperty
);
242 m_currentProperty
= NULL
;
245 m_valueList
->Clear();
246 m_valueText
->SetValue( wxT("") );
250 m_currentProperty
= property
;
251 BeginShowingProperty(property
);
255 int sel
= FindListIndexForProperty(property
);
257 m_propertyScrollingList
->SetSelection(sel
);
262 // Find appropriate validator and load property into value controls
263 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
265 m_currentValidator
= FindPropertyValidator(property
);
266 if (!m_currentValidator
)
269 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
272 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
274 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
275 DisplayProperty(property
);
279 // Find appropriate validator and unload property from value controls
280 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
282 if (!m_currentValidator
)
285 RetrieveProperty(property
);
287 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
290 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
292 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
293 if (m_detailedEditing
)
295 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
296 m_detailedEditing
= FALSE
;
301 void wxPropertyListView::BeginDetailedEditing()
303 if (!m_currentValidator
)
305 if (!m_currentProperty
)
307 if (m_detailedEditing
)
309 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
311 if (!m_currentProperty
->IsEnabled())
314 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
316 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
317 m_detailedEditing
= TRUE
;
320 void wxPropertyListView::EndDetailedEditing()
322 if (!m_currentValidator
)
324 if (!m_currentProperty
)
327 RetrieveProperty(m_currentProperty
);
329 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
332 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
334 if (m_detailedEditing
)
336 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
337 m_detailedEditing
= FALSE
;
341 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
343 if (!m_currentValidator
)
346 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
347 m_valueText
->SetEditable(FALSE
);
349 m_valueText
->SetEditable(TRUE
);
351 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
354 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
356 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
360 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
362 if (!m_currentValidator
)
364 if (!property
->IsEnabled())
367 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
370 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
372 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
374 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
376 UpdatePropertyDisplayInList(property
);
377 OnPropertyChanged(property
);
382 // Revert to old value
383 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
389 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
394 // Called by the listbox callback
395 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
397 int sel
= m_propertyScrollingList
->GetSelection();
400 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
401 if (newSel
&& newSel
!= m_currentProperty
)
403 ShowProperty(newSel
, FALSE
);
408 bool wxPropertyListView::CreateControls()
410 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
412 wxSize
largeButtonSize( 70, 25 );
413 wxSize
smallButtonSize( 23, 23 );
421 wxFont guiFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
425 wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
,
426 wxNORMAL
, wxNORMAL
, FALSE
, _T("Courier New"));
428 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
431 // May need to be changed in future to eliminate clashes with app.
432 // WHAT WAS THIS FOR?
433 // panel->SetClientData((char *)this);
435 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
437 // top row with optional buttons and input line
439 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
440 int buttonborder
= 3;
442 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
444 wxBitmap tickBitmap
= wxArtProvider::GetBitmap(wxART_TICK_MARK
);
445 wxBitmap crossBitmap
= wxArtProvider::GetBitmap(wxART_CROSS_MARK
);
447 if ( tickBitmap
.Ok() && crossBitmap
.Ok() )
449 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, tickBitmap
, wxPoint(-1, -1), smallButtonSize
);
450 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, crossBitmap
, wxPoint(-1, -1), smallButtonSize
);
454 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, _T(":-)"), wxPoint(-1, -1), smallButtonSize
);
455 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, _T("X"), wxPoint(-1, -1), smallButtonSize
);
458 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
459 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
462 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, _T(""),
463 wxPoint(-1, -1), wxSize(-1, smallButtonSize
.y
), wxPROCESS_ENTER
);
464 m_valueText
->Enable(FALSE
);
465 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
467 if (m_buttonFlags
& wxPROP_PULLDOWN
)
469 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, _T("..."), wxPoint(-1, -1), smallButtonSize
);
470 m_editButton
->Enable(FALSE
);
471 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
474 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
476 // middle section with two list boxes
478 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
480 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
481 m_valueList
->Show(FALSE
);
483 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxPoint(-1, -1), wxSize(100, 100));
484 m_propertyScrollingList
->SetFont(* boringFont
);
485 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
487 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
489 // bottom row with buttons
491 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
492 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
493 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
494 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
496 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
499 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
501 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxPoint(-1, -1), largeButtonSize
);
502 m_windowCloseButton
->SetDefault();
503 m_windowCloseButton
->SetFocus();
504 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
506 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
508 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxPoint(-1, -1), largeButtonSize
);
509 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
511 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
513 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxPoint(-1, -1), largeButtonSize
);
514 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
516 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
518 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxPoint(-1, -1), largeButtonSize
);
519 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
522 mainsizer
->Add( bottomsizer
, 0, wxALIGN_RIGHT
| wxEXPAND
);
525 panel
->SetSizer( mainsizer
);
530 void wxPropertyListView::ShowTextControl(bool show
)
533 m_valueText
->Show(show
);
536 void wxPropertyListView::ShowListBoxControl(bool show
)
538 if (!m_valueList
) return;
540 m_valueList
->Show(show
);
542 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
545 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
547 m_middleSizer
->Remove( 0 );
549 m_propertyWindow
->Layout();
553 void wxPropertyListView::EnableCheck(bool show
)
556 m_confirmButton
->Enable(show
);
559 void wxPropertyListView::EnableCross(bool show
)
562 m_cancelButton
->Enable(show
);
565 bool wxPropertyListView::OnClose()
567 // Retrieve the value if any
568 wxCommandEvent event
;
575 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
577 if (m_currentProperty
&& m_currentValidator
)
579 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
582 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
584 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
588 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
590 // Retrieve the value if any
593 m_managedWindow
->Close(TRUE
);
594 sm_dialogCancelled
= FALSE
;
597 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
599 // SetReturnCode(wxID_CANCEL);
600 m_managedWindow
->Close(TRUE
);
601 sm_dialogCancelled
= TRUE
;
604 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
608 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
610 if (m_currentProperty
)
612 RetrieveProperty(m_currentProperty
);
616 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
618 if (m_currentProperty
&& m_currentValidator
)
620 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
623 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
625 // Revert to old value
626 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
630 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
632 if (m_currentProperty
&& m_currentValidator
)
634 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
637 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
639 // Revert to old value
640 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
644 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
646 if (m_currentProperty
&& m_currentValidator
)
648 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
651 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
653 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
657 void wxPropertyListView::OnText(wxCommandEvent
& event
)
659 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
665 // ----------------------------------------------------------------------------
666 // Property dialog box
667 // ----------------------------------------------------------------------------
669 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog
, wxDialog
)
671 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
672 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
673 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
676 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
677 const wxString
& title
, const wxPoint
& pos
,
678 const wxSize
& size
, long style
, const wxString
& name
):
679 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
682 m_view
->AssociatePanel( ((wxPanel
*)this) );
683 m_view
->SetManagedWindow(this);
687 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
691 SetReturnCode(wxID_CANCEL
);
702 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
704 SetReturnCode(wxID_CANCEL
);
708 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
711 if (item == m_view->GetPropertyScrollingList())
712 view->OnDoubleClick();
716 // Extend event processing to search the view's event table
717 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
719 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
720 return wxEvtHandler::ProcessEvent(event
);
725 // ----------------------------------------------------------------------------
727 // ----------------------------------------------------------------------------
729 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel
, wxPanel
)
731 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
732 EVT_SIZE(wxPropertyListPanel::OnSize
)
735 wxPropertyListPanel::~wxPropertyListPanel()
739 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
742 if (item == view->GetPropertyScrollingList())
743 view->OnDoubleClick();
747 // Extend event processing to search the view's event table
748 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
750 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
751 return wxEvtHandler::ProcessEvent(event
);
756 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
761 // ----------------------------------------------------------------------------
763 // ----------------------------------------------------------------------------
765 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame
, wxFrame
)
767 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
768 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
771 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
776 m_propertyPanel
->SetView(NULL
);
787 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
789 return new wxPropertyListPanel(v
, parent
);
792 bool wxPropertyListFrame::Initialize()
794 m_propertyPanel
= OnCreatePanel(this, m_view
);
797 m_view
->AssociatePanel(m_propertyPanel
);
798 m_view
->SetManagedWindow(this);
799 m_propertyPanel
->SetAutoLayout(TRUE
);
806 // ----------------------------------------------------------------------------
807 // Property list specific validator
808 // ----------------------------------------------------------------------------
810 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
812 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
814 // view->GetValueText()->Show(TRUE);
816 OnDisplayValue(property
, view
, parentWindow
);
821 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
823 wxString
s(view
->GetValueList()->GetStringSelection());
826 view
->GetValueText()->SetValue(s
);
827 view
->RetrieveProperty(property
);
832 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
834 // view->GetValueText()->Show(TRUE);
835 wxString
str(property
->GetValue().GetStringRepresentation());
837 view
->GetValueText()->SetValue(str
);
841 // Called when TICK is pressed or focus is lost or view wants to update
842 // the property list.
843 // Does the transferance from the property editing area to the property itself
844 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
846 if (!view
->GetValueText())
851 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
853 if (view
->GetDetailedEditing())
854 view
->EndDetailedEditing();
856 view
->BeginDetailedEditing();
859 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
861 if (view
->GetConfirmButton())
862 view
->GetConfirmButton()->Enable(FALSE
);
863 if (view
->GetCancelButton())
864 view
->GetCancelButton()->Enable(FALSE
);
865 if (view
->GetEditButton())
866 view
->GetEditButton()->Enable(FALSE
);
870 // ----------------------------------------------------------------------------
871 // Default validators
872 // ----------------------------------------------------------------------------
874 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
877 /// Real number validator
879 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
881 if (m_realMin
== 0.0 && m_realMax
== 0.0)
884 if (!view
->GetValueText())
886 wxString
value(view
->GetValueText()->GetValue());
889 if (!StringToFloat(WXSTRINGCAST value
, &val
))
892 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), value
.GetData());
893 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
897 if (val
< m_realMin
|| val
> m_realMax
)
900 wxSprintf(buf
, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin
, m_realMax
);
901 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
907 // Called when TICK is pressed or focus is lost or view wants to update
908 // the property list.
909 // Does the transferance from the property editing area to the property itself
910 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
912 if (!view
->GetValueText())
915 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
918 wxString
value(view
->GetValueText()->GetValue());
919 float f
= (float)wxAtof(value
.GetData());
920 property
->GetValue() = f
;
924 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
926 if (view
->GetConfirmButton())
927 view
->GetConfirmButton()->Enable(TRUE
);
928 if (view
->GetCancelButton())
929 view
->GetCancelButton()->Enable(TRUE
);
930 if (view
->GetEditButton())
931 view
->GetEditButton()->Enable(FALSE
);
932 if (view
->GetValueText())
933 view
->GetValueText()->Enable(TRUE
);
938 /// Integer validator
940 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
942 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
944 if (m_integerMin
== 0 && m_integerMax
== 0)
947 if (!view
->GetValueText())
949 wxString
value(view
->GetValueText()->GetValue());
952 if (!StringToLong(WXSTRINGCAST value
, &val
))
955 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), value
.GetData());
956 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
959 if (val
< m_integerMin
|| val
> m_integerMax
)
962 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
963 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
969 // Called when TICK is pressed or focus is lost or view wants to update
970 // the property list.
971 // Does the transferance from the property editing area to the property itself
972 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
974 if (!view
->GetValueText())
977 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
980 wxString
value(view
->GetValueText()->GetValue());
981 long val
= (long)wxAtoi(value
.GetData());
982 property
->GetValue() = (long)val
;
986 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
988 if (view
->GetConfirmButton())
989 view
->GetConfirmButton()->Enable(TRUE
);
990 if (view
->GetCancelButton())
991 view
->GetCancelButton()->Enable(TRUE
);
992 if (view
->GetEditButton())
993 view
->GetEditButton()->Enable(FALSE
);
994 if (view
->GetValueText())
995 view
->GetValueText()->Enable(TRUE
);
1000 /// boolean validator
1002 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1004 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1006 if (!view
->GetValueText())
1008 wxString
value(view
->GetValueText()->GetValue());
1009 if (value
!= wxT("True") && value
!= wxT("False"))
1011 wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1017 // Called when TICK is pressed or focus is lost or view wants to update
1018 // the property list.
1019 // Does the transferance from the property editing area to the property itself
1020 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1022 if (!view
->GetValueText())
1025 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1028 wxString
value(view
->GetValueText()->GetValue());
1029 bool boolValue
= FALSE
;
1030 if (value
== wxT("True"))
1034 property
->GetValue() = (bool)boolValue
;
1038 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1040 if (!view
->GetValueText())
1042 wxString
str(property
->GetValue().GetStringRepresentation());
1044 view
->GetValueText()->SetValue(str
);
1046 if (view
->GetValueList()->IsShown())
1048 view
->GetValueList()->SetStringSelection(str
);
1053 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1055 if (view
->GetConfirmButton())
1056 view
->GetConfirmButton()->Enable(FALSE
);
1057 if (view
->GetCancelButton())
1058 view
->GetCancelButton()->Enable(FALSE
);
1059 if (view
->GetEditButton())
1060 view
->GetEditButton()->Enable(TRUE
);
1061 if (view
->GetValueText())
1062 view
->GetValueText()->Enable(FALSE
);
1066 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1068 if (view
->GetValueList())
1070 view
->ShowListBoxControl(TRUE
);
1071 view
->GetValueList()->Enable(TRUE
);
1073 view
->GetValueList()->Append(wxT("True"));
1074 view
->GetValueList()->Append(wxT("False"));
1075 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1076 view
->GetValueList()->SetStringSelection(currentString
);
1077 delete[] currentString
;
1082 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1084 if (view
->GetValueList())
1086 view
->GetValueList()->Clear();
1087 view
->ShowListBoxControl(FALSE
);
1088 view
->GetValueList()->Enable(FALSE
);
1093 // Called when the property is double clicked. Extra functionality can be provided,
1094 // cycling through possible values.
1095 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1097 if (!view
->GetValueText())
1099 if (property
->GetValue().BoolValue())
1100 property
->GetValue() = (bool)FALSE
;
1102 property
->GetValue() = (bool)TRUE
;
1103 view
->DisplayProperty(property
);
1104 view
->UpdatePropertyDisplayInList(property
);
1105 view
->OnPropertyChanged(property
);
1110 /// String validator
1112 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1114 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1115 wxPropertyListValidator(flags
)
1118 // If no constraint, we just allow the string to be edited.
1119 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1120 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1123 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1128 if (!view
->GetValueText())
1130 wxString
value(view
->GetValueText()->GetValue());
1132 if (!m_strings
->Member(value
.GetData()))
1134 wxString
str( wxT("Value ") );
1135 str
+= value
.GetData();
1136 str
+= wxT(" is not valid.");
1137 wxMessageBox( str
.GetData(), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1143 // Called when TICK is pressed or focus is lost or view wants to update
1144 // the property list.
1145 // Does the transferance from the property editing area to the property itself
1146 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1148 if (!view
->GetValueText())
1150 wxString
value(view
->GetValueText()->GetValue());
1151 property
->GetValue() = value
;
1155 // Called when TICK is pressed or focus is lost or view wants to update
1156 // the property list.
1157 // Does the transferance from the property editing area to the property itself
1158 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1160 if (!view
->GetValueText())
1162 wxString
str(property
->GetValue().GetStringRepresentation());
1163 view
->GetValueText()->SetValue(str
);
1164 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->GetCount() > 0)
1166 view
->GetValueList()->SetStringSelection(str
);
1171 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1176 if (view
->GetEditButton())
1177 view
->GetEditButton()->Enable(FALSE
);
1178 if (view
->GetConfirmButton())
1179 view
->GetConfirmButton()->Enable(TRUE
);
1180 if (view
->GetCancelButton())
1181 view
->GetCancelButton()->Enable(TRUE
);
1182 if (view
->GetValueText())
1183 view
->GetValueText()->Enable(TRUE
);
1188 if (view
->GetValueText())
1189 view
->GetValueText()->Enable(FALSE
);
1191 if (view
->GetEditButton())
1192 view
->GetEditButton()->Enable(TRUE
);
1194 if (view
->GetConfirmButton())
1195 view
->GetConfirmButton()->Enable(FALSE
);
1196 if (view
->GetCancelButton())
1197 view
->GetCancelButton()->Enable(FALSE
);
1201 bool wxStringListValidator::OnPrepareDetailControls( wxProperty
*property
,
1202 wxPropertyListView
*view
,
1203 wxWindow
*WXUNUSED(parentWindow
) )
1205 if (view
->GetValueList())
1207 view
->ShowListBoxControl(TRUE
);
1208 view
->GetValueList()->Enable(TRUE
);
1209 wxStringList::Node
*node
= m_strings
->GetFirst();
1212 wxChar
*s
= node
->GetData();
1213 view
->GetValueList()->Append(s
);
1214 node
= node
->GetNext();
1216 wxChar
*currentString
= property
->GetValue().StringValue();
1217 view
->GetValueList()->SetStringSelection(currentString
);
1222 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1229 if (view
->GetValueList())
1231 view
->GetValueList()->Clear();
1232 view
->ShowListBoxControl(FALSE
);
1233 view
->GetValueList()->Enable(FALSE
);
1238 // Called when the property is double clicked. Extra functionality can be provided,
1239 // cycling through possible values.
1240 bool wxStringListValidator::OnDoubleClick( wxProperty
*property
,
1241 wxPropertyListView
*view
,
1242 wxWindow
*WXUNUSED(parentWindow
) )
1244 if (!view
->GetValueText())
1249 wxStringList::Node
*node
= m_strings
->GetFirst();
1250 wxChar
*currentString
= property
->GetValue().StringValue();
1253 wxChar
*s
= node
->GetData();
1254 if (wxStrcmp(s
, currentString
) == 0)
1256 wxChar
*nextString
= NULL
;
1257 if (node
->GetNext())
1258 nextString
= node
->GetNext()->GetData();
1260 nextString
= m_strings
->GetFirst()->GetData();
1261 property
->GetValue() = wxString(nextString
);
1262 view
->DisplayProperty(property
);
1263 view
->UpdatePropertyDisplayInList(property
);
1264 view
->OnPropertyChanged(property
);
1267 else node
= node
->GetNext();
1273 /// Filename validator
1275 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1277 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1278 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1282 wxFilenameListValidator::~wxFilenameListValidator()
1286 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1291 // Called when TICK is pressed or focus is lost or view wants to update
1292 // the property list.
1293 // Does the transferance from the property editing area to the property itself
1294 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1296 if (!view
->GetValueText())
1298 wxString
value(view
->GetValueText()->GetValue());
1299 property
->GetValue() = value
;
1303 // Called when TICK is pressed or focus is lost or view wants to update
1304 // the property list.
1305 // Does the transferance from the property editing area to the property itself
1306 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1308 if (!view
->GetValueText())
1310 wxString
str(property
->GetValue().GetStringRepresentation());
1311 view
->GetValueText()->SetValue(str
);
1315 // Called when the property is double clicked. Extra functionality can be provided,
1316 // cycling through possible values.
1317 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1319 if (!view
->GetValueText())
1321 OnEdit(property
, view
, parentWindow
);
1325 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1327 if (view
->GetConfirmButton())
1328 view
->GetConfirmButton()->Enable(TRUE
);
1329 if (view
->GetCancelButton())
1330 view
->GetCancelButton()->Enable(TRUE
);
1331 if (view
->GetEditButton())
1332 view
->GetEditButton()->Enable(TRUE
);
1333 if (view
->GetValueText())
1334 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1338 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1340 if (!view
->GetValueText())
1343 wxString s
= wxFileSelector(
1344 m_filenameMessage
.GetData(),
1345 wxPathOnly(property
->GetValue().StringValue()),
1346 wxFileNameFromPath(property
->GetValue().StringValue()),
1348 m_filenameWildCard
.GetData(),
1353 property
->GetValue() = s
;
1354 view
->DisplayProperty(property
);
1355 view
->UpdatePropertyDisplayInList(property
);
1356 view
->OnPropertyChanged(property
);
1361 /// Colour validator
1363 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1365 wxColourListValidator::wxColourListValidator(long flags
):
1366 wxPropertyListValidator(flags
)
1370 wxColourListValidator::~wxColourListValidator()
1374 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1379 // Called when TICK is pressed or focus is lost or view wants to update
1380 // the property list.
1381 // Does the transferance from the property editing area to the property itself
1382 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1384 if (!view
->GetValueText())
1386 wxString
value(view
->GetValueText()->GetValue());
1388 property
->GetValue() = value
;
1392 // Called when TICK is pressed or focus is lost or view wants to update
1393 // the property list.
1394 // Does the transferance from the property editing area to the property itself
1395 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1397 if (!view
->GetValueText())
1399 wxString
str(property
->GetValue().GetStringRepresentation());
1400 view
->GetValueText()->SetValue(str
);
1404 // Called when the property is double clicked. Extra functionality can be provided,
1405 // cycling through possible values.
1406 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1408 if (!view
->GetValueText())
1410 OnEdit(property
, view
, parentWindow
);
1414 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1416 if (view
->GetConfirmButton())
1417 view
->GetConfirmButton()->Enable(TRUE
);
1418 if (view
->GetCancelButton())
1419 view
->GetCancelButton()->Enable(TRUE
);
1420 if (view
->GetEditButton())
1421 view
->GetEditButton()->Enable(TRUE
);
1422 if (view
->GetValueText())
1423 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1427 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1429 if (!view
->GetValueText())
1432 wxChar
*s
= property
->GetValue().StringValue();
1439 g
= wxHexToDec(s
+2);
1440 b
= wxHexToDec(s
+4);
1443 wxColour
col(r
,g
,b
);
1446 data
.SetChooseFull(TRUE
);
1447 data
.SetColour(col
);
1449 for (int i
= 0; i
< 16; i
++)
1451 wxColour
colour(i
*16, i
*16, i
*16);
1452 data
.SetCustomColour(i
, colour
);
1455 wxColourDialog
dialog(parentWindow
, &data
);
1456 if (dialog
.ShowModal() != wxID_CANCEL
)
1458 wxColourData retData
= dialog
.GetColourData();
1459 col
= retData
.GetColour();
1462 wxDecToHex(col
.Red(), buf
);
1463 wxDecToHex(col
.Green(), buf
+2);
1464 wxDecToHex(col
.Blue(), buf
+4);
1466 property
->GetValue() = wxString(buf
);
1467 view
->DisplayProperty(property
);
1468 view
->UpdatePropertyDisplayInList(property
);
1469 view
->OnPropertyChanged(property
);
1474 /// List of strings validator. For this we need more user interface than
1475 /// we get with a property list; so create a new dialog for editing the list.
1477 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1479 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1480 wxPropertyListValidator(flags
)
1484 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1486 // No constraints for an arbitrary, user-editable list of strings.
1490 // Called when TICK is pressed or focus is lost or view wants to update
1491 // the property list.
1492 // Does the transferance from the property editing area to the property itself.
1493 // In this case, the user cannot directly edit the string list.
1494 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1499 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1501 if (!view
->GetValueText())
1503 wxString
str(property
->GetValue().GetStringRepresentation());
1504 view
->GetValueText()->SetValue(str
);
1508 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1510 if (view
->GetEditButton())
1511 view
->GetEditButton()->Enable(TRUE
);
1512 if (view
->GetValueText())
1513 view
->GetValueText()->Enable(FALSE
);
1515 if (view
->GetConfirmButton())
1516 view
->GetConfirmButton()->Enable(FALSE
);
1517 if (view
->GetCancelButton())
1518 view
->GetCancelButton()->Enable(FALSE
);
1522 // Called when the property is double clicked. Extra functionality can be provided,
1523 // cycling through possible values.
1524 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1526 OnEdit(property
, view
, parentWindow
);
1530 void wxListOfStringsListValidator::OnEdit( wxProperty
*property
,
1531 wxPropertyListView
*view
,
1532 wxWindow
*parentWindow
)
1534 // Convert property value to a list of strings for editing
1535 wxStringList
*stringList
= new wxStringList
;
1537 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1540 wxChar
*s
= expr
->StringValue();
1543 expr
= expr
->GetNext();
1546 wxString
title(wxT("Editing "));
1547 title
+= property
->GetName();
1549 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1551 wxPropertyValue
& oldValue
= property
->GetValue();
1552 oldValue
.ClearList();
1553 wxStringList::Node
*node
= stringList
->GetFirst();
1556 wxChar
*s
= node
->GetData();
1557 oldValue
.Append(new wxPropertyValue(s
));
1559 node
= node
->GetNext();
1562 view
->DisplayProperty(property
);
1563 view
->UpdatePropertyDisplayInList(property
);
1564 view
->OnPropertyChanged(property
);
1569 class wxPropertyStringListEditorDialog
: public wxDialog
1572 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1573 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1574 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= wxT("stringEditorDialogBox")):
1575 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1577 m_stringList
= NULL
;
1578 m_stringText
= NULL
;
1580 sm_dialogCancelled
= FALSE
;
1581 m_currentSelection
= -1;
1583 ~wxPropertyStringListEditorDialog(void) {}
1584 void OnCloseWindow(wxCloseEvent
& event
);
1585 void SaveCurrentSelection(void);
1586 void ShowCurrentSelection(void);
1588 void OnOK(wxCommandEvent
& event
);
1589 void OnCancel(wxCommandEvent
& event
);
1590 void OnAdd(wxCommandEvent
& event
);
1591 void OnDelete(wxCommandEvent
& event
);
1592 void OnStrings(wxCommandEvent
& event
);
1593 void OnText(wxCommandEvent
& event
);
1596 wxStringList
* m_stringList
;
1597 wxListBox
* m_listBox
;
1598 wxTextCtrl
* m_stringText
;
1599 static bool sm_dialogCancelled
;
1600 int m_currentSelection
;
1601 DECLARE_EVENT_TABLE()
1604 #define wxID_PROP_SL_ADD 3000
1605 #define wxID_PROP_SL_DELETE 3001
1606 #define wxID_PROP_SL_STRINGS 3002
1607 #define wxID_PROP_SL_TEXT 3003
1609 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1610 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1611 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1612 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1613 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1614 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1615 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1616 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1619 class wxPropertyStringListEditorText
: public wxTextCtrl
1622 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1623 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1624 long windowStyle
= 0, const wxString
& name
= wxT("text")):
1625 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1630 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1631 dialog
->SaveCurrentSelection();
1635 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1637 // Edit the string list.
1638 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1640 int largeButtonWidth
= 60;
1641 int largeButtonHeight
= 25;
1643 wxBeginBusyCursor();
1644 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1645 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1647 dialog
->m_stringList
= stringList
;
1649 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1650 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1652 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1653 wxID_PROP_SL_TEXT
, wxT(""), wxPoint(5, 240),
1654 wxSize(300, -1), wxPROCESS_ENTER
);
1655 dialog
->m_stringText
->Enable(FALSE
);
1657 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, wxT("Add"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1658 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, wxT("Delete"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1659 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, wxT("Cancel"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1660 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, wxT("OK"), wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1663 okButton
->SetDefault();
1666 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1668 c
->top
.SameAs (dialog
, wxTop
, 2);
1669 c
->left
.SameAs (dialog
, wxLeft
, 2);
1670 c
->right
.SameAs (dialog
, wxRight
, 2);
1671 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1672 dialog
->m_listBox
->SetConstraints(c
);
1674 c
= new wxLayoutConstraints
;
1675 c
->left
.SameAs (dialog
, wxLeft
, 2);
1676 c
->right
.SameAs (dialog
, wxRight
, 2);
1677 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1679 dialog
->m_stringText
->SetConstraints(c
);
1681 c
= new wxLayoutConstraints
;
1682 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1683 c
->left
.SameAs (dialog
, wxLeft
, 2);
1686 addButton
->SetConstraints(c
);
1688 c
= new wxLayoutConstraints
;
1689 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1690 c
->left
.SameAs (addButton
, wxRight
, 2);
1693 deleteButton
->SetConstraints(c
);
1695 c
= new wxLayoutConstraints
;
1696 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1697 c
->right
.SameAs (dialog
, wxRight
, 2);
1700 cancelButton
->SetConstraints(c
);
1702 c
= new wxLayoutConstraints
;
1703 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1704 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1707 okButton
->SetConstraints(c
);
1709 wxStringList::Node
*node
= stringList
->GetFirst();
1712 wxChar
*str
= node
->GetData();
1713 // Save node as client data for each listbox item
1714 dialog
->m_listBox
->Append(str
, (wxChar
*)node
);
1715 node
= node
->GetNext();
1718 dialog
->SetClientSize(310, 305);
1721 dialog
->Centre(wxBOTH
);
1723 if (dialog
->ShowModal() == wxID_CANCEL
)
1730 * String list editor callbacks
1734 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1736 int sel
= m_listBox
->GetSelection();
1739 m_currentSelection
= sel
;
1741 ShowCurrentSelection();
1745 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1747 int sel
= m_listBox
->GetSelection();
1751 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1755 m_listBox
->Delete(sel
);
1756 delete[] (wxChar
*)node
->GetData();
1758 m_currentSelection
= -1;
1759 m_stringText
->SetValue(_T(""));
1762 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1764 SaveCurrentSelection();
1766 wxString initialText
;
1767 wxNode
*node
= m_stringList
->Add(initialText
);
1768 m_listBox
->Append(initialText
, (void *)node
);
1769 m_currentSelection
= m_stringList
->GetCount() - 1;
1770 m_listBox
->SetSelection(m_currentSelection
);
1771 ShowCurrentSelection();
1772 m_stringText
->SetFocus();
1775 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1777 SaveCurrentSelection();
1783 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1785 sm_dialogCancelled
= TRUE
;
1786 EndModal(wxID_CANCEL
);
1791 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1793 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1795 SaveCurrentSelection();
1800 wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
1802 SaveCurrentSelection();
1807 void wxPropertyStringListEditorDialog::SaveCurrentSelection()
1809 if (m_currentSelection
== -1)
1812 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1816 wxString
txt(m_stringText
->GetValue());
1817 if (node
->GetData())
1818 delete[] (wxChar
*)node
->GetData();
1819 node
->SetData((wxObject
*)wxStrdup(txt
));
1821 m_listBox
->SetString(m_currentSelection
, (wxChar
*)node
->GetData());
1824 void wxPropertyStringListEditorDialog::ShowCurrentSelection()
1826 if (m_currentSelection
== -1)
1828 m_stringText
->SetValue(wxT(""));
1831 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1832 wxChar
*txt
= (wxChar
*)node
->GetData();
1833 m_stringText
->SetValue(txt
);
1834 m_stringText
->Enable(TRUE
);
1838 #endif // wxUSE_PROPSHEET