2013-05-04 22:01:13 -04:00
|
|
|
/*
|
2015-07-07 22:12:21 -04:00
|
|
|
Copyright (C) 2013 Paul Davis
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
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.
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
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.
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
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.
|
2013-05-04 22:01:13 -04:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __gtk2_ardour_window_manager_h__
|
|
|
|
#define __gtk2_ardour_window_manager_h__
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <boost/function.hpp>
|
|
|
|
#include <glibmm/refptr.h>
|
|
|
|
#include <sigc++/trackable.h>
|
|
|
|
|
2015-08-10 14:31:59 -04:00
|
|
|
#include "gtkmm2ext/bindings.h"
|
2015-07-07 22:12:21 -04:00
|
|
|
#include "gtkmm2ext/window_proxy.h"
|
|
|
|
|
2013-05-04 22:01:13 -04:00
|
|
|
class XMLNode;
|
|
|
|
|
|
|
|
namespace Gtk {
|
2015-07-07 22:12:21 -04:00
|
|
|
class Window;
|
|
|
|
class Action;
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Gtkmm2ext {
|
2015-08-10 14:31:59 -04:00
|
|
|
class VisibilityTracker;
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace ARDOUR {
|
2015-08-10 14:31:59 -04:00
|
|
|
class Session;
|
|
|
|
class SessionHandlePtr;
|
2013-05-04 22:01:13 -04:00
|
|
|
}
|
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
namespace WM {
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
class ProxyBase;
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2013-07-07 11:44:00 -04:00
|
|
|
class Manager : public ARDOUR::SessionHandlePtr
|
2013-05-07 22:09:16 -04:00
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
public:
|
2015-07-07 22:12:21 -04:00
|
|
|
static Manager& instance();
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
void register_window (ProxyBase*);
|
|
|
|
void remove (const ProxyBase*);
|
|
|
|
void toggle_window (ProxyBase*);
|
|
|
|
void show_visible () const;
|
|
|
|
void set_session (ARDOUR::Session*);
|
|
|
|
void add_state (XMLNode&) const;
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
/* HACK HACK HACK */
|
|
|
|
void set_transient_for (Gtk::Window*);
|
|
|
|
Gtk::Window* transient_parent() const { return current_transient_parent; }
|
2013-05-07 13:01:18 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
private:
|
2015-07-07 22:12:21 -04:00
|
|
|
typedef std::list<ProxyBase*> Windows;
|
|
|
|
Windows _windows;
|
|
|
|
Glib::RefPtr<Gtk::ActionGroup> window_actions;
|
|
|
|
Gtk::Window* current_transient_parent;
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
Manager();
|
|
|
|
~Manager();
|
2013-05-04 22:01:13 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
static Manager* _instance;
|
2017-07-01 12:42:24 -04:00
|
|
|
private:
|
2016-06-12 22:49:47 -04:00
|
|
|
void window_proxy_was_mapped (ProxyBase*);
|
|
|
|
void window_proxy_was_unmapped (ProxyBase*);
|
2013-05-07 22:09:16 -04:00
|
|
|
};
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
class ProxyBase : public ARDOUR::SessionHandlePtr, public Gtkmm2ext::WindowProxy
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
public:
|
2015-07-07 22:12:21 -04:00
|
|
|
ProxyBase (const std::string& name, const std::string& menu_name);
|
|
|
|
ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
virtual ARDOUR::SessionHandlePtr* session_handle () = 0;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
protected:
|
2015-07-07 22:12:21 -04:00
|
|
|
void setup ();
|
2013-05-04 22:01:13 -04:00
|
|
|
};
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
class ProxyTemporary: public ProxyBase
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
public:
|
2015-07-07 22:12:21 -04:00
|
|
|
ProxyTemporary (const std::string& name, Gtk::Window* win);
|
|
|
|
~ProxyTemporary();
|
2015-10-26 14:35:06 -04:00
|
|
|
|
|
|
|
Gtk::Window* get (bool create = false) {
|
2015-07-07 22:12:21 -04:00
|
|
|
(void) create;
|
|
|
|
return _window;
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
|
|
|
Gtk::Window* operator->() {
|
2015-07-07 22:12:21 -04:00
|
|
|
return _window;
|
|
|
|
}
|
|
|
|
|
|
|
|
ARDOUR::SessionHandlePtr* session_handle ();
|
2013-05-07 22:09:16 -04:00
|
|
|
};
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
template<typename T>
|
2015-07-07 22:12:21 -04:00
|
|
|
class ProxyWithConstructor: public ProxyBase
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
public:
|
2015-07-07 22:12:21 -04:00
|
|
|
ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c)
|
|
|
|
: ProxyBase (name, menu_name) , creator (c) {}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function<T*()>& c, const XMLNode* node)
|
|
|
|
: ProxyBase (name, menu_name, *node) , creator (c) {}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
|
|
|
Gtk::Window* get (bool create = false) {
|
2015-07-07 22:12:21 -04:00
|
|
|
if (!_window) {
|
|
|
|
if (!create) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-07 22:09:16 -04:00
|
|
|
|
2013-10-03 04:06:56 -04:00
|
|
|
_window = dynamic_cast<Gtk::Window*> (creator ());
|
2013-05-07 22:09:16 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
if (_window) {
|
|
|
|
setup ();
|
2015-10-26 14:35:06 -04:00
|
|
|
}
|
2015-07-07 22:12:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return _window;
|
|
|
|
}
|
|
|
|
|
2015-10-26 14:35:06 -04:00
|
|
|
T* operator->() {
|
2015-07-07 22:12:21 -04:00
|
|
|
return dynamic_cast<T*> (get (true));
|
|
|
|
}
|
|
|
|
|
|
|
|
ARDOUR::SessionHandlePtr* session_handle () {
|
|
|
|
/* may return null */
|
|
|
|
return dynamic_cast<T*> (_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_session(ARDOUR::Session *s) {
|
|
|
|
SessionHandlePtr::set_session (s);
|
|
|
|
ARDOUR::SessionHandlePtr* sp = session_handle ();
|
|
|
|
if (sp) {
|
|
|
|
sp->set_session (s);
|
|
|
|
dynamic_cast<T*>(_window)->set_session(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
private:
|
2015-07-07 22:12:21 -04:00
|
|
|
boost::function<T*()> creator;
|
2013-05-07 22:09:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
2015-07-07 22:12:21 -04:00
|
|
|
class Proxy : public ProxyBase
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
public:
|
2015-07-07 22:12:21 -04:00
|
|
|
Proxy (const std::string& name, const std::string& menu_name)
|
|
|
|
: ProxyBase (name, menu_name) {}
|
|
|
|
|
|
|
|
Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node)
|
|
|
|
: ProxyBase (name, menu_name, *node) {}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
|
|
|
Gtk::Window* get (bool create = false) {
|
2015-07-07 22:12:21 -04:00
|
|
|
if (!_window) {
|
|
|
|
if (!create) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_window = new T ();
|
|
|
|
|
|
|
|
if (_window) {
|
|
|
|
setup ();
|
2015-10-26 14:35:06 -04:00
|
|
|
}
|
2015-07-07 22:12:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return _window;
|
|
|
|
}
|
|
|
|
|
2015-10-26 14:35:06 -04:00
|
|
|
T* operator->() {
|
2015-07-07 22:12:21 -04:00
|
|
|
return dynamic_cast<T*> (get(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
ARDOUR::SessionHandlePtr* session_handle () {
|
|
|
|
/* may return null */
|
|
|
|
return dynamic_cast<T*> (_window);
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
void set_session(ARDOUR::Session *s) {
|
|
|
|
SessionHandlePtr::set_session (s);
|
|
|
|
ARDOUR::SessionHandlePtr* sp = session_handle ();
|
|
|
|
if (sp) {
|
|
|
|
sp->set_session (s);
|
|
|
|
dynamic_cast<T*>(_window)->set_session(s);
|
|
|
|
}
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
private:
|
2015-07-07 22:12:21 -04:00
|
|
|
boost::function<T*()> creator;
|
2013-05-07 22:09:16 -04:00
|
|
|
};
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2013-05-07 22:09:16 -04:00
|
|
|
} /* namespace */
|
2013-05-04 22:01:13 -04:00
|
|
|
|
|
|
|
#endif /* __gtk2_ardour_window_manager_h__ */
|