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 // TODO: why is this necessary?
187 if (currentlySelected
> -1)
188 propertyScrollingList
->SetSelection(currentlySelected
);
194 // Find the wxListBox index corresponding to this property
195 int wxPropertyListView::FindListIndexForProperty(wxProperty
*property
)
197 int n
= propertyScrollingList
->Number();
198 for (int i
= 0; i
< n
; i
++)
200 if (property
== (wxProperty
*)propertyScrollingList
->wxListBox::GetClientData(i
))
206 wxString
wxPropertyListView::MakeNameValueString(wxString name
, wxString value
)
208 wxString
theString(name
);
211 int padWith
= nameWidth
- theString
.Length();
215 if (GetFlags() & wxPROP_SHOWVALUES
)
217 // Want to pad with spaces
218 theString
.Append(' ', padWith
);
225 // Select and show string representation in validator the given
226 // property. NULL resets to show no property.
227 bool wxPropertyListView::ShowProperty(wxProperty
*property
, bool select
)
231 EndShowingProperty(currentProperty
);
232 currentProperty
= NULL
;
236 valueText
->SetValue("");
240 currentProperty
= property
;
241 BeginShowingProperty(property
);
245 int sel
= FindListIndexForProperty(property
);
247 propertyScrollingList
->SetSelection(sel
);
252 // Find appropriate validator and load property into value controls
253 bool wxPropertyListView::BeginShowingProperty(wxProperty
*property
)
255 currentValidator
= FindPropertyValidator(property
);
256 if (!currentValidator
)
259 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
262 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
264 listValidator
->OnPrepareControls(property
, this, propertyWindow
);
265 DisplayProperty(property
);
269 // Find appropriate validator and unload property from value controls
270 bool wxPropertyListView::EndShowingProperty(wxProperty
*property
)
272 if (!currentValidator
)
275 RetrieveProperty(property
);
277 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
280 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
282 listValidator
->OnClearControls(property
, this, propertyWindow
);
285 listValidator
->OnClearDetailControls(property
, this, propertyWindow
);
286 detailedEditing
= FALSE
;
291 void wxPropertyListView::BeginDetailedEditing(void)
293 if (!currentValidator
)
295 if (!currentProperty
)
299 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
301 if (!currentProperty
->IsEnabled())
304 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
306 if (listValidator
->OnPrepareDetailControls(currentProperty
, this, propertyWindow
))
307 detailedEditing
= TRUE
;
310 void wxPropertyListView::EndDetailedEditing(void)
312 if (!currentValidator
)
314 if (!currentProperty
)
317 RetrieveProperty(currentProperty
);
319 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
322 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
326 listValidator
->OnClearDetailControls(currentProperty
, this, propertyWindow
);
327 detailedEditing
= FALSE
;
331 bool wxPropertyListView::DisplayProperty(wxProperty
*property
)
333 if (!currentValidator
)
336 if (((currentValidator
->GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == 0) || !property
->IsEnabled())
337 valueText
->SetEditable(FALSE
);
339 valueText
->SetEditable(TRUE
);
341 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
344 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
346 listValidator
->OnDisplayValue(property
, this, propertyWindow
);
350 bool wxPropertyListView::RetrieveProperty(wxProperty
*property
)
352 if (!currentValidator
)
354 if (!property
->IsEnabled())
357 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
360 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
362 if (listValidator
->OnCheckValue(property
, this, propertyWindow
))
364 if (listValidator
->OnRetrieveValue(property
, this, propertyWindow
))
366 UpdatePropertyDisplayInList(property
);
367 OnPropertyChanged(property
);
372 // Revert to old value
373 listValidator
->OnDisplayValue(property
, this, propertyWindow
);
379 bool wxPropertyListView::EditProperty(wxProperty
*WXUNUSED(property
))
384 // Called by the listbox callback
385 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
387 int sel
= propertyScrollingList
->GetSelection();
390 wxProperty
*newSel
= (wxProperty
*)propertyScrollingList
->wxListBox::GetClientData(sel
);
391 if (newSel
&& newSel
!= currentProperty
)
393 ShowProperty(newSel
, FALSE
);
398 bool wxPropertyListView::CreateControls(void)
400 wxPanel
*panel
= (wxPanel
*)propertyWindow
;
402 int largeButtonWidth
= 60;
403 int largeButtonHeight
= 25;
405 int smallButtonWidth
= 25;
406 int smallButtonHeight
= 20;
408 // XView must be allowed to choose its own sized buttons
410 largeButtonWidth
= -1;
411 largeButtonHeight
= -1;
413 smallButtonWidth
= -1;
414 smallButtonHeight
= -1;
423 wxWindow
*leftMostWindow
= panel
;
424 wxWindow
*topMostWindow
= panel
;
425 wxWindow
*rightMostWindow
= panel
;
427 wxSystemSettings settings
;
428 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
431 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
433 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxTELETYPE
, wxNORMAL
, wxNORMAL
);
436 // May need to be changed in future to eliminate clashes with app.
437 panel
->SetClientData((char *)this);
439 // These buttons are at the bottom of the window, but create them now
440 // so the constraints are evaluated in the correct order
441 if (buttonFlags
& wxPROP_BUTTON_OK
)
443 windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
444 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
445 windowCloseButton
->SetDefault();
446 windowCloseButton
->SetFocus();
448 else if (buttonFlags
& wxPROP_BUTTON_CLOSE
)
450 windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
451 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
453 if (buttonFlags
& wxPROP_BUTTON_CANCEL
)
455 windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
456 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
458 if (buttonFlags
& wxPROP_BUTTON_HELP
)
460 windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
461 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
464 if (windowCloseButton
)
466 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
468 c1
->left
.SameAs (panel
, wxLeft
, 2);
469 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
472 windowCloseButton
->SetConstraints(c1
);
473 leftMostWindow
= windowCloseButton
;
475 if (windowCancelButton
)
477 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
479 c2
->right
.SameAs (panel
, wxRight
, 2);
480 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
483 windowCancelButton
->SetConstraints(c2
);
484 leftMostWindow
= windowCancelButton
;
486 if (windowHelpButton
)
488 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
489 if (leftMostWindow
== panel
)
490 c2
->left
.SameAs (panel
, wxLeft
, 2);
492 c2
->left
.RightOf (leftMostWindow
, 2);
494 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
497 windowHelpButton
->SetConstraints(c2
);
498 leftMostWindow
= windowHelpButton
;
501 if (buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
507 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
508 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
509 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
522 if (tickBitmap && crossBitmap)
524 confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
525 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
526 cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
527 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
532 confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
533 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
534 cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
535 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
538 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
539 c
->left
.SameAs (panel
, wxLeft
, 2);
541 if (windowCloseButton)
542 c->top.Below (windowCloseButton, 2);
545 c
->top
.SameAs (panel
, wxTop
, 2);
550 cancelButton
->SetConstraints(c
);
552 c
= new wxLayoutConstraints
;
553 c
->left
.RightOf (cancelButton
, 2);
554 c
->top
.SameAs (cancelButton
, wxTop
, 0);
558 confirmButton
->SetConstraints(c
);
560 cancelButton
->Enable(FALSE
);
561 confirmButton
->Enable(FALSE
);
564 if (buttonFlags
& wxPROP_PULLDOWN
)
566 editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
567 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
568 editButton
->Enable(FALSE
);
569 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
572 if (windowCloseButton)
573 c->top.Below (windowCloseButton, 2);
576 c
->top
.SameAs (panel
, wxTop
, 2);
578 c
->right
.SameAs (panel
, wxRight
, 2);
581 editButton
->SetConstraints(c
);
584 valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
585 valueText
->Enable(FALSE
);
587 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
590 c
->left
.RightOf (confirmButton
, 2);
592 c
->left
.SameAs (panel
, wxLeft
, 2);
594 if (windowCloseButton)
595 c->top.Below (windowCloseButton, 2);
598 c
->top
.SameAs (panel
, wxTop
, 2);
601 c
->right
.LeftOf (editButton
, 2);
603 c
->right
.SameAs (panel
, wxRight
, 2);
606 valueText
->SetConstraints(c
);
608 valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
609 valueList
->Show(FALSE
);
611 c
= new wxLayoutConstraints
;
613 c
->left
.SameAs (panel
, wxLeft
, 2);
614 c
->top
.Below (valueText
, 2);
615 c
->right
.SameAs (panel
, wxRight
, 2);
616 c
->height
.Absolute(60);
618 valueList
->SetConstraints(c
);
620 propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
621 wxPoint(-1, -1), wxSize(300, 300));
622 propertyScrollingList
->SetFont(boringFont
);
624 c
= new wxLayoutConstraints
;
626 c
->left
.SameAs (panel
, wxLeft
, 2);
628 if (buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
629 c
->top
.Below (valueText
, 2);
631 c
->top
.Below (valueList
, 2);
633 c
->right
.SameAs (panel
, wxRight
, 2);
635 if (windowCloseButton
)
636 c
->bottom
.Above (windowCloseButton
, -2);
638 c
->bottom
.SameAs (panel
, wxBottom
, 2);
640 propertyScrollingList
->SetConstraints(c
);
643 // Note: if this is called now, it causes a GPF.
650 void wxPropertyListView::ShowTextControl(bool show
)
653 valueText
->Show(show
);
656 void wxPropertyListView::ShowListBoxControl(bool show
)
660 valueList
->Show(show
);
661 if (buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
663 wxLayoutConstraints
*constraints
= propertyScrollingList
->GetConstraints();
668 constraints
->top
.Below(valueList
, 2);
669 // Maintain back-pointer so when valueList is deleted,
670 // any reference to it from this window is removed.
671 valueList
->AddConstraintReference(propertyScrollingList
);
675 constraints
->top
.Below(valueText
, 2);
676 valueText
->AddConstraintReference(propertyScrollingList
);
678 propertyWindow
->Layout();
684 void wxPropertyListView::EnableCheck(bool show
)
687 confirmButton
->Enable(show
);
690 void wxPropertyListView::EnableCross(bool show
)
693 cancelButton
->Enable(show
);
696 bool wxPropertyListView::OnClose(void)
698 // Retrieve the value if any
699 wxCommandEvent event
;
706 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
708 if (currentProperty
&& currentValidator
)
710 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
713 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
715 listValidator
->OnValueListSelect(currentProperty
, this, propertyWindow
);
719 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
721 // Retrieve the value if any
724 managedWindow
->Close(TRUE
);
727 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
729 // SetReturnCode(wxID_CANCEL);
730 managedWindow
->Close(TRUE
);
731 dialogCancelled
= TRUE
;
734 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
738 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
742 RetrieveProperty(currentProperty
);
746 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
748 if (currentProperty
&& currentValidator
)
750 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
753 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
755 // Revert to old value
756 listValidator
->OnDisplayValue(currentProperty
, this, propertyWindow
);
760 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
762 if (currentProperty
&& currentValidator
)
764 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
767 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
769 // Revert to old value
770 listValidator
->OnDoubleClick(currentProperty
, this, propertyWindow
);
774 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
776 if (currentProperty
&& currentValidator
)
778 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
781 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
783 listValidator
->OnEdit(currentProperty
, this, propertyWindow
);
787 void wxPropertyListView::OnText(wxCommandEvent
& event
)
789 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
796 * Property dialog box
799 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
801 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
802 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
805 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
806 const wxString
& title
, const wxPoint
& pos
,
807 const wxSize
& size
, long style
, const wxString
& name
):
808 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
811 view
->AssociatePanel( ((wxPanel
*)this) );
812 view
->SetManagedWindow(this);
816 bool wxPropertyListDialog::OnClose(void)
820 SetReturnCode(wxID_CANCEL
);
829 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
831 SetReturnCode(wxID_CANCEL
);
835 void wxPropertyListDialog::OnDefaultAction(wxControl
*item
)
838 if (item == view->GetPropertyScrollingList())
839 view->OnDoubleClick();
843 // Extend event processing to search the view's event table
844 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
846 if ( !view
|| ! view
->ProcessEvent(event
) )
847 return wxEvtHandler::ProcessEvent(event
);
856 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
858 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
859 EVT_SIZE(wxPropertyListPanel::OnSize
)
862 wxPropertyListPanel::~wxPropertyListPanel()
866 void wxPropertyListPanel::OnDefaultAction(wxControl
*item
)
869 if (item == view->GetPropertyScrollingList())
870 view->OnDoubleClick();
874 // Extend event processing to search the view's event table
875 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
877 if ( !view
|| ! view
->ProcessEvent(event
) )
878 return wxEvtHandler::ProcessEvent(event
);
883 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
892 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
894 bool wxPropertyListFrame::OnClose(void)
899 propertyPanel
->SetView(NULL
);
908 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
910 return new wxPropertyListPanel(v
, parent
);
913 bool wxPropertyListFrame::Initialize(void)
915 propertyPanel
= OnCreatePanel(this, view
);
918 view
->AssociatePanel(propertyPanel
);
919 view
->SetManagedWindow(this);
920 propertyPanel
->SetAutoLayout(TRUE
);
928 * Property list specific validator
931 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
933 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
935 // view->GetValueText()->Show(TRUE);
937 OnDisplayValue(property
, view
, parentWindow
);
942 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
944 wxString
s(view
->GetValueList()->GetStringSelection());
947 view
->GetValueText()->SetValue(s
);
948 view
->RetrieveProperty(property
);
953 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
955 // view->GetValueText()->Show(TRUE);
956 wxString
str(property
->GetValue().GetStringRepresentation());
958 view
->GetValueText()->SetValue(str
);
962 // Called when TICK is pressed or focus is lost or view wants to update
963 // the property list.
964 // Does the transferance from the property editing area to the property itself
965 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
967 if (!view
->GetValueText())
972 void wxPropertyListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
974 if (view
->GetDetailedEditing())
975 view
->EndDetailedEditing();
977 view
->BeginDetailedEditing();
980 bool wxPropertyListValidator::OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
982 if (view
->GetConfirmButton())
983 view
->GetConfirmButton()->Enable(FALSE
);
984 if (view
->GetCancelButton())
985 view
->GetCancelButton()->Enable(FALSE
);
986 if (view
->GetEditButton())
987 view
->GetEditButton()->Enable(FALSE
);
995 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
998 /// Real number validator
1000 bool wxRealListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1002 if (realMin
== 0.0 && realMax
== 0.0)
1005 if (!view
->GetValueText())
1007 wxString
value(view
->GetValueText()->GetValue());
1010 if (!StringToFloat(WXSTRINGCAST value
, &val
))
1013 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
1014 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1018 if (val
< realMin
|| val
> realMax
)
1021 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", realMin
, realMax
);
1022 wxMessageBox(buf
, "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 wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1033 if (!view
->GetValueText())
1036 if (strlen(view
->GetValueText()->GetValue()) == 0)
1039 wxString
value(view
->GetValueText()->GetValue());
1040 float f
= (float)atof(value
.GetData());
1041 property
->GetValue() = f
;
1045 bool wxRealListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1047 if (view
->GetConfirmButton())
1048 view
->GetConfirmButton()->Enable(TRUE
);
1049 if (view
->GetCancelButton())
1050 view
->GetCancelButton()->Enable(TRUE
);
1051 if (view
->GetEditButton())
1052 view
->GetEditButton()->Enable(FALSE
);
1053 if (view
->GetValueText())
1054 view
->GetValueText()->Enable(TRUE
);
1059 /// Integer validator
1061 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1063 bool wxIntegerListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1065 if (integerMin
== 0 && integerMax
== 0)
1068 if (!view
->GetValueText())
1070 wxString
value(view
->GetValueText()->GetValue());
1073 if (!StringToLong(WXSTRINGCAST value
, &val
))
1076 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1077 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1080 if (val
< integerMin
|| val
> integerMax
)
1083 sprintf(buf
, "Value must be an integer between %ld and %ld!", integerMin
, integerMax
);
1084 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1090 // Called when TICK is pressed or focus is lost or view wants to update
1091 // the property list.
1092 // Does the transferance from the property editing area to the property itself
1093 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1095 if (!view
->GetValueText())
1098 if (strlen(view
->GetValueText()->GetValue()) == 0)
1101 wxString
value(view
->GetValueText()->GetValue());
1102 long val
= (long)atoi(value
.GetData());
1103 property
->GetValue() = (long)val
;
1107 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1109 if (view
->GetConfirmButton())
1110 view
->GetConfirmButton()->Enable(TRUE
);
1111 if (view
->GetCancelButton())
1112 view
->GetCancelButton()->Enable(TRUE
);
1113 if (view
->GetEditButton())
1114 view
->GetEditButton()->Enable(FALSE
);
1115 if (view
->GetValueText())
1116 view
->GetValueText()->Enable(TRUE
);
1121 /// boolean validator
1123 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1125 bool wxBoolListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1127 if (!view
->GetValueText())
1129 wxString
value(view
->GetValueText()->GetValue());
1130 if (value
!= "True" && value
!= "False")
1132 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1138 // Called when TICK is pressed or focus is lost or view wants to update
1139 // the property list.
1140 // Does the transferance from the property editing area to the property itself
1141 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1143 if (!view
->GetValueText())
1146 if (strlen(view
->GetValueText()->GetValue()) == 0)
1149 wxString
value(view
->GetValueText()->GetValue());
1150 bool boolValue
= FALSE
;
1151 if (value
== "True")
1155 property
->GetValue() = (bool)boolValue
;
1159 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1161 if (!view
->GetValueText())
1163 wxString
str(property
->GetValue().GetStringRepresentation());
1165 view
->GetValueText()->SetValue(str
);
1167 if (view
->GetValueList()->IsShown())
1169 view
->GetValueList()->SetStringSelection(str
);
1174 bool wxBoolListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1176 if (view
->GetConfirmButton())
1177 view
->GetConfirmButton()->Enable(FALSE
);
1178 if (view
->GetCancelButton())
1179 view
->GetCancelButton()->Enable(FALSE
);
1180 if (view
->GetEditButton())
1181 view
->GetEditButton()->Enable(TRUE
);
1182 if (view
->GetValueText())
1183 view
->GetValueText()->Enable(FALSE
);
1187 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1189 if (view
->GetValueList())
1191 view
->ShowListBoxControl(TRUE
);
1192 view
->GetValueList()->Enable(TRUE
);
1194 view
->GetValueList()->Append("True");
1195 view
->GetValueList()->Append("False");
1196 char *currentString
= copystring(view
->GetValueText()->GetValue());
1197 view
->GetValueList()->SetStringSelection(currentString
);
1198 delete[] currentString
;
1203 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1205 if (view
->GetValueList())
1207 view
->GetValueList()->Clear();
1208 view
->ShowListBoxControl(FALSE
);
1209 view
->GetValueList()->Enable(FALSE
);
1214 // Called when the property is double clicked. Extra functionality can be provided,
1215 // cycling through possible values.
1216 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1218 if (!view
->GetValueText())
1220 if (property
->GetValue().BoolValue())
1221 property
->GetValue() = (bool)FALSE
;
1223 property
->GetValue() = (bool)TRUE
;
1224 view
->DisplayProperty(property
);
1225 view
->UpdatePropertyDisplayInList(property
);
1226 view
->OnPropertyChanged(property
);
1231 /// String validator
1233 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1235 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1236 wxPropertyListValidator(flags
)
1239 // If no constraint, we just allow the string to be edited.
1240 if (!strings
&& ((validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1241 validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1244 bool wxStringListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1249 if (!view
->GetValueText())
1251 wxString
value(view
->GetValueText()->GetValue());
1253 if (!strings
->Member(value
.GetData()))
1255 wxString
s("Value ");
1256 s
+= value
.GetData();
1257 s
+= " is not valid.";
1258 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1264 // Called when TICK is pressed or focus is lost or view wants to update
1265 // the property list.
1266 // Does the transferance from the property editing area to the property itself
1267 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1269 if (!view
->GetValueText())
1271 wxString
value(view
->GetValueText()->GetValue());
1272 property
->GetValue() = value
;
1276 // Called when TICK is pressed or focus is lost or view wants to update
1277 // the property list.
1278 // Does the transferance from the property editing area to the property itself
1279 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1281 if (!view
->GetValueText())
1283 wxString
str(property
->GetValue().GetStringRepresentation());
1284 view
->GetValueText()->SetValue(str
);
1285 if (strings
&& view
->GetValueList() && view
->GetValueList()->IsShown() && view
->GetValueList()->Number() > 0)
1287 view
->GetValueList()->SetStringSelection(str
);
1292 bool wxStringListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1297 if (view
->GetEditButton())
1298 view
->GetEditButton()->Enable(FALSE
);
1299 if (view
->GetConfirmButton())
1300 view
->GetConfirmButton()->Enable(TRUE
);
1301 if (view
->GetCancelButton())
1302 view
->GetCancelButton()->Enable(TRUE
);
1303 if (view
->GetValueText())
1304 view
->GetValueText()->Enable(TRUE
);
1309 if (view
->GetValueText())
1310 view
->GetValueText()->Enable(FALSE
);
1312 if (view
->GetEditButton())
1313 view
->GetEditButton()->Enable(TRUE
);
1315 if (view
->GetConfirmButton())
1316 view
->GetConfirmButton()->Enable(FALSE
);
1317 if (view
->GetCancelButton())
1318 view
->GetCancelButton()->Enable(FALSE
);
1322 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1324 if (view
->GetValueList())
1326 view
->ShowListBoxControl(TRUE
);
1327 view
->GetValueList()->Enable(TRUE
);
1328 wxNode
*node
= strings
->First();
1331 char *s
= (char *)node
->Data();
1332 view
->GetValueList()->Append(s
);
1333 node
= node
->Next();
1335 char *currentString
= property
->GetValue().StringValue();
1336 view
->GetValueList()->SetStringSelection(currentString
);
1341 bool wxStringListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1348 if (view
->GetValueList())
1350 view
->GetValueList()->Clear();
1351 view
->ShowListBoxControl(FALSE
);
1352 view
->GetValueList()->Enable(FALSE
);
1357 // Called when the property is double clicked. Extra functionality can be provided,
1358 // cycling through possible values.
1359 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1361 if (!view
->GetValueText())
1366 wxNode
*node
= strings
->First();
1367 char *currentString
= property
->GetValue().StringValue();
1370 char *s
= (char *)node
->Data();
1371 if (strcmp(s
, currentString
) == 0)
1373 char *nextString
= NULL
;
1375 nextString
= (char *)node
->Next()->Data();
1377 nextString
= (char *)strings
->First()->Data();
1378 property
->GetValue() = wxString(nextString
);
1379 view
->DisplayProperty(property
);
1380 view
->UpdatePropertyDisplayInList(property
);
1381 view
->OnPropertyChanged(property
);
1384 else node
= node
->Next();
1390 /// Filename validator
1392 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1394 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1395 wxPropertyListValidator(flags
), filenameWildCard(wildcard
), filenameMessage(message
)
1399 wxFilenameListValidator::~wxFilenameListValidator(void)
1403 bool wxFilenameListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1408 // Called when TICK is pressed or focus is lost or view wants to update
1409 // the property list.
1410 // Does the transferance from the property editing area to the property itself
1411 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1413 if (!view
->GetValueText())
1415 wxString
value(view
->GetValueText()->GetValue());
1416 property
->GetValue() = value
;
1420 // Called when TICK is pressed or focus is lost or view wants to update
1421 // the property list.
1422 // Does the transferance from the property editing area to the property itself
1423 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1425 if (!view
->GetValueText())
1427 wxString
str(property
->GetValue().GetStringRepresentation());
1428 view
->GetValueText()->SetValue(str
);
1432 // Called when the property is double clicked. Extra functionality can be provided,
1433 // cycling through possible values.
1434 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1436 if (!view
->GetValueText())
1438 OnEdit(property
, view
, parentWindow
);
1442 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1444 if (view
->GetConfirmButton())
1445 view
->GetConfirmButton()->Enable(TRUE
);
1446 if (view
->GetCancelButton())
1447 view
->GetCancelButton()->Enable(TRUE
);
1448 if (view
->GetEditButton())
1449 view
->GetEditButton()->Enable(TRUE
);
1450 if (view
->GetValueText())
1451 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1455 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1457 if (!view
->GetValueText())
1460 char *s
= wxFileSelector(
1461 filenameMessage
.GetData(),
1462 wxPathOnly(property
->GetValue().StringValue()),
1463 wxFileNameFromPath(property
->GetValue().StringValue()),
1465 filenameWildCard
.GetData(),
1470 property
->GetValue() = wxString(s
);
1471 view
->DisplayProperty(property
);
1472 view
->UpdatePropertyDisplayInList(property
);
1473 view
->OnPropertyChanged(property
);
1478 /// Colour validator
1480 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1482 wxColourListValidator::wxColourListValidator(long flags
):
1483 wxPropertyListValidator(flags
)
1487 wxColourListValidator::~wxColourListValidator(void)
1491 bool wxColourListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1496 // Called when TICK is pressed or focus is lost or view wants to update
1497 // the property list.
1498 // Does the transferance from the property editing area to the property itself
1499 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1501 if (!view
->GetValueText())
1503 wxString
value(view
->GetValueText()->GetValue());
1505 property
->GetValue() = value
;
1509 // Called when TICK is pressed or focus is lost or view wants to update
1510 // the property list.
1511 // Does the transferance from the property editing area to the property itself
1512 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1514 if (!view
->GetValueText())
1516 wxString
str(property
->GetValue().GetStringRepresentation());
1517 view
->GetValueText()->SetValue(str
);
1521 // Called when the property is double clicked. Extra functionality can be provided,
1522 // cycling through possible values.
1523 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1525 if (!view
->GetValueText())
1527 OnEdit(property
, view
, parentWindow
);
1531 bool wxColourListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1533 if (view
->GetConfirmButton())
1534 view
->GetConfirmButton()->Enable(TRUE
);
1535 if (view
->GetCancelButton())
1536 view
->GetCancelButton()->Enable(TRUE
);
1537 if (view
->GetEditButton())
1538 view
->GetEditButton()->Enable(TRUE
);
1539 if (view
->GetValueText())
1540 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1544 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1546 if (!view
->GetValueText())
1549 char *s
= property
->GetValue().StringValue();
1556 g
= wxHexToDec(s
+2);
1557 b
= wxHexToDec(s
+4);
1560 wxColour
col(r
,g
,b
);
1563 data
.SetChooseFull(TRUE
);
1564 data
.SetColour(col
);
1566 for (int i
= 0; i
< 16; i
++)
1568 wxColour
colour(i
*16, i
*16, i
*16);
1569 data
.SetCustomColour(i
, colour
);
1572 wxColourDialog
dialog(parentWindow
, &data
);
1573 if (dialog
.ShowModal() != wxID_CANCEL
)
1575 wxColourData retData
= dialog
.GetColourData();
1576 col
= retData
.GetColour();
1579 wxDecToHex(col
.Red(), buf
);
1580 wxDecToHex(col
.Green(), buf
+2);
1581 wxDecToHex(col
.Blue(), buf
+4);
1583 property
->GetValue() = wxString(buf
);
1584 view
->DisplayProperty(property
);
1585 view
->UpdatePropertyDisplayInList(property
);
1586 view
->OnPropertyChanged(property
);
1591 /// List of strings validator. For this we need more user interface than
1592 /// we get with a property list; so create a new dialog for editing the list.
1594 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1596 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1597 wxPropertyListValidator(flags
)
1601 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1603 // No constraints for an arbitrary, user-editable list of strings.
1607 // Called when TICK is pressed or focus is lost or view wants to update
1608 // the property list.
1609 // Does the transferance from the property editing area to the property itself.
1610 // In this case, the user cannot directly edit the string list.
1611 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1616 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1618 if (!view
->GetValueText())
1620 wxString
str(property
->GetValue().GetStringRepresentation());
1621 view
->GetValueText()->SetValue(str
);
1625 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1627 if (view
->GetEditButton())
1628 view
->GetEditButton()->Enable(TRUE
);
1629 if (view
->GetValueText())
1630 view
->GetValueText()->Enable(FALSE
);
1632 if (view
->GetConfirmButton())
1633 view
->GetConfirmButton()->Enable(FALSE
);
1634 if (view
->GetCancelButton())
1635 view
->GetCancelButton()->Enable(FALSE
);
1639 // Called when the property is double clicked. Extra functionality can be provided,
1640 // cycling through possible values.
1641 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1643 OnEdit(property
, view
, parentWindow
);
1647 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1649 // Convert property value to a list of strings for editing
1650 wxStringList
*stringList
= new wxStringList
;
1652 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1655 char *s
= expr
->StringValue();
1658 expr
= expr
->GetNext();
1661 wxString
title("Editing ");
1662 title
+= property
->GetName();
1664 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1666 wxPropertyValue
& oldValue
= property
->GetValue();
1667 oldValue
.ClearList();
1668 wxNode
*node
= stringList
->First();
1671 char *s
= (char *)node
->Data();
1672 oldValue
.Append(new wxPropertyValue(s
));
1674 node
= node
->Next();
1677 view
->DisplayProperty(property
);
1678 view
->UpdatePropertyDisplayInList(property
);
1679 view
->OnPropertyChanged(property
);
1684 class wxPropertyStringListEditorDialog
: public wxDialog
1687 wxStringList
*stringList
;
1689 wxTextCtrl
*stringText
;
1690 static bool dialogCancelled
;
1691 int currentSelection
;
1692 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1693 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1694 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1695 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1700 dialogCancelled
= FALSE
;
1701 currentSelection
= -1;
1703 ~wxPropertyStringListEditorDialog(void) {}
1705 void SaveCurrentSelection(void);
1706 void ShowCurrentSelection(void);
1708 void OnOK(wxCommandEvent
& event
);
1709 void OnCancel(wxCommandEvent
& event
);
1710 void OnAdd(wxCommandEvent
& event
);
1711 void OnDelete(wxCommandEvent
& event
);
1712 void OnStrings(wxCommandEvent
& event
);
1713 void OnText(wxCommandEvent
& event
);
1715 DECLARE_EVENT_TABLE()
1718 #define wxID_PROP_SL_ADD 3000
1719 #define wxID_PROP_SL_DELETE 3001
1720 #define wxID_PROP_SL_STRINGS 3002
1721 #define wxID_PROP_SL_TEXT 3003
1723 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1724 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1725 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1726 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1727 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1728 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1729 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1732 class wxPropertyStringListEditorText
: public wxTextCtrl
1735 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1736 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1737 long windowStyle
= 0, const wxString
& name
= "text"):
1738 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1741 void OnKillFocus(void)
1743 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1744 dialog
->SaveCurrentSelection();
1748 bool wxPropertyStringListEditorDialog::dialogCancelled
= FALSE
;
1750 // Edit the string list.
1751 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1753 wxBeginBusyCursor();
1754 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1755 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1757 dialog
->stringList
= stringList
;
1759 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(5, 5));
1760 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(40, 5));
1762 // wxButton *helpButton = new wxButton(dialog, (wxFunction)StringListEditorHelpProc, "Help");
1763 // helpButton->SetClientData((char *)this);
1765 dialog
->listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1766 wxPoint(5, 30), wxSize(300, 200), 0, NULL
, wxLB_SINGLE
);
1768 dialog
->stringText
= new wxPropertyStringListEditorText(dialog
,
1769 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1770 wxSize(300, -1), wxPROCESS_ENTER
);
1771 dialog
->stringText
->Enable(FALSE
);
1773 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(5, 280));
1774 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(40, 280));
1776 wxNode
*node
= stringList
->First();
1779 char *str
= (char *)node
->Data();
1780 // Save node as client data for each listbox item
1781 dialog
->listBox
->Append(str
, (char *)node
);
1782 node
= node
->Next();
1785 dialog
->SetClientSize(310, 305);
1787 dialog
->Centre(wxBOTH
);
1789 if (dialog
->ShowModal() == wxID_CANCEL
)
1796 * String list editor callbacks
1800 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1802 int sel
= listBox
->GetSelection();
1805 currentSelection
= sel
;
1807 ShowCurrentSelection();
1811 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1813 int sel
= listBox
->GetSelection();
1817 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(sel
);
1821 listBox
->Delete(sel
);
1822 delete[] (char *)node
->Data();
1824 currentSelection
= -1;
1825 stringText
->SetValue("");
1828 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1830 SaveCurrentSelection();
1832 char *initialText
= "";
1833 wxNode
*node
= stringList
->Add(initialText
);
1834 listBox
->Append(initialText
, (char *)node
);
1835 currentSelection
= stringList
->Number() - 1;
1836 listBox
->SetSelection(currentSelection
);
1837 ShowCurrentSelection();
1838 stringText
->SetFocus();
1841 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1843 SaveCurrentSelection();
1848 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1850 dialogCancelled
= TRUE
;
1851 EndModal(wxID_CANCEL
);
1855 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1857 if (event
.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND
)
1859 SaveCurrentSelection();
1863 bool wxPropertyStringListEditorDialog::OnClose(void)
1865 SaveCurrentSelection();
1869 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1871 if (currentSelection
== -1)
1874 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(currentSelection
);
1878 wxString
txt(stringText
->GetValue());
1880 delete[] (char *)node
->Data();
1881 node
->SetData((wxObject
*)copystring(txt
));
1883 listBox
->SetString(currentSelection
, (char *)node
->Data());
1886 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1888 if (currentSelection
== -1)
1890 stringText
->SetValue("");
1893 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(currentSelection
);
1894 char *txt
= (char *)node
->Data();
1895 stringText
->SetValue(txt
);
1896 stringText
->Enable(TRUE
);