]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/preview.cpp
82729ec3074190cfb2f00a672b37f74988fcd8ad
1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "preview.h"
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
21 #include "wx/xml/xml.h"
22 #include "wx/xml/xmlres.h"
23 #include "wx/config.h"
25 #include "wx/splitter.h"
30 #include "wx/xml/xh_menu.h"
32 class MyMenubarHandler
: public wxMenuBarXmlHandler
35 MyMenubarHandler(wxMenuBar
*mbar
) : m_MenuBar(mbar
) {}
37 wxObject
*DoCreateResource()
39 //wxMenuBar *menubar = new wxMenuBar(GetStyle());
40 CreateChildren(m_MenuBar
);
51 PreviewFrame
* PreviewFrame::ms_Instance
= NULL
;
53 PreviewFrame
*PreviewFrame::Get()
55 if (ms_Instance
== NULL
)
57 (void)new PreviewFrame
;
58 ms_Instance
->Show(TRUE
);
63 PreviewFrame::PreviewFrame()
64 : wxFrame(NULL
, -1, _("Preview"))
69 SetMenuBar(new wxMenuBar());
71 m_RC
= new wxXmlResource
;
72 // these handlers take precedence over std. ones:
73 m_RC
->AddHandler(new MyMenubarHandler(GetMenuBar()));
75 m_RC
->InitAllHandlers();
76 m_TmpFile
= wxGetTempFileName(_T("wxrcedit"));
77 m_RC
->Load(m_TmpFile
);
79 wxConfigBase
*cfg
= wxConfigBase::Get();
80 SetSize(wxRect(wxPoint(cfg
->Read(_T("previewframe_x"), -1), cfg
->Read(_T("previewframe_y"), -1)),
81 wxSize(cfg
->Read(_T("previewframe_w"), 400), cfg
->Read(_T("previewframe_h"), 400))));
83 m_Splitter
= new wxSplitterWindow(this, -1);
84 m_LogCtrl
= new wxTextCtrl(m_Splitter
, -1, wxEmptyString
, wxDefaultPosition
,
85 wxDefaultSize
, wxTE_MULTILINE
);
86 m_ScrollWin
= new wxScrolledWindow(m_Splitter
, -1);
87 m_ScrollWin
->SetBackgroundColour(_T("light steel blue"));
88 m_Splitter
->SplitHorizontally(m_ScrollWin
, m_LogCtrl
, cfg
->Read(_T("previewframe_sash"), 300));
95 PreviewFrame::~PreviewFrame()
97 wxConfigBase
*cfg
= wxConfigBase::Get();
98 cfg
->Write(_T("previewframe_x"), (long)GetPosition().x
);
99 cfg
->Write(_T("previewframe_y"), (long)GetPosition().y
);
100 cfg
->Write(_T("previewframe_w"), (long)GetSize().x
);
101 cfg
->Write(_T("previewframe_h"), (long)GetSize().y
);
102 cfg
->Write(_T("previewframe_sash"), (long)m_Splitter
->GetSashPosition());
107 wxRemoveFile(m_TmpFile
);
112 void PreviewFrame::Preview(wxXmlNode
*node
)
114 while (node
->GetParent()->GetParent() != NULL
) node
= node
->GetParent();
118 doc
.SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE
, _T("resource")));
119 doc
.GetRoot()->AddChild(new wxXmlNode(*node
));
121 if (XmlGetClass(doc
.GetRoot()->GetChildren()) == _T("wxDialog"))
122 XmlSetClass(doc
.GetRoot()->GetChildren(), _T("wxPanel"));
124 doc
.Save(m_TmpFile
, wxXML_IO_BIN
);
125 // wxXmlResource will detect change automatically
129 //if (m_Node != node)
132 for (int i
= (int)(GetMenuBar()->GetMenuCount())-1; i
>= 0; i
--)
133 delete GetMenuBar()->Remove(i
);
134 m_ScrollWin
->DestroyChildren();
140 wxLogTextCtrl
mylog(m_LogCtrl
);
141 wxLog
*oldlog
= wxLog::SetActiveTarget(&mylog
);
143 wxString oldcwd
= wxGetCwd();
144 wxSetWorkingDirectory(wxPathOnly(EditorFrame::Get()->GetFileName()));
146 if (XmlGetClass(node
) == _T("wxMenuBar") || XmlGetClass(node
) == _T("wxMenu"))
148 else if (XmlGetClass(node
) == _T("wxToolBar"))
150 else if (XmlGetClass(node
) == _T("wxPanel") || XmlGetClass(node
) == _T("wxDialog"))
153 wxSetWorkingDirectory(oldcwd
);
154 wxLog::SetActiveTarget(oldlog
);
159 void PreviewFrame::PreviewMenu()
163 if (XmlGetClass(m_Node
) == _T("wxMenuBar"))
164 mbar
= m_RC
->LoadMenuBar(m_Node
->GetPropVal(_T("name"), _T("-1")));
167 wxMenu
*m
= m_RC
->LoadMenu(m_Node
->GetPropVal(_T("name"), _T("-1")));
168 if (m
!= NULL
) GetMenuBar()->Append(m
, _("(menu)"));
172 wxLogError(_("Cannot preview the menu -- XML resource corrupted."));
177 void PreviewFrame::PreviewToolbar()
179 SetToolBar(m_RC
->LoadToolBar(this, m_Node
->GetPropVal(_T("name"), _T("-1"))));
184 void PreviewFrame::PreviewPanel()
186 wxPanel
*panel
= m_RC
->LoadPanel(m_ScrollWin
, m_Node
->GetPropVal(_T("name"), _T("-1")));
189 wxLogError(_("Cannot preview the panel -- XML resource corrupted."));
192 m_ScrollWin
->SetScrollbars(1, 1, panel
->GetSize().x
, panel
->GetSize().y
,