Debian Codegraph @

wxcrafter/controls/toolbar_base_wrapper.cpp

raw
1 #include "toolbar_base_wrapper.h"
2
3 #include "allocator_mgr.h"
4 #include "tool_bar_item_wrapper.h"
5 #include "top_level_win_wrapper.h"
6 #include "winid_property.h"
7 #include "wxgui_defs.h"
8 #include "wxgui_helpers.h"
9 #include "xmlutils.h"
10 #include "xy_pair.h"
11
12 #include <wx/aui/auibar.h>
13 #include <wx/pen.h>
14 #include <wx/toolbar.h>
15
16 ToolbarBaseWrapper::ToolbarBaseWrapper(int type)
17 : wxcWidget(type)
18 {
19 m_styles.Clear();
20
21 PREPEND_STYLE_TRUE(wxTB_FLAT);
22 PREPEND_STYLE_FALSE(wxTB_DOCKABLE);
23 PREPEND_STYLE_FALSE(wxTB_HORIZONTAL);
24 PREPEND_STYLE_FALSE(wxTB_VERTICAL);
25 PREPEND_STYLE_FALSE(wxTB_TEXT);
26 PREPEND_STYLE_FALSE(wxTB_NOICONS);
27 PREPEND_STYLE_FALSE(wxTB_NODIVIDER);
28 PREPEND_STYLE_FALSE(wxTB_NOALIGN);
29 PREPEND_STYLE_FALSE(wxTB_HORZ_LAYOUT);
30 PREPEND_STYLE_FALSE(wxTB_HORZ_TEXT);
31
32 m_properties.DeleteValues();
33 AddProperty(new CategoryProperty(_("Common Settings"), "wxToolBar"));
34 AddProperty(new WinIdProperty());
35 AddProperty(new StringProperty(PROP_SIZE, wxT("-1,-1"),
36 _("The control size. It is recommended to leave it as -1,-1 and "
37 "let\nthe sizers calculate the best size for the window")));
38 AddProperty(new StringProperty(PROP_NAME, wxT(""), _("C++ member name")));
39 AddProperty(new StringProperty(PROP_TOOLTIP, wxT(""), _("Tooltip")));
40
41 AddProperty(new CategoryProperty(_("ToolBar")));
42 AddProperty(new StringProperty(PROP_BITMAP_SIZE, wxT("16,16"), _("Sets the default size of each tool bitmap")));
43 AddProperty(
44 new StringProperty(PROP_MARGINS, wxT("-1,-1"), _("Sets the values to be used as margins for the toolbar.")));
45 AddProperty(new StringProperty(PROP_PADDING, wxT("1"), _("Sets the space between tools.")));
46 AddProperty(new StringProperty(PROP_SEPARATOR_SIZE, wxT("5"), _("Sets the width of separators.")));
47
48 AddProperty(new CategoryProperty(_("Subclass")));
49 AddProperty(new StringProperty(PROP_SUBCLASS_NAME, wxT(""),
50 _("The name of the derived class. Used both for C++ and XRC generated code.")));
51 AddProperty(
52 new StringProperty(PROP_SUBCLASS_INCLUDE, wxT(""),
53 _("(C++ only) The name of any extra header file to be #included e.g. mydialog.hpp")));
54 AddText(PROP_SUBCLASS_STYLE,
55 _("Override the default class style with the content of this field.\nThe style should be | separated"));
56 m_namePattern = wxT("m_toolbar");
57 SetName(GenerateName());
58 }
59
60 ToolbarBaseWrapper::~ToolbarBaseWrapper() {}
61
62 wxString ToolbarBaseWrapper::CppCtorCode() const
63 {
64 wxString code;
65 bool isMainToolbar = (GetParent() && GetParent()->GetType() == ID_WXFRAME);
66 bool isSubclassed = (GetRealClassName() != GetWxClassName());
67 if(isMainToolbar && !isSubclassed) {
68 code << GetName() << wxT(" = this->CreateToolBar(") << StyleFlags(wxT("wxTB_FLAT|wxTB_HORIZONTAL")) << wxT(", ")
69 << WindowID() << wxT(");\n");
70 } else {
71 code << CPPStandardWxCtor(wxT("wxTB_HORIZONTAL|wxNO_BORDER"));
72 }
73
74 XYPair pr(PropertyString(PROP_BITMAP_SIZE), 16, 16);
75 code << GetName() << wxT("->SetToolBitmapSize(wxSize") << pr.ToString(true) << wxT(");\n");
76
77 XYPair margins(PropertyString(PROP_MARGINS), -1, -1);
78 if(margins != XYPair(-1, -1)) {
79 code << GetName() << wxT("->SetMargins(") << margins.ToString() << wxT(");\n");
80 }
81 wxString padding = PropertyString(PROP_PADDING);
82 if(padding != "1") {
83 code << GetName() << wxT("->SetToolPacking(") << padding << wxT(");\n");
84 }
85 wxString sepWidth = PropertyString(PROP_SEPARATOR_SIZE);
86 if(sepWidth != "5") {
87 code << GetName() << wxT("->SetToolSeparation(") << sepWidth << wxT(");\n");
88 }
89 return code;
90 }
91
92 void ToolbarBaseWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/toolbar.h>")); }
93
94 wxString ToolbarBaseWrapper::GetWxClassName() const { return wxT("wxToolBar"); }
95
96 void ToolbarBaseWrapper::ToXRC(wxString& text, XRC_TYPE type) const
97 {
98 if(type == XRC_DESIGNER && GetParent()->GetType() == ID_WXFRAME) {
99 // This ToolBar is a direct child of the main frame
100 // however, since our designer preview is wxPanel based
101 // we cant really place it here, so return empty string
102 // we hack it later
103 return;
104 }
105
106 XYPair prSize(PropertyString(PROP_BITMAP_SIZE), 16, 16);
107 XYPair prMargins(PropertyString(PROP_MARGINS), -1, -1);
108
109 text << XRCPrefix() << XRCStyle() << wxT("<bitmapsize>") << prSize.ToString() << wxT("</bitmapsize>");
110
111 if(prMargins != XYPair(-1, -1)) {
112 text << wxT("<margins>") << prMargins.ToString() << wxT("</margins>");
113 }
114
115 wxString padding = PropertyString(PROP_PADDING);
116 if(padding != "1") {
117 text << wxT("<packing>") << padding << wxT("</packing>");
118 }
119 wxString sepWidth = PropertyString(PROP_SEPARATOR_SIZE);
120 if(sepWidth != "5") {
121 text << wxT("<separation>") << sepWidth << wxT("</separation>");
122 }
123
124 ChildrenXRC(text, type);
125 text << XRCSuffix();
126 }
127
128 wxString ToolbarBaseWrapper::DesignerXRC() const
129 {
130 wxString toolbarXRC;
131 toolbarXRC << wxT("<object class=\"") << GetWxClassName() << wxT("\" name=\"TOOL_BAR_ID\">");
132 XYPair prSize(PropertyString(PROP_BITMAP_SIZE), 16, 16);
133 XYPair prMargins(PropertyString(PROP_MARGINS), -1, -1);
134
135 toolbarXRC << XRCStyle() << wxT("<bitmapsize>") << prSize.ToString() << wxT("</bitmapsize>");
136
137 if(prMargins != XYPair(-1, -1)) {
138 toolbarXRC << wxT("<margins>") << prMargins.ToString() << wxT("</margins>");
139 }
140
141 ChildrenXRC(toolbarXRC, XRC_DESIGNER);
142 toolbarXRC << XRCSuffix();
143 return toolbarXRC;
144 }
145
146 void ToolbarBaseWrapper::LoadPropertiesFromXRC(const wxXmlNode* node)
147 {
148 // First call the base-class for the standard things
149 wxcWidget::LoadPropertiesFromXRC(node);
150
151 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("bitmapsize"));
152 if(propertynode) {
153 SetPropertyString(PROP_BITMAP_SIZE, propertynode->GetNodeContent());
154 }
155
156 propertynode = XmlUtils::FindFirstByTagName(node, wxT("margins"));
157 if(propertynode) {
158 SetPropertyString(PROP_MARGINS, propertynode->GetNodeContent());
159 }
160
161 propertynode = XmlUtils::FindFirstByTagName(node, wxT("packing"));
162 if(propertynode) {
163 SetPropertyString(PROP_PADDING, propertynode->GetNodeContent());
164 }
165
166 propertynode = XmlUtils::FindFirstByTagName(node, wxT("separation"));
167 if(propertynode) {
168 SetPropertyString(PROP_SEPARATOR_SIZE, propertynode->GetNodeContent());
169 }
170 }
171
172 void ToolbarBaseWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node)
173 {
174 // First call the base-class for the standard things
175 wxcWidget::LoadPropertiesFromwxFB(node);
176
177 // wxC doesn't (yet) do 'separation' or 'packing'
178 wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "bitmapsize");
179 if(propertynode) {
180 SetPropertyString(PROP_BITMAP_SIZE, propertynode->GetNodeContent());
181 }
182
183 propertynode = XmlUtils::FindNodeByName(node, "property", "margins");
184 if(propertynode) {
185 SetPropertyString(PROP_MARGINS, propertynode->GetNodeContent());
186 }
187
188 propertynode = XmlUtils::FindNodeByName(node, "property", "packing");
189 if(propertynode) {
190 SetPropertyString(PROP_PADDING, propertynode->GetNodeContent());
191 }
192
193 propertynode = XmlUtils::FindNodeByName(node, "property", "separation");
194 if(propertynode) {
195 SetPropertyString(PROP_SEPARATOR_SIZE, propertynode->GetNodeContent());
196 }
197 }
198
199 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
200 /// AUI ToolBar
201 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
202
203 AuiToolbarWrapper::AuiToolbarWrapper()
204 : wxcWidget(ID_WXAUITOOLBAR)
205 {
206 m_styles.Clear();
207 m_properties.DeleteValues();
208 EnableSizerFlag(wxT("wxEXPAND"), true);
209
210 AddProperty(new CategoryProperty(_("Common Settings")));
211 AddProperty(new WinIdProperty());
212 AddProperty(new StringProperty(PROP_SIZE, wxT("-1,-1"),
213 _("The control size. It is recommended to leave it as -1,-1 and "
214 "let\nthe sizers calculate the best size for the window")));
215 AddProperty(new StringProperty(PROP_NAME, wxT(""), _("C++ member name")));
216 AddProperty(new StringProperty(PROP_TOOLTIP, wxT(""), _("Tooltip")));
217
218 AddProperty(new CategoryProperty(_("wxAuiToolBar")));
219 AddProperty(new StringProperty(PROP_BITMAP_SIZE, wxT("16,16"), _("Sets the default size of each tool bitmap")));
220 AddProperty(
221 new StringProperty(PROP_MARGINS, wxT("-1,-1"), _("Set the values to be used as margins for the toolbar.")));
222
223 PREPEND_STYLE_FALSE(wxAUI_TB_TEXT);
224 PREPEND_STYLE_FALSE(wxAUI_TB_NO_TOOLTIPS);
225 PREPEND_STYLE_FALSE(wxAUI_TB_NO_AUTORESIZE);
226 PREPEND_STYLE_FALSE(wxAUI_TB_GRIPPER);
227 PREPEND_STYLE_FALSE(wxAUI_TB_OVERFLOW);
228 PREPEND_STYLE_FALSE(wxAUI_TB_VERTICAL);
229 PREPEND_STYLE_FALSE(wxAUI_TB_HORZ_LAYOUT);
230 PREPEND_STYLE_FALSE(wxAUI_TB_HORZ_TEXT);
231 PREPEND_STYLE_TRUE(wxAUI_TB_DEFAULT_STYLE);
232 PREPEND_STYLE_TRUE(wxAUI_TB_PLAIN_BACKGROUND);
233
234 m_namePattern = wxT("m_auibar");
235 SetName(GenerateName());
236 }
237
238 wxString AuiToolbarWrapper::CppCtorCode() const
239 {
240 wxString code;
241 code << CPPStandardWxCtor(wxT("wxAUI_TB_DEFAULT_STYLE"));
242 XYPair pr(PropertyString(PROP_BITMAP_SIZE), 16, 16);
243 code << GetName() << wxT("->SetToolBitmapSize(wxSize") << pr.ToString(true) << wxT(");\n");
244
245 XYPair margins(PropertyString(PROP_MARGINS), -1, -1);
246 if(margins != XYPair(-1, -1)) {
247 code << GetName() << wxT("->SetMargins(") << margins.ToString() << wxT(");\n");
248 }
249 return code;
250 }
251
252 wxString AuiToolbarWrapper::DoGenerateClassMember() const { return GenerateClassMembers(this); }
253
254 void AuiToolbarWrapper::DoGenerateExtraFunctions(wxString& decl, wxString& impl) const
255 {
256 GenerateExtraFunctions(this, decl, impl);
257 }
258
259 void AuiToolbarWrapper::ToXRC(wxString& text, XRC_TYPE type) const
260 {
261 XYPair prSize(PropertyString(PROP_BITMAP_SIZE), 16, 16);
262 XYPair prMargins(PropertyString(PROP_MARGINS), -1, -1);
263
264 text << XRCPrefix() << XRCStyle() << XRCCommonAttributes() << wxT("<bitmapsize>") << prSize.ToString()
265 << wxT("</bitmapsize>");
266
267 if(prMargins != XYPair(-1, -1)) {
268 text << wxT("<margins>") << prMargins.ToString() << wxT("</margins>");
269 }
270
271 ChildrenXRC(text, type);
272 text << XRCSuffix();
273 }
274
275 void AuiToolbarWrapper::LoadPropertiesFromXRC(const wxXmlNode* node)
276 {
277 // First call the base-class for the standard things
278 wxcWidget::LoadPropertiesFromXRC(node);
279
280 // wxC doesn't (yet) do 'separation' or 'packing'
281 wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("bitmapsize"));
282 if(propertynode) {
283 SetPropertyString(PROP_BITMAP_SIZE, propertynode->GetNodeContent());
284 }
285
286 propertynode = XmlUtils::FindFirstByTagName(node, wxT("margins"));
287 if(propertynode) {
288 SetPropertyString(PROP_MARGINS, propertynode->GetNodeContent());
289 }
290 }
291
292 void AuiToolbarWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node)
293 {
294 // First call the base-class for the standard things
295 wxcWidget::LoadPropertiesFromwxFB(node);
296
297 // wxC doesn't (yet) do 'separation' or 'packing'
298 wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "bitmapsize");
299 if(propertynode) {
300 SetPropertyString(PROP_BITMAP_SIZE, propertynode->GetNodeContent());
301 }
302
303 propertynode = XmlUtils::FindNodeByName(node, "property", "margins");
304 if(propertynode) {
305 SetPropertyString(PROP_MARGINS, propertynode->GetNodeContent());
306 }
307 }
308
309 wxString AuiToolbarWrapper::CppDtorCode() const { return AuiToolbarWrapperBase::CppDtorCode(this); }
310
311 void AuiToolbarWrapper::GetIncludeFile(wxArrayString& headers) const { BaseGetIncludeFile(headers); }