| 1 |
#include "wizard_wrapper.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "file_ficker_property.h" |
| 4 |
#include "import_from_wxFB.h" |
| 5 |
#include "import_from_xrc.h" |
| 6 |
#include "wxc_bitmap_code_generator.h" |
| 7 |
#include "wxgui_defs.h" |
| 8 |
#include "wxgui_helpers.h" |
| 9 |
#include "xmlutils.h" |
| 10 |
#include <wx/wizard.h> |
| 11 |
|
| 12 |
WizardWrapper::WizardWrapper() |
| 13 |
: TopLevelWinWrapper(ID_WXWIZARD) |
| 14 |
{ |
| 15 |
SetPropertyString(_("Common Settings"), "wxWizard"); |
| 16 |
DoSetPropertyStringValue(PROP_TITLE, _("My Wizard")); |
| 17 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH, wxT(""), |
| 18 |
_("The default bitmap used in the left side of the wizard."))); |
| 19 |
|
| 20 |
PREPEND_STYLE(wxDEFAULT_DIALOG_STYLE, true); |
| 21 |
EnableStyle(wxT("wxCLOSE_BOX"), false); |
| 22 |
EnableStyle(wxT("wxSYSTEM_MENU"), false); |
| 23 |
EnableStyle(wxT("wxMINIMIZE_BOX"), false); |
| 24 |
EnableStyle(wxT("wxMAXIMIZE_BOX"), false); |
| 25 |
EnableStyle(wxT("wxRESIZE_BORDER"), false); |
| 26 |
EnableStyle(wxT("wxCAPTION"), false); |
| 27 |
|
| 28 |
// Wizard related events |
| 29 |
RegisterEvent(wxT("wxEVT_WIZARD_PAGE_CHANGED"), wxT("wxWizardEvent"), |
| 30 |
_("The page has just been changed (this event cannot be vetoed)")); |
| 31 |
RegisterEvent(wxT("wxEVT_WIZARD_PAGE_CHANGING"), wxT("wxWizardEvent"), |
| 32 |
_("The page is being changed (this event can be vetoed).")); |
| 33 |
RegisterEvent(wxT("wxEVT_WIZARD_PAGE_SHOWN"), wxT("wxWizardEvent"), _("The page was shown and laid out.")); |
| 34 |
RegisterEvent(wxT("wxEVT_WIZARD_CANCEL"), wxT("wxWizardEvent"), |
| 35 |
_("The user attempted to cancel the wizard (this event may also be vetoed).")); |
| 36 |
RegisterEvent(wxT("wxEVT_WIZARD_HELP"), wxT("wxWizardEvent"), _("The wizard help button was pressed.")); |
| 37 |
RegisterEvent(wxT("wxEVT_WIZARD_FINISHED"), wxT("wxWizardEvent"), _("The wizard finished button was pressed.")); |
| 38 |
|
| 39 |
// Dialog related events |
| 40 |
RegisterEvent(wxT("wxEVT_INIT_DIALOG"), wxT("wxInitDialogEvent"), |
| 41 |
_("A wxInitDialogEvent is sent as a dialog or panel is being initialised. Handlers for this event " |
| 42 |
"can transfer data to the window.\nThe default handler calls wxWindow::TransferDataToWindow")); |
| 43 |
RegisterEvent(wxT("wxEVT_CLOSE_WINDOW"), wxT("wxCloseEvent"), |
| 44 |
_("Process a close event. This event applies to wxFrame and wxDialog classes")); |
| 45 |
RegisterEvent(wxT("wxEVT_ACTIVATE"), wxT("wxActivateEvent"), _("Process a wxEVT_ACTIVATE event")); |
| 46 |
RegisterEvent(wxT("wxEVT_ACTIVATE_APP"), wxT("wxActivateEvent"), _("Process a wxEVT_ACTIVATE_APP event")); |
| 47 |
|
| 48 |
AddCategory(_("Wizard Icons")); |
| 49 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_16, wxT(""), _("Select a 16x16 bitmap"))); |
| 50 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_32, wxT(""), _("Select a 32x32 bitmap"))); |
| 51 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_64, wxT(""), _("Select a 64x64 bitmap"))); |
| 52 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_128, wxT(""), _("Select a 128x128 bitmap"))); |
| 53 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_256, wxT(""), _("Select a 256x256 bitmap"))); |
| 54 |
|
| 55 |
m_namePattern = wxT("MyWizard"); |
| 56 |
SetName(GenerateName()); |
| 57 |
} |
| 58 |
|
| 59 |
WizardWrapper::~WizardWrapper() {} |
| 60 |
|
| 61 |
wxString WizardWrapper::BaseCtorDecl() const |
| 62 |
{ |
| 63 |
wxString code; |
| 64 |
wxcCodeGeneratorHelper::Get().AddBitmap(PropertyFile(PROP_BITMAP_PATH)); |
| 65 |
code << wxT(" ") << CreateBaseclassName() |
| 66 |
<< wxT("(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = ") |
| 67 |
<< wxCrafter::UNDERSCORE(PropertyString(PROP_TITLE)) << wxT(", ") |
| 68 |
<< wxT("const wxBitmap& bmp = wxNullBitmap, ") << wxT("const wxPoint& pos = wxDefaultPosition, ") |
| 69 |
<< wxT("long style = ") << StyleFlags(wxT("wxDEFAULT_DIALOG_STYLE")) << wxT(");\n") << wxT(" ") |
| 70 |
<< wxT("wxWizardPageSimple* GetFirstPage() const { if(!m_pages.empty()) return m_pages.at(0); return NULL; " |
| 71 |
"}\n"); |
| 72 |
return code; |
| 73 |
} |
| 74 |
|
| 75 |
wxString WizardWrapper::BaseCtorImplPrefix() const |
| 76 |
{ |
| 77 |
wxString code; |
| 78 |
code << CreateBaseclassName() << wxT("::") << CreateBaseclassName() |
| 79 |
<< wxT("(wxWindow* parent, wxWindowID id, const wxString& title, const wxBitmap& bmp, const wxPoint& pos, " |
| 80 |
"long style)\n"); |
| 81 |
return code; |
| 82 |
} |
| 83 |
|
| 84 |
wxString WizardWrapper::DesignerXRC(bool forPreviewDialog) const |
| 85 |
{ |
| 86 |
wxUnusedVar(forPreviewDialog); |
| 87 |
wxString text; |
| 88 |
text << wxT("<object class=\"wxPanel\" name=\"PreviewPanel\">") << XRCSize(); |
| 89 |
|
| 90 |
ChildrenXRC(text, XRC_DESIGNER); |
| 91 |
text << wxT("</object>"); |
| 92 |
|
| 93 |
WrapXRC(text); |
| 94 |
return text; |
| 95 |
} |
| 96 |
|
| 97 |
void WizardWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 98 |
{ |
| 99 |
if(type != wxcWidget::XRC_LIVE) { |
| 100 |
text << wxT("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") |
| 101 |
<< wxT("<resource xmlns=\"http://www.wxwidgets.org/wxxrc\" >"); |
| 102 |
} |
| 103 |
|
| 104 |
wxString centred; |
| 105 |
if(!PropertyString(PROP_CENTRE_ON_SCREEN).empty()) { |
| 106 |
centred = wxT("<centered>1</centered>"); // In XRC centring is on/off; it doesn't discriminate between |
| 107 |
// wxBOTH/wxVERTICAL/wxHORIZONTAL |
| 108 |
} |
| 109 |
|
| 110 |
text << XRCPrefix() << wxT("<title>") << wxCrafter::CDATA(PropertyString(PROP_TITLE)) << wxT("</title>") << centred |
| 111 |
<< XRCBitmap() |
| 112 |
<< XRCStyle(type != wxcWidget::XRC_LIVE) // The parameter is to add the wxSTAY_ON_TOP, but not if we're 'live' |
| 113 |
<< XRCCommonAttributes(); |
| 114 |
|
| 115 |
ChildrenXRC(text, type); |
| 116 |
text << wxT("</object>"); |
| 117 |
|
| 118 |
if(type != wxcWidget::XRC_LIVE) { text << wxT("</resource>"); } |
| 119 |
} |
| 120 |
|
| 121 |
void WizardWrapper::GetIncludeFile(wxArrayString& headers) const |
| 122 |
{ |
| 123 |
headers.Add(wxT("#include <wx/wizard.h>")); |
| 124 |
headers.Add(wxT("#include <vector>")); |
| 125 |
headers.Add(wxT("#include <wx/artprov.h>")); |
| 126 |
} |
| 127 |
|
| 128 |
wxString WizardWrapper::CppCtorCode() const |
| 129 |
{ |
| 130 |
wxString code; |
| 131 |
|
| 132 |
// Add the dialog icons to the generator helper |
| 133 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_16)); |
| 134 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_32)); |
| 135 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_64)); |
| 136 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_128)); |
| 137 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_256)); |
| 138 |
|
| 139 |
code << wxT("Create(parent, id, title, ") |
| 140 |
<< wxcCodeGeneratorHelper::Get().BitmapCode(PropertyFile(PROP_BITMAP_PATH)) << wxT(", pos, style);\n"); |
| 141 |
return code; |
| 142 |
} |
| 143 |
|
| 144 |
wxString WizardWrapper::DoGenerateClassMember() const |
| 145 |
{ |
| 146 |
wxString memberCode; |
| 147 |
memberCode << wxT(" std::vector<wxWizardPageSimple*> m_pages;\n"); |
| 148 |
return memberCode; |
| 149 |
} |
| 150 |
|
| 151 |
void WizardWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 152 |
{ |
| 153 |
// First call the base-class for the standard things |
| 154 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 155 |
|
| 156 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("centered")); |
| 157 |
if(propertynode) { SetPropertyString(PROP_CENTRE_ON_SCREEN, propertynode->GetNodeContent()); } |
| 158 |
|
| 159 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("bitmap")); |
| 160 |
if(propertynode) { ImportFromXrc::ProcessBitmapProperty(propertynode, this, PROP_BITMAP_PATH, "wxART_OTHER"); } |
| 161 |
|
| 162 |
// We've already done 'size' in the baseclass, but do it again for TLWindows |
| 163 |
// That's because if no size was specified, wxC inflicts 500,300. This isn't what the user expected |
| 164 |
// So, if there is *not* a specified size, overwrite the wxC default with wxDefaultSize |
| 165 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("size")); |
| 166 |
if(!propertynode) { SetPropertyString(PROP_SIZE, "-1,-1"); } |
| 167 |
} |
| 168 |
|
| 169 |
void WizardWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 170 |
{ |
| 171 |
// First call the base-class for the standard things |
| 172 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 173 |
|
| 174 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "bitmap"); |
| 175 |
if(propertynode) { |
| 176 |
ImportFromwxFB::ProcessBitmapProperty(propertynode->GetNodeContent(), this, PROP_BITMAP_PATH, "wxART_OTHER"); |
| 177 |
} |
| 178 |
|
| 179 |
propertynode = XmlUtils::FindNodeByName(node, "property", "center"); |
| 180 |
if(propertynode) { SetPropertyString(PROP_CENTRE_ON_SCREEN, propertynode->GetNodeContent()); } |
| 181 |
// See the comment in LoadPropertiesFromXRC() |
| 182 |
propertynode = XmlUtils::FindNodeByName(node, "property", wxT("size")); |
| 183 |
if(!propertynode) { SetPropertyString(PROP_SIZE, "-1,-1"); } |
| 184 |
} |
| 185 |
|
| 186 |
bool WizardWrapper::HasIcon() const { return true; } |