Ardour  9.0-pre0-582-g084a23a80d
window_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-2016 John Emmas <john@creativepost.co.uk>
3  * Copyright (C) 2013-2016 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2013-2018 Robin Gareus <robin@gareus.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __gtk2_ardour_window_manager_h__
22 #define __gtk2_ardour_window_manager_h__
23 
24 #include <string>
25 #include <map>
26 
27 #include <sigc++/trackable.h>
28 
29 #include "gtkmm2ext/actions.h"
30 #include "gtkmm2ext/bindings.h"
31 #include "gtkmm2ext/window_proxy.h"
32 
33 #include <glibmm/refptr.h>
34 
35 #include "ardour/session_handle.h"
36 
37 class XMLNode;
38 
39 namespace Gtk {
40 class Window;
41 class Action;
42 }
43 
44 namespace Gtkmm2ext {
45  class VisibilityTracker;
46 }
47 
48 namespace ARDOUR {
49  class Session;
50  class SessionHandlePtr;
51 }
52 
53 namespace WM {
54 
55 class ProxyBase;
56 
58 {
59 public:
60  static Manager& instance();
61 
63  void remove (const ProxyBase*);
65  void show_visible () const;
67  void add_state (XMLNode&) const;
68 
69  /* HACK HACK HACK */
72 
73 private:
74  typedef std::list<ProxyBase*> Windows;
76  Glib::RefPtr<Gtk::ActionGroup> window_actions;
78 
81 
82  static Manager* _instance;
83 private:
86 };
87 
89 {
90 public:
91  ProxyBase (const std::string& name, const std::string& menu_name);
92  ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&);
93 
95 
96 protected:
97  void setup ();
98 };
99 
101 {
102 public:
103  ProxyTemporary (const std::string& name, Gtk::Window* win);
104 
105  Gtk::Window* get (bool create = false) {
106  (void) create;
107  return _window;
108  }
109 
111  return _window;
112  }
113 
115 
116  void explicit_delete () { _window = 0 ; delete this; }
117 };
118 
119 template<typename T>
121 {
122 public:
123  ProxyWithConstructor (const std::string& name, const std::string& menu_name, const std::function<T*()>& c)
124  : ProxyBase (name, menu_name) , creator (c) {}
125 
126  ProxyWithConstructor (const std::string& name, const std::string& menu_name, const std::function<T*()>& c, const XMLNode* node)
127  : ProxyBase (name, menu_name, *node) , creator (c) {}
128 
129  Gtk::Window* get (bool create = false) {
130  if (!_window) {
131  if (!create) {
132  return 0;
133  }
134 
135  _window = dynamic_cast<Gtk::Window*> (creator ());
136 
137  if (_window) {
138  setup ();
139  }
140  }
141 
142  return _window;
143  }
144 
145  T* operator->() {
146  return dynamic_cast<T*> (get (true));
147  }
148 
150  /* may return null */
151  return dynamic_cast<T*> (_window);
152  }
153 
156  if (!s) {
157  return;
158  }
160  if (sp) {
161  sp->set_session (s);
162  }
163  ARDOUR::SessionHandlePtr* wsp = dynamic_cast<T*>(_window);
164  if (wsp && wsp != sp) {
165  /* can this happen ? */
166  assert (0);
167  wsp->set_session(s);
168  }
169  }
170 
171 private:
172  std::function<T*()> creator;
173 };
174 
175 template<typename T>
176 class Proxy : public ProxyBase
177 {
178 public:
179  Proxy (const std::string& name, const std::string& menu_name)
180  : ProxyBase (name, menu_name) {}
181 
182  Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
183  : ProxyBase (name, menu_name, *node) {}
184 
185  Gtk::Window* get (bool create = false) {
186  if (!_window) {
187  if (!create) {
188  return 0;
189  }
190 
191  _window = new T ();
192 
193  if (_window) {
194  setup ();
195  }
196  }
197 
198  return _window;
199  }
200 
201  T* operator->() {
202  return dynamic_cast<T*> (get(true));
203  }
204 
206  /* may return null */
207  return dynamic_cast<T*> (_window);
208  }
209 
212  if (!s) {
213  return;
214  }
216  if (sp) {
217  sp->set_session (s);
218  }
219  ARDOUR::SessionHandlePtr* wsp = dynamic_cast<T*>(_window);
220  if (wsp && wsp != sp) {
221  /* can this happen ? */
222  assert (0);
223  wsp->set_session(s);
224  }
225  }
226 
227 private:
228  std::function<T*()> creator;
229 };
230 
231 } /* namespace */
232 
233 #endif /* __gtk2_ardour_window_manager_h__ */
virtual void set_session(ARDOUR::Session *)
const std::string & menu_name() const
Definition: window_proxy.h:58
const std::string & name() const
Definition: window_proxy.h:57
Gtk::Window * _window
Definition: window_proxy.h:93
void show_visible() const
void set_transient_for(Gtk::Window *)
Glib::RefPtr< Gtk::ActionGroup > window_actions
void toggle_window(ProxyBase *)
void remove(const ProxyBase *)
void window_proxy_was_unmapped(ProxyBase *)
void add_state(XMLNode &) const
void set_session(ARDOUR::Session *)
std::list< ProxyBase * > Windows
Windows _windows
void window_proxy_was_mapped(ProxyBase *)
void register_window(ProxyBase *)
Gtk::Window * transient_parent() const
static Manager & instance()
static Manager * _instance
Gtk::Window * current_transient_parent
ProxyBase(const std::string &name, const std::string &menu_name)
virtual ARDOUR::SessionHandlePtr * session_handle()=0
ProxyBase(const std::string &name, const std::string &menu_name, const XMLNode &)
ARDOUR::SessionHandlePtr * session_handle()
Gtk::Window * operator->()
Gtk::Window * get(bool create=false)
ProxyTemporary(const std::string &name, Gtk::Window *win)
ProxyWithConstructor(const std::string &name, const std::string &menu_name, const std::function< T *()> &c, const XMLNode *node)
void set_session(ARDOUR::Session *s)
ARDOUR::SessionHandlePtr * session_handle()
Gtk::Window * get(bool create=false)
std::function< T *()> creator
ProxyWithConstructor(const std::string &name, const std::string &menu_name, const std::function< T *()> &c)
std::function< T *()> creator
Proxy(const std::string &name, const std::string &menu_name)
T * operator->()
ARDOUR::SessionHandlePtr * session_handle()
Gtk::Window * get(bool create=false)
Proxy(const std::string &name, const std::string &menu_name, const XMLNode *node)
void set_session(ARDOUR::Session *s)
Definition: Window.h:41
Definition: xml++.h:114
void set_session(lua_State *L, Session *s)
Definition: ardour_ui.h:188