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.
19 #include <gtkmm/window.h>
21 #include "pbd/xml++.h"
23 #include "ardour/session_handle.h"
25 #include "gtkmm2ext/bindings.h"
26 #include "gtkmm2ext/visibility_tracker.h"
29 #include "ardour_dialog.h"
30 #include "ardour_ui.h"
31 #include "ardour_window.h"
32 #include "window_manager.h"
33 #include "processor_box.h"
41 Manager* Manager::_instance = 0;
47 _instance = new Manager;
53 : current_transient_parent (0)
62 Manager::register_window (ProxyBase* info)
64 _windows.push_back (info);
66 if (!info->menu_name().empty()) {
68 if (!window_actions) {
69 window_actions = ARDOUR_UI::instance()->global_actions.create_action_group (X_("Window"));
72 ARDOUR_UI::instance()->global_actions.register_toggle_action (window_actions,
73 info->action_name().c_str(), info->menu_name().c_str(),
74 sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info));
76 info->signal_map.connect (sigc::bind (sigc::mem_fun (*this, &Manager::window_proxy_was_mapped), info));
77 info->signal_unmap.connect (sigc::bind (sigc::mem_fun (*this, &Manager::window_proxy_was_unmapped), info));
83 Manager::window_proxy_was_mapped (ProxyBase* proxy)
85 Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
89 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
94 tact->set_active (true);
98 Manager::window_proxy_was_unmapped (ProxyBase* proxy)
100 Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
104 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
109 tact->set_active (false);
113 Manager::remove (const ProxyBase* info)
115 for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) {
124 Manager::toggle_window (ProxyBase* proxy)
126 Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
130 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
135 if (tact->get_active()) {
143 Manager::show_visible() const
145 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
146 if ((*i)->visible()) {
147 Gtk::Window* win = (*i)->get (true);
149 /* the window may be a plugin GUI for a plugin which
150 * is disabled or longer present.
154 if (dynamic_cast<ArdourDialog*> (win)) {
155 /* do not show dialogs at startup. Most
156 * dialogs require some signal connection work
157 * because we are trying to avoid recursive
158 * event loops (connecting instead to
159 * ::signal_response(). This means we need to
160 * destroy the window as well, so that the code
161 * which checks if it should be created will
162 * find that it is missing and will create it
163 * and connect to any necessary signals.
165 (*i)->drop_window ();
175 Manager::add_state (XMLNode& root) const
177 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
178 /* don't save state for temporary proxy windows
181 if (dynamic_cast<ProxyTemporary*> (*i)) {
185 root.add_child_nocopy ((*i)->get_state());
190 Manager::set_session (ARDOUR::Session* s)
192 SessionHandlePtr::set_session (s);
193 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
194 (*i)->set_session(s);
199 Manager::set_transient_for (Gtk::Window* parent)
201 /* OS X has a richer concept of window layering than X does (or
202 * certainly, than any accepted conventions on X), and so the use of
203 * Manager::set_transient_for() is not necessary on that platform.
205 * On OS X this is mostly taken care of by using the window type rather
206 * than explicit 1:1 transient-for relationships.
211 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
212 Gtk::Window* win = (*i)->get();
214 win->set_transient_for (*parent);
218 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
219 Gtk::Window* win = (*i)->get();
221 gtk_window_set_transient_for (win->gobj(), 0);
226 current_transient_parent = parent;
230 /*-------------------------*/
232 ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name)
233 : WindowProxy (name, menu_name)
237 ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode& node)
238 : WindowProxy (name, menu_name, node)
245 WindowProxy::setup ();
246 set_session(_session);
250 /*-----------------------*/
252 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
253 : ProxyBase (name, string())
258 ProxyTemporary::~ProxyTemporary ()
263 ARDOUR::SessionHandlePtr*
264 ProxyTemporary::session_handle()
266 /* may return null */
267 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
268 if (aw) { return aw; }
269 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
270 if (ad) { return ad; }