1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "proplist.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
32 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
35 #include <strstream.h>
38 #include "wx/window.h"
41 #include "wx/colordlg.h"
45 * Property text edit control
48 IMPLEMENT_CLASS(wxPropertyTextEdit
, wxTextCtrl
)
50 wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
,
51 const wxWindowID id
, const wxString
& value
,
52 const wxPoint
& pos
, const wxSize
& size
,
53 long style
, const wxString
& name
):
54 wxTextCtrl(parent
, id
, value
, pos
, size
, style
, wxDefaultValidator
, name
)
59 void wxPropertyTextEdit::OnSetFocus(void)
63 void wxPropertyTextEdit::OnKillFocus(void)
71 IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView
, wxPropertyView
)
73 BEGIN_EVENT_TABLE(wxPropertyListView
, wxPropertyView
)
74 EVT_BUTTON(wxID_OK
, wxPropertyListView::OnOk
)
75 EVT_BUTTON(wxID_CANCEL
, wxPropertyListView::OnCancel
)
76 EVT_BUTTON(wxID_HELP
, wxPropertyListView::OnHelp
)
77 EVT_BUTTON(wxID_PROP_CROSS
, wxPropertyListView::OnCross
)
78 EVT_BUTTON(wxID_PROP_CHECK
, wxPropertyListView::OnCheck
)
79 EVT_BUTTON(wxID_PROP_EDIT
, wxPropertyListView::OnEdit
)
80 EVT_TEXT_ENTER(wxID_PROP_TEXT
, wxPropertyListView::OnText
)
81 EVT_LISTBOX(wxID_PROP_SELECT
, wxPropertyListView::OnPropertySelect
)
82 EVT_COMMAND(wxID_PROP_SELECT
, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxPropertyListView::OnPropertyDoubleClick
)
83 EVT_LISTBOX(wxID_PROP_VALUE_SELECT
, wxPropertyListView::OnValueListSelect
)
86 bool wxPropertyListView::dialogCancelled
= FALSE
;
87 wxBitmap
*wxPropertyListView::tickBitmap
= NULL
;
88 wxBitmap
*wxPropertyListView::crossBitmap
= NULL
;
90 wxPropertyListView::wxPropertyListView(wxPanel
*propPanel
, long flags
):wxPropertyView(flags
)
92 propertyScrollingList
= NULL
;
98 propertyWindow
= propPanel
;
101 windowCloseButton
= NULL
;
102 windowCancelButton
= NULL
;
103 windowHelpButton
= NULL
;
105 detailedEditing
= FALSE
;
108 wxPropertyListView::~wxPropertyListView(void)
118 void wxPropertyListView::ShowView(wxPropertySheet
*ps
, wxPanel
*panel
)
122 AssociatePanel(panel
);
125 UpdatePropertyList();
129 // Update this view of the viewed object, called e.g. by
130 // the object itself.
131 bool wxPropertyListView::OnUpdateView(void)
136 bool wxPropertyListView::UpdatePropertyList(bool clearEditArea
)
138 if (!propertyScrollingList
|| !propertySheet
)
141 propertyScrollingList
->Clear();
145 valueText
->SetValue("");
147 wxNode
*node
= propertySheet
->GetProperties().First();
149 // Should sort them... later...
152 wxProperty
*property
= (wxProperty
*)node
->Data();
153 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
154 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
156 propertyScrollingList
->Append(paddedString
.GetData(), (char *)property
);
162 bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty
*property
)
164 if (!propertyScrollingList
|| !propertySheet
)
167 int currentlySelected
= propertyScrollingList
->GetSelection();
169 wxString
stringValueRepr(property
->GetValue().GetStringRepresentation());
170 wxString
paddedString(MakeNameValueString(property
->GetName(), stringValueRepr
));
171 int sel
= FindListIndexForProperty(property
);
175 // Don't update the listbox unnecessarily because it can cause
178 if (paddedString
!= propertyScrollingList
->GetString(sel
))
179 propertyScrollingList
->SetString(sel
, paddedString
.GetData());
182 // UpdatePropertyList(FALSE);
185 if (currentlySelected
> -1)
186 propertyScrollingList
->SetSelection(currentlySelected
);
191 // Find the wxListBox index corresponding to this property
192 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
194 int n
= propertyScrollingList
->Number();
195 for (int i
= 0; i
< n
; i
++)
197 if (property
== (wxProperty
*)propertyScrollingList
->wxListBox::GetClientData(i
))
203 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
205 wxString
theString(name
);
208 int padWith
= nameWidth
- theString
.Length();
212 if (GetFlags() & wxPROP_SHOWVALUES
)
214 // Want to pad with spaces
215 theString
.Append(' ', padWith
);
222 // Select and show string representation in validator the given
223 // property. NULL resets to show no property.
224 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
228 EndShowingProperty(currentProperty
);
229 currentProperty
= NULL
;
233 valueText
->SetValue("");
237 currentProperty
= property
;
238 BeginShowingProperty(property
);
242 int sel
= FindListIndexForProperty(property
);
244 propertyScrollingList
->SetSelection(sel
);
249 // Find appropriate validator and load property into value controls
250 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
252 currentValidator
= FindPropertyValidator(property
);
253 if (!currentValidator
)
256 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
259 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
261 listValidator
->OnPrepareControls(property
, this, propertyWindow
);
262 DisplayProperty(property
);
266 // Find appropriate validator and unload property from value controls
267 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
269 if (!currentValidator
)
272 RetrieveProperty(property
);
274 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
277 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
279 listValidator
->OnClearControls(property
, this, propertyWindow
);
282 listValidator
->OnClearDetailControls(property
, this, propertyWindow
);
283 detailedEditing
= FALSE
;
288 void wxPropertyListView::BeginDetailedEditing(void)
290 if (!currentValidator
)
292 if (!currentProperty
)
296 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
298 if (!currentProperty
->IsEnabled())
301 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
303 if (listValidator
->OnPrepareDetailControls(currentProperty
, this, propertyWindow
))
304 detailedEditing
= TRUE
;
307 void wxPropertyListView::EndDetailedEditing(void)
309 if (!currentValidator
)
311 if (!currentProperty
)
314 RetrieveProperty(currentProperty
);
316 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
319 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
323 listValidator
->OnClearDetailControls(currentProperty
, this, propertyWindow
);
324 detailedEditing
= FALSE
;
328 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
330 if (!currentValidator
)
333 if (((currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
334 valueText
->SetEditable(FALSE
);
336 valueText
->SetEditable(TRUE
);
338 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
341 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
343 listValidator
->OnDisplayValue(property
, this, propertyWindow
);
347 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
349 if (!currentValidator
)
351 if (!property
->IsEnabled())
354 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
357 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
359 if (listValidator
->OnCheckValue(property
, this, propertyWindow
))
361 if (listValidator
->OnRetrieveValue(property
, this, propertyWindow
))
363 UpdatePropertyDisplayInList(property
);
364 OnPropertyChanged(property
);
369 // Revert to old value
370 listValidator
->OnDisplayValue(property
, this, propertyWindow
);
376 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
381 // Called by the listbox callback
382 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
384 int sel
= propertyScrollingList
->GetSelection();
387 wxProperty
*newSel
= (wxProperty
*)propertyScrollingList
->wxListBox::GetClientData(sel
);
388 if (newSel
&& newSel
!= currentProperty
)
390 ShowProperty(newSel
, FALSE
);
395 bool wxPropertyListView::CreateControls(void)
397 wxPanel
*panel
= (wxPanel
*)propertyWindow
;
399 int largeButtonWidth
= 60;
400 int largeButtonHeight
= 25;
402 int smallButtonWidth
= 25;
403 int smallButtonHeight
= 20;
405 // XView must be allowed to choose its own sized buttons
407 largeButtonWidth
= -1;
408 largeButtonHeight
= -1;
410 smallButtonWidth
= -1;
411 smallButtonHeight
= -1;
420 wxWindow
*leftMostWindow
= panel
;
421 wxWindow
*topMostWindow
= panel
;
422 wxWindow
*rightMostWindow
= panel
;
424 wxSystemSettings settings
;
425 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
428 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
430 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
433 // May need to be changed in future to eliminate clashes with app.
434 panel
->SetClientData((char *)this);
436 // These buttons are at the bottom of the window, but create them now
437 // so the constraints are evaluated in the correct order
438 if (buttonFlags
& wxPROP_BUTTON_OK
)
440 windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
441 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
442 windowCloseButton
->SetDefault();
443 windowCloseButton
->SetFocus();
445 else if (buttonFlags
& wxPROP_BUTTON_CLOSE
)
447 windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
448 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
450 if (buttonFlags
& wxPROP_BUTTON_CANCEL
)
452 windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
453 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
455 if (buttonFlags
& wxPROP_BUTTON_HELP
)
457 windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
458 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
461 if (windowCloseButton
)
463 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
465 c1
->left
.SameAs (panel
, wxLeft
, 2);
466 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
469 windowCloseButton
->SetConstraints(c1
);
470 leftMostWindow
= windowCloseButton
;
472 if (windowCancelButton
)
474 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
476 c2
->right
.SameAs (panel
, wxRight
, 2);
477 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
480 windowCancelButton
->SetConstraints(c2
);
481 leftMostWindow
= windowCancelButton
;
483 if (windowHelpButton
)
485 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
486 if (leftMostWindow
== panel
)
487 c2
->left
.SameAs (panel
, wxLeft
, 2);
489 c2
->left
.RightOf (leftMostWindow
, 2);
491 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
494 windowHelpButton
->SetConstraints(c2
);
495 leftMostWindow
= windowHelpButton
;
498 if (buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
504 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
505 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
506 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
519 if (tickBitmap && crossBitmap)
521 confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
522 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
523 cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
524 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
529 confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
530 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
531 cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
532 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
535 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
536 c
->left
.SameAs (panel
, wxLeft
, 2);
538 if (windowCloseButton)
539 c->top.Below (windowCloseButton, 2);
542 c
->top
.SameAs (panel
, wxTop
, 2);
547 cancelButton
->SetConstraints(c
);
549 c
= new wxLayoutConstraints
;
550 c
->left
.RightOf (cancelButton
, 2);
551 c
->top
.SameAs (cancelButton
, wxTop
, 0);
555 confirmButton
->SetConstraints(c
);
557 cancelButton
->Enable(FALSE
);
558 confirmButton
->Enable(FALSE
);
561 if (buttonFlags
& wxPROP_PULLDOWN
)
563 editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
564 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
565 editButton
->Enable(FALSE
);
566 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
569 if (windowCloseButton)
570 c->top.Below (windowCloseButton, 2);
573 c
->top
.SameAs (panel
, wxTop
, 2);
575 c
->right
.SameAs (panel
, wxRight
, 2);
578 editButton
->SetConstraints(c
);
581 valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
582 valueText
->Enable(FALSE
);
584 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
587 c
->left
.RightOf (confirmButton
, 2);
589 c
->left
.SameAs (panel
, wxLeft
, 2);
591 if (windowCloseButton)
592 c->top.Below (windowCloseButton, 2);
595 c
->top
.SameAs (panel
, wxTop
, 2);
598 c
->right
.LeftOf (editButton
, 2);
600 c
->right
.SameAs (panel
, wxRight
, 2);
603 valueText
->SetConstraints(c
);
605 valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
606 valueList
->Show(FALSE
);
608 c
= new wxLayoutConstraints
;
610 c
->left
.SameAs (panel
, wxLeft
, 2);
611 c
->top
.Below (valueText
, 2);
612 c
->right
.SameAs (panel
, wxRight
, 2);
613 c
->height
.Absolute(60);
615 valueList
->SetConstraints(c
);
617 propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
618 wxPoint(-1, -1), wxSize(300, 300));
619 propertyScrollingList
->SetFont(boringFont
);
621 c
= new wxLayoutConstraints
;
623 c
->left
.SameAs (panel
, wxLeft
, 2);
625 if (buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
626 c
->top
.Below (valueText
, 2);
628 c
->top
.Below (valueList
, 2);
630 c
->right
.SameAs (panel
, wxRight
, 2);
632 if (windowCloseButton
)
633 c
->bottom
.Above (windowCloseButton
, -2);
635 c
->bottom
.SameAs (panel
, wxBottom
, 2);
637 propertyScrollingList
->SetConstraints(c
);
640 // Note: if this is called now, it causes a GPF.
647 void wxPropertyListView::ShowTextControl(bool show
)
650 valueText
->Show(show
);
653 void wxPropertyListView::ShowListBoxControl(bool show
)
657 valueList
->Show(show
);
658 if (buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
660 wxLayoutConstraints
*constraints
= propertyScrollingList
->GetConstraints();
665 constraints
->top
.Below(valueList
, 2);
666 // Maintain back-pointer so when valueList is deleted,
667 // any reference to it from this window is removed.
668 valueList
->AddConstraintReference(propertyScrollingList
);
672 constraints
->top
.Below(valueText
, 2);
673 valueText
->AddConstraintReference(propertyScrollingList
);
675 propertyWindow
->Layout();
681 void wxPropertyListView::EnableCheck(bool show
)
684 confirmButton
->Enable(show
);
687 void wxPropertyListView::EnableCross(bool show
)
690 cancelButton
->Enable(show
);
693 bool wxPropertyListView::OnClose(void)
695 // Retrieve the value if any
696 wxCommandEvent event
;
703 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
705 if (currentProperty
&& currentValidator
)
707 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
710 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
712 listValidator
->OnValueListSelect(currentProperty
, this, propertyWindow
);
716 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
718 // Retrieve the value if any
721 managedWindow
->Close(TRUE
);
724 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
726 // SetReturnCode(wxID_CANCEL);
727 managedWindow
->Close(TRUE
);
728 dialogCancelled
= TRUE
;
731 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
735 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
739 RetrieveProperty(currentProperty
);
743 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
745 if (currentProperty
&& currentValidator
)
747 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
750 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
752 // Revert to old value
753 listValidator
->OnDisplayValue(currentProperty
, this, propertyWindow
);
757 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
759 if (currentProperty
&& currentValidator
)
761 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
764 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
766 // Revert to old value
767 listValidator
->OnDoubleClick(currentProperty
, this, propertyWindow
);
771 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
773 if (currentProperty
&& currentValidator
)
775 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
778 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
780 listValidator
->OnEdit(currentProperty
, this, propertyWindow
);
784 void wxPropertyListView::OnText(wxCommandEvent
& event
)
786 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
793 * Property dialog box
796 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
798 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
799 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
802 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
803 const wxString
& title
, const wxPoint
& pos
,
804 const wxSize
& size
, long style
, const wxString
& name
):
805 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
808 view
->AssociatePanel( ((wxPanel
*)this) );
809 view
->SetManagedWindow(this);
813 bool wxPropertyListDialog::OnClose(void)
817 SetReturnCode(wxID_CANCEL
);
826 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
828 SetReturnCode(wxID_CANCEL
);
832 void wxPropertyListDialog::OnDefaultAction(wxControl
*item
)
835 if (item == view->GetPropertyScrollingList())
836 view->OnDoubleClick();
840 // Extend event processing to search the view's event table
841 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
843 if ( !view
|| ! view
->ProcessEvent(event
) )
844 return wxEvtHandler::ProcessEvent(event
);
853 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
855 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
856 EVT_SIZE(wxPropertyListPanel::OnSize
)
859 wxPropertyListPanel::~wxPropertyListPanel()
863 void wxPropertyListPanel::OnDefaultAction(wxControl
*item
)
866 if (item == view->GetPropertyScrollingList())
867 view->OnDoubleClick();
871 // Extend event processing to search the view's event table
872 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
874 if ( !view
|| ! view
->ProcessEvent(event
) )
875 return wxEvtHandler::ProcessEvent(event
);
880 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
889 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
891 bool wxPropertyListFrame::OnClose(void)
896 propertyPanel
->SetView(NULL
);
905 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
907 return new wxPropertyListPanel(v
, parent
);
910 bool wxPropertyListFrame::Initialize(void)
912 propertyPanel
= OnCreatePanel(this, view
);
915 view
->AssociatePanel(propertyPanel
);
916 view
->SetManagedWindow(this);
917 propertyPanel
->SetAutoLayout(TRUE
);
925 * Property list specific validator
928 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
930 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
932 // view->GetValueText()->Show(TRUE);
934 OnDisplayValue(property
, view
, parentWindow
);
939 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
941 wxString
s(view
->GetValueList()->GetStringSelection());
944 view
->GetValueText()->SetValue(s
);
945 view
->RetrieveProperty(property
);
950 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
952 // view->GetValueText()->Show(TRUE);
953 wxString
str(property
->GetValue().GetStringRepresentation());
955 view
->GetValueText()->SetValue(str
.GetData());
959 // Called when TICK is pressed or focus is lost or view wants to update
960 // the property list.
961 // Does the transferance from the property editing area to the property itself
962 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
964 if (!view
->GetValueText())
969 void wxPropertyListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
971 if (view
->GetDetailedEditing())
972 view
->EndDetailedEditing();
974 view
->BeginDetailedEditing();
977 bool wxPropertyListValidator::OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
979 if (view
->GetConfirmButton())
980 view
->GetConfirmButton()->Enable(FALSE
);
981 if (view
->GetCancelButton())
982 view
->GetCancelButton()->Enable(FALSE
);
983 if (view
->GetEditButton())
984 view
->GetEditButton()->Enable(FALSE
);
992 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
995 /// Real number validator
997 bool wxRealListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
999 if (realMin
== 0.0 && realMax
== 0.0)
1002 if (!view
->GetValueText())
1004 wxString
value(view
->GetValueText()->GetValue());
1007 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1010 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
1011 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1015 if (val
< realMin
|| val
> realMax
)
1018 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", realMin
, realMax
);
1019 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1025 // Called when TICK is pressed or focus is lost or view wants to update
1026 // the property list.
1027 // Does the transferance from the property editing area to the property itself
1028 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1030 if (!view
->GetValueText())
1033 if (strlen(view
->GetValueText()->GetValue()) == 0)
1036 wxString
value(view
->GetValueText()->GetValue());
1037 float f
= (float)atof(value
.GetData());
1038 property
->GetValue() = f
;
1042 bool wxRealListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1044 if (view
->GetConfirmButton())
1045 view
->GetConfirmButton()->Enable(TRUE
);
1046 if (view
->GetCancelButton())
1047 view
->GetCancelButton()->Enable(TRUE
);
1048 if (view
->GetEditButton())
1049 view
->GetEditButton()->Enable(FALSE
);
1050 if (view
->GetValueText())
1051 view
->GetValueText()->Enable(TRUE
);
1056 /// Integer validator
1058 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1060 bool wxIntegerListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1062 if (integerMin
== 0 && integerMax
== 0)
1065 if (!view
->GetValueText())
1067 wxString
value(view
->GetValueText()->GetValue());
1070 if (!StringToLong(WXSTRINGCAST value
, &val
))
1073 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1074 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1077 if (val
< integerMin
|| val
> integerMax
)
1080 sprintf(buf
, "Value must be an integer between %ld and %ld!", integerMin
, integerMax
);
1081 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1087 // Called when TICK is pressed or focus is lost or view wants to update
1088 // the property list.
1089 // Does the transferance from the property editing area to the property itself
1090 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1092 if (!view
->GetValueText())
1095 if (strlen(view
->GetValueText()->GetValue()) == 0)
1098 wxString
value(view
->GetValueText()->GetValue());
1099 long val
= (long)atoi(value
.GetData());
1100 property
->GetValue() = (long)val
;
1104 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1106 if (view
->GetConfirmButton())
1107 view
->GetConfirmButton()->Enable(TRUE
);
1108 if (view
->GetCancelButton())
1109 view
->GetCancelButton()->Enable(TRUE
);
1110 if (view
->GetEditButton())
1111 view
->GetEditButton()->Enable(FALSE
);
1112 if (view
->GetValueText())
1113 view
->GetValueText()->Enable(TRUE
);
1118 /// boolean validator
1120 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1122 bool wxBoolListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1124 if (!view
->GetValueText())
1126 wxString
value(view
->GetValueText()->GetValue());
1127 if (value
!= "True" && value
!= "False")
1129 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1135 // Called when TICK is pressed or focus is lost or view wants to update
1136 // the property list.
1137 // Does the transferance from the property editing area to the property itself
1138 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1140 if (!view
->GetValueText())
1143 if (strlen(view
->GetValueText()->GetValue()) == 0)
1146 wxString
value(view
->GetValueText()->GetValue());
1147 bool boolValue
= FALSE
;
1148 if (value
== "True")
1152 property
->GetValue() = (bool)boolValue
;
1156 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1158 if (!view
->GetValueText())
1160 wxString
str(property
->GetValue().GetStringRepresentation());
1162 view
->GetValueText()->SetValue(str
.GetData());
1163 view
->GetValueList()->SetStringSelection(str
.GetData());
1167 bool wxBoolListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1169 if (view
->GetConfirmButton())
1170 view
->GetConfirmButton()->Enable(FALSE
);
1171 if (view
->GetCancelButton())
1172 view
->GetCancelButton()->Enable(FALSE
);
1173 if (view
->GetEditButton())
1174 view
->GetEditButton()->Enable(TRUE
);
1175 if (view
->GetValueText())
1176 view
->GetValueText()->Enable(FALSE
);
1180 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1182 if (view
->GetValueList())
1184 view
->ShowListBoxControl(TRUE
);
1185 view
->GetValueList()->Enable(TRUE
);
1187 view
->GetValueList()->Append("True");
1188 view
->GetValueList()->Append("False");
1189 char *currentString
= copystring(view
->GetValueText()->GetValue());
1190 view
->GetValueList()->SetStringSelection(currentString
);
1191 delete[] currentString
;
1196 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1198 if (view
->GetValueList())
1200 view
->GetValueList()->Clear();
1201 view
->ShowListBoxControl(FALSE
);
1202 view
->GetValueList()->Enable(FALSE
);
1207 // Called when the property is double clicked. Extra functionality can be provided,
1208 // cycling through possible values.
1209 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1211 if (!view
->GetValueText())
1213 if (property
->GetValue().BoolValue())
1214 property
->GetValue() = (bool)FALSE
;
1216 property
->GetValue() = (bool)TRUE
;
1217 view
->DisplayProperty(property
);
1218 view
->UpdatePropertyDisplayInList(property
);
1219 view
->OnPropertyChanged(property
);
1224 /// String validator
1226 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1228 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1229 wxPropertyListValidator(flags
)
1232 // If no constraint, we just allow the string to be edited.
1233 if (!strings
&& ((validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1234 validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1237 bool wxStringListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1242 if (!view
->GetValueText())
1244 wxString
value(view
->GetValueText()->GetValue());
1246 if (!strings
->Member(value
.GetData()))
1248 wxString
s("Value ");
1249 s
+= value
.GetData();
1250 s
+= " is not valid.";
1251 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1257 // Called when TICK is pressed or focus is lost or view wants to update
1258 // the property list.
1259 // Does the transferance from the property editing area to the property itself
1260 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1262 if (!view
->GetValueText())
1264 wxString
value(view
->GetValueText()->GetValue());
1265 property
->GetValue() = value
;
1269 // Called when TICK is pressed or focus is lost or view wants to update
1270 // the property list.
1271 // Does the transferance from the property editing area to the property itself
1272 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1274 if (!view
->GetValueText())
1276 wxString
str(property
->GetValue().GetStringRepresentation());
1277 view
->GetValueText()->SetValue(str
.GetData());
1278 if (strings
&& view
->GetValueList() && view
->GetValueList()->Number() > 0)
1280 view
->GetValueList()->SetStringSelection(str
.GetData());
1285 bool wxStringListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1290 if (view
->GetEditButton())
1291 view
->GetEditButton()->Enable(FALSE
);
1292 if (view
->GetConfirmButton())
1293 view
->GetConfirmButton()->Enable(TRUE
);
1294 if (view
->GetCancelButton())
1295 view
->GetCancelButton()->Enable(TRUE
);
1296 if (view
->GetValueText())
1297 view
->GetValueText()->Enable(TRUE
);
1302 if (view
->GetValueText())
1303 view
->GetValueText()->Enable(FALSE
);
1305 if (view
->GetEditButton())
1306 view
->GetEditButton()->Enable(TRUE
);
1308 if (view
->GetConfirmButton())
1309 view
->GetConfirmButton()->Enable(FALSE
);
1310 if (view
->GetCancelButton())
1311 view
->GetCancelButton()->Enable(FALSE
);
1315 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1317 if (view
->GetValueList())
1319 view
->ShowListBoxControl(TRUE
);
1320 view
->GetValueList()->Enable(TRUE
);
1321 wxNode
*node
= strings
->First();
1324 char *s
= (char *)node
->Data();
1325 view
->GetValueList()->Append(s
);
1326 node
= node
->Next();
1328 char *currentString
= property
->GetValue().StringValue();
1329 view
->GetValueList()->SetStringSelection(currentString
);
1334 bool wxStringListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1341 if (view
->GetValueList())
1343 view
->GetValueList()->Clear();
1344 view
->ShowListBoxControl(FALSE
);
1345 view
->GetValueList()->Enable(FALSE
);
1350 // Called when the property is double clicked. Extra functionality can be provided,
1351 // cycling through possible values.
1352 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1354 if (!view
->GetValueText())
1359 wxNode
*node
= strings
->First();
1360 char *currentString
= property
->GetValue().StringValue();
1363 char *s
= (char *)node
->Data();
1364 if (strcmp(s
, currentString
) == 0)
1366 char *nextString
= NULL
;
1368 nextString
= (char *)node
->Next()->Data();
1370 nextString
= (char *)strings
->First()->Data();
1371 property
->GetValue() = wxString(nextString
);
1372 view
->DisplayProperty(property
);
1373 view
->UpdatePropertyDisplayInList(property
);
1374 view
->OnPropertyChanged(property
);
1377 else node
= node
->Next();
1383 /// Filename validator
1385 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1387 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1388 wxPropertyListValidator(flags
), filenameWildCard(wildcard
), filenameMessage(message
)
1392 wxFilenameListValidator::~wxFilenameListValidator(void)
1396 bool wxFilenameListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1401 // Called when TICK is pressed or focus is lost or view wants to update
1402 // the property list.
1403 // Does the transferance from the property editing area to the property itself
1404 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1406 if (!view
->GetValueText())
1408 wxString
value(view
->GetValueText()->GetValue());
1409 property
->GetValue() = value
;
1413 // Called when TICK is pressed or focus is lost or view wants to update
1414 // the property list.
1415 // Does the transferance from the property editing area to the property itself
1416 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1418 if (!view
->GetValueText())
1420 wxString
str(property
->GetValue().GetStringRepresentation());
1421 view
->GetValueText()->SetValue(str
);
1425 // Called when the property is double clicked. Extra functionality can be provided,
1426 // cycling through possible values.
1427 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1429 if (!view
->GetValueText())
1431 OnEdit(property
, view
, parentWindow
);
1435 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1437 if (view
->GetConfirmButton())
1438 view
->GetConfirmButton()->Enable(TRUE
);
1439 if (view
->GetCancelButton())
1440 view
->GetCancelButton()->Enable(TRUE
);
1441 if (view
->GetEditButton())
1442 view
->GetEditButton()->Enable(TRUE
);
1443 if (view
->GetValueText())
1444 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1448 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1450 if (!view
->GetValueText())
1453 char *s
= wxFileSelector(
1454 filenameMessage
.GetData(),
1455 wxPathOnly(property
->GetValue().StringValue()),
1456 wxFileNameFromPath(property
->GetValue().StringValue()),
1458 filenameWildCard
.GetData(),
1463 property
->GetValue() = wxString(s
);
1464 view
->DisplayProperty(property
);
1465 view
->UpdatePropertyDisplayInList(property
);
1466 view
->OnPropertyChanged(property
);
1471 /// Colour validator
1473 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1475 wxColourListValidator::wxColourListValidator(long flags
):
1476 wxPropertyListValidator(flags
)
1480 wxColourListValidator::~wxColourListValidator(void)
1484 bool wxColourListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1489 // Called when TICK is pressed or focus is lost or view wants to update
1490 // the property list.
1491 // Does the transferance from the property editing area to the property itself
1492 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1494 if (!view
->GetValueText())
1496 wxString
value(view
->GetValueText()->GetValue());
1498 property
->GetValue() = value
;
1502 // Called when TICK is pressed or focus is lost or view wants to update
1503 // the property list.
1504 // Does the transferance from the property editing area to the property itself
1505 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1507 if (!view
->GetValueText())
1509 wxString
str(property
->GetValue().GetStringRepresentation());
1510 view
->GetValueText()->SetValue(str
);
1514 // Called when the property is double clicked. Extra functionality can be provided,
1515 // cycling through possible values.
1516 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1518 if (!view
->GetValueText())
1520 OnEdit(property
, view
, parentWindow
);
1524 bool wxColourListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1526 if (view
->GetConfirmButton())
1527 view
->GetConfirmButton()->Enable(TRUE
);
1528 if (view
->GetCancelButton())
1529 view
->GetCancelButton()->Enable(TRUE
);
1530 if (view
->GetEditButton())
1531 view
->GetEditButton()->Enable(TRUE
);
1532 if (view
->GetValueText())
1533 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1537 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1539 if (!view
->GetValueText())
1542 char *s
= property
->GetValue().StringValue();
1549 g
= wxHexToDec(s
+2);
1550 b
= wxHexToDec(s
+4);
1553 wxColour
col(r
,g
,b
);
1556 data
.SetChooseFull(TRUE
);
1557 data
.SetColour(col
);
1559 for (int i
= 0; i
< 16; i
++)
1561 wxColour
colour(i
*16, i
*16, i
*16);
1562 data
.SetCustomColour(i
, colour
);
1565 wxColourDialog
dialog(parentWindow
, &data
);
1566 if (dialog
.ShowModal() != wxID_CANCEL
)
1568 wxColourData retData
= dialog
.GetColourData();
1569 col
= retData
.GetColour();
1572 wxDecToHex(col
.Red(), buf
);
1573 wxDecToHex(col
.Green(), buf
+2);
1574 wxDecToHex(col
.Blue(), buf
+4);
1576 property
->GetValue() = wxString(buf
);
1577 view
->DisplayProperty(property
);
1578 view
->UpdatePropertyDisplayInList(property
);
1579 view
->OnPropertyChanged(property
);
1584 /// List of strings validator. For this we need more user interface than
1585 /// we get with a property list; so create a new dialog for editing the list.
1587 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1589 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1590 wxPropertyListValidator(flags
)
1594 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1596 // No constraints for an arbitrary, user-editable list of strings.
1600 // Called when TICK is pressed or focus is lost or view wants to update
1601 // the property list.
1602 // Does the transferance from the property editing area to the property itself.
1603 // In this case, the user cannot directly edit the string list.
1604 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1609 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1611 if (!view
->GetValueText())
1613 wxString
str(property
->GetValue().GetStringRepresentation());
1614 view
->GetValueText()->SetValue(str
.GetData());
1618 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1620 if (view
->GetEditButton())
1621 view
->GetEditButton()->Enable(TRUE
);
1622 if (view
->GetValueText())
1623 view
->GetValueText()->Enable(FALSE
);
1625 if (view
->GetConfirmButton())
1626 view
->GetConfirmButton()->Enable(FALSE
);
1627 if (view
->GetCancelButton())
1628 view
->GetCancelButton()->Enable(FALSE
);
1632 // Called when the property is double clicked. Extra functionality can be provided,
1633 // cycling through possible values.
1634 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1636 OnEdit(property
, view
, parentWindow
);
1640 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1642 // Convert property value to a list of strings for editing
1643 wxStringList
*stringList
= new wxStringList
;
1645 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1648 char *s
= expr
->StringValue();
1651 expr
= expr
->GetNext();
1654 wxString
title("Editing ");
1655 title
+= property
->GetName();
1657 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1659 wxPropertyValue
& oldValue
= property
->GetValue();
1660 oldValue
.ClearList();
1661 wxNode
*node
= stringList
->First();
1664 char *s
= (char *)node
->Data();
1665 oldValue
.Append(new wxPropertyValue(s
));
1667 node
= node
->Next();
1670 view
->DisplayProperty(property
);
1671 view
->UpdatePropertyDisplayInList(property
);
1672 view
->OnPropertyChanged(property
);
1677 class wxPropertyStringListEditorDialog
: public wxDialog
1680 wxStringList
*stringList
;
1682 wxTextCtrl
*stringText
;
1683 static bool dialogCancelled
;
1684 int currentSelection
;
1685 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1686 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1687 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1688 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1693 dialogCancelled
= FALSE
;
1694 currentSelection
= -1;
1696 ~wxPropertyStringListEditorDialog(void) {}
1698 void SaveCurrentSelection(void);
1699 void ShowCurrentSelection(void);
1701 void OnOK(wxCommandEvent
& event
);
1702 void OnCancel(wxCommandEvent
& event
);
1703 void OnAdd(wxCommandEvent
& event
);
1704 void OnDelete(wxCommandEvent
& event
);
1705 void OnStrings(wxCommandEvent
& event
);
1706 void OnText(wxCommandEvent
& event
);
1708 DECLARE_EVENT_TABLE()
1711 #define wxID_PROP_SL_ADD 3000
1712 #define wxID_PROP_SL_DELETE 3001
1713 #define wxID_PROP_SL_STRINGS 3002
1714 #define wxID_PROP_SL_TEXT 3003
1716 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1717 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1718 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1719 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1720 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1721 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1722 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1725 class wxPropertyStringListEditorText
: public wxTextCtrl
1728 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1729 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1730 long windowStyle
= 0, const wxString
& name
= "text"):
1731 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1734 void OnKillFocus(void)
1736 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1737 dialog
->SaveCurrentSelection();
1741 bool wxPropertyStringListEditorDialog::dialogCancelled
= FALSE
;
1743 // Edit the string list.
1744 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1746 wxBeginBusyCursor();
1747 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1748 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1750 dialog
->stringList
= stringList
;
1752 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(5, 5));
1753 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(40, 5));
1755 // wxButton *helpButton = new wxButton(dialog, (wxFunction)StringListEditorHelpProc, "Help");
1756 // helpButton->SetClientData((char *)this);
1758 dialog
->listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1759 wxPoint(5, 30), wxSize(300, 200), 0, NULL
, wxLB_SINGLE
);
1761 dialog
->stringText
= new wxPropertyStringListEditorText(dialog
,
1762 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1763 wxSize(300, -1), wxPROCESS_ENTER
);
1764 dialog
->stringText
->Enable(FALSE
);
1766 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(5, 280));
1767 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(40, 280));
1769 wxNode
*node
= stringList
->First();
1772 char *str
= (char *)node
->Data();
1773 // Save node as client data for each listbox item
1774 dialog
->listBox
->Append(str
, (char *)node
);
1775 node
= node
->Next();
1778 dialog
->SetClientSize(310, 305);
1780 dialog
->Centre(wxBOTH
);
1782 if (dialog
->ShowModal() == wxID_CANCEL
)
1789 * String list editor callbacks
1793 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1795 int sel
= listBox
->GetSelection();
1798 currentSelection
= sel
;
1800 ShowCurrentSelection();
1804 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1806 int sel
= listBox
->GetSelection();
1810 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(sel
);
1814 listBox
->Delete(sel
);
1815 delete[] (char *)node
->Data();
1817 currentSelection
= -1;
1818 stringText
->SetValue("");
1821 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1823 SaveCurrentSelection();
1825 char *initialText
= "";
1826 wxNode
*node
= stringList
->Add(initialText
);
1827 listBox
->Append(initialText
, (char *)node
);
1828 currentSelection
= stringList
->Number() - 1;
1829 listBox
->SetSelection(currentSelection
);
1830 ShowCurrentSelection();
1831 stringText
->SetFocus();
1834 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1836 SaveCurrentSelection();
1841 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1843 dialogCancelled
= TRUE
;
1844 EndModal(wxID_CANCEL
);
1848 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1850 if (event
.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND
)
1852 SaveCurrentSelection();
1856 bool wxPropertyStringListEditorDialog::OnClose(void)
1858 SaveCurrentSelection();
1862 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1864 if (currentSelection
== -1)
1867 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(currentSelection
);
1871 wxString
txt(stringText
->GetValue());
1873 delete[] (char *)node
->Data();
1874 node
->SetData((wxObject
*)copystring(txt
));
1876 listBox
->SetString(currentSelection
, (char *)node
->Data());
1879 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1881 if (currentSelection
== -1)
1883 stringText
->SetValue("");
1886 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(currentSelection
);
1887 char *txt
= (char *)node
->Data();
1888 stringText
->SetValue(txt
);
1889 stringText
->Enable(TRUE
);