GlsMenu
gls_menu_item.h
Go to the documentation of this file.
1 
41 #if !defined(GLS_MENUITEM_H)
42 #define GLS_MENUITEM_H
43 
44 #ifdef WIN32
45 #pragma warning (disable:4786)
46 #endif
47 
48 #include <string>
49 
50 #include "gls_menu_data_group.h"
51 #include "gls_menu_action.h"
52 #include "gls_bool_expression.h"
53 #include "gls_color.h"
54 #include "gls_menu_action.h"
55 
56 
57 //----------------------------------------------------------------------------
58 //----------------------------------------------------------------------------
79 //----------------------------------------------------------------------------
80 //----------------------------------------------------------------------------
82 {
83 public:
84 
85  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
98  const std::string& label,
99  GlsMenuDictionary& dataDict,
100  GlsMenuAction::HandlerCont_t& actionHandlers);
101 
102  //------------------------------------------------------------------------
106  //------------------------------------------------------------------------
107  virtual ~GlsMenuItemState();
108 
109  //------------------------------------------------------------------------
113  //------------------------------------------------------------------------
114  virtual bool Active() const { return _active(); }
115 
116  //------------------------------------------------------------------------
120  //------------------------------------------------------------------------
121  const disti::glsColor& Color() const;
122 
123  //------------------------------------------------------------------------
127  //------------------------------------------------------------------------
128  virtual std::string Label() const;
129 
130  //------------------------------------------------------------------------
134  //------------------------------------------------------------------------
135  virtual bool Visible() const { return _visible(); }
136 
137  //------------------------------------------------------------------------
144  //------------------------------------------------------------------------
145  virtual void Select();
146 
147  //------------------------------------------------------------------------
153  //------------------------------------------------------------------------
154  void CheckTimers();
155 
156 protected:
159 
162 
164  std::string _colorName;
165 
168 
171 
174 
175 
176 }; // end GlsMenuItemState
177 
178 
179 //----------------------------------------------------------------------------
180 //----------------------------------------------------------------------------
190 //----------------------------------------------------------------------------
191 //----------------------------------------------------------------------------
192 template <class State_t>
193 class GlsMenuItem_T : public GlsMenuHandlerGroup_T<State_t>
194 {
195 public:
197 
198  //------------------------------------------------------------------------
211  //------------------------------------------------------------------------
213  const std::string& name,
214  GlsMenuDictionary& dataDict,
215  GlsMenuAction::HandlerCont_t& actionHandlers) :
216 
217  GlsMenuHandlerGroup_T<State_t>(name, dataDict, actionHandlers, false),
218  _currentState(0)
219  {}
220 
221  //------------------------------------------------------------------------
225  //------------------------------------------------------------------------
226  virtual ~GlsMenuItem_T() {}
227 
228  //------------------------------------------------------------------------
236  //------------------------------------------------------------------------
237  State_t* State()
238  {
239  _currentState = 0;
240 
241  for (GlsMenuDictionary::iterator stateIt = BaseClass::_attr.Begin();
242  stateIt != BaseClass::_attr.End();
243  ++stateIt)
244  {
245  State_t* state = dynamic_cast<State_t*>(*stateIt);
246 
247  if (state)
248  {
249  state->CheckTimers();
250 
251  if (state->Visible())
252  {
253  _currentState = state;
254  break;
255  }
256  }
257  }
258  return _currentState;
259  }
260 
261  //------------------------------------------------------------------------
266  //------------------------------------------------------------------------
267  void Select()
268  {
269  if (_currentState)
270  _currentState->Select();
271  }
272 
273 
274 protected:
275  State_t* _currentState;
276 
277 }; // end GlsMenuItem
278 
279 
280 
281 #endif // GLS_MENUITEM_H
282 
GlsMenuItem_T(const std::string &name, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers)
State_t * _currentState
GlsBoolExpression _active
Whether the state is active or not.
const disti::glsColor & Color() const
virtual void Select()
virtual bool Visible() const
GlsMenuDictionary _attr
The dictionary of attributes for the group attribute.
virtual std::string Label() const
GlsMenuItemState(const std::string &label, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers)
State_t * State()
std::map< std::string, ActionHandler_t * > HandlerCont_t
GlsMenuHandlerGroup_T< State_t > BaseClass
This file defines classes for groups of menu meta-data.
virtual ~GlsMenuItem_T()
GlsBoolExpression _visible
Visibility of the menu item state.
GlsMenuActionGroup * _actions
Actions to execute when the menu item state is selected.
std::string _colorName
Current color name of the menu item state.
GlsMenuHandlerGroup_T< GlsMenuTimer > * _timers
Container of timers associated with the state.
virtual ~GlsMenuItemState()
GlsMenuDictionary & _dataDict
Meta-data dictionary used for expanding the values of variables.
virtual bool Active() const
This file defines menu action (callback) meta-data classes.
This file defines a class that provides a string-based boolean expression parser and evaluator...