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("");
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("");
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
);
443 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
445 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
448 // May need to be changed in future to eliminate clashes with app.
449 // WHAT WAS THIS FOR?
450 // panel->SetClientData((char *)this);
452 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
454 // top row with optional buttons and input line
456 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
457 int buttonborder
= 3;
459 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
461 wxBitmap
*tickBitmap
= GetTickBitmap();
462 wxBitmap
*crossBitmap
= GetCrossBitmap();
464 if ( tickBitmap
&& crossBitmap
)
466 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, *tickBitmap
, wxPoint(-1, -1), smallButtonSize
);
467 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, *crossBitmap
, wxPoint(-1, -1), smallButtonSize
);
471 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)", wxPoint(-1, -1), smallButtonSize
);
472 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X", wxPoint(-1, -1), smallButtonSize
);
475 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
476 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
479 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "",
480 wxPoint(-1, -1), wxSize(-1, smallButtonSize
.y
), wxPROCESS_ENTER
);
481 m_valueText
->Enable(FALSE
);
482 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
484 if (m_buttonFlags
& wxPROP_PULLDOWN
)
486 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...", wxPoint(-1, -1), smallButtonSize
);
487 m_editButton
->Enable(FALSE
);
488 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
491 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
493 // middle section with two list boxes
495 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
497 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
498 m_valueList
->Show(FALSE
);
500 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxPoint(-1, -1), wxSize(100, 100));
501 m_propertyScrollingList
->SetFont(* boringFont
);
502 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
504 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
506 // bottom row with buttons
508 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
509 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
510 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
511 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
513 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
516 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
518 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxPoint(-1, -1), largeButtonSize
);
519 m_windowCloseButton
->SetDefault();
520 m_windowCloseButton
->SetFocus();
521 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
523 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
525 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxPoint(-1, -1), largeButtonSize
);
526 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
528 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
530 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxPoint(-1, -1), largeButtonSize
);
531 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
533 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
535 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxPoint(-1, -1), largeButtonSize
);
536 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
539 mainsizer
->Add( bottomsizer
, 0, wxALIGN_RIGHT
| wxEXPAND
);
542 panel
->SetSizer( mainsizer
);
547 void wxPropertyListView::ShowTextControl(bool show
)
550 m_valueText
->Show(show
);
553 void wxPropertyListView::ShowListBoxControl(bool show
)
555 if (!m_valueList
) return;
557 m_valueList
->Show(show
);
559 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
562 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
564 m_middleSizer
->Remove( 0 );
566 m_propertyWindow
->Layout();
570 void wxPropertyListView::EnableCheck(bool show
)
573 m_confirmButton
->Enable(show
);
576 void wxPropertyListView::EnableCross(bool show
)
579 m_cancelButton
->Enable(show
);
582 bool wxPropertyListView::OnClose()
584 // Retrieve the value if any
585 wxCommandEvent event
;
592 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
594 if (m_currentProperty
&& m_currentValidator
)
596 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
599 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
601 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
605 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
607 // Retrieve the value if any
610 m_managedWindow
->Close(TRUE
);
613 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
615 // SetReturnCode(wxID_CANCEL);
616 m_managedWindow
->Close(TRUE
);
617 sm_dialogCancelled
= TRUE
;
620 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
624 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
626 if (m_currentProperty
)
628 RetrieveProperty(m_currentProperty
);
632 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
634 if (m_currentProperty
&& m_currentValidator
)
636 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
639 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
641 // Revert to old value
642 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
646 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
648 if (m_currentProperty
&& m_currentValidator
)
650 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
653 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
655 // Revert to old value
656 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
660 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
662 if (m_currentProperty
&& m_currentValidator
)
664 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
667 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
669 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
673 void wxPropertyListView::OnText(wxCommandEvent
& event
)
675 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
681 // ----------------------------------------------------------------------------
682 // Property dialog box
683 // ----------------------------------------------------------------------------
685 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog
, wxDialog
)
687 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
688 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
689 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
692 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
693 const wxString
& title
, const wxPoint
& pos
,
694 const wxSize
& size
, long style
, const wxString
& name
):
695 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
698 m_view
->AssociatePanel( ((wxPanel
*)this) );
699 m_view
->SetManagedWindow(this);
703 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
707 SetReturnCode(wxID_CANCEL
);
718 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
720 SetReturnCode(wxID_CANCEL
);
724 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
727 if (item == m_view->GetPropertyScrollingList())
728 view->OnDoubleClick();
732 // Extend event processing to search the view's event table
733 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
735 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
736 return wxEvtHandler::ProcessEvent(event
);
741 // ----------------------------------------------------------------------------
743 // ----------------------------------------------------------------------------
745 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel
, wxPanel
)
747 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
748 EVT_SIZE(wxPropertyListPanel::OnSize
)
751 wxPropertyListPanel::~wxPropertyListPanel()
755 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
758 if (item == view->GetPropertyScrollingList())
759 view->OnDoubleClick();
763 // Extend event processing to search the view's event table
764 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
766 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
767 return wxEvtHandler::ProcessEvent(event
);
772 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
777 // ----------------------------------------------------------------------------
779 // ----------------------------------------------------------------------------
781 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame
, wxFrame
)
783 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
784 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
787 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
792 m_propertyPanel
->SetView(NULL
);
803 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
805 return new wxPropertyListPanel(v
, parent
);
808 bool wxPropertyListFrame::Initialize()
810 m_propertyPanel
= OnCreatePanel(this, m_view
);
813 m_view
->AssociatePanel(m_propertyPanel
);
814 m_view
->SetManagedWindow(this);
815 m_propertyPanel
->SetAutoLayout(TRUE
);
822 // ----------------------------------------------------------------------------
823 // Property list specific validator
824 // ----------------------------------------------------------------------------
826 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
828 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
830 // view->GetValueText()->Show(TRUE);
832 OnDisplayValue(property
, view
, parentWindow
);
837 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
839 wxString
s(view
->GetValueList()->GetStringSelection());
842 view
->GetValueText()->SetValue(s
);
843 view
->RetrieveProperty(property
);
848 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
850 // view->GetValueText()->Show(TRUE);
851 wxString
str(property
->GetValue().GetStringRepresentation());
853 view
->GetValueText()->SetValue(str
);
857 // Called when TICK is pressed or focus is lost or view wants to update
858 // the property list.
859 // Does the transferance from the property editing area to the property itself
860 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
862 if (!view
->GetValueText())
867 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
869 if (view
->GetDetailedEditing())
870 view
->EndDetailedEditing();
872 view
->BeginDetailedEditing();
875 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
877 if (view
->GetConfirmButton())
878 view
->GetConfirmButton()->Enable(FALSE
);
879 if (view
->GetCancelButton())
880 view
->GetCancelButton()->Enable(FALSE
);
881 if (view
->GetEditButton())
882 view
->GetEditButton()->Enable(FALSE
);
886 // ----------------------------------------------------------------------------
887 // Default validators
888 // ----------------------------------------------------------------------------
890 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
893 /// Real number validator
895 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
897 if (m_realMin
== 0.0 && m_realMax
== 0.0)
900 if (!view
->GetValueText())
902 wxString
value(view
->GetValueText()->GetValue());
905 if (!StringToFloat(WXSTRINGCAST value
, &val
))
908 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), value
.GetData());
909 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
913 if (val
< m_realMin
|| val
> m_realMax
)
916 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
917 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
923 // Called when TICK is pressed or focus is lost or view wants to update
924 // the property list.
925 // Does the transferance from the property editing area to the property itself
926 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
928 if (!view
->GetValueText())
931 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
934 wxString
value(view
->GetValueText()->GetValue());
935 float f
= (float)wxAtof(value
.GetData());
936 property
->GetValue() = f
;
940 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
942 if (view
->GetConfirmButton())
943 view
->GetConfirmButton()->Enable(TRUE
);
944 if (view
->GetCancelButton())
945 view
->GetCancelButton()->Enable(TRUE
);
946 if (view
->GetEditButton())
947 view
->GetEditButton()->Enable(FALSE
);
948 if (view
->GetValueText())
949 view
->GetValueText()->Enable(TRUE
);
954 /// Integer validator
956 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
958 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
960 if (m_integerMin
== 0 && m_integerMax
== 0)
963 if (!view
->GetValueText())
965 wxString
value(view
->GetValueText()->GetValue());
968 if (!StringToLong(WXSTRINGCAST value
, &val
))
971 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), value
.GetData());
972 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
975 if (val
< m_integerMin
|| val
> m_integerMax
)
978 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
979 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
985 // Called when TICK is pressed or focus is lost or view wants to update
986 // the property list.
987 // Does the transferance from the property editing area to the property itself
988 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
990 if (!view
->GetValueText())
993 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
996 wxString
value(view
->GetValueText()->GetValue());
997 long val
= (long)wxAtoi(value
.GetData());
998 property
->GetValue() = (long)val
;
1002 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1004 if (view
->GetConfirmButton())
1005 view
->GetConfirmButton()->Enable(TRUE
);
1006 if (view
->GetCancelButton())
1007 view
->GetCancelButton()->Enable(TRUE
);
1008 if (view
->GetEditButton())
1009 view
->GetEditButton()->Enable(FALSE
);
1010 if (view
->GetValueText())
1011 view
->GetValueText()->Enable(TRUE
);
1016 /// boolean validator
1018 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1020 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1022 if (!view
->GetValueText())
1024 wxString
value(view
->GetValueText()->GetValue());
1025 if (value
!= wxT("True") && value
!= wxT("False"))
1027 wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1033 // Called when TICK is pressed or focus is lost or view wants to update
1034 // the property list.
1035 // Does the transferance from the property editing area to the property itself
1036 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1038 if (!view
->GetValueText())
1041 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1044 wxString
value(view
->GetValueText()->GetValue());
1045 bool boolValue
= FALSE
;
1046 if (value
== wxT("True"))
1050 property
->GetValue() = (bool)boolValue
;
1054 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1056 if (!view
->GetValueText())
1058 wxString
str(property
->GetValue().GetStringRepresentation());
1060 view
->GetValueText()->SetValue(str
);
1062 if (view
->GetValueList()->IsShown())
1064 view
->GetValueList()->SetStringSelection(str
);
1069 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1071 if (view
->GetConfirmButton())
1072 view
->GetConfirmButton()->Enable(FALSE
);
1073 if (view
->GetCancelButton())
1074 view
->GetCancelButton()->Enable(FALSE
);
1075 if (view
->GetEditButton())
1076 view
->GetEditButton()->Enable(TRUE
);
1077 if (view
->GetValueText())
1078 view
->GetValueText()->Enable(FALSE
);
1082 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1084 if (view
->GetValueList())
1086 view
->ShowListBoxControl(TRUE
);
1087 view
->GetValueList()->Enable(TRUE
);
1089 view
->GetValueList()->Append(wxT("True"));
1090 view
->GetValueList()->Append(wxT("False"));
1091 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1092 view
->GetValueList()->SetStringSelection(currentString
);
1093 delete[] currentString
;
1098 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1100 if (view
->GetValueList())
1102 view
->GetValueList()->Clear();
1103 view
->ShowListBoxControl(FALSE
);
1104 view
->GetValueList()->Enable(FALSE
);
1109 // Called when the property is double clicked. Extra functionality can be provided,
1110 // cycling through possible values.
1111 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1113 if (!view
->GetValueText())
1115 if (property
->GetValue().BoolValue())
1116 property
->GetValue() = (bool)FALSE
;
1118 property
->GetValue() = (bool)TRUE
;
1119 view
->DisplayProperty(property
);
1120 view
->UpdatePropertyDisplayInList(property
);
1121 view
->OnPropertyChanged(property
);
1126 /// String validator
1128 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1130 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1131 wxPropertyListValidator(flags
)
1134 // If no constraint, we just allow the string to be edited.
1135 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1136 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1139 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1144 if (!view
->GetValueText())
1146 wxString
value(view
->GetValueText()->GetValue());
1148 if (!m_strings
->Member(value
.GetData()))
1150 wxString
s("Value ");
1151 s
+= value
.GetData();
1152 s
+= " is not valid.";
1153 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1159 // Called when TICK is pressed or focus is lost or view wants to update
1160 // the property list.
1161 // Does the transferance from the property editing area to the property itself
1162 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1164 if (!view
->GetValueText())
1166 wxString
value(view
->GetValueText()->GetValue());
1167 property
->GetValue() = value
;
1171 // Called when TICK is pressed or focus is lost or view wants to update
1172 // the property list.
1173 // Does the transferance from the property editing area to the property itself
1174 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1176 if (!view
->GetValueText())
1178 wxString
str(property
->GetValue().GetStringRepresentation());
1179 view
->GetValueText()->SetValue(str
);
1180 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->GetCount() > 0)
1182 view
->GetValueList()->SetStringSelection(str
);
1187 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1192 if (view
->GetEditButton())
1193 view
->GetEditButton()->Enable(FALSE
);
1194 if (view
->GetConfirmButton())
1195 view
->GetConfirmButton()->Enable(TRUE
);
1196 if (view
->GetCancelButton())
1197 view
->GetCancelButton()->Enable(TRUE
);
1198 if (view
->GetValueText())
1199 view
->GetValueText()->Enable(TRUE
);
1204 if (view
->GetValueText())
1205 view
->GetValueText()->Enable(FALSE
);
1207 if (view
->GetEditButton())
1208 view
->GetEditButton()->Enable(TRUE
);
1210 if (view
->GetConfirmButton())
1211 view
->GetConfirmButton()->Enable(FALSE
);
1212 if (view
->GetCancelButton())
1213 view
->GetCancelButton()->Enable(FALSE
);
1217 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1219 if (view
->GetValueList())
1221 view
->ShowListBoxControl(TRUE
);
1222 view
->GetValueList()->Enable(TRUE
);
1223 wxNode
*node
= m_strings
->First();
1226 wxChar
*s
= (wxChar
*)node
->Data();
1227 view
->GetValueList()->Append(s
);
1228 node
= node
->Next();
1230 wxChar
*currentString
= property
->GetValue().StringValue();
1231 view
->GetValueList()->SetStringSelection(currentString
);
1236 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1243 if (view
->GetValueList())
1245 view
->GetValueList()->Clear();
1246 view
->ShowListBoxControl(FALSE
);
1247 view
->GetValueList()->Enable(FALSE
);
1252 // Called when the property is double clicked. Extra functionality can be provided,
1253 // cycling through possible values.
1254 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1256 if (!view
->GetValueText())
1261 wxNode
*node
= m_strings
->First();
1262 wxChar
*currentString
= property
->GetValue().StringValue();
1265 wxChar
*s
= (wxChar
*)node
->Data();
1266 if (wxStrcmp(s
, currentString
) == 0)
1268 wxChar
*nextString
= NULL
;
1270 nextString
= (wxChar
*)node
->Next()->Data();
1272 nextString
= (wxChar
*)m_strings
->First()->Data();
1273 property
->GetValue() = wxString(nextString
);
1274 view
->DisplayProperty(property
);
1275 view
->UpdatePropertyDisplayInList(property
);
1276 view
->OnPropertyChanged(property
);
1279 else node
= node
->Next();
1285 /// Filename validator
1287 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1289 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1290 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1294 wxFilenameListValidator::~wxFilenameListValidator()
1298 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
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::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1308 if (!view
->GetValueText())
1310 wxString
value(view
->GetValueText()->GetValue());
1311 property
->GetValue() = value
;
1315 // Called when TICK is pressed or focus is lost or view wants to update
1316 // the property list.
1317 // Does the transferance from the property editing area to the property itself
1318 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1320 if (!view
->GetValueText())
1322 wxString
str(property
->GetValue().GetStringRepresentation());
1323 view
->GetValueText()->SetValue(str
);
1327 // Called when the property is double clicked. Extra functionality can be provided,
1328 // cycling through possible values.
1329 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1331 if (!view
->GetValueText())
1333 OnEdit(property
, view
, parentWindow
);
1337 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1339 if (view
->GetConfirmButton())
1340 view
->GetConfirmButton()->Enable(TRUE
);
1341 if (view
->GetCancelButton())
1342 view
->GetCancelButton()->Enable(TRUE
);
1343 if (view
->GetEditButton())
1344 view
->GetEditButton()->Enable(TRUE
);
1345 if (view
->GetValueText())
1346 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1350 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1352 if (!view
->GetValueText())
1355 wxString s
= wxFileSelector(
1356 m_filenameMessage
.GetData(),
1357 wxPathOnly(property
->GetValue().StringValue()),
1358 wxFileNameFromPath(property
->GetValue().StringValue()),
1360 m_filenameWildCard
.GetData(),
1365 property
->GetValue() = s
;
1366 view
->DisplayProperty(property
);
1367 view
->UpdatePropertyDisplayInList(property
);
1368 view
->OnPropertyChanged(property
);
1373 /// Colour validator
1375 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1377 wxColourListValidator::wxColourListValidator(long flags
):
1378 wxPropertyListValidator(flags
)
1382 wxColourListValidator::~wxColourListValidator()
1386 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1391 // Called when TICK is pressed or focus is lost or view wants to update
1392 // the property list.
1393 // Does the transferance from the property editing area to the property itself
1394 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1396 if (!view
->GetValueText())
1398 wxString
value(view
->GetValueText()->GetValue());
1400 property
->GetValue() = value
;
1404 // Called when TICK is pressed or focus is lost or view wants to update
1405 // the property list.
1406 // Does the transferance from the property editing area to the property itself
1407 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1409 if (!view
->GetValueText())
1411 wxString
str(property
->GetValue().GetStringRepresentation());
1412 view
->GetValueText()->SetValue(str
);
1416 // Called when the property is double clicked. Extra functionality can be provided,
1417 // cycling through possible values.
1418 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1420 if (!view
->GetValueText())
1422 OnEdit(property
, view
, parentWindow
);
1426 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1428 if (view
->GetConfirmButton())
1429 view
->GetConfirmButton()->Enable(TRUE
);
1430 if (view
->GetCancelButton())
1431 view
->GetCancelButton()->Enable(TRUE
);
1432 if (view
->GetEditButton())
1433 view
->GetEditButton()->Enable(TRUE
);
1434 if (view
->GetValueText())
1435 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1439 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1441 if (!view
->GetValueText())
1444 wxChar
*s
= property
->GetValue().StringValue();
1451 g
= wxHexToDec(s
+2);
1452 b
= wxHexToDec(s
+4);
1455 wxColour
col(r
,g
,b
);
1458 data
.SetChooseFull(TRUE
);
1459 data
.SetColour(col
);
1461 for (int i
= 0; i
< 16; i
++)
1463 wxColour
colour(i
*16, i
*16, i
*16);
1464 data
.SetCustomColour(i
, colour
);
1467 wxColourDialog
dialog(parentWindow
, &data
);
1468 if (dialog
.ShowModal() != wxID_CANCEL
)
1470 wxColourData retData
= dialog
.GetColourData();
1471 col
= retData
.GetColour();
1474 wxDecToHex(col
.Red(), buf
);
1475 wxDecToHex(col
.Green(), buf
+2);
1476 wxDecToHex(col
.Blue(), buf
+4);
1478 property
->GetValue() = wxString(buf
);
1479 view
->DisplayProperty(property
);
1480 view
->UpdatePropertyDisplayInList(property
);
1481 view
->OnPropertyChanged(property
);
1486 /// List of strings validator. For this we need more user interface than
1487 /// we get with a property list; so create a new dialog for editing the list.
1489 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1491 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1492 wxPropertyListValidator(flags
)
1496 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1498 // No constraints for an arbitrary, user-editable list of strings.
1502 // Called when TICK is pressed or focus is lost or view wants to update
1503 // the property list.
1504 // Does the transferance from the property editing area to the property itself.
1505 // In this case, the user cannot directly edit the string list.
1506 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1511 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1513 if (!view
->GetValueText())
1515 wxString
str(property
->GetValue().GetStringRepresentation());
1516 view
->GetValueText()->SetValue(str
);
1520 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1522 if (view
->GetEditButton())
1523 view
->GetEditButton()->Enable(TRUE
);
1524 if (view
->GetValueText())
1525 view
->GetValueText()->Enable(FALSE
);
1527 if (view
->GetConfirmButton())
1528 view
->GetConfirmButton()->Enable(FALSE
);
1529 if (view
->GetCancelButton())
1530 view
->GetCancelButton()->Enable(FALSE
);
1534 // Called when the property is double clicked. Extra functionality can be provided,
1535 // cycling through possible values.
1536 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1538 OnEdit(property
, view
, parentWindow
);
1542 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1544 // Convert property value to a list of strings for editing
1545 wxStringList
*stringList
= new wxStringList
;
1547 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1550 wxChar
*s
= expr
->StringValue();
1553 expr
= expr
->GetNext();
1556 wxString
title(wxT("Editing "));
1557 title
+= property
->GetName();
1559 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1561 wxPropertyValue
& oldValue
= property
->GetValue();
1562 oldValue
.ClearList();
1563 wxNode
*node
= stringList
->First();
1566 wxChar
*s
= (wxChar
*)node
->Data();
1567 oldValue
.Append(new wxPropertyValue(s
));
1569 node
= node
->Next();
1572 view
->DisplayProperty(property
);
1573 view
->UpdatePropertyDisplayInList(property
);
1574 view
->OnPropertyChanged(property
);
1579 class wxPropertyStringListEditorDialog
: public wxDialog
1582 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1583 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1584 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1585 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1587 m_stringList
= NULL
;
1588 m_stringText
= NULL
;
1590 sm_dialogCancelled
= FALSE
;
1591 m_currentSelection
= -1;
1593 ~wxPropertyStringListEditorDialog(void) {}
1594 void OnCloseWindow(wxCloseEvent
& event
);
1595 void SaveCurrentSelection(void);
1596 void ShowCurrentSelection(void);
1598 void OnOK(wxCommandEvent
& event
);
1599 void OnCancel(wxCommandEvent
& event
);
1600 void OnAdd(wxCommandEvent
& event
);
1601 void OnDelete(wxCommandEvent
& event
);
1602 void OnStrings(wxCommandEvent
& event
);
1603 void OnText(wxCommandEvent
& event
);
1606 wxStringList
* m_stringList
;
1607 wxListBox
* m_listBox
;
1608 wxTextCtrl
* m_stringText
;
1609 static bool sm_dialogCancelled
;
1610 int m_currentSelection
;
1611 DECLARE_EVENT_TABLE()
1614 #define wxID_PROP_SL_ADD 3000
1615 #define wxID_PROP_SL_DELETE 3001
1616 #define wxID_PROP_SL_STRINGS 3002
1617 #define wxID_PROP_SL_TEXT 3003
1619 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1620 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1621 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1622 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1623 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1624 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1625 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1626 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1629 class wxPropertyStringListEditorText
: public wxTextCtrl
1632 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1633 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1634 long windowStyle
= 0, const wxString
& name
= "text"):
1635 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1640 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1641 dialog
->SaveCurrentSelection();
1645 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1647 // Edit the string list.
1648 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1650 int largeButtonWidth
= 60;
1651 int largeButtonHeight
= 25;
1653 wxBeginBusyCursor();
1654 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1655 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1657 dialog
->m_stringList
= stringList
;
1659 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1660 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1662 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1663 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1664 wxSize(300, -1), wxPROCESS_ENTER
);
1665 dialog
->m_stringText
->Enable(FALSE
);
1667 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1668 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1669 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1670 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1673 okButton
->SetDefault();
1676 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1678 c
->top
.SameAs (dialog
, wxTop
, 2);
1679 c
->left
.SameAs (dialog
, wxLeft
, 2);
1680 c
->right
.SameAs (dialog
, wxRight
, 2);
1681 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1682 dialog
->m_listBox
->SetConstraints(c
);
1684 c
= new wxLayoutConstraints
;
1685 c
->left
.SameAs (dialog
, wxLeft
, 2);
1686 c
->right
.SameAs (dialog
, wxRight
, 2);
1687 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1689 dialog
->m_stringText
->SetConstraints(c
);
1691 c
= new wxLayoutConstraints
;
1692 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1693 c
->left
.SameAs (dialog
, wxLeft
, 2);
1696 addButton
->SetConstraints(c
);
1698 c
= new wxLayoutConstraints
;
1699 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1700 c
->left
.SameAs (addButton
, wxRight
, 2);
1703 deleteButton
->SetConstraints(c
);
1705 c
= new wxLayoutConstraints
;
1706 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1707 c
->right
.SameAs (dialog
, wxRight
, 2);
1710 cancelButton
->SetConstraints(c
);
1712 c
= new wxLayoutConstraints
;
1713 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1714 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1717 okButton
->SetConstraints(c
);
1719 wxNode
*node
= stringList
->First();
1722 char *str
= (char *)node
->Data();
1723 // Save node as client data for each listbox item
1724 dialog
->m_listBox
->Append(str
, (char *)node
);
1725 node
= node
->Next();
1728 dialog
->SetClientSize(310, 305);
1731 dialog
->Centre(wxBOTH
);
1733 if (dialog
->ShowModal() == wxID_CANCEL
)
1740 * String list editor callbacks
1744 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1746 int sel
= m_listBox
->GetSelection();
1749 m_currentSelection
= sel
;
1751 ShowCurrentSelection();
1755 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1757 int sel
= m_listBox
->GetSelection();
1761 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1765 m_listBox
->Delete(sel
);
1766 delete[] (wxChar
*)node
->Data();
1768 m_currentSelection
= -1;
1769 m_stringText
->SetValue("");
1772 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1774 SaveCurrentSelection();
1776 wxChar
*initialText
= wxT("");
1777 wxNode
*node
= m_stringList
->Add(initialText
);
1778 m_listBox
->Append(initialText
, (void *)node
);
1779 m_currentSelection
= m_stringList
->Number() - 1;
1780 m_listBox
->SetSelection(m_currentSelection
);
1781 ShowCurrentSelection();
1782 m_stringText
->SetFocus();
1785 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1787 SaveCurrentSelection();
1793 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1795 sm_dialogCancelled
= TRUE
;
1796 EndModal(wxID_CANCEL
);
1801 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1803 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1805 SaveCurrentSelection();
1810 wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
1812 SaveCurrentSelection();
1817 void wxPropertyStringListEditorDialog::SaveCurrentSelection()
1819 if (m_currentSelection
== -1)
1822 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1826 wxString
txt(m_stringText
->GetValue());
1828 delete[] (char *)node
->Data();
1829 node
->SetData((wxObject
*)copystring(txt
));
1831 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1834 void wxPropertyStringListEditorDialog::ShowCurrentSelection()
1836 if (m_currentSelection
== -1)
1838 m_stringText
->SetValue("");
1841 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1842 char *txt
= (char *)node
->Data();
1843 m_stringText
->SetValue(txt
);
1844 m_stringText
->Enable(TRUE
);
1847 // ----------------------------------------------------------------------------
1849 // ----------------------------------------------------------------------------
1852 static wxBitmap
*GetTickBitmap()
1854 static wxBitmap
* s_tickBitmap
= (wxBitmap
*) NULL
;
1855 static bool s_loaded
= FALSE
;
1859 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1861 #if defined(__WXMSW__) || defined(__WXPM__)
1862 s_tickBitmap
= new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE
);
1864 s_tickBitmap
= new wxBitmap( tick_xpm
);
1868 return s_tickBitmap
;
1871 static wxBitmap
*GetCrossBitmap()
1873 static wxBitmap
* s_crossBitmap
= (wxBitmap
*) NULL
;
1874 static bool s_loaded
= FALSE
;
1878 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1880 #if defined(__WXMSW__) || defined(__WXPM__)
1881 s_crossBitmap
= new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE
);
1883 s_crossBitmap
= new wxBitmap( cross_xpm
);
1887 return s_crossBitmap
;
1890 #endif // wxUSE_PROPSHEET