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_TEXT(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
*property
)
381 // Called by the listbox callback
382 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& 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
= 50;
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
);
427 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
);
429 // May need to be changed in future to eliminate clashes with app.
430 panel
->SetClientData((char *)this);
432 if (buttonFlags
& wxPROP_BUTTON_OK
)
434 windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
435 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
436 windowCloseButton
->SetDefault();
437 windowCloseButton
->SetFocus();
439 if (buttonFlags
& wxPROP_BUTTON_CLOSE
)
441 windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
442 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
444 if (buttonFlags
& wxPROP_BUTTON_CANCEL
)
446 windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
447 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
449 if (buttonFlags
& wxPROP_BUTTON_HELP
)
451 windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
452 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
455 if (windowCloseButton
)
457 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
458 c1
->left
.SameAs (panel
, wxLeft
, 2);
459 c1
->top
.SameAs (panel
, wxTop
, 2);
462 windowCloseButton
->SetConstraints(c1
);
463 leftMostWindow
= windowCloseButton
;
465 if (windowCancelButton
)
467 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
468 if (leftMostWindow
== panel
)
469 c2
->left
.SameAs (panel
, wxLeft
, 2);
471 c2
->left
.RightOf (leftMostWindow
, 2);
473 c2
->top
.SameAs (panel
, wxTop
, 2);
476 windowCancelButton
->SetConstraints(c2
);
477 leftMostWindow
= windowCancelButton
;
479 if (windowHelpButton
)
481 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
482 if (leftMostWindow
== panel
)
483 c2
->left
.SameAs (panel
, wxLeft
, 2);
485 c2
->left
.RightOf (leftMostWindow
, 2);
487 c2
->top
.SameAs (panel
, wxTop
, 2);
490 windowHelpButton
->SetConstraints(c2
);
491 leftMostWindow
= windowHelpButton
;
494 if (buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
500 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
501 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
502 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
515 if (tickBitmap && crossBitmap)
517 confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
518 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
519 cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
520 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
525 confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
526 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
527 cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
528 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
531 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
532 c
->left
.SameAs (panel
, wxLeft
, 2);
533 if (windowCloseButton
)
534 c
->top
.Below (windowCloseButton
, 2);
536 c
->top
.SameAs (panel
, wxTop
, 2);
541 cancelButton
->SetConstraints(c
);
543 c
= new wxLayoutConstraints
;
544 c
->left
.RightOf (cancelButton
, 2);
545 c
->top
.SameAs (cancelButton
, wxTop
, 0);
549 confirmButton
->SetConstraints(c
);
551 cancelButton
->Enable(FALSE
);
552 confirmButton
->Enable(FALSE
);
555 if (buttonFlags
& wxPROP_PULLDOWN
)
557 editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
558 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
559 editButton
->Enable(FALSE
);
560 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
562 if (windowCloseButton
)
563 c
->top
.Below (windowCloseButton
, 2);
565 c
->top
.SameAs (panel
, wxTop
, 2);
567 c
->right
.SameAs (panel
, wxRight
, 2);
570 editButton
->SetConstraints(c
);
573 valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
574 valueText
->Enable(FALSE
);
576 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
579 c
->left
.RightOf (confirmButton
, 2);
581 c
->left
.SameAs (panel
, wxLeft
, 2);
583 if (windowCloseButton
)
584 c
->top
.Below (windowCloseButton
, 2);
586 c
->top
.SameAs (panel
, wxTop
, 2);
589 c
->right
.LeftOf (editButton
, 2);
591 c
->right
.SameAs (panel
, wxRight
, 2);
594 valueText
->SetConstraints(c
);
596 valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
597 valueList
->Show(FALSE
);
599 c
= new wxLayoutConstraints
;
601 c
->left
.SameAs (panel
, wxLeft
, 2);
602 c
->top
.Below (valueText
, 2);
603 c
->right
.SameAs (panel
, wxRight
, 2);
604 c
->height
.Absolute(60);
606 valueList
->SetConstraints(c
);
608 propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
609 wxPoint(-1, -1), wxSize(300, 300));
610 propertyScrollingList
->SetFont(boringFont
);
612 c
= new wxLayoutConstraints
;
614 c
->left
.SameAs (panel
, wxLeft
, 2);
616 if (buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
617 c
->top
.Below (valueText
, 2);
619 c
->top
.Below (valueList
, 2);
621 c
->right
.SameAs (panel
, wxRight
, 2);
622 c
->bottom
.SameAs (panel
, wxBottom
, 2);
624 propertyScrollingList
->SetConstraints(c
);
626 // Note: if this is called now, it causes a GPF.
633 void wxPropertyListView::ShowTextControl(bool show
)
636 valueText
->Show(show
);
639 void wxPropertyListView::ShowListBoxControl(bool show
)
643 valueList
->Show(show
);
644 if (buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
646 wxLayoutConstraints
*constraints
= propertyScrollingList
->GetConstraints();
650 constraints
->top
.Below(valueList
, 2);
652 constraints
->top
.Below(valueText
, 2);
653 propertyWindow
->Layout();
659 void wxPropertyListView::EnableCheck(bool show
)
662 confirmButton
->Enable(show
);
665 void wxPropertyListView::EnableCross(bool show
)
668 cancelButton
->Enable(show
);
671 bool wxPropertyListView::OnClose(void)
673 // Retrieve the value if any
674 wxCommandEvent event
;
681 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& event
)
683 if (currentProperty
&& currentValidator
)
685 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
688 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
690 listValidator
->OnValueListSelect(currentProperty
, this, propertyWindow
);
694 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
696 // Retrieve the value if any
699 managedWindow
->Close(TRUE
);
702 void wxPropertyListView::OnCancel(wxCommandEvent
& event
)
704 // SetReturnCode(wxID_CANCEL);
705 managedWindow
->Close(TRUE
);
706 dialogCancelled
= TRUE
;
709 void wxPropertyListView::OnHelp(wxCommandEvent
& event
)
713 void wxPropertyListView::OnCheck(wxCommandEvent
& event
)
717 RetrieveProperty(currentProperty
);
721 void wxPropertyListView::OnCross(wxCommandEvent
& event
)
723 if (currentProperty
&& currentValidator
)
725 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
728 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
730 // Revert to old value
731 listValidator
->OnDisplayValue(currentProperty
, this, propertyWindow
);
735 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& event
)
737 if (currentProperty
&& currentValidator
)
739 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
742 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
744 // Revert to old value
745 listValidator
->OnDoubleClick(currentProperty
, this, propertyWindow
);
749 void wxPropertyListView::OnEdit(wxCommandEvent
& event
)
751 if (currentProperty
&& currentValidator
)
753 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
756 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
758 listValidator
->OnEdit(currentProperty
, this, propertyWindow
);
762 void wxPropertyListView::OnText(wxCommandEvent
& event
)
764 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
771 * Property dialog box
774 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
776 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
777 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
780 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
781 const wxString
& title
, const wxPoint
& pos
,
782 const wxSize
& size
, long style
, const wxString
& name
):
783 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
786 view
->AssociatePanel(this);
787 view
->SetManagedWindow(this);
791 bool wxPropertyListDialog::OnClose(void)
795 SetReturnCode(wxID_CANCEL
);
804 void wxPropertyListDialog::OnCancel(wxCommandEvent
& event
)
806 SetReturnCode(wxID_CANCEL
);
810 void wxPropertyListDialog::OnDefaultAction(wxControl
*item
)
813 if (item == view->GetPropertyScrollingList())
814 view->OnDoubleClick();
818 // Extend event processing to search the view's event table
819 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
821 if ( !view
|| ! view
->ProcessEvent(event
) )
822 return wxEvtHandler::ProcessEvent(event
);
831 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
833 void wxPropertyListPanel::OnDefaultAction(wxControl
*item
)
836 if (item == view->GetPropertyScrollingList())
837 view->OnDoubleClick();
841 // Extend event processing to search the view's event table
842 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
844 if ( !view
|| ! view
->ProcessEvent(event
) )
845 return wxEvtHandler::ProcessEvent(event
);
854 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
856 bool wxPropertyListFrame::OnClose(void)
859 return view
->OnClose();
864 wxPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
866 return new wxPropertyListPanel(v
, parent
);
869 bool wxPropertyListFrame::Initialize(void)
871 propertyPanel
= OnCreatePanel(this, view
);
874 view
->AssociatePanel(propertyPanel
);
875 view
->SetManagedWindow(this);
876 propertyPanel
->SetAutoLayout(TRUE
);
884 * Property list specific validator
887 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
889 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
891 // view->GetValueText()->Show(TRUE);
893 OnDisplayValue(property
, view
, parentWindow
);
898 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
900 wxString
s(view
->GetValueList()->GetStringSelection());
903 view
->GetValueText()->SetValue(s
);
904 view
->RetrieveProperty(property
);
909 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
911 // view->GetValueText()->Show(TRUE);
912 wxString
str(property
->GetValue().GetStringRepresentation());
914 view
->GetValueText()->SetValue(str
.GetData());
918 // Called when TICK is pressed or focus is lost or view wants to update
919 // the property list.
920 // Does the transferance from the property editing area to the property itself
921 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
923 if (!view
->GetValueText())
928 void wxPropertyListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
930 if (view
->GetDetailedEditing())
931 view
->EndDetailedEditing();
933 view
->BeginDetailedEditing();
936 bool wxPropertyListValidator::OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
938 if (view
->GetConfirmButton())
939 view
->GetConfirmButton()->Enable(FALSE
);
940 if (view
->GetCancelButton())
941 view
->GetCancelButton()->Enable(FALSE
);
942 if (view
->GetEditButton())
943 view
->GetEditButton()->Enable(FALSE
);
951 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
954 /// Real number validator
956 bool wxRealListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
958 if (realMin
== 0.0 && realMax
== 0.0)
961 if (!view
->GetValueText())
963 wxString
value(view
->GetValueText()->GetValue());
966 if (!StringToFloat(WXSTRINGCAST value
, &val
))
969 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
970 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
974 if (val
< realMin
|| val
> realMax
)
977 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", realMin
, realMax
);
978 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
984 // Called when TICK is pressed or focus is lost or view wants to update
985 // the property list.
986 // Does the transferance from the property editing area to the property itself
987 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
989 if (!view
->GetValueText())
992 if (strlen(view
->GetValueText()->GetValue()) == 0)
995 wxString
value(view
->GetValueText()->GetValue());
996 float f
= (float)atof(value
.GetData());
997 property
->GetValue() = f
;
1001 bool wxRealListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1003 if (view
->GetConfirmButton())
1004 view
->GetConfirmButton()->Enable(TRUE
);
1005 if (view
->GetCancelButton())
1006 view
->GetCancelButton()->Enable(TRUE
);
1007 if (view
->GetEditButton())
1008 view
->GetEditButton()->Enable(FALSE
);
1009 if (view
->GetValueText())
1010 view
->GetValueText()->Enable(TRUE
);
1015 /// Integer validator
1017 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1019 bool wxIntegerListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1021 if (integerMin
== 0 && integerMax
== 0)
1024 if (!view
->GetValueText())
1026 wxString
value(view
->GetValueText()->GetValue());
1029 if (!StringToLong(WXSTRINGCAST value
, &val
))
1032 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1033 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1036 if (val
< integerMin
|| val
> integerMax
)
1039 sprintf(buf
, "Value must be an integer between %ld and %ld!", integerMin
, integerMax
);
1040 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1046 // Called when TICK is pressed or focus is lost or view wants to update
1047 // the property list.
1048 // Does the transferance from the property editing area to the property itself
1049 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1051 if (!view
->GetValueText())
1054 if (strlen(view
->GetValueText()->GetValue()) == 0)
1057 wxString
value(view
->GetValueText()->GetValue());
1058 long val
= (long)atoi(value
.GetData());
1059 property
->GetValue() = (long)val
;
1063 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1065 if (view
->GetConfirmButton())
1066 view
->GetConfirmButton()->Enable(TRUE
);
1067 if (view
->GetCancelButton())
1068 view
->GetCancelButton()->Enable(TRUE
);
1069 if (view
->GetEditButton())
1070 view
->GetEditButton()->Enable(FALSE
);
1071 if (view
->GetValueText())
1072 view
->GetValueText()->Enable(TRUE
);
1077 /// boolean validator
1079 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1081 bool wxBoolListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1083 if (!view
->GetValueText())
1085 wxString
value(view
->GetValueText()->GetValue());
1086 if (value
!= "True" && value
!= "False")
1088 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1094 // Called when TICK is pressed or focus is lost or view wants to update
1095 // the property list.
1096 // Does the transferance from the property editing area to the property itself
1097 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1099 if (!view
->GetValueText())
1102 if (strlen(view
->GetValueText()->GetValue()) == 0)
1105 wxString
value(view
->GetValueText()->GetValue());
1106 bool boolValue
= FALSE
;
1107 if (value
== "True")
1111 property
->GetValue() = (bool)boolValue
;
1115 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1117 if (!view
->GetValueText())
1119 wxString
str(property
->GetValue().GetStringRepresentation());
1121 view
->GetValueText()->SetValue(str
.GetData());
1122 view
->GetValueList()->SetStringSelection(str
.GetData());
1126 bool wxBoolListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1128 if (view
->GetConfirmButton())
1129 view
->GetConfirmButton()->Enable(FALSE
);
1130 if (view
->GetCancelButton())
1131 view
->GetCancelButton()->Enable(FALSE
);
1132 if (view
->GetEditButton())
1133 view
->GetEditButton()->Enable(TRUE
);
1134 if (view
->GetValueText())
1135 view
->GetValueText()->Enable(FALSE
);
1139 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1141 if (view
->GetValueList())
1143 view
->ShowListBoxControl(TRUE
);
1144 view
->GetValueList()->Enable(TRUE
);
1146 view
->GetValueList()->Append("True");
1147 view
->GetValueList()->Append("False");
1148 char *currentString
= copystring(view
->GetValueText()->GetValue());
1149 view
->GetValueList()->SetStringSelection(currentString
);
1150 delete[] currentString
;
1155 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1157 if (view
->GetValueList())
1159 view
->GetValueList()->Clear();
1160 view
->ShowListBoxControl(FALSE
);
1161 view
->GetValueList()->Enable(FALSE
);
1166 // Called when the property is double clicked. Extra functionality can be provided,
1167 // cycling through possible values.
1168 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1170 if (!view
->GetValueText())
1172 if (property
->GetValue().BoolValue())
1173 property
->GetValue() = (bool)FALSE
;
1175 property
->GetValue() = (bool)TRUE
;
1176 view
->DisplayProperty(property
);
1177 view
->UpdatePropertyDisplayInList(property
);
1178 view
->OnPropertyChanged(property
);
1183 /// String validator
1185 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1187 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1188 wxPropertyListValidator(flags
)
1191 // If no constraint, we just allow the string to be edited.
1192 if (!strings
&& ((validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1193 validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1196 bool wxStringListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1201 if (!view
->GetValueText())
1203 wxString
value(view
->GetValueText()->GetValue());
1205 if (!strings
->Member(value
.GetData()))
1207 wxString
s("Value ");
1208 s
+= value
.GetData();
1209 s
+= " is not valid.";
1210 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1216 // Called when TICK is pressed or focus is lost or view wants to update
1217 // the property list.
1218 // Does the transferance from the property editing area to the property itself
1219 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1221 if (!view
->GetValueText())
1223 wxString
value(view
->GetValueText()->GetValue());
1224 property
->GetValue() = value
;
1228 // Called when TICK is pressed or focus is lost or view wants to update
1229 // the property list.
1230 // Does the transferance from the property editing area to the property itself
1231 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1233 if (!view
->GetValueText())
1235 wxString
str(property
->GetValue().GetStringRepresentation());
1236 view
->GetValueText()->SetValue(str
.GetData());
1239 view
->GetValueList()->SetStringSelection(str
.GetData());
1244 bool wxStringListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1249 if (view
->GetEditButton())
1250 view
->GetEditButton()->Enable(FALSE
);
1251 if (view
->GetConfirmButton())
1252 view
->GetConfirmButton()->Enable(TRUE
);
1253 if (view
->GetCancelButton())
1254 view
->GetCancelButton()->Enable(TRUE
);
1255 if (view
->GetValueText())
1256 view
->GetValueText()->Enable(TRUE
);
1261 if (view
->GetValueText())
1262 view
->GetValueText()->Enable(FALSE
);
1264 if (view
->GetEditButton())
1265 view
->GetEditButton()->Enable(TRUE
);
1267 if (view
->GetConfirmButton())
1268 view
->GetConfirmButton()->Enable(FALSE
);
1269 if (view
->GetCancelButton())
1270 view
->GetCancelButton()->Enable(FALSE
);
1274 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1276 if (view
->GetValueList())
1278 view
->ShowListBoxControl(TRUE
);
1279 view
->GetValueList()->Enable(TRUE
);
1280 wxNode
*node
= strings
->First();
1283 char *s
= (char *)node
->Data();
1284 view
->GetValueList()->Append(s
);
1285 node
= node
->Next();
1287 char *currentString
= property
->GetValue().StringValue();
1288 view
->GetValueList()->SetStringSelection(currentString
);
1293 bool wxStringListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1300 if (view
->GetValueList())
1302 view
->GetValueList()->Clear();
1303 view
->ShowListBoxControl(FALSE
);
1304 view
->GetValueList()->Enable(FALSE
);
1309 // Called when the property is double clicked. Extra functionality can be provided,
1310 // cycling through possible values.
1311 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1313 if (!view
->GetValueText())
1318 wxNode
*node
= strings
->First();
1319 char *currentString
= property
->GetValue().StringValue();
1322 char *s
= (char *)node
->Data();
1323 if (strcmp(s
, currentString
) == 0)
1325 char *nextString
= NULL
;
1327 nextString
= (char *)node
->Next()->Data();
1329 nextString
= (char *)strings
->First()->Data();
1330 property
->GetValue() = wxString(nextString
);
1331 view
->DisplayProperty(property
);
1332 view
->UpdatePropertyDisplayInList(property
);
1333 view
->OnPropertyChanged(property
);
1336 else node
= node
->Next();
1342 /// Filename validator
1344 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1346 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1347 wxPropertyListValidator(flags
), filenameWildCard(wildcard
), filenameMessage(message
)
1351 wxFilenameListValidator::~wxFilenameListValidator(void)
1355 bool wxFilenameListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1360 // Called when TICK is pressed or focus is lost or view wants to update
1361 // the property list.
1362 // Does the transferance from the property editing area to the property itself
1363 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1365 if (!view
->GetValueText())
1367 wxString
value(view
->GetValueText()->GetValue());
1368 property
->GetValue() = value
;
1372 // Called when TICK is pressed or focus is lost or view wants to update
1373 // the property list.
1374 // Does the transferance from the property editing area to the property itself
1375 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1377 if (!view
->GetValueText())
1379 wxString
str(property
->GetValue().GetStringRepresentation());
1380 view
->GetValueText()->SetValue(str
);
1384 // Called when the property is double clicked. Extra functionality can be provided,
1385 // cycling through possible values.
1386 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1388 if (!view
->GetValueText())
1390 OnEdit(property
, view
, parentWindow
);
1394 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1396 if (view
->GetConfirmButton())
1397 view
->GetConfirmButton()->Enable(TRUE
);
1398 if (view
->GetCancelButton())
1399 view
->GetCancelButton()->Enable(TRUE
);
1400 if (view
->GetEditButton())
1401 view
->GetEditButton()->Enable(TRUE
);
1402 if (view
->GetValueText())
1403 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1407 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1409 if (!view
->GetValueText())
1412 char *s
= wxFileSelector(
1413 filenameMessage
.GetData(),
1414 wxPathOnly(property
->GetValue().StringValue()),
1415 wxFileNameFromPath(property
->GetValue().StringValue()),
1417 filenameWildCard
.GetData(),
1422 property
->GetValue() = wxString(s
);
1423 view
->DisplayProperty(property
);
1424 view
->UpdatePropertyDisplayInList(property
);
1425 view
->OnPropertyChanged(property
);
1430 /// Colour validator
1432 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1434 wxColourListValidator::wxColourListValidator(long flags
):
1435 wxPropertyListValidator(flags
)
1439 wxColourListValidator::~wxColourListValidator(void)
1443 bool wxColourListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1448 // Called when TICK is pressed or focus is lost or view wants to update
1449 // the property list.
1450 // Does the transferance from the property editing area to the property itself
1451 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1453 if (!view
->GetValueText())
1455 wxString
value(view
->GetValueText()->GetValue());
1457 property
->GetValue() = value
;
1461 // Called when TICK is pressed or focus is lost or view wants to update
1462 // the property list.
1463 // Does the transferance from the property editing area to the property itself
1464 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1466 if (!view
->GetValueText())
1468 wxString
str(property
->GetValue().GetStringRepresentation());
1469 view
->GetValueText()->SetValue(str
);
1473 // Called when the property is double clicked. Extra functionality can be provided,
1474 // cycling through possible values.
1475 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1477 if (!view
->GetValueText())
1479 OnEdit(property
, view
, parentWindow
);
1483 bool wxColourListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1485 if (view
->GetConfirmButton())
1486 view
->GetConfirmButton()->Enable(TRUE
);
1487 if (view
->GetCancelButton())
1488 view
->GetCancelButton()->Enable(TRUE
);
1489 if (view
->GetEditButton())
1490 view
->GetEditButton()->Enable(TRUE
);
1491 if (view
->GetValueText())
1492 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1496 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1498 if (!view
->GetValueText())
1501 char *s
= property
->GetValue().StringValue();
1508 g
= wxHexToDec(s
+2);
1509 b
= wxHexToDec(s
+4);
1512 wxColour
col(r
,g
,b
);
1515 data
.SetChooseFull(TRUE
);
1516 data
.SetColour(col
);
1518 for (int i
= 0; i
< 16; i
++)
1520 wxColour
colour(i
*16, i
*16, i
*16);
1521 data
.SetCustomColour(i
, colour
);
1524 wxColourDialog
dialog(parentWindow
, &data
);
1525 if (dialog
.ShowModal() != wxID_CANCEL
)
1527 wxColourData retData
= dialog
.GetColourData();
1528 col
= retData
.GetColour();
1531 wxDecToHex(col
.Red(), buf
);
1532 wxDecToHex(col
.Green(), buf
+2);
1533 wxDecToHex(col
.Blue(), buf
+4);
1535 property
->GetValue() = wxString(buf
);
1536 view
->DisplayProperty(property
);
1537 view
->UpdatePropertyDisplayInList(property
);
1538 view
->OnPropertyChanged(property
);
1543 /// List of strings validator. For this we need more user interface than
1544 /// we get with a property list; so create a new dialog for editing the list.
1546 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1548 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1549 wxPropertyListValidator(flags
)
1553 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1555 // No constraints for an arbitrary, user-editable list of strings.
1559 // Called when TICK is pressed or focus is lost or view wants to update
1560 // the property list.
1561 // Does the transferance from the property editing area to the property itself.
1562 // In this case, the user cannot directly edit the string list.
1563 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1568 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1570 if (!view
->GetValueText())
1572 wxString
str(property
->GetValue().GetStringRepresentation());
1573 view
->GetValueText()->SetValue(str
.GetData());
1577 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1579 if (view
->GetEditButton())
1580 view
->GetEditButton()->Enable(TRUE
);
1581 if (view
->GetValueText())
1582 view
->GetValueText()->Enable(FALSE
);
1584 if (view
->GetConfirmButton())
1585 view
->GetConfirmButton()->Enable(FALSE
);
1586 if (view
->GetCancelButton())
1587 view
->GetCancelButton()->Enable(FALSE
);
1591 // Called when the property is double clicked. Extra functionality can be provided,
1592 // cycling through possible values.
1593 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1595 OnEdit(property
, view
, parentWindow
);
1599 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1601 // Convert property value to a list of strings for editing
1602 wxStringList
*stringList
= new wxStringList
;
1604 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1607 char *s
= expr
->StringValue();
1610 expr
= expr
->GetNext();
1613 wxString
title("Editing ");
1614 title
+= property
->GetName();
1616 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1618 wxPropertyValue
& oldValue
= property
->GetValue();
1619 oldValue
.ClearList();
1620 wxNode
*node
= stringList
->First();
1623 char *s
= (char *)node
->Data();
1624 oldValue
.Append(new wxPropertyValue(s
));
1626 node
= node
->Next();
1629 view
->DisplayProperty(property
);
1630 view
->UpdatePropertyDisplayInList(property
);
1631 view
->OnPropertyChanged(property
);
1636 class wxPropertyStringListEditorDialog
: public wxDialog
1639 wxStringList
*stringList
;
1641 wxTextCtrl
*stringText
;
1642 static bool dialogCancelled
;
1643 int currentSelection
;
1644 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1645 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1646 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1647 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1652 dialogCancelled
= FALSE
;
1653 currentSelection
= -1;
1655 ~wxPropertyStringListEditorDialog(void) {}
1657 void SaveCurrentSelection(void);
1658 void ShowCurrentSelection(void);
1660 void OnOK(wxCommandEvent
& event
);
1661 void OnCancel(wxCommandEvent
& event
);
1662 void OnAdd(wxCommandEvent
& event
);
1663 void OnDelete(wxCommandEvent
& event
);
1664 void OnStrings(wxCommandEvent
& event
);
1665 void OnText(wxCommandEvent
& event
);
1667 DECLARE_EVENT_TABLE()
1670 #define wxID_PROP_SL_ADD 3000
1671 #define wxID_PROP_SL_DELETE 3001
1672 #define wxID_PROP_SL_STRINGS 3002
1673 #define wxID_PROP_SL_TEXT 3003
1675 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1676 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1677 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1678 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1679 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1680 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1681 EVT_TEXT(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1684 class wxPropertyStringListEditorText
: public wxTextCtrl
1687 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1688 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1689 long windowStyle
= 0, const wxString
& name
= "text"):
1690 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1693 void OnKillFocus(void)
1695 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1696 dialog
->SaveCurrentSelection();
1700 bool wxPropertyStringListEditorDialog::dialogCancelled
= FALSE
;
1702 // Edit the string list.
1703 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1705 wxBeginBusyCursor();
1706 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1707 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1709 dialog
->stringList
= stringList
;
1711 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(5, 5));
1712 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(40, 5));
1714 // wxButton *helpButton = new wxButton(dialog, (wxFunction)StringListEditorHelpProc, "Help");
1715 // helpButton->SetClientData((char *)this);
1717 dialog
->listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1718 wxPoint(5, 30), wxSize(300, 200), 0, NULL
, wxLB_SINGLE
);
1720 dialog
->stringText
= new wxPropertyStringListEditorText(dialog
,
1721 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1722 wxSize(300, -1), wxPROCESS_ENTER
);
1723 dialog
->stringText
->Enable(FALSE
);
1725 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(5, 280));
1726 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(40, 280));
1728 wxNode
*node
= stringList
->First();
1731 char *str
= (char *)node
->Data();
1732 // Save node as client data for each listbox item
1733 dialog
->listBox
->Append(str
, (char *)node
);
1734 node
= node
->Next();
1737 dialog
->SetClientSize(310, 305);
1739 dialog
->Centre(wxBOTH
);
1741 if (dialog
->ShowModal() == wxID_CANCEL
)
1748 * String list editor callbacks
1752 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& event
)
1754 int sel
= listBox
->GetSelection();
1757 currentSelection
= sel
;
1759 ShowCurrentSelection();
1763 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& event
)
1765 int sel
= listBox
->GetSelection();
1769 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(sel
);
1773 listBox
->Delete(sel
);
1774 delete[] (char *)node
->Data();
1776 currentSelection
= -1;
1777 stringText
->SetValue("");
1780 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& event
)
1782 SaveCurrentSelection();
1784 char *initialText
= "";
1785 wxNode
*node
= stringList
->Add(initialText
);
1786 listBox
->Append(initialText
, (char *)node
);
1787 currentSelection
= stringList
->Number() - 1;
1788 listBox
->SetSelection(currentSelection
);
1789 ShowCurrentSelection();
1790 stringText
->SetFocus();
1793 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& event
)
1795 SaveCurrentSelection();
1800 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& event
)
1802 dialogCancelled
= TRUE
;
1803 EndModal(wxID_CANCEL
);
1807 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1809 if (event
.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND
)
1811 SaveCurrentSelection();
1815 bool wxPropertyStringListEditorDialog::OnClose(void)
1817 SaveCurrentSelection();
1821 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1823 if (currentSelection
== -1)
1826 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(currentSelection
);
1830 wxString
txt(stringText
->GetValue());
1832 delete[] (char *)node
->Data();
1833 node
->SetData((wxObject
*)copystring(txt
));
1835 listBox
->SetString(currentSelection
, (char *)node
->Data());
1838 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1840 if (currentSelection
== -1)
1842 stringText
->SetValue("");
1845 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(currentSelection
);
1846 char *txt
= (char *)node
->Data();
1847 stringText
->SetValue(txt
);
1848 stringText
->Enable(TRUE
);