1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "proplist.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/window.h"
26 #include "wx/button.h"
27 #include "wx/bmpbuttn.h"
28 #include "wx/textctrl.h"
29 #include "wx/listbox.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
32 #include "wx/filedlg.h"
36 #include "wx/module.h"
39 #include "wx/colordlg.h"
40 #include "wx/proplist.h"
48 #include "wx/generic/cross.xpm"
49 #include "wx/generic/tick.xpm"
57 static wxBitmap
* gs_tickBitmap
= (wxBitmap
*) NULL
;
58 static wxBitmap
* gs_crossBitmap
= (wxBitmap
*) NULL
;
62 * Property text edit control
65 IMPLEMENT_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
67 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
68 const wxWindowID id
, const wxString
& value
,
69 const wxPoint
& pos
, const wxSize
& size
,
70 long style
, const wxString
& name
):
71 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
76 void wxPropertyTextEdit::OnSetFocus(void)
80 void wxPropertyTextEdit::OnKillFocus(void)
88 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
90 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
92 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
93 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
94 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
95 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
96 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
97 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
98 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
99 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
100 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
101 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
102 wxPropertyListView::OnPropertyDoubleClick
)
103 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
106 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
108 m_propertyScrollingList
= NULL
;
112 m_confirmButton
= NULL
;
113 m_cancelButton
= NULL
;
114 m_propertyWindow
= propPanel
;
115 m_managedWindow
= NULL
;
117 m_windowCloseButton
= NULL
;
118 m_windowCancelButton
= NULL
;
119 m_windowHelpButton
= NULL
;
121 m_detailedEditing
= FALSE
;
124 wxPropertyListView::~wxPropertyListView(void)
128 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
130 m_propertySheet
= ps
;
132 AssociatePanel(panel
);
135 UpdatePropertyList();
139 // Update this view of the viewed object, called e.g. by
140 // the object itself.
141 bool wxPropertyListView::OnUpdateView(void)
146 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
148 if (!m_propertyScrollingList
|| !m_propertySheet
)
151 m_propertyScrollingList
->Clear();
154 m_valueList
->Clear();
155 m_valueText
->SetValue("");
157 wxNode
*node
= m_propertySheet
->GetProperties().First();
159 // Should sort them... later...
162 wxProperty
*property
= (wxProperty
*)node
->Data();
163 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
164 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
165 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
171 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
173 if (!m_propertyScrollingList
|| !m_propertySheet
)
177 int currentlySelected
= m_propertyScrollingList
->GetSelection();
180 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
181 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
182 int sel
= FindListIndexForProperty(property
);
186 // Don't update the listbox unnecessarily because it can cause
189 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
190 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
193 // UpdatePropertyList(FALSE);
196 // TODO: why is this necessary?
198 if (currentlySelected
> -1)
199 m_propertyScrollingList
->SetSelection(currentlySelected
);
205 // Find the wxListBox index corresponding to this property
206 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
208 int n
= m_propertyScrollingList
->Number();
209 for (int i
= 0; i
< n
; i
++)
211 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
217 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
219 wxString
theString(name
);
222 int padWith
= nameWidth
- theString
.Length();
226 if (GetFlags() & wxPROP_SHOWVALUES
)
228 // Want to pad with spaces
229 theString
.Append(' ', padWith
);
236 // Select and show string representation in validator the given
237 // property. NULL resets to show no property.
238 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
240 if (m_currentProperty
)
242 EndShowingProperty(m_currentProperty
);
243 m_currentProperty
= NULL
;
246 m_valueList
->Clear();
247 m_valueText
->SetValue("");
251 m_currentProperty
= property
;
252 BeginShowingProperty(property
);
256 int sel
= FindListIndexForProperty(property
);
258 m_propertyScrollingList
->SetSelection(sel
);
263 // Find appropriate validator and load property into value controls
264 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
266 m_currentValidator
= FindPropertyValidator(property
);
267 if (!m_currentValidator
)
270 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
273 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
275 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
276 DisplayProperty(property
);
280 // Find appropriate validator and unload property from value controls
281 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
283 if (!m_currentValidator
)
286 RetrieveProperty(property
);
288 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
291 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
293 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
294 if (m_detailedEditing
)
296 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
297 m_detailedEditing
= FALSE
;
302 void wxPropertyListView::BeginDetailedEditing(void)
304 if (!m_currentValidator
)
306 if (!m_currentProperty
)
308 if (m_detailedEditing
)
310 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
312 if (!m_currentProperty
->IsEnabled())
315 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
317 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
318 m_detailedEditing
= TRUE
;
321 void wxPropertyListView::EndDetailedEditing(void)
323 if (!m_currentValidator
)
325 if (!m_currentProperty
)
328 RetrieveProperty(m_currentProperty
);
330 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
333 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
335 if (m_detailedEditing
)
337 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
338 m_detailedEditing
= FALSE
;
342 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
344 if (!m_currentValidator
)
347 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
348 m_valueText
->SetEditable(FALSE
);
350 m_valueText
->SetEditable(TRUE
);
352 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
355 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
357 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
361 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
363 if (!m_currentValidator
)
365 if (!property
->IsEnabled())
368 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
371 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
373 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
375 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
377 UpdatePropertyDisplayInList(property
);
378 OnPropertyChanged(property
);
383 // Revert to old value
384 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
390 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
395 // Called by the listbox callback
396 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
398 int sel
= m_propertyScrollingList
->GetSelection();
401 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
402 if (newSel
&& newSel
!= m_currentProperty
)
404 ShowProperty(newSel
, FALSE
);
409 bool wxPropertyListView::CreateControls()
411 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
413 wxSize
largeButtonSize( 60, 25 );
414 wxSize
smallButtonSize( 23, 23 );
422 wxSystemSettings settings
;
423 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
426 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
428 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
431 // May need to be changed in future to eliminate clashes with app.
432 // WHAT WAS THIS FOR?
433 // panel->SetClientData((char *)this);
435 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
437 // top row with optional buttons and input line
439 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
440 int buttonborder
= 3;
442 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
444 if (gs_tickBitmap
&& gs_crossBitmap
)
446 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, *gs_tickBitmap
, wxPoint(-1, -1), smallButtonSize
);
447 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, *gs_crossBitmap
, wxPoint(-1, -1), smallButtonSize
);
451 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)", wxPoint(-1, -1), smallButtonSize
);
452 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X", wxPoint(-1, -1), smallButtonSize
);
455 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
456 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
459 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "",
460 wxPoint(-1, -1), wxSize(-1, smallButtonSize
.y
), wxPROCESS_ENTER
);
461 m_valueText
->Enable(FALSE
);
462 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
464 if (m_buttonFlags
& wxPROP_PULLDOWN
)
466 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...", wxPoint(-1, -1), smallButtonSize
);
467 m_editButton
->Enable(FALSE
);
468 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
471 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
473 // middle section with two list boxes
475 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
477 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
478 m_valueList
->Show(FALSE
);
480 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxPoint(-1, -1), wxSize(100, 100));
481 m_propertyScrollingList
->SetFont(* boringFont
);
482 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
484 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
486 // bottom row with buttons
488 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
489 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
490 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
491 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
493 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
496 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
498 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxPoint(-1, -1), largeButtonSize
);
499 m_windowCloseButton
->SetDefault();
500 m_windowCloseButton
->SetFocus();
501 bottomsizer
->Add( m_windowCloseButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
, buttonborder
);
503 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
505 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxPoint(-1, -1), largeButtonSize
);
506 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
508 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
510 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxPoint(-1, -1), largeButtonSize
);
511 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
513 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
515 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxPoint(-1, -1), largeButtonSize
);
516 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
519 mainsizer
->Add( bottomsizer
, 1, wxALIGN_RIGHT
| wxEXPAND
);
522 panel
->SetSizer( mainsizer
);
527 void wxPropertyListView::ShowTextControl(bool show
)
530 m_valueText
->Show(show
);
533 void wxPropertyListView::ShowListBoxControl(bool show
)
535 if (!m_valueList
) return;
537 m_valueList
->Show(show
);
539 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
542 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
544 m_middleSizer
->Remove( 0 );
546 m_propertyWindow
->Layout();
550 void wxPropertyListView::EnableCheck(bool show
)
553 m_confirmButton
->Enable(show
);
556 void wxPropertyListView::EnableCross(bool show
)
559 m_cancelButton
->Enable(show
);
562 bool wxPropertyListView::OnClose(void)
564 // Retrieve the value if any
565 wxCommandEvent event
;
572 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
574 if (m_currentProperty
&& m_currentValidator
)
576 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
579 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
581 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
585 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
587 // Retrieve the value if any
590 m_managedWindow
->Close(TRUE
);
593 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
595 // SetReturnCode(wxID_CANCEL);
596 m_managedWindow
->Close(TRUE
);
597 sm_dialogCancelled
= TRUE
;
600 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
604 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
606 if (m_currentProperty
)
608 RetrieveProperty(m_currentProperty
);
612 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
614 if (m_currentProperty
&& m_currentValidator
)
616 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
619 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
621 // Revert to old value
622 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
626 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
628 if (m_currentProperty
&& m_currentValidator
)
630 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
633 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
635 // Revert to old value
636 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
640 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
642 if (m_currentProperty
&& m_currentValidator
)
644 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
647 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
649 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
653 void wxPropertyListView::OnText(wxCommandEvent
& event
)
655 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
662 * Property dialog box
665 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
667 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
668 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
669 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
672 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
673 const wxString
& title
, const wxPoint
& pos
,
674 const wxSize
& size
, long style
, const wxString
& name
):
675 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
678 m_view
->AssociatePanel( ((wxPanel
*)this) );
679 m_view
->SetManagedWindow(this);
683 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
687 SetReturnCode(wxID_CANCEL
);
698 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
700 SetReturnCode(wxID_CANCEL
);
704 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
707 if (item == m_view->GetPropertyScrollingList())
708 view->OnDoubleClick();
712 // Extend event processing to search the view's event table
713 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
715 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
716 return wxEvtHandler::ProcessEvent(event
);
725 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
727 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
728 EVT_SIZE(wxPropertyListPanel::OnSize
)
731 wxPropertyListPanel::~wxPropertyListPanel()
735 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
738 if (item == view->GetPropertyScrollingList())
739 view->OnDoubleClick();
743 // Extend event processing to search the view's event table
744 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
746 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
747 return wxEvtHandler::ProcessEvent(event
);
752 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
761 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
763 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
764 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
767 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
772 m_propertyPanel
->SetView(NULL
);
783 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
785 return new wxPropertyListPanel(v
, parent
);
788 bool wxPropertyListFrame::Initialize(void)
790 m_propertyPanel
= OnCreatePanel(this, m_view
);
793 m_view
->AssociatePanel(m_propertyPanel
);
794 m_view
->SetManagedWindow(this);
795 m_propertyPanel
->SetAutoLayout(TRUE
);
803 * Property list specific validator
806 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
808 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
810 // view->GetValueText()->Show(TRUE);
812 OnDisplayValue(property
, view
, parentWindow
);
817 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
819 wxString
s(view
->GetValueList()->GetStringSelection());
822 view
->GetValueText()->SetValue(s
);
823 view
->RetrieveProperty(property
);
828 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
830 // view->GetValueText()->Show(TRUE);
831 wxString
str(property
->GetValue().GetStringRepresentation());
833 view
->GetValueText()->SetValue(str
);
837 // Called when TICK is pressed or focus is lost or view wants to update
838 // the property list.
839 // Does the transferance from the property editing area to the property itself
840 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
842 if (!view
->GetValueText())
847 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
849 if (view
->GetDetailedEditing())
850 view
->EndDetailedEditing();
852 view
->BeginDetailedEditing();
855 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
857 if (view
->GetConfirmButton())
858 view
->GetConfirmButton()->Enable(FALSE
);
859 if (view
->GetCancelButton())
860 view
->GetCancelButton()->Enable(FALSE
);
861 if (view
->GetEditButton())
862 view
->GetEditButton()->Enable(FALSE
);
870 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
873 /// Real number validator
875 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
877 if (m_realMin
== 0.0 && m_realMax
== 0.0)
880 if (!view
->GetValueText())
882 wxString
value(view
->GetValueText()->GetValue());
885 if (!StringToFloat(WXSTRINGCAST value
, &val
))
888 wxSprintf(buf
, _T("Value %s is not a valid real number!"), value
.GetData());
889 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
893 if (val
< m_realMin
|| val
> m_realMax
)
896 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
897 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
903 // Called when TICK is pressed or focus is lost or view wants to update
904 // the property list.
905 // Does the transferance from the property editing area to the property itself
906 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
908 if (!view
->GetValueText())
911 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
914 wxString
value(view
->GetValueText()->GetValue());
915 float f
= (float)wxAtof(value
.GetData());
916 property
->GetValue() = f
;
920 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
922 if (view
->GetConfirmButton())
923 view
->GetConfirmButton()->Enable(TRUE
);
924 if (view
->GetCancelButton())
925 view
->GetCancelButton()->Enable(TRUE
);
926 if (view
->GetEditButton())
927 view
->GetEditButton()->Enable(FALSE
);
928 if (view
->GetValueText())
929 view
->GetValueText()->Enable(TRUE
);
934 /// Integer validator
936 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
938 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
940 if (m_integerMin
== 0 && m_integerMax
== 0)
943 if (!view
->GetValueText())
945 wxString
value(view
->GetValueText()->GetValue());
948 if (!StringToLong(WXSTRINGCAST value
, &val
))
951 wxSprintf(buf
, _T("Value %s is not a valid integer!"), value
.GetData());
952 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
955 if (val
< m_integerMin
|| val
> m_integerMax
)
958 wxSprintf(buf
, _T("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
959 wxMessageBox(buf
, _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
965 // Called when TICK is pressed or focus is lost or view wants to update
966 // the property list.
967 // Does the transferance from the property editing area to the property itself
968 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
970 if (!view
->GetValueText())
973 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
976 wxString
value(view
->GetValueText()->GetValue());
977 long val
= (long)wxAtoi(value
.GetData());
978 property
->GetValue() = (long)val
;
982 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
984 if (view
->GetConfirmButton())
985 view
->GetConfirmButton()->Enable(TRUE
);
986 if (view
->GetCancelButton())
987 view
->GetCancelButton()->Enable(TRUE
);
988 if (view
->GetEditButton())
989 view
->GetEditButton()->Enable(FALSE
);
990 if (view
->GetValueText())
991 view
->GetValueText()->Enable(TRUE
);
996 /// boolean validator
998 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1000 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1002 if (!view
->GetValueText())
1004 wxString
value(view
->GetValueText()->GetValue());
1005 if (value
!= _T("True") && value
!= _T("False"))
1007 wxMessageBox(_T("Value must be True or False!"), _T("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1013 // Called when TICK is pressed or focus is lost or view wants to update
1014 // the property list.
1015 // Does the transferance from the property editing area to the property itself
1016 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1018 if (!view
->GetValueText())
1021 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1024 wxString
value(view
->GetValueText()->GetValue());
1025 bool boolValue
= FALSE
;
1026 if (value
== _T("True"))
1030 property
->GetValue() = (bool)boolValue
;
1034 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1036 if (!view
->GetValueText())
1038 wxString
str(property
->GetValue().GetStringRepresentation());
1040 view
->GetValueText()->SetValue(str
);
1042 if (view
->GetValueList()->IsShown())
1044 view
->GetValueList()->SetStringSelection(str
);
1049 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1051 if (view
->GetConfirmButton())
1052 view
->GetConfirmButton()->Enable(FALSE
);
1053 if (view
->GetCancelButton())
1054 view
->GetCancelButton()->Enable(FALSE
);
1055 if (view
->GetEditButton())
1056 view
->GetEditButton()->Enable(TRUE
);
1057 if (view
->GetValueText())
1058 view
->GetValueText()->Enable(FALSE
);
1062 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1064 if (view
->GetValueList())
1066 view
->ShowListBoxControl(TRUE
);
1067 view
->GetValueList()->Enable(TRUE
);
1069 view
->GetValueList()->Append(_T("True"));
1070 view
->GetValueList()->Append(_T("False"));
1071 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1072 view
->GetValueList()->SetStringSelection(currentString
);
1073 delete[] currentString
;
1078 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1080 if (view
->GetValueList())
1082 view
->GetValueList()->Clear();
1083 view
->ShowListBoxControl(FALSE
);
1084 view
->GetValueList()->Enable(FALSE
);
1089 // Called when the property is double clicked. Extra functionality can be provided,
1090 // cycling through possible values.
1091 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1093 if (!view
->GetValueText())
1095 if (property
->GetValue().BoolValue())
1096 property
->GetValue() = (bool)FALSE
;
1098 property
->GetValue() = (bool)TRUE
;
1099 view
->DisplayProperty(property
);
1100 view
->UpdatePropertyDisplayInList(property
);
1101 view
->OnPropertyChanged(property
);
1106 /// String validator
1108 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1110 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1111 wxPropertyListValidator(flags
)
1114 // If no constraint, we just allow the string to be edited.
1115 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1116 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1119 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1124 if (!view
->GetValueText())
1126 wxString
value(view
->GetValueText()->GetValue());
1128 if (!m_strings
->Member(value
.GetData()))
1130 wxString
s("Value ");
1131 s
+= value
.GetData();
1132 s
+= " is not valid.";
1133 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1139 // Called when TICK is pressed or focus is lost or view wants to update
1140 // the property list.
1141 // Does the transferance from the property editing area to the property itself
1142 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1144 if (!view
->GetValueText())
1146 wxString
value(view
->GetValueText()->GetValue());
1147 property
->GetValue() = value
;
1151 // Called when TICK is pressed or focus is lost or view wants to update
1152 // the property list.
1153 // Does the transferance from the property editing area to the property itself
1154 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1156 if (!view
->GetValueText())
1158 wxString
str(property
->GetValue().GetStringRepresentation());
1159 view
->GetValueText()->SetValue(str
);
1160 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1162 view
->GetValueList()->SetStringSelection(str
);
1167 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1172 if (view
->GetEditButton())
1173 view
->GetEditButton()->Enable(FALSE
);
1174 if (view
->GetConfirmButton())
1175 view
->GetConfirmButton()->Enable(TRUE
);
1176 if (view
->GetCancelButton())
1177 view
->GetCancelButton()->Enable(TRUE
);
1178 if (view
->GetValueText())
1179 view
->GetValueText()->Enable(TRUE
);
1184 if (view
->GetValueText())
1185 view
->GetValueText()->Enable(FALSE
);
1187 if (view
->GetEditButton())
1188 view
->GetEditButton()->Enable(TRUE
);
1190 if (view
->GetConfirmButton())
1191 view
->GetConfirmButton()->Enable(FALSE
);
1192 if (view
->GetCancelButton())
1193 view
->GetCancelButton()->Enable(FALSE
);
1197 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1199 if (view
->GetValueList())
1201 view
->ShowListBoxControl(TRUE
);
1202 view
->GetValueList()->Enable(TRUE
);
1203 wxNode
*node
= m_strings
->First();
1206 wxChar
*s
= (wxChar
*)node
->Data();
1207 view
->GetValueList()->Append(s
);
1208 node
= node
->Next();
1210 wxChar
*currentString
= property
->GetValue().StringValue();
1211 view
->GetValueList()->SetStringSelection(currentString
);
1216 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1223 if (view
->GetValueList())
1225 view
->GetValueList()->Clear();
1226 view
->ShowListBoxControl(FALSE
);
1227 view
->GetValueList()->Enable(FALSE
);
1232 // Called when the property is double clicked. Extra functionality can be provided,
1233 // cycling through possible values.
1234 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1236 if (!view
->GetValueText())
1241 wxNode
*node
= m_strings
->First();
1242 wxChar
*currentString
= property
->GetValue().StringValue();
1245 wxChar
*s
= (wxChar
*)node
->Data();
1246 if (wxStrcmp(s
, currentString
) == 0)
1248 wxChar
*nextString
= NULL
;
1250 nextString
= (wxChar
*)node
->Next()->Data();
1252 nextString
= (wxChar
*)m_strings
->First()->Data();
1253 property
->GetValue() = wxString(nextString
);
1254 view
->DisplayProperty(property
);
1255 view
->UpdatePropertyDisplayInList(property
);
1256 view
->OnPropertyChanged(property
);
1259 else node
= node
->Next();
1265 /// Filename validator
1267 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1269 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1270 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1274 wxFilenameListValidator::~wxFilenameListValidator(void)
1278 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1283 // Called when TICK is pressed or focus is lost or view wants to update
1284 // the property list.
1285 // Does the transferance from the property editing area to the property itself
1286 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1288 if (!view
->GetValueText())
1290 wxString
value(view
->GetValueText()->GetValue());
1291 property
->GetValue() = value
;
1295 // Called when TICK is pressed or focus is lost or view wants to update
1296 // the property list.
1297 // Does the transferance from the property editing area to the property itself
1298 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1300 if (!view
->GetValueText())
1302 wxString
str(property
->GetValue().GetStringRepresentation());
1303 view
->GetValueText()->SetValue(str
);
1307 // Called when the property is double clicked. Extra functionality can be provided,
1308 // cycling through possible values.
1309 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1311 if (!view
->GetValueText())
1313 OnEdit(property
, view
, parentWindow
);
1317 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1319 if (view
->GetConfirmButton())
1320 view
->GetConfirmButton()->Enable(TRUE
);
1321 if (view
->GetCancelButton())
1322 view
->GetCancelButton()->Enable(TRUE
);
1323 if (view
->GetEditButton())
1324 view
->GetEditButton()->Enable(TRUE
);
1325 if (view
->GetValueText())
1326 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1330 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1332 if (!view
->GetValueText())
1335 wxString s
= wxFileSelector(
1336 m_filenameMessage
.GetData(),
1337 wxPathOnly(property
->GetValue().StringValue()),
1338 wxFileNameFromPath(property
->GetValue().StringValue()),
1340 m_filenameWildCard
.GetData(),
1345 property
->GetValue() = s
;
1346 view
->DisplayProperty(property
);
1347 view
->UpdatePropertyDisplayInList(property
);
1348 view
->OnPropertyChanged(property
);
1353 /// Colour validator
1355 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1357 wxColourListValidator::wxColourListValidator(long flags
):
1358 wxPropertyListValidator(flags
)
1362 wxColourListValidator::~wxColourListValidator(void)
1366 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1371 // Called when TICK is pressed or focus is lost or view wants to update
1372 // the property list.
1373 // Does the transferance from the property editing area to the property itself
1374 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1376 if (!view
->GetValueText())
1378 wxString
value(view
->GetValueText()->GetValue());
1380 property
->GetValue() = value
;
1384 // Called when TICK is pressed or focus is lost or view wants to update
1385 // the property list.
1386 // Does the transferance from the property editing area to the property itself
1387 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1389 if (!view
->GetValueText())
1391 wxString
str(property
->GetValue().GetStringRepresentation());
1392 view
->GetValueText()->SetValue(str
);
1396 // Called when the property is double clicked. Extra functionality can be provided,
1397 // cycling through possible values.
1398 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1400 if (!view
->GetValueText())
1402 OnEdit(property
, view
, parentWindow
);
1406 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1408 if (view
->GetConfirmButton())
1409 view
->GetConfirmButton()->Enable(TRUE
);
1410 if (view
->GetCancelButton())
1411 view
->GetCancelButton()->Enable(TRUE
);
1412 if (view
->GetEditButton())
1413 view
->GetEditButton()->Enable(TRUE
);
1414 if (view
->GetValueText())
1415 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1419 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1421 if (!view
->GetValueText())
1424 wxChar
*s
= property
->GetValue().StringValue();
1431 g
= wxHexToDec(s
+2);
1432 b
= wxHexToDec(s
+4);
1435 wxColour
col(r
,g
,b
);
1438 data
.SetChooseFull(TRUE
);
1439 data
.SetColour(col
);
1441 for (int i
= 0; i
< 16; i
++)
1443 wxColour
colour(i
*16, i
*16, i
*16);
1444 data
.SetCustomColour(i
, colour
);
1447 wxColourDialog
dialog(parentWindow
, &data
);
1448 if (dialog
.ShowModal() != wxID_CANCEL
)
1450 wxColourData retData
= dialog
.GetColourData();
1451 col
= retData
.GetColour();
1454 wxDecToHex(col
.Red(), buf
);
1455 wxDecToHex(col
.Green(), buf
+2);
1456 wxDecToHex(col
.Blue(), buf
+4);
1458 property
->GetValue() = wxString(buf
);
1459 view
->DisplayProperty(property
);
1460 view
->UpdatePropertyDisplayInList(property
);
1461 view
->OnPropertyChanged(property
);
1466 /// List of strings validator. For this we need more user interface than
1467 /// we get with a property list; so create a new dialog for editing the list.
1469 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1471 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1472 wxPropertyListValidator(flags
)
1476 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1478 // No constraints for an arbitrary, user-editable list of strings.
1482 // Called when TICK is pressed or focus is lost or view wants to update
1483 // the property list.
1484 // Does the transferance from the property editing area to the property itself.
1485 // In this case, the user cannot directly edit the string list.
1486 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1491 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1493 if (!view
->GetValueText())
1495 wxString
str(property
->GetValue().GetStringRepresentation());
1496 view
->GetValueText()->SetValue(str
);
1500 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1502 if (view
->GetEditButton())
1503 view
->GetEditButton()->Enable(TRUE
);
1504 if (view
->GetValueText())
1505 view
->GetValueText()->Enable(FALSE
);
1507 if (view
->GetConfirmButton())
1508 view
->GetConfirmButton()->Enable(FALSE
);
1509 if (view
->GetCancelButton())
1510 view
->GetCancelButton()->Enable(FALSE
);
1514 // Called when the property is double clicked. Extra functionality can be provided,
1515 // cycling through possible values.
1516 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1518 OnEdit(property
, view
, parentWindow
);
1522 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1524 // Convert property value to a list of strings for editing
1525 wxStringList
*stringList
= new wxStringList
;
1527 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1530 wxChar
*s
= expr
->StringValue();
1533 expr
= expr
->GetNext();
1536 wxString
title(_T("Editing "));
1537 title
+= property
->GetName();
1539 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1541 wxPropertyValue
& oldValue
= property
->GetValue();
1542 oldValue
.ClearList();
1543 wxNode
*node
= stringList
->First();
1546 wxChar
*s
= (wxChar
*)node
->Data();
1547 oldValue
.Append(new wxPropertyValue(s
));
1549 node
= node
->Next();
1552 view
->DisplayProperty(property
);
1553 view
->UpdatePropertyDisplayInList(property
);
1554 view
->OnPropertyChanged(property
);
1559 class wxPropertyStringListEditorDialog
: public wxDialog
1562 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1563 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1564 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1565 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1567 m_stringList
= NULL
;
1568 m_stringText
= NULL
;
1570 sm_dialogCancelled
= FALSE
;
1571 m_currentSelection
= -1;
1573 ~wxPropertyStringListEditorDialog(void) {}
1574 void OnCloseWindow(wxCloseEvent
& event
);
1575 void SaveCurrentSelection(void);
1576 void ShowCurrentSelection(void);
1578 void OnOK(wxCommandEvent
& event
);
1579 void OnCancel(wxCommandEvent
& event
);
1580 void OnAdd(wxCommandEvent
& event
);
1581 void OnDelete(wxCommandEvent
& event
);
1582 void OnStrings(wxCommandEvent
& event
);
1583 void OnText(wxCommandEvent
& event
);
1586 wxStringList
* m_stringList
;
1587 wxListBox
* m_listBox
;
1588 wxTextCtrl
* m_stringText
;
1589 static bool sm_dialogCancelled
;
1590 int m_currentSelection
;
1591 DECLARE_EVENT_TABLE()
1594 #define wxID_PROP_SL_ADD 3000
1595 #define wxID_PROP_SL_DELETE 3001
1596 #define wxID_PROP_SL_STRINGS 3002
1597 #define wxID_PROP_SL_TEXT 3003
1599 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1600 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1601 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1602 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1603 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1604 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1605 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1606 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1609 class wxPropertyStringListEditorText
: public wxTextCtrl
1612 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1613 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1614 long windowStyle
= 0, const wxString
& name
= "text"):
1615 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1618 void OnKillFocus(void)
1620 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1621 dialog
->SaveCurrentSelection();
1625 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1627 // Edit the string list.
1628 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1630 int largeButtonWidth
= 60;
1631 int largeButtonHeight
= 25;
1633 wxBeginBusyCursor();
1634 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1635 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1637 dialog
->m_stringList
= stringList
;
1639 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1640 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1642 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1643 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1644 wxSize(300, -1), wxPROCESS_ENTER
);
1645 dialog
->m_stringText
->Enable(FALSE
);
1647 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1648 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1649 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1650 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1653 okButton
->SetDefault();
1656 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1658 c
->top
.SameAs (dialog
, wxTop
, 2);
1659 c
->left
.SameAs (dialog
, wxLeft
, 2);
1660 c
->right
.SameAs (dialog
, wxRight
, 2);
1661 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1662 dialog
->m_listBox
->SetConstraints(c
);
1664 c
= new wxLayoutConstraints
;
1665 c
->left
.SameAs (dialog
, wxLeft
, 2);
1666 c
->right
.SameAs (dialog
, wxRight
, 2);
1667 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1669 dialog
->m_stringText
->SetConstraints(c
);
1671 c
= new wxLayoutConstraints
;
1672 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1673 c
->left
.SameAs (dialog
, wxLeft
, 2);
1676 addButton
->SetConstraints(c
);
1678 c
= new wxLayoutConstraints
;
1679 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1680 c
->left
.SameAs (addButton
, wxRight
, 2);
1683 deleteButton
->SetConstraints(c
);
1685 c
= new wxLayoutConstraints
;
1686 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1687 c
->right
.SameAs (dialog
, wxRight
, 2);
1690 cancelButton
->SetConstraints(c
);
1692 c
= new wxLayoutConstraints
;
1693 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1694 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1697 okButton
->SetConstraints(c
);
1699 wxNode
*node
= stringList
->First();
1702 char *str
= (char *)node
->Data();
1703 // Save node as client data for each listbox item
1704 dialog
->m_listBox
->Append(str
, (char *)node
);
1705 node
= node
->Next();
1708 dialog
->SetClientSize(310, 305);
1711 dialog
->Centre(wxBOTH
);
1713 if (dialog
->ShowModal() == wxID_CANCEL
)
1720 * String list editor callbacks
1724 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1726 int sel
= m_listBox
->GetSelection();
1729 m_currentSelection
= sel
;
1731 ShowCurrentSelection();
1735 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1737 int sel
= m_listBox
->GetSelection();
1741 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1745 m_listBox
->Delete(sel
);
1746 delete[] (wxChar
*)node
->Data();
1748 m_currentSelection
= -1;
1749 m_stringText
->SetValue("");
1752 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1754 SaveCurrentSelection();
1756 wxChar
*initialText
= _T("");
1757 wxNode
*node
= m_stringList
->Add(initialText
);
1758 m_listBox
->Append(initialText
, (void *)node
);
1759 m_currentSelection
= m_stringList
->Number() - 1;
1760 m_listBox
->SetSelection(m_currentSelection
);
1761 ShowCurrentSelection();
1762 m_stringText
->SetFocus();
1765 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1767 SaveCurrentSelection();
1773 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1775 sm_dialogCancelled
= TRUE
;
1776 EndModal(wxID_CANCEL
);
1781 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1783 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1785 SaveCurrentSelection();
1789 void wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& event
)
1791 SaveCurrentSelection();
1795 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1797 if (m_currentSelection
== -1)
1800 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1804 wxString
txt(m_stringText
->GetValue());
1806 delete[] (char *)node
->Data();
1807 node
->SetData((wxObject
*)copystring(txt
));
1809 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1812 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1814 if (m_currentSelection
== -1)
1816 m_stringText
->SetValue("");
1819 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1820 char *txt
= (char *)node
->Data();
1821 m_stringText
->SetValue(txt
);
1822 m_stringText
->Enable(TRUE
);
1825 //-----------------------------------------------------------------------------
1827 //-----------------------------------------------------------------------------
1829 class wxPropertyModule
: public wxModule
1831 DECLARE_DYNAMIC_CLASS(wxPropertyModule
)
1834 wxPropertyModule() {}
1839 IMPLEMENT_DYNAMIC_CLASS(wxPropertyModule
,wxModule
)
1841 bool wxPropertyModule::OnInit()
1844 gs_tickBitmap
= new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE
);
1845 gs_crossBitmap
= new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE
);
1847 gs_tickBitmap
= new wxBitmap( tick_xpm
);
1848 gs_crossBitmap
= new wxBitmap( cross_xpm
);
1850 if (!gs_tickBitmap
|| !gs_crossBitmap
|| !gs_tickBitmap
->Ok() || !gs_crossBitmap
->Ok())
1852 if (gs_tickBitmap
) delete gs_tickBitmap
;
1853 if (gs_crossBitmap
) delete gs_crossBitmap
;
1854 gs_tickBitmap
= (wxBitmap
*) NULL
;
1855 gs_crossBitmap
= (wxBitmap
*) NULL
;
1861 void wxPropertyModule::OnExit()
1864 delete gs_tickBitmap
;
1866 delete gs_crossBitmap
;