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
*WXUNUSED(property
))
381 // Called by the listbox callback
382 void wxPropertyListView::OnPropertySelect(wxCommandEvent
& WXUNUSED(event
))
384 int sel
= propertyScrollingList
->GetSelection();
387 wxProperty
*newSel
= (wxProperty
*)propertyScrollingList
->wxListBox::GetClientData(sel
);
388 if (newSel
&& newSel
!= currentProperty
)
390 ShowProperty(newSel
, FALSE
);
395 bool wxPropertyListView::CreateControls(void)
397 wxPanel
*panel
= (wxPanel
*)propertyWindow
;
399 int largeButtonWidth
= 60;
400 int largeButtonHeight
= 25;
402 int smallButtonWidth
= 25;
403 int smallButtonHeight
= 20;
405 // XView must be allowed to choose its own sized buttons
407 largeButtonWidth
= -1;
408 largeButtonHeight
= -1;
410 smallButtonWidth
= -1;
411 smallButtonHeight
= -1;
420 wxWindow
*leftMostWindow
= panel
;
421 wxWindow
*topMostWindow
= panel
;
422 wxWindow
*rightMostWindow
= panel
;
424 wxSystemSettings settings
;
425 wxFont guiFont
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
428 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxDEFAULT
, wxNORMAL
, wxNORMAL
, FALSE
, "Courier New");
430 wxFont
*boringFont
= wxTheFontList
->FindOrCreateFont(guiFont
.GetPointSize(), wxMODERN
, wxNORMAL
, wxNORMAL
);
433 // May need to be changed in future to eliminate clashes with app.
434 panel
->SetClientData((char *)this);
436 // These buttons are at the bottom of the window, but create them now
437 // so the constraints are evaluated in the correct order
438 if (buttonFlags
& wxPROP_BUTTON_OK
)
440 windowCloseButton
= new wxButton(panel
, wxID_OK
, "OK",
441 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
442 windowCloseButton
->SetDefault();
443 windowCloseButton
->SetFocus();
445 else if (buttonFlags
& wxPROP_BUTTON_CLOSE
)
447 windowCloseButton
= new wxButton(panel
, wxID_OK
, "Close",
448 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
450 if (buttonFlags
& wxPROP_BUTTON_CANCEL
)
452 windowCancelButton
= new wxButton(panel
, wxID_CANCEL
, "Cancel",
453 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
455 if (buttonFlags
& wxPROP_BUTTON_HELP
)
457 windowHelpButton
= new wxButton(panel
, wxID_HELP
, "Help",
458 wxPoint(-1, -1), wxSize(largeButtonWidth
, largeButtonHeight
));
461 if (windowCloseButton
)
463 wxLayoutConstraints
*c1
= new wxLayoutConstraints
;
465 c1
->left
.SameAs (panel
, wxLeft
, 2);
466 c1
->bottom
.SameAs (panel
, wxBottom
, 2);
469 windowCloseButton
->SetConstraints(c1
);
470 leftMostWindow
= windowCloseButton
;
472 if (windowCancelButton
)
474 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
476 c2
->right
.SameAs (panel
, wxRight
, 2);
477 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
480 windowCancelButton
->SetConstraints(c2
);
481 leftMostWindow
= windowCancelButton
;
483 if (windowHelpButton
)
485 wxLayoutConstraints
*c2
= new wxLayoutConstraints
;
486 if (leftMostWindow
== panel
)
487 c2
->left
.SameAs (panel
, wxLeft
, 2);
489 c2
->left
.RightOf (leftMostWindow
, 2);
491 c2
->bottom
.SameAs (panel
, wxBottom
, 2);
494 windowHelpButton
->SetConstraints(c2
);
495 leftMostWindow
= windowHelpButton
;
498 if (buttonFlags
& wxPROP_BUTTON_CHECK_CROSS
)
504 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
505 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
506 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
519 if (tickBitmap && crossBitmap)
521 confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
522 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
523 cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
524 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
529 confirmButton
= new wxButton(panel
, wxID_PROP_CHECK
, ":-)",
530 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
531 cancelButton
= new wxButton(panel
, wxID_PROP_CROSS
, "X",
532 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
535 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
536 c
->left
.SameAs (panel
, wxLeft
, 2);
538 if (windowCloseButton)
539 c->top.Below (windowCloseButton, 2);
542 c
->top
.SameAs (panel
, wxTop
, 2);
547 cancelButton
->SetConstraints(c
);
549 c
= new wxLayoutConstraints
;
550 c
->left
.RightOf (cancelButton
, 2);
551 c
->top
.SameAs (cancelButton
, wxTop
, 0);
555 confirmButton
->SetConstraints(c
);
557 cancelButton
->Enable(FALSE
);
558 confirmButton
->Enable(FALSE
);
561 if (buttonFlags
& wxPROP_PULLDOWN
)
563 editButton
= new wxButton(panel
, wxID_PROP_EDIT
, "...",
564 wxPoint(-1, -1), wxSize(smallButtonWidth
, smallButtonHeight
));
565 editButton
->Enable(FALSE
);
566 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
569 if (windowCloseButton)
570 c->top.Below (windowCloseButton, 2);
573 c
->top
.SameAs (panel
, wxTop
, 2);
575 c
->right
.SameAs (panel
, wxRight
, 2);
578 editButton
->SetConstraints(c
);
581 valueText
= new wxPropertyTextEdit(this, panel
, wxID_PROP_TEXT
, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER
);
582 valueText
->Enable(FALSE
);
584 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
587 c
->left
.RightOf (confirmButton
, 2);
589 c
->left
.SameAs (panel
, wxLeft
, 2);
591 if (windowCloseButton)
592 c->top.Below (windowCloseButton, 2);
595 c
->top
.SameAs (panel
, wxTop
, 2);
598 c
->right
.LeftOf (editButton
, 2);
600 c
->right
.SameAs (panel
, wxRight
, 2);
603 valueText
->SetConstraints(c
);
605 valueList
= new wxListBox(panel
, wxID_PROP_VALUE_SELECT
, wxPoint(-1, -1), wxSize(-1, 60));
606 valueList
->Show(FALSE
);
608 c
= new wxLayoutConstraints
;
610 c
->left
.SameAs (panel
, wxLeft
, 2);
611 c
->top
.Below (valueText
, 2);
612 c
->right
.SameAs (panel
, wxRight
, 2);
613 c
->height
.Absolute(60);
615 valueList
->SetConstraints(c
);
617 propertyScrollingList
= new wxListBox(panel
, wxID_PROP_SELECT
,
618 wxPoint(-1, -1), wxSize(300, 300));
619 propertyScrollingList
->SetFont(boringFont
);
621 c
= new wxLayoutConstraints
;
623 c
->left
.SameAs (panel
, wxLeft
, 2);
625 if (buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
626 c
->top
.Below (valueText
, 2);
628 c
->top
.Below (valueList
, 2);
630 c
->right
.SameAs (panel
, wxRight
, 2);
632 if (windowCloseButton
)
633 c
->bottom
.Above (windowCloseButton
, -2);
635 c
->bottom
.SameAs (panel
, wxBottom
, 2);
637 propertyScrollingList
->SetConstraints(c
);
640 // Note: if this is called now, it causes a GPF.
647 void wxPropertyListView::ShowTextControl(bool show
)
650 valueText
->Show(show
);
653 void wxPropertyListView::ShowListBoxControl(bool show
)
657 valueList
->Show(show
);
658 if (buttonFlags
& wxPROP_DYNAMIC_VALUE_FIELD
)
660 wxLayoutConstraints
*constraints
= propertyScrollingList
->GetConstraints();
664 constraints
->top
.Below(valueList
, 2);
666 constraints
->top
.Below(valueText
, 2);
667 propertyWindow
->Layout();
673 void wxPropertyListView::EnableCheck(bool show
)
676 confirmButton
->Enable(show
);
679 void wxPropertyListView::EnableCross(bool show
)
682 cancelButton
->Enable(show
);
685 bool wxPropertyListView::OnClose(void)
687 // Retrieve the value if any
688 wxCommandEvent event
;
695 void wxPropertyListView::OnValueListSelect(wxCommandEvent
& WXUNUSED(event
))
697 if (currentProperty
&& currentValidator
)
699 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
702 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
704 listValidator
->OnValueListSelect(currentProperty
, this, propertyWindow
);
708 void wxPropertyListView::OnOk(wxCommandEvent
& event
)
710 // Retrieve the value if any
713 managedWindow
->Close(TRUE
);
716 void wxPropertyListView::OnCancel(wxCommandEvent
& WXUNUSED(event
))
718 // SetReturnCode(wxID_CANCEL);
719 managedWindow
->Close(TRUE
);
720 dialogCancelled
= TRUE
;
723 void wxPropertyListView::OnHelp(wxCommandEvent
& WXUNUSED(event
))
727 void wxPropertyListView::OnCheck(wxCommandEvent
& WXUNUSED(event
))
731 RetrieveProperty(currentProperty
);
735 void wxPropertyListView::OnCross(wxCommandEvent
& WXUNUSED(event
))
737 if (currentProperty
&& currentValidator
)
739 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
742 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
744 // Revert to old value
745 listValidator
->OnDisplayValue(currentProperty
, this, propertyWindow
);
749 void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent
& WXUNUSED(event
))
751 if (currentProperty
&& currentValidator
)
753 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
756 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
758 // Revert to old value
759 listValidator
->OnDoubleClick(currentProperty
, this, propertyWindow
);
763 void wxPropertyListView::OnEdit(wxCommandEvent
& WXUNUSED(event
))
765 if (currentProperty
&& currentValidator
)
767 if (!currentValidator
->IsKindOf(CLASSINFO(wxPropertyListValidator
)))
770 wxPropertyListValidator
*listValidator
= (wxPropertyListValidator
*)currentValidator
;
772 listValidator
->OnEdit(currentProperty
, this, propertyWindow
);
776 void wxPropertyListView::OnText(wxCommandEvent
& event
)
778 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
785 * Property dialog box
788 IMPLEMENT_CLASS(wxPropertyListDialog
, wxDialog
)
790 BEGIN_EVENT_TABLE(wxPropertyListDialog
, wxDialog
)
791 EVT_BUTTON(wxID_CANCEL
, wxPropertyListDialog::OnCancel
)
794 wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
,
795 const wxString
& title
, const wxPoint
& pos
,
796 const wxSize
& size
, long style
, const wxString
& name
):
797 wxDialog(parent
, -1, title
, pos
, size
, style
, name
)
800 view
->AssociatePanel( ((wxPanel
*)this) );
801 view
->SetManagedWindow(this);
805 bool wxPropertyListDialog::OnClose(void)
809 SetReturnCode(wxID_CANCEL
);
818 void wxPropertyListDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
820 SetReturnCode(wxID_CANCEL
);
824 void wxPropertyListDialog::OnDefaultAction(wxControl
*item
)
827 if (item == view->GetPropertyScrollingList())
828 view->OnDoubleClick();
832 // Extend event processing to search the view's event table
833 bool wxPropertyListDialog::ProcessEvent(wxEvent
& event
)
835 if ( !view
|| ! view
->ProcessEvent(event
) )
836 return wxEvtHandler::ProcessEvent(event
);
845 IMPLEMENT_CLASS(wxPropertyListPanel
, wxPanel
)
847 BEGIN_EVENT_TABLE(wxPropertyListPanel
, wxPanel
)
848 EVT_SIZE(wxPropertyListPanel::OnSize
)
851 void wxPropertyListPanel::OnDefaultAction(wxControl
*item
)
854 if (item == view->GetPropertyScrollingList())
855 view->OnDoubleClick();
859 // Extend event processing to search the view's event table
860 bool wxPropertyListPanel::ProcessEvent(wxEvent
& event
)
862 if ( !view
|| ! view
->ProcessEvent(event
) )
863 return wxEvtHandler::ProcessEvent(event
);
868 void wxPropertyListPanel::OnSize(wxSizeEvent
& WXUNUSED(event
))
877 IMPLEMENT_CLASS(wxPropertyListFrame
, wxFrame
)
879 bool wxPropertyListFrame::OnClose(void)
884 propertyPanel
->SetView(NULL
);
893 wxPropertyListPanel
*wxPropertyListFrame::OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
)
895 return new wxPropertyListPanel(v
, parent
);
898 bool wxPropertyListFrame::Initialize(void)
900 propertyPanel
= OnCreatePanel(this, view
);
903 view
->AssociatePanel(propertyPanel
);
904 view
->SetManagedWindow(this);
905 propertyPanel
->SetAutoLayout(TRUE
);
913 * Property list specific validator
916 IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator
, wxPropertyValidator
)
918 bool wxPropertyListValidator::OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
920 // view->GetValueText()->Show(TRUE);
922 OnDisplayValue(property
, view
, parentWindow
);
927 bool wxPropertyListValidator::OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
929 wxString
s(view
->GetValueList()->GetStringSelection());
932 view
->GetValueText()->SetValue(s
);
933 view
->RetrieveProperty(property
);
938 bool wxPropertyListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
940 // view->GetValueText()->Show(TRUE);
941 wxString
str(property
->GetValue().GetStringRepresentation());
943 view
->GetValueText()->SetValue(str
.GetData());
947 // Called when TICK is pressed or focus is lost or view wants to update
948 // the property list.
949 // Does the transferance from the property editing area to the property itself
950 bool wxPropertyListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
952 if (!view
->GetValueText())
957 void wxPropertyListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
959 if (view
->GetDetailedEditing())
960 view
->EndDetailedEditing();
962 view
->BeginDetailedEditing();
965 bool wxPropertyListValidator::OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
967 if (view
->GetConfirmButton())
968 view
->GetConfirmButton()->Enable(FALSE
);
969 if (view
->GetCancelButton())
970 view
->GetCancelButton()->Enable(FALSE
);
971 if (view
->GetEditButton())
972 view
->GetEditButton()->Enable(FALSE
);
980 IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator
, wxPropertyListValidator
)
983 /// Real number validator
985 bool wxRealListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
987 if (realMin
== 0.0 && realMax
== 0.0)
990 if (!view
->GetValueText())
992 wxString
value(view
->GetValueText()->GetValue());
995 if (!StringToFloat(WXSTRINGCAST value
, &val
))
998 sprintf(buf
, "Value %s is not a valid real number!", value
.GetData());
999 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1003 if (val
< realMin
|| val
> realMax
)
1006 sprintf(buf
, "Value must be a real number between %.2f and %.2f!", realMin
, realMax
);
1007 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1013 // Called when TICK is pressed or focus is lost or view wants to update
1014 // the property list.
1015 // Does the transferance from the property editing area to the property itself
1016 bool wxRealListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1018 if (!view
->GetValueText())
1021 if (strlen(view
->GetValueText()->GetValue()) == 0)
1024 wxString
value(view
->GetValueText()->GetValue());
1025 float f
= (float)atof(value
.GetData());
1026 property
->GetValue() = f
;
1030 bool wxRealListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1032 if (view
->GetConfirmButton())
1033 view
->GetConfirmButton()->Enable(TRUE
);
1034 if (view
->GetCancelButton())
1035 view
->GetCancelButton()->Enable(TRUE
);
1036 if (view
->GetEditButton())
1037 view
->GetEditButton()->Enable(FALSE
);
1038 if (view
->GetValueText())
1039 view
->GetValueText()->Enable(TRUE
);
1044 /// Integer validator
1046 IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator
, wxPropertyListValidator
)
1048 bool wxIntegerListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1050 if (integerMin
== 0 && integerMax
== 0)
1053 if (!view
->GetValueText())
1055 wxString
value(view
->GetValueText()->GetValue());
1058 if (!StringToLong(WXSTRINGCAST value
, &val
))
1061 sprintf(buf
, "Value %s is not a valid integer!", value
.GetData());
1062 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1065 if (val
< integerMin
|| val
> integerMax
)
1068 sprintf(buf
, "Value must be an integer between %ld and %ld!", integerMin
, integerMax
);
1069 wxMessageBox(buf
, "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1075 // Called when TICK is pressed or focus is lost or view wants to update
1076 // the property list.
1077 // Does the transferance from the property editing area to the property itself
1078 bool wxIntegerListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1080 if (!view
->GetValueText())
1083 if (strlen(view
->GetValueText()->GetValue()) == 0)
1086 wxString
value(view
->GetValueText()->GetValue());
1087 long val
= (long)atoi(value
.GetData());
1088 property
->GetValue() = (long)val
;
1092 bool wxIntegerListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1094 if (view
->GetConfirmButton())
1095 view
->GetConfirmButton()->Enable(TRUE
);
1096 if (view
->GetCancelButton())
1097 view
->GetCancelButton()->Enable(TRUE
);
1098 if (view
->GetEditButton())
1099 view
->GetEditButton()->Enable(FALSE
);
1100 if (view
->GetValueText())
1101 view
->GetValueText()->Enable(TRUE
);
1106 /// boolean validator
1108 IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator
, wxPropertyListValidator
)
1110 bool wxBoolListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1112 if (!view
->GetValueText())
1114 wxString
value(view
->GetValueText()->GetValue());
1115 if (value
!= "True" && value
!= "False")
1117 wxMessageBox("Value must be True or False!", "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1123 // Called when TICK is pressed or focus is lost or view wants to update
1124 // the property list.
1125 // Does the transferance from the property editing area to the property itself
1126 bool wxBoolListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1128 if (!view
->GetValueText())
1131 if (strlen(view
->GetValueText()->GetValue()) == 0)
1134 wxString
value(view
->GetValueText()->GetValue());
1135 bool boolValue
= FALSE
;
1136 if (value
== "True")
1140 property
->GetValue() = (bool)boolValue
;
1144 bool wxBoolListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1146 if (!view
->GetValueText())
1148 wxString
str(property
->GetValue().GetStringRepresentation());
1150 view
->GetValueText()->SetValue(str
.GetData());
1151 view
->GetValueList()->SetStringSelection(str
.GetData());
1155 bool wxBoolListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1157 if (view
->GetConfirmButton())
1158 view
->GetConfirmButton()->Enable(FALSE
);
1159 if (view
->GetCancelButton())
1160 view
->GetCancelButton()->Enable(FALSE
);
1161 if (view
->GetEditButton())
1162 view
->GetEditButton()->Enable(TRUE
);
1163 if (view
->GetValueText())
1164 view
->GetValueText()->Enable(FALSE
);
1168 bool wxBoolListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1170 if (view
->GetValueList())
1172 view
->ShowListBoxControl(TRUE
);
1173 view
->GetValueList()->Enable(TRUE
);
1175 view
->GetValueList()->Append("True");
1176 view
->GetValueList()->Append("False");
1177 char *currentString
= copystring(view
->GetValueText()->GetValue());
1178 view
->GetValueList()->SetStringSelection(currentString
);
1179 delete[] currentString
;
1184 bool wxBoolListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1186 if (view
->GetValueList())
1188 view
->GetValueList()->Clear();
1189 view
->ShowListBoxControl(FALSE
);
1190 view
->GetValueList()->Enable(FALSE
);
1195 // Called when the property is double clicked. Extra functionality can be provided,
1196 // cycling through possible values.
1197 bool wxBoolListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1199 if (!view
->GetValueText())
1201 if (property
->GetValue().BoolValue())
1202 property
->GetValue() = (bool)FALSE
;
1204 property
->GetValue() = (bool)TRUE
;
1205 view
->DisplayProperty(property
);
1206 view
->UpdatePropertyDisplayInList(property
);
1207 view
->OnPropertyChanged(property
);
1212 /// String validator
1214 IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator
, wxPropertyListValidator
)
1216 wxStringListValidator::wxStringListValidator(wxStringList
*list
, long flags
):
1217 wxPropertyListValidator(flags
)
1220 // If no constraint, we just allow the string to be edited.
1221 if (!strings
&& ((validatorFlags
& wxPROP_ALLOW_TEXT_EDITING
) == 0))
1222 validatorFlags
|= wxPROP_ALLOW_TEXT_EDITING
;
1225 bool wxStringListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1230 if (!view
->GetValueText())
1232 wxString
value(view
->GetValueText()->GetValue());
1234 if (!strings
->Member(value
.GetData()))
1236 wxString
s("Value ");
1237 s
+= value
.GetData();
1238 s
+= " is not valid.";
1239 wxMessageBox(s
.GetData(), "Property value error", wxOK
| wxICON_EXCLAMATION
, parentWindow
);
1245 // Called when TICK is pressed or focus is lost or view wants to update
1246 // the property list.
1247 // Does the transferance from the property editing area to the property itself
1248 bool wxStringListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1250 if (!view
->GetValueText())
1252 wxString
value(view
->GetValueText()->GetValue());
1253 property
->GetValue() = value
;
1257 // Called when TICK is pressed or focus is lost or view wants to update
1258 // the property list.
1259 // Does the transferance from the property editing area to the property itself
1260 bool wxStringListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1262 if (!view
->GetValueText())
1264 wxString
str(property
->GetValue().GetStringRepresentation());
1265 view
->GetValueText()->SetValue(str
.GetData());
1268 view
->GetValueList()->SetStringSelection(str
.GetData());
1273 bool wxStringListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1278 if (view
->GetEditButton())
1279 view
->GetEditButton()->Enable(FALSE
);
1280 if (view
->GetConfirmButton())
1281 view
->GetConfirmButton()->Enable(TRUE
);
1282 if (view
->GetCancelButton())
1283 view
->GetCancelButton()->Enable(TRUE
);
1284 if (view
->GetValueText())
1285 view
->GetValueText()->Enable(TRUE
);
1290 if (view
->GetValueText())
1291 view
->GetValueText()->Enable(FALSE
);
1293 if (view
->GetEditButton())
1294 view
->GetEditButton()->Enable(TRUE
);
1296 if (view
->GetConfirmButton())
1297 view
->GetConfirmButton()->Enable(FALSE
);
1298 if (view
->GetCancelButton())
1299 view
->GetCancelButton()->Enable(FALSE
);
1303 bool wxStringListValidator::OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1305 if (view
->GetValueList())
1307 view
->ShowListBoxControl(TRUE
);
1308 view
->GetValueList()->Enable(TRUE
);
1309 wxNode
*node
= strings
->First();
1312 char *s
= (char *)node
->Data();
1313 view
->GetValueList()->Append(s
);
1314 node
= node
->Next();
1316 char *currentString
= property
->GetValue().StringValue();
1317 view
->GetValueList()->SetStringSelection(currentString
);
1322 bool wxStringListValidator::OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1329 if (view
->GetValueList())
1331 view
->GetValueList()->Clear();
1332 view
->ShowListBoxControl(FALSE
);
1333 view
->GetValueList()->Enable(FALSE
);
1338 // Called when the property is double clicked. Extra functionality can be provided,
1339 // cycling through possible values.
1340 bool wxStringListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1342 if (!view
->GetValueText())
1347 wxNode
*node
= strings
->First();
1348 char *currentString
= property
->GetValue().StringValue();
1351 char *s
= (char *)node
->Data();
1352 if (strcmp(s
, currentString
) == 0)
1354 char *nextString
= NULL
;
1356 nextString
= (char *)node
->Next()->Data();
1358 nextString
= (char *)strings
->First()->Data();
1359 property
->GetValue() = wxString(nextString
);
1360 view
->DisplayProperty(property
);
1361 view
->UpdatePropertyDisplayInList(property
);
1362 view
->OnPropertyChanged(property
);
1365 else node
= node
->Next();
1371 /// Filename validator
1373 IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator
, wxPropertyListValidator
)
1375 wxFilenameListValidator::wxFilenameListValidator(wxString message
, wxString wildcard
, long flags
):
1376 wxPropertyListValidator(flags
), filenameWildCard(wildcard
), filenameMessage(message
)
1380 wxFilenameListValidator::~wxFilenameListValidator(void)
1384 bool wxFilenameListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1389 // Called when TICK is pressed or focus is lost or view wants to update
1390 // the property list.
1391 // Does the transferance from the property editing area to the property itself
1392 bool wxFilenameListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1394 if (!view
->GetValueText())
1396 wxString
value(view
->GetValueText()->GetValue());
1397 property
->GetValue() = value
;
1401 // Called when TICK is pressed or focus is lost or view wants to update
1402 // the property list.
1403 // Does the transferance from the property editing area to the property itself
1404 bool wxFilenameListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1406 if (!view
->GetValueText())
1408 wxString
str(property
->GetValue().GetStringRepresentation());
1409 view
->GetValueText()->SetValue(str
);
1413 // Called when the property is double clicked. Extra functionality can be provided,
1414 // cycling through possible values.
1415 bool wxFilenameListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1417 if (!view
->GetValueText())
1419 OnEdit(property
, view
, parentWindow
);
1423 bool wxFilenameListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1425 if (view
->GetConfirmButton())
1426 view
->GetConfirmButton()->Enable(TRUE
);
1427 if (view
->GetCancelButton())
1428 view
->GetCancelButton()->Enable(TRUE
);
1429 if (view
->GetEditButton())
1430 view
->GetEditButton()->Enable(TRUE
);
1431 if (view
->GetValueText())
1432 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1436 void wxFilenameListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1438 if (!view
->GetValueText())
1441 char *s
= wxFileSelector(
1442 filenameMessage
.GetData(),
1443 wxPathOnly(property
->GetValue().StringValue()),
1444 wxFileNameFromPath(property
->GetValue().StringValue()),
1446 filenameWildCard
.GetData(),
1451 property
->GetValue() = wxString(s
);
1452 view
->DisplayProperty(property
);
1453 view
->UpdatePropertyDisplayInList(property
);
1454 view
->OnPropertyChanged(property
);
1459 /// Colour validator
1461 IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator
, wxPropertyListValidator
)
1463 wxColourListValidator::wxColourListValidator(long flags
):
1464 wxPropertyListValidator(flags
)
1468 wxColourListValidator::~wxColourListValidator(void)
1472 bool wxColourListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1477 // Called when TICK is pressed or focus is lost or view wants to update
1478 // the property list.
1479 // Does the transferance from the property editing area to the property itself
1480 bool wxColourListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1482 if (!view
->GetValueText())
1484 wxString
value(view
->GetValueText()->GetValue());
1486 property
->GetValue() = value
;
1490 // Called when TICK is pressed or focus is lost or view wants to update
1491 // the property list.
1492 // Does the transferance from the property editing area to the property itself
1493 bool wxColourListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1495 if (!view
->GetValueText())
1497 wxString
str(property
->GetValue().GetStringRepresentation());
1498 view
->GetValueText()->SetValue(str
);
1502 // Called when the property is double clicked. Extra functionality can be provided,
1503 // cycling through possible values.
1504 bool wxColourListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1506 if (!view
->GetValueText())
1508 OnEdit(property
, view
, parentWindow
);
1512 bool wxColourListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1514 if (view
->GetConfirmButton())
1515 view
->GetConfirmButton()->Enable(TRUE
);
1516 if (view
->GetCancelButton())
1517 view
->GetCancelButton()->Enable(TRUE
);
1518 if (view
->GetEditButton())
1519 view
->GetEditButton()->Enable(TRUE
);
1520 if (view
->GetValueText())
1521 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1525 void wxColourListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1527 if (!view
->GetValueText())
1530 char *s
= property
->GetValue().StringValue();
1537 g
= wxHexToDec(s
+2);
1538 b
= wxHexToDec(s
+4);
1541 wxColour
col(r
,g
,b
);
1544 data
.SetChooseFull(TRUE
);
1545 data
.SetColour(col
);
1547 for (int i
= 0; i
< 16; i
++)
1549 wxColour
colour(i
*16, i
*16, i
*16);
1550 data
.SetCustomColour(i
, colour
);
1553 wxColourDialog
dialog(parentWindow
, &data
);
1554 if (dialog
.ShowModal() != wxID_CANCEL
)
1556 wxColourData retData
= dialog
.GetColourData();
1557 col
= retData
.GetColour();
1560 wxDecToHex(col
.Red(), buf
);
1561 wxDecToHex(col
.Green(), buf
+2);
1562 wxDecToHex(col
.Blue(), buf
+4);
1564 property
->GetValue() = wxString(buf
);
1565 view
->DisplayProperty(property
);
1566 view
->UpdatePropertyDisplayInList(property
);
1567 view
->OnPropertyChanged(property
);
1572 /// List of strings validator. For this we need more user interface than
1573 /// we get with a property list; so create a new dialog for editing the list.
1575 IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator
, wxPropertyListValidator
)
1577 wxListOfStringsListValidator::wxListOfStringsListValidator(long flags
):
1578 wxPropertyListValidator(flags
)
1582 bool wxListOfStringsListValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1584 // No constraints for an arbitrary, user-editable list of strings.
1588 // Called when TICK is pressed or focus is lost or view wants to update
1589 // the property list.
1590 // Does the transferance from the property editing area to the property itself.
1591 // In this case, the user cannot directly edit the string list.
1592 bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1597 bool wxListOfStringsListValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1599 if (!view
->GetValueText())
1601 wxString
str(property
->GetValue().GetStringRepresentation());
1602 view
->GetValueText()->SetValue(str
.GetData());
1606 bool wxListOfStringsListValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1608 if (view
->GetEditButton())
1609 view
->GetEditButton()->Enable(TRUE
);
1610 if (view
->GetValueText())
1611 view
->GetValueText()->Enable(FALSE
);
1613 if (view
->GetConfirmButton())
1614 view
->GetConfirmButton()->Enable(FALSE
);
1615 if (view
->GetCancelButton())
1616 view
->GetCancelButton()->Enable(FALSE
);
1620 // Called when the property is double clicked. Extra functionality can be provided,
1621 // cycling through possible values.
1622 bool wxListOfStringsListValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1624 OnEdit(property
, view
, parentWindow
);
1628 void wxListOfStringsListValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1630 // Convert property value to a list of strings for editing
1631 wxStringList
*stringList
= new wxStringList
;
1633 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1636 char *s
= expr
->StringValue();
1639 expr
= expr
->GetNext();
1642 wxString
title("Editing ");
1643 title
+= property
->GetName();
1645 if (EditStringList(parentWindow
, stringList
, title
.GetData()))
1647 wxPropertyValue
& oldValue
= property
->GetValue();
1648 oldValue
.ClearList();
1649 wxNode
*node
= stringList
->First();
1652 char *s
= (char *)node
->Data();
1653 oldValue
.Append(new wxPropertyValue(s
));
1655 node
= node
->Next();
1658 view
->DisplayProperty(property
);
1659 view
->UpdatePropertyDisplayInList(property
);
1660 view
->OnPropertyChanged(property
);
1665 class wxPropertyStringListEditorDialog
: public wxDialog
1668 wxStringList
*stringList
;
1670 wxTextCtrl
*stringText
;
1671 static bool dialogCancelled
;
1672 int currentSelection
;
1673 wxPropertyStringListEditorDialog(wxWindow
*parent
, const wxString
& title
,
1674 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1675 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "stringEditorDialogBox"):
1676 wxDialog(parent
, -1, title
, pos
, size
, windowStyle
, name
)
1681 dialogCancelled
= FALSE
;
1682 currentSelection
= -1;
1684 ~wxPropertyStringListEditorDialog(void) {}
1686 void SaveCurrentSelection(void);
1687 void ShowCurrentSelection(void);
1689 void OnOK(wxCommandEvent
& event
);
1690 void OnCancel(wxCommandEvent
& event
);
1691 void OnAdd(wxCommandEvent
& event
);
1692 void OnDelete(wxCommandEvent
& event
);
1693 void OnStrings(wxCommandEvent
& event
);
1694 void OnText(wxCommandEvent
& event
);
1696 DECLARE_EVENT_TABLE()
1699 #define wxID_PROP_SL_ADD 3000
1700 #define wxID_PROP_SL_DELETE 3001
1701 #define wxID_PROP_SL_STRINGS 3002
1702 #define wxID_PROP_SL_TEXT 3003
1704 BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog
, wxDialog
)
1705 EVT_BUTTON(wxID_OK
, wxPropertyStringListEditorDialog::OnOK
)
1706 EVT_BUTTON(wxID_CANCEL
, wxPropertyStringListEditorDialog::OnCancel
)
1707 EVT_BUTTON(wxID_PROP_SL_ADD
, wxPropertyStringListEditorDialog::OnAdd
)
1708 EVT_BUTTON(wxID_PROP_SL_DELETE
, wxPropertyStringListEditorDialog::OnDelete
)
1709 EVT_LISTBOX(wxID_PROP_SL_STRINGS
, wxPropertyStringListEditorDialog::OnStrings
)
1710 EVT_TEXT(wxID_PROP_SL_TEXT
, wxPropertyStringListEditorDialog::OnText
)
1713 class wxPropertyStringListEditorText
: public wxTextCtrl
1716 wxPropertyStringListEditorText(wxWindow
*parent
, wxWindowID id
, const wxString
& val
,
1717 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
1718 long windowStyle
= 0, const wxString
& name
= "text"):
1719 wxTextCtrl(parent
, id
, val
, pos
, size
, windowStyle
, wxDefaultValidator
, name
)
1722 void OnKillFocus(void)
1724 wxPropertyStringListEditorDialog
*dialog
= (wxPropertyStringListEditorDialog
*)GetParent();
1725 dialog
->SaveCurrentSelection();
1729 bool wxPropertyStringListEditorDialog::dialogCancelled
= FALSE
;
1731 // Edit the string list.
1732 bool wxListOfStringsListValidator::EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
)
1734 wxBeginBusyCursor();
1735 wxPropertyStringListEditorDialog
*dialog
= new wxPropertyStringListEditorDialog(parent
,
1736 title
, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
);
1738 dialog
->stringList
= stringList
;
1740 wxButton
*okButton
= new wxButton(dialog
, wxID_OK
, "OK", wxPoint(5, 5));
1741 wxButton
*cancelButton
= new wxButton(dialog
, wxID_CANCEL
, "Cancel", wxPoint(40, 5));
1743 // wxButton *helpButton = new wxButton(dialog, (wxFunction)StringListEditorHelpProc, "Help");
1744 // helpButton->SetClientData((char *)this);
1746 dialog
->listBox
= new wxListBox(dialog
, wxID_PROP_SL_STRINGS
,
1747 wxPoint(5, 30), wxSize(300, 200), 0, NULL
, wxLB_SINGLE
);
1749 dialog
->stringText
= new wxPropertyStringListEditorText(dialog
,
1750 wxID_PROP_SL_TEXT
, "", wxPoint(5, 240),
1751 wxSize(300, -1), wxPROCESS_ENTER
);
1752 dialog
->stringText
->Enable(FALSE
);
1754 wxButton
*addButton
= new wxButton(dialog
, wxID_PROP_SL_ADD
, "Add", wxPoint(5, 280));
1755 wxButton
*deleteButton
= new wxButton(dialog
, wxID_PROP_SL_DELETE
, "Delete", wxPoint(40, 280));
1757 wxNode
*node
= stringList
->First();
1760 char *str
= (char *)node
->Data();
1761 // Save node as client data for each listbox item
1762 dialog
->listBox
->Append(str
, (char *)node
);
1763 node
= node
->Next();
1766 dialog
->SetClientSize(310, 305);
1768 dialog
->Centre(wxBOTH
);
1770 if (dialog
->ShowModal() == wxID_CANCEL
)
1777 * String list editor callbacks
1781 void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent
& WXUNUSED(event
))
1783 int sel
= listBox
->GetSelection();
1786 currentSelection
= sel
;
1788 ShowCurrentSelection();
1792 void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1794 int sel
= listBox
->GetSelection();
1798 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(sel
);
1802 listBox
->Delete(sel
);
1803 delete[] (char *)node
->Data();
1805 currentSelection
= -1;
1806 stringText
->SetValue("");
1809 void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent
& WXUNUSED(event
))
1811 SaveCurrentSelection();
1813 char *initialText
= "";
1814 wxNode
*node
= stringList
->Add(initialText
);
1815 listBox
->Append(initialText
, (char *)node
);
1816 currentSelection
= stringList
->Number() - 1;
1817 listBox
->SetSelection(currentSelection
);
1818 ShowCurrentSelection();
1819 stringText
->SetFocus();
1822 void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
1824 SaveCurrentSelection();
1829 void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
1831 dialogCancelled
= TRUE
;
1832 EndModal(wxID_CANCEL
);
1836 void wxPropertyStringListEditorDialog::OnText(wxCommandEvent
& event
)
1838 if (event
.GetEventType() == wxEVENT_TYPE_TEXT_ENTER_COMMAND
)
1840 SaveCurrentSelection();
1844 bool wxPropertyStringListEditorDialog::OnClose(void)
1846 SaveCurrentSelection();
1850 void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1852 if (currentSelection
== -1)
1855 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(currentSelection
);
1859 wxString
txt(stringText
->GetValue());
1861 delete[] (char *)node
->Data();
1862 node
->SetData((wxObject
*)copystring(txt
));
1864 listBox
->SetString(currentSelection
, (char *)node
->Data());
1867 void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1869 if (currentSelection
== -1)
1871 stringText
->SetValue("");
1874 wxNode
*node
= (wxNode
*)listBox
->wxListBox::GetClientData(currentSelection
);
1875 char *txt
= (char *)node
->Data();
1876 stringText
->SetValue(txt
);
1877 stringText
->Enable(TRUE
);