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)
56 Manager::register_window (ProxyBase* info)
58 _windows.push_back (info);
60 if (!info->menu_name().empty()) {
62 if (!window_actions) {
63 window_actions = Gtk::ActionGroup::create (X_("Window"));
64 ActionManager::add_action_group (window_actions);
67 info->set_action (ActionManager::register_action (window_actions, info->action_name().c_str(), info->menu_name().c_str(),
68 sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info)));
73 Manager::remove (const ProxyBase* info)
75 for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) {
84 Manager::toggle_window (ProxyBase* proxy)
92 Manager::show_visible() const
94 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
95 if ((*i)->visible()) {
103 Manager::add_state (XMLNode& root) const
105 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
106 /* don't save state for temporary proxy windows
108 if (dynamic_cast<ProxyTemporary*> (*i)) {
111 if (dynamic_cast<ProcessorWindowProxy*> (*i)) {
112 ProcessorWindowProxy *pi = dynamic_cast<ProcessorWindowProxy*> (*i);
113 root.add_child_nocopy (pi->get_state());
115 root.add_child_nocopy ((*i)->get_state());
121 Manager::set_session (ARDOUR::Session* s)
123 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
124 ARDOUR::SessionHandlePtr* sp = (*i)->session_handle ();
132 Manager::set_transient_for (Gtk::Window* parent)
134 /* OS X has a richer concept of window layering than X does (or
135 * certainly, than any accepted conventions on X), and so the use of
136 * Manager::set_transient_for() is not necessary on that platform.
138 * On OS X this is mostly taken care of by using the window type rather
139 * than explicit 1:1 transient-for relationships.
144 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
145 Gtk::Window* win = (*i)->get();
147 win->set_transient_for (*parent);
151 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
152 Gtk::Window* win = (*i)->get();
154 gtk_window_set_transient_for (win->gobj(), 0);
159 current_transient_parent = parent;
163 /*-------------------------*/
165 ProxyBase::ProxyBase (const string& name, const std::string& menu_name)
167 , _menu_name (menu_name)
178 ProxyBase::ProxyBase (const string& name, const std::string& menu_name, const XMLNode& node)
180 , _menu_name (menu_name)
192 ProxyBase::~ProxyBase ()
198 ProxyBase::set_state (const XMLNode& node)
200 XMLNodeList children = node.children ();
202 XMLNodeList::const_iterator i = children.begin ();
204 while (i != children.end()) {
205 XMLProperty* prop = (*i)->property (X_("name"));
206 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
213 if (i != children.end()) {
217 if ((prop = (*i)->property (X_("visible"))) != 0) {
218 _visible = PBD::string_is_affirmative (prop->value ());
221 if ((prop = (*i)->property (X_("x-off"))) != 0) {
222 _x_off = atoi (prop->value());
224 if ((prop = (*i)->property (X_("y-off"))) != 0) {
225 _y_off = atoi (prop->value());
227 if ((prop = (*i)->property (X_("x-size"))) != 0) {
228 _width = atoi (prop->value());
230 if ((prop = (*i)->property (X_("y-size"))) != 0) {
231 _height = atoi (prop->value());
235 /* if we have a window already, reset its properties */
243 ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
249 ProxyBase::action_name() const
251 return string_compose (X_("toggle-%1"), _name);
260 /* XXX this is a hack - the window object should really
261 ensure its components are all visible. sigh.
264 /* we'd like to just call this and nothing else */
267 vistracker->cycle_visibility ();
272 ProxyBase::get_state () const
274 XMLNode* node = new XMLNode (X_("Window"));
277 node->add_property (X_("name"), _name);
279 if (_window && vistracker) {
281 /* we have a window, so use current state */
283 _visible = vistracker->partially_visible ();
284 _window->get_position (_x_off, _y_off);
285 _window->get_size (_width, _height);
288 node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
290 snprintf (buf, sizeof (buf), "%d", _x_off);
291 node->add_property (X_("x-off"), buf);
292 snprintf (buf, sizeof (buf), "%d", _y_off);
293 node->add_property (X_("y-off"), buf);
294 snprintf (buf, sizeof (buf), "%d", _width);
295 node->add_property (X_("x-size"), buf);
296 snprintf (buf, sizeof (buf), "%d", _height);
297 node->add_property (X_("y-size"), buf);
303 ProxyBase::drop_window ()
315 ProxyBase::use_window (Gtk::Window& win)
327 vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
329 if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
330 /* cancel any mouse-based positioning */
331 _window->set_position (Gtk::WIN_POS_NONE);
334 if (_width != -1 && _height != -1) {
335 _window->set_default_size (_width, _height);
338 if (_x_off != -1 && _y_off != -1) {
339 _window->move (_x_off, _y_off);
346 Gtk::Window* win = get (true);
351 ProxyBase::maybe_show ()
359 ProxyBase::show_all ()
361 Gtk::Window* win = get (true);
367 ProxyBase::present ()
369 Gtk::Window* win = get (true);
373 /* turn off any mouse-based positioning */
374 _window->set_position (Gtk::WIN_POS_NONE);
380 Gtk::Window* win = get (false);
386 /*-----------------------*/
388 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
389 : ProxyBase (name, string())
394 ProxyTemporary::~ProxyTemporary ()
398 ARDOUR::SessionHandlePtr*
399 ProxyTemporary::session_handle()
401 /* may return null */
402 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
403 if (aw) { return aw; }
404 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
405 if (ad) { return ad; }