change API for CairoWidget::focus_handler
[ardour.git] / gtk2_ardour / editor_actions.cc
index 008a4d75dcd17d85113c9896fe2f2f05b92bde1b..280bc3f9cb67517eb4b388126d37ebabde15fa68 100644 (file)
@@ -1739,9 +1739,40 @@ Editor::parameter_changed (std::string p)
 }
 
 void
-Editor::reset_focus ()
+Editor::reset_focus (Gtk::Widget* w)
 {
-       _track_canvas->grab_focus();
+       /* this resets focus to the first focusable parent of the given widget,
+        * or, if there is no focusable parent, cancels focus in the toplevel
+        * window that the given widget is packed into (if there is one).
+        */
+
+       if (!w) {
+               return;
+       }
+
+       Gtk::Widget* top = w->get_toplevel();
+
+       if (!top || !top->is_toplevel()) {
+               return;
+       }
+
+       w = w->get_parent ();
+
+       while (w) {
+               if (w->get_can_focus ()) {
+                       Window* win = dynamic_cast<Window*> (top);
+                       win->set_focus (*w);
+                       return;
+               }
+               w = w->get_parent ();
+       }
+
+       /* no focusable parent found, cancel focus in top level window.
+          C++ API cannot be used for this. Thanks, references.
+        */
+
+       gtk_window_set_focus (GTK_WINDOW(top->gobj()), 0);
+
 }
 
 void