Allow strips to add or remove personal sends
[ardour.git] / gtk2_ardour / window_manager.cc
index 629e24419b470716e51ae078e9c3609eb5ac5bfa..1d63751c5ec369e9f1fe1eee4c768274206b02e0 100644 (file)
 
 #include "ardour/session_handle.h"
 
+#include "gtkmm2ext/bindings.h"
 #include "gtkmm2ext/visibility_tracker.h"
 
 #include "actions.h"
 #include "ardour_dialog.h"
+#include "ardour_ui.h"
 #include "ardour_window.h"
 #include "window_manager.h"
 #include "processor_box.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using std::string;
 using namespace WM;
@@ -64,13 +66,47 @@ Manager::register_window (ProxyBase* info)
        if (!info->menu_name().empty()) {
 
                if (!window_actions) {
-                       window_actions = Gtk::ActionGroup::create (X_("Window"));
-                       ActionManager::add_action_group (window_actions);
+                       window_actions = ARDOUR_UI::instance()->global_actions.create_action_group (X_("Window"));
                }
 
-               info->set_action (ActionManager::register_action (window_actions, info->action_name().c_str(), info->menu_name().c_str(), 
-                                                                 sigc::bind (sigc::mem_fun (*this, &Manager::toggle_window), info)));
+               ARDOUR_UI::instance()->global_actions.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));
+
+               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)
+{
+       Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
+       if (!act) {
+               return;
+       }
+       Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
+       if (!tact) {
+               return;
        }
+
+       tact->set_active (true);
+}
+
+void
+Manager::window_proxy_was_unmapped (ProxyBase* proxy)
+{
+       Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
+       if (!act) {
+               return;
+       }
+       Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
+       if (!tact) {
+               return;
+       }
+
+       tact->set_active (false);
 }
 
 void
@@ -87,8 +123,19 @@ Manager::remove (const ProxyBase* info)
 void
 Manager::toggle_window (ProxyBase* proxy)
 {
-       if (proxy) {
-               proxy->toggle ();
+       Glib::RefPtr<Gtk::Action> act = ARDOUR_UI::instance()->global_actions.find_action (string_compose ("%1/%2", window_actions->get_name(), proxy->action_name()));
+       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 ();
        }
 }
 
@@ -97,6 +144,27 @@ Manager::show_visible() const
 {
        for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
                if ((*i)->visible()) {
+                       Gtk::Window* win = (*i)->get (true);
+                       if (!win) {
+                               /* the window may be a plugin GUI for a plugin which
+                                * is disabled or longer present.
+                                */
+                               continue;
+                       }
+                       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
+                                * find that it is missing and will create it
+                                * and connect to any necessary signals.
+                                */
+                               (*i)->drop_window ();
+                               continue;
+                       }
                        (*i)->show_all ();
                        (*i)->present ();
                }
@@ -109,15 +177,12 @@ Manager::add_state (XMLNode& root) const
        for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) {
                /* don't save state for temporary proxy windows
                 */
+
                if (dynamic_cast<ProxyTemporary*> (*i)) {
                        continue;
                }
-               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());
-               }
+
+               root.add_child_nocopy ((*i)->get_state());
        }
 }
 
@@ -136,7 +201,7 @@ Manager::set_transient_for (Gtk::Window* parent)
        /* 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.
         */
@@ -157,272 +222,31 @@ Manager::set_transient_for (Gtk::Window* parent)
                        }
                }
        }
-       
+
        current_transient_parent = parent;
 #endif
 }
 
 /*-------------------------*/
 
-ProxyBase::ProxyBase (const 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)
-       , _height (-1) 
-       , vistracker (0)
-{
-}
-
-ProxyBase::ProxyBase (const 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)
-       , _height (-1) 
-       , vistracker (0)
-{
-       set_state (node);
-}
-
-ProxyBase::~ProxyBase ()
-{
-       delete vistracker;
-}
-
-void
-ProxyBase::set_state (const XMLNode& node)
-{
-       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) {
-                       _x_off = atoi (prop->value());
-               }
-               if ((prop = (*i)->property (X_("y-off"))) != 0) {
-                       _y_off = atoi (prop->value());
-               }
-               if ((prop = (*i)->property (X_("x-size"))) != 0) {
-                       _width = atoi (prop->value());
-               }
-               if ((prop = (*i)->property (X_("y-size"))) != 0) {
-                       _height = atoi (prop->value());
-               }
-       }
-
-       /* if we have a window already, reset its properties */
-
-       if (_window) {
-               setup ();
-       }
-}
-
-void
-ProxyBase::set_action (Glib::RefPtr<Gtk::Action> act)
-{
-       _action = act;
-}
-
-std::string
-ProxyBase::action_name() const 
-{
-       return string_compose (X_("toggle-%1"), _name);
-}
-
-void
-ProxyBase::toggle() 
+ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name)
+       : WindowProxy (name, menu_name)
 {
-       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 ();
-
-               if (_width != -1 && _height != -1) {
-                       _window->set_default_size (_width, _height);
-               }
-               if (_x_off != -1 && _y_off != -1) {
-                       _window->move (_x_off, _y_off);
-               }
-
-       } else {
-               if (_window->is_mapped()) {
-                       save_pos_and_size();
-               }
-               vistracker->cycle_visibility ();
-               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);
-                       }
-               }
-       }
 }
 
-XMLNode&
-ProxyBase::get_state () const
+ProxyBase::ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode& node)
+       : WindowProxy (name, menu_name, node)
 {
-       XMLNode* node = new XMLNode (X_("Window"));
-       char buf[32];   
-
-       node->add_property (X_("name"), _name);
-
-       if (_window && vistracker) {
-               
-               /* we have a window, so use current state */
-
-               _visible = vistracker->partially_visible ();
-               if (_visible) {
-                       _window->get_position (_x_off, _y_off);
-                       _window->get_size (_width, _height);
-               }
-       }
-
-       node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
-       
-       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
-ProxyBase::drop_window ()
-{
-       if (_window) {
-               _window->hide ();
-               delete _window;
-               _window = 0;
-               delete vistracker;
-               vistracker = 0;
-       }
-}
-
-void
-ProxyBase::use_window (Gtk::Window& win)
-{
-       drop_window ();
-       _window = &win;
-       setup ();
 }
 
 void
 ProxyBase::setup ()
 {
-       assert (_window);
-
-       vistracker = new Gtkmm2ext::VisibilityTracker (*_window);
-       _window->signal_delete_event().connect (sigc::mem_fun (*this, &ProxyBase::handle_win_event));
-
-       if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
-               /* cancel any mouse-based positioning */
-               _window->set_position (Gtk::WIN_POS_NONE);
-       }
-
-       if (_width != -1 && _height != -1) {
-               _window->set_default_size (_width, _height);
-       }
-
-       if (_x_off != -1 && _y_off != -1) {
-               _window->move (_x_off, _y_off);
-       }
+       WindowProxy::setup ();
        set_session(_session);
-}
-       
-void
-ProxyBase::show ()
-{
-       Gtk::Window* win = get (true);
-       win->show ();
-}
-
-void
-ProxyBase::maybe_show ()
-{
-       if (_visible) {
-               show ();
-       }
-}
 
-void
-ProxyBase::show_all ()
-{
-       Gtk::Window* win = get (true);
-       win->show_all ();
 }
 
-
-void
-ProxyBase::present ()
-{
-       Gtk::Window* win = get (true);
-       win->show_all ();
-       win->present ();
-
-       /* turn off any mouse-based positioning */
-       _window->set_position (Gtk::WIN_POS_NONE);
-}
-
-void
-ProxyBase::hide ()
-{
-       Gtk::Window* win = get (false);
-       if (win) {
-               save_pos_and_size();
-               win->hide ();
-       }
-}
-
-bool
-ProxyBase::handle_win_event (GdkEventAny *ev)
-{
-       hide();
-       return true;
-}
-
-void
-ProxyBase::save_pos_and_size ()
-{
-       Gtk::Window* win = get (false);
-       win->get_position (_x_off, _y_off);
-       win->get_size (_width, _height);
-}
 /*-----------------------*/
 
 ProxyTemporary::ProxyTemporary (const string& name, Gtk::Window* win)