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 "gtkmm2ext/bindings.h"
31 #include "gtkmm2ext/window_proxy.h"
41 class VisibilityTracker;
46 class SessionHandlePtr;
53 class Manager : public ARDOUR::SessionHandlePtr
56 static Manager& instance();
58 void register_window (ProxyBase*);
59 void remove (const ProxyBase*);
60 void toggle_window (ProxyBase*);
61 void show_visible () const;
62 void set_session (ARDOUR::Session*);
63 void add_state (XMLNode&) const;
66 void set_transient_for (Gtk::Window*);
67 Gtk::Window* transient_parent() const { return current_transient_parent; }
70 typedef std::list<ProxyBase*> Windows;
72 Glib::RefPtr<Gtk::ActionGroup> window_actions;
73 Gtk::Window* current_transient_parent;
78 static Manager* _instance;
80 void window_proxy_was_mapped (ProxyBase*);
81 void window_proxy_was_unmapped (ProxyBase*);
84 class ProxyBase : public ARDOUR::SessionHandlePtr, public Gtkmm2ext::WindowProxy
87 ProxyBase (const std::string& name, const std::string& menu_name);
88 ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&);
90 virtual ARDOUR::SessionHandlePtr* session_handle () = 0;
96 class ProxyTemporary: public ProxyBase
99 ProxyTemporary (const std::string& name, Gtk::Window* win);
101 Gtk::Window* get (bool create = false) {
106 Gtk::Window* operator->() {
110 ARDOUR::SessionHandlePtr* session_handle ();
112 void explicit_delete () { _window = 0 ; delete this; }
116 class ProxyWithConstructor: public ProxyBase
119 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
120 : ProxyBase (name, menu_name) , creator (c) {}
122 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c, const XMLNode* node)
123 : ProxyBase (name, menu_name, *node) , creator (c) {}
125 Gtk::Window* get (bool create = false) {
131 _window = dynamic_cast<Gtk::Window*> (creator ());
142 return dynamic_cast<T*> (get (true));
145 ARDOUR::SessionHandlePtr* session_handle () {
146 /* may return null */
147 return dynamic_cast<T*> (_window);
150 void set_session(ARDOUR::Session *s) {
151 SessionHandlePtr::set_session (s);
152 ARDOUR::SessionHandlePtr* sp = session_handle ();
155 dynamic_cast<T*>(_window)->set_session(s);
160 boost::function<T*()> creator;
164 class Proxy : public ProxyBase
167 Proxy (const std::string& name, const std::string& menu_name)
168 : ProxyBase (name, menu_name) {}
170 Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
171 : ProxyBase (name, menu_name, *node) {}
173 Gtk::Window* get (bool create = false) {
190 return dynamic_cast<T*> (get(true));
193 ARDOUR::SessionHandlePtr* session_handle () {
194 /* may return null */
195 return dynamic_cast<T*> (_window);
198 void set_session(ARDOUR::Session *s) {
199 SessionHandlePtr::set_session (s);
200 ARDOUR::SessionHandlePtr* sp = session_handle ();
203 dynamic_cast<T*>(_window)->set_session(s);
208 boost::function<T*()> creator;
213 #endif /* __gtk2_ardour_window_manager_h__ */