1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "prophnd.h"
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
21 #include "wx/xml/xml.h"
23 #include "wx/arrimpl.cpp"
24 #include "wx/valtext.h"
25 #include "wx/tokenzr.h"
26 #include "wx/checklst.h"
27 #include "wx/listctrl.h"
32 WX_DEFINE_OBJARRAY(PropertyInfoArray
);
37 ID_EDITCTRL
= wxID_HIGHEST
+ 1000,
47 class PropertyPanel
: public wxPanel
50 PropertyPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
)
51 : wxPanel(parent
, -1), m_Handler(hnd
), m_PLI(pli
) {}
53 void Update(const wxString
& value
)
55 XmlWriteValue(m_PLI
->m_Node
, m_PLI
->m_PropInfo
->Name
, value
);
56 m_PLI
->m_ListCtrl
->SetItemImage(m_PLI
->m_Index
, 1, 1);
57 m_PLI
->m_ListCtrl
->SetItem(m_PLI
->m_Index
, 1,
58 m_Handler
->GetBriefValue(m_PLI
->m_Node
, m_PLI
->m_PropInfo
));
62 PropertyHandler
*m_Handler
;
70 int PropertyHandler::CreateListItem(wxListCtrl
*listctrl
, wxXmlNode
*node
, PropertyInfo
*pi
)
75 if (XmlFindNode(node
, pi
->Name
) == NULL
) iconnum
= 0; else iconnum
= 1;
77 value
= GetBriefValue(node
, pi
);
79 long pos
= listctrl
->GetItemCount();
80 listctrl
->InsertItem(pos
, name
, iconnum
);
81 listctrl
->SetItem(pos
, 1, value
);
87 wxString
PropertyHandler::GetBriefValue(wxXmlNode
*node
, PropertyInfo
*pi
)
89 return XmlReadValue(node
, pi
->Name
);
97 class TextPropPanel
: public PropertyPanel
100 TextPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
102 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
105 sz
->Add(new wxStaticText(this, -1, _("Value:")), 0, wxLEFT
, 5);
106 sz
->Add(tc
= new wxTextCtrl(this, ID_EDITCTRL
, XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
)), 0, wxALL
|wxEXPAND
, 5);
114 void OnEdit(wxCommandEvent
&event
)
116 Update(((wxTextCtrl
*)event
.GetEventObject())->GetValue());
119 DECLARE_EVENT_TABLE()
122 BEGIN_EVENT_TABLE(TextPropPanel
, PropertyPanel
)
123 EVT_TEXT(ID_EDITCTRL
, TextPropPanel::OnEdit
)
127 wxPanel
*TextPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
129 return new TextPropPanel(parent
, this, pli
);
142 class CoordPropPanel
: public PropertyPanel
145 CoordPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
147 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
148 wxSizer
*sz
= new wxBoxSizer(wxHORIZONTAL
);
149 m_ed1
= m_ed2
= NULL
; m_chb
= NULL
;
151 sz
->Add(new wxStaticText(this, -1, _("X:")), 0, wxLEFT
|wxRIGHT
|wxALIGN_CENTER
, 5);
152 sz
->Add(m_ed1
= new wxTextCtrl(this, ID_XEDIT
, "",
153 wxDefaultPosition
, wxDefaultSize
, 0,
154 wxTextValidator(wxFILTER_NUMERIC
)),
158 sz
->Add(new wxStaticText(this, -1, _("Y:")), 0, wxLEFT
|wxRIGHT
|wxALIGN_CENTER
, 5);
159 sz
->Add(m_ed2
= new wxTextCtrl(this, ID_YEDIT
, "",
160 wxDefaultPosition
, wxDefaultSize
, 0,
161 wxTextValidator(wxFILTER_NUMERIC
)),
163 sizer
->Add(sz
, 0, wxEXPAND
|wxTOP
, 5);
165 sizer
->Add(m_chb
= new wxCheckBox(this, ID_USEDLG
, _("Use dialog units")), 0, wxLEFT
|wxTOP
, 5);
171 wxString val
= XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
);
172 m_chb
->SetValue(val
.Len()==0 || val
[val
.Len()-1] == 'd');
173 m_ed1
->SetValue(val
.BeforeFirst(','));
174 m_ed2
->SetValue(val
.AfterFirst(',').BeforeFirst('d'));
177 void OnEdit(wxCommandEvent
&event
)
179 wxString val
, v1
, v2
;
181 if (m_ed1
== NULL
|| m_ed2
== NULL
|| m_chb
== NULL
) return;
183 v1
= m_ed1
->GetValue();
184 v2
= m_ed2
->GetValue();
185 if (v1
.IsEmpty() || v2
.IsEmpty()) return;
187 if (m_chb
->GetValue()) val
<< 'd';
191 wxTextCtrl
*m_ed1
, *m_ed2
;
194 DECLARE_EVENT_TABLE()
197 BEGIN_EVENT_TABLE(CoordPropPanel
, PropertyPanel
)
198 EVT_TEXT(ID_XEDIT
, CoordPropPanel::OnEdit
)
199 EVT_TEXT(ID_YEDIT
, CoordPropPanel::OnEdit
)
200 EVT_CHECKBOX(ID_USEDLG
, CoordPropPanel::OnEdit
)
203 wxPanel
*CoordPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
205 return new CoordPropPanel(parent
, this, pli
);
214 class DimensionPropPanel
: public PropertyPanel
217 DimensionPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
219 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
220 m_ed1
= NULL
; m_chb
= NULL
;
222 sizer
->Add(new wxStaticText(this, -1, _("Value:")), 0, wxLEFT
, 5);
223 sizer
->Add(m_ed1
= new wxTextCtrl(this, ID_XEDIT
, "",
224 wxDefaultPosition
, wxDefaultSize
, 0,
225 wxTextValidator(wxFILTER_NUMERIC
)),
229 sizer
->Add(m_chb
= new wxCheckBox(this, ID_USEDLG
, _("Use dialog units")), 0, wxLEFT
|wxTOP
, 5);
235 wxString val
= XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
);
236 m_chb
->SetValue(val
.Len()>0 && val
[val
.Len()-1] == 'd');
237 m_ed1
->SetValue(val
.BeforeFirst('d'));
240 void OnEdit(wxCommandEvent
&event
)
244 if (m_ed1
== NULL
|| m_chb
== NULL
) return;
246 val
= m_ed1
->GetValue();
247 if (val
.IsEmpty()) return;
248 if (m_chb
->GetValue()) val
<< 'd';
255 DECLARE_EVENT_TABLE()
258 BEGIN_EVENT_TABLE(DimensionPropPanel
, PropertyPanel
)
259 EVT_TEXT(ID_XEDIT
, DimensionPropPanel::OnEdit
)
260 EVT_TEXT(ID_YEDIT
, DimensionPropPanel::OnEdit
)
261 EVT_CHECKBOX(ID_USEDLG
, DimensionPropPanel::OnEdit
)
264 wxPanel
*DimensionPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
266 return new DimensionPropPanel(parent
, this, pli
);
275 class BoolPropPanel
: public PropertyPanel
278 BoolPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
281 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
282 sizer
->Add(m_chb
= new wxCheckBox(this, ID_BOOLVAL
, _("On/Yes/True")), 0, wxLEFT
|wxTOP
, 5);
286 m_chb
->SetValue(XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
) == "1");
289 void OnEdit(wxCommandEvent
&event
)
291 if (m_chb
== NULL
) return;
292 if (m_chb
->GetValue()) Update("1");
298 DECLARE_EVENT_TABLE()
301 BEGIN_EVENT_TABLE(BoolPropPanel
, PropertyPanel
)
302 EVT_CHECKBOX(ID_BOOLVAL
, BoolPropPanel::OnEdit
)
305 wxPanel
*BoolPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
307 return new BoolPropPanel(parent
, this, pli
);
310 wxString
BoolPropertyHandler::GetBriefValue(wxXmlNode
*node
, PropertyInfo
*pi
)
312 wxString v
= XmlReadValue(node
, pi
->Name
);
313 if (v
.IsEmpty()) return wxEmptyString
;
314 else if (v
== "1") return "true";
325 class FlagsPropPanel
: public PropertyPanel
328 FlagsPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
331 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
332 sizer
->Add(m_chl
= new wxCheckListBox(this, ID_CHECKLIST
), 1, wxEXPAND
|wxALL
, 5);
338 wxStringTokenizer
tkn(pli
->m_PropInfo
->MoreInfo
, ",");
340 while (tkn
.HasMoreTokens())
342 s
= tkn
.GetNextToken();
349 wxStringTokenizer
tkn(XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
), "| ");
351 while (tkn
.HasMoreTokens())
353 index
= m_flags
.Index(tkn
.GetNextToken());
354 if (index
!= wxNOT_FOUND
)
360 void OnEdit(wxCommandEvent
&event
)
365 for (size_t i
= 0; i
< m_flags
.GetCount(); i
++)
367 if (m_chl
->IsChecked(i
))
369 if (!first
) s
<< '|';
375 if (m_PLI
->m_PropInfo
->Name
== "orient")
376 // FIXME - dirty hack related to sizers
377 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED_ICON
);
380 wxCheckListBox
*m_chl
;
381 wxArrayString m_flags
;
383 DECLARE_EVENT_TABLE()
386 BEGIN_EVENT_TABLE(FlagsPropPanel
, PropertyPanel
)
387 EVT_CHECKLISTBOX(ID_CHECKLIST
, FlagsPropPanel::OnEdit
)
390 wxPanel
*FlagsPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
392 return new FlagsPropPanel(parent
, this, pli
);
398 wxPanel
*NotImplPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
400 wxPanel
*p
= new wxPanel(parent
);
401 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
402 sizer
->Add(new wxStaticText(p
, -1, _("Sorry, this is not supported.\nYou have to edit XML code directly.")), 1, wxEXPAND
|wxALL
, 5);
403 p
->SetAutoLayout(TRUE
);