2000-07-25 14:47:21 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 2000/05/05
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2000 Vaclav Slavik
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "nodehnd.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "nodehnd.h"
|
2001-06-09 18:18:45 -04:00
|
|
|
#include "wx/xrc/xml.h"
|
2000-07-25 14:47:21 -04:00
|
|
|
#include "wx/filefn.h"
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#include "wx/arrimpl.cpp"
|
|
|
|
#include "wx/textfile.h"
|
|
|
|
#include "wx/tokenzr.h"
|
|
|
|
#include "wx/listctrl.h"
|
|
|
|
#include "editor.h"
|
|
|
|
#include "treedt.h"
|
|
|
|
#include "xmlhelpr.h"
|
2000-11-04 18:34:33 -05:00
|
|
|
#include "nodesdb.h"
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
wxList NodeHandler::ms_Handlers;
|
|
|
|
bool NodeHandler::ms_HandlersLoaded = FALSE;
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
NodeHandler *NodeHandler::Find(wxXmlNode *node)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-11-04 18:34:33 -05:00
|
|
|
if (!ms_HandlersLoaded)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-11-04 18:34:33 -05:00
|
|
|
ms_HandlersLoaded = TRUE;
|
|
|
|
ms_Handlers.DeleteContents(TRUE);
|
|
|
|
|
|
|
|
NodeInfoArray& arr = NodesDb::Get()->GetNodesInfo();
|
|
|
|
NodeHandler *hnd;
|
|
|
|
for (size_t i = 0; i < arr.GetCount(); i++)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-11-04 18:34:33 -05:00
|
|
|
if (arr[i].NodeClass.IsEmpty() || arr[i].Abstract) continue;
|
|
|
|
|
|
|
|
if (arr[i].Type == _T("panel"))
|
|
|
|
hnd = new NodeHandlerPanel(&(arr[i]));
|
|
|
|
else if (arr[i].Type == _T("sizer"))
|
|
|
|
hnd = new NodeHandlerSizer(&(arr[i]));
|
|
|
|
else if (arr[i].Type == _T("sizeritem"))
|
|
|
|
hnd = new NodeHandlerSizerItem(&(arr[i]));
|
|
|
|
else if (arr[i].Type == _T("notebook"))
|
|
|
|
hnd = new NodeHandlerNotebook(&(arr[i]));
|
|
|
|
else if (arr[i].Type == _T("notebookpage"))
|
|
|
|
hnd = new NodeHandlerNotebookPage(&(arr[i]));
|
|
|
|
else
|
|
|
|
hnd = new NodeHandler(&(arr[i]));
|
|
|
|
if (hnd) ms_Handlers.Append(hnd);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
2000-11-04 18:34:33 -05:00
|
|
|
ms_Handlers.Append(new NodeHandlerUnknown);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
wxNode *n = ms_Handlers.GetFirst();
|
|
|
|
while (n)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-11-04 18:34:33 -05:00
|
|
|
NodeHandler *h = (NodeHandler*) n->GetData();
|
|
|
|
if (h->CanHandle(node))
|
|
|
|
return h;
|
|
|
|
n = n->GetNext();
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
2000-11-04 18:34:33 -05:00
|
|
|
return NULL;
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
NodeHandler::NodeHandler(NodeInfo *ni) :
|
2000-07-25 14:47:21 -04:00
|
|
|
m_NodeInfo(ni)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
NodeHandler::~NodeHandler()
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
|
|
|
|
bool NodeHandler::CanHandle(wxXmlNode *node)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-11-04 18:34:33 -05:00
|
|
|
return (m_NodeInfo->NodeClass == XmlGetClass(node));
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
|
|
|
|
PropertyInfoArray& NodeHandler::GetPropsList(wxXmlNode *node)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-11-04 18:34:33 -05:00
|
|
|
return m_NodeInfo->Props;
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxTreeItemId NodeHandler::CreateTreeNode(wxTreeCtrl *treectrl,
|
|
|
|
wxTreeItemId parent,
|
|
|
|
wxXmlNode *node)
|
|
|
|
{
|
|
|
|
int icon = GetTreeIcon(node);
|
|
|
|
wxTreeItemId item =
|
|
|
|
treectrl->AppendItem(parent, GetTreeString(node),
|
|
|
|
icon, icon, new XmlTreeData(node));
|
|
|
|
if (parent == treectrl->GetRootItem())
|
|
|
|
treectrl->SetItemBold(item);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxString NodeHandler::GetTreeString(wxXmlNode *node)
|
|
|
|
{
|
2000-10-07 17:56:37 -04:00
|
|
|
wxString xmlid = node->GetPropVal(_T("name"), wxEmptyString);
|
2000-07-25 14:47:21 -04:00
|
|
|
if (xmlid.IsEmpty())
|
2000-10-07 17:56:37 -04:00
|
|
|
return XmlGetClass(node);
|
2000-07-25 14:47:21 -04:00
|
|
|
else
|
2000-10-07 17:56:37 -04:00
|
|
|
return XmlGetClass(node) + _T(" '") + xmlid + _T("'");
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString& NodeHandler::GetChildTypes()
|
|
|
|
{
|
|
|
|
if (m_ChildTypes.IsEmpty())
|
|
|
|
{
|
|
|
|
wxString basetype = m_NodeInfo->ChildType;
|
2000-11-04 18:34:33 -05:00
|
|
|
NodeInfoArray& arr = NodesDb::Get()->GetNodesInfo();
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
for (size_t i = 0; i < arr.GetCount(); i++)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-11-04 18:34:33 -05:00
|
|
|
NodeInfo &ni = arr[i];
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
if (ni.NodeClass == basetype && !ni.Abstract)
|
|
|
|
m_ChildTypes.Add(ni.NodeClass);
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
if (ni.DerivedFrom.Index(basetype) != wxNOT_FOUND && !ni.Abstract)
|
2000-11-04 18:34:33 -05:00
|
|
|
m_ChildTypes.Add(ni.NodeClass);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
m_ChildTypes.Sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_ChildTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NodeHandler::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
|
|
|
|
{
|
|
|
|
delete node;
|
|
|
|
wxLogError(_("Cannot insert child into this type of node!"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxTreeItemId NodeHandlerPanel::CreateTreeNode(wxTreeCtrl *treectrl,
|
|
|
|
wxTreeItemId parent,
|
|
|
|
wxXmlNode *node)
|
|
|
|
{
|
|
|
|
wxTreeItemId root = NodeHandler::CreateTreeNode(treectrl, parent, node);
|
|
|
|
|
2000-10-07 17:56:37 -04:00
|
|
|
wxXmlNode *n = XmlFindNode(node, "object");
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
while (n)
|
|
|
|
{
|
2000-10-07 17:56:37 -04:00
|
|
|
if (n->GetType() == wxXML_ELEMENT_NODE &&
|
|
|
|
n->GetName() == _T("object"))
|
2000-11-04 18:34:33 -05:00
|
|
|
Find(n)->CreateTreeNode(treectrl, root, n);
|
2000-07-25 14:47:21 -04:00
|
|
|
n = n->GetNext();
|
|
|
|
}
|
2000-11-04 18:34:33 -05:00
|
|
|
//treectrl->Expand(root);
|
2000-07-25 14:47:21 -04:00
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NodeHandlerPanel::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
|
|
|
|
{
|
|
|
|
if (insert_before)
|
2000-10-07 17:56:37 -04:00
|
|
|
parent->InsertChild(node, insert_before);
|
2000-07-25 14:47:21 -04:00
|
|
|
else
|
2000-10-07 17:56:37 -04:00
|
|
|
parent->AddChild(node);
|
2000-07-25 14:47:21 -04:00
|
|
|
EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NodeHandlerSizer::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
|
2000-10-07 17:56:37 -04:00
|
|
|
{
|
|
|
|
if (XmlGetClass(node) == _T("spacer") || XmlGetClass(node) == _T("sizeritem"))
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
|
|
|
if (insert_before)
|
2000-10-07 17:56:37 -04:00
|
|
|
parent->InsertChild(node, insert_before);
|
2000-07-25 14:47:21 -04:00
|
|
|
else
|
2000-10-07 17:56:37 -04:00
|
|
|
parent->AddChild(node);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-07 17:56:37 -04:00
|
|
|
wxXmlNode *itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, _T("object"));
|
|
|
|
itemnode->AddProperty(_T("class"), _T("sizeritem"));
|
|
|
|
itemnode->AddChild(node);
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
if (insert_before)
|
2000-10-07 17:56:37 -04:00
|
|
|
parent->InsertChild(itemnode, insert_before);
|
2000-07-25 14:47:21 -04:00
|
|
|
else
|
2000-10-07 17:56:37 -04:00
|
|
|
parent->AddChild(itemnode);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int NodeHandlerSizer::GetTreeIcon(wxXmlNode *node)
|
|
|
|
{
|
2000-07-27 14:52:12 -04:00
|
|
|
int orig = NodeHandler::GetTreeIcon(node);
|
|
|
|
if (orig == 0)
|
|
|
|
{
|
2000-10-07 17:56:37 -04:00
|
|
|
if (XmlReadValue(node, _T("orient")) == _T("wxVERTICAL")) return 2;
|
2000-07-27 14:52:12 -04:00
|
|
|
else return 3;
|
|
|
|
}
|
|
|
|
else return orig;
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxTreeItemId NodeHandlerSizerItem::CreateTreeNode(wxTreeCtrl *treectrl,
|
|
|
|
wxTreeItemId parent,
|
|
|
|
wxXmlNode *node)
|
|
|
|
{
|
|
|
|
wxTreeItemId root;
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
root = Find(GetRealNode(node))->CreateTreeNode(treectrl, parent, GetRealNode(node));
|
2000-07-25 14:47:21 -04:00
|
|
|
((XmlTreeData*)treectrl->GetItemData(root))->Node = node;
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
//treectrl->Expand(root);
|
2000-07-25 14:47:21 -04:00
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-04 18:34:33 -05:00
|
|
|
PropertyInfoArray& NodeHandlerSizerItem::GetPropsList(wxXmlNode *node)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-11-04 18:34:33 -05:00
|
|
|
m_dummy = NodeHandler::GetPropsList(node);
|
|
|
|
wxXmlNode *nd = GetRealNode(node);
|
|
|
|
m_dummy.Add(PropertyInfo(wxEmptyString, wxEmptyString, wxEmptyString));
|
|
|
|
size_t pos = m_dummy.GetCount();
|
|
|
|
WX_APPEND_ARRAY(m_dummy,
|
|
|
|
Find(nd)->GetPropsList(nd));
|
|
|
|
for (size_t i = pos; i < m_dummy.GetCount(); i++)
|
|
|
|
m_dummy[i].Name = _T("object/") + m_dummy[i].Name;
|
|
|
|
|
|
|
|
return m_dummy;
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxString NodeHandlerSizerItem::GetTreeString(wxXmlNode *node)
|
|
|
|
{
|
|
|
|
wxXmlNode *n = GetRealNode(node);
|
2000-11-04 18:34:33 -05:00
|
|
|
return Find(n)->GetTreeString(n);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int NodeHandlerSizerItem::GetTreeIcon(wxXmlNode *node)
|
|
|
|
{
|
|
|
|
wxXmlNode *n = GetRealNode(node);
|
2000-11-04 18:34:33 -05:00
|
|
|
return Find(n)->GetTreeIcon(n);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxXmlNode *NodeHandlerSizerItem::GetRealNode(wxXmlNode *node)
|
|
|
|
{
|
2000-10-07 17:56:37 -04:00
|
|
|
return XmlFindNode(node, _T("object"));
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
2000-07-27 14:52:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NodeHandlerNotebook::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before)
|
2000-10-07 17:56:37 -04:00
|
|
|
{
|
2000-07-27 14:52:12 -04:00
|
|
|
{
|
2000-08-06 12:51:32 -04:00
|
|
|
wxXmlNode *itemnode;
|
|
|
|
|
2000-10-07 17:56:37 -04:00
|
|
|
if (XmlGetClass(node) == _T("notebookpage"))
|
2000-08-06 12:51:32 -04:00
|
|
|
itemnode = node;
|
|
|
|
else
|
|
|
|
{
|
2000-10-07 17:56:37 -04:00
|
|
|
itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, _T("object"));
|
|
|
|
itemnode->AddProperty(_T("class"), _T("notebookpage"));
|
|
|
|
itemnode->AddChild(node);
|
2000-08-06 12:51:32 -04:00
|
|
|
}
|
2000-07-27 14:52:12 -04:00
|
|
|
|
|
|
|
if (insert_before)
|
2000-10-07 17:56:37 -04:00
|
|
|
parent->InsertChild(itemnode, insert_before);
|
2000-07-27 14:52:12 -04:00
|
|
|
else
|
2000-10-07 17:56:37 -04:00
|
|
|
parent->AddChild(itemnode);
|
2000-07-27 14:52:12 -04:00
|
|
|
}
|
|
|
|
EditorFrame::Get()->NotifyChanged(CHANGED_TREE);
|
|
|
|
}
|