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)
5  2019, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
50 #ifndef STAGE_MODEL_VIEW_HOOK_H
51 #define STAGE_MODEL_VIEW_HOOK_H
52 
53 #include "lib/nocopy.hpp"
54 #include "lib/util.hpp"
55 
56 #include <utility>
57 
58 
59 namespace stage {
60 namespace model {
61 
62 
74  template<class WID>
75  class ViewHook
76  {
77  public:
78  virtual ~ViewHook() { }
79 
80  virtual void hook (WID& widget) =0;
81  virtual void remove (WID& widget) =0;
82  virtual void rehook (WID& widget) noexcept =0;
83 
84  template<class IT>
85  void reOrder (IT newOrder);
86  };
87 
88 
89 
113  template<class WID, class BASE =WID>
115  : public WID
117  {
118  using View = ViewHook<BASE>;
119  View* view_;
120 
121  public:
122  template<typename...ARGS>
123  ViewHooked (View& view, ARGS&& ...args)
124  : WID{std::forward<ARGS>(args)...}
125  , view_{&view}
126  {
127  view_->hook (*this);
128  }
129 
130  ~ViewHooked() noexcept
131  {
132  try {
133  if (view_)
134  view_->remove (*this);
135  }
136  ERROR_LOG_AND_IGNORE (progress, "Detaching of ViewHooked widgets from the presentation")
137  }
138  };
139 
140 
141 
155  template<class WID>
156  template<class IT>
157  void
159  {
160  for (WID& existingHook : newOrder)
161  this->rehook (existingHook);
162  }
163 
164 
165 
166 }}// namespace stage::model
167 #endif /*STAGE_MODEL_VIEW_HOOK_H*/
void reOrder(IT newOrder)
re-attach elements in a given, new order.
Definition: view-hook.hpp:158
virtual ~ViewHook()
this is an interface
Definition: view-hook.hpp:78
A widget attached onto a display canvas or similar central presentation context.
Definition: view-hook.hpp:114
#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:266
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
Interface to represent _"some presentation layout entity",_ with the ability to attach widgets (manag...
Definition: view-hook.hpp:75
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...