]> git.saurik.com Git - wxWidgets.git/blame - contrib/utils/wxrcedit/nodehnd.cpp
fixed 'patch' #422993 (Error in wxConfigBase::Write for doubles)
[wxWidgets.git] / contrib / utils / wxrcedit / nodehnd.cpp
CommitLineData
56d2f750
VS
1/////////////////////////////////////////////////////////////////////////////
2// Author: Vaclav Slavik
3// Created: 2000/05/05
4// RCS-ID: $Id$
5// Copyright: (c) 2000 Vaclav Slavik
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9#ifdef __GNUG__
10 #pragma implementation "nodehnd.h"
11#endif
12
13// For compilers that support precompilation, includes "wx/wx.h".
14#include "wx/wxprec.h"
15
16#ifdef __BORLANDC__
17 #pragma hdrstop
18#endif
19
20#include "nodehnd.h"
21#include "wx/xml/xml.h"
22#include "wx/filefn.h"
23#include "wx/wx.h"
24#include "wx/arrimpl.cpp"
25#include "wx/textfile.h"
26#include "wx/tokenzr.h"
27#include "wx/listctrl.h"
28#include "editor.h"
29#include "treedt.h"
30#include "xmlhelpr.h"
12d9e308 31#include "nodesdb.h"
56d2f750
VS
32
33
56d2f750 34
12d9e308
VS
35wxList NodeHandler::ms_Handlers;
36bool NodeHandler::ms_HandlersLoaded = FALSE;
56d2f750
VS
37
38
12d9e308 39NodeHandler *NodeHandler::Find(wxXmlNode *node)
56d2f750 40{
12d9e308 41 if (!ms_HandlersLoaded)
56d2f750 42 {
12d9e308
VS
43 ms_HandlersLoaded = TRUE;
44 ms_Handlers.DeleteContents(TRUE);
45
46 NodeInfoArray& arr = NodesDb::Get()->GetNodesInfo();
47 NodeHandler *hnd;
48 for (size_t i = 0; i < arr.GetCount(); i++)
56d2f750 49 {
12d9e308
VS
50 if (arr[i].NodeClass.IsEmpty() || arr[i].Abstract) continue;
51
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]));
62 else
63 hnd = new NodeHandler(&(arr[i]));
64 if (hnd) ms_Handlers.Append(hnd);
56d2f750 65 }
12d9e308 66 ms_Handlers.Append(new NodeHandlerUnknown);
56d2f750 67 }
56d2f750 68
12d9e308
VS
69 wxNode *n = ms_Handlers.GetFirst();
70 while (n)
56d2f750 71 {
12d9e308
VS
72 NodeHandler *h = (NodeHandler*) n->GetData();
73 if (h->CanHandle(node))
74 return h;
75 n = n->GetNext();
56d2f750 76 }
12d9e308 77 return NULL;
56d2f750
VS
78}
79
80
81
82
12d9e308 83NodeHandler::NodeHandler(NodeInfo *ni) :
56d2f750
VS
84 m_NodeInfo(ni)
85{
56d2f750
VS
86}
87
88
12d9e308 89NodeHandler::~NodeHandler()
56d2f750 90{
56d2f750
VS
91}
92
93
12d9e308
VS
94
95bool NodeHandler::CanHandle(wxXmlNode *node)
56d2f750 96{
12d9e308 97 return (m_NodeInfo->NodeClass == XmlGetClass(node));
56d2f750
VS
98}
99
100
101
12d9e308
VS
102
103PropertyInfoArray& NodeHandler::GetPropsList(wxXmlNode *node)
56d2f750 104{
12d9e308 105 return m_NodeInfo->Props;
56d2f750
VS
106}
107
108
109
110wxTreeItemId NodeHandler::CreateTreeNode(wxTreeCtrl *treectrl,
111 wxTreeItemId parent,
112 wxXmlNode *node)
113{
114 int icon = GetTreeIcon(node);
115 wxTreeItemId item =
116 treectrl->AppendItem(parent, GetTreeString(node),
117 icon, icon, new XmlTreeData(node));
118 if (parent == treectrl->GetRootItem())
119 treectrl->SetItemBold(item);
120 return item;
121}
122
123
124
125wxString NodeHandler::GetTreeString(wxXmlNode *node)
126{
e066e256 127 wxString xmlid = node->GetPropVal(_T("name"), wxEmptyString);
56d2f750 128 if (xmlid.IsEmpty())
e066e256 129 return XmlGetClass(node);
56d2f750 130 else
e066e256 131 return XmlGetClass(node) + _T(" '") + xmlid + _T("'");
56d2f750
VS
132}
133
134
135
56d2f750
VS
136
137wxArrayString& NodeHandler::GetChildTypes()
138{
139 if (m_ChildTypes.IsEmpty())
140 {
141 wxString basetype = m_NodeInfo->ChildType;
12d9e308 142 NodeInfoArray& arr = NodesDb::Get()->GetNodesInfo();
56d2f750 143
12d9e308 144 for (size_t i = 0; i < arr.GetCount(); i++)
56d2f750 145 {
12d9e308 146 NodeInfo &ni = arr[i];
56d2f750 147
12d9e308
VS
148 if (ni.NodeClass == basetype && !ni.Abstract)
149 m_ChildTypes.Add(ni.NodeClass);
56d2f750
VS
150
151 if (ni.DerivedFrom.Index(basetype) != wxNOT_FOUND && !ni.Abstract)
12d9e308 152 m_ChildTypes.Add(ni.NodeClass);
56d2f750
VS
153 }
154 m_ChildTypes.Sort();
155 }
156
157 return m_ChildTypes;
158}
159
160
161
162void NodeHandler::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
163{
164 delete node;
165 wxLogError(_("Cannot insert child into this type of node!"));
166}
167
168
169
170
171
172
173
174
175wxTreeItemId NodeHandlerPanel::CreateTreeNode(wxTreeCtrl *treectrl,
176 wxTreeItemId parent,
177 wxXmlNode *node)
178{
179 wxTreeItemId root = NodeHandler::CreateTreeNode(treectrl, parent, node);
180
e066e256 181 wxXmlNode *n = XmlFindNode(node, "object");
56d2f750 182
56d2f750
VS
183 while (n)
184 {
e066e256
VS
185 if (n->GetType() == wxXML_ELEMENT_NODE &&
186 n->GetName() == _T("object"))
12d9e308 187 Find(n)->CreateTreeNode(treectrl, root, n);
56d2f750
VS
188 n = n->GetNext();
189 }
12d9e308 190 //treectrl->Expand(root);
56d2f750
VS
191 return root;
192}
193
194
195
196void NodeHandlerPanel::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
197{
56d2f750 198 if (insert_before)
e066e256 199 parent->InsertChild(node, insert_before);
56d2f750 200 else
e066e256 201 parent->AddChild(node);
56d2f750
VS
202 EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
203}
204
205
206
207
208
209void NodeHandlerSizer::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
e066e256
VS
210{
211 if (XmlGetClass(node) == _T("spacer") || XmlGetClass(node) == _T("sizeritem"))
56d2f750
VS
212 {
213 if (insert_before)
e066e256 214 parent->InsertChild(node, insert_before);
56d2f750 215 else
e066e256 216 parent->AddChild(node);
56d2f750
VS
217 }
218 else
219 {
e066e256
VS
220 wxXmlNode *itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, _T("object"));
221 itemnode->AddProperty(_T("class"), _T("sizeritem"));
222 itemnode->AddChild(node);
56d2f750
VS
223
224 if (insert_before)
e066e256 225 parent->InsertChild(itemnode, insert_before);
56d2f750 226 else
e066e256 227 parent->AddChild(itemnode);
56d2f750
VS
228 }
229 EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
230}
231
232
233
234int NodeHandlerSizer::GetTreeIcon(wxXmlNode *node)
235{
ab13d1c5
VS
236 int orig = NodeHandler::GetTreeIcon(node);
237 if (orig == 0)
238 {
e066e256 239 if (XmlReadValue(node, _T("orient")) == _T("wxVERTICAL")) return 2;
ab13d1c5
VS
240 else return 3;
241 }
242 else return orig;
56d2f750
VS
243}
244
245
246
247wxTreeItemId NodeHandlerSizerItem::CreateTreeNode(wxTreeCtrl *treectrl,
248 wxTreeItemId parent,
249 wxXmlNode *node)
250{
251 wxTreeItemId root;
252
12d9e308 253 root = Find(GetRealNode(node))->CreateTreeNode(treectrl, parent, GetRealNode(node));
56d2f750
VS
254 ((XmlTreeData*)treectrl->GetItemData(root))->Node = node;
255
12d9e308 256 //treectrl->Expand(root);
56d2f750
VS
257 return root;
258}
259
260
261
12d9e308 262PropertyInfoArray& NodeHandlerSizerItem::GetPropsList(wxXmlNode *node)
56d2f750 263{
12d9e308
VS
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;
272
273 return m_dummy;
56d2f750
VS
274}
275
276
277
278wxString NodeHandlerSizerItem::GetTreeString(wxXmlNode *node)
279{
280 wxXmlNode *n = GetRealNode(node);
12d9e308 281 return Find(n)->GetTreeString(n);
56d2f750
VS
282}
283
284
285
286int NodeHandlerSizerItem::GetTreeIcon(wxXmlNode *node)
287{
288 wxXmlNode *n = GetRealNode(node);
12d9e308 289 return Find(n)->GetTreeIcon(n);
56d2f750
VS
290}
291
292
293
294wxXmlNode *NodeHandlerSizerItem::GetRealNode(wxXmlNode *node)
295{
e066e256 296 return XmlFindNode(node, _T("object"));
56d2f750 297}
ab13d1c5
VS
298
299
300
301
302
303
304void NodeHandlerNotebook::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
e066e256 305{
ab13d1c5 306 {
2ada7c65
VS
307 wxXmlNode *itemnode;
308
e066e256 309 if (XmlGetClass(node) == _T("notebookpage"))
2ada7c65
VS
310 itemnode = node;
311 else
312 {
e066e256
VS
313 itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, _T("object"));
314 itemnode->AddProperty(_T("class"), _T("notebookpage"));
315 itemnode->AddChild(node);
2ada7c65 316 }
ab13d1c5
VS
317
318 if (insert_before)
e066e256 319 parent->InsertChild(itemnode, insert_before);
ab13d1c5 320 else
e066e256 321 parent->AddChild(itemnode);
ab13d1c5
VS
322 }
323 EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
324}