remove Glib::ustring from gtk2_ardour
[ardour.git] / gtk2_ardour / plugin_ui.cc
index a59d2f130f02d3c337ed751f9d3ee5b7bfe04753..84c95cf16e4fd5007635a4c948bb3d45212325a7 100644 (file)
@@ -73,14 +73,13 @@ using namespace ARDOUR;
 using namespace PBD;
 using namespace Gtkmm2ext;
 using namespace Gtk;
-using namespace sigc;
 
 PluginUIWindow::PluginUIWindow (Gtk::Window* win, boost::shared_ptr<PluginInsert> insert, bool scrollable)
        : parent (win)
+        , was_visible (false)
+        , _keyboard_focused (false)
 {
        bool have_gui = false;
-       non_gtk_gui = false;
-       was_visible = false;
 
        Label* label = manage (new Label());
        label->set_markup ("<b>THIS IS THE PLUGIN UI</b>");
@@ -121,7 +120,8 @@ PluginUIWindow::PluginUIWindow (Gtk::Window* win, boost::shared_ptr<PluginInsert
                GenericPluginUI*  pu  = new GenericPluginUI (insert, scrollable);
 
                _pluginui = pu;
-               add( *pu );
+               _pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
+               add (*pu);
 
                /*
                Gtk::HBox *hbox = new Gtk::HBox();
@@ -132,18 +132,18 @@ PluginUIWindow::PluginUIWindow (Gtk::Window* win, boost::shared_ptr<PluginInsert
                add (*manage(hbox));
                */
 
-               set_wmclass (X_("ardour_plugin_editor"), "Ardour");
+               set_wmclass (X_("ardour_plugin_editor"), PROGRAM_NAME);
 
-               signal_map_event().connect (mem_fun (*pu, &GenericPluginUI::start_updating));
-               signal_unmap_event().connect (mem_fun (*pu, &GenericPluginUI::stop_updating));
+               signal_map_event().connect (sigc::mem_fun (*pu, &GenericPluginUI::start_updating));
+               signal_unmap_event().connect (sigc::mem_fun (*pu, &GenericPluginUI::stop_updating));
        }
 
        // set_position (Gtk::WIN_POS_MOUSE);
        set_name ("PluginEditor");
        add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
 
-       signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
-       death_connection = insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away));
+       signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
+       insert->DropReferences.connect (death_connection, invalidator (*this), boost::bind (&PluginUIWindow::plugin_going_away, this), gui_context());
 
        gint h = _pluginui->get_preferred_height ();
        gint w = _pluginui->get_preferred_width ();
@@ -239,7 +239,7 @@ PluginUIWindow::on_hide ()
 }
 
 void
-PluginUIWindow::set_title(const Glib::ustring& title)
+PluginUIWindow::set_title(const std::string& title)
 {
        //cout << "PluginUIWindow::set_title(\"" << title << "\"" << endl;
        Gtk::Window::set_title(title);
@@ -267,11 +267,11 @@ PluginUIWindow::create_vst_editor(boost::shared_ptr<PluginInsert>)
                VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
 
                _pluginui = vpu;
+               _pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
                add (*vpu);
                vpu->package (*this);
        }
 
-       non_gtk_gui = true;
        return true;
 #endif
 }
@@ -288,11 +288,11 @@ PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert>)
 #else
        VBox* box;
        _pluginui = create_au_gui (insert, &box);
+        _pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
        add (*box);
-       non_gtk_gui = true;
 
        extern sigc::signal<void,bool> ApplicationActivationChanged;
-       ApplicationActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
+       ApplicationActivationChanged.connect (sigc::mem_fun (*this, &PluginUIWindow::app_activated));
 
        return true;
 #endif
@@ -342,27 +342,62 @@ PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
                lpu->package (*this);
        }
 
-       non_gtk_gui = false;
        return true;
 #endif
 }
 
+void
+PluginUIWindow::keyboard_focused (bool yn)
+{
+       _keyboard_focused = yn;
+}
+
 bool
 PluginUIWindow::on_key_press_event (GdkEventKey* event)
 {
-       return relay_key_press (event, this);
+       if (_keyboard_focused) {
+               if (_pluginui) {
+                        if (_pluginui->non_gtk_gui()) {
+                                _pluginui->forward_key_event (event); 
+                        } else {
+                                return relay_key_press (event, this);
+                        }
+               }
+               return true;
+       } else {
+                if (_pluginui->non_gtk_gui()) {
+                        /* pass editor window as the window for the event
+                           to be handled in, not this one, because there are
+                           no widgets in this window that we want to have
+                           key focus.
+                        */
+                        return relay_key_press (event, &PublicEditor::instance());
+                } else {
+                        return relay_key_press (event, this);
+                }
+       }
 }
 
 bool
-PluginUIWindow::on_key_release_event (GdkEventKey *)
+PluginUIWindow::on_key_release_event (GdkEventKey *event)
 {
-       return true;
+       if (_keyboard_focused) {
+               if (_pluginui) {
+                        if (_pluginui->non_gtk_gui()) {
+                                _pluginui->forward_key_event (event);
+                        } 
+                        return true;
+               }
+               return false;
+       } else {
+               return true;
+       }
 }
 
 void
 PluginUIWindow::plugin_going_away ()
 {
-       ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
+       ENSURE_GUI_THREAD (*this, &PluginUIWindow::plugin_going_away)
 
        if (_pluginui) {
                _pluginui->stop_updating(0);
@@ -385,23 +420,21 @@ PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
        update_presets();
        preset_combo.set_size_request (100, -1);
        preset_combo.set_active_text ("");
-       preset_combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
+       preset_combo.signal_changed().connect(sigc::mem_fun(*this, &PlugUIBase::setting_selected));
        no_load_preset = false;
 
        save_button.set_name ("PluginSaveButton");
-       save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
+       save_button.signal_clicked().connect(sigc::mem_fun(*this, &PlugUIBase::save_plugin_setting));
 
-       insert->ActiveChanged.connect (bind(
-                       mem_fun(*this, &PlugUIBase::processor_active_changed),
-                       boost::weak_ptr<Processor>(insert)));
+       insert->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&PlugUIBase::processor_active_changed, this,  boost::weak_ptr<Processor>(insert)), gui_context());
 
        bypass_button.set_active (!pi->active());
 
        bypass_button.set_name ("PluginBypassButton");
-       bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
+       bypass_button.signal_toggled().connect (sigc::mem_fun(*this, &PlugUIBase::bypass_toggled));
        focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
 
-       focus_button.signal_button_release_event().connect (mem_fun(*this, &PlugUIBase::focus_toggled));
+       focus_button.signal_button_release_event().connect (sigc::mem_fun(*this, &PlugUIBase::focus_toggled));
        focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
 
        /* these images are not managed, so that we can remove them at will */
@@ -411,13 +444,13 @@ PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
 
        focus_button.add (*focus_out_image);
 
-       ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
-       ARDOUR_UI::instance()->set_tip (&bypass_button, _("Click to enable/disable this plugin"), "");
+       ARDOUR_UI::instance()->set_tip (focus_button, string_compose (_("Click to allow the plugin to receive keyboard events that %1 would normally use as a shortcut"), PROGRAM_NAME));
+       ARDOUR_UI::instance()->set_tip (bypass_button, _("Click to enable/disable this plugin"));
 
-       plugin_analysis_expander.property_expanded().signal_changed().connect( mem_fun(*this, &PlugUIBase::toggle_plugin_analysis));
+       plugin_analysis_expander.property_expanded().signal_changed().connect( sigc::mem_fun(*this, &PlugUIBase::toggle_plugin_analysis));
        plugin_analysis_expander.set_expanded(false);
-
-       insert->GoingAway.connect (mem_fun (*this, &PlugUIBase::plugin_going_away));
+       
+       insert->DropReferences.connect (death_connection, invalidator (*this), boost::bind (&PlugUIBase::plugin_going_away, this), gui_context());
 }
 
 PlugUIBase::~PlugUIBase()
@@ -431,6 +464,7 @@ PlugUIBase::plugin_going_away ()
        /* drop references to the plugin/insert */
        insert.reset ();
        plugin.reset ();
+       death_connection.disconnect ();
 }
 
 void
@@ -456,7 +490,7 @@ PlugUIBase::latency_button_clicked ()
                latency_gui = new LatencyGUI (*(insert.get()), insert->session().frame_rate(), insert->session().get_block_size());
                latency_dialog = new ArdourDialog ("Edit Latency", false, false);
                latency_dialog->get_vbox()->pack_start (*latency_gui);
-               latency_dialog->signal_hide().connect (mem_fun (*this, &PlugUIBase::set_latency_label));
+               latency_dialog->signal_hide().connect (sigc::mem_fun (*this, &PlugUIBase::set_latency_label));
        }
 
        latency_dialog->show_all ();
@@ -465,7 +499,7 @@ PlugUIBase::latency_button_clicked ()
 void
 PlugUIBase::processor_active_changed (boost::weak_ptr<Processor> weak_p)
 {
-       ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlugUIBase::processor_active_changed), weak_p));
+       ENSURE_GUI_THREAD (*this, &PlugUIBase::processor_active_changed, weak_p)
        boost::shared_ptr<Processor> p (weak_p);
        if (p) {
                bypass_button.set_active (!p->active());
@@ -540,13 +574,15 @@ PlugUIBase::focus_toggled (GdkEventButton*)
                focus_button.remove ();
                focus_button.add (*focus_out_image);
                focus_out_image->show ();
-               ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
+               ARDOUR_UI::instance()->set_tip (focus_button, string_compose (_("Click to allow the plugin to receive keyboard events that %1 would normally use as a shortcut"), PROGRAM_NAME));
+               KeyboardFocused (false);
        } else {
                Keyboard::the_keyboard().magic_widget_grab_focus();
                focus_button.remove ();
                focus_button.add (*focus_in_image);
                focus_in_image->show ();
-               ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow normal use of Ardour keyboard shortcuts"), "");
+               ARDOUR_UI::instance()->set_tip (focus_button, string_compose (_("Click to allow normal use of %1 keyboard shortcuts"), PROGRAM_NAME));
+               KeyboardFocused (true);
        }
 
        return true;