2 Copyright (C) 2015 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.
20 #include <gtkmm/action.h>
21 #include <gtkmm/window.h>
23 #include "pbd/convert.h"
24 #include "pbd/xml++.h"
26 #include "gtkmm2ext/window_proxy.h"
27 #include "gtkmm2ext/visibility_tracker.h"
32 using namespace Gtkmm2ext;
35 WindowProxy::WindowProxy (const std::string& name)
47 WindowProxy::WindowProxy (const std::string& name, const std::string& menu_name)
49 , _menu_name (menu_name)
60 WindowProxy::WindowProxy (const std::string& name, const std::string& menu_name, const XMLNode& node)
62 , _menu_name (menu_name)
74 WindowProxy::~WindowProxy ()
81 WindowProxy::set_state (const XMLNode& node, int /* version */)
83 XMLNodeList children = node.children ();
85 XMLNodeList::const_iterator i = children.begin ();
87 while (i != children.end()) {
88 XMLProperty* prop = (*i)->property (X_("name"));
89 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
96 if (i != children.end()) {
100 if ((prop = (*i)->property (X_("visible"))) != 0) {
101 _visible = PBD::string_is_affirmative (prop->value ());
104 if ((prop = (*i)->property (X_("x-off"))) != 0) {
105 _x_off = atoi (prop->value());
107 if ((prop = (*i)->property (X_("y-off"))) != 0) {
108 _y_off = atoi (prop->value());
110 if ((prop = (*i)->property (X_("x-size"))) != 0) {
111 _width = atoi (prop->value());
113 if ((prop = (*i)->property (X_("y-size"))) != 0) {
114 _height = atoi (prop->value());
118 /* if the window is marked visible but doesn't yet exist, create it */
122 _window = get (true);
134 WindowProxy::set_action (Glib::RefPtr<Gtk::Action> act)
140 WindowProxy::action_name() const
142 return string_compose (X_("toggle-%1"), _name);
146 WindowProxy::toggle()
151 /* XXX this is a hack - the window object should really
152 ensure its components are all visible. sigh.
155 /* we'd like to just call this and nothing else */
159 if (_window->is_mapped()) {
162 vistracker->cycle_visibility ();
163 if (_window->is_mapped()) {
164 if (_width != -1 && _height != -1) {
165 _window->set_default_size (_width, _height);
167 if (_x_off != -1 && _y_off != -1) {
168 _window->move (_x_off, _y_off);
175 WindowProxy::get_state ()
177 XMLNode* node = new XMLNode (X_("Window"));
180 node->add_property (X_("name"), _name);
182 if (_window && vistracker) {
184 /* we have a window, so use current state */
186 _visible = vistracker->partially_visible ();
187 _window->get_position (_x_off, _y_off);
188 _window->get_size (_width, _height);
191 node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
192 snprintf (buf, sizeof (buf), "%d", _x_off);
193 node->add_property (X_("x-off"), buf);
194 snprintf (buf, sizeof (buf), "%d", _y_off);
195 node->add_property (X_("y-off"), buf);
196 snprintf (buf, sizeof (buf), "%d", _width);
197 node->add_property (X_("x-size"), buf);
198 snprintf (buf, sizeof (buf), "%d", _height);
199 node->add_property (X_("y-size"), buf);
205 WindowProxy::drop_window ()
217 WindowProxy::use_window (Gtk::Window& win)
225 WindowProxy::setup ()
229 vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
230 _window->signal_delete_event().connect (sigc::mem_fun (*this, &WindowProxy::delete_event_handler));
244 WindowProxy::maybe_show ()
252 WindowProxy::show_all ()
256 _window->show_all ();
260 WindowProxy::present ()
265 _window->show_all ();
268 /* turn off any mouse-based positioning */
269 _window->set_position (Gtk::WIN_POS_NONE);
282 WindowProxy::delete_event_handler (GdkEventAny* /*ev*/)
289 WindowProxy::save_pos_and_size ()
292 _window->get_position (_x_off, _y_off);
293 _window->get_size (_width, _height);
298 WindowProxy::set_pos_and_size ()
304 if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
305 /* cancel any mouse-based positioning */
306 _window->set_position (Gtk::WIN_POS_NONE);
309 if (_width != -1 && _height != -1) {
310 _window->set_default_size (_width, _height);
313 if (_x_off != -1 && _y_off != -1) {
314 _window->move (_x_off, _y_off);