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"
31 WX_DEFINE_OBJARRAY(PropertyInfoArray
);
36 ID_EDITCTRL
= wxID_HIGHEST
+ 1000,
46 class PropertyPanel
: public wxPanel
49 PropertyPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
)
50 : wxPanel(parent
, -1), m_Handler(hnd
), m_PLI(pli
) {}
52 void Update(const wxString
& value
)
54 XmlWriteValue(m_PLI
->m_Node
, m_PLI
->m_PropInfo
->Name
, value
);
55 m_PLI
->m_ListCtrl
->SetItemImage(m_PLI
->m_Index
, 1, 1);
56 m_PLI
->m_ListCtrl
->SetItem(m_PLI
->m_Index
, 1,
57 m_Handler
->GetBriefValue(m_PLI
->m_Node
, m_PLI
->m_PropInfo
));
61 PropertyHandler
*m_Handler
;
69 int PropertyHandler::CreateListItem(wxListCtrl
*listctrl
, wxXmlNode
*node
, PropertyInfo
*pi
)
74 if (XmlFindNode(node
, pi
->Name
) == NULL
) iconnum
= 0; else iconnum
= 1;
76 value
= GetBriefValue(node
, pi
);
78 long pos
= listctrl
->GetItemCount();
79 listctrl
->InsertItem(pos
, name
, iconnum
);
80 listctrl
->SetItem(pos
, 1, value
);
86 wxString
PropertyHandler::GetBriefValue(wxXmlNode
*node
, PropertyInfo
*pi
)
88 return XmlReadValue(node
, pi
->Name
);
96 class TextPropPanel
: public PropertyPanel
99 TextPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
101 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
104 sz
->Add(new wxStaticText(this, -1, _("Value:")), 0, wxLEFT
, 5);
105 sz
->Add(tc
= new wxTextCtrl(this, ID_EDITCTRL
, XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
)), 0, wxALL
|wxEXPAND
, 5);
113 void OnEdit(wxCommandEvent
&event
)
115 Update(((wxTextCtrl
*)event
.GetEventObject())->GetValue());
118 DECLARE_EVENT_TABLE()
121 BEGIN_EVENT_TABLE(TextPropPanel
, PropertyPanel
)
122 EVT_TEXT(ID_EDITCTRL
, TextPropPanel::OnEdit
)
126 wxPanel
*TextPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
128 return new TextPropPanel(parent
, this, pli
);
141 class CoordPropPanel
: public PropertyPanel
144 CoordPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
146 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
147 wxSizer
*sz
= new wxBoxSizer(wxHORIZONTAL
);
148 m_ed1
= m_ed2
= NULL
; m_chb
= NULL
;
150 sz
->Add(new wxStaticText(this, -1, _("X:")), 0, wxLEFT
|wxRIGHT
|wxALIGN_CENTER
, 5);
151 sz
->Add(m_ed1
= new wxTextCtrl(this, ID_XEDIT
, "",
152 wxDefaultPosition
, wxDefaultSize
, 0,
153 wxTextValidator(wxFILTER_NUMERIC
)),
157 sz
->Add(new wxStaticText(this, -1, _("Y:")), 0, wxLEFT
|wxRIGHT
|wxALIGN_CENTER
, 5);
158 sz
->Add(m_ed2
= new wxTextCtrl(this, ID_YEDIT
, "",
159 wxDefaultPosition
, wxDefaultSize
, 0,
160 wxTextValidator(wxFILTER_NUMERIC
)),
162 sizer
->Add(sz
, 0, wxEXPAND
|wxTOP
, 5);
164 sizer
->Add(m_chb
= new wxCheckBox(this, ID_USEDLG
, _("Use dialog units")), 0, wxLEFT
|wxTOP
, 5);
170 wxString val
= XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
);
171 m_chb
->SetValue(val
.Len()==0 || val
[val
.Len()-1] == 'd');
172 m_ed1
->SetValue(val
.BeforeFirst(','));
173 m_ed2
->SetValue(val
.AfterFirst(',').BeforeFirst('d'));
176 void OnEdit(wxCommandEvent
&event
)
178 wxString val
, v1
, v2
;
180 if (m_ed1
== NULL
|| m_ed2
== NULL
|| m_chb
== NULL
) return;
182 v1
= m_ed1
->GetValue();
183 v2
= m_ed2
->GetValue();
184 if (v1
.IsEmpty() || v2
.IsEmpty()) return;
186 if (m_chb
->GetValue()) val
<< 'd';
190 wxTextCtrl
*m_ed1
, *m_ed2
;
193 DECLARE_EVENT_TABLE()
196 BEGIN_EVENT_TABLE(CoordPropPanel
, PropertyPanel
)
197 EVT_TEXT(ID_XEDIT
, CoordPropPanel::OnEdit
)
198 EVT_TEXT(ID_YEDIT
, CoordPropPanel::OnEdit
)
199 EVT_CHECKBOX(ID_USEDLG
, CoordPropPanel::OnEdit
)
202 wxPanel
*CoordPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
204 return new CoordPropPanel(parent
, this, pli
);
214 class BoolPropPanel
: public PropertyPanel
217 BoolPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
220 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
221 sizer
->Add(m_chb
= new wxCheckBox(this, ID_BOOLVAL
, _("On/Yes/True")), 0, wxLEFT
|wxTOP
, 5);
225 m_chb
->SetValue(XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
) == "1");
228 void OnEdit(wxCommandEvent
&event
)
230 if (m_chb
== NULL
) return;
231 if (m_chb
->GetValue()) Update("1");
237 DECLARE_EVENT_TABLE()
240 BEGIN_EVENT_TABLE(BoolPropPanel
, PropertyPanel
)
241 EVT_CHECKBOX(ID_BOOLVAL
, BoolPropPanel::OnEdit
)
244 wxPanel
*BoolPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
246 return new BoolPropPanel(parent
, this, pli
);
249 wxString
BoolPropertyHandler::GetBriefValue(wxXmlNode
*node
, PropertyInfo
*pi
)
251 wxString v
= XmlReadValue(node
, pi
->Name
);
252 if (v
.IsEmpty()) return wxEmptyString
;
253 else if (v
== "1") return "true";
264 class FlagsPropPanel
: public PropertyPanel
267 FlagsPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
270 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
271 sizer
->Add(m_chl
= new wxCheckListBox(this, ID_CHECKLIST
), 1, wxEXPAND
|wxALL
, 5);
277 wxStringTokenizer
tkn(pli
->m_PropInfo
->MoreInfo
, ",");
279 while (tkn
.HasMoreTokens())
281 s
= tkn
.GetNextToken();
288 wxStringTokenizer
tkn(XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
), "| ");
290 while (tkn
.HasMoreTokens())
292 index
= m_flags
.Index(tkn
.GetNextToken());
293 if (index
!= wxNOT_FOUND
)
299 void OnEdit(wxCommandEvent
&event
)
304 for (size_t i
= 0; i
< m_flags
.GetCount(); i
++)
306 if (m_chl
->IsChecked(i
))
308 if (!first
) s
<< '|';
314 if (m_PLI
->m_PropInfo
->Name
== "orient")
315 // FIXME - dirty hack related to sizers
316 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED_ICON
);
319 wxCheckListBox
*m_chl
;
320 wxArrayString m_flags
;
322 DECLARE_EVENT_TABLE()
325 BEGIN_EVENT_TABLE(FlagsPropPanel
, PropertyPanel
)
326 EVT_CHECKLISTBOX(ID_CHECKLIST
, FlagsPropPanel::OnEdit
)
329 wxPanel
*FlagsPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
331 return new FlagsPropPanel(parent
, this, pli
);