File: menu_wrapper.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (78 lines) | stat: -rw-r--r-- 2,741 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "menu_wrapper.h"
#include "allocator_mgr.h"
#include "wxgui_defs.h"
#include "wxgui_helpers.h"

MenuWrapper::MenuWrapper()
    : wxcWidget(ID_WXMENU)
{
    m_styles.Clear();
    m_properties.DeleteValues();

#ifdef __WXGTK__
    PREPEND_STYLE_FALSE(wxMENU_TEAROFF);
#endif

    RegisterEvent("wxEVT_MENU_OPEN", "wxMenuEvent", _("The menu is about to open"));
    RegisterEvent("wxEVT_MENU_HIGHLIGHT", "wxMenuEvent", _("A particular menu item has been highlit"));
    RegisterEvent("wxEVT_MENU_HIGHLIGHT_ALL", "wxMenuEvent", _("The currently selected menu item has changed"));
    RegisterEvent("wxEVT_MENU_CLOSE", "wxMenuEvent", _("The menu is about to close"));

    SetPropertyString(_("Common Settings"), "wxMenu");
    AddProperty(new CategoryProperty(_("Menu")));
    AddProperty(new StringProperty(PROP_NAME, "", _("C++ variable name")));
    AddProperty(new StringProperty(PROP_LABEL, _("Menu"), _("A title for the popup menu")));

    m_namePattern = wxT("m_menu");
    SetName(GenerateName());
}

MenuWrapper::~MenuWrapper() {}

wxcWidget* MenuWrapper::Clone() const { return new MenuWrapper(); }

wxString MenuWrapper::CppCtorCode() const
{
    wxString code;

    wxcWidget* ancestor = GetParent(); // Find the first non-menu parent, to check it's kosher
    while(ancestor && (ancestor->GetType() == ID_WXMENU || ancestor->GetType() == ID_WXSUBMENU)) {
        ancestor = ancestor->GetParent();
    }
    if(ancestor && ancestor->GetType() == ID_WXTOOLBARITEM) {
        // A toolbaritem dropdown menu (probably an auitoolbar, as that's not yet implemented for the standard one
        // This is handled in a completely different way, so don't emit anything
        return code;
    }

    code << GetName() << wxT(" = new ") << GetWxClassName() << wxT("();\n");

    wxcWidget* parent = GetParent();
    if(parent) {
        if(parent->GetType() == ID_WXMENUBAR) {

            // This menu is a child of a menubar, add it
            code << GetWindowParent() << wxT("->Append(") << GetName() << wxT(", ")
                 << wxCrafter::UNDERSCORE(PropertyString(PROP_LABEL)) << wxT(");\n");

        } else if(parent->GetType() == ID_WXMENU || parent->GetType() == ID_WXSUBMENU) {

            // Sub menu
            code << GetWindowParent() << wxT("->AppendSubMenu(") << GetName() << wxT(", ") << Label() << wxT(");\n");
        }
    }
    return code;
}

void MenuWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/menu.h>")); }

wxString MenuWrapper::GetWxClassName() const { return wxT("wxMenu"); }

void MenuWrapper::ToXRC(wxString& text, XRC_TYPE type) const
{
    text << XRCPrefix() << XRCLabel() << XRCStyle();

    ChildrenXRC(text, type);

    text << XRCSuffix();
}