| 1 |
#include "preview_wizard.h" |
| 2 |
#include "DirectoryChanger.h" |
| 3 |
#include "wxgui_helpers.h" |
| 4 |
#include "wxguicraft_main_view.h" |
| 5 |
#include <wx/app.h> |
| 6 |
#include <wx/sstream.h> |
| 7 |
#include <wx/xml/xml.h> |
| 8 |
|
| 9 |
BEGIN_EVENT_TABLE(PreviewWizard, wxWizard) |
| 10 |
EVT_CLOSE(PreviewWizard::OnClose) |
| 11 |
EVT_WIZARD_CANCEL(wxID_ANY, PreviewWizard::OnWizard) |
| 12 |
EVT_WIZARD_FINISHED(wxID_ANY, PreviewWizard::OnWizard) |
| 13 |
END_EVENT_TABLE() |
| 14 |
|
| 15 |
PreviewWizard::PreviewWizard(wxWindow* parent, const WizardWrapper& dw) |
| 16 |
{ |
| 17 |
wxString text; |
| 18 |
dw.ToXRC(text, wxcWidget::XRC_PREVIEW); |
| 19 |
wxXmlDocument doc; |
| 20 |
|
| 21 |
wxStringInputStream str(text); |
| 22 |
doc.Load(str); |
| 23 |
|
| 24 |
wxString xrcFilePath = wxFileName(wxCrafter::GetUserDataDir(), wxT("mywizard.xrc")).GetFullPath(); |
| 25 |
doc.Save(xrcFilePath); |
| 26 |
|
| 27 |
DirectoryChanger dc(wxcProjectMetadata::Get().GetProjectPath()); |
| 28 |
|
| 29 |
wxXmlResource::Get()->Load(xrcFilePath); |
| 30 |
wxXmlResource::Get()->LoadObject(this, parent, dw.GetName(), wxT("wxWizard")); |
| 31 |
wxXmlResource::Get()->Unload(xrcFilePath); |
| 32 |
|
| 33 |
Center(); |
| 34 |
EventNotifier::Get()->Connect(wxEVT_CLOSE_PREVIEW, wxCommandEventHandler(PreviewWizard::OnClosePreview), NULL, |
| 35 |
this); |
| 36 |
} |
| 37 |
|
| 38 |
PreviewWizard::~PreviewWizard() |
| 39 |
{ |
| 40 |
EventNotifier::Get()->Disconnect(wxEVT_CLOSE_PREVIEW, wxCommandEventHandler(PreviewWizard::OnClosePreview), NULL, |
| 41 |
this); |
| 42 |
|
| 43 |
wxCommandEvent event(wxEVT_PREVIEW_CLOSED); |
| 44 |
EventNotifier::Get()->AddPendingEvent(event); |
| 45 |
} |
| 46 |
|
| 47 |
void PreviewWizard::OnClosePreview(wxCommandEvent& e) |
| 48 |
{ |
| 49 |
e.Skip(); |
| 50 |
// Destroy(); |
| 51 |
} |
| 52 |
|
| 53 |
void PreviewWizard::OnClose(wxCloseEvent& e) |
| 54 |
{ |
| 55 |
e.Skip(); |
| 56 |
// Destroy(); |
| 57 |
} |
| 58 |
|
| 59 |
void PreviewWizard::Run() |
| 60 |
{ |
| 61 |
wxWizardPageSimple* pageOne = XRCCTRL((*this), "WIZARD_PAGE_ONE", wxWizardPageSimple); |
| 62 |
if(pageOne) { |
| 63 |
GetPageAreaSizer()->Add(pageOne); |
| 64 |
RunWizard(pageOne); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
void PreviewWizard::OnWizard(wxWizardEvent& e) |
| 69 |
{ |
| 70 |
e.Skip(); |
| 71 |
// Destroy(); |
| 72 |
} |