| 1 |
#include "frame_wrapper.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "choice_property.h" |
| 4 |
#include "file_ficker_property.h" |
| 5 |
#include "menu_bar_wrapper.h" |
| 6 |
#include "status_bar_wrapper.h" |
| 7 |
#include "toolbar_base_wrapper.h" |
| 8 |
#include "wxc_bitmap_code_generator.h" |
| 9 |
#include "wxc_widget.h" |
| 10 |
#include "wxgui_helpers.h" |
| 11 |
#include "xmlutils.h" |
| 12 |
#include <wx/docview.h> |
| 13 |
#include <wx/ffile.h> |
| 14 |
#include <wx/filename.h> |
| 15 |
#include <wx/frame.h> |
| 16 |
#include <wx/msgdlg.h> |
| 17 |
#include <wx/tokenzr.h> |
| 18 |
#include <wx/toplevel.h> |
| 19 |
|
| 20 |
FrameWrapper::FrameWrapper() |
| 21 |
: TopLevelWinWrapper(ID_WXFRAME) |
| 22 |
{ |
| 23 |
PREPEND_STYLE(wxFRAME_FLOAT_ON_PARENT, false); |
| 24 |
PREPEND_STYLE(wxFRAME_NO_TASKBAR, false); |
| 25 |
PREPEND_STYLE(wxFRAME_TOOL_WINDOW, false); |
| 26 |
PREPEND_STYLE(wxDEFAULT_FRAME_STYLE, true); |
| 27 |
|
| 28 |
SetPropertyString(_("Common Settings"), "wxFrame"); |
| 29 |
DoSetPropertyStringValue(PROP_TITLE, _("My Frame")); |
| 30 |
|
| 31 |
RegisterEvent(wxT("wxEVT_CLOSE_WINDOW"), wxT("wxCloseEvent"), |
| 32 |
_("Process a close event. This event applies to wxFrame and wxDialog classes")); |
| 33 |
RegisterEvent(wxT("wxEVT_ACTIVATE"), wxT("wxActivateEvent"), _("Process a wxEVT_ACTIVATE event")); |
| 34 |
RegisterEvent(wxT("wxEVT_ACTIVATE_APP"), wxT("wxActivateEvent"), _("Process a wxEVT_ACTIVATE_APP event")); |
| 35 |
|
| 36 |
AddCategory(_("Frame Type")); |
| 37 |
wxArrayString frameTypes; |
| 38 |
frameTypes.Add("wxFrame"); |
| 39 |
frameTypes.Add("wxDocMDIParentFrame"); |
| 40 |
frameTypes.Add("wxDocMDIChildFrame"); |
| 41 |
frameTypes.Add("wxDocParentFrame"); |
| 42 |
frameTypes.Add("wxDocChildFrame"); |
| 43 |
frameTypes.Add("wxMiniFrame"); |
| 44 |
AddProperty(new ChoiceProperty(PROP_FRAME_TYPE, frameTypes, 0, _("Select the wxFrame type you want"))); |
| 45 |
|
| 46 |
AddCategory(_("Frame Icons")); |
| 47 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_16, wxT(""), _("Select a 16x16 bitmap"))); |
| 48 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_32, wxT(""), _("Select a 32x32 bitmap"))); |
| 49 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_64, wxT(""), _("Select a 64x64 bitmap"))); |
| 50 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_128, wxT(""), _("Select a 128x128 bitmap"))); |
| 51 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_256, wxT(""), _("Select a 256x256 bitmap"))); |
| 52 |
|
| 53 |
m_namePattern = wxT("MyFrame"); |
| 54 |
SetName(GenerateName()); |
| 55 |
} |
| 56 |
|
| 57 |
FrameWrapper::~FrameWrapper() {} |
| 58 |
|
| 59 |
void FrameWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 60 |
{ |
| 61 |
if(type != XRC_LIVE) { |
| 62 |
text << wxT("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") |
| 63 |
<< wxT("<resource xmlns=\"http://www.wxwidgets.org/wxxrc\" >"); |
| 64 |
} |
| 65 |
|
| 66 |
wxString centred; |
| 67 |
if(!PropertyString(PROP_CENTRE_ON_SCREEN).empty()) { |
| 68 |
centred = wxT("<centered>1</centered>"); // In XRC centring is on/off; it doesn't discriminate between |
| 69 |
// wxBOTH/wxVERTICAL/wxHORIZONTAL |
| 70 |
} |
| 71 |
|
| 72 |
wxString xrcPrefix = "wxFrame"; |
| 73 |
if(PropertyString(PROP_FRAME_TYPE) == "wxMiniFrame") { |
| 74 |
xrcPrefix = "wxMiniFrame"; |
| 75 |
} |
| 76 |
|
| 77 |
text << XRCPrefix("wxFrame") << wxT("<title>") << wxCrafter::CDATA(PropertyString(PROP_TITLE)) << wxT("</title>") |
| 78 |
<< centred |
| 79 |
<< XRCStyle(type != wxcWidget::XRC_LIVE) // The parameter is to add the wxSTAY_ON_TOP, but not if we're 'live' |
| 80 |
<< XRCSize() << XRCCommonAttributes(); |
| 81 |
|
| 82 |
ChildrenXRC(text, type); |
| 83 |
text << wxT("</object>"); |
| 84 |
|
| 85 |
if(type != wxcWidget::XRC_LIVE) { text << wxT("</resource>"); } |
| 86 |
} |
| 87 |
|
| 88 |
wxString FrameWrapper::DesignerXRC(bool forPreviewDialog) const |
| 89 |
{ |
| 90 |
wxUnusedVar(forPreviewDialog); |
| 91 |
wxString text; |
| 92 |
text << wxT("<object class=\"wxPanel\" name=\"PreviewPanel\">") << "<caption-title>" |
| 93 |
<< wxCrafter::CDATA(PropertyString(PROP_TITLE)) << "</caption-title>" |
| 94 |
<< "<tlw-style>" << StyleFlags() << "</tlw-style>" |
| 95 |
<< "<tlw-icon>" << wxCrafter::CDATA(PropertyString(PROP_BITMAP_PATH_16)) << "</tlw-icon>" |
| 96 |
<< wxT("<hidden>1</hidden>") << XRCSize() << XRCCommonAttributes(); |
| 97 |
|
| 98 |
ChildrenXRC(text, XRC_DESIGNER); |
| 99 |
text << wxT("</object>"); |
| 100 |
|
| 101 |
// frame can have a wxMenuBar / wxToolBar / wxStatusBar as a direct child, search for them |
| 102 |
bool bMenuBar = false; |
| 103 |
bool bToolBar = false; |
| 104 |
bool bStatusBar = false; |
| 105 |
|
| 106 |
wxcWidget::List_t::const_iterator iter = m_children.begin(); |
| 107 |
for(; iter != m_children.end(); ++iter) { |
| 108 |
if(!bMenuBar && (*iter)->GetType() == ID_WXMENUBAR) { |
| 109 |
wxString menuBarXRC; |
| 110 |
MenuBarWrapper* mb = dynamic_cast<MenuBarWrapper*>(*iter); |
| 111 |
if(mb) { |
| 112 |
menuBarXRC = mb->DesignerXRC(); |
| 113 |
text.Prepend(menuBarXRC); |
| 114 |
bMenuBar = true; |
| 115 |
} |
| 116 |
|
| 117 |
} else if(!bToolBar && (*iter)->GetType() == ID_WXTOOLBAR) { |
| 118 |
|
| 119 |
wxString toolbarXRC; |
| 120 |
ToolbarWrapper* tb = dynamic_cast<ToolbarWrapper*>(*iter); |
| 121 |
if(tb) { |
| 122 |
toolbarXRC = tb->DesignerXRC(); |
| 123 |
text.Prepend(toolbarXRC); |
| 124 |
bToolBar = true; |
| 125 |
} |
| 126 |
|
| 127 |
} else if(!bStatusBar && (*iter)->GetType() == ID_WXSTATUSBAR) { |
| 128 |
|
| 129 |
wxString statusBarXRC; |
| 130 |
StatusBarWrapper* sb = dynamic_cast<StatusBarWrapper*>(*iter); |
| 131 |
if(sb) { |
| 132 |
statusBarXRC = sb->DesignerXRC(); |
| 133 |
text.Prepend(statusBarXRC); |
| 134 |
bStatusBar = true; |
| 135 |
} |
| 136 |
|
| 137 |
} else if(bToolBar && bMenuBar && bStatusBar) { |
| 138 |
break; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
WrapXRC(text); |
| 143 |
return text; |
| 144 |
} |
| 145 |
|
| 146 |
wxString FrameWrapper::CppCtorCode() const |
| 147 |
{ |
| 148 |
// Add the dialog icons to the generator helper |
| 149 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_16)); |
| 150 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_32)); |
| 151 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_64)); |
| 152 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_128)); |
| 153 |
wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_256)); |
| 154 |
return TopLevelWinWrapper::CppCtorCode(); |
| 155 |
} |
| 156 |
|
| 157 |
void FrameWrapper::GetIncludeFile(wxArrayString& headers) const |
| 158 |
{ |
| 159 |
headers.Add(wxT("#include <wx/frame.h>")); |
| 160 |
headers.Add(wxT("#include <wx/iconbndl.h>")); |
| 161 |
headers.Add(wxT("#include <wx/artprov.h>")); |
| 162 |
headers.Add(wxT("#include <wx/sizer.h>")); // needed for (GetSizer()->...) |
| 163 |
|
| 164 |
if(PropertyString(PROP_FRAME_TYPE) == "wxMiniFrame") { |
| 165 |
headers.Add("#include <wx/minifram.h>"); |
| 166 |
} else if(PropertyString(PROP_FRAME_TYPE) != "wxFrame") { |
| 167 |
headers.Add("#include <wx/docview.h>"); |
| 168 |
headers.Add("#include <wx/docmdi.h>"); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
wxString FrameWrapper::BaseCtorImplPrefix() const |
| 173 |
{ |
| 174 |
wxString code; |
| 175 |
wxString frameType = PropertyString(PROP_FRAME_TYPE); |
| 176 |
if(frameType == "wxDocMDIParentFrame") { |
| 177 |
code << CreateBaseclassName() << wxT("::") << CreateBaseclassName() |
| 178 |
<< "(wxDocManager *manager, wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, " |
| 179 |
"const wxSize& size, long style)\n"; |
| 180 |
code << " : " << GetRealClassName() << "(manager, parent, id, title, pos, size, style)\n"; |
| 181 |
|
| 182 |
} else if(frameType == "wxDocMDIChildFrame") { |
| 183 |
code << CreateBaseclassName() << wxT("::") << CreateBaseclassName() |
| 184 |
<< "(wxDocument *doc, wxView *view, wxMDIParentFrame *parent, wxWindowID id, const wxString& title, const " |
| 185 |
"wxPoint& pos, const wxSize& size, long style)\n"; |
| 186 |
code << " : " << GetRealClassName() << "(doc, view, parent, id, title, pos, size, style)\n"; |
| 187 |
|
| 188 |
} else if(frameType == "wxDocChildFrame") { |
| 189 |
code << CreateBaseclassName() << wxT("::") << CreateBaseclassName() |
| 190 |
<< "(wxDocument *doc, wxView *view, wxFrame *parent, wxWindowID id, const wxString& title, const wxPoint& " |
| 191 |
"pos, const wxSize& size, long style)\n"; |
| 192 |
code << " : " << GetRealClassName() << "(doc, view, parent, id, title, pos, size, style)\n"; |
| 193 |
|
| 194 |
} else if(frameType == "wxDocParentFrame") { |
| 195 |
code << CreateBaseclassName() << wxT("::") << CreateBaseclassName() |
| 196 |
<< "(wxDocManager *manager, wxFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, " |
| 197 |
"const wxSize& size, long style)\n"; |
| 198 |
code << " : " << GetRealClassName() << "(manager, parent, id, title, pos, size, style)\n"; |
| 199 |
|
| 200 |
} else { // wxFrame or wxMiniFrame |
| 201 |
code << CreateBaseclassName() << wxT("::") << CreateBaseclassName() |
| 202 |
<< wxT("(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, " |
| 203 |
"long style)\n"); |
| 204 |
code << " : " << GetRealClassName() << "(parent, id, title, pos, size, style)\n"; |
| 205 |
} |
| 206 |
return code; |
| 207 |
} |
| 208 |
|
| 209 |
wxString FrameWrapper::BaseCtorDecl() const |
| 210 |
{ |
| 211 |
wxString code; |
| 212 |
wxString frameType = PropertyString(PROP_FRAME_TYPE); |
| 213 |
wxString title = wxCrafter::UNDERSCORE(PropertyString(PROP_TITLE)); |
| 214 |
|
| 215 |
if(frameType == "wxDocMDIParentFrame") { |
| 216 |
// wxDocMDIParentFrame |
| 217 |
code << wxT(" ") << CreateBaseclassName() |
| 218 |
<< wxT("(wxDocManager *manager, wxFrame* parent, wxWindowID id = wxID_ANY, const wxString& title = ") |
| 219 |
<< title << wxT(", ") << wxT("const wxPoint& pos = wxDefaultPosition, const wxSize& size = ") |
| 220 |
<< SizeAsString() << wxT(", ") << wxT("long style = ") << StyleFlags(wxT("0")) << wxT(");\n"); |
| 221 |
|
| 222 |
} else if(frameType == "wxDocMDIChildFrame") { |
| 223 |
code << wxT(" ") << CreateBaseclassName() |
| 224 |
<< wxT("(wxDocument *doc, wxView *view, wxMDIParentFrame *parent, " |
| 225 |
"wxWindowID id = wxID_ANY, const wxString& title = ") |
| 226 |
<< title << wxT(", ") << wxT("const wxPoint& pos = wxDefaultPosition, const wxSize& size = ") |
| 227 |
<< SizeAsString() << wxT(", ") << wxT("long style = ") << StyleFlags(wxT("0")) << wxT(");\n"); |
| 228 |
|
| 229 |
} else if(frameType == "wxDocChildFrame") { |
| 230 |
code << wxT(" ") << CreateBaseclassName() |
| 231 |
<< wxT("(wxDocument *doc, wxView *view, wxFrame *parent, " |
| 232 |
"wxWindowID id = wxID_ANY, const wxString& title = ") |
| 233 |
<< title << wxT(", ") << wxT("const wxPoint& pos = wxDefaultPosition, const wxSize& size = ") |
| 234 |
<< SizeAsString() << wxT(", ") << wxT("long style = ") << StyleFlags(wxT("0")) << wxT(");\n"); |
| 235 |
|
| 236 |
} else if(frameType == "wxDocParentFrame") { |
| 237 |
code << wxT(" ") << CreateBaseclassName() |
| 238 |
<< wxT("(wxDocManager *manager, wxFrame *parent, wxWindowID id = wxID_ANY, const wxString& title = ") |
| 239 |
<< title << wxT(", ") << wxT("const wxPoint& pos = wxDefaultPosition, const wxSize& size = ") |
| 240 |
<< SizeAsString() << wxT(", ") << wxT("long style = ") << StyleFlags(wxT("0")) << wxT(");\n"); |
| 241 |
|
| 242 |
} else { |
| 243 |
// wxFrame |
| 244 |
code << wxT(" ") << CreateBaseclassName() |
| 245 |
<< wxT("(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = ") << title << wxT(", ") |
| 246 |
<< wxT("const wxPoint& pos = wxDefaultPosition, const wxSize& size = ") << SizeAsString() << wxT(", ") |
| 247 |
<< wxT("long style = ") << StyleFlags(wxT("0")) << wxT(");\n"); |
| 248 |
} |
| 249 |
return code; |
| 250 |
} |
| 251 |
|
| 252 |
void FrameWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 253 |
{ |
| 254 |
// First call the base-class for the standard things |
| 255 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 256 |
|
| 257 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("centered")); |
| 258 |
if(propertynode) { SetPropertyString(PROP_CENTRE_ON_SCREEN, propertynode->GetNodeContent()); } |
| 259 |
|
| 260 |
// We've already done 'size' in the baseclass, but do it again for TLWindows |
| 261 |
// That's because if no size was specified, wxC inflicts 500,300. This isn't what the user expected |
| 262 |
// So, if there is *not* a specified size, overwrite the wxC default with wxDefaultSize |
| 263 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("size")); |
| 264 |
if(!propertynode) { SetPropertyString(PROP_SIZE, "-1,-1"); } |
| 265 |
} |
| 266 |
|
| 267 |
void FrameWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 268 |
{ |
| 269 |
// First call the base-class for the standard things |
| 270 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 271 |
|
| 272 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("centered")); |
| 273 |
if(propertynode) { SetPropertyString(PROP_CENTRE_ON_SCREEN, propertynode->GetNodeContent()); } |
| 274 |
|
| 275 |
// We've already done 'size' in the baseclass, but do it again for TLWindows |
| 276 |
// That's because if no size was specified, wxC inflicts 500,300. This isn't what the user expected |
| 277 |
// So, if there is *not* a specified size, overwrite the wxC default with wxDefaultSize |
| 278 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("size")); |
| 279 |
if(!propertynode) { SetPropertyString(PROP_SIZE, "-1,-1"); } |
| 280 |
} |
| 281 |
|
| 282 |
void FrameWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 283 |
{ |
| 284 |
// First call the base-class for the standard things |
| 285 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 286 |
|
| 287 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "center"); |
| 288 |
if(propertynode) { SetPropertyString(PROP_CENTRE_ON_SCREEN, propertynode->GetNodeContent()); } |
| 289 |
// See the comment in LoadPropertiesFromXRC() |
| 290 |
propertynode = XmlUtils::FindNodeByName(node, "property", wxT("size")); |
| 291 |
if(!propertynode) { SetPropertyString(PROP_SIZE, "-1,-1"); } |
| 292 |
} |
| 293 |
|
| 294 |
bool FrameWrapper::HasIcon() const { return true; } |
| 295 |
|
| 296 |
wxString FrameWrapper::GetWxClassName() const { return PropertyString(PROP_FRAME_TYPE); } |
| 297 |
|
| 298 |
wxString FrameWrapper::GetDerivedClassCtorSignature() const |
| 299 |
{ |
| 300 |
wxString code; |
| 301 |
wxString frameType = PropertyString(PROP_FRAME_TYPE); |
| 302 |
if(frameType == "wxDocMDIParentFrame") { |
| 303 |
code << "(wxDocManager *manager, wxFrame* parent)"; |
| 304 |
|
| 305 |
} else if(frameType == "wxDocMDIChildFrame") { |
| 306 |
code << "(wxDocument *doc, wxView *view, wxMDIParentFrame *parent)"; |
| 307 |
|
| 308 |
} else if(frameType == "wxDocChildFrame") { |
| 309 |
code << "(wxDocument *doc, wxView *view, wxFrame *parent)"; |
| 310 |
|
| 311 |
} else if(frameType == "wxDocParentFrame") { |
| 312 |
code << "(wxDocManager *manager, wxFrame *parent)"; |
| 313 |
|
| 314 |
} else { |
| 315 |
// default |
| 316 |
code << TopLevelWinWrapper::GetDerivedClassCtorSignature(); |
| 317 |
} |
| 318 |
return code; |
| 319 |
} |
| 320 |
|
| 321 |
wxString FrameWrapper::GetParentCtorInitArgumentList() const |
| 322 |
{ |
| 323 |
wxString code; |
| 324 |
wxString frameType = PropertyString(PROP_FRAME_TYPE); |
| 325 |
if(frameType == "wxDocMDIParentFrame") { |
| 326 |
code << "(manager, parent)"; |
| 327 |
|
| 328 |
} else if(frameType == "wxDocMDIChildFrame") { |
| 329 |
code << "(doc, view, parent)"; |
| 330 |
|
| 331 |
} else if(frameType == "wxDocChildFrame") { |
| 332 |
code << "(doc, view, parent)"; |
| 333 |
|
| 334 |
} else if(frameType == "wxDocParentFrame") { |
| 335 |
code << "(manager, parent)"; |
| 336 |
|
| 337 |
} else { |
| 338 |
// default |
| 339 |
code << TopLevelWinWrapper::GetParentCtorInitArgumentList(); |
| 340 |
} |
| 341 |
return code; |
| 342 |
} |