SCV  4.2.1
Simple Components for Visual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ContextMenu.h
Go to the documentation of this file.
1 #ifndef __SCV_CONTEXT_MENU_H__
2 #define __SCV_CONTEXT_MENU_H__
3 
4 #include "Label.h"
5 #include "Texture2D.h"
6 
7 #include "PopupMenuStyle.h"
8 
9 namespace scv {
10 class MenuHolder;
11 
12 class ContextMenu {
13 friend class MenuHolder;
14 friend class MenuBar;
15 public:
16  typedef std::deque<ContextMenu*> MenuList;
17 
18  ContextMenu(const std::string& name);
19  virtual ~ContextMenu(void);
20 
21  virtual void onMenuAccessed(const std::deque<std::string> &address) {}
22  virtual void onMouseClick(const scv::MouseEvent &evt, const std::deque<std::string> &address) {}
23  virtual void onMouseOver(const scv::MouseEvent &evt, const std::deque<std::string> &address) {}
24  virtual void onStatusChange(void) {}
25 
26  void addMenu(ContextMenu *menu);
27  void removeMenu(ContextMenu *menu);
28  void removeAllMenus();
29 
30  std::string getString(void);
31  void setString(const std::string &label);
32 
33  void setPosition(const scv::Point &position);
34  scv::Point getCurrPosition(void) const;
35 
36  bool getStatus(void) const;
37  void setStatus(bool status);
38 
39  int getWidth(void) const;
40  int getHeight(void) const;
41 
42  bool hasSubMenus(void) const;
43 
44  void setMenuStyle(const PopupMenuStyle* style);
45 
46  const MenuList& getMenus() const;
47 
48  bool processMouse(const scv::MouseEvent &evt);
49  bool processKey(const scv::KeyEvent &evt);
50 
51  void display(void);
52 
53 private:
54  bool isInside(const Point &p);
55  bool isInsideItem(const Point &p, int i) const;
56 
57  bool hasSubMenuActive(void) const;
58 
59  void setSubMenusStatus(bool status);
60  void registerParentMenu(ContextMenu *parentMenu);
61  void processMouseCallback(const MouseEvent &evt, std::deque<std::string> address);
62  void processKeyboardCallback(const KeyEvent &evt, std::deque<std::string> address);
63 
64  bool _recentlyChange;
65  bool _status;
66  int _currSelectedMenu;
67 
68  MenuList _list;
69  ContextMenu *_parentMenu;
70  scv::Point _currPosition;
71  std::string _label;
72  const PopupMenuStyle* _style;
73 };
74 
76  return _list;
77 }
78 
79 inline bool ContextMenu::hasSubMenus(void) const {
80  return _list.size() > 0;
81 }
82 
83 inline std::string ContextMenu::getString(void) {
84  return _label;
85 }
86 
87 inline void ContextMenu::setString(const std::string &label) {
88  _label = label;
89 }
90 
91 inline void ContextMenu::setPosition(const scv::Point &position) {
92  _currPosition = position;
93 }
94 
96  return _currPosition;
97 }
98 
99 inline bool ContextMenu::getStatus(void) const {
100  return _status;
101 }
102 
103 inline int ContextMenu::getWidth(void) const {
104  return _style->calculateWidth(this);
105 }
106 
107 inline int ContextMenu::getHeight(void) const {
108  return _style->calculateHeight(this);
109 }
110 
111 inline bool ContextMenu::isInsideItem(const Point &p, int i) const {
112  return _style->isInsideItem(this, p, i);
113 }
114 
115 } // namespace scv
116 
117 
118 #endif // __SCV_CONTEXT_MENU_H__