Lumiera  0.pre.03
»edit your freedom«
tangible.cpp
Go to the documentation of this file.
1 /*
2  Tangible - common implementation base of all relevant interface elements
3 
4  Copyright (C) Lumiera.org
5  2015, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
33 #include "stage/model/tangible.hpp"
34 #include "stage/model/widget.hpp"
36 #include "include/ui-protocol.hpp"
37 #include "lib/diff/gen-node.hpp"
38 #include "lib/meta/util.hpp"
39 
40 
41 namespace stage {
42 namespace model {
43 
44 
45 
46  Tangible::~Tangible() { } // Emit VTables here...
47 
48 
49 
53  Tangible::operator string() const
54  {
55  return lib::meta::typeStr (this)
56  + "("
57  + string{this->getID()}
58  + ")";
59  }
60 
61 
73  void
75  {
76  if (this->doReset())
77  uiBus_.note (GenNode{string{MARK_reset}, true});
78  }
79 
80 
95  void
97  {
98  if (this->doClearErr())
99  uiBus_.note (GenNode{string{MARK_clearErr}, true});
100  }
101 
102 
106  void
108  {
109  if (this->doClearMsg())
110  uiBus_.note (GenNode{string{MARK_clearMsg}, true});
111  }
112 
113 
118  void
120  {
121  this->doFlash();
122  }
123 
124 
138  void
139  Tangible::markMsg (string message)
140  {
141  if (this->doMsg (message))
142  uiBus_.note (GenNode{string{MARK_Message}, message});
143  }
144 
145 
149  void
151  {
152  if (this->doErr (error))
153  uiBus_.note (GenNode{string{MARK_Error}, error});
154  }
155 
156 
169  void
171  {
172  if (this->doExpand (true))
173  uiBus_.note (GenNode{string{MARK_expand}, true});
174  }
175 
176 
181  void
183  {
184  if (this->doExpand (false))
185  uiBus_.note (GenNode{string{MARK_expand}, false});
186  }
187 
188 
195  bool
197  {
198  if (not expand_.canExpand())
199  return false;
200  bool oldState = expand_(yes);
201  return oldState != yes; // actually changed
202  }
203 
204 
221  void
223  {
224  this->doReveal();
225  }
226 
227 
233  void
235  {
236  if (reveal_.canReveal())
237  reveal_();
238  }
239 
240 
241 
250  void
251  Tangible::invoke (Symbol cmdID, Rec&& arguments)
252  {
253  uiBus_.act (GenNode{string{cmdID}, std::forward<Rec>(arguments)});
254  }
255 
256 
257 
259  void
260  Tangible::mark (GenNode const& stateMark)
261  {
262  if (stateMark.idi.getSym() == MARK_Flash)
263  this->doFlash();
264  else
265  if (stateMark.idi.getSym() == MARK_Error)
266  this->markErr (stateMark.data.get<string>());
267  else
268  if (stateMark.idi.getSym() == MARK_Message)
269  this->markMsg (stateMark.data.get<string>());
270  else
271  this->doMark(stateMark);
272  }
273 
274 
294  void
295  Tangible::doMark (GenNode const& stateMark)
296  {
297  if (stateMark.idi.getSym() == MARK_expand)
298  {
299  if (this->doExpand (stateMark.data.get<bool>()))
300  uiBus_.note (GenNode(string{MARK_expand}, true)); // possibly reentrant (yet harmless)
301  }
302  else
303  if (stateMark.idi.getSym() == MARK_reset)
304  this->reset();
305  else
306  if (stateMark.idi.getSym() == MARK_clearMsg)
307  this->clearMsg();
308  else
309  if (stateMark.idi.getSym() == MARK_clearErr)
310  this->clearErr();
311  else
312  if (stateMark.idi.getSym() == MARK_reveal)
313  this->doReveal();
314  }
315 
316 
317 
318 }} // namespace stage::model
virtual ~Tangible()
this is an interface
Definition: tangible.cpp:46
void slotExpand()
Expand this element and remember the expanded state.
Definition: tangible.cpp:170
Abstraction: a tangible element of the User Interface.
Hard wired key constants and basic definitions for communication with the GUI.
Common Abstraction of all UIBus connected widget elements.
void reset()
invoke the generic reset hook
Definition: tangible.cpp:74
Simple and lightweight helpers for metaprogramming and type detection.
virtual void note(ID subject, GenNode const &mark)
capture and record a "state mark" for later replay for restoring UI state.
Definition: ui-bus.cpp:158
void mark(GenNode const &)
generic handler for all incoming "state mark" messages
Definition: tangible.cpp:260
virtual bool doExpand(bool yes)
generic default implementation of the expand/collapse functionality.
Definition: tangible.cpp:196
void clearMsg()
invoke the hook to clear notification messages
Definition: tangible.cpp:107
Token or Atom with distinct identity.
Definition: symbol.hpp:116
void markMsg(string message)
push a notification (or warning) message to the element.
Definition: tangible.cpp:139
void markFlash()
highlight the element visually to catch the user&#39;s attention
Definition: tangible.cpp:119
void markErr(string error)
push an error state tag to the element
Definition: tangible.cpp:150
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Generic building block for tree shaped (meta)data structures.
virtual void doMark(GenNode const &)=0
default implementation and catch-all handler for receiving »state mark« messages. ...
Definition: tangible.cpp:295
virtual void doReveal()
generic default implementation of the "reveal" functionality.
Definition: tangible.cpp:234
void slotCollapse()
Collapse or minimise this element and remember the collapsed state.
Definition: tangible.cpp:182
void clearErr()
invoke the hook to clear error markers
Definition: tangible.cpp:96
object-like record of data.
Definition: record.hpp:150
Common Abstraction of all sub-controller, coordinated by the UI-Bus.
virtual void act(GenNode const &command)
prepare or trigger invocation of a command.
Definition: ui-bus.cpp:139
generic data element node within a tree
Definition: gen-node.hpp:231
void slotReveal()
Cause the element to be brought into sight.
Definition: tangible.cpp:222