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 info->set_action (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)));
79 Manager::remove (const ProxyBase* info)
81 for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) {
90 Manager::toggle_window (ProxyBase* proxy)
93 Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
97 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
102 if (tact->get_active()) {
110 Manager::show_visible() const
112 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
113 if ((*i)->visible()) {
114 if (! (*i)->get (true)) {
115 /* the window may be a plugin GUI for a plugin which
116 * is disabled or longer present.
127 Manager::add_state (XMLNode& root) const
129 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
130 /* don't save state for temporary proxy windows
133 if (dynamic_cast<ProxyTemporary*> (*i)) {
137 root.add_child_nocopy ((*i)->get_state());
142 Manager::set_session (ARDOUR::Session* s)
144 SessionHandlePtr::set_session (s);
145 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
146 (*i)->set_session(s);
151 Manager::set_transient_for (Gtk::Window* parent)
153 /* OS X has a richer concept of window layering than X does (or
154 * certainly, than any accepted conventions on X), and so the use of
155 * Manager::set_transient_for() is not necessary on that platform.
157 * On OS X this is mostly taken care of by using the window type rather
158 * than explicit 1:1 transient-for relationships.
163 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
164 Gtk::Window* win = (*i)->get();
166 win->set_transient_for (*parent);
170 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
171 Gtk::Window* win = (*i)->get();
173 gtk_window_set_transient_for (win->gobj(), 0);
178 current_transient_parent = parent;
182 /*-------------------------*/
184 ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name)
185 : WindowProxy (name, menu_name)
189 ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode& node)
190 : WindowProxy (name, menu_name, node)
197 WindowProxy::setup ();
198 set_session(_session);
201 /*-----------------------*/
203 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
204 : ProxyBase (name, string())
209 ProxyTemporary::~ProxyTemporary ()
214 ARDOUR::SessionHandlePtr*
215 ProxyTemporary::session_handle()
217 /* may return null */
218 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
219 if (aw) { return aw; }
220 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
221 if (ad) { return ad; }