Ardour  9.0-pre0-350-gf17a656217
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 
157  if (sp) {
158  sp->set_session (s);
159  }
160  ARDOUR::SessionHandlePtr* wsp = dynamic_cast<T*>(_window);
161  if (wsp && wsp != sp) {
162  /* can this happen ? */
163  assert (0);
164  wsp->set_session(s);
165  }
166  }
167 
168 private:
169  std::function<T*()> creator;
170 };
171 
172 template<typename T>
173 class Proxy : public ProxyBase
174 {
175 public:
176  Proxy (const std::string& name, const std::string& menu_name)
177  : ProxyBase (name, menu_name) {}
178 
179  Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
180  : ProxyBase (name, menu_name, *node) {}
181 
182  Gtk::Window* get (bool create = false) {
183  if (!_window) {
184  if (!create) {
185  return 0;
186  }
187 
188  _window = new T ();
189 
190  if (_window) {
191  setup ();
192  }
193  }
194 
195  return _window;
196  }
197 
198  T* operator->() {
199  return dynamic_cast<T*> (get(true));
200  }
201 
203  /* may return null */
204  return dynamic_cast<T*> (_window);
205  }
206 
210  if (sp) {
211  sp->set_session (s);
212  }
213  ARDOUR::SessionHandlePtr* wsp = dynamic_cast<T*>(_window);
214  if (wsp && wsp != sp) {
215  /* can this happen ? */
216  assert (0);
217  wsp->set_session(s);
218  }
219  }
220 
221 private:
222  std::function<T*()> creator;
223 };
224 
225 } /* namespace */
226 
227 #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:187