X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/75e01429429a48f75ccac96778bc48849bb01b49..3527f29c8769e09d796c547c0c309f8b86407012:/contrib/utils/wxrcedit/preview.cpp diff --git a/contrib/utils/wxrcedit/preview.cpp b/contrib/utils/wxrcedit/preview.cpp index 89dcaa30ae..29a11c77bd 100644 --- a/contrib/utils/wxrcedit/preview.cpp +++ b/contrib/utils/wxrcedit/preview.cpp @@ -19,7 +19,7 @@ #include "wx/wx.h" #include "wx/xml/xml.h" -#include "wx/xml/xmlres.h" +#include "wx/xrc/xmlres.h" #include "wx/config.h" #include "wx/log.h" #include "wx/splitter.h" @@ -27,7 +27,7 @@ #include "xmlhelpr.h" #include "editor.h" -#include "wx/xml/xh_menu.h" +#include "wx/xrc/xh_menu.h" class MyMenubarHandler : public wxMenuBarXmlHandler { @@ -75,13 +75,9 @@ PreviewFrame::PreviewFrame() SetMenuBar(new wxMenuBar()); - m_RC = new wxXmlResource; - // these handlers take precedence over std. ones: - m_RC->AddHandler(new MyMenubarHandler(GetMenuBar())); - // std handlers: - m_RC->InitAllHandlers(); + m_RC = NULL; m_TmpFile = wxGetTempFileName(_T("wxrcedit")); - m_RC->Load(m_TmpFile); + ResetResource(); wxConfigBase *cfg = wxConfigBase::Get(); SetSize(wxRect(wxPoint(cfg->Read(_T("previewframe_x"), -1), cfg->Read(_T("previewframe_y"), -1)), @@ -96,11 +92,25 @@ PreviewFrame::PreviewFrame() CreateStatusBar(); - SetSize(GetSize()); // refresh: MSW needs it +#ifdef __WXMSW__ + SendSizeEvent(); // force resize for WXMSW +#endif } +void PreviewFrame::ResetResource() +{ + delete m_RC; + m_RC = new wxXmlResource; + // these handlers take precedence over std. ones: + m_RC->AddHandler(new MyMenubarHandler(GetMenuBar())); + // std handlers: + m_RC->InitAllHandlers(); + wxRemoveFile(m_TmpFile); + m_RC->Load(m_TmpFile); +} + PreviewFrame::~PreviewFrame() { wxConfigBase *cfg = wxConfigBase::Get(); @@ -130,19 +140,27 @@ void PreviewFrame::MakeDirty() -void PreviewFrame::Preview(wxXmlNode *node) +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(); { wxXmlDocument doc; - doc.SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE, _T("resource"))); + wxXmlNode *root = new wxXmlNode(wxXML_ELEMENT_NODE, _T("resource")); + 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 } @@ -156,6 +174,7 @@ void PreviewFrame::Preview(wxXmlNode *node) } m_Node = node; + m_Doc = orig_doc; m_LogCtrl->Clear(); wxLogTextCtrl mylog(m_LogCtrl); @@ -170,7 +189,9 @@ void PreviewFrame::Preview(wxXmlNode *node) PreviewToolbar(); else if (XmlGetClass(node) == _T("wxPanel") || XmlGetClass(node) == _T("wxDialog")) PreviewPanel(); - + else if (XmlGetClass(node) == _T("wxFrame")) + PreviewWXFrame(); + wxSetWorkingDirectory(oldcwd); wxLog::SetActiveTarget(oldlog); @@ -181,7 +202,7 @@ void PreviewFrame::Preview(wxXmlNode *node) void PreviewFrame::PreviewMenu() { - wxMenuBar *mbar; + wxMenuBar *mbar = NULL; if (XmlGetClass(m_Node) == _T("wxMenuBar")) mbar = m_RC->LoadMenuBar(m_Node->GetPropVal(_T("name"), _T("-1"))); @@ -207,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 @@ -217,13 +238,43 @@ 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) END_EVENT_TABLE() -void PreviewFrame::OnMouseEnter(wxMouseEvent& event) +void PreviewFrame::OnMouseEnter(wxMouseEvent& WXUNUSED(event)) { - if (m_Dirty) Preview(m_Node); + if (m_Dirty) Preview(m_Node,m_Doc); }