]> git.saurik.com Git - wxWidgets.git/blobdiff - src/xrc/xml.cpp
Some doc tweaks
[wxWidgets.git] / src / xrc / xml.cpp
index d6ba14d820a58083a769f45acbdae91f3d6961fd..cf0f9630bf41894411a49df5f14e280a7e5c36ac 100644 (file)
@@ -71,10 +71,29 @@ wxXmlNode::wxXmlNode(const wxXmlNode& node)
 
 
 
+wxXmlNode::~wxXmlNode()
+{
+    wxXmlNode *c, *c2;
+    for (c = m_children; c; c = c2)
+    {
+        c2 = c->m_next;
+        delete c;
+    }
+
+    wxXmlProperty *p, *p2;
+    for (p = m_properties; p; p = p2)
+    {
+        p2 = p->GetNext();
+        delete p;
+    }
+}
+
+
+
 wxXmlNode& wxXmlNode::operator=(const wxXmlNode& node)
 {
-    delete m_properties;
-    delete m_children;
+    wxDELETE(m_properties);
+    wxDELETE(m_children);
     DoCopy(node);
     return *this;
 }
@@ -237,12 +256,14 @@ void wxXmlNode::AddProperty(wxXmlProperty *prop)
 
 bool wxXmlNode::DeleteProperty(const wxString& name)
 {
+    wxXmlProperty *prop;
+
     if (m_properties == NULL)
         return FALSE;
 
     else if (m_properties->GetName() == name)
     {
-        wxXmlProperty *prop = m_properties;
+        prop = m_properties;
         m_properties = prop->GetNext();
         prop->SetNext(NULL);
         delete prop;
@@ -256,7 +277,7 @@ bool wxXmlNode::DeleteProperty(const wxString& name)
         {
             if (p->GetNext()->GetName() == name)
             {
-                wxXmlProperty *prop = p->GetNext();
+                prop = p->GetNext();
                 p->SetNext(prop->GetNext());
                 prop->SetNext(NULL);
                 delete prop;
@@ -279,25 +300,25 @@ wxList *wxXmlDocument::sm_handlers = NULL;
 
 
 
-wxXmlDocument::wxXmlDocument(const wxString& filename, wxXmlIOType io_type)
+wxXmlDocument::wxXmlDocument(const wxString& filename, wxXmlIOType io_type,
+                             const wxString& encoding)
                           : wxObject(), m_root(NULL)
 {
-    if (!Load(filename, io_type))
+    if (!Load(filename, io_type, encoding))
     {
-        delete m_root;
-        m_root = NULL;
+        wxDELETE(m_root);
     }
 }
 
 
 
-wxXmlDocument::wxXmlDocument(wxInputStream& stream, wxXmlIOType io_type)
+wxXmlDocument::wxXmlDocument(wxInputStream& stream, wxXmlIOType io_type,
+                             const wxString& encoding)
                           : wxObject(), m_root(NULL)
 {
-    if (!Load(stream, io_type))
+    if (!Load(stream, io_type, encoding))
     {
-        delete m_root;
-        m_root = NULL;
+        wxDELETE(m_root);
     }
 }
 
@@ -312,7 +333,7 @@ wxXmlDocument::wxXmlDocument(const wxXmlDocument& doc)
 
 wxXmlDocument& wxXmlDocument::operator=(const wxXmlDocument& doc)
 {
-    delete m_root;
+    wxDELETE(m_root);
     DoCopy(doc);
     return *this;
 }
@@ -322,22 +343,33 @@ wxXmlDocument& wxXmlDocument::operator=(const wxXmlDocument& doc)
 void wxXmlDocument::DoCopy(const wxXmlDocument& doc)
 {
     m_version = doc.m_version;
+#if !wxUSE_UNICODE
     m_encoding = doc.m_encoding;
+#endif
+    m_fileEncoding = doc.m_fileEncoding;
     m_root = new wxXmlNode(*doc.m_root);
 }
 
 
 
-bool wxXmlDocument::Load(const wxString& filename, wxXmlIOType io_type)
+bool wxXmlDocument::Load(const wxString& filename, wxXmlIOType io_type,
+                         const wxString& encoding)
 {
     wxFileInputStream stream(filename);
-    return Load(stream, io_type);
+    return Load(stream, io_type, encoding);
 }
 
 
 
-bool wxXmlDocument::Load(wxInputStream& stream, wxXmlIOType io_type)
+bool wxXmlDocument::Load(wxInputStream& stream, wxXmlIOType io_type,
+                         const wxString& encoding)
 {
+#if wxUSE_UNICODE
+    (void)encoding;
+#else
+    m_encoding = encoding;
+#endif
+
     wxNode *n = sm_handlers->GetFirst();
     while (n)
     {
@@ -346,7 +378,7 @@ bool wxXmlDocument::Load(wxInputStream& stream, wxXmlIOType io_type)
         if ((io_type == wxXML_IO_AUTO || io_type == h->GetType()) &&
             h->CanLoad(stream))
         {
-            return h->Load(stream, *this);
+            return h->Load(stream, *this, encoding);
         }
         n = n->GetNext();
     }
@@ -398,8 +430,7 @@ void wxXmlDocument::AddHandler(wxXmlIOHandler *handler)
 
 void wxXmlDocument::CleanUpHandlers()
 {
-    delete sm_handlers;
-    sm_handlers = NULL;
+    wxDELETE(sm_handlers);
 }