Ardour  8.12
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 <boost/function.hpp>
28 #include <glibmm/refptr.h>
29 #include <sigc++/trackable.h>
30 
31 #include "gtkmm2ext/bindings.h"
32 #include "gtkmm2ext/window_proxy.h"
33 
34 class XMLNode;
35 
36 namespace Gtk {
37 class Window;
38 class Action;
39 }
40 
41 namespace Gtkmm2ext {
42  class VisibilityTracker;
43 }
44 
45 namespace ARDOUR {
46  class Session;
47  class SessionHandlePtr;
48 }
49 
50 namespace WM {
51 
52 class ProxyBase;
53 
55 {
56 public:
57  static Manager& instance();
58 
60  void remove (const ProxyBase*);
62  void show_visible () const;
64  void add_state (XMLNode&) const;
65 
66  /* HACK HACK HACK */
69 
70 private:
71  typedef std::list<ProxyBase*> Windows;
73  Glib::RefPtr<Gtk::ActionGroup> window_actions;
75 
78 
79  static Manager* _instance;
80 private:
83 };
84 
86 {
87 public:
88  ProxyBase (const std::string& name, const std::string& menu_name);
89  ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&);
90 
92 
93 protected:
94  void setup ();
95 };
96 
98 {
99 public:
100  ProxyTemporary (const std::string& name, Gtk::Window* win);
101 
102  Gtk::Window* get (bool create = false) {
103  (void) create;
104  return _window;
105  }
106 
108  return _window;
109  }
110 
112 
113  void explicit_delete () { _window = 0 ; delete this; }
114 };
115 
116 template<typename T>
118 {
119 public:
120  ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
121  : ProxyBase (name, menu_name) , creator (c) {}
122 
123  ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c, const XMLNode* node)
124  : ProxyBase (name, menu_name, *node) , creator (c) {}
125 
126  Gtk::Window* get (bool create = false) {
127  if (!_window) {
128  if (!create) {
129  return 0;
130  }
131 
132  _window = dynamic_cast<Gtk::Window*> (creator ());
133 
134  if (_window) {
135  setup ();
136  }
137  }
138 
139  return _window;
140  }
141 
142  T* operator->() {
143  return dynamic_cast<T*> (get (true));
144  }
145 
147  /* may return null */
148  return dynamic_cast<T*> (_window);
149  }
150 
154  if (sp) {
155  sp->set_session (s);
156  }
157  ARDOUR::SessionHandlePtr* wsp = dynamic_cast<T*>(_window);
158  if (wsp && wsp != sp) {
159  /* can this happen ? */
160  assert (0);
161  wsp->set_session(s);
162  }
163  }
164 
165 private:
166  boost::function<T*()> creator;
167 };
168 
169 template<typename T>
170 class Proxy : public ProxyBase
171 {
172 public:
173  Proxy (const std::string& name, const std::string& menu_name)
174  : ProxyBase (name, menu_name) {}
175 
176  Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
177  : ProxyBase (name, menu_name, *node) {}
178 
179  Gtk::Window* get (bool create = false) {
180  if (!_window) {
181  if (!create) {
182  return 0;
183  }
184 
185  _window = new T ();
186 
187  if (_window) {
188  setup ();
189  }
190  }
191 
192  return _window;
193  }
194 
195  T* operator->() {
196  return dynamic_cast<T*> (get(true));
197  }
198 
200  /* may return null */
201  return dynamic_cast<T*> (_window);
202  }
203 
207  if (sp) {
208  sp->set_session (s);
209  }
210  ARDOUR::SessionHandlePtr* wsp = dynamic_cast<T*>(_window);
211  if (wsp && wsp != sp) {
212  /* can this happen ? */
213  assert (0);
214  wsp->set_session(s);
215  }
216  }
217 
218 private:
219  boost::function<T*()> creator;
220 };
221 
222 } /* namespace */
223 
224 #endif /* __gtk2_ardour_window_manager_h__ */
virtual void set_session(ARDOUR::Session *)
const std::string & menu_name() const
Definition: window_proxy.h:56
const std::string & name() const
Definition: window_proxy.h:55
Gtk::Window * _window
Definition: window_proxy.h:91
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)
boost::function< T *()> creator
ProxyWithConstructor(const std::string &name, const std::string &menu_name, const boost::function< T *()> &c)
void set_session(ARDOUR::Session *s)
ProxyWithConstructor(const std::string &name, const std::string &menu_name, const boost::function< T *()> &c, const XMLNode *node)
ARDOUR::SessionHandlePtr * session_handle()
Gtk::Window * get(bool create=false)
Proxy(const std::string &name, const std::string &menu_name)
T * operator->()
ARDOUR::SessionHandlePtr * session_handle()
boost::function< T *()> creator
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