| 1 |
#include "popup_window_preview.h" |
| 2 |
#include "DirectoryChanger.h" |
| 3 |
#include "wxc_project_metadata.h" |
| 4 |
#include "wxgui_helpers.h" |
| 5 |
#include "wxguicraft_main_view.h" |
| 6 |
#include <event_notifier.h> |
| 7 |
#include <wx/sstream.h> |
| 8 |
#include <wx/xml/xml.h> |
| 9 |
#include <wx/xrc/xmlres.h> |
| 10 |
|
| 11 |
BEGIN_EVENT_TABLE(PopupWindowPreview, wxFrame) |
| 12 |
END_EVENT_TABLE() |
| 13 |
PopupWindowPreview::PopupWindowPreview(wxWindow* parent, const PopupWindowWrapper& wrapper) |
| 14 |
: wxFrame(parent, wxID_ANY, wxT("Preview"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxSTAY_ON_TOP) |
| 15 |
{ |
| 16 |
wxString text; |
| 17 |
wrapper.ToXRC(text, wxcWidget::XRC_PREVIEW); |
| 18 |
wxXmlDocument doc; |
| 19 |
|
| 20 |
wxStringInputStream str(text); |
| 21 |
doc.Load(str); |
| 22 |
|
| 23 |
wxString xrcFilePath = wxFileName(wxCrafter::GetUserDataDir(), wxT("mypanel.xrc")).GetFullPath(); |
| 24 |
|
| 25 |
doc.Save(xrcFilePath); |
| 26 |
wxBoxSizer* sz = new wxBoxSizer(wxVERTICAL); |
| 27 |
SetSizer(sz); |
| 28 |
|
| 29 |
DirectoryChanger dc(wxcProjectMetadata::Get().GetProjectPath()); |
| 30 |
|
| 31 |
wxXmlResource::Get()->Load(xrcFilePath); |
| 32 |
wxPanel* panel = wxXmlResource::Get()->LoadPanel(this, wrapper.GetName()); |
| 33 |
wxXmlResource::Get()->Unload(xrcFilePath); |
| 34 |
sz->Add(panel, 1, wxEXPAND); |
| 35 |
|
| 36 |
Center(); |
| 37 |
sz->Layout(); |
| 38 |
GetSizer()->Fit(this); |
| 39 |
EventNotifier::Get()->Connect(wxEVT_CLOSE_PREVIEW, |
| 40 |
wxCommandEventHandler(PopupWindowPreview::OnClosePreviewPreviewPanel), NULL, this); |
| 41 |
} |
| 42 |
|
| 43 |
PopupWindowPreview::~PopupWindowPreview() |
| 44 |
{ |
| 45 |
EventNotifier::Get()->Disconnect(wxEVT_CLOSE_PREVIEW, |
| 46 |
wxCommandEventHandler(PopupWindowPreview::OnClosePreviewPreviewPanel), NULL, this); |
| 47 |
wxCommandEvent event(wxEVT_PREVIEW_CLOSED); |
| 48 |
EventNotifier::Get()->AddPendingEvent(event); |
| 49 |
} |
| 50 |
|
| 51 |
void PopupWindowPreview::OnClosePreviewPreviewPanel(wxCommandEvent& e) |
| 52 |
{ |
| 53 |
e.Skip(); |
| 54 |
Close(); |
| 55 |
} |