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;
49 static WindowManager& instance();
51 class ProxyBase : public sigc::trackable {
53 ProxyBase (const std::string& name, const std::string& menu_name);
54 ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&);
63 bool visible() const { return _visible; }
64 const std::string& name() const { return _name; }
65 const std::string& menu_name() const { return _menu_name; }
67 std::string action_name() const;
68 void set_action (Glib::RefPtr<Gtk::Action>);
69 Glib::RefPtr<Gtk::Action> action() const { return _action; };
72 void use_window (Gtk::Window&);
74 virtual Gtk::Window* get (bool create = false) = 0;
76 virtual void toggle ();
78 void set_state (const XMLNode&);
79 XMLNode& get_state () const;
81 virtual ARDOUR::SessionHandlePtr* session_handle () = 0;
83 operator bool() const { return _window != 0; }
87 std::string _menu_name;
88 Glib::RefPtr<Gtk::Action> _action;
90 mutable bool _visible; ///< true if the window should be visible on startup
91 mutable int _x_off; ///< x position
92 mutable int _y_off; ///< y position
93 mutable int _width; ///< width
94 mutable int _height; ///< height
95 Gtkmm2ext::VisibilityTracker* vistracker;
101 class ProxyWithConstructor: public ProxyBase {
103 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
104 : ProxyBase (name, menu_name) , creator (c) {}
106 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c, const XMLNode* node)
107 : ProxyBase (name, menu_name, node) , creator (c) {}
109 Gtk::Window* get (bool create = false) {
115 _window = creator ();
126 return dynamic_cast<T*> (get (true));
129 ARDOUR::SessionHandlePtr* session_handle () {
130 /* may return null */
131 return dynamic_cast<T*> (_window);
135 boost::function<T*()> creator;
139 class Proxy : public ProxyBase {
141 Proxy (const std::string& name, const std::string& menu_name)
142 : ProxyBase (name, menu_name) {}
144 Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
145 : ProxyBase (name, menu_name, node) {}
147 Gtk::Window* get (bool create = false) {
164 return dynamic_cast<T*> (get(true));
167 ARDOUR::SessionHandlePtr* session_handle () {
168 /* may return null */
169 return dynamic_cast<T*> (_window);
173 boost::function<T*()> creator;
176 void register_window (ProxyBase*);
177 void remove (const ProxyBase*);
178 void toggle_window (ProxyBase*);
179 void show_visible () const;
180 void set_session (ARDOUR::Session*);
181 void add_state (XMLNode&) const;
184 void set_transient_for (Gtk::Window*);
185 Gtk::Window* transient_parent() const { return current_transient_parent; }
188 typedef std::list<ProxyBase*> Windows;
190 Glib::RefPtr<Gtk::ActionGroup> window_actions;
191 Gtk::Window* current_transient_parent;
196 static WindowManager* _instance;
199 #endif /* __gtk2_ardour_window_manager_h__ */