2 * Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2013-2018 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <gtkmm/window.h>
22 #include "pbd/xml++.h"
24 #include "ardour/session_handle.h"
26 #include "gtkmm2ext/bindings.h"
27 #include "gtkmm2ext/visibility_tracker.h"
30 #include "ardour_dialog.h"
31 #include "ardour_ui.h"
32 #include "ardour_window.h"
33 #include "window_manager.h"
34 #include "processor_box.h"
42 Manager* Manager::_instance = 0;
48 _instance = new Manager;
54 : current_transient_parent (0)
63 Manager::register_window (ProxyBase* info)
65 _windows.push_back (info);
67 if (!info->menu_name().empty()) {
69 if (!window_actions) {
70 window_actions = ActionManager::create_action_group (Gtkmm2ext::UI::instance()->global_bindings, X_("Window"));
73 ActionManager::register_toggle_action (window_actions,
74 info->action_name().c_str(), info->menu_name().c_str(),
75 sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info));
77 info->signal_map.connect (sigc::bind (sigc::mem_fun (*this, &Manager::window_proxy_was_mapped), info));
78 info->signal_unmap.connect (sigc::bind (sigc::mem_fun (*this, &Manager::window_proxy_was_unmapped), info));
84 Manager::window_proxy_was_mapped (ProxyBase* proxy)
86 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
90 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
95 tact->set_active (true);
99 Manager::window_proxy_was_unmapped (ProxyBase* proxy)
101 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
105 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
110 tact->set_active (false);
114 Manager::remove (const ProxyBase* info)
116 for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) {
125 Manager::toggle_window (ProxyBase* proxy)
127 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
131 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
136 if (tact->get_active()) {
144 Manager::show_visible() const
146 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
147 if ((*i)->visible()) {
148 Gtk::Window* win = (*i)->get (true);
150 /* the window may be a plugin GUI for a plugin which
151 * is disabled or longer present.
155 if (dynamic_cast<ArdourDialog*> (win)) {
156 /* do not show dialogs at startup. Most
157 * dialogs require some signal connection work
158 * because we are trying to avoid recursive
159 * event loops (connecting instead to
160 * ::signal_response(). This means we need to
161 * destroy the window as well, so that the code
162 * which checks if it should be created will
163 * find that it is missing and will create it
164 * and connect to any necessary signals.
166 (*i)->drop_window ();
176 Manager::add_state (XMLNode& root) const
178 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
179 /* don't save state for temporary proxy windows
182 if (dynamic_cast<ProxyTemporary*> (*i)) {
186 root.add_child_nocopy ((*i)->get_state());
191 Manager::set_session (ARDOUR::Session* s)
193 SessionHandlePtr::set_session (s);
194 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
195 (*i)->set_session(s);
200 Manager::set_transient_for (Gtk::Window* parent)
202 /* OS X has a richer concept of window layering than X does (or
203 * certainly, than any accepted conventions on X), and so the use of
204 * Manager::set_transient_for() is not necessary on that platform.
206 * On OS X this is mostly taken care of by using the window type rather
207 * than explicit 1:1 transient-for relationships.
212 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
213 Gtk::Window* win = (*i)->get();
215 win->set_transient_for (*parent);
219 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
220 Gtk::Window* win = (*i)->get();
222 gtk_window_set_transient_for (win->gobj(), 0);
227 current_transient_parent = parent;
231 /*-------------------------*/
233 ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name)
234 : WindowProxy (name, menu_name)
238 ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode& node)
239 : WindowProxy (name, menu_name, node)
246 WindowProxy::setup ();
247 set_session(_session);
251 /*-----------------------*/
253 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
254 : ProxyBase (name, string())
259 ARDOUR::SessionHandlePtr*
260 ProxyTemporary::session_handle()
262 /* may return null */
263 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
264 if (aw) { return aw; }
265 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
266 if (ad) { return ad; }