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
);
215 class BoolPropPanel
: public PropertyPanel
218 BoolPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
221 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
222 sizer
->Add(m_chb
= new wxCheckBox(this, ID_BOOLVAL
, _("On/Yes/True")), 0, wxLEFT
|wxTOP
, 5);
226 m_chb
->SetValue(XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
) == "1");
229 void OnEdit(wxCommandEvent
&event
)
231 if (m_chb
== NULL
) return;
232 if (m_chb
->GetValue()) Update("1");
238 DECLARE_EVENT_TABLE()
241 BEGIN_EVENT_TABLE(BoolPropPanel
, PropertyPanel
)
242 EVT_CHECKBOX(ID_BOOLVAL
, BoolPropPanel::OnEdit
)
245 wxPanel
*BoolPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
247 return new BoolPropPanel(parent
, this, pli
);
250 wxString
BoolPropertyHandler::GetBriefValue(wxXmlNode
*node
, PropertyInfo
*pi
)
252 wxString v
= XmlReadValue(node
, pi
->Name
);
253 if (v
.IsEmpty()) return wxEmptyString
;
254 else if (v
== "1") return "true";
265 class FlagsPropPanel
: public PropertyPanel
268 FlagsPropPanel(wxWindow
*parent
, PropertyHandler
*hnd
, PropsListInfo
*pli
) : PropertyPanel(parent
, hnd
, pli
)
271 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
272 sizer
->Add(m_chl
= new wxCheckListBox(this, ID_CHECKLIST
), 1, wxEXPAND
|wxALL
, 5);
278 wxStringTokenizer
tkn(pli
->m_PropInfo
->MoreInfo
, ",");
280 while (tkn
.HasMoreTokens())
282 s
= tkn
.GetNextToken();
289 wxStringTokenizer
tkn(XmlReadValue(pli
->m_Node
, pli
->m_PropInfo
->Name
), "| ");
291 while (tkn
.HasMoreTokens())
293 index
= m_flags
.Index(tkn
.GetNextToken());
294 if (index
!= wxNOT_FOUND
)
300 void OnEdit(wxCommandEvent
&event
)
305 for (size_t i
= 0; i
< m_flags
.GetCount(); i
++)
307 if (m_chl
->IsChecked(i
))
309 if (!first
) s
<< '|';
315 if (m_PLI
->m_PropInfo
->Name
== "orient")
316 // FIXME - dirty hack related to sizers
317 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED_ICON
);
320 wxCheckListBox
*m_chl
;
321 wxArrayString m_flags
;
323 DECLARE_EVENT_TABLE()
326 BEGIN_EVENT_TABLE(FlagsPropPanel
, PropertyPanel
)
327 EVT_CHECKLISTBOX(ID_CHECKLIST
, FlagsPropPanel::OnEdit
)
330 wxPanel
*FlagsPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
332 return new FlagsPropPanel(parent
, this, pli
);
338 wxPanel
*NotImplPropertyHandler::CreateEditPanel(wxWindow
*parent
, PropsListInfo
*pli
)
340 wxPanel
*p
= new wxPanel(parent
);
341 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
342 sizer
->Add(new wxStaticText(p
, -1, _("Sorry, this is not supported.\nYou have to edit XML code directly.")), 1, wxEXPAND
|wxALL
, 5);
343 p
->SetAutoLayout(TRUE
);