2 Copyright (C) 2013 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __gtk2_ardour_window_manager_h__
21 #define __gtk2_ardour_window_manager_h__
26 #include <boost/function.hpp>
27 #include <glibmm/refptr.h>
28 #include <sigc++/trackable.h>
30 #include "lua_script_manager.h"
32 #include "gtkmm2ext/bindings.h"
33 #include "gtkmm2ext/window_proxy.h"
43 class VisibilityTracker;
48 class SessionHandlePtr;
55 class Manager : public ARDOUR::SessionHandlePtr
58 static Manager& instance();
60 void register_window (ProxyBase*);
61 void remove (const ProxyBase*);
62 void toggle_window (ProxyBase*);
63 void show_visible () const;
64 void set_session (ARDOUR::Session*);
65 void add_state (XMLNode&) const;
68 void set_transient_for (Gtk::Window*);
69 Gtk::Window* transient_parent() const { return current_transient_parent; }
72 typedef std::list<ProxyBase*> Windows;
74 Glib::RefPtr<Gtk::ActionGroup> window_actions;
75 Gtk::Window* current_transient_parent;
80 static Manager* _instance;
83 class ProxyBase : public ARDOUR::SessionHandlePtr, public Gtkmm2ext::WindowProxy
86 ProxyBase (const std::string& name, const std::string& menu_name);
87 ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&);
89 virtual ARDOUR::SessionHandlePtr* session_handle () = 0;
95 class ProxyTemporary: public ProxyBase
98 ProxyTemporary (const std::string& name, Gtk::Window* win);
101 Gtk::Window* get (bool create = false) {
106 Gtk::Window* operator->() {
110 ARDOUR::SessionHandlePtr* session_handle ();
114 class ProxyWithConstructor: public ProxyBase
117 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
118 : ProxyBase (name, menu_name) , creator (c) {}
120 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c, const XMLNode* node)
121 : ProxyBase (name, menu_name, *node) , creator (c) {}
123 Gtk::Window* get (bool create = false) {
129 _window = dynamic_cast<Gtk::Window*> (creator ());
140 return dynamic_cast<T*> (get (true));
143 ARDOUR::SessionHandlePtr* session_handle () {
144 /* may return null */
145 return dynamic_cast<T*> (_window);
148 void set_session(ARDOUR::Session *s) {
149 SessionHandlePtr::set_session (s);
150 ARDOUR::SessionHandlePtr* sp = session_handle ();
153 dynamic_cast<T*>(_window)->set_session(s);
158 boost::function<T*()> creator;
162 class Proxy : public ProxyBase
165 Proxy (const std::string& name, const std::string& menu_name)
166 : ProxyBase (name, menu_name) {}
168 Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
169 : ProxyBase (name, menu_name, *node) {}
171 Gtk::Window* get (bool create = false) {
188 return dynamic_cast<T*> (get(true));
191 ARDOUR::SessionHandlePtr* session_handle () {
192 /* may return null */
193 return dynamic_cast<T*> (_window);
196 void set_session(ARDOUR::Session *s) {
197 SessionHandlePtr::set_session (s);
198 ARDOUR::SessionHandlePtr* sp = session_handle ();
201 dynamic_cast<T*>(_window)->set_session(s);
206 boost::function<T*()> creator;
211 #endif /* __gtk2_ardour_window_manager_h__ */