1 /////////////////////////////////////////////////////////////////////////////
2 // Name: custompropertydialog.cpp
3 // Purpose: Custom property dialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/statline.h"
23 #include "wx/splitter.h"
24 #include "wx/scrolwin.h"
25 #include "wx/spinctrl.h"
26 #include "wx/spinbutt.h"
30 #include "wx/cshelp.h"
31 #include "wx/valgen.h"
32 #include "custompropertydialog.h"
38 * ctCustomPropertyDialog type definition
41 IMPLEMENT_CLASS( ctCustomPropertyDialog
, wxDialog
)
44 * ctCustomPropertyDialog event table definition
47 BEGIN_EVENT_TABLE( ctCustomPropertyDialog
, wxDialog
)
49 ////@begin ctCustomPropertyDialog event table entries
50 EVT_UPDATE_UI( ID_PROPERTY_CHOICES
, ctCustomPropertyDialog::OnUpdatePropertyChoices
)
52 EVT_BUTTON( ID_PROPERTY_CHOICE_ADD
, ctCustomPropertyDialog::OnPropertyChoiceAdd
)
53 EVT_UPDATE_UI( ID_PROPERTY_CHOICE_ADD
, ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd
)
55 EVT_BUTTON( ID_PROPERTY_CHOICE_REMOVE
, ctCustomPropertyDialog::OnPropertyChoiceRemove
)
56 EVT_UPDATE_UI( ID_PROPERTY_CHOICE_REMOVE
, ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove
)
58 ////@end ctCustomPropertyDialog event table entries
63 * ctCustomPropertyDialog constructor
66 ctCustomPropertyDialog::ctCustomPropertyDialog( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
)
68 m_type
= wxT("string");
70 wxDialog::Create( parent
, id
, caption
);
76 * Control creation for ctCustomPropertyDialog
79 void ctCustomPropertyDialog::CreateControls()
81 ////@begin ctCustomPropertyDialog content construction
85 ctCustomPropertyDialog
* item1
= this;
87 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
88 item1
->SetSizer(item2
);
90 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
91 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
93 wxStaticText
* item4
= new wxStaticText(item1
, wxID_STATIC
, _("&Enter name, type and description for your custom property."), wxDefaultPosition
, wxDefaultSize
, 0);
94 item3
->Add(item4
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
96 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Name:"), wxDefaultPosition
, wxDefaultSize
, 0);
97 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
99 m_customPropertyName
= new wxTextCtrl(item1
, wxID_ANY
);
100 item3
->Add(m_customPropertyName
, 0, wxGROW
|wxALL
, 5);
102 wxBoxSizer
* item7
= new wxBoxSizer(wxHORIZONTAL
);
103 item3
->Add(item7
, 0, wxGROW
, 5);
105 wxBoxSizer
* item8
= new wxBoxSizer(wxVERTICAL
);
106 item7
->Add(item8
, 1, wxGROW
, 5);
108 wxStaticText
* item9
= new wxStaticText(item1
, wxID_STATIC
, _("&Data type:"), wxDefaultPosition
, wxDefaultSize
, 0);
109 item8
->Add(item9
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
112 items
.Add(_("string"));
113 items
.Add(_("bool"));
114 items
.Add(_("double"));
115 items
.Add(_("long"));
116 m_customPrototype
= new wxChoice(item1
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, items
);
117 m_customPrototype
->SetStringSelection(_("string"));
118 item8
->Add(m_customPrototype
, 1, wxGROW
|wxALL
, 5);
120 wxBoxSizer
* item11
= new wxBoxSizer(wxVERTICAL
);
121 item7
->Add(item11
, 0, wxALIGN_CENTER_VERTICAL
, 5);
123 wxStaticText
* item12
= new wxStaticText(item1
, wxID_STATIC
, _("&Editor type:"), wxDefaultPosition
, wxDefaultSize
, 0);
124 item11
->Add(item12
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
127 items
.Add(_("string"));
128 items
.Add(_("choice"));
129 items
.Add(_("bool"));
130 items
.Add(_("float"));
131 items
.Add(_("integer"));
132 items
.Add(_("configitems"));
133 m_customPropertyEditorType
= new wxChoice(item1
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, items
);
134 m_customPropertyEditorType
->SetStringSelection(_("string"));
135 item11
->Add(m_customPropertyEditorType
, 1, wxGROW
|wxALL
, 5);
137 wxStaticBox
* item14Static
= new wxStaticBox(item1
, wxID_ANY
, _("Choices"));
138 wxStaticBoxSizer
* item14
= new wxStaticBoxSizer(item14Static
, wxHORIZONTAL
);
139 item3
->Add(item14
, 0, wxGROW
|wxALL
, 5);
141 wxString
* item15Strings
= NULL
;
142 m_propertyChoices
= new wxListBox(item1
, ID_PROPERTY_CHOICES
, wxDefaultPosition
, wxDefaultSize
, 0, item15Strings
, wxLB_SINGLE
);
143 item14
->Add(m_propertyChoices
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
145 wxBoxSizer
* item16
= new wxBoxSizer(wxVERTICAL
);
146 item14
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
, 5);
148 wxButton
* item17
= new wxButton(item1
, ID_PROPERTY_CHOICE_ADD
, _("&Add..."), wxDefaultPosition
, wxDefaultSize
, 0);
149 item16
->Add(item17
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
151 wxButton
* item18
= new wxButton(item1
, ID_PROPERTY_CHOICE_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
152 item16
->Add(item18
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
154 wxStaticText
* item19
= new wxStaticText(item1
, wxID_STATIC
, _("&Description:"), wxDefaultPosition
, wxDefaultSize
, 0);
155 item3
->Add(item19
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
157 m_customPropertyDescription
= new wxTextCtrl(item1
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
|wxTE_RICH
);
158 item3
->Add(m_customPropertyDescription
, 1, wxGROW
|wxALL
, 5);
160 wxBoxSizer
* item21
= new wxBoxSizer(wxHORIZONTAL
);
161 item3
->Add(item21
, 0, wxGROW
|wxALL
, 5);
163 item21
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
165 wxButton
* item23
= new wxButton(item1
, wxID_OK
);
166 item21
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
168 wxButton
* item24
= new wxButton(item1
, wxID_CANCEL
);
169 item21
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
171 wxButton
* item25
= new wxButton(item1
, wxID_HELP
);
172 item21
->Add(item25
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
174 GetSizer()->Fit(this);
175 GetSizer()->SetSizeHints(this);
177 ////@end ctCustomPropertyDialog content construction
180 m_customPropertyName
->SetValidator(wxGenericValidator(& m_name
));
181 m_customPrototype
->SetValidator(wxGenericValidator(& m_type
));
182 m_customPropertyEditorType
->SetValidator(wxGenericValidator(& m_editorType
));
183 m_customPropertyDescription
->SetValidator(wxGenericValidator(& m_description
));
187 * Should we show tooltips?
190 bool ctCustomPropertyDialog::ShowToolTips()
196 * Update event handler for ID_PROPERTY_CHOICES
199 void ctCustomPropertyDialog::OnUpdatePropertyChoices( wxUpdateUIEvent
& event
)
201 if(m_customPrototype
)
202 event
.Enable( m_customPrototype
->GetSelection() > -1 && m_customPrototype
->GetStringSelection() == wxT("choice") );
206 * Event handler for ID_PROPERTY_CHOICE_ADD
209 void ctCustomPropertyDialog::OnPropertyChoiceAdd( wxCommandEvent
& WXUNUSED(event
) )
211 if(m_customPrototype
)
213 if ( m_customPropertyEditorType
->GetSelection() > -1 && m_customPropertyEditorType
->GetStringSelection() == wxT("choice") )
215 wxString str
= wxGetTextFromUser(_T("New choice"), _("Add choice"));
216 if (!str
.empty() && m_propertyChoices
)
218 m_propertyChoices
->Append(str
);
226 * Update event handler for ID_PROPERTY_CHOICE_ADD
229 void ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd( wxUpdateUIEvent
& event
)
231 if(m_customPropertyEditorType
)
232 event
.Enable( m_customPropertyEditorType
->GetSelection() > -1 &&
233 m_customPropertyEditorType
->GetStringSelection() == wxT("choice") );
237 * Event handler for ID_PROPERTY_CHOICE_REMOVE
240 void ctCustomPropertyDialog::OnPropertyChoiceRemove( wxCommandEvent
& WXUNUSED(event
) )
242 if (m_propertyChoices
&& m_propertyChoices
->GetSelection() > -1)
244 m_propertyChoices
->Delete(m_propertyChoices
->GetSelection());
245 m_choices
.RemoveAt(m_propertyChoices
->GetSelection());
250 * Update event handler for ID_PROPERTY_CHOICE_REMOVE
253 void ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove( wxUpdateUIEvent
& event
)
255 if (m_customPropertyEditorType
&& m_propertyChoices
)
256 event
.Enable( m_customPropertyEditorType
->GetSelection() > -1 &&
257 m_customPropertyEditorType
->GetStringSelection() == wxT("choice") &&
258 m_propertyChoices
->GetSelection() > -1 );
261 void ctCustomPropertyDialog::SetChoices(const wxArrayString
& choices
)
263 size_t i
, len
= choices
.GetCount();
264 if (m_propertyChoices
)
265 for (i
= 0; i
< len
; i
++)
266 m_propertyChoices
->Append(m_choices
[i
]);