X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fwindow_manager.h;h=93d71add928244f63cfe691a3d79dc6e3375e54d;hb=6b1b72a247bf04c81292fc41af4f69c9b7f90379;hp=9f4382725d70b0c0827f9087a768ba4e5393b8ec;hpb=128b3749542f310ce2c3b66d9ba792c9bfd15cb9;p=ardour.git diff --git a/gtk2_ardour/window_manager.h b/gtk2_ardour/window_manager.h index 9f4382725d..93d71add92 100644 --- a/gtk2_ardour/window_manager.h +++ b/gtk2_ardour/window_manager.h @@ -1,19 +1,19 @@ /* - Copyright (C) 2013 Paul Davis + 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 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. + 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. + 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. */ @@ -27,11 +27,14 @@ #include #include +#include "gtkmm2ext/bindings.h" +#include "gtkmm2ext/window_proxy.h" + class XMLNode; namespace Gtk { - class Window; - class Action; +class Window; +class Action; } namespace Gtkmm2ext { @@ -43,86 +46,99 @@ namespace ARDOUR { class SessionHandlePtr; } -class WindowManager +namespace WM { + +class ProxyBase; + +class Manager : public ARDOUR::SessionHandlePtr { - public: - static WindowManager& instance(); +public: + static Manager& instance(); + + 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; + + /* HACK HACK HACK */ + void set_transient_for (Gtk::Window*); + Gtk::Window* transient_parent() const { return current_transient_parent; } + +private: + typedef std::list Windows; + Windows _windows; + Glib::RefPtr window_actions; + Gtk::Window* current_transient_parent; + + Manager(); + ~Manager(); + + static Manager* _instance; +private: + void window_proxy_was_mapped (ProxyBase*); + void window_proxy_was_unmapped (ProxyBase*); +}; - class ProxyBase : public sigc::trackable { - public: +class ProxyBase : public ARDOUR::SessionHandlePtr, public Gtkmm2ext::WindowProxy +{ +public: ProxyBase (const std::string& name, const std::string& menu_name); ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&); - virtual ~ProxyBase(); - void show (); - void show_all (); - void hide (); - void present (); - void maybe_show (); - - bool visible() const { return _visible; } - const std::string& name() const { return _name; } - const std::string& menu_name() const { return _menu_name; } - - std::string action_name() const; - void set_action (Glib::RefPtr); - Glib::RefPtr action() const { return _action; }; - - void drop_window (); - void use_window (Gtk::Window&); - - virtual Gtk::Window* get (bool create = false) = 0; + virtual ARDOUR::SessionHandlePtr* session_handle () = 0; - virtual void toggle (); +protected: + void setup (); +}; - void set_state (const XMLNode&); - XMLNode& get_state () const; +class ProxyTemporary: public ProxyBase +{ +public: + ProxyTemporary (const std::string& name, Gtk::Window* win); - virtual ARDOUR::SessionHandlePtr* session_handle () = 0; + Gtk::Window* get (bool create = false) { + (void) create; + return _window; + } - operator bool() const { return _window != 0; } + Gtk::Window* operator->() { + return _window; + } - protected: - std::string _name; - std::string _menu_name; - Glib::RefPtr _action; - Gtk::Window* _window; - mutable bool _visible; ///< true if the window should be visible on startup - mutable int _x_off; ///< x position - mutable int _y_off; ///< y position - mutable int _width; ///< width - mutable int _height; ///< height - Gtkmm2ext::VisibilityTracker* vistracker; + ARDOUR::SessionHandlePtr* session_handle (); - void setup (); - }; + void explicit_delete () { _window = 0 ; delete this; } +}; - template - class ProxyWithConstructor: public ProxyBase { - public: +template +class ProxyWithConstructor: public ProxyBase +{ +public: ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function& c) : ProxyBase (name, menu_name) , creator (c) {} - + ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function& c, const XMLNode* node) - : ProxyBase (name, menu_name, node) , creator (c) {} - - Gtk::Window* get (bool create = false) { + : ProxyBase (name, menu_name, *node) , creator (c) {} + + Gtk::Window* get (bool create = false) { if (!_window) { if (!create) { return 0; } - _window = creator (); + _window = dynamic_cast (creator ()); if (_window) { setup (); - } + } } return _window; } - T* operator->() { + T* operator->() { return dynamic_cast (get (true)); } @@ -131,20 +147,30 @@ class WindowManager return dynamic_cast (_window); } - private: + void set_session(ARDOUR::Session *s) { + SessionHandlePtr::set_session (s); + ARDOUR::SessionHandlePtr* sp = session_handle (); + if (sp) { + sp->set_session (s); + dynamic_cast(_window)->set_session(s); + } + } + +private: boost::function creator; - }; +}; - template - class Proxy : public ProxyBase { - public: +template +class Proxy : public ProxyBase +{ +public: 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) {} - - Gtk::Window* get (bool create = false) { + : ProxyBase (name, menu_name, *node) {} + + Gtk::Window* get (bool create = false) { if (!_window) { if (!create) { return 0; @@ -154,13 +180,13 @@ class WindowManager if (_window) { setup (); - } + } } return _window; } - T* operator->() { + T* operator->() { return dynamic_cast (get(true)); } @@ -169,26 +195,19 @@ class WindowManager return dynamic_cast (_window); } - private: + void set_session(ARDOUR::Session *s) { + SessionHandlePtr::set_session (s); + ARDOUR::SessionHandlePtr* sp = session_handle (); + if (sp) { + sp->set_session (s); + dynamic_cast(_window)->set_session(s); + } + } + +private: boost::function creator; - }; - - 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; - - private: - typedef std::list Windows; - Windows _windows; - Glib::RefPtr window_actions; - - WindowManager(); - ~WindowManager(); - - static WindowManager* _instance; }; +} /* namespace */ + #endif /* __gtk2_ardour_window_manager_h__ */