2013-05-04 22:01:13 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 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/window.h>
|
|
|
|
|
|
|
|
#include "pbd/xml++.h"
|
|
|
|
|
|
|
|
#include "ardour/session_handle.h"
|
|
|
|
|
|
|
|
#include "gtkmm2ext/visibility_tracker.h"
|
|
|
|
|
|
|
|
#include "actions.h"
|
2013-05-07 22:09:16 -04:00
|
|
|
#include "ardour_dialog.h"
|
|
|
|
#include "ardour_window.h"
|
2013-05-04 22:01:13 -04:00
|
|
|
#include "window_manager.h"
|
2013-05-21 15:23:10 -04:00
|
|
|
#include "processor_box.h"
|
2013-05-04 22:01:13 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using std::string;
|
2013-05-07 22:09:16 -04:00
|
|
|
using namespace WM;
|
2013-06-08 03:03:26 -04:00
|
|
|
using namespace PBD;
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager* Manager::_instance = 0;
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager&
|
|
|
|
Manager::instance ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
if (!_instance) {
|
2013-05-07 22:09:16 -04:00
|
|
|
_instance = new Manager;
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
return *_instance;
|
|
|
|
}
|
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager::Manager ()
|
2013-05-07 18:09:12 -04:00
|
|
|
: current_transient_parent (0)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-07 11:44:00 -04:00
|
|
|
Manager::~Manager ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-04 22:01:13 -04:00
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager::register_window (ProxyBase* info)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
_windows.push_back (info);
|
|
|
|
|
2013-05-04 22:02:05 -04:00
|
|
|
if (!info->menu_name().empty()) {
|
2013-05-04 22:01:13 -04:00
|
|
|
|
|
|
|
if (!window_actions) {
|
|
|
|
window_actions = Gtk::ActionGroup::create (X_("Window"));
|
|
|
|
ActionManager::add_action_group (window_actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
info->set_action (ActionManager::register_action (window_actions, info->action_name().c_str(), info->menu_name().c_str(),
|
2013-05-07 22:09:16 -04:00
|
|
|
sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info)));
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager::remove (const ProxyBase* info)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) {
|
|
|
|
if ((*i) == info) {
|
|
|
|
_windows.erase (i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager::toggle_window (ProxyBase* proxy)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
if (proxy) {
|
|
|
|
proxy->toggle ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager::show_visible() const
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
|
|
|
|
if ((*i)->visible()) {
|
|
|
|
(*i)->show_all ();
|
|
|
|
(*i)->present ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager::add_state (XMLNode& root) const
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
|
2013-05-07 22:09:16 -04:00
|
|
|
/* don't save state for temporary proxy windows
|
|
|
|
*/
|
|
|
|
if (dynamic_cast<ProxyTemporary*> (*i)) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-21 15:23:10 -04:00
|
|
|
if (dynamic_cast<ProcessorWindowProxy*> (*i)) {
|
|
|
|
ProcessorWindowProxy *pi = dynamic_cast<ProcessorWindowProxy*> (*i);
|
|
|
|
root.add_child_nocopy (pi->get_state());
|
|
|
|
} else {
|
|
|
|
root.add_child_nocopy ((*i)->get_state());
|
|
|
|
}
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager::set_session (ARDOUR::Session* s)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
2013-07-07 11:44:00 -04:00
|
|
|
SessionHandlePtr::set_session (s);
|
2013-05-04 22:01:13 -04:00
|
|
|
for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
|
2013-07-07 11:44:00 -04:00
|
|
|
(*i)->set_session(s);
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 13:01:18 -04:00
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
Manager::set_transient_for (Gtk::Window* parent)
|
2013-05-07 13:01:18 -04:00
|
|
|
{
|
2013-06-07 11:58:57 -04:00
|
|
|
/* OS X has a richer concept of window layering than X does (or
|
|
|
|
* certainly, than any accepted conventions on X), and so the use of
|
|
|
|
* Manager::set_transient_for() is not necessary on that platform.
|
|
|
|
*
|
|
|
|
* On OS X this is mostly taken care of by using the window type rather
|
|
|
|
* than explicit 1:1 transient-for relationships.
|
|
|
|
*/
|
|
|
|
|
2013-05-07 22:30:01 -04:00
|
|
|
#ifndef __APPLE__
|
2013-05-07 13:01:18 -04:00
|
|
|
if (parent) {
|
|
|
|
for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
|
|
|
|
Gtk::Window* win = (*i)->get();
|
|
|
|
if (win) {
|
|
|
|
win->set_transient_for (*parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
|
|
|
|
Gtk::Window* win = (*i)->get();
|
|
|
|
if (win) {
|
|
|
|
gtk_window_set_transient_for (win->gobj(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-07 22:09:16 -04:00
|
|
|
|
2013-05-07 18:09:12 -04:00
|
|
|
current_transient_parent = parent;
|
2013-05-07 22:30:01 -04:00
|
|
|
#endif
|
2013-05-07 13:01:18 -04:00
|
|
|
}
|
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
/*-------------------------*/
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::ProxyBase (const string& name, const std::string& menu_name)
|
2013-05-04 22:01:13 -04:00
|
|
|
: _name (name)
|
|
|
|
, _menu_name (menu_name)
|
|
|
|
, _window (0)
|
|
|
|
, _visible (false)
|
|
|
|
, _x_off (-1)
|
|
|
|
, _y_off (-1)
|
|
|
|
, _width (-1)
|
|
|
|
, _height (-1)
|
|
|
|
, vistracker (0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::ProxyBase (const string& name, const std::string& menu_name, const XMLNode& node)
|
2013-05-04 22:01:13 -04:00
|
|
|
: _name (name)
|
|
|
|
, _menu_name (menu_name)
|
|
|
|
, _window (0)
|
|
|
|
, _visible (false)
|
|
|
|
, _x_off (-1)
|
|
|
|
, _y_off (-1)
|
|
|
|
, _width (-1)
|
|
|
|
, _height (-1)
|
|
|
|
, vistracker (0)
|
|
|
|
{
|
|
|
|
set_state (node);
|
|
|
|
}
|
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::~ProxyBase ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
delete vistracker;
|
2013-10-07 20:17:49 -04:00
|
|
|
delete _window;
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::set_state (const XMLNode& node)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
XMLNodeList children = node.children ();
|
|
|
|
|
|
|
|
XMLNodeList::const_iterator i = children.begin ();
|
|
|
|
|
|
|
|
while (i != children.end()) {
|
|
|
|
XMLProperty* prop = (*i)->property (X_("name"));
|
|
|
|
if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != children.end()) {
|
|
|
|
|
|
|
|
XMLProperty* prop;
|
|
|
|
|
|
|
|
if ((prop = (*i)->property (X_("visible"))) != 0) {
|
|
|
|
_visible = PBD::string_is_affirmative (prop->value ());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((prop = (*i)->property (X_("x-off"))) != 0) {
|
2013-06-08 03:03:26 -04:00
|
|
|
_x_off = atoi (prop->value());
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
if ((prop = (*i)->property (X_("y-off"))) != 0) {
|
2013-06-08 03:03:26 -04:00
|
|
|
_y_off = atoi (prop->value());
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
if ((prop = (*i)->property (X_("x-size"))) != 0) {
|
2013-06-08 03:03:26 -04:00
|
|
|
_width = atoi (prop->value());
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
if ((prop = (*i)->property (X_("y-size"))) != 0) {
|
2013-06-08 03:03:26 -04:00
|
|
|
_height = atoi (prop->value());
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we have a window already, reset its properties */
|
|
|
|
|
|
|
|
if (_window) {
|
|
|
|
setup ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
_action = act;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::action_name() const
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
return string_compose (X_("toggle-%1"), _name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::toggle()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
if (!_window) {
|
|
|
|
(void) get (true);
|
|
|
|
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 ();
|
2013-07-07 13:29:42 -04:00
|
|
|
|
|
|
|
if (_width != -1 && _height != -1) {
|
|
|
|
_window->set_default_size (_width, _height);
|
|
|
|
}
|
|
|
|
if (_x_off != -1 && _y_off != -1) {
|
|
|
|
_window->move (_x_off, _y_off);
|
|
|
|
}
|
|
|
|
|
2013-05-04 22:01:13 -04:00
|
|
|
} else {
|
2013-07-07 13:29:42 -04:00
|
|
|
if (_window->is_mapped()) {
|
|
|
|
save_pos_and_size();
|
|
|
|
}
|
2013-05-04 22:01:13 -04:00
|
|
|
vistracker->cycle_visibility ();
|
2013-07-07 13:29:42 -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);
|
|
|
|
}
|
|
|
|
}
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::get_state () const
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode (X_("Window"));
|
2013-05-04 22:02:05 -04:00
|
|
|
char buf[32];
|
|
|
|
|
2013-05-04 22:01:13 -04:00
|
|
|
node->add_property (X_("name"), _name);
|
|
|
|
|
2013-05-04 22:02:05 -04:00
|
|
|
if (_window && vistracker) {
|
|
|
|
|
|
|
|
/* we have a window, so use current state */
|
|
|
|
|
|
|
|
_visible = vistracker->partially_visible ();
|
2013-07-07 16:24:15 -04:00
|
|
|
if (_visible) {
|
|
|
|
_window->get_position (_x_off, _y_off);
|
|
|
|
_window->get_size (_width, _height);
|
|
|
|
}
|
2013-05-04 22:02:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
|
|
|
|
|
2013-05-04 22:01:13 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%d", _x_off);
|
|
|
|
node->add_property (X_("x-off"), buf);
|
|
|
|
snprintf (buf, sizeof (buf), "%d", _y_off);
|
|
|
|
node->add_property (X_("y-off"), buf);
|
|
|
|
snprintf (buf, sizeof (buf), "%d", _width);
|
|
|
|
node->add_property (X_("x-size"), buf);
|
|
|
|
snprintf (buf, sizeof (buf), "%d", _height);
|
|
|
|
node->add_property (X_("y-size"), buf);
|
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::drop_window ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
if (_window) {
|
|
|
|
_window->hide ();
|
|
|
|
delete _window;
|
|
|
|
_window = 0;
|
|
|
|
delete vistracker;
|
|
|
|
vistracker = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::use_window (Gtk::Window& win)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
2013-05-04 22:02:05 -04:00
|
|
|
drop_window ();
|
2013-05-04 22:01:13 -04:00
|
|
|
_window = &win;
|
|
|
|
setup ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::setup ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
assert (_window);
|
|
|
|
|
|
|
|
vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
|
2013-10-13 22:40:39 -04:00
|
|
|
_window->signal_delete_event().connect (sigc::mem_fun (*this, &ProxyBase::delete_event_handler));
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2013-05-06 12:13:43 -04:00
|
|
|
if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
|
|
|
|
/* cancel any mouse-based positioning */
|
|
|
|
_window->set_position (Gtk::WIN_POS_NONE);
|
|
|
|
}
|
|
|
|
|
2013-05-04 22:01:13 -04:00
|
|
|
if (_width != -1 && _height != -1) {
|
|
|
|
_window->set_default_size (_width, _height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_x_off != -1 && _y_off != -1) {
|
|
|
|
_window->move (_x_off, _y_off);
|
|
|
|
}
|
2013-07-07 11:44:00 -04:00
|
|
|
set_session(_session);
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::show ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
2013-10-13 22:40:39 -04:00
|
|
|
get (true);
|
|
|
|
assert (_window);
|
|
|
|
_window->show ();
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::maybe_show ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
if (_visible) {
|
|
|
|
show ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::show_all ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
2013-10-13 22:40:39 -04:00
|
|
|
get (true);
|
|
|
|
assert (_window);
|
|
|
|
_window->show_all ();
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::present ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
2013-10-13 22:40:39 -04:00
|
|
|
get (true);
|
|
|
|
assert (_window);
|
|
|
|
|
|
|
|
_window->show_all ();
|
|
|
|
_window->present ();
|
2013-05-06 12:13:43 -04:00
|
|
|
|
|
|
|
/* turn off any mouse-based positioning */
|
|
|
|
_window->set_position (Gtk::WIN_POS_NONE);
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::hide ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
2013-10-13 22:40:39 -04:00
|
|
|
if (_window) {
|
2013-07-07 13:29:42 -04:00
|
|
|
save_pos_and_size();
|
2013-10-13 22:40:39 -04:00
|
|
|
_window->hide ();
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-07 11:44:00 -04:00
|
|
|
bool
|
2013-10-13 22:40:39 -04:00
|
|
|
ProxyBase::delete_event_handler (GdkEventAny* /*ev*/)
|
2013-07-07 11:44:00 -04:00
|
|
|
{
|
2013-07-07 16:24:15 -04:00
|
|
|
hide();
|
|
|
|
return true;
|
2013-07-07 11:44:00 -04:00
|
|
|
}
|
|
|
|
|
2013-07-07 13:29:42 -04:00
|
|
|
void
|
|
|
|
ProxyBase::save_pos_and_size ()
|
|
|
|
{
|
2013-10-13 22:40:39 -04:00
|
|
|
if (_window) {
|
|
|
|
_window->get_position (_x_off, _y_off);
|
|
|
|
_window->get_size (_width, _height);
|
2013-07-10 09:22:56 -04:00
|
|
|
}
|
2013-07-07 13:29:42 -04:00
|
|
|
}
|
2013-05-07 22:09:16 -04:00
|
|
|
/*-----------------------*/
|
|
|
|
|
|
|
|
ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
|
|
|
|
: ProxyBase (name, string())
|
|
|
|
{
|
|
|
|
_window = win;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyTemporary::~ProxyTemporary ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-07 11:44:00 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
ARDOUR::SessionHandlePtr*
|
|
|
|
ProxyTemporary::session_handle()
|
|
|
|
{
|
|
|
|
/* may return null */
|
|
|
|
ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
|
|
|
|
if (aw) { return aw; }
|
|
|
|
ArdourDialog* ad = dynamic_cast<ArdourDialog*> (_window);
|
|
|
|
if (ad) { return ad; }
|
|
|
|
return 0;
|
|
|
|
}
|