+wxXmlNode *
+wxXmlResource::GetResourceNodeAndLocation(const wxString& name,
+ const wxString& classname,
+ bool recursive,
+ wxString *path) const
+{
+ // ensure everything is up-to-date: this is needed to support on-remand
+ // reloading of XRC files
+ const_cast<wxXmlResource *>(this)->UpdateResources();
+
+ for ( wxXmlResourceDataRecords::const_iterator f = Data().begin();
+ f != Data().end(); ++f )
+ {
+ wxXmlResourceDataRecord *const rec = *f;
+ wxXmlDocument * const doc = rec->Doc;
+ if ( !doc || !doc->GetRoot() )
+ continue;
+
+ wxXmlNode * const
+ found = DoFindResource(doc->GetRoot(), name, classname, recursive);
+ if ( found )
+ {
+ if ( path )
+ *path = rec->File;
+
+ return found;
+ }
+ }
+
+ return NULL;
+}
+
+static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
+{
+ // Merge attributes:
+ for ( wxXmlAttribute *attr = with.GetAttributes();
+ attr; attr = attr->GetNext() )
+ {
+ wxXmlAttribute *dattr;
+ for (dattr = dest.GetAttributes(); dattr; dattr = dattr->GetNext())
+ {
+
+ if ( dattr->GetName() == attr->GetName() )
+ {
+ dattr->SetValue(attr->GetValue());
+ break;
+ }
+ }
+
+ if ( !dattr )
+ dest.AddAttribute(attr->GetName(), attr->GetValue());
+ }
+
+ // Merge child nodes:
+ for (wxXmlNode* node = with.GetChildren(); node; node = node->GetNext())
+ {
+ wxString name = node->GetAttribute(wxT("name"), wxEmptyString);
+ wxXmlNode *dnode;
+
+ for (dnode = dest.GetChildren(); dnode; dnode = dnode->GetNext() )
+ {
+ if ( dnode->GetName() == node->GetName() &&
+ dnode->GetAttribute(wxT("name"), wxEmptyString) == name &&
+ dnode->GetType() == node->GetType() )
+ {
+ MergeNodes(*dnode, *node);
+ break;
+ }
+ }
+
+ if ( !dnode )
+ {
+ static const wxChar *AT_END = wxT("end");
+ wxString insert_pos = node->GetAttribute(wxT("insert_at"), AT_END);
+ if ( insert_pos == AT_END )
+ {
+ dest.AddChild(new wxXmlNode(*node));
+ }
+ else if ( insert_pos == wxT("begin") )
+ {
+ dest.InsertChild(new wxXmlNode(*node), dest.GetChildren());
+ }
+ }
+ }
+
+ if ( dest.GetType() == wxXML_TEXT_NODE && with.GetContent().length() )
+ dest.SetContent(with.GetContent());
+}
+
+wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent,
+ wxObject *instance,
+ wxXmlResourceHandler *handlerToUse)