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/visibility_tracker.h"
28 #include "ardour_dialog.h"
29 #include "ardour_window.h"
30 #include "window_manager.h"
31 #include "processor_box.h"
39 Manager* Manager::_instance = 0;
45 _instance = new Manager;
51 : current_transient_parent (0)
60 Manager::register_window (ProxyBase* info)
62 _windows.push_back (info);
64 if (!info->menu_name().empty()) {
66 if (!window_actions) {
67 window_actions = Gtk::ActionGroup::create (X_("Window"));
68 ActionManager::add_action_group (window_actions);
71 info->set_action (ActionManager::register_action (window_actions, info->action_name().c_str(), info->menu_name().c_str(),
72 sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info)));
77 Manager::remove (const ProxyBase* info)
79 for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) {
88 Manager::toggle_window (ProxyBase* proxy)
96 Manager::show_visible() const
98 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
99 if ((*i)->visible()) {
100 if (! (*i)->get (true)) {
101 /* the window may be a plugin GUI for a plugin which
102 * is disabled or longer present.
113 Manager::add_state (XMLNode& root) const
115 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
116 /* don't save state for temporary proxy windows
118 if (dynamic_cast<ProxyTemporary*> (*i)) {
121 if (dynamic_cast<ProcessorWindowProxy*> (*i)) {
122 ProcessorWindowProxy *pi = dynamic_cast<ProcessorWindowProxy*> (*i);
123 root.add_child_nocopy (pi->get_state());
125 root.add_child_nocopy ((*i)->get_state());
131 Manager::set_session (ARDOUR::Session* s)
133 SessionHandlePtr::set_session (s);
134 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
135 (*i)->set_session(s);
140 Manager::set_transient_for (Gtk::Window* parent)
142 /* OS X has a richer concept of window layering than X does (or
143 * certainly, than any accepted conventions on X), and so the use of
144 * Manager::set_transient_for() is not necessary on that platform.
146 * On OS X this is mostly taken care of by using the window type rather
147 * than explicit 1:1 transient-for relationships.
152 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
153 Gtk::Window* win = (*i)->get();
155 win->set_transient_for (*parent);
159 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
160 Gtk::Window* win = (*i)->get();
162 gtk_window_set_transient_for (win->gobj(), 0);
167 current_transient_parent = parent;
171 /*-------------------------*/
173 ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name)
174 : WindowProxy (name, menu_name)
178 ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode& node)
179 : WindowProxy (name, menu_name, node)
186 WindowProxy::setup ();
187 set_session(_session);
190 /*-----------------------*/
192 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
193 : ProxyBase (name, string())
198 ProxyTemporary::~ProxyTemporary ()
203 ARDOUR::SessionHandlePtr*
204 ProxyTemporary::session_handle()
206 /* may return null */
207 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
208 if (aw) { return aw; }
209 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
210 if (ad) { return ad; }