Debian Codegraph @

wxcrafter/top_level_windows/dialog_wrapper.cpp

raw
1 #include "dialog_wrapper.h"
2 #include "allocator_mgr.h"
3 #include "file_ficker_property.h"
4 #include "wxc_bitmap_code_generator.h"
5 #include "wxgui_helpers.h"
6 #include "xmlutils.h"
7 #include <wx/dialog.h>
8
9 DialogWrapper::DialogWrapper()
10 : TopLevelWinWrapper(ID_WXDIALOG)
11 {
12 DoClearFlags(m_styles);
13 PREPEND_STYLE(wxDIALOG_NO_PARENT, false);
14 PREPEND_STYLE(wxDIALOG_EX_CONTEXTHELP, false);
15 PREPEND_STYLE(wxSTAY_ON_TOP, false);
16 PREPEND_STYLE(wxDEFAULT_DIALOG_STYLE, true);
17
18 RegisterEvent(wxT("wxEVT_INIT_DIALOG"), wxT("wxInitDialogEvent"),
19 _("A wxInitDialogEvent is sent as a dialog or panel is being initialised. Handlers for this event "
20 "can transfer data to the window.\nThe default handler calls wxWindow::TransferDataToWindow"));
21 RegisterEvent(wxT("wxEVT_CLOSE_WINDOW"), wxT("wxCloseEvent"),
22 _("Process a close event. This event applies to wxFrame and wxDialog classes"));
23 RegisterEvent(wxT("wxEVT_ACTIVATE"), wxT("wxActivateEvent"), _("Process a wxEVT_ACTIVATE event"));
24 RegisterEvent(wxT("wxEVT_ACTIVATE_APP"), wxT("wxActivateEvent"), _("Process a wxEVT_ACTIVATE_APP event"));
25
26 SetPropertyString(_("Common Settings"), "wxDialog");
27 DoSetPropertyStringValue(PROP_TITLE, _("My Dialog"));
28 m_namePattern = wxT("MyDialog");
29
30 AddCategory(_("Dialog Icons"));
31 AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_16, wxT(""), _("Select a 16x16 bitmap")));
32 AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_32, wxT(""), _("Select a 32x32 bitmap")));
33 AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_64, wxT(""), _("Select a 64x64 bitmap")));
34 AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_128, wxT(""), _("Select a 128x128 bitmap")));
35 AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH_256, wxT(""), _("Select a 256x256 bitmap")));
36 SetName(GenerateName());
37 }
38
39 DialogWrapper::~DialogWrapper() {}
40
41 wxString DialogWrapper::DesignerXRC(bool forPreviewDialog) const
42 {
43 wxUnusedVar(forPreviewDialog);
44 wxString text;
45 text << wxT("<object class=\"wxPanel\" name=\"PreviewPanel\">") << "<caption-title>"
46 << wxCrafter::CDATA(PropertyString(PROP_TITLE)) << "</caption-title>"
47 << "<tlw-style>" << StyleFlags() << "</tlw-style>"
48 << "<tlw-icon>" << wxCrafter::CDATA(PropertyString(PROP_BITMAP_PATH_16)) << "</tlw-icon>"
49 << wxT("<hidden>1</hidden>") << XRCSize();
50
51 ChildrenXRC(text, XRC_DESIGNER);
52 text << wxT("</object>");
53
54 WrapXRC(text);
55 return text;
56 }
57
58 wxString DialogWrapper::BaseCtorDecl() const
59 {
60 wxString code;
61 wxString title = wxCrafter::UNDERSCORE(PropertyString(PROP_TITLE));
62 code << wxT(" ") << CreateBaseclassName()
63 << wxT("(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = ") << title << wxT(", ")
64 << wxT("const wxPoint& pos = wxDefaultPosition, const wxSize& size = ") << SizeAsString() << wxT(", ")
65 << wxT("long style = ") << StyleFlags(wxT("0")) << wxT(");\n");
66 return code;
67 }
68
69 wxString DialogWrapper::BaseCtorImplPrefix() const
70 {
71 wxString code;
72 code << CreateBaseclassName() << wxT("::") << CreateBaseclassName()
73 << wxT("(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long "
74 "style)\n");
75 code << " : " << GetRealClassName() << "(parent, id, title, pos, size, style)\n";
76 return code;
77 }
78
79 wxcWidget* DialogWrapper::Clone() const { return new DialogWrapper(); }
80
81 wxString DialogWrapper::CppCtorCode() const
82 {
83 // Add the dialog icons to the generator helper
84 wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_16));
85 wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_32));
86 wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_64));
87 wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_128));
88 wxcCodeGeneratorHelper::Get().AddIcon(PropertyFile(PROP_BITMAP_PATH_256));
89 return TopLevelWinWrapper::CppCtorCode();
90 }
91
92 void DialogWrapper::GetIncludeFile(wxArrayString& headers) const
93 {
94 headers.Add(wxT("#include <wx/dialog.h>"));
95 headers.Add(wxT("#include <wx/iconbndl.h>"));
96 headers.Add(wxT("#include <wx/artprov.h>"));
97 }
98
99 wxString DialogWrapper::GetWxClassName() const { return wxT("wxDialog"); }
100
101 void DialogWrapper::ToXRC(wxString& text, XRC_TYPE type) const
102 {
103 if(type != wxcWidget::XRC_LIVE) {
104 text << wxT("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>")
105 << wxT("<resource xmlns=\"http://www.wxwidgets.org/wxxrc\">");
106 }
107
108 wxString centred;
109 if(!PropertyString(PROP_CENTRE_ON_SCREEN).empty()) {
110 centred = wxT("<centered>1</centered>"); // In XRC centring is on/off; it doesn't discriminate between
111 // wxBOTH/wxVERTICAL/wxHORIZONTAL
112 }
113
114 text << XRCPrefix() << wxT("<title>") << wxCrafter::CDATA(PropertyString(PROP_TITLE)) << wxT("</title>") << centred
115 << XRCStyle(type != wxcWidget::XRC_LIVE) // The parameter is to add the wxSTAY_ON_TOP, but not if we're 'live'
116 << XRCCommonAttributes() << XRCSize();
117
118 ChildrenXRC(text, type);
119 text << wxT("</object>");
120
121 if(type != wxcWidget::XRC_LIVE) { text << wxT("</resource>"); }
122 }
123
124 void DialogWrapper::LoadPropertiesFromXRC(const wxXmlNode* node)
125 {
126 // First call the base-class for the standard things
127 wxcWidget::LoadPropertiesFromXRC(node);
128
129 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("centered"));
130 if(propertynode) { SetPropertyString(PROP_CENTRE_ON_SCREEN, propertynode->GetNodeContent()); }
131
132 // We've already done 'size' in the baseclass, but do it again for TLWindows
133 // That's because if no size was specified, wxC inflicts 500,300. This isn't what the user expected
134 // So, if there is *not* a specified size, overwrite the wxC default with wxDefaultSize
135 propertynode = XmlUtils::FindFirstByTagName(node, wxT("size"));
136 if(!propertynode) { SetPropertyString(PROP_SIZE, "-1,-1"); }
137 }
138
139 void DialogWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node)
140 {
141 // First call the base-class for the standard things
142 wxcWidget::LoadPropertiesFromwxSmith(node);
143
144 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("centered"));
145 if(propertynode) { SetPropertyString(PROP_CENTRE_ON_SCREEN, propertynode->GetNodeContent()); }
146
147 // We've already done 'size' in the baseclass, but do it again for TLWindows
148 // That's because if no size was specified, wxC inflicts 500,300. This isn't what the user expected
149 // So, if there is *not* a specified size, overwrite the wxC default with wxDefaultSize
150 propertynode = XmlUtils::FindFirstByTagName(node, wxT("size"));
151 if(!propertynode) { SetPropertyString(PROP_SIZE, "-1,-1"); }
152 }
153
154 void DialogWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node)
155 {
156 // First call the base-class for the standard things
157 wxcWidget::LoadPropertiesFromwxFB(node);
158
159 wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "center");
160 if(propertynode) { SetPropertyString(PROP_CENTRE_ON_SCREEN, propertynode->GetNodeContent()); }
161 // See the comment in LoadPropertiesFromXRC()
162 propertynode = XmlUtils::FindNodeByName(node, "property", wxT("size"));
163 if(!propertynode) { SetPropertyString(PROP_SIZE, "-1,-1"); }
164 }
165
166 bool DialogWrapper::HasIcon() const { return true; }