vcl/source/window/menubarwindow.cxx |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

New commits:
commit bff36583c7be2eb4112adfb778d19a308b458ca8
Author: Maxim Monastirsky <momonas...@gmail.com>
Date:   Wed May 9 23:52:00 2018 +0300

    tdf#117440 Can't move focus to disposed window
    
    xSaveFocusId is the already disposed comments floating window,
    so it can't accept focus anymore. Moreover, if closing the
    menu by clicking its title, the focus results nowhere, and no
    keyboard interaction works at all (including e.g. F6 or F10).
    
    This patch makes the focus switch back to the document, like
    it was in earlier LO versions. And does it in a way that
    doesn't break tdf#115227.
    
    Change-Id: I1d473557c10faf65b5b1fa917f5a5d66d0de8656
    Reviewed-on: https://gerrit.libreoffice.org/55457
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Maxim Monastirsky <momonas...@gmail.com>

diff --git a/vcl/source/window/menubarwindow.cxx 
b/vcl/source/window/menubarwindow.cxx
index c264e89fba0a..e2d6660dd7af 100644
--- a/vcl/source/window/menubarwindow.cxx
+++ b/vcl/source/window/menubarwindow.cxx
@@ -514,20 +514,25 @@ void MenuBarWindow::ChangeHighlightItem( sal_uInt16 n, 
bool bSelectEntry, bool b
         ImplGetSVData()->maWinData.mbNoDeactivate = false;
         if( !ImplGetSVData()->maWinData.mbNoSaveFocus )
         {
-            VclPtr<vcl::Window> xTempFocusId = xSaveFocusId;
+            VclPtr<vcl::Window> xTempFocusId;
+            if (xSaveFocusId && !xSaveFocusId->isDisposed())
+                xTempFocusId = xSaveFocusId;
             xSaveFocusId = nullptr;
+
             if (bAllowRestoreFocus)
             {
                 // tdf#115227 the popup is already killed, so temporarily set 
us as the
                 // focus window, so we could avoid sending superfluous 
activate events
                 // to top window listeners.
-                ImplGetSVData()->maWinData.mpFocusWin = this;
-                Window::EndSaveFocus(xTempFocusId);
-                assert(xTempFocusId == nullptr || 
ImplGetSVData()->maWinData.mpFocusWin != this);
+                if (xTempFocusId || bDefaultToDocument)
+                    ImplGetSVData()->maWinData.mpFocusWin = this;
+
+                // #105406# restore focus to document if we could not save 
focus before
+                if (!xTempFocusId && bDefaultToDocument)
+                    GrabFocusToDocument();
+                else
+                    Window::EndSaveFocus(xTempFocusId);
             }
-            // #105406# restore focus to document if we could not save focus 
before
-            if (bDefaultToDocument && xTempFocusId == nullptr && 
bAllowRestoreFocus)
-                GrabFocusToDocument();
         }
     }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to