summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vcl/source/window/menubarwindow.cxx19
1 files changed, 12 insertions, 7 deletions
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();
}
}