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_bool_expression.h"
51 # include "gls_color.h"
52 # include "gls_menu_action.h"
53 # include "gls_menu_data_group.h"
54 
55 //----------------------------------------------------------------------------
56 //----------------------------------------------------------------------------
77 //----------------------------------------------------------------------------
78 //----------------------------------------------------------------------------
80 {
81 public:
82  //------------------------------------------------------------------------
93  //------------------------------------------------------------------------
95  const std::string& label,
96  GlsMenuDictionary& dataDict,
97  GlsMenuAction::HandlerCont_t& actionHandlers );
98 
99  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  virtual ~GlsMenuItemState();
105 
106  //------------------------------------------------------------------------
110  //------------------------------------------------------------------------
111  virtual bool Active() const { return _active(); }
112 
113  //------------------------------------------------------------------------
117  //------------------------------------------------------------------------
118  const disti::glsColor& Color() const;
119 
120  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  virtual std::string Label() const;
126 
127  //------------------------------------------------------------------------
131  //------------------------------------------------------------------------
132  virtual bool Visible() const { return _visible(); }
133 
134  //------------------------------------------------------------------------
141  //------------------------------------------------------------------------
142  virtual void Select();
143 
144  //------------------------------------------------------------------------
150  //------------------------------------------------------------------------
151  void CheckTimers();
152 
153 protected:
156 
159 
161  std::string _colorName;
162 
165 
168 
171 
172 }; // end GlsMenuItemState
173 
174 //----------------------------------------------------------------------------
175 //----------------------------------------------------------------------------
185 //----------------------------------------------------------------------------
186 //----------------------------------------------------------------------------
187 template<class State_t>
188 class GlsMenuItem_T : public GlsMenuHandlerGroup_T<State_t>
189 {
190 public:
192 
193  //------------------------------------------------------------------------
206  //------------------------------------------------------------------------
208  const std::string& name,
209  GlsMenuDictionary& dataDict,
210  GlsMenuAction::HandlerCont_t& actionHandlers )
211  :
212 
213  GlsMenuHandlerGroup_T<State_t>( name, dataDict, actionHandlers, false )
214  , _currentState( 0 )
215  {}
216 
217  //------------------------------------------------------------------------
221  //------------------------------------------------------------------------
222  virtual ~GlsMenuItem_T() {}
223 
224  //------------------------------------------------------------------------
232  //------------------------------------------------------------------------
233  State_t* State()
234  {
235  _currentState = 0;
236 
237  for( GlsMenuDictionary::iterator stateIt = BaseClass::_attr.Begin();
238  stateIt != BaseClass::_attr.End();
239  ++stateIt )
240  {
241  State_t* state = dynamic_cast<State_t*>( *stateIt );
242 
243  if( state )
244  {
245  state->CheckTimers();
246 
247  if( state->Visible() )
248  {
249  _currentState = state;
250  break;
251  }
252  }
253  }
254  return _currentState;
255  }
256 
257  //------------------------------------------------------------------------
262  //------------------------------------------------------------------------
263  void Select()
264  {
265  if( _currentState )
266  _currentState->Select();
267  }
268 
269 protected:
270  State_t* _currentState;
271 
272 }; // end GlsMenuItem
273 
274 #endif // GLS_MENUITEM_H
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()
const_iterator End() const
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.
disti::DistiAttribDict::iterator iterator
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...