]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/utils/wxrcedit/editor.cpp
added test for wxProgressDialog::Resume
[wxWidgets.git] / contrib / utils / wxrcedit / editor.cpp
index 383462d1c8fcd7a4cc0bf0e78b0475b8a42b9b90..affbc9e01bcd7b614db6c55851fa3d9ca8f88e45 100644 (file)
@@ -19,8 +19,8 @@
 #endif
 
 #include "wx/wx.h"
-#include "wx/xml/xml.h"
-#include "wx/xml/xmlres.h"
+#include "wx/xrc/xml.h"
+#include "wx/xrc/xmlres.h"
 #include "wx/splitter.h"
 #include "wx/config.h"
 #include "wx/dir.h"
 #include "propframe.h"
 
 
+void wxXmlRcEditDocument::UpgradeNodeValue(wxXmlNode *node)
+{
+    wxXmlNode *n = node;
+    if (n == NULL) return;
+    n = n->GetChildren();
+
+    while (n)
+    {
+        if (n->GetType() == wxXML_TEXT_NODE ||
+            n->GetType() == wxXML_CDATA_SECTION_NODE)
+        {
+            wxString str1 = n->GetContent();
+            const wxChar *dt;
+
+            for (dt = str1.c_str(); *dt; dt++)
+            {
+                // Remap amp_char to &, map double amp_char to amp_char (for things
+                // like "&File..." -- this is illegal in XML, so we use "_File..."):
+                if (*dt == '$')
+                {
+                    if ( *(++dt) != '$' )
+                        str1[size_t(dt-str1.c_str()-1)] = '_';
+                }
+            }
+            n->SetContent(str1);
+        }
+        n = n->GetNext();
+    }
+}
+
+void wxXmlRcEditDocument::UpgradeNode(wxXmlNode *node)
+{
+    if (node)
+    {
+        UpgradeNodeValue(node);
+        UpgradeNode(node->GetNext());
+        UpgradeNode(node->GetChildren());
+    }
+}
+
+void wxXmlRcEditDocument::Upgrade()
+{
+    int v1,v2,v3,v4;
+    long version;
+    wxXmlNode *node = GetRoot();
+    wxString verstr = wxT("0.0.0.0");
+    node->GetPropVal(wxT("version"),verstr);
+    if (wxSscanf(verstr.c_str(), wxT("%i.%i.%i.%i"),
+        &v1, &v2, &v3, &v4) == 4)
+        version = v1*256*256*256+v2*256*256+v3*256+v4;
+    else
+        version = 0;
+    if (!version)
+    {
+        UpgradeNode(node);
+    }
+    node->DeleteProperty(wxT("version"));
+    node->AddProperty(wxT("version"), wxT(WX_XMLRES_CURRENT_VERSION_STRING));
+}
+
 
 class EditorTreeCtrl : public wxTreeCtrl
 {
@@ -85,7 +145,7 @@ enum
     ID_NEWMENU,
     ID_NEWMENUBAR,
     ID_NEWTOOLBAR,   
-    ID_NEWNODE = wxID_HIGHEST + 10000, // safely out of XMLID range :)
+    ID_NEWNODE = wxID_HIGHEST + 10000, // safely out of XRCID range :)
     ID_NEWSYBNODE = ID_NEWNODE + 20000
 };
 
@@ -230,11 +290,14 @@ void EditorFrame::LoadFile(const wxString& filename)
 
     delete m_Resource;
     
+     // create new resource in order to handle version differences properly
+    PreviewFrame::Get()->ResetResource();
+    
     m_FileName = "";
-    m_Resource = new wxXmlDocument;
+    m_Resource = new wxXmlRcEditDocument;
     m_Modified = FALSE;
     
-    if (!m_Resource->Load(filename))
+    if (!m_Resource->Load(filename,  wxLocale::GetSystemEncodingName()))
     {
         delete m_Resource;
         m_Resource = NULL;
@@ -244,6 +307,9 @@ void EditorFrame::LoadFile(const wxString& filename)
     else
     {
         m_FileName = filename;
+
+        // Upgrades old versions
+        m_Resource->Upgrade();
         RefreshTree();
     }
     RefreshTitle();
@@ -254,7 +320,8 @@ void EditorFrame::LoadFile(const wxString& filename)
 void EditorFrame::SaveFile(const wxString& filename)
 {
     m_FileName = filename;
-
+    
+    // save it:
     if (!m_Resource->Save(filename))
         wxLogError(_("Error saving ") + filename);
     else
@@ -272,7 +339,7 @@ void EditorFrame::NewFile()
     delete m_Resource;
     
     m_FileName = "";
-    m_Resource = new wxXmlDocument;
+    m_Resource = new wxXmlRcEditDocument;
     m_Resource->SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE, _("resource")));
     
     m_Modified = FALSE;
@@ -287,7 +354,7 @@ void EditorFrame::RefreshTitle()
     wxString s;
     if (m_Modified) s << _T("* ");
     s << _("wxrcedit");
-    if (!m_FileName)
+    if (m_FileName != "")
         s << _T(" - ") << wxFileNameFromPath(m_FileName);
     SetTitle(s);
 }
@@ -427,7 +494,8 @@ void EditorFrame::OnTreeSel(wxTreeEvent& event)
         }
         RecursivelyExpand(m_TreeCtrl, event.GetItem());
 
-        PreviewFrame::Get()->Preview(node);
+        PreviewFrame::Get()->Preview(node,m_Resource->GetRoot()->GetPropVal(
+                                      wxT("version"), wxT("0.0.0.0")));
     }
 }
 
@@ -441,7 +509,8 @@ void EditorFrame::OnToolbar(wxCommandEvent& event)
             {
             XmlTreeData* dt = (XmlTreeData*)m_TreeCtrl->GetItemData(m_TreeCtrl->GetSelection());;
             if (dt != NULL && dt->Node != NULL)
-                PreviewFrame::Get()->Preview(dt->Node);
+                PreviewFrame::Get()->Preview(dt->Node,m_Resource->GetRoot()->GetPropVal(
+                                      wxT("version"), wxT("0.0.0.0")));
             break;
             }