1 /////////////////////////////////////////////////////////////////////////////
2 // Name: custompropertydialog.cpp
3 // Purpose: Custom property dialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "custompropertydialog.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/statline.h"
27 #include "wx/splitter.h"
28 #include "wx/scrolwin.h"
29 #include "wx/spinctrl.h"
30 #include "wx/spinbutt.h"
34 #include "wx/cshelp.h"
35 #include "wx/valgen.h"
36 #include "custompropertydialog.h"
42 * ctCustomPropertyDialog type definition
45 IMPLEMENT_CLASS( ctCustomPropertyDialog
, wxDialog
)
48 * ctCustomPropertyDialog event table definition
51 BEGIN_EVENT_TABLE( ctCustomPropertyDialog
, wxDialog
)
53 ////@begin ctCustomPropertyDialog event table entries
54 EVT_UPDATE_UI( ID_PROPERTY_CHOICES
, ctCustomPropertyDialog::OnUpdatePropertyChoices
)
56 EVT_BUTTON( ID_PROPERTY_CHOICE_ADD
, ctCustomPropertyDialog::OnPropertyChoiceAdd
)
57 EVT_UPDATE_UI( ID_PROPERTY_CHOICE_ADD
, ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd
)
59 EVT_BUTTON( ID_PROPERTY_CHOICE_REMOVE
, ctCustomPropertyDialog::OnPropertyChoiceRemove
)
60 EVT_UPDATE_UI( ID_PROPERTY_CHOICE_REMOVE
, ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove
)
62 ////@end ctCustomPropertyDialog event table entries
67 * ctCustomPropertyDialog constructor
70 ctCustomPropertyDialog::ctCustomPropertyDialog( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
)
72 m_type
= wxT("string");
74 wxDialog::Create( parent
, id
, caption
);
80 * Control creation for ctCustomPropertyDialog
83 void ctCustomPropertyDialog::CreateControls()
85 ////@begin ctCustomPropertyDialog content construction
89 ctCustomPropertyDialog
* item1
= this;
91 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
92 item1
->SetSizer(item2
);
94 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
95 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
97 wxStaticText
* item4
= new wxStaticText(item1
, wxID_STATIC
, _("&Enter name, type and description for your custom property."), wxDefaultPosition
, wxDefaultSize
, 0);
98 item3
->Add(item4
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
100 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Name:"), wxDefaultPosition
, wxDefaultSize
, 0);
101 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
103 m_customPropertyName
= new wxTextCtrl(item1
, wxID_ANY
);
104 item3
->Add(m_customPropertyName
, 0, wxGROW
|wxALL
, 5);
106 wxBoxSizer
* item7
= new wxBoxSizer(wxHORIZONTAL
);
107 item3
->Add(item7
, 0, wxGROW
, 5);
109 wxBoxSizer
* item8
= new wxBoxSizer(wxVERTICAL
);
110 item7
->Add(item8
, 1, wxGROW
, 5);
112 wxStaticText
* item9
= new wxStaticText(item1
, wxID_STATIC
, _("&Data type:"), wxDefaultPosition
, wxDefaultSize
, 0);
113 item8
->Add(item9
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
116 items
.Add(_("string"));
117 items
.Add(_("bool"));
118 items
.Add(_("double"));
119 items
.Add(_("long"));
120 m_customPrototype
= new wxChoice(item1
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, items
);
121 m_customPrototype
->SetStringSelection(_("string"));
122 item8
->Add(m_customPrototype
, 1, wxGROW
|wxALL
, 5);
124 wxBoxSizer
* item11
= new wxBoxSizer(wxVERTICAL
);
125 item7
->Add(item11
, 0, wxALIGN_CENTER_VERTICAL
, 5);
127 wxStaticText
* item12
= new wxStaticText(item1
, wxID_STATIC
, _("&Editor type:"), wxDefaultPosition
, wxDefaultSize
, 0);
128 item11
->Add(item12
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
131 items
.Add(_("string"));
132 items
.Add(_("choice"));
133 items
.Add(_("bool"));
134 items
.Add(_("float"));
135 items
.Add(_("integer"));
136 items
.Add(_("configitems"));
137 m_customPropertyEditorType
= new wxChoice(item1
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, items
);
138 m_customPropertyEditorType
->SetStringSelection(_("string"));
139 item11
->Add(m_customPropertyEditorType
, 1, wxGROW
|wxALL
, 5);
141 wxStaticBox
* item14Static
= new wxStaticBox(item1
, wxID_ANY
, _("Choices"));
142 wxStaticBoxSizer
* item14
= new wxStaticBoxSizer(item14Static
, wxHORIZONTAL
);
143 item3
->Add(item14
, 0, wxGROW
|wxALL
, 5);
145 wxString
* item15Strings
= NULL
;
146 m_propertyChoices
= new wxListBox(item1
, ID_PROPERTY_CHOICES
, wxDefaultPosition
, wxDefaultSize
, 0, item15Strings
, wxLB_SINGLE
);
147 item14
->Add(m_propertyChoices
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
149 wxBoxSizer
* item16
= new wxBoxSizer(wxVERTICAL
);
150 item14
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
, 5);
152 wxButton
* item17
= new wxButton(item1
, ID_PROPERTY_CHOICE_ADD
, _("&Add..."), wxDefaultPosition
, wxDefaultSize
, 0);
153 item16
->Add(item17
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
155 wxButton
* item18
= new wxButton(item1
, ID_PROPERTY_CHOICE_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
156 item16
->Add(item18
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
158 wxStaticText
* item19
= new wxStaticText(item1
, wxID_STATIC
, _("&Description:"), wxDefaultPosition
, wxDefaultSize
, 0);
159 item3
->Add(item19
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
161 m_customPropertyDescription
= new wxTextCtrl(item1
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
|wxTE_RICH
);
162 item3
->Add(m_customPropertyDescription
, 1, wxGROW
|wxALL
, 5);
164 wxBoxSizer
* item21
= new wxBoxSizer(wxHORIZONTAL
);
165 item3
->Add(item21
, 0, wxGROW
|wxALL
, 5);
167 item21
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
169 wxButton
* item23
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
170 item21
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
172 wxButton
* item24
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
173 item21
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
175 wxButton
* item25
= new wxButton(item1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0);
176 item21
->Add(item25
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
178 GetSizer()->Fit(this);
179 GetSizer()->SetSizeHints(this);
181 ////@end ctCustomPropertyDialog content construction
184 m_customPropertyName
->SetValidator(wxGenericValidator(& m_name
));
185 m_customPrototype
->SetValidator(wxGenericValidator(& m_type
));
186 m_customPropertyEditorType
->SetValidator(wxGenericValidator(& m_editorType
));
187 m_customPropertyDescription
->SetValidator(wxGenericValidator(& m_description
));
191 * Should we show tooltips?
194 bool ctCustomPropertyDialog::ShowToolTips()
200 * Update event handler for ID_PROPERTY_CHOICES
203 void ctCustomPropertyDialog::OnUpdatePropertyChoices( wxUpdateUIEvent
& event
)
205 if(m_customPrototype
)
206 event
.Enable( m_customPrototype
->GetSelection() > -1 && m_customPrototype
->GetStringSelection() == wxT("choice") );
210 * Event handler for ID_PROPERTY_CHOICE_ADD
213 void ctCustomPropertyDialog::OnPropertyChoiceAdd( wxCommandEvent
& WXUNUSED(event
) )
215 if(m_customPrototype
)
217 if ( m_customPropertyEditorType
->GetSelection() > -1 && m_customPropertyEditorType
->GetStringSelection() == wxT("choice") )
219 wxString str
= wxGetTextFromUser(_T("New choice"), _("Add choice"));
220 if (!str
.IsEmpty() && m_propertyChoices
)
222 m_propertyChoices
->Append(str
);
230 * Update event handler for ID_PROPERTY_CHOICE_ADD
233 void ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd( wxUpdateUIEvent
& event
)
235 if(m_customPropertyEditorType
)
236 event
.Enable( m_customPropertyEditorType
->GetSelection() > -1 &&
237 m_customPropertyEditorType
->GetStringSelection() == wxT("choice") );
241 * Event handler for ID_PROPERTY_CHOICE_REMOVE
244 void ctCustomPropertyDialog::OnPropertyChoiceRemove( wxCommandEvent
& WXUNUSED(event
) )
246 if (m_propertyChoices
&& m_propertyChoices
->GetSelection() > -1)
248 m_propertyChoices
->Delete(m_propertyChoices
->GetSelection());
249 m_choices
.RemoveAt(m_propertyChoices
->GetSelection());
254 * Update event handler for ID_PROPERTY_CHOICE_REMOVE
257 void ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove( wxUpdateUIEvent
& event
)
259 if (m_customPropertyEditorType
&& m_propertyChoices
)
260 event
.Enable( m_customPropertyEditorType
->GetSelection() > -1 &&
261 m_customPropertyEditorType
->GetStringSelection() == wxT("choice") &&
262 m_propertyChoices
->GetSelection() > -1 );
265 void ctCustomPropertyDialog::SetChoices(const wxArrayString
& choices
)
267 size_t i
, len
= choices
.GetCount();
268 if (m_propertyChoices
)
269 for (i
= 0; i
< len
; i
++)
270 m_propertyChoices
->Append(m_choices
[i
]);