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>
38 class VisibilityTracker;
43 class SessionHandlePtr;
50 class Manager : public ARDOUR::SessionHandlePtr
53 static Manager& instance();
55 void register_window (ProxyBase*);
56 void remove (const ProxyBase*);
57 void toggle_window (ProxyBase*);
58 void show_visible () const;
59 void set_session (ARDOUR::Session*);
60 void add_state (XMLNode&) const;
63 void set_transient_for (Gtk::Window*);
64 Gtk::Window* transient_parent() const { return current_transient_parent; }
67 typedef std::list<ProxyBase*> Windows;
69 Glib::RefPtr<Gtk::ActionGroup> window_actions;
70 Gtk::Window* current_transient_parent;
75 static Manager* _instance;
78 class ProxyBase : public ARDOUR::SessionHandlePtr, public sigc::trackable {
80 ProxyBase (const std::string& name, const std::string& menu_name);
81 ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&);
90 bool visible() const { return _visible; }
91 const std::string& name() const { return _name; }
92 const std::string& menu_name() const { return _menu_name; }
94 std::string action_name() const;
95 void set_action (Glib::RefPtr<Gtk::Action>);
96 Glib::RefPtr<Gtk::Action> action() const { return _action; };
99 void use_window (Gtk::Window&);
101 virtual Gtk::Window* get (bool create = false) = 0;
103 virtual void toggle ();
105 void set_state (const XMLNode&);
106 XMLNode& get_state () const;
108 virtual ARDOUR::SessionHandlePtr* session_handle () = 0;
110 operator bool() const { return _window != 0; }
114 std::string _menu_name;
115 Glib::RefPtr<Gtk::Action> _action;
116 Gtk::Window* _window;
117 mutable bool _visible; ///< true if the window should be visible on startup
118 mutable int _x_off; ///< x position
119 mutable int _y_off; ///< y position
120 mutable int _width; ///< width
121 mutable int _height; ///< height
122 Gtkmm2ext::VisibilityTracker* vistracker;
124 void save_pos_and_size ();
125 bool delete_event_handler (GdkEventAny *ev);
130 class ProxyTemporary: public ProxyBase {
132 ProxyTemporary (const std::string& name, Gtk::Window* win);
135 Gtk::Window* get (bool create = false) {
140 Gtk::Window* operator->() {
144 ARDOUR::SessionHandlePtr* session_handle ();
148 class ProxyWithConstructor: public ProxyBase {
150 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
151 : ProxyBase (name, menu_name) , creator (c) {}
153 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c, const XMLNode* node)
154 : ProxyBase (name, menu_name, *node) , creator (c) {}
156 Gtk::Window* get (bool create = false) {
162 _window = dynamic_cast<Gtk::Window*> (creator ());
173 return dynamic_cast<T*> (get (true));
176 ARDOUR::SessionHandlePtr* session_handle () {
177 /* may return null */
178 return dynamic_cast<T*> (_window);
181 void set_session(ARDOUR::Session *s) {
182 SessionHandlePtr::set_session (s);
183 ARDOUR::SessionHandlePtr* sp = session_handle ();
186 dynamic_cast<T*>(_window)->set_session(s);
191 boost::function<T*()> creator;
195 class Proxy : public ProxyBase {
197 Proxy (const std::string& name, const std::string& menu_name)
198 : ProxyBase (name, menu_name) {}
200 Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
201 : ProxyBase (name, menu_name, *node) {}
203 Gtk::Window* get (bool create = false) {
220 return dynamic_cast<T*> (get(true));
223 ARDOUR::SessionHandlePtr* session_handle () {
224 /* may return null */
225 return dynamic_cast<T*> (_window);
228 void set_session(ARDOUR::Session *s) {
229 SessionHandlePtr::set_session (s);
230 ARDOUR::SessionHandlePtr* sp = session_handle ();
233 dynamic_cast<T*>(_window)->set_session(s);
238 boost::function<T*()> creator;
243 #endif /* __gtk2_ardour_window_manager_h__ */