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 string& name, const std::string& menu_name)
175 , _menu_name (menu_name)
186 ProxyBase::ProxyBase (const string& name, const std::string& menu_name, const XMLNode& node)
188 , _menu_name (menu_name)
200 ProxyBase::~ProxyBase ()
207 ProxyBase::set_state (const XMLNode& node)
209 XMLNodeList children = node.children ();
211 XMLNodeList::const_iterator i = children.begin ();
213 while (i != children.end()) {
214 XMLProperty* prop = (*i)->property (X_("name"));
215 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
222 if (i != children.end()) {
226 if ((prop = (*i)->property (X_("visible"))) != 0) {
227 _visible = PBD::string_is_affirmative (prop->value ());
230 if ((prop = (*i)->property (X_("x-off"))) != 0) {
231 _x_off = atoi (prop->value());
233 if ((prop = (*i)->property (X_("y-off"))) != 0) {
234 _y_off = atoi (prop->value());
236 if ((prop = (*i)->property (X_("x-size"))) != 0) {
237 _width = atoi (prop->value());
239 if ((prop = (*i)->property (X_("y-size"))) != 0) {
240 _height = atoi (prop->value());
244 /* if we have a window already, reset its properties */
252 ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
258 ProxyBase::action_name() const
260 return string_compose (X_("toggle-%1"), _name);
269 /* XXX this is a hack - the window object should really
270 ensure its components are all visible. sigh.
273 /* we'd like to just call this and nothing else */
276 if (_width != -1 && _height != -1) {
277 _window->set_default_size (_width, _height);
279 if (_x_off != -1 && _y_off != -1) {
280 _window->move (_x_off, _y_off);
284 if (_window->is_mapped()) {
287 vistracker->cycle_visibility ();
288 if (_window->is_mapped()) {
289 if (_width != -1 && _height != -1) {
290 _window->set_default_size (_width, _height);
292 if (_x_off != -1 && _y_off != -1) {
293 _window->move (_x_off, _y_off);
300 ProxyBase::get_state () const
302 XMLNode* node = new XMLNode (X_("Window"));
305 node->add_property (X_("name"), _name);
307 if (_window && vistracker) {
309 /* we have a window, so use current state */
311 _visible = vistracker->partially_visible ();
313 _window->get_position (_x_off, _y_off);
314 _window->get_size (_width, _height);
318 node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
320 snprintf (buf, sizeof (buf), "%d", _x_off);
321 node->add_property (X_("x-off"), buf);
322 snprintf (buf, sizeof (buf), "%d", _y_off);
323 node->add_property (X_("y-off"), buf);
324 snprintf (buf, sizeof (buf), "%d", _width);
325 node->add_property (X_("x-size"), buf);
326 snprintf (buf, sizeof (buf), "%d", _height);
327 node->add_property (X_("y-size"), buf);
333 ProxyBase::drop_window ()
345 ProxyBase::use_window (Gtk::Window& win)
357 vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
358 _window->signal_delete_event().connect (sigc::mem_fun (*this, &ProxyBase::delete_event_handler));
360 if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
361 /* cancel any mouse-based positioning */
362 _window->set_position (Gtk::WIN_POS_NONE);
365 if (_width != -1 && _height != -1) {
366 _window->set_default_size (_width, _height);
369 if (_x_off != -1 && _y_off != -1) {
370 _window->move (_x_off, _y_off);
372 set_session(_session);
384 ProxyBase::maybe_show ()
392 ProxyBase::show_all ()
396 _window->show_all ();
400 ProxyBase::present ()
405 _window->show_all ();
408 /* turn off any mouse-based positioning */
409 _window->set_position (Gtk::WIN_POS_NONE);
422 ProxyBase::delete_event_handler (GdkEventAny* /*ev*/)
429 ProxyBase::save_pos_and_size ()
432 _window->get_position (_x_off, _y_off);
433 _window->get_size (_width, _height);
436 /*-----------------------*/
438 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
439 : ProxyBase (name, string())
444 ProxyTemporary::~ProxyTemporary ()
449 ARDOUR::SessionHandlePtr*
450 ProxyTemporary::session_handle()
452 /* may return null */
453 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
454 if (aw) { return aw; }
455 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
456 if (ad) { return ad; }