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"
34 #include "wx/window.h"
36 #include "wx/button.h"
37 #include "wx/bmpbuttn.h"
38 #include "wx/textctrl.h"
39 #include "wx/listbox.h"
40 #include "wx/settings.h"
41 #include "wx/msgdlg.h"
42 #include "wx/filedlg.h"
46 #include "wx/module.h"
49 #include "wx/colordlg.h"
50 #include "wx/proplist.h"
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // XPM hack: make the arrays const
62 #define static static const
65 #include "wx/generic/cross.xpm"
66 #include "wx/generic/tick.xpm"
71 // ----------------------------------------------------------------------------
72 // accessor functions for the bitmaps (may return NULL, check for it!)
73 // ----------------------------------------------------------------------------
75 static wxBitmap
*GetTickBitmap();
76 static wxBitmap
*GetCrossBitmap();
78 // ----------------------------------------------------------------------------
79 // Property text edit control
80 // ----------------------------------------------------------------------------
82 IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
84 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
85 const wxWindowID id
, const wxString
& value
,
86 const wxPoint
& pos
, const wxSize
& size
,
87 long style
, const wxString
& name
):
88 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
93 void wxPropertyTextEdit::OnSetFocus()
97 void wxPropertyTextEdit::OnKillFocus()
101 // ----------------------------------------------------------------------------
102 // Property list view
103 // ----------------------------------------------------------------------------
105 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
107 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
109 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
110 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
111 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
112 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
113 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
114 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
115 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
116 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
117 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
118 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
119 wxPropertyListView::OnPropertyDoubleClick
)
120 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
123 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
125 m_propertyScrollingList
= NULL
;
129 m_confirmButton
= NULL
;
130 m_cancelButton
= NULL
;
131 m_propertyWindow
= propPanel
;
132 m_managedWindow
= NULL
;
134 m_windowCloseButton
= NULL
;
135 m_windowCancelButton
= NULL
;
136 m_windowHelpButton
= NULL
;
138 m_detailedEditing
= FALSE
;
141 wxPropertyListView::~wxPropertyListView()
145 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
147 m_propertySheet
= ps
;
149 AssociatePanel(panel
);
152 UpdatePropertyList();
156 // Update this view of the viewed object, called e.g. by
157 // the object itself.
158 bool wxPropertyListView::OnUpdateView()
163 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
165 if (!m_propertyScrollingList
|| !m_propertySheet
)
168 m_propertyScrollingList
->Clear();
171 m_valueList
->Clear();
172 m_valueText
->SetValue(_T(""));
174 wxNode
*node
= m_propertySheet
->GetProperties().First();
176 // Should sort them... later...
179 wxProperty
*property
= (wxProperty
*)node
->Data();
180 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
181 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
182 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
188 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
190 if (!m_propertyScrollingList
|| !m_propertySheet
)
194 int currentlySelected
= m_propertyScrollingList
->GetSelection();
197 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
198 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
199 int sel
= FindListIndexForProperty(property
);
203 // Don't update the listbox unnecessarily because it can cause
206 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
207 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
210 // UpdatePropertyList(FALSE);
213 // TODO: why is this necessary?
215 if (currentlySelected
> -1)
216 m_propertyScrollingList
->SetSelection(currentlySelected
);
222 // Find the wxListBox index corresponding to this property
223 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
225 int n
= m_propertyScrollingList
->GetCount();
226 for (int i
= 0; i
< n
; i
++)
228 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
234 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
236 wxString
theString(name
);
239 int padWith
= nameWidth
- theString
.Length();
243 if (GetFlags() & wxPROP_SHOWVALUES
)
245 // Want to pad with spaces
246 theString
.Append(' ', padWith
);
253 // Select and show string representation in validator the given
254 // property. NULL resets to show no property.
255 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
257 if (m_currentProperty
)
259 EndShowingProperty(m_currentProperty
);
260 m_currentProperty
= NULL
;
263 m_valueList
->Clear();
264 m_valueText
->SetValue(_T(""));
268 m_currentProperty
= property
;
269 BeginShowingProperty(property
);
273 int sel
= FindListIndexForProperty(property
);
275 m_propertyScrollingList
->SetSelection(sel
);
280 // Find appropriate validator and load property into value controls
281 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
283 m_currentValidator
= FindPropertyValidator(property
);
284 if (!m_currentValidator
)
287 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
290 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
292 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
293 DisplayProperty(property
);
297 // Find appropriate validator and unload property from value controls
298 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
300 if (!m_currentValidator
)
303 RetrieveProperty(property
);
305 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
308 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
310 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
311 if (m_detailedEditing
)
313 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
314 m_detailedEditing
= FALSE
;
319 void wxPropertyListView::BeginDetailedEditing()
321 if (!m_currentValidator
)
323 if (!m_currentProperty
)
325 if (m_detailedEditing
)
327 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
329 if (!m_currentProperty
->IsEnabled())
332 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
334 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
335 m_detailedEditing
= TRUE
;
338 void wxPropertyListView::EndDetailedEditing()
340 if (!m_currentValidator
)
342 if (!m_currentProperty
)
345 RetrieveProperty(m_currentProperty
);
347 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
350 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
352 if (m_detailedEditing
)
354 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
355 m_detailedEditing
= FALSE
;
359 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
361 if (!m_currentValidator
)
364 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
365 m_valueText
->SetEditable(FALSE
);
367 m_valueText
->SetEditable(TRUE
);
369 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
372 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
374 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
378 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
380 if (!m_currentValidator
)
382 if (!property
->IsEnabled())
385 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
388 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
390 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
392 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
394 UpdatePropertyDisplayInList(property
);
395 OnPropertyChanged(property
);
400 // Revert to old value
401 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
407 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
412 // Called by the listbox callback
413 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
415 int sel
= m_propertyScrollingList
->GetSelection();
418 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
419 if (newSel
&& newSel
!= m_currentProperty
)
421 ShowProperty(newSel
, FALSE
);
426 bool wxPropertyListView::CreateControls()
428 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
430 wxSize
largeButtonSize( 70, 25 );
431 wxSize
smallButtonSize( 23, 23 );
439 wxSystemSettings settings
;
440 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
444 wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
,
445 wxNORMAL
, wxNORMAL
, FALSE
, _T("Courier New"));
447 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
450 // May need to be changed in future to eliminate clashes with app.
451 // WHAT WAS THIS FOR?
452 // panel->SetClientData((char *)this);
454 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
456 // top row with optional buttons and input line
458 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
459 int buttonborder
= 3;
461 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
463 wxBitmap
*tickBitmap
= GetTickBitmap();
464 wxBitmap
*crossBitmap
= GetCrossBitmap();
466 if ( tickBitmap
&& crossBitmap
)
468 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, *tickBitmap
, wxPoint(-1, -1), smallButtonSize
);
469 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, *crossBitmap
, wxPoint(-1, -1), smallButtonSize
);
473 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, _T(":-)"), wxPoint(-1, -1), smallButtonSize
);
474 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, _T("X"), wxPoint(-1, -1), smallButtonSize
);
477 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
478 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
481 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, _T(""),
482 wxPoint(-1, -1), wxSize(-1, smallButtonSize
.y
), wxPROCESS_ENTER
);
483 m_valueText
->Enable(FALSE
);
484 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
486 if (m_buttonFlags
& wxPROP_PULLDOWN
)
488 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, _T("..."), wxPoint(-1, -1), smallButtonSize
);
489 m_editButton
->Enable(FALSE
);
490 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
493 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
495 // middle section with two list boxes
497 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
499 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
500 m_valueList
->Show(FALSE
);
502 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxPoint(-1, -1), wxSize(100, 100));
503 m_propertyScrollingList
->SetFont(* boringFont
);
504 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
506 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
508 // bottom row with buttons
510 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
511 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
512 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
513 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
515 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
518 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
520 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxPoint(-1, -1), largeButtonSize
);
521 m_windowCloseButton
->SetDefault();
522 m_windowCloseButton
->SetFocus();
523 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
525 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
527 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxPoint(-1, -1), largeButtonSize
);
528 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
530 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
532 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxPoint(-1, -1), largeButtonSize
);
533 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
535 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
537 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxPoint(-1, -1), largeButtonSize
);
538 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
541 mainsizer
->Add( bottomsizer
, 0, wxALIGN_RIGHT
| wxEXPAND
);
544 panel
->SetSizer( mainsizer
);
549 void wxPropertyListView::ShowTextControl(bool show
)
552 m_valueText
->Show(show
);
555 void wxPropertyListView::ShowListBoxControl(bool show
)
557 if (!m_valueList
) return;
559 m_valueList
->Show(show
);
561 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
564 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
566 m_middleSizer
->Remove( 0 );
568 m_propertyWindow
->Layout();
572 void wxPropertyListView::EnableCheck(bool show
)
575 m_confirmButton
->Enable(show
);
578 void wxPropertyListView::EnableCross(bool show
)
581 m_cancelButton
->Enable(show
);
584 bool wxPropertyListView::OnClose()
586 // Retrieve the value if any
587 wxCommandEvent event
;
594 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
596 if (m_currentProperty
&& m_currentValidator
)
598 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
601 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
603 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
607 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
609 // Retrieve the value if any
612 m_managedWindow
->Close(TRUE
);
615 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
617 // SetReturnCode(wxID_CANCEL);
618 m_managedWindow
->Close(TRUE
);
619 sm_dialogCancelled
= TRUE
;
622 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
626 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
628 if (m_currentProperty
)
630 RetrieveProperty(m_currentProperty
);
634 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
636 if (m_currentProperty
&& m_currentValidator
)
638 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
641 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
643 // Revert to old value
644 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
648 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
650 if (m_currentProperty
&& m_currentValidator
)
652 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
655 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
657 // Revert to old value
658 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
662 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
664 if (m_currentProperty
&& m_currentValidator
)
666 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
669 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
671 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
675 void wxPropertyListView::OnText(wxCommandEvent
& event
)
677 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
683 // ----------------------------------------------------------------------------
684 // Property dialog box
685 // ----------------------------------------------------------------------------
687 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog
, wxDialog
)
689 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
690 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
691 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
694 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
695 const wxString
& title
, const wxPoint
& pos
,
696 const wxSize
& size
, long style
, const wxString
& name
):
697 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
700 m_view
->AssociatePanel( ((wxPanel
*)this) );
701 m_view
->SetManagedWindow(this);
705 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
709 SetReturnCode(wxID_CANCEL
);
720 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
722 SetReturnCode(wxID_CANCEL
);
726 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
729 if (item == m_view->GetPropertyScrollingList())
730 view->OnDoubleClick();
734 // Extend event processing to search the view's event table
735 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
737 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
738 return wxEvtHandler::ProcessEvent(event
);
743 // ----------------------------------------------------------------------------
745 // ----------------------------------------------------------------------------
747 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel
, wxPanel
)
749 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
750 EVT_SIZE(wxPropertyListPanel::OnSize
)
753 wxPropertyListPanel::~wxPropertyListPanel()
757 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
760 if (item == view->GetPropertyScrollingList())
761 view->OnDoubleClick();
765 // Extend event processing to search the view's event table
766 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
768 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
769 return wxEvtHandler::ProcessEvent(event
);
774 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
779 // ----------------------------------------------------------------------------
781 // ----------------------------------------------------------------------------
783 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame
, wxFrame
)
785 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
786 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
789 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
794 m_propertyPanel
->SetView(NULL
);
805 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
807 return new wxPropertyListPanel(v
, parent
);
810 bool wxPropertyListFrame::Initialize()
812 m_propertyPanel
= OnCreatePanel(this, m_view
);
815 m_view
->AssociatePanel(m_propertyPanel
);
816 m_view
->SetManagedWindow(this);
817 m_propertyPanel
->SetAutoLayout(TRUE
);
824 // ----------------------------------------------------------------------------
825 // Property list specific validator
826 // ----------------------------------------------------------------------------
828 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
830 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
832 // view->GetValueText()->Show(TRUE);
834 OnDisplayValue(property
, view
, parentWindow
);
839 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
841 wxString
s(view
->GetValueList()->GetStringSelection());
844 view
->GetValueText()->SetValue(s
);
845 view
->RetrieveProperty(property
);
850 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
852 // view->GetValueText()->Show(TRUE);
853 wxString
str(property
->GetValue().GetStringRepresentation());
855 view
->GetValueText()->SetValue(str
);
859 // Called when TICK is pressed or focus is lost or view wants to update
860 // the property list.
861 // Does the transferance from the property editing area to the property itself
862 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
864 if (!view
->GetValueText())
869 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
871 if (view
->GetDetailedEditing())
872 view
->EndDetailedEditing();
874 view
->BeginDetailedEditing();
877 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
879 if (view
->GetConfirmButton())
880 view
->GetConfirmButton()->Enable(FALSE
);
881 if (view
->GetCancelButton())
882 view
->GetCancelButton()->Enable(FALSE
);
883 if (view
->GetEditButton())
884 view
->GetEditButton()->Enable(FALSE
);
888 // ----------------------------------------------------------------------------
889 // Default validators
890 // ----------------------------------------------------------------------------
892 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
895 /// Real number validator
897 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
899 if (m_realMin
== 0.0 && m_realMax
== 0.0)
902 if (!view
->GetValueText())
904 wxString
value(view
->GetValueText()->GetValue());
907 if (!StringToFloat(WXSTRINGCAST value
, &val
))
910 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), value
.GetData());
911 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
915 if (val
< m_realMin
|| val
> m_realMax
)
918 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
919 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
925 // Called when TICK is pressed or focus is lost or view wants to update
926 // the property list.
927 // Does the transferance from the property editing area to the property itself
928 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
930 if (!view
->GetValueText())
933 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
936 wxString
value(view
->GetValueText()->GetValue());
937 float f
= (float)wxAtof(value
.GetData());
938 property
->GetValue() = f
;
942 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
944 if (view
->GetConfirmButton())
945 view
->GetConfirmButton()->Enable(TRUE
);
946 if (view
->GetCancelButton())
947 view
->GetCancelButton()->Enable(TRUE
);
948 if (view
->GetEditButton())
949 view
->GetEditButton()->Enable(FALSE
);
950 if (view
->GetValueText())
951 view
->GetValueText()->Enable(TRUE
);
956 /// Integer validator
958 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
960 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
962 if (m_integerMin
== 0 && m_integerMax
== 0)
965 if (!view
->GetValueText())
967 wxString
value(view
->GetValueText()->GetValue());
970 if (!StringToLong(WXSTRINGCAST value
, &val
))
973 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), value
.GetData());
974 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
977 if (val
< m_integerMin
|| val
> m_integerMax
)
980 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
981 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
987 // Called when TICK is pressed or focus is lost or view wants to update
988 // the property list.
989 // Does the transferance from the property editing area to the property itself
990 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
992 if (!view
->GetValueText())
995 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
998 wxString
value(view
->GetValueText()->GetValue());
999 long val
= (long)wxAtoi(value
.GetData());
1000 property
->GetValue() = (long)val
;
1004 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1006 if (view
->GetConfirmButton())
1007 view
->GetConfirmButton()->Enable(TRUE
);
1008 if (view
->GetCancelButton())
1009 view
->GetCancelButton()->Enable(TRUE
);
1010 if (view
->GetEditButton())
1011 view
->GetEditButton()->Enable(FALSE
);
1012 if (view
->GetValueText())
1013 view
->GetValueText()->Enable(TRUE
);
1018 /// boolean validator
1020 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1022 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1024 if (!view
->GetValueText())
1026 wxString
value(view
->GetValueText()->GetValue());
1027 if (value
!= wxT("True") && value
!= wxT("False"))
1029 wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1035 // Called when TICK is pressed or focus is lost or view wants to update
1036 // the property list.
1037 // Does the transferance from the property editing area to the property itself
1038 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1040 if (!view
->GetValueText())
1043 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1046 wxString
value(view
->GetValueText()->GetValue());
1047 bool boolValue
= FALSE
;
1048 if (value
== wxT("True"))
1052 property
->GetValue() = (bool)boolValue
;
1056 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1058 if (!view
->GetValueText())
1060 wxString
str(property
->GetValue().GetStringRepresentation());
1062 view
->GetValueText()->SetValue(str
);
1064 if (view
->GetValueList()->IsShown())
1066 view
->GetValueList()->SetStringSelection(str
);
1071 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1073 if (view
->GetConfirmButton())
1074 view
->GetConfirmButton()->Enable(FALSE
);
1075 if (view
->GetCancelButton())
1076 view
->GetCancelButton()->Enable(FALSE
);
1077 if (view
->GetEditButton())
1078 view
->GetEditButton()->Enable(TRUE
);
1079 if (view
->GetValueText())
1080 view
->GetValueText()->Enable(FALSE
);
1084 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1086 if (view
->GetValueList())
1088 view
->ShowListBoxControl(TRUE
);
1089 view
->GetValueList()->Enable(TRUE
);
1091 view
->GetValueList()->Append(wxT("True"));
1092 view
->GetValueList()->Append(wxT("False"));
1093 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1094 view
->GetValueList()->SetStringSelection(currentString
);
1095 delete[] currentString
;
1100 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1102 if (view
->GetValueList())
1104 view
->GetValueList()->Clear();
1105 view
->ShowListBoxControl(FALSE
);
1106 view
->GetValueList()->Enable(FALSE
);
1111 // Called when the property is double clicked. Extra functionality can be provided,
1112 // cycling through possible values.
1113 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1115 if (!view
->GetValueText())
1117 if (property
->GetValue().BoolValue())
1118 property
->GetValue() = (bool)FALSE
;
1120 property
->GetValue() = (bool)TRUE
;
1121 view
->DisplayProperty(property
);
1122 view
->UpdatePropertyDisplayInList(property
);
1123 view
->OnPropertyChanged(property
);
1128 /// String validator
1130 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1132 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1133 wxPropertyListValidator(flags
)
1136 // If no constraint, we just allow the string to be edited.
1137 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1138 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1141 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1146 if (!view
->GetValueText())
1148 wxString
value(view
->GetValueText()->GetValue());
1150 if (!m_strings
->Member(value
.GetData()))
1152 wxString
s("Value ");
1153 s
+= value
.GetData();
1154 s
+= " is not valid.";
1155 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1161 // Called when TICK is pressed or focus is lost or view wants to update
1162 // the property list.
1163 // Does the transferance from the property editing area to the property itself
1164 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1166 if (!view
->GetValueText())
1168 wxString
value(view
->GetValueText()->GetValue());
1169 property
->GetValue() = value
;
1173 // Called when TICK is pressed or focus is lost or view wants to update
1174 // the property list.
1175 // Does the transferance from the property editing area to the property itself
1176 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1178 if (!view
->GetValueText())
1180 wxString
str(property
->GetValue().GetStringRepresentation());
1181 view
->GetValueText()->SetValue(str
);
1182 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->GetCount() > 0)
1184 view
->GetValueList()->SetStringSelection(str
);
1189 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1194 if (view
->GetEditButton())
1195 view
->GetEditButton()->Enable(FALSE
);
1196 if (view
->GetConfirmButton())
1197 view
->GetConfirmButton()->Enable(TRUE
);
1198 if (view
->GetCancelButton())
1199 view
->GetCancelButton()->Enable(TRUE
);
1200 if (view
->GetValueText())
1201 view
->GetValueText()->Enable(TRUE
);
1206 if (view
->GetValueText())
1207 view
->GetValueText()->Enable(FALSE
);
1209 if (view
->GetEditButton())
1210 view
->GetEditButton()->Enable(TRUE
);
1212 if (view
->GetConfirmButton())
1213 view
->GetConfirmButton()->Enable(FALSE
);
1214 if (view
->GetCancelButton())
1215 view
->GetCancelButton()->Enable(FALSE
);
1219 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1221 if (view
->GetValueList())
1223 view
->ShowListBoxControl(TRUE
);
1224 view
->GetValueList()->Enable(TRUE
);
1225 wxNode
*node
= m_strings
->First();
1228 wxChar
*s
= (wxChar
*)node
->Data();
1229 view
->GetValueList()->Append(s
);
1230 node
= node
->Next();
1232 wxChar
*currentString
= property
->GetValue().StringValue();
1233 view
->GetValueList()->SetStringSelection(currentString
);
1238 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1245 if (view
->GetValueList())
1247 view
->GetValueList()->Clear();
1248 view
->ShowListBoxControl(FALSE
);
1249 view
->GetValueList()->Enable(FALSE
);
1254 // Called when the property is double clicked. Extra functionality can be provided,
1255 // cycling through possible values.
1256 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1258 if (!view
->GetValueText())
1263 wxNode
*node
= m_strings
->First();
1264 wxChar
*currentString
= property
->GetValue().StringValue();
1267 wxChar
*s
= (wxChar
*)node
->Data();
1268 if (wxStrcmp(s
, currentString
) == 0)
1270 wxChar
*nextString
= NULL
;
1272 nextString
= (wxChar
*)node
->Next()->Data();
1274 nextString
= (wxChar
*)m_strings
->First()->Data();
1275 property
->GetValue() = wxString(nextString
);
1276 view
->DisplayProperty(property
);
1277 view
->UpdatePropertyDisplayInList(property
);
1278 view
->OnPropertyChanged(property
);
1281 else node
= node
->Next();
1287 /// Filename validator
1289 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1291 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1292 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1296 wxFilenameListValidator::~wxFilenameListValidator()
1300 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1305 // Called when TICK is pressed or focus is lost or view wants to update
1306 // the property list.
1307 // Does the transferance from the property editing area to the property itself
1308 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1310 if (!view
->GetValueText())
1312 wxString
value(view
->GetValueText()->GetValue());
1313 property
->GetValue() = value
;
1317 // Called when TICK is pressed or focus is lost or view wants to update
1318 // the property list.
1319 // Does the transferance from the property editing area to the property itself
1320 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1322 if (!view
->GetValueText())
1324 wxString
str(property
->GetValue().GetStringRepresentation());
1325 view
->GetValueText()->SetValue(str
);
1329 // Called when the property is double clicked. Extra functionality can be provided,
1330 // cycling through possible values.
1331 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1333 if (!view
->GetValueText())
1335 OnEdit(property
, view
, parentWindow
);
1339 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1341 if (view
->GetConfirmButton())
1342 view
->GetConfirmButton()->Enable(TRUE
);
1343 if (view
->GetCancelButton())
1344 view
->GetCancelButton()->Enable(TRUE
);
1345 if (view
->GetEditButton())
1346 view
->GetEditButton()->Enable(TRUE
);
1347 if (view
->GetValueText())
1348 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1352 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1354 if (!view
->GetValueText())
1357 wxString s
= wxFileSelector(
1358 m_filenameMessage
.GetData(),
1359 wxPathOnly(property
->GetValue().StringValue()),
1360 wxFileNameFromPath(property
->GetValue().StringValue()),
1362 m_filenameWildCard
.GetData(),
1367 property
->GetValue() = s
;
1368 view
->DisplayProperty(property
);
1369 view
->UpdatePropertyDisplayInList(property
);
1370 view
->OnPropertyChanged(property
);
1375 /// Colour validator
1377 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1379 wxColourListValidator::wxColourListValidator(long flags
):
1380 wxPropertyListValidator(flags
)
1384 wxColourListValidator::~wxColourListValidator()
1388 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1393 // Called when TICK is pressed or focus is lost or view wants to update
1394 // the property list.
1395 // Does the transferance from the property editing area to the property itself
1396 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1398 if (!view
->GetValueText())
1400 wxString
value(view
->GetValueText()->GetValue());
1402 property
->GetValue() = value
;
1406 // Called when TICK is pressed or focus is lost or view wants to update
1407 // the property list.
1408 // Does the transferance from the property editing area to the property itself
1409 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1411 if (!view
->GetValueText())
1413 wxString
str(property
->GetValue().GetStringRepresentation());
1414 view
->GetValueText()->SetValue(str
);
1418 // Called when the property is double clicked. Extra functionality can be provided,
1419 // cycling through possible values.
1420 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1422 if (!view
->GetValueText())
1424 OnEdit(property
, view
, parentWindow
);
1428 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1430 if (view
->GetConfirmButton())
1431 view
->GetConfirmButton()->Enable(TRUE
);
1432 if (view
->GetCancelButton())
1433 view
->GetCancelButton()->Enable(TRUE
);
1434 if (view
->GetEditButton())
1435 view
->GetEditButton()->Enable(TRUE
);
1436 if (view
->GetValueText())
1437 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1441 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1443 if (!view
->GetValueText())
1446 wxChar
*s
= property
->GetValue().StringValue();
1453 g
= wxHexToDec(s
+2);
1454 b
= wxHexToDec(s
+4);
1457 wxColour
col(r
,g
,b
);
1460 data
.SetChooseFull(TRUE
);
1461 data
.SetColour(col
);
1463 for (int i
= 0; i
< 16; i
++)
1465 wxColour
colour(i
*16, i
*16, i
*16);
1466 data
.SetCustomColour(i
, colour
);
1469 wxColourDialog
dialog(parentWindow
, &data
);
1470 if (dialog
.ShowModal() != wxID_CANCEL
)
1472 wxColourData retData
= dialog
.GetColourData();
1473 col
= retData
.GetColour();
1476 wxDecToHex(col
.Red(), buf
);
1477 wxDecToHex(col
.Green(), buf
+2);
1478 wxDecToHex(col
.Blue(), buf
+4);
1480 property
->GetValue() = wxString(buf
);
1481 view
->DisplayProperty(property
);
1482 view
->UpdatePropertyDisplayInList(property
);
1483 view
->OnPropertyChanged(property
);
1488 /// List of strings validator. For this we need more user interface than
1489 /// we get with a property list; so create a new dialog for editing the list.
1491 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1493 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1494 wxPropertyListValidator(flags
)
1498 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1500 // No constraints for an arbitrary, user-editable list of strings.
1504 // Called when TICK is pressed or focus is lost or view wants to update
1505 // the property list.
1506 // Does the transferance from the property editing area to the property itself.
1507 // In this case, the user cannot directly edit the string list.
1508 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1513 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1515 if (!view
->GetValueText())
1517 wxString
str(property
->GetValue().GetStringRepresentation());
1518 view
->GetValueText()->SetValue(str
);
1522 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1524 if (view
->GetEditButton())
1525 view
->GetEditButton()->Enable(TRUE
);
1526 if (view
->GetValueText())
1527 view
->GetValueText()->Enable(FALSE
);
1529 if (view
->GetConfirmButton())
1530 view
->GetConfirmButton()->Enable(FALSE
);
1531 if (view
->GetCancelButton())
1532 view
->GetCancelButton()->Enable(FALSE
);
1536 // Called when the property is double clicked. Extra functionality can be provided,
1537 // cycling through possible values.
1538 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1540 OnEdit(property
, view
, parentWindow
);
1544 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1546 // Convert property value to a list of strings for editing
1547 wxStringList
*stringList
= new wxStringList
;
1549 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1552 wxChar
*s
= expr
->StringValue();
1555 expr
= expr
->GetNext();
1558 wxString
title(wxT("Editing "));
1559 title
+= property
->GetName();
1561 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1563 wxPropertyValue
& oldValue
= property
->GetValue();
1564 oldValue
.ClearList();
1565 wxNode
*node
= stringList
->First();
1568 wxChar
*s
= (wxChar
*)node
->Data();
1569 oldValue
.Append(new wxPropertyValue(s
));
1571 node
= node
->Next();
1574 view
->DisplayProperty(property
);
1575 view
->UpdatePropertyDisplayInList(property
);
1576 view
->OnPropertyChanged(property
);
1581 class wxPropertyStringListEditorDialog
: public wxDialog
1584 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1585 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1586 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1587 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1589 m_stringList
= NULL
;
1590 m_stringText
= NULL
;
1592 sm_dialogCancelled
= FALSE
;
1593 m_currentSelection
= -1;
1595 ~wxPropertyStringListEditorDialog(void) {}
1596 void OnCloseWindow(wxCloseEvent
& event
);
1597 void SaveCurrentSelection(void);
1598 void ShowCurrentSelection(void);
1600 void OnOK(wxCommandEvent
& event
);
1601 void OnCancel(wxCommandEvent
& event
);
1602 void OnAdd(wxCommandEvent
& event
);
1603 void OnDelete(wxCommandEvent
& event
);
1604 void OnStrings(wxCommandEvent
& event
);
1605 void OnText(wxCommandEvent
& event
);
1608 wxStringList
* m_stringList
;
1609 wxListBox
* m_listBox
;
1610 wxTextCtrl
* m_stringText
;
1611 static bool sm_dialogCancelled
;
1612 int m_currentSelection
;
1613 DECLARE_EVENT_TABLE()
1616 #define wxID_PROP_SL_ADD 3000
1617 #define wxID_PROP_SL_DELETE 3001
1618 #define wxID_PROP_SL_STRINGS 3002
1619 #define wxID_PROP_SL_TEXT 3003
1621 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1622 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1623 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1624 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1625 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1626 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1627 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1628 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1631 class wxPropertyStringListEditorText
: public wxTextCtrl
1634 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1635 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1636 long windowStyle
= 0, const wxString
& name
= "text"):
1637 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1642 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1643 dialog
->SaveCurrentSelection();
1647 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1649 // Edit the string list.
1650 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1652 int largeButtonWidth
= 60;
1653 int largeButtonHeight
= 25;
1655 wxBeginBusyCursor();
1656 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1657 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1659 dialog
->m_stringList
= stringList
;
1661 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1662 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1664 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1665 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1666 wxSize(300, -1), wxPROCESS_ENTER
);
1667 dialog
->m_stringText
->Enable(FALSE
);
1669 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1670 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1671 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1672 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1675 okButton
->SetDefault();
1678 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1680 c
->top
.SameAs (dialog
, wxTop
, 2);
1681 c
->left
.SameAs (dialog
, wxLeft
, 2);
1682 c
->right
.SameAs (dialog
, wxRight
, 2);
1683 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1684 dialog
->m_listBox
->SetConstraints(c
);
1686 c
= new wxLayoutConstraints
;
1687 c
->left
.SameAs (dialog
, wxLeft
, 2);
1688 c
->right
.SameAs (dialog
, wxRight
, 2);
1689 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1691 dialog
->m_stringText
->SetConstraints(c
);
1693 c
= new wxLayoutConstraints
;
1694 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1695 c
->left
.SameAs (dialog
, wxLeft
, 2);
1698 addButton
->SetConstraints(c
);
1700 c
= new wxLayoutConstraints
;
1701 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1702 c
->left
.SameAs (addButton
, wxRight
, 2);
1705 deleteButton
->SetConstraints(c
);
1707 c
= new wxLayoutConstraints
;
1708 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1709 c
->right
.SameAs (dialog
, wxRight
, 2);
1712 cancelButton
->SetConstraints(c
);
1714 c
= new wxLayoutConstraints
;
1715 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1716 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1719 okButton
->SetConstraints(c
);
1721 wxNode
*node
= stringList
->First();
1724 char *str
= (char *)node
->Data();
1725 // Save node as client data for each listbox item
1726 dialog
->m_listBox
->Append(str
, (char *)node
);
1727 node
= node
->Next();
1730 dialog
->SetClientSize(310, 305);
1733 dialog
->Centre(wxBOTH
);
1735 if (dialog
->ShowModal() == wxID_CANCEL
)
1742 * String list editor callbacks
1746 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1748 int sel
= m_listBox
->GetSelection();
1751 m_currentSelection
= sel
;
1753 ShowCurrentSelection();
1757 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1759 int sel
= m_listBox
->GetSelection();
1763 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1767 m_listBox
->Delete(sel
);
1768 delete[] (wxChar
*)node
->Data();
1770 m_currentSelection
= -1;
1771 m_stringText
->SetValue(_T(""));
1774 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1776 SaveCurrentSelection();
1778 wxString initialText
;
1779 wxNode
*node
= m_stringList
->Add(initialText
);
1780 m_listBox
->Append(initialText
, (void *)node
);
1781 m_currentSelection
= m_stringList
->Number() - 1;
1782 m_listBox
->SetSelection(m_currentSelection
);
1783 ShowCurrentSelection();
1784 m_stringText
->SetFocus();
1787 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1789 SaveCurrentSelection();
1795 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1797 sm_dialogCancelled
= TRUE
;
1798 EndModal(wxID_CANCEL
);
1803 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1805 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1807 SaveCurrentSelection();
1812 wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
1814 SaveCurrentSelection();
1819 void wxPropertyStringListEditorDialog::SaveCurrentSelection()
1821 if (m_currentSelection
== -1)
1824 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1828 wxString
txt(m_stringText
->GetValue());
1830 delete[] (char *)node
->Data();
1831 node
->SetData((wxObject
*)copystring(txt
));
1833 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1836 void wxPropertyStringListEditorDialog::ShowCurrentSelection()
1838 if (m_currentSelection
== -1)
1840 m_stringText
->SetValue(_T(""));
1843 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1844 char *txt
= (char *)node
->Data();
1845 m_stringText
->SetValue(txt
);
1846 m_stringText
->Enable(TRUE
);
1849 // ----------------------------------------------------------------------------
1851 // ----------------------------------------------------------------------------
1854 static wxBitmap
*GetTickBitmap()
1856 static wxBitmap
* s_tickBitmap
= (wxBitmap
*) NULL
;
1857 static bool s_loaded
= FALSE
;
1861 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1863 #if defined(__WXMSW__) || defined(__WXPM__)
1864 s_tickBitmap
= new wxBitmap(_T("tick_bmp"), wxBITMAP_TYPE_RESOURCE
);
1866 s_tickBitmap
= new wxBitmap( tick_xpm
);
1870 return s_tickBitmap
;
1873 static wxBitmap
*GetCrossBitmap()
1875 static wxBitmap
* s_crossBitmap
= (wxBitmap
*) NULL
;
1876 static bool s_loaded
= FALSE
;
1880 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1882 #if defined(__WXMSW__) || defined(__WXPM__)
1883 s_crossBitmap
= new wxBitmap(_T("cross_bmp"), wxBITMAP_TYPE_RESOURCE
);
1885 s_crossBitmap
= new wxBitmap( cross_xpm
);
1889 return s_crossBitmap
;
1892 #endif // wxUSE_PROPSHEET