]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/nodehnd.cpp
306e91264cc1b747d1da2987781e3389697d232d
1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "nodehnd.h"
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
21 #include "wx/xrc/xml.h"
22 #include "wx/filefn.h"
24 #include "wx/arrimpl.cpp"
25 #include "wx/textfile.h"
26 #include "wx/tokenzr.h"
27 #include "wx/listctrl.h"
35 wxList
NodeHandler::ms_Handlers
;
36 bool NodeHandler::ms_HandlersLoaded
= FALSE
;
39 NodeHandler
*NodeHandler::Find(wxXmlNode
*node
)
41 if (!ms_HandlersLoaded
)
43 ms_HandlersLoaded
= TRUE
;
44 ms_Handlers
.DeleteContents(TRUE
);
46 NodeInfoArray
& arr
= NodesDb::Get()->GetNodesInfo();
48 for (size_t i
= 0; i
< arr
.GetCount(); i
++)
50 if (arr
[i
].NodeClass
.IsEmpty() || arr
[i
].Abstract
) continue;
52 if (arr
[i
].Type
== _T("panel"))
53 hnd
= new NodeHandlerPanel(&(arr
[i
]));
54 else if (arr
[i
].Type
== _T("sizer"))
55 hnd
= new NodeHandlerSizer(&(arr
[i
]));
56 else if (arr
[i
].Type
== _T("sizeritem"))
57 hnd
= new NodeHandlerSizerItem(&(arr
[i
]));
58 else if (arr
[i
].Type
== _T("notebook"))
59 hnd
= new NodeHandlerNotebook(&(arr
[i
]));
60 else if (arr
[i
].Type
== _T("notebookpage"))
61 hnd
= new NodeHandlerNotebookPage(&(arr
[i
]));
63 hnd
= new NodeHandler(&(arr
[i
]));
64 if (hnd
) ms_Handlers
.Append(hnd
);
66 ms_Handlers
.Append(new NodeHandlerUnknown
);
69 wxNode
*n
= ms_Handlers
.GetFirst();
72 NodeHandler
*h
= (NodeHandler
*) n
->GetData();
73 if (h
->CanHandle(node
))
83 NodeHandler::NodeHandler(NodeInfo
*ni
) :
89 NodeHandler::~NodeHandler()
95 bool NodeHandler::CanHandle(wxXmlNode
*node
)
97 return (m_NodeInfo
->NodeClass
== XmlGetClass(node
));
103 PropertyInfoArray
& NodeHandler::GetPropsList(wxXmlNode
*node
)
105 return m_NodeInfo
->Props
;
110 wxTreeItemId
NodeHandler::CreateTreeNode(wxTreeCtrl
*treectrl
,
114 int icon
= GetTreeIcon(node
);
116 treectrl
->AppendItem(parent
, GetTreeString(node
),
117 icon
, icon
, new XmlTreeData(node
));
118 if (parent
== treectrl
->GetRootItem())
119 treectrl
->SetItemBold(item
);
125 wxString
NodeHandler::GetTreeString(wxXmlNode
*node
)
127 wxString xmlid
= node
->GetPropVal(_T("name"), wxEmptyString
);
129 return XmlGetClass(node
);
131 return XmlGetClass(node
) + _T(" '") + xmlid
+ _T("'");
137 wxArrayString
& NodeHandler::GetChildTypes()
139 if (m_ChildTypes
.IsEmpty())
141 wxString basetype
= m_NodeInfo
->ChildType
;
142 NodeInfoArray
& arr
= NodesDb::Get()->GetNodesInfo();
144 for (size_t i
= 0; i
< arr
.GetCount(); i
++)
146 NodeInfo
&ni
= arr
[i
];
148 if (ni
.NodeClass
== basetype
&& !ni
.Abstract
)
149 m_ChildTypes
.Add(ni
.NodeClass
);
151 if (ni
.DerivedFrom
.Index(basetype
) != wxNOT_FOUND
&& !ni
.Abstract
)
152 m_ChildTypes
.Add(ni
.NodeClass
);
162 void NodeHandler::InsertNode(wxXmlNode
*parent
, wxXmlNode
*node
, wxXmlNode
*insert_before
)
165 wxLogError(_("Cannot insert child into this type of node!"));
175 wxTreeItemId
NodeHandlerPanel::CreateTreeNode(wxTreeCtrl
*treectrl
,
179 wxTreeItemId root
= NodeHandler::CreateTreeNode(treectrl
, parent
, node
);
181 wxXmlNode
*n
= XmlFindNode(node
, "object");
185 if (n
->GetType() == wxXML_ELEMENT_NODE
&&
186 n
->GetName() == _T("object"))
187 Find(n
)->CreateTreeNode(treectrl
, root
, n
);
190 //treectrl->Expand(root);
196 void NodeHandlerPanel::InsertNode(wxXmlNode
*parent
, wxXmlNode
*node
, wxXmlNode
*insert_before
)
199 parent
->InsertChild(node
, insert_before
);
201 parent
->AddChild(node
);
202 EditorFrame::Get()->NotifyChanged(CHANGED_TREE
);
209 void NodeHandlerSizer::InsertNode(wxXmlNode
*parent
, wxXmlNode
*node
, wxXmlNode
*insert_before
)
211 if (XmlGetClass(node
) == _T("spacer") || XmlGetClass(node
) == _T("sizeritem"))
214 parent
->InsertChild(node
, insert_before
);
216 parent
->AddChild(node
);
220 wxXmlNode
*itemnode
= new wxXmlNode(wxXML_ELEMENT_NODE
, _T("object"));
221 itemnode
->AddProperty(_T("class"), _T("sizeritem"));
222 itemnode
->AddChild(node
);
225 parent
->InsertChild(itemnode
, insert_before
);
227 parent
->AddChild(itemnode
);
229 EditorFrame::Get()->NotifyChanged(CHANGED_TREE
);
234 int NodeHandlerSizer::GetTreeIcon(wxXmlNode
*node
)
236 int orig
= NodeHandler::GetTreeIcon(node
);
239 if (XmlReadValue(node
, _T("orient")) == _T("wxVERTICAL")) return 2;
247 wxTreeItemId
NodeHandlerSizerItem::CreateTreeNode(wxTreeCtrl
*treectrl
,
253 root
= Find(GetRealNode(node
))->CreateTreeNode(treectrl
, parent
, GetRealNode(node
));
254 ((XmlTreeData
*)treectrl
->GetItemData(root
))->Node
= node
;
256 //treectrl->Expand(root);
262 PropertyInfoArray
& NodeHandlerSizerItem::GetPropsList(wxXmlNode
*node
)
264 m_dummy
= NodeHandler::GetPropsList(node
);
265 wxXmlNode
*nd
= GetRealNode(node
);
266 m_dummy
.Add(PropertyInfo(wxEmptyString
, wxEmptyString
, wxEmptyString
));
267 size_t pos
= m_dummy
.GetCount();
268 WX_APPEND_ARRAY(m_dummy
,
269 Find(nd
)->GetPropsList(nd
));
270 for (size_t i
= pos
; i
< m_dummy
.GetCount(); i
++)
271 m_dummy
[i
].Name
= _T("object/") + m_dummy
[i
].Name
;
278 wxString
NodeHandlerSizerItem::GetTreeString(wxXmlNode
*node
)
280 wxXmlNode
*n
= GetRealNode(node
);
281 return Find(n
)->GetTreeString(n
);
286 int NodeHandlerSizerItem::GetTreeIcon(wxXmlNode
*node
)
288 wxXmlNode
*n
= GetRealNode(node
);
289 return Find(n
)->GetTreeIcon(n
);
294 wxXmlNode
*NodeHandlerSizerItem::GetRealNode(wxXmlNode
*node
)
296 return XmlFindNode(node
, _T("object"));
304 void NodeHandlerNotebook::InsertNode(wxXmlNode
*parent
, wxXmlNode
*node
, wxXmlNode
*insert_before
)
309 if (XmlGetClass(node
) == _T("notebookpage"))
313 itemnode
= new wxXmlNode(wxXML_ELEMENT_NODE
, _T("object"));
314 itemnode
->AddProperty(_T("class"), _T("notebookpage"));
315 itemnode
->AddChild(node
);
319 parent
->InsertChild(itemnode
, insert_before
);
321 parent
->AddChild(itemnode
);
323 EditorFrame::Get()->NotifyChanged(CHANGED_TREE
);