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 bool rc_configured() const { return true; }
77 virtual void toggle ();
79 void set_state (const XMLNode&);
80 XMLNode& get_state () const;
82 virtual ARDOUR::SessionHandlePtr* session_handle () = 0;
84 operator bool() const { return _window != 0; }
88 std::string _menu_name;
89 Glib::RefPtr<Gtk::Action> _action;
91 bool _visible; ///< true if the window should be visible on startup
92 int _x_off; ///< x position
93 int _y_off; ///< y position
94 int _width; ///< width
95 int _height; ///< height
96 Gtkmm2ext::VisibilityTracker* vistracker;
97 sigc::connection configure_connection;
100 bool configured (GdkEventConfigure*);
104 class ProxyWithConstructor: public ProxyBase {
106 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
107 : ProxyBase (name, menu_name) , creator (c) {}
109 ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c, const XMLNode* node)
110 : ProxyBase (name, menu_name, node) , creator (c) {}
112 Gtk::Window* get (bool create = false) {
118 _window = creator ();
129 return dynamic_cast<T*> (get (true));
132 ARDOUR::SessionHandlePtr* session_handle () {
133 /* may return null */
134 return dynamic_cast<T*> (_window);
138 boost::function<T*()> creator;
142 class Proxy : public ProxyBase {
144 Proxy (const std::string& name, const std::string& menu_name)
145 : ProxyBase (name, menu_name) {}
147 Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
148 : ProxyBase (name, menu_name, node) {}
150 Gtk::Window* get (bool create = false) {
167 /* make return null */
168 return dynamic_cast<T*> (_window);
171 ARDOUR::SessionHandlePtr* session_handle () {
172 return dynamic_cast<T*> (get());
176 boost::function<T*()> creator;
179 void register_window (ProxyBase*);
180 void remove (const ProxyBase*);
181 void toggle_window (ProxyBase*);
182 void show_visible () const;
183 void set_session (ARDOUR::Session*);
184 void add_state (XMLNode&) const;
187 typedef std::list<ProxyBase*> Windows;
189 Glib::RefPtr<Gtk::ActionGroup> window_actions;
194 static WindowManager* _instance;
197 #endif /* __gtk2_ardour_window_manager_h__ */