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 ()
200 ProxyBase::set_state (const XMLNode& node)
202 XMLNodeList children = node.children ();
204 XMLNodeList::const_iterator i = children.begin ();
206 while (i != children.end()) {
207 XMLProperty* prop = (*i)->property (X_("name"));
208 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
215 if (i != children.end()) {
219 if ((prop = (*i)->property (X_("visible"))) != 0) {
220 _visible = PBD::string_is_affirmative (prop->value ());
223 if ((prop = (*i)->property (X_("x-off"))) != 0) {
224 _x_off = atoi (prop->value());
226 if ((prop = (*i)->property (X_("y-off"))) != 0) {
227 _y_off = atoi (prop->value());
229 if ((prop = (*i)->property (X_("x-size"))) != 0) {
230 _width = atoi (prop->value());
232 if ((prop = (*i)->property (X_("y-size"))) != 0) {
233 _height = atoi (prop->value());
237 /* if we have a window already, reset its properties */
245 ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
251 ProxyBase::action_name() const
253 return string_compose (X_("toggle-%1"), _name);
262 /* XXX this is a hack - the window object should really
263 ensure its components are all visible. sigh.
266 /* we'd like to just call this and nothing else */
269 if (_width != -1 && _height != -1) {
270 _window->set_default_size (_width, _height);
272 if (_x_off != -1 && _y_off != -1) {
273 _window->move (_x_off, _y_off);
277 if (_window->is_mapped()) {
280 vistracker->cycle_visibility ();
281 if (_window->is_mapped()) {
282 if (_width != -1 && _height != -1) {
283 _window->set_default_size (_width, _height);
285 if (_x_off != -1 && _y_off != -1) {
286 _window->move (_x_off, _y_off);
293 ProxyBase::get_state () const
295 XMLNode* node = new XMLNode (X_("Window"));
298 node->add_property (X_("name"), _name);
300 if (_window && vistracker) {
302 /* we have a window, so use current state */
304 _visible = vistracker->partially_visible ();
306 _window->get_position (_x_off, _y_off);
307 _window->get_size (_width, _height);
311 node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
313 snprintf (buf, sizeof (buf), "%d", _x_off);
314 node->add_property (X_("x-off"), buf);
315 snprintf (buf, sizeof (buf), "%d", _y_off);
316 node->add_property (X_("y-off"), buf);
317 snprintf (buf, sizeof (buf), "%d", _width);
318 node->add_property (X_("x-size"), buf);
319 snprintf (buf, sizeof (buf), "%d", _height);
320 node->add_property (X_("y-size"), buf);
326 ProxyBase::drop_window ()
338 ProxyBase::use_window (Gtk::Window& win)
350 vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
351 _window->signal_delete_event().connect (sigc::mem_fun (*this, &ProxyBase::handle_win_event));
353 if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
354 /* cancel any mouse-based positioning */
355 _window->set_position (Gtk::WIN_POS_NONE);
358 if (_width != -1 && _height != -1) {
359 _window->set_default_size (_width, _height);
362 if (_x_off != -1 && _y_off != -1) {
363 _window->move (_x_off, _y_off);
365 set_session(_session);
371 Gtk::Window* win = get (true);
376 ProxyBase::maybe_show ()
384 ProxyBase::show_all ()
386 Gtk::Window* win = get (true);
392 ProxyBase::present ()
394 Gtk::Window* win = get (true);
398 /* turn off any mouse-based positioning */
399 _window->set_position (Gtk::WIN_POS_NONE);
405 Gtk::Window* win = get (false);
413 ProxyBase::handle_win_event (GdkEventAny *ev)
420 ProxyBase::save_pos_and_size ()
422 Gtk::Window* win = get (false);
424 win->get_position (_x_off, _y_off);
425 win->get_size (_width, _height);
428 /*-----------------------*/
430 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
431 : ProxyBase (name, string())
436 ProxyTemporary::~ProxyTemporary ()
441 ARDOUR::SessionHandlePtr*
442 ProxyTemporary::session_handle()
444 /* may return null */
445 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
446 if (aw) { return aw; }
447 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
448 if (ad) { return ad; }