2013-05-04 22:01:13 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2013-2018 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-05-04 22:01:13 -04:00
|
|
|
|
|
|
|
#include <gtkmm/window.h>
|
|
|
|
|
|
|
|
#include "pbd/xml++.h"
|
|
|
|
|
|
|
|
#include "ardour/session_handle.h"
|
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
#include "gtkmm2ext/bindings.h"
|
2013-05-04 22:01:13 -04:00
|
|
|
#include "gtkmm2ext/visibility_tracker.h"
|
|
|
|
|
|
|
|
#include "actions.h"
|
2013-05-07 22:09:16 -04:00
|
|
|
#include "ardour_dialog.h"
|
2015-08-04 14:00:08 -04:00
|
|
|
#include "ardour_ui.h"
|
2013-05-07 22:09:16 -04:00
|
|
|
#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
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2013-05-04 22:01:13 -04:00
|
|
|
|
|
|
|
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) {
|
2018-12-11 05:06:26 -05:00
|
|
|
window_actions = ActionManager::create_action_group (Gtkmm2ext::UI::instance()->global_bindings, X_("Window"));
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
2016-07-13 16:38:08 -04:00
|
|
|
|
2018-12-10 08:33:31 -05:00
|
|
|
ActionManager::register_toggle_action (window_actions,
|
|
|
|
info->action_name().c_str(), info->menu_name().c_str(),
|
|
|
|
sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info));
|
2016-06-12 22:49:47 -04:00
|
|
|
|
|
|
|
info->signal_map.connect (sigc::bind (sigc::mem_fun (*this, &Manager::window_proxy_was_mapped), info));
|
|
|
|
info->signal_unmap.connect (sigc::bind (sigc::mem_fun (*this, &Manager::window_proxy_was_unmapped), info));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Manager::window_proxy_was_mapped (ProxyBase* proxy)
|
|
|
|
{
|
2018-12-10 08:33:31 -05:00
|
|
|
Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
|
2016-06-12 22:49:47 -04:00
|
|
|
if (!act) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
|
|
|
|
if (!tact) {
|
|
|
|
return;
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
2016-06-12 22:49:47 -04:00
|
|
|
|
|
|
|
tact->set_active (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Manager::window_proxy_was_unmapped (ProxyBase* proxy)
|
|
|
|
{
|
2018-12-10 08:33:31 -05:00
|
|
|
Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
|
2016-06-12 22:49:47 -04:00
|
|
|
if (!act) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
|
|
|
|
if (!tact) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tact->set_active (false);
|
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
|
|
|
{
|
2018-12-10 08:33:31 -05:00
|
|
|
Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
|
2015-08-04 14:30:41 -04:00
|
|
|
if (!act) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
|
|
|
|
if (!tact) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tact->get_active()) {
|
|
|
|
proxy->present ();
|
|
|
|
} else {
|
|
|
|
proxy->hide ();
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
2016-07-12 10:27:19 -04:00
|
|
|
Gtk::Window* win = (*i)->get (true);
|
|
|
|
if (!win) {
|
2015-09-01 07:28:33 -04:00
|
|
|
/* the window may be a plugin GUI for a plugin which
|
|
|
|
* is disabled or longer present.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-12 10:27:19 -04:00
|
|
|
if (dynamic_cast<ArdourDialog*> (win)) {
|
|
|
|
/* do not show dialogs at startup. Most
|
|
|
|
* dialogs require some signal connection work
|
|
|
|
* because we are trying to avoid recursive
|
|
|
|
* event loops (connecting instead to
|
|
|
|
* ::signal_response(). This means we need to
|
|
|
|
* destroy the window as well, so that the code
|
|
|
|
* which checks if it should be created will
|
2016-07-13 16:38:08 -04:00
|
|
|
* find that it is missing and will create it
|
2016-07-12 10:27:19 -04:00
|
|
|
* and connect to any necessary signals.
|
|
|
|
*/
|
|
|
|
(*i)->drop_window ();
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-04 22:01:13 -04:00
|
|
|
(*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
|
|
|
|
*/
|
2015-07-09 12:40:51 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
if (dynamic_cast<ProxyTemporary*> (*i)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-09 12:40:51 -04:00
|
|
|
|
|
|
|
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.
|
2015-10-04 14:51:05 -04:00
|
|
|
*
|
2013-06-07 11:58:57 -04:00
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -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
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name)
|
|
|
|
: WindowProxy (name, menu_name)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode& node)
|
|
|
|
: WindowProxy (name, menu_name, node)
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-07 22:09:16 -04:00
|
|
|
ProxyBase::setup ()
|
2013-05-04 22:01:13 -04:00
|
|
|
{
|
2015-07-07 22:12:21 -04:00
|
|
|
WindowProxy::setup ();
|
2013-07-07 11:44:00 -04:00
|
|
|
set_session(_session);
|
2016-06-12 22:49:47 -04:00
|
|
|
|
2015-10-26 14:35:06 -04:00
|
|
|
}
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
/*-----------------------*/
|
|
|
|
|
|
|
|
ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)
|
|
|
|
: ProxyBase (name, string())
|
|
|
|
{
|
|
|
|
_window = win;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|