Lumiera  0.pre.03
»edit your freedom«
view-hook.hpp
Go to the documentation of this file.
1 /*
2  VIEW-HOOK.hpp - abstracted attachment to a canvas or display facility
3 
4  Copyright (C) Lumiera.org
5  2019, 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 
59 #ifndef STAGE_MODEL_VIEW_HOOK_H
60 #define STAGE_MODEL_VIEW_HOOK_H
61 
62 #include "lib/nocopy.hpp"
63 #include "lib/util.hpp"
64 
65 #include <utility>
66 
67 
68 namespace stage {
69 namespace model {
70 
71 
83  template<class WID>
84  class ViewHook
85  {
86  public:
87  virtual ~ViewHook() { }
88 
89  virtual void hook (WID& widget) =0;
90  virtual void remove (WID& widget) =0;
91  virtual void rehook (WID& widget) noexcept =0;
92 
93  template<class IT>
94  void reOrder (IT newOrder);
95  };
96 
97 
98 
122  template<class WID, class BASE =WID>
124  : public WID
126  {
127  using View = ViewHook<BASE>;
128  View* view_;
129 
130  public:
131  template<typename...ARGS>
132  ViewHooked (View& view, ARGS&& ...args)
133  : WID{std::forward<ARGS>(args)...}
134  , view_{&view}
135  {
136  view_->hook (*this);
137  }
138 
139  ~ViewHooked() noexcept
140  {
141  try {
142  if (view_)
143  view_->remove (*this);
144  }
145  ERROR_LOG_AND_IGNORE (progress, "Detaching of ViewHooked widgets from the presentation")
146  }
147  };
148 
149 
150 
164  template<class WID>
165  template<class IT>
166  void
168  {
169  for (WID& existingHook : newOrder)
170  this->rehook (existingHook);
171  }
172 
173 
174 
175 }}// namespace stage::model
176 #endif /*STAGE_MODEL_VIEW_HOOK_H*/
void reOrder(IT newOrder)
re-attach elements in a given, new order.
Definition: view-hook.hpp:167
virtual ~ViewHook()
this is an interface
Definition: view-hook.hpp:87
A widget attached onto a display canvas or similar central presentation context.
Definition: view-hook.hpp:123
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error...
Definition: error.hpp:275
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
Interface to represent _"some presentation layout entity",_ with the ability to attach widgets (manag...
Definition: view-hook.hpp:84
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...