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;
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 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 ();
129 class ProxyTemporary: public ProxyBase {
131 ProxyTemporary (const std::string& name, Gtk::Window* win);
134 Gtk::Window* get (bool create = false) {
139 Gtk::Window* operator->() {
143 ARDOUR::SessionHandlePtr* session_handle ();
147 class ProxyWithConstructor: public ProxyBase {
149 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
150 : ProxyBase (name, menu_name) , creator (c) {}
152 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c, const XMLNode* node)
153 : ProxyBase (name, menu_name, node) , creator (c) {}
155 Gtk::Window* get (bool create = false) {
161 _window = creator ();
172 return dynamic_cast<T*> (get (true));
175 ARDOUR::SessionHandlePtr* session_handle () {
176 /* may return null */
177 return dynamic_cast<T*> (_window);
181 boost::function<T*()> creator;
185 class Proxy : public ProxyBase {
187 Proxy (const std::string& name, const std::string& menu_name)
188 : ProxyBase (name, menu_name) {}
190 Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
191 : ProxyBase (name, menu_name, node) {}
193 Gtk::Window* get (bool create = false) {
210 return dynamic_cast<T*> (get(true));
213 ARDOUR::SessionHandlePtr* session_handle () {
214 /* may return null */
215 return dynamic_cast<T*> (_window);
219 boost::function<T*()> creator;
224 #endif /* __gtk2_ardour_window_manager_h__ */