GlsMenu
gls_menu.h
Go to the documentation of this file.
1 
41 #if !defined(GLS_MENU_H)
42 #define GLS_MENU_H
43 
44 #ifdef WIN32
45 #pragma warning (disable:4786)
46 #endif
47 
48 #include <string>
49 #include "gls_menu_data_group.h"
50 
51 class GlsMenuActionGroup;
52 
53 //----------------------------------------------------------------------------
57 //----------------------------------------------------------------------------
58 class GlsMenu : public GlsMenuDataGroup
59 {
60 public:
61 
62  //------------------------------------------------------------------------
68  //------------------------------------------------------------------------
69  virtual void Hide();
70 
71  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  virtual void Show();
79 
80 protected:
81 
82  //------------------------------------------------------------------------
92  //------------------------------------------------------------------------
93  GlsMenu(
94  const std::string& name,
95  GlsMenuDictionary& dataDict,
96  GlsMenuAction::HandlerCont_t& actionHandlers);
97 
98  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  virtual ~GlsMenu();
104 
105 private:
106 
109 
112 
113 }; // end GlsMenu
114 
115 
116 //----------------------------------------------------------------------------
128 //----------------------------------------------------------------------------
129 template <class MenuItem_t, class MenuItemId_t>
130 class GlsMenu_T : public GlsMenu
131 {
132 public:
133 
134  typedef MenuItem_t Item_t;
135  typedef MenuItemId_t ItemId_t;
137 
138  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
144  const std::string& name,
145  GlsMenuDictionary& dataDict,
146  GlsMenuAction::HandlerCont_t& actionHandlers) :
147 
148  GlsMenu(name, dataDict, actionHandlers),
149  _menuItems(new ItemGroup_t("Items", dataDict, actionHandlers))
150  {
151  _attr.Add(_menuItems);
152  }
153 
154  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  virtual ~GlsMenu_T() {}
160 
161  //------------------------------------------------------------------------
167  //------------------------------------------------------------------------
168  ItemGroup_t* Items() const
169  {
170  return _menuItems;
171  }
172 
173  //------------------------------------------------------------------------
182  //------------------------------------------------------------------------
183  MenuItem_t* Item(const ItemId_t& itemId) const
184  {
185  std::stringstream itemName;
186  itemName << itemId;
187  MenuItem_t* menuItem = _menuItems->Item(itemName.str());
188 
189  return menuItem;
190  }
191 
192  //------------------------------------------------------------------------
198  //------------------------------------------------------------------------
199  void SelectItem(const ItemId_t& itemId)
200  {
201  std::stringstream itemName;
202  itemName << itemId;
203  MenuItem_t* menuItem = _menuItems->Item(itemName.str());
204  if (menuItem)
205  menuItem->Select();
206  }
207 
208 private:
209 
211  ItemGroup_t* _menuItems;
212 
213 }; // end GlsMenu_T
214 
215 
216 
217 
218 #endif // GLS_MENU_H
219 
virtual ~GlsMenu_T()
Definition: gls_menu.h:159
ItemGroup_t * _menuItems
Container of menu items within the menu.
Definition: gls_menu.h:211
virtual void Hide()
GlsMenuDictionary _attr
The dictionary of attributes for the group attribute.
MenuItemId_t ItemId_t
Definition: gls_menu.h:135
virtual ~GlsMenu()
ItemGroup_t * Items() const
Definition: gls_menu.h:168
GlsMenu(const std::string &name, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers)
std::map< std::string, ActionHandler_t * > HandlerCont_t
This file defines classes for groups of menu meta-data.
GlsMenuActionGroup * _onHideActions
Group of actions to execute when menu is hidden.
Definition: gls_menu.h:111
GlsMenuHandlerGroup_T< MenuItem_t > ItemGroup_t
Definition: gls_menu.h:136
void SelectItem(const ItemId_t &itemId)
Definition: gls_menu.h:199
MenuItem_t Item_t
Definition: gls_menu.h:134
virtual void Show()
GlsMenu_T(const std::string &name, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers)
Definition: gls_menu.h:143
MenuItem_t * Item(const ItemId_t &itemId) const
Definition: gls_menu.h:183
GlsMenuActionGroup * _onShowActions
Group of actions to execute when menu is shown.
Definition: gls_menu.h:108
T * Item(const std::string &name) const