]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/nodehnd.cpp
added patch for theme savvy checkbox metrics
[wxWidgets.git] / contrib / utils / wxrcedit / nodehnd.cpp
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/xrc/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"
31 #include "nodesdb.h"
32
33
34
35 wxList NodeHandler::ms_Handlers;
36 bool NodeHandler::ms_HandlersLoaded = FALSE;
37
38
39 NodeHandler *NodeHandler::Find(wxXmlNode *node)
40 {
41 if (!ms_HandlersLoaded)
42 {
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++)
49 {
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);
65 }
66 ms_Handlers.Append(new NodeHandlerUnknown);
67 }
68
69 wxNode *n = ms_Handlers.GetFirst();
70 while (n)
71 {
72 NodeHandler *h = (NodeHandler*) n->GetData();
73 if (h->CanHandle(node))
74 return h;
75 n = n->GetNext();
76 }
77 return NULL;
78 }
79
80
81
82
83 NodeHandler::NodeHandler(NodeInfo *ni) :
84 m_NodeInfo(ni)
85 {
86 }
87
88
89 NodeHandler::~NodeHandler()
90 {
91 }
92
93
94
95 bool NodeHandler::CanHandle(wxXmlNode *node)
96 {
97 return (m_NodeInfo->NodeClass == XmlGetClass(node));
98 }
99
100
101
102
103 PropertyInfoArray& NodeHandler::GetPropsList(wxXmlNode *node)
104 {
105 return m_NodeInfo->Props;
106 }
107
108
109
110 wxTreeItemId 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
125 wxString NodeHandler::GetTreeString(wxXmlNode *node)
126 {
127 wxString xmlid = node->GetPropVal(_T("name"), wxEmptyString);
128 if (xmlid.IsEmpty())
129 return XmlGetClass(node);
130 else
131 return XmlGetClass(node) + _T(" '") + xmlid + _T("'");
132 }
133
134
135
136
137 wxArrayString& NodeHandler::GetChildTypes()
138 {
139 if (m_ChildTypes.IsEmpty())
140 {
141 wxString basetype = m_NodeInfo->ChildType;
142 NodeInfoArray& arr = NodesDb::Get()->GetNodesInfo();
143
144 for (size_t i = 0; i < arr.GetCount(); i++)
145 {
146 NodeInfo &ni = arr[i];
147
148 if (ni.NodeClass == basetype && !ni.Abstract)
149 m_ChildTypes.Add(ni.NodeClass);
150
151 if (ni.DerivedFrom.Index(basetype) != wxNOT_FOUND && !ni.Abstract)
152 m_ChildTypes.Add(ni.NodeClass);
153 }
154 m_ChildTypes.Sort();
155 }
156
157 return m_ChildTypes;
158 }
159
160
161
162 void 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
175 wxTreeItemId NodeHandlerPanel::CreateTreeNode(wxTreeCtrl *treectrl,
176 wxTreeItemId parent,
177 wxXmlNode *node)
178 {
179 wxTreeItemId root = NodeHandler::CreateTreeNode(treectrl, parent, node);
180
181 wxXmlNode *n = XmlFindNode(node, "object");
182
183 while (n)
184 {
185 if (n->GetType() == wxXML_ELEMENT_NODE &&
186 n->GetName() == _T("object"))
187 Find(n)->CreateTreeNode(treectrl, root, n);
188 n = n->GetNext();
189 }
190 //treectrl->Expand(root);
191 return root;
192 }
193
194
195
196 void NodeHandlerPanel::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
197 {
198 if (insert_before)
199 parent->InsertChild(node, insert_before);
200 else
201 parent->AddChild(node);
202 EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
203 }
204
205
206
207
208
209 void NodeHandlerSizer::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
210 {
211 if (XmlGetClass(node) == _T("spacer") || XmlGetClass(node) == _T("sizeritem"))
212 {
213 if (insert_before)
214 parent->InsertChild(node, insert_before);
215 else
216 parent->AddChild(node);
217 }
218 else
219 {
220 wxXmlNode *itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, _T("object"));
221 itemnode->AddProperty(_T("class"), _T("sizeritem"));
222 itemnode->AddChild(node);
223
224 if (insert_before)
225 parent->InsertChild(itemnode, insert_before);
226 else
227 parent->AddChild(itemnode);
228 }
229 EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
230 }
231
232
233
234 int NodeHandlerSizer::GetTreeIcon(wxXmlNode *node)
235 {
236 int orig = NodeHandler::GetTreeIcon(node);
237 if (orig == 0)
238 {
239 if (XmlReadValue(node, _T("orient")) == _T("wxVERTICAL")) return 2;
240 else return 3;
241 }
242 else return orig;
243 }
244
245
246
247 wxTreeItemId NodeHandlerSizerItem::CreateTreeNode(wxTreeCtrl *treectrl,
248 wxTreeItemId parent,
249 wxXmlNode *node)
250 {
251 wxTreeItemId root;
252
253 root = Find(GetRealNode(node))->CreateTreeNode(treectrl, parent, GetRealNode(node));
254 ((XmlTreeData*)treectrl->GetItemData(root))->Node = node;
255
256 //treectrl->Expand(root);
257 return root;
258 }
259
260
261
262 PropertyInfoArray& NodeHandlerSizerItem::GetPropsList(wxXmlNode *node)
263 {
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;
274 }
275
276
277
278 wxString NodeHandlerSizerItem::GetTreeString(wxXmlNode *node)
279 {
280 wxXmlNode *n = GetRealNode(node);
281 return Find(n)->GetTreeString(n);
282 }
283
284
285
286 int NodeHandlerSizerItem::GetTreeIcon(wxXmlNode *node)
287 {
288 wxXmlNode *n = GetRealNode(node);
289 return Find(n)->GetTreeIcon(n);
290 }
291
292
293
294 wxXmlNode *NodeHandlerSizerItem::GetRealNode(wxXmlNode *node)
295 {
296 return XmlFindNode(node, _T("object"));
297 }
298
299
300
301
302
303
304 void NodeHandlerNotebook::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
305 {
306 {
307 wxXmlNode *itemnode;
308
309 if (XmlGetClass(node) == _T("notebookpage"))
310 itemnode = node;
311 else
312 {
313 itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, _T("object"));
314 itemnode->AddProperty(_T("class"), _T("notebookpage"));
315 itemnode->AddChild(node);
316 }
317
318 if (insert_before)
319 parent->InsertChild(itemnode, insert_before);
320 else
321 parent->AddChild(itemnode);
322 }
323 EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
324 }