| 1 |
#include "preview_frame.h" |
| 2 |
#include "DirectoryChanger.h" |
| 3 |
#include "wxc_aui_manager.h" |
| 4 |
#include "wxgui_helpers.h" |
| 5 |
#include "wxguicraft_main_view.h" |
| 6 |
#include <wx/app.h> |
| 7 |
#include <wx/sizer.h> |
| 8 |
#include <wx/sstream.h> |
| 9 |
#include <wx/xml/xml.h> |
| 10 |
|
| 11 |
BEGIN_EVENT_TABLE(PreviewFrame, wxFrame) |
| 12 |
END_EVENT_TABLE() |
| 13 |
|
| 14 |
PreviewFrame::PreviewFrame(wxWindow* parent, const TopLevelWinWrapper& fw) |
| 15 |
{ |
| 16 |
wxSize sz = wxCrafter::DecodeSize(fw.SizeAsString()); |
| 17 |
wxString text; |
| 18 |
|
| 19 |
fw.ToXRC(text, wxcWidget::XRC_PREVIEW); |
| 20 |
wxXmlDocument doc; |
| 21 |
|
| 22 |
wxStringInputStream str(text); |
| 23 |
doc.Load(str); |
| 24 |
|
| 25 |
wxString xrcFilePath = wxFileName(wxCrafter::GetUserDataDir(), wxT("myframe.xrc")).GetFullPath(); |
| 26 |
doc.Save(xrcFilePath); |
| 27 |
DirectoryChanger dc(wxcProjectMetadata::Get().GetProjectPath()); |
| 28 |
|
| 29 |
wxXmlResource::Get()->Load(xrcFilePath); |
| 30 |
wxXmlResource::Get()->LoadFrame(this, parent, fw.GetName()); |
| 31 |
wxXmlResource::Get()->Unload(xrcFilePath); |
| 32 |
|
| 33 |
Center(); |
| 34 |
SetSizeHints(sz); |
| 35 |
|
| 36 |
if(wxcAuiManager::Get().Find(this)) { |
| 37 |
wxcAuiManager::Get().Find(this)->Update(); |
| 38 |
} else { |
| 39 |
Layout(); |
| 40 |
} |
| 41 |
|
| 42 |
EventNotifier::Get()->Connect(wxEVT_CLOSE_PREVIEW, wxCommandEventHandler(PreviewFrame::OnClosePreview), NULL, this); |
| 43 |
} |
| 44 |
|
| 45 |
PreviewFrame::~PreviewFrame() |
| 46 |
{ |
| 47 |
wxcAuiManager::Get().UnInit(this); |
| 48 |
EventNotifier::Get()->Disconnect(wxEVT_CLOSE_PREVIEW, wxCommandEventHandler(PreviewFrame::OnClosePreview), NULL, |
| 49 |
this); |
| 50 |
wxCommandEvent event(wxEVT_PREVIEW_CLOSED); |
| 51 |
EventNotifier::Get()->AddPendingEvent(event); |
| 52 |
} |
| 53 |
|
| 54 |
void PreviewFrame::OnClosePreview(wxCommandEvent& e) |
| 55 |
{ |
| 56 |
e.Skip(); |
| 57 |
Close(); |
| 58 |
} |