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"
17 #include <wx/cshelp.h>
18 #include <wx/statline.h>
19 #include <wx/splitter.h>
20 #include <wx/scrolwin.h>
21 #include <wx/spinctrl.h>
22 #include <wx/spinbutt.h>
23 #include <wx/valgen.h>
25 #include "custompropertydialog.h"
31 * ctCustomPropertyDialog type definition
34 IMPLEMENT_CLASS( ctCustomPropertyDialog
, wxDialog
)
37 * ctCustomPropertyDialog event table definition
40 BEGIN_EVENT_TABLE( ctCustomPropertyDialog
, wxDialog
)
42 ////@begin ctCustomPropertyDialog event table entries
43 EVT_UPDATE_UI( ID_PROPERTY_CHOICES
, ctCustomPropertyDialog::OnUpdatePropertyChoices
)
45 EVT_BUTTON( ID_PROPERTY_CHOICE_ADD
, ctCustomPropertyDialog::OnPropertyChoiceAdd
)
46 EVT_UPDATE_UI( ID_PROPERTY_CHOICE_ADD
, ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd
)
48 EVT_BUTTON( ID_PROPERTY_CHOICE_REMOVE
, ctCustomPropertyDialog::OnPropertyChoiceRemove
)
49 EVT_UPDATE_UI( ID_PROPERTY_CHOICE_REMOVE
, ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove
)
51 ////@end ctCustomPropertyDialog event table entries
56 * ctCustomPropertyDialog constructor
59 ctCustomPropertyDialog::ctCustomPropertyDialog( wxWindow
* parent
, wxWindowID id
, const wxString
& caption
, const wxPoint
& pos
, const wxSize
& size
, long style
)
61 m_type
= wxT("string");
63 wxDialog::Create( parent
, id
, caption
, pos
, size
, style
);
69 * Control creation for ctCustomPropertyDialog
72 void ctCustomPropertyDialog::CreateControls()
74 ////@begin ctCustomPropertyDialog content construction
76 ctCustomPropertyDialog
* item1
= this;
78 wxBoxSizer
* item2
= new wxBoxSizer(wxVERTICAL
);
79 item1
->SetSizer(item2
);
80 item1
->SetAutoLayout(TRUE
);
82 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
83 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
85 wxStaticText
* item4
= new wxStaticText(item1
, wxID_STATIC
, _("&Enter name, type and description for your custom property."), wxDefaultPosition
, wxDefaultSize
, 0);
86 item3
->Add(item4
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
88 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Name:"), wxDefaultPosition
, wxDefaultSize
, 0);
89 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
91 wxTextCtrl
* item6
= new wxTextCtrl(item1
, ID_CUSTOMPROPERTYNAME
, _(""), wxDefaultPosition
, wxDefaultSize
, 0);
92 item3
->Add(item6
, 0, wxGROW
|wxALL
, 5);
94 wxBoxSizer
* item7
= new wxBoxSizer(wxHORIZONTAL
);
95 item3
->Add(item7
, 0, wxGROW
, 5);
97 wxBoxSizer
* item8
= new wxBoxSizer(wxVERTICAL
);
98 item7
->Add(item8
, 1, wxGROW
, 5);
100 wxStaticText
* item9
= new wxStaticText(item1
, wxID_STATIC
, _("&Data type:"), wxDefaultPosition
, wxDefaultSize
, 0);
101 item8
->Add(item9
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
103 wxString item10Strings
[] = {
109 wxChoice
* item10
= new wxChoice(item1
, ID_CUSTOMPROPERTYTYPE
, wxDefaultPosition
, wxDefaultSize
, 4, item10Strings
, 0);
110 item10
->SetStringSelection(_("string"));
111 item8
->Add(item10
, 1, wxGROW
|wxALL
, 5);
113 wxBoxSizer
* item11
= new wxBoxSizer(wxVERTICAL
);
114 item7
->Add(item11
, 0, wxALIGN_CENTER_VERTICAL
, 5);
116 wxStaticText
* item12
= new wxStaticText(item1
, wxID_STATIC
, _("&Editor type:"), wxDefaultPosition
, wxDefaultSize
, 0);
117 item11
->Add(item12
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
119 wxString item13Strings
[] = {
127 wxChoice
* item13
= new wxChoice(item1
, ID_CUSTOMPROPERTYEDITORTYPE
, wxDefaultPosition
, wxDefaultSize
, 6, item13Strings
, 0);
128 item13
->SetStringSelection(_("string"));
129 item11
->Add(item13
, 1, wxGROW
|wxALL
, 5);
131 wxStaticBox
* item14Static
= new wxStaticBox(item1
, -1, _("Choices"));
132 wxStaticBoxSizer
* item14
= new wxStaticBoxSizer(item14Static
, wxHORIZONTAL
);
133 item3
->Add(item14
, 0, wxGROW
|wxALL
, 5);
135 wxString
* item15Strings
= NULL
;
136 wxListBox
* item15
= new wxListBox(item1
, ID_PROPERTY_CHOICES
, wxDefaultPosition
, wxDefaultSize
, 0, item15Strings
, wxLB_SINGLE
);
137 item14
->Add(item15
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
139 wxBoxSizer
* item16
= new wxBoxSizer(wxVERTICAL
);
140 item14
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
, 5);
142 wxButton
* item17
= new wxButton(item1
, ID_PROPERTY_CHOICE_ADD
, _("&Add..."), wxDefaultPosition
, wxDefaultSize
, 0);
143 item16
->Add(item17
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
145 wxButton
* item18
= new wxButton(item1
, ID_PROPERTY_CHOICE_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
146 item16
->Add(item18
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
148 wxStaticText
* item19
= new wxStaticText(item1
, wxID_STATIC
, _("&Description:"), wxDefaultPosition
, wxDefaultSize
, 0);
149 item3
->Add(item19
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
151 wxTextCtrl
* item20
= new wxTextCtrl(item1
, ID_CUSTOMPROPERTYDESCRIPTION
, _(""), wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
|wxTE_RICH
);
152 item3
->Add(item20
, 1, wxGROW
|wxALL
, 5);
154 wxBoxSizer
* item21
= new wxBoxSizer(wxHORIZONTAL
);
155 item3
->Add(item21
, 0, wxGROW
|wxALL
, 5);
157 item21
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
159 wxButton
* item23
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
160 item21
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
162 wxButton
* item24
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
163 item21
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
165 wxButton
* item25
= new wxButton(item1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0);
166 item21
->Add(item25
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
168 GetSizer()->Fit(this);
169 GetSizer()->SetSizeHints(this);
171 ////@end ctCustomPropertyDialog content construction
174 FindWindow(ID_CUSTOMPROPERTYNAME
)->SetValidator(wxGenericValidator(& m_name
));
175 FindWindow(ID_CUSTOMPROPERTYTYPE
)->SetValidator(wxGenericValidator(& m_type
));
176 FindWindow(ID_CUSTOMPROPERTYEDITORTYPE
)->SetValidator(wxGenericValidator(& m_editorType
));
177 FindWindow(ID_CUSTOMPROPERTYDESCRIPTION
)->SetValidator(wxGenericValidator(& m_description
));
181 * Should we show tooltips?
184 bool ctCustomPropertyDialog::ShowToolTips()
190 * Update event handler for ID_PROPERTY_CHOICES
193 void ctCustomPropertyDialog::OnUpdatePropertyChoices( wxUpdateUIEvent
& event
)
195 wxChoice
* choice
= (wxChoice
* ) FindWindow(ID_CUSTOMPROPERTYTYPE
);
196 event
.Enable( choice
->GetSelection() > -1 && choice
->GetStringSelection() == wxT("choice") );
200 * Event handler for ID_PROPERTY_CHOICE_ADD
203 void ctCustomPropertyDialog::OnPropertyChoiceAdd( wxCommandEvent
& WXUNUSED(event
) )
205 wxChoice
* choice
= (wxChoice
* ) FindWindow(ID_CUSTOMPROPERTYTYPE
);
206 if ( choice
->GetSelection() > -1 && choice
->GetStringSelection() == wxT("choice") )
208 wxString str
= wxGetTextFromUser(_T("New choice"), _("Add choice"));
211 wxListBox
* listBox
= (wxListBox
* ) FindWindow(ID_PROPERTY_CHOICES
);
212 listBox
->Append(str
);
219 * Update event handler for ID_PROPERTY_CHOICE_ADD
222 void ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd( wxUpdateUIEvent
& event
)
224 wxChoice
* choice
= (wxChoice
* ) FindWindow(ID_CUSTOMPROPERTYEDITORTYPE
);
225 event
.Enable( choice
->GetSelection() > -1 && choice
->GetStringSelection() == wxT("choice") );
229 * Event handler for ID_PROPERTY_CHOICE_REMOVE
232 void ctCustomPropertyDialog::OnPropertyChoiceRemove( wxCommandEvent
& WXUNUSED(event
) )
234 /* wxChoice* choice = (wxChoice* ) */ FindWindow(ID_CUSTOMPROPERTYEDITORTYPE
);
235 wxListBox
* listBox
= (wxListBox
* ) FindWindow(ID_PROPERTY_CHOICES
);
236 if (listBox
->GetSelection() > -1)
238 listBox
->Delete(listBox
->GetSelection());
239 m_choices
.RemoveAt(listBox
->GetSelection());
244 * Update event handler for ID_PROPERTY_CHOICE_REMOVE
247 void ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove( wxUpdateUIEvent
& event
)
249 wxChoice
* choice
= (wxChoice
* ) FindWindow(ID_CUSTOMPROPERTYEDITORTYPE
);
250 wxListBox
* listBox
= (wxListBox
* ) FindWindow(ID_PROPERTY_CHOICES
);
251 event
.Enable( choice
->GetSelection() > -1 && choice
->GetStringSelection() == wxT("choice") &&
252 listBox
->GetSelection() > -1 );
255 void ctCustomPropertyDialog::SetChoices(const wxArrayString
& choices
)
257 wxListBox
* listBox
= (wxListBox
* ) FindWindow(ID_PROPERTY_CHOICES
);
258 size_t i
, len
= choices
.GetCount();
259 for (i
= 0; i
< len
; i
++)
260 listBox
->Append(m_choices
[i
]);