From 921018cfc8bba29e75f3e9d78c55015eb4f92520 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 3 Feb 2024 19:47:27 +0100 Subject: [PATCH] Add wxXmlResourceHandler::GetNodeName() This allows to get the name of the node which is needed for XRC handlers using specific elements instead of using the object elements with specific name attribute. --- include/wx/xrc/xmlres.h | 4 ++++ include/wx/xrc/xmlreshandler.h | 7 +++++++ interface/wx/xrc/xmlres.h | 10 ++++++++++ src/xrc/xmlres.cpp | 5 +++++ 4 files changed, 26 insertions(+) diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index ecf0ca4c0b..2ededfc555 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -507,6 +507,10 @@ public: bool IsOfClass(wxXmlNode *node, const wxString& classname) const override; bool IsObjectNode(const wxXmlNode *node) const override; + + // Returns the name of the node, e.g. "object" or "sizeritem". + wxString GetNodeName(const wxXmlNode *node) const override; + // Gets node content from wxXML_ENTITY_NODE // The problem is, content is represented as // wxXML_ENTITY_NODE name="tag", content="" diff --git a/include/wx/xrc/xmlreshandler.h b/include/wx/xrc/xmlreshandler.h index 2b00ceefe4..d78f474c36 100644 --- a/include/wx/xrc/xmlreshandler.h +++ b/include/wx/xrc/xmlreshandler.h @@ -61,6 +61,7 @@ public: wxObject *instance) = 0; virtual bool IsOfClass(wxXmlNode *node, const wxString& classname) const = 0; virtual bool IsObjectNode(const wxXmlNode *node) const = 0; + virtual wxString GetNodeName(const wxXmlNode *node) const = 0; virtual wxString GetNodeContent(const wxXmlNode *node) const = 0; virtual wxXmlNode *GetNodeParent(const wxXmlNode *node) const = 0; virtual wxXmlNode *GetNodeNext(const wxXmlNode *node) const = 0; @@ -240,6 +241,12 @@ protected: { return GetImpl()->IsObjectNode(node); } + + wxString GetNodeName(const wxXmlNode *node) const + { + return GetImpl()->GetNodeName(node); + } + wxString GetNodeContent(const wxXmlNode *node) const { return GetImpl()->GetNodeContent(node); diff --git a/interface/wx/xrc/xmlres.h b/interface/wx/xrc/xmlres.h index ce1db0dede..b1a620f1aa 100644 --- a/interface/wx/xrc/xmlres.h +++ b/interface/wx/xrc/xmlres.h @@ -760,6 +760,16 @@ protected: @since 3.1.0 */ bool IsObjectNode(const wxXmlNode *node) const; + + /** + Returns the node name. + + Returns empty string if @a node is @NULL. + + @since 3.3.0 + */ + wxString GetNodeName(wxXmlNode* node) const; + /** Gets node content from wxXML_ENTITY_NODE. */ diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index e3746da976..e3d4311727 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -2260,6 +2260,11 @@ bool wxXmlResourceHandlerImpl::IsObjectNode(const wxXmlNode *node) const node->GetName() == wxS("object_ref")); } +wxString wxXmlResourceHandlerImpl::GetNodeName(const wxXmlNode *node) const +{ + return node ? node->GetName() : wxString{}; +} + wxString wxXmlResourceHandlerImpl::GetNodeContent(const wxXmlNode *node) const { return node ? node->GetNodeContent() : wxString{};