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"
38 Manager* Manager::_instance = 0;
44 _instance = new Manager;
50 : current_transient_parent (0)
55 Manager::register_window (ProxyBase* info)
57 _windows.push_back (info);
59 if (!info->menu_name().empty()) {
61 if (!window_actions) {
62 window_actions = Gtk::ActionGroup::create (X_("Window"));
63 ActionManager::add_action_group (window_actions);
66 info->set_action (ActionManager::register_action (window_actions, info->action_name().c_str(), info->menu_name().c_str(),
67 sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info)));
72 Manager::remove (const ProxyBase* info)
74 for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) {
83 Manager::toggle_window (ProxyBase* proxy)
91 Manager::show_visible() const
93 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
94 if ((*i)->visible()) {
102 Manager::add_state (XMLNode& root) const
104 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
105 /* don't save state for temporary proxy windows
107 if (dynamic_cast<ProxyTemporary*> (*i)) {
110 if (dynamic_cast<ProcessorWindowProxy*> (*i)) {
111 ProcessorWindowProxy *pi = dynamic_cast<ProcessorWindowProxy*> (*i);
112 root.add_child_nocopy (pi->get_state());
114 root.add_child_nocopy ((*i)->get_state());
120 Manager::set_session (ARDOUR::Session* s)
122 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
123 ARDOUR::SessionHandlePtr* sp = (*i)->session_handle ();
131 Manager::set_transient_for (Gtk::Window* parent)
133 /* OS X has a richer concept of window layering than X does (or
134 * certainly, than any accepted conventions on X), and so the use of
135 * Manager::set_transient_for() is not necessary on that platform.
137 * On OS X this is mostly taken care of by using the window type rather
138 * than explicit 1:1 transient-for relationships.
143 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
144 Gtk::Window* win = (*i)->get();
146 win->set_transient_for (*parent);
150 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
151 Gtk::Window* win = (*i)->get();
153 gtk_window_set_transient_for (win->gobj(), 0);
158 current_transient_parent = parent;
162 /*-------------------------*/
164 ProxyBase::ProxyBase (const string& name, const std::string& menu_name)
166 , _menu_name (menu_name)
177 ProxyBase::ProxyBase (const string& name, const std::string& menu_name, const XMLNode& node)
179 , _menu_name (menu_name)
191 ProxyBase::~ProxyBase ()
197 ProxyBase::set_state (const XMLNode& node)
199 XMLNodeList children = node.children ();
201 XMLNodeList::const_iterator i = children.begin ();
203 while (i != children.end()) {
204 XMLProperty* prop = (*i)->property (X_("name"));
205 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
212 if (i != children.end()) {
216 if ((prop = (*i)->property (X_("visible"))) != 0) {
217 _visible = PBD::string_is_affirmative (prop->value ());
220 if ((prop = (*i)->property (X_("x-off"))) != 0) {
221 _x_off = atoi (prop->value().c_str());
223 if ((prop = (*i)->property (X_("y-off"))) != 0) {
224 _y_off = atoi (prop->value().c_str());
226 if ((prop = (*i)->property (X_("x-size"))) != 0) {
227 _width = atoi (prop->value().c_str());
229 if ((prop = (*i)->property (X_("y-size"))) != 0) {
230 _height = atoi (prop->value().c_str());
234 /* if we have a window already, reset its properties */
242 ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
248 ProxyBase::action_name() const
250 return string_compose (X_("toggle-%1"), _name);
259 /* XXX this is a hack - the window object should really
260 ensure its components are all visible. sigh.
263 /* we'd like to just call this and nothing else */
266 vistracker->cycle_visibility ();
271 ProxyBase::get_state () const
273 XMLNode* node = new XMLNode (X_("Window"));
276 node->add_property (X_("name"), _name);
278 if (_window && vistracker) {
280 /* we have a window, so use current state */
282 _visible = vistracker->partially_visible ();
283 _window->get_position (_x_off, _y_off);
284 _window->get_size (_width, _height);
287 node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
289 snprintf (buf, sizeof (buf), "%d", _x_off);
290 node->add_property (X_("x-off"), buf);
291 snprintf (buf, sizeof (buf), "%d", _y_off);
292 node->add_property (X_("y-off"), buf);
293 snprintf (buf, sizeof (buf), "%d", _width);
294 node->add_property (X_("x-size"), buf);
295 snprintf (buf, sizeof (buf), "%d", _height);
296 node->add_property (X_("y-size"), buf);
302 ProxyBase::drop_window ()
314 ProxyBase::use_window (Gtk::Window& win)
326 vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
328 if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
329 /* cancel any mouse-based positioning */
330 _window->set_position (Gtk::WIN_POS_NONE);
333 if (_width != -1 && _height != -1) {
334 _window->set_default_size (_width, _height);
337 if (_x_off != -1 && _y_off != -1) {
338 _window->move (_x_off, _y_off);
345 Gtk::Window* win = get (true);
350 ProxyBase::maybe_show ()
358 ProxyBase::show_all ()
360 Gtk::Window* win = get (true);
366 ProxyBase::present ()
368 Gtk::Window* win = get (true);
372 /* turn off any mouse-based positioning */
373 _window->set_position (Gtk::WIN_POS_NONE);
379 Gtk::Window* win = get (false);
385 /*-----------------------*/
387 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
388 : ProxyBase (name, string())
393 ProxyTemporary::~ProxyTemporary ()
397 ARDOUR::SessionHandlePtr*
398 ProxyTemporary::session_handle()
400 /* may return null */
401 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
402 if (aw) { return aw; }
403 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
404 if (ad) { return ad; }