A widget being hidden must remove its focus grab with GTK+, otherwise GTK+
would continue sending all input messages to it but fail to process them
because the widget is not realized any more, resulting in a complete freeze of
the entire program.
Do it when detaching menus from menubar and menubar from the frame to fix just
such a problem in case SetMenuBar() was called while the previous menubar was
opened.
Closes #15221.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74056 
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
+// This should be called when detaching menus to ensure that they don't keep
+// focus grab, because if they do, they continue getting all GTK+ messages
+// which they can't process any more in their (soon to be) unrealized state.
+void
+EnsureNoGrab(GtkWidget* widget)
+{
+#if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
+    gtk_widget_hide(widget);
+    gtk_grab_remove(widget);
+#endif // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
+}
+
 void
 DetachFromFrame(wxMenu* menu, wxFrame* frame)
 {
 void
 DetachFromFrame(wxMenu* menu, wxFrame* frame)
 {
             DetachFromFrame(menuitem->GetSubMenu(), frame);
         node = node->GetNext();
     }
             DetachFromFrame(menuitem->GetSubMenu(), frame);
         node = node->GetNext();
     }
+
+    EnsureNoGrab(menu->m_menu);
         node = node->GetNext();
     }
 
         node = node->GetNext();
     }
 
+    EnsureNoGrab(m_widget);
+
     wxMenuBarBase::Detach();
 }
 
     wxMenuBarBase::Detach();
 }