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()) {
107 Manager::add_state (XMLNode& root) const
109 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
110 /* don't save state for temporary proxy windows
112 if (dynamic_cast<ProxyTemporary*> (*i)) {
115 if (dynamic_cast<ProcessorWindowProxy*> (*i)) {
116 ProcessorWindowProxy *pi = dynamic_cast<ProcessorWindowProxy*> (*i);
117 root.add_child_nocopy (pi->get_state());
119 root.add_child_nocopy ((*i)->get_state());
125 Manager::set_session (ARDOUR::Session* s)
127 SessionHandlePtr::set_session (s);
128 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
129 (*i)->set_session(s);
134 Manager::set_transient_for (Gtk::Window* parent)
136 /* OS X has a richer concept of window layering than X does (or
137 * certainly, than any accepted conventions on X), and so the use of
138 * Manager::set_transient_for() is not necessary on that platform.
140 * On OS X this is mostly taken care of by using the window type rather
141 * than explicit 1:1 transient-for relationships.
146 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
147 Gtk::Window* win = (*i)->get();
149 win->set_transient_for (*parent);
153 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
154 Gtk::Window* win = (*i)->get();
156 gtk_window_set_transient_for (win->gobj(), 0);
161 current_transient_parent = parent;
165 /*-------------------------*/
167 ProxyBase::ProxyBase (const string& name, const std::string& menu_name)
169 , _menu_name (menu_name)
180 ProxyBase::ProxyBase (const string& name, const std::string& menu_name, const XMLNode& node)
182 , _menu_name (menu_name)
194 ProxyBase::~ProxyBase ()
201 ProxyBase::set_state (const XMLNode& node)
203 XMLNodeList children = node.children ();
205 XMLNodeList::const_iterator i = children.begin ();
207 while (i != children.end()) {
208 XMLProperty* prop = (*i)->property (X_("name"));
209 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
216 if (i != children.end()) {
220 if ((prop = (*i)->property (X_("visible"))) != 0) {
221 _visible = PBD::string_is_affirmative (prop->value ());
224 if ((prop = (*i)->property (X_("x-off"))) != 0) {
225 _x_off = atoi (prop->value());
227 if ((prop = (*i)->property (X_("y-off"))) != 0) {
228 _y_off = atoi (prop->value());
230 if ((prop = (*i)->property (X_("x-size"))) != 0) {
231 _width = atoi (prop->value());
233 if ((prop = (*i)->property (X_("y-size"))) != 0) {
234 _height = atoi (prop->value());
238 /* if we have a window already, reset its properties */
246 ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
252 ProxyBase::action_name() const
254 return string_compose (X_("toggle-%1"), _name);
263 /* XXX this is a hack - the window object should really
264 ensure its components are all visible. sigh.
267 /* we'd like to just call this and nothing else */
270 if (_width != -1 && _height != -1) {
271 _window->set_default_size (_width, _height);
273 if (_x_off != -1 && _y_off != -1) {
274 _window->move (_x_off, _y_off);
278 if (_window->is_mapped()) {
281 vistracker->cycle_visibility ();
282 if (_window->is_mapped()) {
283 if (_width != -1 && _height != -1) {
284 _window->set_default_size (_width, _height);
286 if (_x_off != -1 && _y_off != -1) {
287 _window->move (_x_off, _y_off);
294 ProxyBase::get_state () const
296 XMLNode* node = new XMLNode (X_("Window"));
299 node->add_property (X_("name"), _name);
301 if (_window && vistracker) {
303 /* we have a window, so use current state */
305 _visible = vistracker->partially_visible ();
307 _window->get_position (_x_off, _y_off);
308 _window->get_size (_width, _height);
312 node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
314 snprintf (buf, sizeof (buf), "%d", _x_off);
315 node->add_property (X_("x-off"), buf);
316 snprintf (buf, sizeof (buf), "%d", _y_off);
317 node->add_property (X_("y-off"), buf);
318 snprintf (buf, sizeof (buf), "%d", _width);
319 node->add_property (X_("x-size"), buf);
320 snprintf (buf, sizeof (buf), "%d", _height);
321 node->add_property (X_("y-size"), buf);
327 ProxyBase::drop_window ()
339 ProxyBase::use_window (Gtk::Window& win)
351 vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
352 _window->signal_delete_event().connect (sigc::mem_fun (*this, &ProxyBase::delete_event_handler));
354 if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
355 /* cancel any mouse-based positioning */
356 _window->set_position (Gtk::WIN_POS_NONE);
359 if (_width != -1 && _height != -1) {
360 _window->set_default_size (_width, _height);
363 if (_x_off != -1 && _y_off != -1) {
364 _window->move (_x_off, _y_off);
366 set_session(_session);
378 ProxyBase::maybe_show ()
386 ProxyBase::show_all ()
390 _window->show_all ();
394 ProxyBase::present ()
399 _window->show_all ();
402 /* turn off any mouse-based positioning */
403 _window->set_position (Gtk::WIN_POS_NONE);
416 ProxyBase::delete_event_handler (GdkEventAny* /*ev*/)
423 ProxyBase::save_pos_and_size ()
426 _window->get_position (_x_off, _y_off);
427 _window->get_size (_width, _height);
430 /*-----------------------*/
432 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
433 : ProxyBase (name, string())
438 ProxyTemporary::~ProxyTemporary ()
443 ARDOUR::SessionHandlePtr*
444 ProxyTemporary::session_handle()
446 /* may return null */
447 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
448 if (aw) { return aw; }
449 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
450 if (ad) { return ad; }