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
);
81 wxBoxSizer
* item3
= new wxBoxSizer(wxVERTICAL
);
82 item2
->Add(item3
, 1, wxGROW
|wxALL
, 5);
84 wxStaticText
* item4
= new wxStaticText(item1
, wxID_STATIC
, _("&Enter name, type and description for your custom property."), wxDefaultPosition
, wxDefaultSize
, 0);
85 item3
->Add(item4
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
87 wxStaticText
* item5
= new wxStaticText(item1
, wxID_STATIC
, _("&Name:"), wxDefaultPosition
, wxDefaultSize
, 0);
88 item3
->Add(item5
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
90 wxTextCtrl
* item6
= new wxTextCtrl(item1
, ID_CUSTOMPROPERTYNAME
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, 0);
91 item3
->Add(item6
, 0, wxGROW
|wxALL
, 5);
93 wxBoxSizer
* item7
= new wxBoxSizer(wxHORIZONTAL
);
94 item3
->Add(item7
, 0, wxGROW
, 5);
96 wxBoxSizer
* item8
= new wxBoxSizer(wxVERTICAL
);
97 item7
->Add(item8
, 1, wxGROW
, 5);
99 wxStaticText
* item9
= new wxStaticText(item1
, wxID_STATIC
, _("&Data type:"), wxDefaultPosition
, wxDefaultSize
, 0);
100 item8
->Add(item9
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
102 wxString item10Strings
[] = {
108 wxChoice
* item10
= new wxChoice(item1
, ID_CUSTOMPROPERTYTYPE
, wxDefaultPosition
, wxDefaultSize
, 4, item10Strings
, 0);
109 item10
->SetStringSelection(_("string"));
110 item8
->Add(item10
, 1, wxGROW
|wxALL
, 5);
112 wxBoxSizer
* item11
= new wxBoxSizer(wxVERTICAL
);
113 item7
->Add(item11
, 0, wxALIGN_CENTER_VERTICAL
, 5);
115 wxStaticText
* item12
= new wxStaticText(item1
, wxID_STATIC
, _("&Editor type:"), wxDefaultPosition
, wxDefaultSize
, 0);
116 item11
->Add(item12
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
118 wxString item13Strings
[] = {
126 wxChoice
* item13
= new wxChoice(item1
, ID_CUSTOMPROPERTYEDITORTYPE
, wxDefaultPosition
, wxDefaultSize
, 6, item13Strings
, 0);
127 item13
->SetStringSelection(_("string"));
128 item11
->Add(item13
, 1, wxGROW
|wxALL
, 5);
130 wxStaticBox
* item14Static
= new wxStaticBox(item1
, wxID_ANY
, _("Choices"));
131 wxStaticBoxSizer
* item14
= new wxStaticBoxSizer(item14Static
, wxHORIZONTAL
);
132 item3
->Add(item14
, 0, wxGROW
|wxALL
, 5);
134 wxString
* item15Strings
= NULL
;
135 wxListBox
* item15
= new wxListBox(item1
, ID_PROPERTY_CHOICES
, wxDefaultPosition
, wxDefaultSize
, 0, item15Strings
, wxLB_SINGLE
);
136 item14
->Add(item15
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
138 wxBoxSizer
* item16
= new wxBoxSizer(wxVERTICAL
);
139 item14
->Add(item16
, 0, wxALIGN_CENTER_VERTICAL
, 5);
141 wxButton
* item17
= new wxButton(item1
, ID_PROPERTY_CHOICE_ADD
, _("&Add..."), wxDefaultPosition
, wxDefaultSize
, 0);
142 item16
->Add(item17
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
144 wxButton
* item18
= new wxButton(item1
, ID_PROPERTY_CHOICE_REMOVE
, _("&Remove"), wxDefaultPosition
, wxDefaultSize
, 0);
145 item16
->Add(item18
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
147 wxStaticText
* item19
= new wxStaticText(item1
, wxID_STATIC
, _("&Description:"), wxDefaultPosition
, wxDefaultSize
, 0);
148 item3
->Add(item19
, 0, wxALIGN_LEFT
|wxALL
|wxADJUST_MINSIZE
, 5);
150 wxTextCtrl
* item20
= new wxTextCtrl(item1
, ID_CUSTOMPROPERTYDESCRIPTION
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
|wxTE_RICH
);
151 item3
->Add(item20
, 1, wxGROW
|wxALL
, 5);
153 wxBoxSizer
* item21
= new wxBoxSizer(wxHORIZONTAL
);
154 item3
->Add(item21
, 0, wxGROW
|wxALL
, 5);
156 item21
->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
158 wxButton
* item23
= new wxButton(item1
, wxID_OK
, _("&OK"), wxDefaultPosition
, wxDefaultSize
, 0);
159 item21
->Add(item23
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
161 wxButton
* item24
= new wxButton(item1
, wxID_CANCEL
, _("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0);
162 item21
->Add(item24
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
164 wxButton
* item25
= new wxButton(item1
, wxID_HELP
, _("&Help"), wxDefaultPosition
, wxDefaultSize
, 0);
165 item21
->Add(item25
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
167 GetSizer()->Fit(this);
168 GetSizer()->SetSizeHints(this);
170 ////@end ctCustomPropertyDialog content construction
173 FindWindow(ID_CUSTOMPROPERTYNAME
)->SetValidator(wxGenericValidator(& m_name
));
174 FindWindow(ID_CUSTOMPROPERTYTYPE
)->SetValidator(wxGenericValidator(& m_type
));
175 FindWindow(ID_CUSTOMPROPERTYEDITORTYPE
)->SetValidator(wxGenericValidator(& m_editorType
));
176 FindWindow(ID_CUSTOMPROPERTYDESCRIPTION
)->SetValidator(wxGenericValidator(& m_description
));
180 * Should we show tooltips?
183 bool ctCustomPropertyDialog::ShowToolTips()
189 * Update event handler for ID_PROPERTY_CHOICES
192 void ctCustomPropertyDialog::OnUpdatePropertyChoices( wxUpdateUIEvent
& event
)
194 wxChoice
* choice
= (wxChoice
* ) FindWindow(ID_CUSTOMPROPERTYTYPE
);
195 event
.Enable( choice
->GetSelection() > -1 && choice
->GetStringSelection() == wxT("choice") );
199 * Event handler for ID_PROPERTY_CHOICE_ADD
202 void ctCustomPropertyDialog::OnPropertyChoiceAdd( wxCommandEvent
& WXUNUSED(event
) )
204 wxChoice
* choice
= (wxChoice
* ) FindWindow(ID_CUSTOMPROPERTYTYPE
);
205 if ( choice
->GetSelection() > -1 && choice
->GetStringSelection() == wxT("choice") )
207 wxString str
= wxGetTextFromUser(_T("New choice"), _("Add choice"));
210 wxListBox
* listBox
= (wxListBox
* ) FindWindow(ID_PROPERTY_CHOICES
);
211 listBox
->Append(str
);
218 * Update event handler for ID_PROPERTY_CHOICE_ADD
221 void ctCustomPropertyDialog::OnUpdatePropertyChoiceAdd( wxUpdateUIEvent
& event
)
223 wxChoice
* choice
= (wxChoice
* ) FindWindow(ID_CUSTOMPROPERTYEDITORTYPE
);
224 event
.Enable( choice
->GetSelection() > -1 && choice
->GetStringSelection() == wxT("choice") );
228 * Event handler for ID_PROPERTY_CHOICE_REMOVE
231 void ctCustomPropertyDialog::OnPropertyChoiceRemove( wxCommandEvent
& WXUNUSED(event
) )
233 /* wxChoice* choice = (wxChoice* ) */ FindWindow(ID_CUSTOMPROPERTYEDITORTYPE
);
234 wxListBox
* listBox
= (wxListBox
* ) FindWindow(ID_PROPERTY_CHOICES
);
235 if (listBox
->GetSelection() > -1)
237 listBox
->Delete(listBox
->GetSelection());
238 m_choices
.RemoveAt(listBox
->GetSelection());
243 * Update event handler for ID_PROPERTY_CHOICE_REMOVE
246 void ctCustomPropertyDialog::OnUpdatePropertyChoiceRemove( wxUpdateUIEvent
& event
)
248 wxChoice
* choice
= (wxChoice
* ) FindWindow(ID_CUSTOMPROPERTYEDITORTYPE
);
249 wxListBox
* listBox
= (wxListBox
* ) FindWindow(ID_PROPERTY_CHOICES
);
250 event
.Enable( choice
->GetSelection() > -1 && choice
->GetStringSelection() == wxT("choice") &&
251 listBox
->GetSelection() > -1 );
254 void ctCustomPropertyDialog::SetChoices(const wxArrayString
& choices
)
256 wxListBox
* listBox
= (wxListBox
* ) FindWindow(ID_PROPERTY_CHOICES
);
257 size_t i
, len
= choices
.GetCount();
258 for (i
= 0; i
< len
; i
++)
259 listBox
->Append(m_choices
[i
]);