2015-07-01 17:26:14 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2015 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtkmm/action.h>
|
|
|
|
#include <gtkmm/window.h>
|
|
|
|
|
|
|
|
#include "pbd/convert.h"
|
|
|
|
#include "pbd/xml++.h"
|
2015-08-04 14:30:41 -04:00
|
|
|
#include "pbd/stacktrace.h"
|
2015-07-01 17:26:14 -04:00
|
|
|
|
|
|
|
#include "gtkmm2ext/window_proxy.h"
|
|
|
|
#include "gtkmm2ext/visibility_tracker.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2015-07-01 17:26:14 -04:00
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace PBD;
|
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
WindowProxy::WindowProxy (const std::string& name)
|
|
|
|
: _name (name)
|
|
|
|
, _window (0)
|
2015-07-03 15:06:59 -04:00
|
|
|
, _visible (false)
|
|
|
|
, _x_off (-1)
|
|
|
|
, _y_off (-1)
|
|
|
|
, _width (-1)
|
2015-10-26 14:35:06 -04:00
|
|
|
, _height (-1)
|
2015-07-03 15:06:59 -04:00
|
|
|
, vistracker (0)
|
2016-04-27 00:01:13 -04:00
|
|
|
, _state_mask (StateMask (Position|Size))
|
2015-07-03 15:06:59 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-01 17:26:14 -04:00
|
|
|
WindowProxy::WindowProxy (const std::string& name, const std::string& menu_name)
|
|
|
|
: _name (name)
|
|
|
|
, _menu_name (menu_name)
|
|
|
|
, _window (0)
|
|
|
|
, _visible (false)
|
|
|
|
, _x_off (-1)
|
|
|
|
, _y_off (-1)
|
|
|
|
, _width (-1)
|
2015-10-26 14:35:06 -04:00
|
|
|
, _height (-1)
|
2015-07-01 17:26:14 -04:00
|
|
|
, vistracker (0)
|
2016-04-27 00:01:13 -04:00
|
|
|
, _state_mask (StateMask (Position|Size))
|
2015-07-01 17:26:14 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowProxy::WindowProxy (const std::string& name, const std::string& menu_name, const XMLNode& node)
|
|
|
|
: _name (name)
|
|
|
|
, _menu_name (menu_name)
|
|
|
|
, _window (0)
|
|
|
|
, _visible (false)
|
|
|
|
, _x_off (-1)
|
|
|
|
, _y_off (-1)
|
|
|
|
, _width (-1)
|
2015-10-26 14:35:06 -04:00
|
|
|
, _height (-1)
|
2015-07-01 17:26:14 -04:00
|
|
|
, vistracker (0)
|
|
|
|
{
|
2015-07-07 22:12:21 -04:00
|
|
|
set_state (node, 0);
|
2015-07-01 17:26:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
WindowProxy::~WindowProxy ()
|
|
|
|
{
|
|
|
|
delete vistracker;
|
|
|
|
delete _window;
|
|
|
|
}
|
|
|
|
|
2015-07-03 15:06:59 -04:00
|
|
|
int
|
2015-07-07 22:12:21 -04:00
|
|
|
WindowProxy::set_state (const XMLNode& node, int /* version */)
|
2015-07-01 17:26:14 -04:00
|
|
|
{
|
|
|
|
XMLNodeList children = node.children ();
|
2016-05-04 23:09:37 -04:00
|
|
|
XMLNode const * child;
|
2015-07-01 17:26:14 -04:00
|
|
|
XMLNodeList::const_iterator i = children.begin ();
|
|
|
|
|
|
|
|
while (i != children.end()) {
|
2016-05-04 23:09:37 -04:00
|
|
|
child = *i;
|
|
|
|
XMLProperty const * prop = child->property (X_("name"));
|
|
|
|
if (child->name() == X_("Window") && prop && prop->value() == _name) {
|
2015-07-01 17:26:14 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != children.end()) {
|
|
|
|
|
2016-05-04 23:09:37 -04:00
|
|
|
XMLProperty const * prop;
|
|
|
|
child = *i;
|
2015-07-01 17:26:14 -04:00
|
|
|
|
2016-05-04 23:09:37 -04:00
|
|
|
if ((prop = child->property (X_("visible"))) != 0) {
|
2015-07-01 17:26:14 -04:00
|
|
|
_visible = PBD::string_is_affirmative (prop->value ());
|
|
|
|
}
|
|
|
|
|
2016-05-04 23:09:37 -04:00
|
|
|
if ((prop = child->property (X_("x-off"))) != 0) {
|
2015-07-01 17:26:14 -04:00
|
|
|
_x_off = atoi (prop->value());
|
|
|
|
}
|
2016-05-04 23:09:37 -04:00
|
|
|
if ((prop = child->property (X_("y-off"))) != 0) {
|
2015-07-01 17:26:14 -04:00
|
|
|
_y_off = atoi (prop->value());
|
|
|
|
}
|
2016-05-04 23:09:37 -04:00
|
|
|
if ((prop = child->property (X_("x-size"))) != 0) {
|
2015-07-01 17:26:14 -04:00
|
|
|
_width = atoi (prop->value());
|
|
|
|
}
|
2016-05-04 23:09:37 -04:00
|
|
|
if ((prop = child->property (X_("y-size"))) != 0) {
|
2015-07-01 17:26:14 -04:00
|
|
|
_height = atoi (prop->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_window) {
|
|
|
|
setup ();
|
|
|
|
}
|
2015-07-03 15:06:59 -04:00
|
|
|
|
|
|
|
return 0;
|
2015-07-01 17:26:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::set_action (Glib::RefPtr<Gtk::Action> act)
|
|
|
|
{
|
|
|
|
_action = act;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2015-10-26 14:35:06 -04:00
|
|
|
WindowProxy::action_name() const
|
2015-07-01 17:26:14 -04:00
|
|
|
{
|
|
|
|
return string_compose (X_("toggle-%1"), _name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-26 14:35:06 -04:00
|
|
|
WindowProxy::toggle()
|
2015-07-01 17:26:14 -04:00
|
|
|
{
|
|
|
|
if (!_window) {
|
|
|
|
(void) get (true);
|
2015-08-04 14:30:41 -04:00
|
|
|
setup ();
|
2015-07-01 17:26:14 -04:00
|
|
|
assert (_window);
|
|
|
|
/* XXX this is a hack - the window object should really
|
|
|
|
ensure its components are all visible. sigh.
|
|
|
|
*/
|
|
|
|
_window->show_all();
|
|
|
|
/* we'd like to just call this and nothing else */
|
|
|
|
_window->present ();
|
|
|
|
} else {
|
|
|
|
if (_window->is_mapped()) {
|
|
|
|
save_pos_and_size();
|
|
|
|
}
|
2015-08-04 14:30:41 -04:00
|
|
|
|
2015-07-01 17:26:14 -04:00
|
|
|
vistracker->cycle_visibility ();
|
2015-08-04 14:30:41 -04:00
|
|
|
|
2015-07-01 17:26:14 -04:00
|
|
|
if (_window->is_mapped()) {
|
|
|
|
if (_width != -1 && _height != -1) {
|
|
|
|
_window->set_default_size (_width, _height);
|
|
|
|
}
|
|
|
|
if (_x_off != -1 && _y_off != -1) {
|
|
|
|
_window->move (_x_off, _y_off);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 12:40:51 -04:00
|
|
|
std::string
|
|
|
|
WindowProxy::xml_node_name()
|
|
|
|
{
|
|
|
|
return X_("Window");
|
|
|
|
}
|
|
|
|
|
2015-07-01 17:26:14 -04:00
|
|
|
XMLNode&
|
2015-07-07 22:12:21 -04:00
|
|
|
WindowProxy::get_state ()
|
2015-07-01 17:26:14 -04:00
|
|
|
{
|
2015-07-09 12:40:51 -04:00
|
|
|
XMLNode* node = new XMLNode (xml_node_name());
|
2015-10-26 14:35:06 -04:00
|
|
|
char buf[32];
|
2015-07-01 17:26:14 -04:00
|
|
|
|
|
|
|
node->add_property (X_("name"), _name);
|
|
|
|
|
|
|
|
if (_window && vistracker) {
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-07-01 17:26:14 -04:00
|
|
|
/* we have a window, so use current state */
|
|
|
|
|
|
|
|
_visible = vistracker->partially_visible ();
|
|
|
|
_window->get_position (_x_off, _y_off);
|
|
|
|
_window->get_size (_width, _height);
|
|
|
|
}
|
|
|
|
|
2016-04-27 00:01:13 -04:00
|
|
|
int x, y, w, h;
|
|
|
|
|
|
|
|
if (_state_mask & Position) {
|
|
|
|
x = _x_off;
|
|
|
|
y = _y_off;
|
|
|
|
} else {
|
|
|
|
x = -1;
|
|
|
|
y = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_state_mask & Size) {
|
|
|
|
w = _width;
|
|
|
|
h = _height;
|
|
|
|
} else {
|
|
|
|
w = -1;
|
|
|
|
h = -1;
|
|
|
|
}
|
|
|
|
|
2015-07-01 17:26:14 -04:00
|
|
|
node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
|
2016-04-27 00:01:13 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%d", x);
|
2015-07-01 17:26:14 -04:00
|
|
|
node->add_property (X_("x-off"), buf);
|
2016-04-27 00:01:13 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%d", y);
|
2015-07-01 17:26:14 -04:00
|
|
|
node->add_property (X_("y-off"), buf);
|
2016-04-27 00:01:13 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%d", w);
|
2015-07-01 17:26:14 -04:00
|
|
|
node->add_property (X_("x-size"), buf);
|
2016-04-27 00:01:13 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%d", h);
|
2015-07-01 17:26:14 -04:00
|
|
|
node->add_property (X_("y-size"), buf);
|
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::drop_window ()
|
|
|
|
{
|
|
|
|
if (_window) {
|
2016-05-10 09:46:12 -04:00
|
|
|
delete_connection.disconnect ();
|
|
|
|
configure_connection.disconnect ();
|
2016-06-12 22:49:15 -04:00
|
|
|
map_connection.disconnect ();
|
|
|
|
unmap_connection.disconnect ();
|
2015-07-01 17:26:14 -04:00
|
|
|
_window->hide ();
|
|
|
|
delete _window;
|
|
|
|
_window = 0;
|
|
|
|
delete vistracker;
|
|
|
|
vistracker = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::use_window (Gtk::Window& win)
|
|
|
|
{
|
|
|
|
drop_window ();
|
|
|
|
_window = &win;
|
|
|
|
setup ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::setup ()
|
|
|
|
{
|
|
|
|
assert (_window);
|
|
|
|
|
|
|
|
vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
|
2016-05-10 09:46:12 -04:00
|
|
|
|
|
|
|
delete_connection = _window->signal_delete_event().connect (sigc::mem_fun (*this, &WindowProxy::delete_event_handler));
|
|
|
|
configure_connection = _window->signal_configure_event().connect (sigc::mem_fun (*this, &WindowProxy::configure_handler), false);
|
2016-06-12 22:49:15 -04:00
|
|
|
map_connection = _window->signal_map().connect (sigc::mem_fun (*this, &WindowProxy::map_handler), false);
|
|
|
|
unmap_connection = _window->signal_unmap().connect (sigc::mem_fun (*this, &WindowProxy::unmap_handler), false);
|
2015-07-01 17:26:14 -04:00
|
|
|
|
|
|
|
set_pos_and_size ();
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-06-12 22:49:15 -04:00
|
|
|
void
|
|
|
|
WindowProxy::map_handler ()
|
|
|
|
{
|
|
|
|
/* emit our own signal */
|
|
|
|
signal_map ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::unmap_handler ()
|
|
|
|
{
|
|
|
|
/* emit out own signal */
|
|
|
|
signal_unmap ();
|
|
|
|
}
|
|
|
|
|
2016-05-10 09:46:12 -04:00
|
|
|
bool
|
|
|
|
WindowProxy::configure_handler (GdkEventConfigure* ev)
|
|
|
|
{
|
|
|
|
/* stupidly, the geometry data in the event isn't the same as we get
|
|
|
|
from the window geometry APIs.so we have to actively interrogate
|
|
|
|
them to get the new information.
|
|
|
|
|
|
|
|
the difference is generally down to window manager framing.
|
|
|
|
*/
|
2017-02-01 17:05:49 -05:00
|
|
|
if (!visible() || !_window->is_mapped()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-10 09:46:12 -04:00
|
|
|
save_pos_and_size ();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-20 14:19:22 -05:00
|
|
|
bool
|
|
|
|
WindowProxy::visible() const
|
|
|
|
{
|
|
|
|
if (vistracker) {
|
|
|
|
/* update with current state */
|
|
|
|
_visible = vistracker->partially_visible();
|
|
|
|
}
|
|
|
|
return _visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WindowProxy::fully_visible () const
|
|
|
|
{
|
|
|
|
if (!vistracker) {
|
|
|
|
/* no vistracker .. no window .. cannot be fully visible */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return vistracker->fully_visible();
|
|
|
|
}
|
|
|
|
|
2015-07-01 17:26:14 -04:00
|
|
|
void
|
|
|
|
WindowProxy::show ()
|
|
|
|
{
|
|
|
|
get (true);
|
|
|
|
assert (_window);
|
|
|
|
_window->show ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::maybe_show ()
|
|
|
|
{
|
|
|
|
if (_visible) {
|
|
|
|
show ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::show_all ()
|
|
|
|
{
|
|
|
|
get (true);
|
|
|
|
assert (_window);
|
|
|
|
_window->show_all ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::present ()
|
|
|
|
{
|
|
|
|
get (true);
|
|
|
|
assert (_window);
|
|
|
|
|
|
|
|
_window->show_all ();
|
|
|
|
_window->present ();
|
|
|
|
|
|
|
|
/* turn off any mouse-based positioning */
|
|
|
|
_window->set_position (Gtk::WIN_POS_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::hide ()
|
|
|
|
{
|
|
|
|
if (_window) {
|
|
|
|
save_pos_and_size();
|
|
|
|
_window->hide ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WindowProxy::delete_event_handler (GdkEventAny* /*ev*/)
|
|
|
|
{
|
2015-08-04 14:30:41 -04:00
|
|
|
if (_action) {
|
|
|
|
_action->activate ();
|
|
|
|
} else {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2015-07-01 17:26:14 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::save_pos_and_size ()
|
|
|
|
{
|
|
|
|
if (_window) {
|
|
|
|
_window->get_position (_x_off, _y_off);
|
|
|
|
_window->get_size (_width, _height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::set_pos_and_size ()
|
|
|
|
{
|
|
|
|
if (!_window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-27 00:01:13 -04:00
|
|
|
if ((_state_mask & Position) && (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1)) {
|
2015-07-01 17:26:14 -04:00
|
|
|
/* cancel any mouse-based positioning */
|
|
|
|
_window->set_position (Gtk::WIN_POS_NONE);
|
|
|
|
}
|
|
|
|
|
2016-04-27 00:01:13 -04:00
|
|
|
if ((_state_mask & Size) && _width != -1 && _height != -1) {
|
2016-02-26 18:51:23 -05:00
|
|
|
_window->resize (_width, _height);
|
2015-07-01 17:26:14 -04:00
|
|
|
}
|
|
|
|
|
2016-04-27 00:01:13 -04:00
|
|
|
if ((_state_mask & Position) && _x_off != -1 && _y_off != -1) {
|
2015-07-01 17:26:14 -04:00
|
|
|
_window->move (_x_off, _y_off);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-26 18:51:23 -05:00
|
|
|
void
|
|
|
|
WindowProxy::set_pos ()
|
|
|
|
{
|
|
|
|
if (!_window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-27 00:01:13 -04:00
|
|
|
if (!(_state_mask & Position)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-26 18:51:23 -05:00
|
|
|
if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
|
|
|
|
/* cancel any mouse-based positioning */
|
|
|
|
_window->set_position (Gtk::WIN_POS_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_x_off != -1 && _y_off != -1) {
|
|
|
|
_window->move (_x_off, _y_off);
|
|
|
|
}
|
|
|
|
}
|
2016-04-27 00:01:13 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
WindowProxy::set_state_mask (StateMask sm)
|
|
|
|
{
|
|
|
|
_state_mask = sm;
|
|
|
|
}
|