diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 8924bcc391..88c71fef49 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -481,6 +481,7 @@ public: // e.g. . bool IsOfClass(wxXmlNode *node, const wxString& classname) const; + bool IsObjectNode(const wxXmlNode *node) const; // Gets node content from wxXML_ENTITY_NODE // The problem is, content is represented as // wxXML_ENTITY_NODE name="tag", content="" @@ -488,6 +489,10 @@ public: // wxXML_CDATA_SECTION_NODE name="" content="content" wxString GetNodeContent(const wxXmlNode *node); + wxXmlNode *GetNodeParent(const wxXmlNode *node) const; + wxXmlNode *GetNodeNext(const wxXmlNode *node) const; + wxXmlNode *GetNodeChildren(const wxXmlNode *node) const; + // Check to see if a parameter exists. bool HasParam(const wxString& param); diff --git a/include/wx/xrc/xmlreshandler.h b/include/wx/xrc/xmlreshandler.h index 7aa12b7bc6..c5ee3cc2e6 100644 --- a/include/wx/xrc/xmlreshandler.h +++ b/include/wx/xrc/xmlreshandler.h @@ -52,7 +52,11 @@ public: virtual wxObject *CreateResource(wxXmlNode *node, wxObject *parent, wxObject *instance) = 0; virtual bool IsOfClass(wxXmlNode *node, const wxString& classname) const = 0; + virtual bool IsObjectNode(const wxXmlNode *node) const = 0; virtual wxString GetNodeContent(const wxXmlNode *node) = 0; + virtual wxXmlNode *GetNodeParent(const wxXmlNode *node) const = 0; + virtual wxXmlNode *GetNodeNext(const wxXmlNode *node) const = 0; + virtual wxXmlNode *GetNodeChildren(const wxXmlNode *node) const = 0; virtual bool HasParam(const wxString& param) = 0; virtual wxXmlNode *GetParamNode(const wxString& param) = 0; virtual wxString GetParamValue(const wxString& param) = 0; @@ -206,10 +210,29 @@ protected: { return GetImpl()->IsOfClass(node, classname); } + + bool IsObjectNode(const wxXmlNode *node) const + { + return GetImpl()->IsObjectNode(node); + } wxString GetNodeContent(const wxXmlNode *node) { return GetImpl()->GetNodeContent(node); } + + wxXmlNode *GetNodeParent(const wxXmlNode *node) const + { + return GetImpl()->GetNodeParent(node); + } + wxXmlNode *GetNodeNext(const wxXmlNode *node) const + { + return GetImpl()->GetNodeNext(node); + } + wxXmlNode *GetNodeChildren(const wxXmlNode *node) const + { + return GetImpl()->GetNodeChildren(node); + } + bool HasParam(const wxString& param) { return GetImpl()->HasParam(param); diff --git a/interface/wx/xrc/xmlres.h b/interface/wx/xrc/xmlres.h index 72583a6e86..42217ed965 100644 --- a/interface/wx/xrc/xmlres.h +++ b/interface/wx/xrc/xmlres.h @@ -651,11 +651,50 @@ protected: */ wxString GetName(); + /** + Checks if the given node is an object node. + + Object nodes are those named "object" or "object_ref". + + @since 3.1.0 + */ + bool IsObjectNode(const wxXmlNode *node) const; /** Gets node content from wxXML_ENTITY_NODE. */ wxString GetNodeContent(wxXmlNode* node); + /** + Gets the parent of the node given. + + This method is safe to call with @NULL argument, it just returns @NULL + in this case. + + @since 3.1.0 + */ + wxXmlNode *GetNodeParent(const wxXmlNode *node) const; + + /** + Gets the next sibling node related to the given node, possibly @NULL. + + This method is safe to call with @NULL argument, it just returns @NULL + in this case. + + @since 3.1.0 + */ + wxXmlNode *GetNodeNext(const wxXmlNode *node) const; + + /** + Gets the first child of the given node or @NULL. + + This method is safe to call with @NULL argument, it just returns @NULL + in this case. + + @since 3.1.0 + */ + wxXmlNode *GetNodeChildren(const wxXmlNode *node) const; + + /** Finds the node or returns @NULL. */ diff --git a/src/xrc/xh_auitoolb.cpp b/src/xrc/xh_auitoolb.cpp index 1b16eee8f3..2043594835 100644 --- a/src/xrc/xh_auitoolb.cpp +++ b/src/xrc/xh_auitoolb.cpp @@ -84,7 +84,7 @@ wxObject *wxAuiToolBarXmlHandler::DoCreateResource() // also check for the menu specified inside dropdown (it is // optional and may be absent for e.g. dynamically-created // menus) - wxXmlNode * const nodeMenu = nodeDropdown->GetChildren(); + wxXmlNode * const nodeMenu = GetNodeChildren(nodeDropdown); if ( nodeMenu ) { wxObject *res = CreateResFromNode(nodeMenu, NULL); @@ -98,11 +98,11 @@ wxObject *wxAuiToolBarXmlHandler::DoCreateResource() ); } - if ( nodeMenu->GetNext() ) + if ( GetNodeNext(nodeMenu) ) { ReportError ( - nodeMenu->GetNext(), + GetNodeNext(nodeMenu), "unexpected extra contents under drop-down tool" ); } @@ -195,8 +195,7 @@ wxObject *wxAuiToolBarXmlHandler::DoCreateResource() while (n) { - if ((n->GetType() == wxXML_ELEMENT_NODE) && - (n->GetName() == wxS("object") || n->GetName() == wxS("object_ref"))) + if (IsObjectNode(n)) { wxObject *created = CreateResFromNode(n, toolbar, NULL); wxControl *control = wxDynamicCast(created, wxControl); @@ -206,7 +205,7 @@ wxObject *wxAuiToolBarXmlHandler::DoCreateResource() control != NULL) toolbar->AddControl(control); } - n = n->GetNext(); + n = GetNodeNext(n); } m_isInside = false; diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 49967c1024..473db8717d 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -2007,6 +2007,13 @@ bool wxXmlResourceHandlerImpl::IsOfClass(wxXmlNode *node, const wxString& classn } +bool wxXmlResourceHandlerImpl::IsObjectNode(const wxXmlNode *node) const +{ + return node && + node->GetType() == wxXML_ELEMENT_NODE && + (node->GetName() == wxS("object") || + node->GetName() == wxS("object_ref")); +} wxString wxXmlResourceHandlerImpl::GetNodeContent(const wxXmlNode *node) { @@ -2024,6 +2031,21 @@ wxString wxXmlResourceHandlerImpl::GetNodeContent(const wxXmlNode *node) return wxEmptyString; } +wxXmlNode *wxXmlResourceHandlerImpl::GetNodeParent(const wxXmlNode *node) const +{ + return node ? node->GetParent() : NULL; +} + +wxXmlNode *wxXmlResourceHandlerImpl::GetNodeNext(const wxXmlNode *node) const +{ + return node ? node->GetNext() : NULL; +} + +wxXmlNode *wxXmlResourceHandlerImpl::GetNodeChildren(const wxXmlNode *node) const +{ + return node ? node->GetChildren() : NULL; +} + wxString wxXmlResourceHandlerImpl::GetParamValue(const wxString& param)