X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/56d2f75071fc2a29ec10abe97c5a908bb35f30f4..19311d4e7c43a3f6243bf805c164fd76cada0386:/contrib/utils/wxrcedit/nodehnd.cpp diff --git a/contrib/utils/wxrcedit/nodehnd.cpp b/contrib/utils/wxrcedit/nodehnd.cpp index b8fc433f4c..2152ad8bb0 100644 --- a/contrib/utils/wxrcedit/nodehnd.cpp +++ b/contrib/utils/wxrcedit/nodehnd.cpp @@ -28,193 +28,91 @@ #include "editor.h" #include "treedt.h" #include "xmlhelpr.h" +#include "nodesdb.h" -WX_DEFINE_OBJARRAY(NodeInfoArray); +wxList NodeHandler::ms_Handlers; +bool NodeHandler::ms_HandlersLoaded = false; -void NodeInfo::Read(const wxString& filename) +NodeHandler *NodeHandler::Find(wxXmlNode *node) { - HandlerType tp = HANDLER_NONE; - wxString nd, cht; - bool ab = FALSE; - long icn = -1; - - Node.Empty(); - - wxPathList list; - list.Add("."); - list.Add("./df"); - #ifdef __UNIX__ - list.Add(wxGetHomeDir() + "/.wxrcedit"); - #endif - - wxString path = list.FindValidPath(filename); - if (path.IsEmpty()) return; - - wxTextFile tf; - tf.Open(path); - if (!tf.IsOpened()) return; - - for (size_t i = 0; i < tf.GetLineCount(); i++) + if (!ms_HandlersLoaded) { - if (tf[i].IsEmpty() || tf[i][0] == '#') continue; - wxStringTokenizer tkn(tf[i], ' '); - wxString s = tkn.GetNextToken(); - if (s == "node") - nd = tkn.GetNextToken(); - else if (s == "childtype") - cht = tkn.GetNextToken(); - else if (s == "icon") - tkn.GetNextToken().ToLong(&icn); - else if (s == "derived") - { - if (tkn.GetNextToken() == "from") - { - s = tkn.GetNextToken(); - DerivedFrom.Add(s); - Read(s + ".df"); - } - } - else if (s == "abstract") - ab = true; - else if (s == "type") - { - s = tkn.GetNextToken(); - if (s == "sizer") tp = HANDLER_SIZER; - else if (s == "sizeritem") tp = HANDLER_SIZERITEM; - else if (s == "panel") tp = HANDLER_PANEL; - else /*if (s == "normal")*/ tp = HANDLER_NORMAL; - } - else if (s == "var") + ms_HandlersLoaded = true; + ms_Handlers.DeleteContents(true); + + NodeInfoArray& arr = NodesDb::Get()->GetNodesInfo(); + NodeHandler *hnd; + for (size_t i = 0; i < arr.GetCount(); i++) { - PropertyInfo pi; - pi.Name = tkn.GetNextToken(); - tkn.GetNextToken(); - wxString typ = tkn.GetNextToken(); - if (tkn.HasMoreTokens()) pi.MoreInfo = tkn.GetNextToken(); - if (typ == "color") pi.Type = PROP_COLOR; - else if (typ == "flags") pi.Type = PROP_FLAGS; - else if (typ == "bool") pi.Type = PROP_BOOL; - else if (typ == "integer") pi.Type = PROP_INTEGER; - else if (typ == "coord") pi.Type = PROP_COORD; - else /*if (typ == "text")*/ pi.Type = PROP_TEXT; - - bool fnd = FALSE; - for (size_t j = 0; j < Props.GetCount(); j++) - { - if (Props[j].Name == pi.Name) - { - if (Props[j].Type == pi.Type && pi.Type == PROP_FLAGS) - Props[j].MoreInfo << ',' << pi.MoreInfo; - else - Props[j] = pi; - fnd = TRUE; - } - } - - if (!fnd) Props.Add(pi); + 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); } + ms_Handlers.Append(new NodeHandlerUnknown); } - - if (!nd.IsEmpty()) Node = nd; - if (!cht.IsEmpty()) ChildType = cht; - if (tp != HANDLER_NONE) Type = tp; - if (icn != -1) Icon = icn; - Abstract = ab; -} - - -NodeHandler *NodeHandler::CreateFromFile(const wxString& filename, EditorFrame *frame) -{ - NodeHandler *hnd = NULL; - - if (s_AllNodes == NULL) s_AllNodes = new NodeInfoArray; - - NodeInfo *ni = new NodeInfo; - ni->Type = HANDLER_NONE; - ni->Icon = 0; - ni->Read(filename); - s_AllNodes->Add(*ni); // add a copy - - if (ni->Type == HANDLER_NONE || ni->Node.IsEmpty() || ni->Abstract) - return NULL; - - switch (ni->Type) + wxNode *n = ms_Handlers.GetFirst(); + while (n) { - case HANDLER_PANEL: - hnd = new NodeHandlerPanel(frame, ni); - break; - case HANDLER_SIZER: - hnd = new NodeHandlerSizer(frame, ni); - break; - case HANDLER_SIZERITEM: - hnd = new NodeHandlerSizerItem(frame, ni); - break; - default: - hnd = new NodeHandler(frame, ni); - break; + NodeHandler *h = (NodeHandler*) n->GetData(); + if (h->CanHandle(node)) + return h; + n = n->GetNext(); } - - return hnd; + return NULL; } - - -PropertyHandler* NodeHandler::s_PropHandlers[PROP_TYPES_CNT] = {NULL}; -int NodeHandler::s_RefCnt = 0; -NodeInfoArray* NodeHandler::s_AllNodes = NULL; - - -NodeHandler::NodeHandler(EditorFrame *frame, NodeInfo *ni) : +NodeHandler::NodeHandler(NodeInfo *ni) : m_NodeInfo(ni) { - if (s_RefCnt++ == 0) CreatePropHandlers(); } -void NodeHandler::CreatePropHandlers() +NodeHandler::~NodeHandler() { - s_PropHandlers[PROP_TEXT] = new TextPropertyHandler; - s_PropHandlers[PROP_FLAGS] = new FlagsPropertyHandler; - s_PropHandlers[PROP_COLOR] = new TextPropertyHandler; - s_PropHandlers[PROP_BOOL] = new BoolPropertyHandler; - s_PropHandlers[PROP_INTEGER] = new TextPropertyHandler; - s_PropHandlers[PROP_COORD] = new CoordPropertyHandler; } -NodeHandler::~NodeHandler() + +bool NodeHandler::CanHandle(wxXmlNode *node) { - if (--s_RefCnt == 0) - { - for (int i = 0; i < PROP_TYPES_CNT; i++) - delete s_PropHandlers[i]; - delete s_AllNodes; s_AllNodes = NULL; - } - delete m_NodeInfo; + return (m_NodeInfo->NodeClass == XmlGetClass(node)); } -bool NodeHandler::CanHandle(wxXmlNode *node) + +PropertyInfoArray& NodeHandler::GetPropsList(wxXmlNode *WXUNUSED(node)) { - return (m_NodeInfo->Node == node->GetName()); + return m_NodeInfo->Props; } -wxTreeItemId NodeHandler::CreateTreeNode(wxTreeCtrl *treectrl, +wxTreeItemId NodeHandler::CreateTreeNode(wxTreeCtrl *treectrl, wxTreeItemId parent, wxXmlNode *node) { int icon = GetTreeIcon(node); - wxTreeItemId item = + wxTreeItemId item = treectrl->AppendItem(parent, GetTreeString(node), icon, icon, new XmlTreeData(node)); if (parent == treectrl->GetRootItem()) @@ -226,55 +124,32 @@ wxTreeItemId NodeHandler::CreateTreeNode(wxTreeCtrl *treectrl, wxString NodeHandler::GetTreeString(wxXmlNode *node) { - wxString xmlid = node->GetPropVal("name", ""); + wxString xmlid = node->GetPropVal(_T("name"), wxEmptyString); if (xmlid.IsEmpty()) - return node->GetName(); + return XmlGetClass(node); else - return (node->GetName() + " '" + xmlid + "'"); + return XmlGetClass(node) + _T(" '") + xmlid + _T("'"); } -void NodeHandler::CreatePropsList(wxListCtrl *listctrl, wxXmlNode *node) -{ - int index; - - for (size_t i = 0; i < m_NodeInfo->Props.GetCount(); i++) - { - PropertyInfo *p = &(m_NodeInfo->Props[i]); - index = s_PropHandlers[p->Type]->CreateListItem(listctrl, node, p); - listctrl->SetItemData(index, (long)new PropsListInfo( - index, s_PropHandlers[p->Type], node, - p, listctrl)); - } -} - - - -wxPanel *NodeHandler::CreatePropEditPanel(wxWindow *parent, wxListCtrl *listctrl, int index) -{ - PropsListInfo *pli = (PropsListInfo*)listctrl->GetItemData(index); - - return pli->m_Handler->CreateEditPanel(parent, pli); -} - - wxArrayString& NodeHandler::GetChildTypes() { if (m_ChildTypes.IsEmpty()) { wxString basetype = m_NodeInfo->ChildType; - - for (size_t i = 0; i < s_AllNodes->GetCount(); i++) + NodeInfoArray& arr = NodesDb::Get()->GetNodesInfo(); + + for (size_t i = 0; i < arr.GetCount(); i++) { - NodeInfo &ni = (*s_AllNodes)[i]; - - if (ni.Node == basetype && !ni.Abstract) - m_ChildTypes.Add(ni.Node); - + NodeInfo &ni = arr[i]; + + if (ni.NodeClass == basetype && !ni.Abstract) + m_ChildTypes.Add(ni.NodeClass); + if (ni.DerivedFrom.Index(basetype) != wxNOT_FOUND && !ni.Abstract) - m_ChildTypes.Add(ni.Node); + m_ChildTypes.Add(ni.NodeClass); } m_ChildTypes.Sort(); } @@ -284,7 +159,7 @@ wxArrayString& NodeHandler::GetChildTypes() -void NodeHandler::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before) +void NodeHandler::InsertNode(wxXmlNode *WXUNUSED(parent), wxXmlNode *node, wxXmlNode *WXUNUSED(insert_before)) { delete node; wxLogError(_("Cannot insert child into this type of node!")); @@ -297,23 +172,22 @@ void NodeHandler::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *inse -wxTreeItemId NodeHandlerPanel::CreateTreeNode(wxTreeCtrl *treectrl, +wxTreeItemId NodeHandlerPanel::CreateTreeNode(wxTreeCtrl *treectrl, wxTreeItemId parent, wxXmlNode *node) { wxTreeItemId root = NodeHandler::CreateTreeNode(treectrl, parent, node); - - wxXmlNode *n = XmlFindNode(node, "children"); - if (n) n = n->GetChildren(); - + wxXmlNode *n = XmlFindNode(node, _T("object")); + while (n) { - if (n->GetType() == wxXML_ELEMENT_NODE) - EditorFrame::Get()->CreateTreeNode(treectrl, root, n); + if (n->GetType() == wxXML_ELEMENT_NODE && + n->GetName() == _T("object")) + Find(n)->CreateTreeNode(treectrl, root, n); n = n->GetNext(); } - treectrl->Expand(root); + //treectrl->Expand(root); return root; } @@ -321,16 +195,10 @@ wxTreeItemId NodeHandlerPanel::CreateTreeNode(wxTreeCtrl *treectrl, void NodeHandlerPanel::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before) { - wxXmlNode *cnd = XmlFindNode(parent, "children"); - if (cnd == NULL) - { - cnd = new wxXmlNode(wxXML_ELEMENT_NODE, "children"); - parent->AddChild(cnd); - } if (insert_before) - cnd->InsertChild(node, insert_before); + parent->InsertChild(node, insert_before); else - cnd->AddChild(node); + parent->AddChild(node); EditorFrame::Get()->NotifyChanged(CHANGED_TREE); } @@ -340,31 +208,23 @@ void NodeHandlerPanel::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode void NodeHandlerSizer::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before) { - wxXmlNode *cnd = XmlFindNode(parent, "children"); - if (cnd == NULL) - { - cnd = new wxXmlNode(wxXML_ELEMENT_NODE, "children"); - parent->AddChild(cnd); - } - - if (node->GetName() == "spacer") + if (XmlGetClass(node) == _T("spacer") || XmlGetClass(node) == _T("sizeritem")) { if (insert_before) - cnd->InsertChild(node, insert_before); + parent->InsertChild(node, insert_before); else - cnd->AddChild(node); + parent->AddChild(node); } else { - wxXmlNode *itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, "sizeritem"); - wxXmlNode *winnode = new wxXmlNode(wxXML_ELEMENT_NODE, "window"); - itemnode->AddChild(winnode); - winnode->AddChild(node); + wxXmlNode *itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, _T("object")); + itemnode->AddProperty(_T("class"), _T("sizeritem")); + itemnode->AddChild(node); if (insert_before) - cnd->InsertChild(itemnode, insert_before); + parent->InsertChild(itemnode, insert_before); else - cnd->AddChild(itemnode); + parent->AddChild(itemnode); } EditorFrame::Get()->NotifyChanged(CHANGED_TREE); } @@ -373,34 +233,44 @@ void NodeHandlerSizer::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode int NodeHandlerSizer::GetTreeIcon(wxXmlNode *node) { - if (XmlReadValue(node, "orient") == "wxVERTICAL") return 2; - else return 3; + int orig = NodeHandler::GetTreeIcon(node); + if (orig == 0) + { + if (XmlReadValue(node, _T("orient")) == _T("wxVERTICAL")) return 2; + else return 3; + } + else return orig; } -wxTreeItemId NodeHandlerSizerItem::CreateTreeNode(wxTreeCtrl *treectrl, +wxTreeItemId NodeHandlerSizerItem::CreateTreeNode(wxTreeCtrl *treectrl, wxTreeItemId parent, wxXmlNode *node) { wxTreeItemId root; - root = EditorFrame::Get()->CreateTreeNode(treectrl, parent, GetRealNode(node)); + root = Find(GetRealNode(node))->CreateTreeNode(treectrl, parent, GetRealNode(node)); ((XmlTreeData*)treectrl->GetItemData(root))->Node = node; - treectrl->Expand(root); + //treectrl->Expand(root); return root; } -void NodeHandlerSizerItem::CreatePropsList(wxListCtrl *listctrl, wxXmlNode *node) +PropertyInfoArray& NodeHandlerSizerItem::GetPropsList(wxXmlNode *node) { - NodeHandler::CreatePropsList(listctrl, node); - int item = listctrl->GetItemCount(); - listctrl->InsertItem(item, "------"); - listctrl->SetItemImage(item, 0, 0); - EditorFrame::Get()->CreatePropsList(listctrl, GetRealNode(node)); + 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; } @@ -408,7 +278,7 @@ void NodeHandlerSizerItem::CreatePropsList(wxListCtrl *listctrl, wxXmlNode *node wxString NodeHandlerSizerItem::GetTreeString(wxXmlNode *node) { wxXmlNode *n = GetRealNode(node); - return EditorFrame::Get()->FindHandler(n)->GetTreeString(n); + return Find(n)->GetTreeString(n); } @@ -416,22 +286,39 @@ wxString NodeHandlerSizerItem::GetTreeString(wxXmlNode *node) int NodeHandlerSizerItem::GetTreeIcon(wxXmlNode *node) { wxXmlNode *n = GetRealNode(node); - return EditorFrame::Get()->FindHandler(n)->GetTreeIcon(n); + return Find(n)->GetTreeIcon(n); } wxXmlNode *NodeHandlerSizerItem::GetRealNode(wxXmlNode *node) { - wxXmlNode *n = XmlFindNode(node, "window"); - - if (n) n = n->GetChildren(); - - while (n) + return XmlFindNode(node, _T("object")); +} + + + + + + +void NodeHandlerNotebook::InsertNode(wxXmlNode *parent, wxXmlNode *node, wxXmlNode *insert_before) +{ { - if (n->GetType() == wxXML_ELEMENT_NODE) - return n; - n = n->GetNext(); + wxXmlNode *itemnode; + + if (XmlGetClass(node) == _T("notebookpage")) + itemnode = node; + else + { + itemnode = new wxXmlNode(wxXML_ELEMENT_NODE, _T("object")); + itemnode->AddProperty(_T("class"), _T("notebookpage")); + itemnode->AddChild(node); + } + + if (insert_before) + parent->InsertChild(itemnode, insert_before); + else + parent->AddChild(itemnode); } - return NULL; + EditorFrame::Get()->NotifyChanged(CHANGED_TREE); }