diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-07-18 20:46:36 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-10-11 21:36:08 +0200 |
commit | f016af33cc1b6e5f1a617ccaa37c2e3d6c81678f (patch) | |
tree | d9f66662888f266ff60d42b9f4bbc2fc7df2252c | |
parent | e04fb52e8cdc8811c90f7c3492caa87c03ea6c67 (diff) |
lok: ensure that dialog windows are focused before emitting events.
Otherwise, we can emit events on a different view's window, causing
problems, and cross-user interference. Also emit the key-event on
the focused sub-window so event bubbling works.
Change-Id: I9dd16c2a256bae58d754f94c6d94a1f3fcdb800b
Reviewed-on: https://gerrit.libreoffice.org/80659
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r-- | include/vcl/window.hxx | 1 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 25 | ||||
-rw-r--r-- | vcl/source/window/window.cxx | 8 |
3 files changed, 24 insertions, 10 deletions
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx index 965bc79f65c7..58dad46aeef2 100644 --- a/include/vcl/window.hxx +++ b/include/vcl/window.hxx @@ -1088,6 +1088,7 @@ public: bool HasActiveChildFrame() const; GetFocusFlags GetGetFocusFlags() const; void GrabFocusToDocument(); + VclPtr<vcl::Window> GetFocusedWindow() const; /** * Set this when you need to act as if the window has focus even if it diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index b7a4b238f18b..4224c54a3df7 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -317,24 +317,29 @@ namespace SfxLokHelper::setView(pLOKEv->mnView); } + if (!pLOKEv->mpWindow->HasChildPathFocus(true)) + { + SAL_INFO("sfx.view", "LOK - focus mismatch, switching focus"); + pLOKEv->mpWindow->GrabFocus(); + } + + VclPtr<vcl::Window> pFocusWindow = pLOKEv->mpWindow->GetFocusedWindow(); + if (!pFocusWindow) + pFocusWindow = pLOKEv->mpWindow; + switch (pLOKEv->mnEvent) { case VclEventId::WindowKeyInput: { sal_uInt16 nRepeat = pLOKEv->maKeyEvent.GetRepeat(); - if (nRepeat > 0) - { - KeyEvent singlePress(pLOKEv->maKeyEvent.GetCharCode(), - pLOKEv->maKeyEvent.GetKeyCode()); - for (sal_uInt16 i = 0; i <= nRepeat; ++i) - pLOKEv->mpWindow->KeyInput(singlePress); - } - else - pLOKEv->mpWindow->KeyInput(pLOKEv->maKeyEvent); + KeyEvent singlePress(pLOKEv->maKeyEvent.GetCharCode(), + pLOKEv->maKeyEvent.GetKeyCode()); + for (sal_uInt16 i = 0; i <= nRepeat; ++i) + pFocusWindow->KeyInput(singlePress); break; } case VclEventId::WindowKeyUp: - pLOKEv->mpWindow->KeyUp(pLOKEv->maKeyEvent); + pFocusWindow->KeyUp(pLOKEv->maKeyEvent); break; case VclEventId::WindowMouseButtonDown: pLOKEv->mpWindow->LogicMouseButtonDown(pLOKEv->maMouseEvent); diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 05fe9b8ff9e3..b09158b9b16c 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -2992,6 +2992,14 @@ void Window::GrabFocusToDocument() ImplGrabFocusToDocument(GetFocusFlags::NONE); } +VclPtr<vcl::Window> Window::GetFocusedWindow() const +{ + if (mpWindowImpl && mpWindowImpl->mpFrameData) + return mpWindowImpl->mpFrameData->mpFocusWin; + else + return VclPtr<vcl::Window>(); +} + void Window::SetFakeFocus( bool bFocus ) { ImplGetWindowImpl()->mbFakeFocusSet = bFocus; |