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 "window_manager.h"
34 WindowManager* WindowManager::_instance = 0;
37 WindowManager::instance ()
40 _instance = new WindowManager;
45 WindowManager::WindowManager ()
50 WindowManager::register_window (ProxyBase* info)
52 _windows.push_back (info);
54 if (!info->menu_name().empty()) {
56 if (!window_actions) {
57 window_actions = Gtk::ActionGroup::create (X_("Window"));
58 ActionManager::add_action_group (window_actions);
61 info->set_action (ActionManager::register_action (window_actions, info->action_name().c_str(), info->menu_name().c_str(),
62 sigc::bind (sigc::mem_fun (*this, &WindowManager::toggle_window), info)));
67 WindowManager::remove (const ProxyBase* info)
69 for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) {
78 WindowManager::toggle_window (ProxyBase* proxy)
86 WindowManager::show_visible() const
88 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
89 if ((*i)->visible()) {
97 WindowManager::add_state (XMLNode& root) const
99 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
100 root.add_child_nocopy ((*i)->get_state());
105 WindowManager::set_session (ARDOUR::Session* s)
107 for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
108 ARDOUR::SessionHandlePtr* sp = (*i)->session_handle ();
115 /*-----------------------*/
117 WindowManager::ProxyBase::ProxyBase (const string& name, const std::string& menu_name)
119 , _menu_name (menu_name)
130 WindowManager::ProxyBase::ProxyBase (const string& name, const std::string& menu_name, const XMLNode& node)
132 , _menu_name (menu_name)
144 WindowManager::ProxyBase::~ProxyBase ()
150 WindowManager::ProxyBase::set_state (const XMLNode& node)
152 XMLNodeList children = node.children ();
154 XMLNodeList::const_iterator i = children.begin ();
156 while (i != children.end()) {
157 XMLProperty* prop = (*i)->property (X_("name"));
158 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
165 if (i != children.end()) {
169 if ((prop = (*i)->property (X_("visible"))) != 0) {
170 _visible = PBD::string_is_affirmative (prop->value ());
173 if ((prop = (*i)->property (X_("x-off"))) != 0) {
174 _x_off = atoi (prop->value().c_str());
176 if ((prop = (*i)->property (X_("y-off"))) != 0) {
177 _y_off = atoi (prop->value().c_str());
179 if ((prop = (*i)->property (X_("x-size"))) != 0) {
180 _width = atoi (prop->value().c_str());
182 if ((prop = (*i)->property (X_("y-size"))) != 0) {
183 _height = atoi (prop->value().c_str());
187 /* if we have a window already, reset its properties */
195 WindowManager::ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
201 WindowManager::ProxyBase::action_name() const
203 return string_compose (X_("toggle-%1"), _name);
207 WindowManager::ProxyBase::toggle()
212 /* XXX this is a hack - the window object should really
213 ensure its components are all visible. sigh.
216 /* we'd like to just call this and nothing else */
219 vistracker->cycle_visibility ();
224 WindowManager::ProxyBase::get_state () const
226 XMLNode* node = new XMLNode (X_("Window"));
229 node->add_property (X_("name"), _name);
231 if (_window && vistracker) {
233 /* we have a window, so use current state */
235 _visible = vistracker->partially_visible ();
236 _window->get_position (_x_off, _y_off);
237 _window->get_size (_width, _height);
240 node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
242 snprintf (buf, sizeof (buf), "%d", _x_off);
243 node->add_property (X_("x-off"), buf);
244 snprintf (buf, sizeof (buf), "%d", _y_off);
245 node->add_property (X_("y-off"), buf);
246 snprintf (buf, sizeof (buf), "%d", _width);
247 node->add_property (X_("x-size"), buf);
248 snprintf (buf, sizeof (buf), "%d", _height);
249 node->add_property (X_("y-size"), buf);
255 WindowManager::ProxyBase::drop_window ()
267 WindowManager::ProxyBase::use_window (Gtk::Window& win)
275 WindowManager::ProxyBase::setup ()
279 vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
281 if (_width != -1 && _height != -1) {
282 _window->set_default_size (_width, _height);
285 if (_x_off != -1 && _y_off != -1) {
286 _window->move (_x_off, _y_off);
291 WindowManager::ProxyBase::show ()
293 Gtk::Window* win = get (true);
298 WindowManager::ProxyBase::maybe_show ()
306 WindowManager::ProxyBase::show_all ()
308 Gtk::Window* win = get (true);
314 WindowManager::ProxyBase::present ()
316 Gtk::Window* win = get (true);
322 WindowManager::ProxyBase::hide ()
324 Gtk::Window* win = get (false);