/
MenuItem.h
135 lines (100 loc) · 3.35 KB
/
MenuItem.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#pragma once
#include "xmlutil/Node.h"
#include "iuimanager.h"
#include <vector>
#include <memory>
/** greebo: This is a representation of a general menu item/element.
*
* The possible menuitem types are defined in iuimanager.h.
* Each menu item can have a list of sub-menuitems (this applies to the
* types eMenuBar and eFolder).
*
* Use the MenuManager class to access these menuitems.
*/
namespace ui
{
class MenuItem;
typedef std::shared_ptr<MenuItem> MenuItemPtr;
typedef std::weak_ptr<MenuItem> MenuItemWeakPtr;
class MenuItem :
public std::enable_shared_from_this<MenuItem>
{
// The parent of this MenuItem (weak reference to avoid circular ownership)
MenuItemWeakPtr _parent;
// The name of this node
std::string _name;
// The caption (display string) incl. the mnemonic
std::string _caption;
// The icon name
std::string _icon;
// The associated event
std::string _event;
wxObject* _widget;
// The children of this MenuItem
typedef std::vector<MenuItemPtr> MenuItemList;
MenuItemList _children;
eMenuItemType _type;
// Stays false until the widgets are actually created.
bool _constructed;
static int _nextMenuItemId;
public:
// Constructor, needs a name and a parent specified
MenuItem(const MenuItemPtr& parent = MenuItemPtr());
// Destructor disconnects the widget from the event
~MenuItem();
// The name of this MenuItem
std::string getName() const;
void setName(const std::string& name);
void setIcon(const std::string& icon);
// Returns TRUE if this item has no parent item
bool isRoot() const;
// Returns the pointer to the parent (is NULL for the root item)
MenuItemPtr parent() const;
void setParent(const MenuItemPtr& parent);
/** greebo: Adds the given menuitem to the list of children.
*
* Note: the new child is NOT reparented, the calling function must to this.
*/
void addChild(const MenuItemPtr& newChild);
/**
* Removes the given child from this menu item.
*/
void removeChild(const MenuItemPtr& child);
// Removes all child nodes
void removeAllChildren();
/** greebo: Tries to find the GtkMenu position index of the given child.
*/
int getMenuPosition(const MenuItemPtr& child);
// Returns the type of this item node
eMenuItemType getType() const;
void setType(eMenuItemType type);
// Gets/sets the caption of this item
void setCaption(const std::string& caption);
std::string getCaption() const;
// Returns TRUE if this has no actual event assigned
bool isEmpty() const;
// Returns the number of child items
std::size_t numChildren() const;
// Return / set the event name
std::string getEvent() const;
void setEvent(const std::string& eventName);
void connectEvent();
void disconnectEvent();
// Use this to get the corresponding wx menu widget out of this item.
wxObject* getWidget();
void setWidget(wxObject* object);
// Tries to (recursively) locate the menuitem by looking up the path
MenuItemPtr find(const std::string& menuPath);
/**
* Parses the given XML node recursively and creates all items from the
* information it finds. Returns the constructed MenuItem.
*/
static MenuItemPtr CreateFromNode(const xml::Node& node);
private:
/** greebo: This constructs the actual widgets. This is invoked as soon
* as the first getWidget of this object is requested.
*/
void construct();
static eMenuItemType GetTypeForXmlNode(const xml::Node& node);
};
} // namespace ui