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>
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.
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.
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.
21 #ifndef __gtk2_ardour_window_manager_h__
22 #define __gtk2_ardour_window_manager_h__
27 #include <boost/function.hpp>
28 #include <glibmm/refptr.h>
29 #include <sigc++/trackable.h>
31 #include "gtkmm2ext/bindings.h"
32 #include "gtkmm2ext/window_proxy.h"
42 class VisibilityTracker;
47 class SessionHandlePtr;
54 class Manager : public ARDOUR::SessionHandlePtr
57 static Manager& instance();
59 void register_window (ProxyBase*);
60 void remove (const ProxyBase*);
61 void toggle_window (ProxyBase*);
62 void show_visible () const;
63 void set_session (ARDOUR::Session*);
64 void add_state (XMLNode&) const;
67 void set_transient_for (Gtk::Window*);
68 Gtk::Window* transient_parent() const { return current_transient_parent; }
71 typedef std::list<ProxyBase*> Windows;
73 Glib::RefPtr<Gtk::ActionGroup> window_actions;
74 Gtk::Window* current_transient_parent;
79 static Manager* _instance;
81 void window_proxy_was_mapped (ProxyBase*);
82 void window_proxy_was_unmapped (ProxyBase*);
85 class ProxyBase : public ARDOUR::SessionHandlePtr, public Gtkmm2ext::WindowProxy
88 ProxyBase (const std::string& name, const std::string& menu_name);
89 ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&);
91 virtual ARDOUR::SessionHandlePtr* session_handle () = 0;
97 class ProxyTemporary: public ProxyBase
100 ProxyTemporary (const std::string& name, Gtk::Window* win);
102 Gtk::Window* get (bool create = false) {
107 Gtk::Window* operator->() {
111 ARDOUR::SessionHandlePtr* session_handle ();
113 void explicit_delete () { _window = 0 ; delete this; }
117 class ProxyWithConstructor: public ProxyBase
120 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
121 : ProxyBase (name, menu_name) , creator (c) {}
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) {}
126 Gtk::Window* get (bool create = false) {
132 _window = dynamic_cast<Gtk::Window*> (creator ());
143 return dynamic_cast<T*> (get (true));
146 ARDOUR::SessionHandlePtr* session_handle () {
147 /* may return null */
148 return dynamic_cast<T*> (_window);
151 void set_session(ARDOUR::Session *s) {
152 SessionHandlePtr::set_session (s);
153 ARDOUR::SessionHandlePtr* sp = session_handle ();
156 dynamic_cast<T*>(_window)->set_session(s);
161 boost::function<T*()> creator;
165 class Proxy : public ProxyBase
168 Proxy (const std::string& name, const std::string& menu_name)
169 : ProxyBase (name, menu_name) {}
171 Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
172 : ProxyBase (name, menu_name, *node) {}
174 Gtk::Window* get (bool create = false) {
191 return dynamic_cast<T*> (get(true));
194 ARDOUR::SessionHandlePtr* session_handle () {
195 /* may return null */
196 return dynamic_cast<T*> (_window);
199 void set_session(ARDOUR::Session *s) {
200 SessionHandlePtr::set_session (s);
201 ARDOUR::SessionHandlePtr* sp = session_handle ();
204 dynamic_cast<T*>(_window)->set_session(s);
209 boost::function<T*()> creator;
214 #endif /* __gtk2_ardour_window_manager_h__ */