Debian Codegraph @

wxcrafter/controls/menu_wrapper.cpp

raw
1 #include "menu_wrapper.h"
2 #include "allocator_mgr.h"
3 #include "wxgui_defs.h"
4 #include "wxgui_helpers.h"
5
6 MenuWrapper::MenuWrapper()
7 : wxcWidget(ID_WXMENU)
8 {
9 m_styles.Clear();
10 m_properties.DeleteValues();
11
12 #ifdef __WXGTK__
13 PREPEND_STYLE_FALSE(wxMENU_TEAROFF);
14 #endif
15
16 RegisterEvent("wxEVT_MENU_OPEN", "wxMenuEvent", _("The menu is about to open"));
17 RegisterEvent("wxEVT_MENU_HIGHLIGHT", "wxMenuEvent", _("A particular menu item has been highlit"));
18 RegisterEvent("wxEVT_MENU_HIGHLIGHT_ALL", "wxMenuEvent", _("The currently selected menu item has changed"));
19 RegisterEvent("wxEVT_MENU_CLOSE", "wxMenuEvent", _("The menu is about to close"));
20
21 SetPropertyString(_("Common Settings"), "wxMenu");
22 AddProperty(new CategoryProperty(_("Menu")));
23 AddProperty(new StringProperty(PROP_NAME, "", _("C++ variable name")));
24 AddProperty(new StringProperty(PROP_LABEL, _("Menu"), _("A title for the popup menu")));
25
26 m_namePattern = wxT("m_menu");
27 SetName(GenerateName());
28 }
29
30 MenuWrapper::~MenuWrapper() {}
31
32 wxcWidget* MenuWrapper::Clone() const { return new MenuWrapper(); }
33
34 wxString MenuWrapper::CppCtorCode() const
35 {
36 wxString code;
37
38 wxcWidget* ancestor = GetParent(); // Find the first non-menu parent, to check it's kosher
39 while(ancestor && (ancestor->GetType() == ID_WXMENU || ancestor->GetType() == ID_WXSUBMENU)) {
40 ancestor = ancestor->GetParent();
41 }
42 if(ancestor && ancestor->GetType() == ID_WXTOOLBARITEM) {
43 // A toolbaritem dropdown menu (probably an auitoolbar, as that's not yet implemented for the standard one
44 // This is handled in a completely different way, so don't emit anything
45 return code;
46 }
47
48 code << GetName() << wxT(" = new ") << GetWxClassName() << wxT("();\n");
49
50 wxcWidget* parent = GetParent();
51 if(parent) {
52 if(parent->GetType() == ID_WXMENUBAR) {
53
54 // This menu is a child of a menubar, add it
55 code << GetWindowParent() << wxT("->Append(") << GetName() << wxT(", ")
56 << wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << wxT(");\n");
57
58 } else if(parent->GetType() == ID_WXMENU || parent->GetType() == ID_WXSUBMENU) {
59
60 // Sub menu
61 code << GetWindowParent() << wxT("->AppendSubMenu(") << GetName() << wxT(", ") << Label() << wxT(");\n");
62 }
63 }
64 return code;
65 }
66
67 void MenuWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/menu.h>")); }
68
69 wxString MenuWrapper::GetWxClassName() const { return wxT("wxMenu"); }
70
71 void MenuWrapper::ToXRC(wxString& text, XRC_TYPE type) const
72 {
73 text << XRCPrefix() << XRCLabel() << XRCStyle();
74
75 ChildrenXRC(text, type);
76
77 text << XRCSuffix();
78 }