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)
135 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
136 Gtk::Window* win = (*i)->get();
138 std::cerr << "marked " << win->get_title() << " as transient of " << parent->get_title() << std::endl;
139 win->set_transient_for (*parent);
143 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
144 Gtk::Window* win = (*i)->get();
146 gtk_window_set_transient_for (win->gobj(), 0);
151 current_transient_parent = parent;
155 /*-------------------------*/
157 ProxyBase::ProxyBase (const string& name, const std::string& menu_name)
159 , _menu_name (menu_name)
170 ProxyBase::ProxyBase (const string& name, const std::string& menu_name, const XMLNode& node)
172 , _menu_name (menu_name)
184 ProxyBase::~ProxyBase ()
190 ProxyBase::set_state (const XMLNode& node)
192 XMLNodeList children = node.children ();
194 XMLNodeList::const_iterator i = children.begin ();
196 while (i != children.end()) {
197 XMLProperty* prop = (*i)->property (X_("name"));
198 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
205 if (i != children.end()) {
209 if ((prop = (*i)->property (X_("visible"))) != 0) {
210 _visible = PBD::string_is_affirmative (prop->value ());
213 if ((prop = (*i)->property (X_("x-off"))) != 0) {
214 _x_off = atoi (prop->value().c_str());
216 if ((prop = (*i)->property (X_("y-off"))) != 0) {
217 _y_off = atoi (prop->value().c_str());
219 if ((prop = (*i)->property (X_("x-size"))) != 0) {
220 _width = atoi (prop->value().c_str());
222 if ((prop = (*i)->property (X_("y-size"))) != 0) {
223 _height = atoi (prop->value().c_str());
227 /* if we have a window already, reset its properties */
235 ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
241 ProxyBase::action_name() const
243 return string_compose (X_("toggle-%1"), _name);
252 /* XXX this is a hack - the window object should really
253 ensure its components are all visible. sigh.
256 /* we'd like to just call this and nothing else */
259 vistracker->cycle_visibility ();
264 ProxyBase::get_state () const
266 XMLNode* node = new XMLNode (X_("Window"));
269 node->add_property (X_("name"), _name);
271 if (_window && vistracker) {
273 /* we have a window, so use current state */
275 _visible = vistracker->partially_visible ();
276 _window->get_position (_x_off, _y_off);
277 _window->get_size (_width, _height);
280 node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
282 snprintf (buf, sizeof (buf), "%d", _x_off);
283 node->add_property (X_("x-off"), buf);
284 snprintf (buf, sizeof (buf), "%d", _y_off);
285 node->add_property (X_("y-off"), buf);
286 snprintf (buf, sizeof (buf), "%d", _width);
287 node->add_property (X_("x-size"), buf);
288 snprintf (buf, sizeof (buf), "%d", _height);
289 node->add_property (X_("y-size"), buf);
295 ProxyBase::drop_window ()
307 ProxyBase::use_window (Gtk::Window& win)
319 vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
321 if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
322 /* cancel any mouse-based positioning */
323 _window->set_position (Gtk::WIN_POS_NONE);
326 if (_width != -1 && _height != -1) {
327 _window->set_default_size (_width, _height);
330 if (_x_off != -1 && _y_off != -1) {
331 _window->move (_x_off, _y_off);
338 Gtk::Window* win = get (true);
343 ProxyBase::maybe_show ()
351 ProxyBase::show_all ()
353 Gtk::Window* win = get (true);
359 ProxyBase::present ()
361 Gtk::Window* win = get (true);
365 /* turn off any mouse-based positioning */
366 _window->set_position (Gtk::WIN_POS_NONE);
372 Gtk::Window* win = get (false);
378 /*-----------------------*/
380 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
381 : ProxyBase (name, string())
386 ProxyTemporary::~ProxyTemporary ()
390 ARDOUR::SessionHandlePtr*
391 ProxyTemporary::session_handle()
393 /* may return null */
394 ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
395 if (aw) { return aw; }
396 ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
397 if (ad) { return ad; }