]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/utils/wxrcedit/preview.cpp
change MSW libs directories so that libraries are shared by builds
[wxWidgets.git] / contrib / utils / wxrcedit / preview.cpp
index 9aeb6154019746d3c272703918f6b6e9bdf9cb9b..b939a4314eef5ba340589d3c3ece515ab508ba13 100644 (file)
@@ -140,8 +140,10 @@ void PreviewFrame::MakeDirty()
 
 
 
-void PreviewFrame::Preview(wxXmlNode *node,const wxString &version)
+void PreviewFrame::Preview(wxXmlNode *node, wxXmlDocument *orig_doc)
 {
+   wxString version = orig_doc->GetRoot()->GetPropVal(wxT("version"), wxT("0.0.0.0"));
+
    while (node->GetParent()->GetParent() != NULL) node = node->GetParent();
 
    {
@@ -150,11 +152,15 @@ void PreviewFrame::Preview(wxXmlNode *node,const wxString &version)
        root->AddProperty(new wxXmlProperty(wxT("version"),version,NULL));
        doc.SetRoot(root);
        doc.GetRoot()->AddChild(new wxXmlNode(*node));
+       doc.SetFileEncoding(orig_doc->GetFileEncoding());
 
        if (XmlGetClass(doc.GetRoot()->GetChildren()) == _T("wxDialog")) 
            XmlSetClass(doc.GetRoot()->GetChildren(), _T("wxPanel"));   
 
-       doc.Save(m_TmpFile, wxXML_IO_BIN);
+       if (XmlGetClass(doc.GetRoot()->GetChildren()) == _T("wxFrame")) 
+           XmlSetClass(doc.GetRoot()->GetChildren(), _T("wxPanel"));  
+
+       doc.Save(m_TmpFile);
        // wxXmlResource will detect change automatically
    }
 
@@ -168,7 +174,7 @@ void PreviewFrame::Preview(wxXmlNode *node,const wxString &version)
    }
 
    m_Node = node;
-   m_Version = version;
+   m_Doc = orig_doc;
 
    m_LogCtrl->Clear();
    wxLogTextCtrl mylog(m_LogCtrl);
@@ -183,7 +189,9 @@ void PreviewFrame::Preview(wxXmlNode *node,const wxString &version)
        PreviewToolbar();
    else if (XmlGetClass(node) == _T("wxPanel") || XmlGetClass(node) == _T("wxDialog"))
        PreviewPanel();
-   
+   else if (XmlGetClass(node) == _T("wxFrame"))
+          PreviewWXFrame();    
+
    wxSetWorkingDirectory(oldcwd);
    wxLog::SetActiveTarget(oldlog);
    
@@ -220,7 +228,7 @@ void PreviewFrame::PreviewToolbar()
 void PreviewFrame::PreviewPanel()
 {
     wxPanel *panel = m_RC->LoadPanel(m_ScrollWin, m_Node->GetPropVal(_T("name"), _T("-1")));
-    
+
     if (panel == NULL)
         wxLogError(_("Cannot preview the panel -- XML resource corrupted."));
     else
@@ -230,6 +238,37 @@ void PreviewFrame::PreviewPanel()
     }
 }
 
+void PreviewFrame::PreviewWXFrame()
+{
+       //for this to work the frame MUST have a child panel!
+
+       wxXmlNode*      child = m_Node;
+       wxString name;
+
+       while( child != NULL)
+       {
+               name = child->GetPropVal(_T("name"), _T("-1"));
+               
+               if(name != _T("-1"))
+               {
+                       wxXmlNode* parent = child->GetParent();
+                       if(parent->GetPropVal(_T("class"),_T("-1")) == _T("wxPanel"))
+                               break;
+               }
+               child = child->GetNext();
+       }
+
+    wxPanel *panel = m_RC->LoadPanel(m_ScrollWin, name);
+    
+    if (panel == NULL)
+        wxLogError(_("Cannot preview the panel -- XML resource corrupted."));
+    else
+    {
+        m_ScrollWin->SetScrollbars(1, 1, panel->GetSize().x, panel->GetSize().y,
+                                   0, 0, TRUE);
+    }
+
+}
 
 BEGIN_EVENT_TABLE(PreviewFrame, wxFrame)
     EVT_ENTER_WINDOW(PreviewFrame::OnMouseEnter)
@@ -237,5 +276,5 @@ END_EVENT_TABLE()
 
 void PreviewFrame::OnMouseEnter(wxMouseEvent& event)
 {
-    if (m_Dirty) Preview(m_Node,m_Version);
+    if (m_Dirty) Preview(m_Node,m_Doc);
 }