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 // ----------------------------------------------------------------------------
62 #include "wx/generic/cross.xpm"
63 #include "wx/generic/tick.xpm"
66 // ----------------------------------------------------------------------------
67 // accessor functions for the bitmaps (may return NULL, check for it!)
68 // ----------------------------------------------------------------------------
70 static wxBitmap
*GetTickBitmap();
71 static wxBitmap
*GetCrossBitmap();
73 // ----------------------------------------------------------------------------
74 // Property text edit control
75 // ----------------------------------------------------------------------------
77 IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
79 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
80 const wxWindowID id
, const wxString
& value
,
81 const wxPoint
& pos
, const wxSize
& size
,
82 long style
, const wxString
& name
):
83 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
88 void wxPropertyTextEdit::OnSetFocus()
92 void wxPropertyTextEdit::OnKillFocus()
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 bool wxPropertyListView::sm_dialogCancelled
= FALSE
;
102 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
104 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
105 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
106 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
107 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
108 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
109 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
110 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
111 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
112 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
113 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
,
114 wxPropertyListView::OnPropertyDoubleClick
)
115 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
118 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
120 m_propertyScrollingList
= NULL
;
124 m_confirmButton
= NULL
;
125 m_cancelButton
= NULL
;
126 m_propertyWindow
= propPanel
;
127 m_managedWindow
= NULL
;
129 m_windowCloseButton
= NULL
;
130 m_windowCancelButton
= NULL
;
131 m_windowHelpButton
= NULL
;
133 m_detailedEditing
= FALSE
;
136 wxPropertyListView::~wxPropertyListView()
140 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
142 m_propertySheet
= ps
;
144 AssociatePanel(panel
);
147 UpdatePropertyList();
151 // Update this view of the viewed object, called e.g. by
152 // the object itself.
153 bool wxPropertyListView::OnUpdateView()
158 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
160 if (!m_propertyScrollingList
|| !m_propertySheet
)
163 m_propertyScrollingList
->Clear();
166 m_valueList
->Clear();
167 m_valueText
->SetValue("");
169 wxNode
*node
= m_propertySheet
->GetProperties().First();
171 // Should sort them... later...
174 wxProperty
*property
= (wxProperty
*)node
->Data();
175 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
176 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
177 m_propertyScrollingList
->Append(paddedString
.GetData(), (void *)property
);
183 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
185 if (!m_propertyScrollingList
|| !m_propertySheet
)
189 int currentlySelected
= m_propertyScrollingList
->GetSelection();
192 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
193 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
194 int sel
= FindListIndexForProperty(property
);
198 // Don't update the listbox unnecessarily because it can cause
201 if (paddedString
!= m_propertyScrollingList
->GetString(sel
))
202 m_propertyScrollingList
->SetString(sel
, paddedString
.GetData());
205 // UpdatePropertyList(FALSE);
208 // TODO: why is this necessary?
210 if (currentlySelected
> -1)
211 m_propertyScrollingList
->SetSelection(currentlySelected
);
217 // Find the wxListBox index corresponding to this property
218 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
220 int n
= m_propertyScrollingList
->Number();
221 for (int i
= 0; i
< n
; i
++)
223 if (property
== (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(i
))
229 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
231 wxString
theString(name
);
234 int padWith
= nameWidth
- theString
.Length();
238 if (GetFlags() & wxPROP_SHOWVALUES
)
240 // Want to pad with spaces
241 theString
.Append(' ', padWith
);
248 // Select and show string representation in validator the given
249 // property. NULL resets to show no property.
250 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
252 if (m_currentProperty
)
254 EndShowingProperty(m_currentProperty
);
255 m_currentProperty
= NULL
;
258 m_valueList
->Clear();
259 m_valueText
->SetValue("");
263 m_currentProperty
= property
;
264 BeginShowingProperty(property
);
268 int sel
= FindListIndexForProperty(property
);
270 m_propertyScrollingList
->SetSelection(sel
);
275 // Find appropriate validator and load property into value controls
276 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
278 m_currentValidator
= FindPropertyValidator(property
);
279 if (!m_currentValidator
)
282 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
285 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
287 listValidator
->OnPrepareControls(property
, this, m_propertyWindow
);
288 DisplayProperty(property
);
292 // Find appropriate validator and unload property from value controls
293 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
295 if (!m_currentValidator
)
298 RetrieveProperty(property
);
300 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
303 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
305 listValidator
->OnClearControls(property
, this, m_propertyWindow
);
306 if (m_detailedEditing
)
308 listValidator
->OnClearDetailControls(property
, this, m_propertyWindow
);
309 m_detailedEditing
= FALSE
;
314 void wxPropertyListView::BeginDetailedEditing()
316 if (!m_currentValidator
)
318 if (!m_currentProperty
)
320 if (m_detailedEditing
)
322 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
324 if (!m_currentProperty
->IsEnabled())
327 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
329 if (listValidator
->OnPrepareDetailControls(m_currentProperty
, this, m_propertyWindow
))
330 m_detailedEditing
= TRUE
;
333 void wxPropertyListView::EndDetailedEditing()
335 if (!m_currentValidator
)
337 if (!m_currentProperty
)
340 RetrieveProperty(m_currentProperty
);
342 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
345 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
347 if (m_detailedEditing
)
349 listValidator
->OnClearDetailControls(m_currentProperty
, this, m_propertyWindow
);
350 m_detailedEditing
= FALSE
;
354 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
356 if (!m_currentValidator
)
359 if (((m_currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
360 m_valueText
->SetEditable(FALSE
);
362 m_valueText
->SetEditable(TRUE
);
364 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
367 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
369 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
373 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
375 if (!m_currentValidator
)
377 if (!property
->IsEnabled())
380 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
383 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
385 if (listValidator
->OnCheckValue(property
, this, m_propertyWindow
))
387 if (listValidator
->OnRetrieveValue(property
, this, m_propertyWindow
))
389 UpdatePropertyDisplayInList(property
);
390 OnPropertyChanged(property
);
395 // Revert to old value
396 listValidator
->OnDisplayValue(property
, this, m_propertyWindow
);
402 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
407 // Called by the listbox callback
408 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
410 int sel
= m_propertyScrollingList
->GetSelection();
413 wxProperty
*newSel
= (wxProperty
*)m_propertyScrollingList
->wxListBox::GetClientData(sel
);
414 if (newSel
&& newSel
!= m_currentProperty
)
416 ShowProperty(newSel
, FALSE
);
421 bool wxPropertyListView::CreateControls()
423 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
425 wxSize
largeButtonSize( 70, 25 );
426 wxSize
smallButtonSize( 23, 23 );
434 wxSystemSettings settings
;
435 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
438 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
440 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
443 // May need to be changed in future to eliminate clashes with app.
444 // WHAT WAS THIS FOR?
445 // panel->SetClientData((char *)this);
447 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
449 // top row with optional buttons and input line
451 wxBoxSizer
*topsizer
= new wxBoxSizer( wxHORIZONTAL
);
452 int buttonborder
= 3;
454 if (m_buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
456 wxBitmap
*tickBitmap
= GetTickBitmap();
457 wxBitmap
*crossBitmap
= GetCrossBitmap();
459 if ( tickBitmap
&& crossBitmap
)
461 m_confirmButton
= new wxBitmapButton(panel
, wxID_PROP_CHECK
, *tickBitmap
, wxPoint(-1, -1), smallButtonSize
);
462 m_cancelButton
= new wxBitmapButton(panel
, wxID_PROP_CROSS
, *crossBitmap
, wxPoint(-1, -1), smallButtonSize
);
466 m_confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)", wxPoint(-1, -1), smallButtonSize
);
467 m_cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X", wxPoint(-1, -1), smallButtonSize
);
470 topsizer
->Add( m_confirmButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
471 topsizer
->Add( m_cancelButton
, 0, wxLEFT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
474 m_valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "",
475 wxPoint(-1, -1), wxSize(-1, smallButtonSize
.y
), wxPROCESS_ENTER
);
476 m_valueText
->Enable(FALSE
);
477 topsizer
->Add( m_valueText
, 1, wxALL
| wxEXPAND
, buttonborder
);
479 if (m_buttonFlags
& wxPROP_PULLDOWN
)
481 m_editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...", wxPoint(-1, -1), smallButtonSize
);
482 m_editButton
->Enable(FALSE
);
483 topsizer
->Add( m_editButton
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, buttonborder
);
486 mainsizer
->Add( topsizer
, 0, wxEXPAND
);
488 // middle section with two list boxes
490 m_middleSizer
= new wxBoxSizer( wxVERTICAL
);
492 m_valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
493 m_valueList
->Show(FALSE
);
495 m_propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
, wxPoint(-1, -1), wxSize(100, 100));
496 m_propertyScrollingList
->SetFont(* boringFont
);
497 m_middleSizer
->Add( m_propertyScrollingList
, 1, wxALL
|wxEXPAND
, buttonborder
);
499 mainsizer
->Add( m_middleSizer
, 1, wxEXPAND
);
501 // bottom row with buttons
503 if ((m_buttonFlags
& wxPROP_BUTTON_OK
) ||
504 (m_buttonFlags
& wxPROP_BUTTON_CLOSE
) ||
505 (m_buttonFlags
& wxPROP_BUTTON_CANCEL
) ||
506 (m_buttonFlags
& wxPROP_BUTTON_HELP
))
508 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
511 if (m_buttonFlags
& wxPROP_BUTTON_OK
)
513 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("OK"), wxPoint(-1, -1), largeButtonSize
);
514 m_windowCloseButton
->SetDefault();
515 m_windowCloseButton
->SetFocus();
516 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
518 else if (m_buttonFlags
& wxPROP_BUTTON_CLOSE
)
520 m_windowCloseButton
= new wxButton(panel
, wxID_OK
, _("Close"), wxPoint(-1, -1), largeButtonSize
);
521 bottomsizer
->Add( m_windowCloseButton
, 0, wxALL
, buttonborder
);
523 if (m_buttonFlags
& wxPROP_BUTTON_CANCEL
)
525 m_windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, _("Cancel"), wxPoint(-1, -1), largeButtonSize
);
526 bottomsizer
->Add( m_windowCancelButton
, 0, wxALL
, buttonborder
);
528 if (m_buttonFlags
& wxPROP_BUTTON_HELP
)
530 m_windowHelpButton
= new wxButton(panel
, wxID_HELP
, _("Help"), wxPoint(-1, -1), largeButtonSize
);
531 bottomsizer
->Add( m_windowHelpButton
, 0, wxALL
, buttonborder
);
534 mainsizer
->Add( bottomsizer
, 0, wxALIGN_RIGHT
| wxEXPAND
);
537 panel
->SetSizer( mainsizer
);
542 void wxPropertyListView::ShowTextControl(bool show
)
545 m_valueText
->Show(show
);
548 void wxPropertyListView::ShowListBoxControl(bool show
)
550 if (!m_valueList
) return;
552 m_valueList
->Show(show
);
554 if (m_buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
557 m_middleSizer
->Prepend( m_valueList
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 3 );
559 m_middleSizer
->Remove( 0 );
561 m_propertyWindow
->Layout();
565 void wxPropertyListView::EnableCheck(bool show
)
568 m_confirmButton
->Enable(show
);
571 void wxPropertyListView::EnableCross(bool show
)
574 m_cancelButton
->Enable(show
);
577 bool wxPropertyListView::OnClose()
579 // Retrieve the value if any
580 wxCommandEvent event
;
587 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
589 if (m_currentProperty
&& m_currentValidator
)
591 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
594 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
596 listValidator
->OnValueListSelect(m_currentProperty
, this, m_propertyWindow
);
600 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
602 // Retrieve the value if any
605 m_managedWindow
->Close(TRUE
);
608 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
610 // SetReturnCode(wxID_CANCEL);
611 m_managedWindow
->Close(TRUE
);
612 sm_dialogCancelled
= TRUE
;
615 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
619 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
621 if (m_currentProperty
)
623 RetrieveProperty(m_currentProperty
);
627 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
629 if (m_currentProperty
&& m_currentValidator
)
631 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
634 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
636 // Revert to old value
637 listValidator
->OnDisplayValue(m_currentProperty
, this, m_propertyWindow
);
641 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
643 if (m_currentProperty
&& m_currentValidator
)
645 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
648 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
650 // Revert to old value
651 listValidator
->OnDoubleClick(m_currentProperty
, this, m_propertyWindow
);
655 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
657 if (m_currentProperty
&& m_currentValidator
)
659 if (!m_currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
662 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)m_currentValidator
;
664 listValidator
->OnEdit(m_currentProperty
, this, m_propertyWindow
);
668 void wxPropertyListView::OnText(wxCommandEvent
& event
)
670 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
676 // ----------------------------------------------------------------------------
677 // Property dialog box
678 // ----------------------------------------------------------------------------
680 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog
, wxDialog
)
682 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
683 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
684 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow
)
687 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
688 const wxString
& title
, const wxPoint
& pos
,
689 const wxSize
& size
, long style
, const wxString
& name
):
690 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
693 m_view
->AssociatePanel( ((wxPanel
*)this) );
694 m_view
->SetManagedWindow(this);
698 void wxPropertyListDialog::OnCloseWindow(wxCloseEvent
& event
)
702 SetReturnCode(wxID_CANCEL
);
713 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
715 SetReturnCode(wxID_CANCEL
);
719 void wxPropertyListDialog::OnDefaultAction(wxControl
*WXUNUSED(item
))
722 if (item == m_view->GetPropertyScrollingList())
723 view->OnDoubleClick();
727 // Extend event processing to search the view's event table
728 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
730 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
731 return wxEvtHandler::ProcessEvent(event
);
736 // ----------------------------------------------------------------------------
738 // ----------------------------------------------------------------------------
740 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel
, wxPanel
)
742 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
743 EVT_SIZE(wxPropertyListPanel::OnSize
)
746 wxPropertyListPanel::~wxPropertyListPanel()
750 void wxPropertyListPanel::OnDefaultAction(wxControl
*WXUNUSED(item
))
753 if (item == view->GetPropertyScrollingList())
754 view->OnDoubleClick();
758 // Extend event processing to search the view's event table
759 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
761 if ( !m_view
|| ! m_view
->ProcessEvent(event
) )
762 return wxEvtHandler::ProcessEvent(event
);
767 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
772 // ----------------------------------------------------------------------------
774 // ----------------------------------------------------------------------------
776 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame
, wxFrame
)
778 BEGIN_EVENT_TABLE(wxPropertyListFrame
, wxFrame
)
779 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow
)
782 void wxPropertyListFrame::OnCloseWindow(wxCloseEvent
& event
)
787 m_propertyPanel
->SetView(NULL
);
798 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
800 return new wxPropertyListPanel(v
, parent
);
803 bool wxPropertyListFrame::Initialize()
805 m_propertyPanel
= OnCreatePanel(this, m_view
);
808 m_view
->AssociatePanel(m_propertyPanel
);
809 m_view
->SetManagedWindow(this);
810 m_propertyPanel
->SetAutoLayout(TRUE
);
817 // ----------------------------------------------------------------------------
818 // Property list specific validator
819 // ----------------------------------------------------------------------------
821 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
823 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
825 // view->GetValueText()->Show(TRUE);
827 OnDisplayValue(property
, view
, parentWindow
);
832 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
834 wxString
s(view
->GetValueList()->GetStringSelection());
837 view
->GetValueText()->SetValue(s
);
838 view
->RetrieveProperty(property
);
843 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
845 // view->GetValueText()->Show(TRUE);
846 wxString
str(property
->GetValue().GetStringRepresentation());
848 view
->GetValueText()->SetValue(str
);
852 // Called when TICK is pressed or focus is lost or view wants to update
853 // the property list.
854 // Does the transferance from the property editing area to the property itself
855 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
857 if (!view
->GetValueText())
862 void wxPropertyListValidator::OnEdit(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
864 if (view
->GetDetailedEditing())
865 view
->EndDetailedEditing();
867 view
->BeginDetailedEditing();
870 bool wxPropertyListValidator::OnClearControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
872 if (view
->GetConfirmButton())
873 view
->GetConfirmButton()->Enable(FALSE
);
874 if (view
->GetCancelButton())
875 view
->GetCancelButton()->Enable(FALSE
);
876 if (view
->GetEditButton())
877 view
->GetEditButton()->Enable(FALSE
);
881 // ----------------------------------------------------------------------------
882 // Default validators
883 // ----------------------------------------------------------------------------
885 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
888 /// Real number validator
890 bool wxRealListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
892 if (m_realMin
== 0.0 && m_realMax
== 0.0)
895 if (!view
->GetValueText())
897 wxString
value(view
->GetValueText()->GetValue());
900 if (!StringToFloat(WXSTRINGCAST value
, &val
))
903 wxSprintf(buf
, wxT("Value %s is not a valid real number!"), value
.GetData());
904 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
908 if (val
< m_realMin
|| val
> m_realMax
)
911 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", m_realMin
, m_realMax
);
912 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
918 // Called when TICK is pressed or focus is lost or view wants to update
919 // the property list.
920 // Does the transferance from the property editing area to the property itself
921 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
923 if (!view
->GetValueText())
926 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
929 wxString
value(view
->GetValueText()->GetValue());
930 float f
= (float)wxAtof(value
.GetData());
931 property
->GetValue() = f
;
935 bool wxRealListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
937 if (view
->GetConfirmButton())
938 view
->GetConfirmButton()->Enable(TRUE
);
939 if (view
->GetCancelButton())
940 view
->GetCancelButton()->Enable(TRUE
);
941 if (view
->GetEditButton())
942 view
->GetEditButton()->Enable(FALSE
);
943 if (view
->GetValueText())
944 view
->GetValueText()->Enable(TRUE
);
949 /// Integer validator
951 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
953 bool wxIntegerListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
955 if (m_integerMin
== 0 && m_integerMax
== 0)
958 if (!view
->GetValueText())
960 wxString
value(view
->GetValueText()->GetValue());
963 if (!StringToLong(WXSTRINGCAST value
, &val
))
966 wxSprintf(buf
, wxT("Value %s is not a valid integer!"), value
.GetData());
967 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
970 if (val
< m_integerMin
|| val
> m_integerMax
)
973 wxSprintf(buf
, wxT("Value must be an integer between %ld and %ld!"), m_integerMin
, m_integerMax
);
974 wxMessageBox(buf
, wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
980 // Called when TICK is pressed or focus is lost or view wants to update
981 // the property list.
982 // Does the transferance from the property editing area to the property itself
983 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
985 if (!view
->GetValueText())
988 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
991 wxString
value(view
->GetValueText()->GetValue());
992 long val
= (long)wxAtoi(value
.GetData());
993 property
->GetValue() = (long)val
;
997 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
999 if (view
->GetConfirmButton())
1000 view
->GetConfirmButton()->Enable(TRUE
);
1001 if (view
->GetCancelButton())
1002 view
->GetCancelButton()->Enable(TRUE
);
1003 if (view
->GetEditButton())
1004 view
->GetEditButton()->Enable(FALSE
);
1005 if (view
->GetValueText())
1006 view
->GetValueText()->Enable(TRUE
);
1011 /// boolean validator
1013 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1015 bool wxBoolListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1017 if (!view
->GetValueText())
1019 wxString
value(view
->GetValueText()->GetValue());
1020 if (value
!= wxT("True") && value
!= wxT("False"))
1022 wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1028 // Called when TICK is pressed or focus is lost or view wants to update
1029 // the property list.
1030 // Does the transferance from the property editing area to the property itself
1031 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1033 if (!view
->GetValueText())
1036 if (wxStrlen(view
->GetValueText()->GetValue()) == 0)
1039 wxString
value(view
->GetValueText()->GetValue());
1040 bool boolValue
= FALSE
;
1041 if (value
== wxT("True"))
1045 property
->GetValue() = (bool)boolValue
;
1049 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1051 if (!view
->GetValueText())
1053 wxString
str(property
->GetValue().GetStringRepresentation());
1055 view
->GetValueText()->SetValue(str
);
1057 if (view
->GetValueList()->IsShown())
1059 view
->GetValueList()->SetStringSelection(str
);
1064 bool wxBoolListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1066 if (view
->GetConfirmButton())
1067 view
->GetConfirmButton()->Enable(FALSE
);
1068 if (view
->GetCancelButton())
1069 view
->GetCancelButton()->Enable(FALSE
);
1070 if (view
->GetEditButton())
1071 view
->GetEditButton()->Enable(TRUE
);
1072 if (view
->GetValueText())
1073 view
->GetValueText()->Enable(FALSE
);
1077 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1079 if (view
->GetValueList())
1081 view
->ShowListBoxControl(TRUE
);
1082 view
->GetValueList()->Enable(TRUE
);
1084 view
->GetValueList()->Append(wxT("True"));
1085 view
->GetValueList()->Append(wxT("False"));
1086 wxChar
*currentString
= copystring(view
->GetValueText()->GetValue());
1087 view
->GetValueList()->SetStringSelection(currentString
);
1088 delete[] currentString
;
1093 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1095 if (view
->GetValueList())
1097 view
->GetValueList()->Clear();
1098 view
->ShowListBoxControl(FALSE
);
1099 view
->GetValueList()->Enable(FALSE
);
1104 // Called when the property is double clicked. Extra functionality can be provided,
1105 // cycling through possible values.
1106 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1108 if (!view
->GetValueText())
1110 if (property
->GetValue().BoolValue())
1111 property
->GetValue() = (bool)FALSE
;
1113 property
->GetValue() = (bool)TRUE
;
1114 view
->DisplayProperty(property
);
1115 view
->UpdatePropertyDisplayInList(property
);
1116 view
->OnPropertyChanged(property
);
1121 /// String validator
1123 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1125 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1126 wxPropertyListValidator(flags
)
1129 // If no constraint, we just allow the string to be edited.
1130 if (!m_strings
&& ((m_validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1131 m_validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1134 bool wxStringListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*parentWindow
)
1139 if (!view
->GetValueText())
1141 wxString
value(view
->GetValueText()->GetValue());
1143 if (!m_strings
->Member(value
.GetData()))
1145 wxString
s("Value ");
1146 s
+= value
.GetData();
1147 s
+= " is not valid.";
1148 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1154 // Called when TICK is pressed or focus is lost or view wants to update
1155 // the property list.
1156 // Does the transferance from the property editing area to the property itself
1157 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1159 if (!view
->GetValueText())
1161 wxString
value(view
->GetValueText()->GetValue());
1162 property
->GetValue() = value
;
1166 // Called when TICK is pressed or focus is lost or view wants to update
1167 // the property list.
1168 // Does the transferance from the property editing area to the property itself
1169 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1171 if (!view
->GetValueText())
1173 wxString
str(property
->GetValue().GetStringRepresentation());
1174 view
->GetValueText()->SetValue(str
);
1175 if (m_strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1177 view
->GetValueList()->SetStringSelection(str
);
1182 bool wxStringListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1187 if (view
->GetEditButton())
1188 view
->GetEditButton()->Enable(FALSE
);
1189 if (view
->GetConfirmButton())
1190 view
->GetConfirmButton()->Enable(TRUE
);
1191 if (view
->GetCancelButton())
1192 view
->GetCancelButton()->Enable(TRUE
);
1193 if (view
->GetValueText())
1194 view
->GetValueText()->Enable(TRUE
);
1199 if (view
->GetValueText())
1200 view
->GetValueText()->Enable(FALSE
);
1202 if (view
->GetEditButton())
1203 view
->GetEditButton()->Enable(TRUE
);
1205 if (view
->GetConfirmButton())
1206 view
->GetConfirmButton()->Enable(FALSE
);
1207 if (view
->GetCancelButton())
1208 view
->GetCancelButton()->Enable(FALSE
);
1212 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1214 if (view
->GetValueList())
1216 view
->ShowListBoxControl(TRUE
);
1217 view
->GetValueList()->Enable(TRUE
);
1218 wxNode
*node
= m_strings
->First();
1221 wxChar
*s
= (wxChar
*)node
->Data();
1222 view
->GetValueList()->Append(s
);
1223 node
= node
->Next();
1225 wxChar
*currentString
= property
->GetValue().StringValue();
1226 view
->GetValueList()->SetStringSelection(currentString
);
1231 bool wxStringListValidator::OnClearDetailControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1238 if (view
->GetValueList())
1240 view
->GetValueList()->Clear();
1241 view
->ShowListBoxControl(FALSE
);
1242 view
->GetValueList()->Enable(FALSE
);
1247 // Called when the property is double clicked. Extra functionality can be provided,
1248 // cycling through possible values.
1249 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1251 if (!view
->GetValueText())
1256 wxNode
*node
= m_strings
->First();
1257 wxChar
*currentString
= property
->GetValue().StringValue();
1260 wxChar
*s
= (wxChar
*)node
->Data();
1261 if (wxStrcmp(s
, currentString
) == 0)
1263 wxChar
*nextString
= NULL
;
1265 nextString
= (wxChar
*)node
->Next()->Data();
1267 nextString
= (wxChar
*)m_strings
->First()->Data();
1268 property
->GetValue() = wxString(nextString
);
1269 view
->DisplayProperty(property
);
1270 view
->UpdatePropertyDisplayInList(property
);
1271 view
->OnPropertyChanged(property
);
1274 else node
= node
->Next();
1280 /// Filename validator
1282 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1284 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1285 wxPropertyListValidator(flags
), m_filenameWildCard(wildcard
), m_filenameMessage(message
)
1289 wxFilenameListValidator::~wxFilenameListValidator()
1293 bool wxFilenameListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1298 // Called when TICK is pressed or focus is lost or view wants to update
1299 // the property list.
1300 // Does the transferance from the property editing area to the property itself
1301 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1303 if (!view
->GetValueText())
1305 wxString
value(view
->GetValueText()->GetValue());
1306 property
->GetValue() = value
;
1310 // Called when TICK is pressed or focus is lost or view wants to update
1311 // the property list.
1312 // Does the transferance from the property editing area to the property itself
1313 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1315 if (!view
->GetValueText())
1317 wxString
str(property
->GetValue().GetStringRepresentation());
1318 view
->GetValueText()->SetValue(str
);
1322 // Called when the property is double clicked. Extra functionality can be provided,
1323 // cycling through possible values.
1324 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1326 if (!view
->GetValueText())
1328 OnEdit(property
, view
, parentWindow
);
1332 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1334 if (view
->GetConfirmButton())
1335 view
->GetConfirmButton()->Enable(TRUE
);
1336 if (view
->GetCancelButton())
1337 view
->GetCancelButton()->Enable(TRUE
);
1338 if (view
->GetEditButton())
1339 view
->GetEditButton()->Enable(TRUE
);
1340 if (view
->GetValueText())
1341 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1345 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1347 if (!view
->GetValueText())
1350 wxString s
= wxFileSelector(
1351 m_filenameMessage
.GetData(),
1352 wxPathOnly(property
->GetValue().StringValue()),
1353 wxFileNameFromPath(property
->GetValue().StringValue()),
1355 m_filenameWildCard
.GetData(),
1360 property
->GetValue() = s
;
1361 view
->DisplayProperty(property
);
1362 view
->UpdatePropertyDisplayInList(property
);
1363 view
->OnPropertyChanged(property
);
1368 /// Colour validator
1370 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1372 wxColourListValidator::wxColourListValidator(long flags
):
1373 wxPropertyListValidator(flags
)
1377 wxColourListValidator::~wxColourListValidator()
1381 bool wxColourListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1386 // Called when TICK is pressed or focus is lost or view wants to update
1387 // the property list.
1388 // Does the transferance from the property editing area to the property itself
1389 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1391 if (!view
->GetValueText())
1393 wxString
value(view
->GetValueText()->GetValue());
1395 property
->GetValue() = value
;
1399 // Called when TICK is pressed or focus is lost or view wants to update
1400 // the property list.
1401 // Does the transferance from the property editing area to the property itself
1402 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1404 if (!view
->GetValueText())
1406 wxString
str(property
->GetValue().GetStringRepresentation());
1407 view
->GetValueText()->SetValue(str
);
1411 // Called when the property is double clicked. Extra functionality can be provided,
1412 // cycling through possible values.
1413 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1415 if (!view
->GetValueText())
1417 OnEdit(property
, view
, parentWindow
);
1421 bool wxColourListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1423 if (view
->GetConfirmButton())
1424 view
->GetConfirmButton()->Enable(TRUE
);
1425 if (view
->GetCancelButton())
1426 view
->GetCancelButton()->Enable(TRUE
);
1427 if (view
->GetEditButton())
1428 view
->GetEditButton()->Enable(TRUE
);
1429 if (view
->GetValueText())
1430 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1434 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1436 if (!view
->GetValueText())
1439 wxChar
*s
= property
->GetValue().StringValue();
1446 g
= wxHexToDec(s
+2);
1447 b
= wxHexToDec(s
+4);
1450 wxColour
col(r
,g
,b
);
1453 data
.SetChooseFull(TRUE
);
1454 data
.SetColour(col
);
1456 for (int i
= 0; i
< 16; i
++)
1458 wxColour
colour(i
*16, i
*16, i
*16);
1459 data
.SetCustomColour(i
, colour
);
1462 wxColourDialog
dialog(parentWindow
, &data
);
1463 if (dialog
.ShowModal() != wxID_CANCEL
)
1465 wxColourData retData
= dialog
.GetColourData();
1466 col
= retData
.GetColour();
1469 wxDecToHex(col
.Red(), buf
);
1470 wxDecToHex(col
.Green(), buf
+2);
1471 wxDecToHex(col
.Blue(), buf
+4);
1473 property
->GetValue() = wxString(buf
);
1474 view
->DisplayProperty(property
);
1475 view
->UpdatePropertyDisplayInList(property
);
1476 view
->OnPropertyChanged(property
);
1481 /// List of strings validator. For this we need more user interface than
1482 /// we get with a property list; so create a new dialog for editing the list.
1484 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1486 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1487 wxPropertyListValidator(flags
)
1491 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1493 // No constraints for an arbitrary, user-editable list of strings.
1497 // Called when TICK is pressed or focus is lost or view wants to update
1498 // the property list.
1499 // Does the transferance from the property editing area to the property itself.
1500 // In this case, the user cannot directly edit the string list.
1501 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
1506 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1508 if (!view
->GetValueText())
1510 wxString
str(property
->GetValue().GetStringRepresentation());
1511 view
->GetValueText()->SetValue(str
);
1515 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
1517 if (view
->GetEditButton())
1518 view
->GetEditButton()->Enable(TRUE
);
1519 if (view
->GetValueText())
1520 view
->GetValueText()->Enable(FALSE
);
1522 if (view
->GetConfirmButton())
1523 view
->GetConfirmButton()->Enable(FALSE
);
1524 if (view
->GetCancelButton())
1525 view
->GetCancelButton()->Enable(FALSE
);
1529 // Called when the property is double clicked. Extra functionality can be provided,
1530 // cycling through possible values.
1531 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1533 OnEdit(property
, view
, parentWindow
);
1537 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1539 // Convert property value to a list of strings for editing
1540 wxStringList
*stringList
= new wxStringList
;
1542 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1545 wxChar
*s
= expr
->StringValue();
1548 expr
= expr
->GetNext();
1551 wxString
title(wxT("Editing "));
1552 title
+= property
->GetName();
1554 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1556 wxPropertyValue
& oldValue
= property
->GetValue();
1557 oldValue
.ClearList();
1558 wxNode
*node
= stringList
->First();
1561 wxChar
*s
= (wxChar
*)node
->Data();
1562 oldValue
.Append(new wxPropertyValue(s
));
1564 node
= node
->Next();
1567 view
->DisplayProperty(property
);
1568 view
->UpdatePropertyDisplayInList(property
);
1569 view
->OnPropertyChanged(property
);
1574 class wxPropertyStringListEditorDialog
: public wxDialog
1577 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1578 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1579 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1580 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1582 m_stringList
= NULL
;
1583 m_stringText
= NULL
;
1585 sm_dialogCancelled
= FALSE
;
1586 m_currentSelection
= -1;
1588 ~wxPropertyStringListEditorDialog(void) {}
1589 void OnCloseWindow(wxCloseEvent
& event
);
1590 void SaveCurrentSelection(void);
1591 void ShowCurrentSelection(void);
1593 void OnOK(wxCommandEvent
& event
);
1594 void OnCancel(wxCommandEvent
& event
);
1595 void OnAdd(wxCommandEvent
& event
);
1596 void OnDelete(wxCommandEvent
& event
);
1597 void OnStrings(wxCommandEvent
& event
);
1598 void OnText(wxCommandEvent
& event
);
1601 wxStringList
* m_stringList
;
1602 wxListBox
* m_listBox
;
1603 wxTextCtrl
* m_stringText
;
1604 static bool sm_dialogCancelled
;
1605 int m_currentSelection
;
1606 DECLARE_EVENT_TABLE()
1609 #define wxID_PROP_SL_ADD 3000
1610 #define wxID_PROP_SL_DELETE 3001
1611 #define wxID_PROP_SL_STRINGS 3002
1612 #define wxID_PROP_SL_TEXT 3003
1614 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1615 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1616 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1617 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1618 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1619 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1620 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1621 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow
)
1624 class wxPropertyStringListEditorText
: public wxTextCtrl
1627 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1628 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1629 long windowStyle
= 0, const wxString
& name
= "text"):
1630 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1635 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1636 dialog
->SaveCurrentSelection();
1640 bool wxPropertyStringListEditorDialog::sm_dialogCancelled
= FALSE
;
1642 // Edit the string list.
1643 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
)
1645 int largeButtonWidth
= 60;
1646 int largeButtonHeight
= 25;
1648 wxBeginBusyCursor();
1649 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1650 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1652 dialog
->m_stringList
= stringList
;
1654 dialog
->m_listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1655 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL
, wxLB_SINGLE
);
1657 dialog
->m_stringText
= new wxPropertyStringListEditorText(dialog
,
1658 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1659 wxSize(300, -1), wxPROCESS_ENTER
);
1660 dialog
->m_stringText
->Enable(FALSE
);
1662 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1663 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1664 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1665 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
1668 okButton
->SetDefault();
1671 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
1673 c
->top
.SameAs (dialog
, wxTop
, 2);
1674 c
->left
.SameAs (dialog
, wxLeft
, 2);
1675 c
->right
.SameAs (dialog
, wxRight
, 2);
1676 c
->bottom
.SameAs (dialog
->m_stringText
, wxTop
, 2);
1677 dialog
->m_listBox
->SetConstraints(c
);
1679 c
= new wxLayoutConstraints
;
1680 c
->left
.SameAs (dialog
, wxLeft
, 2);
1681 c
->right
.SameAs (dialog
, wxRight
, 2);
1682 c
->bottom
.SameAs (addButton
, wxTop
, 2);
1684 dialog
->m_stringText
->SetConstraints(c
);
1686 c
= new wxLayoutConstraints
;
1687 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1688 c
->left
.SameAs (dialog
, wxLeft
, 2);
1691 addButton
->SetConstraints(c
);
1693 c
= new wxLayoutConstraints
;
1694 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1695 c
->left
.SameAs (addButton
, wxRight
, 2);
1698 deleteButton
->SetConstraints(c
);
1700 c
= new wxLayoutConstraints
;
1701 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1702 c
->right
.SameAs (dialog
, wxRight
, 2);
1705 cancelButton
->SetConstraints(c
);
1707 c
= new wxLayoutConstraints
;
1708 c
->bottom
.SameAs (dialog
, wxBottom
, 2);
1709 c
->right
.SameAs (cancelButton
, wxLeft
, 2);
1712 okButton
->SetConstraints(c
);
1714 wxNode
*node
= stringList
->First();
1717 char *str
= (char *)node
->Data();
1718 // Save node as client data for each listbox item
1719 dialog
->m_listBox
->Append(str
, (char *)node
);
1720 node
= node
->Next();
1723 dialog
->SetClientSize(310, 305);
1726 dialog
->Centre(wxBOTH
);
1728 if (dialog
->ShowModal() == wxID_CANCEL
)
1735 * String list editor callbacks
1739 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1741 int sel
= m_listBox
->GetSelection();
1744 m_currentSelection
= sel
;
1746 ShowCurrentSelection();
1750 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1752 int sel
= m_listBox
->GetSelection();
1756 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(sel
);
1760 m_listBox
->Delete(sel
);
1761 delete[] (wxChar
*)node
->Data();
1763 m_currentSelection
= -1;
1764 m_stringText
->SetValue("");
1767 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1769 SaveCurrentSelection();
1771 wxChar
*initialText
= wxT("");
1772 wxNode
*node
= m_stringList
->Add(initialText
);
1773 m_listBox
->Append(initialText
, (void *)node
);
1774 m_currentSelection
= m_stringList
->Number() - 1;
1775 m_listBox
->SetSelection(m_currentSelection
);
1776 ShowCurrentSelection();
1777 m_stringText
->SetFocus();
1780 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1782 SaveCurrentSelection();
1788 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1790 sm_dialogCancelled
= TRUE
;
1791 EndModal(wxID_CANCEL
);
1796 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1798 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
1800 SaveCurrentSelection();
1805 wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
1807 SaveCurrentSelection();
1812 void wxPropertyStringListEditorDialog::SaveCurrentSelection()
1814 if (m_currentSelection
== -1)
1817 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1821 wxString
txt(m_stringText
->GetValue());
1823 delete[] (char *)node
->Data();
1824 node
->SetData((wxObject
*)copystring(txt
));
1826 m_listBox
->SetString(m_currentSelection
, (char *)node
->Data());
1829 void wxPropertyStringListEditorDialog::ShowCurrentSelection()
1831 if (m_currentSelection
== -1)
1833 m_stringText
->SetValue("");
1836 wxNode
*node
= (wxNode
*)m_listBox
->wxListBox::GetClientData(m_currentSelection
);
1837 char *txt
= (char *)node
->Data();
1838 m_stringText
->SetValue(txt
);
1839 m_stringText
->Enable(TRUE
);
1842 // ----------------------------------------------------------------------------
1844 // ----------------------------------------------------------------------------
1847 static wxBitmap
*GetTickBitmap()
1849 static wxBitmap
* s_tickBitmap
= (wxBitmap
*) NULL
;
1850 static bool s_loaded
= FALSE
;
1854 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1856 #if defined(__WXMSW__) || defined(__WXPM__)
1857 s_tickBitmap
= new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE
);
1859 s_tickBitmap
= new wxBitmap( tick_xpm
);
1863 return s_tickBitmap
;
1866 static wxBitmap
*GetCrossBitmap()
1868 static wxBitmap
* s_crossBitmap
= (wxBitmap
*) NULL
;
1869 static bool s_loaded
= FALSE
;
1873 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1875 #if defined(__WXMSW__) || defined(__WXPM__)
1876 s_crossBitmap
= new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE
);
1878 s_crossBitmap
= new wxBitmap( cross_xpm
);
1882 return s_crossBitmap
;
1885 #endif // wxUSE_PROPSHEET