include/sfx2/lokcomponenthelpers.hxx | 6 ++++-- sfx2/source/view/lokstarmathhelper.cxx | 25 ++++++++++++++----------- starmath/source/utility.cxx | 12 +++++++++++- sw/source/uibase/uno/unotxdoc.cxx | 2 +- 4 files changed, 30 insertions(+), 15 deletions(-)
New commits: commit fd7a84aca0c94044bbc3bfb8852a1ae5115845bf Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Feb 2 11:22:53 2022 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Feb 2 11:04:04 2022 +0100 lok: find active SmViewShell reliably ... even after SfxViewShell::Current() had been set to parent document frame's viewshell (e.g., see LOKPostAsyncEvent grabbing focus, which replaces current frame and its associated viewshell). Change-Id: If63087f4c7f3f878ada93d93cc0af6c20a6c0a62 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129323 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/sfx2/lokcomponenthelpers.hxx b/include/sfx2/lokcomponenthelpers.hxx index 114912253043..cace035b16a1 100644 --- a/include/sfx2/lokcomponenthelpers.hxx +++ b/include/sfx2/lokcomponenthelpers.hxx @@ -66,7 +66,8 @@ public: { } - vcl::Window* GetWindow(); + vcl::Window* GetGraphicWindow(); + vcl::Window* GetWidgetWindow(); bool postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier, double fScaleX = 1.0, double fScaleY = 1.0); @@ -77,7 +78,8 @@ private: SfxViewShell* mpViewShell; css::uno::Reference<css::frame::XController> mxController; - VclPtr<vcl::Window> mpWindow; + VclPtr<vcl::Window> mpGraphicWindow; + VclPtr<vcl::Window> mpWidgetWindow; }; #endif diff --git a/sfx2/source/view/lokstarmathhelper.cxx b/sfx2/source/view/lokstarmathhelper.cxx index fedd931b08fd..885decdc2fea 100644 --- a/sfx2/source/view/lokstarmathhelper.cxx +++ b/sfx2/source/view/lokstarmathhelper.cxx @@ -83,28 +83,31 @@ vcl::Window* FindChildSmGraphicWidgetWindow(vcl::Window* pWin) } return nullptr; } - -vcl::Window* FindSmGraphicWidgetWindow(vcl::Window* pWin) -{ - return FindChildSmGraphicWidgetWindow(FindSmGraphicWindow(pWin)); -} } -vcl::Window* LokStarMathHelper::GetWindow() +vcl::Window* LokStarMathHelper::GetGraphicWindow() { - if (!mpWindow) + if (!mpGraphicWindow) { if (const css::uno::Reference<css::frame::XController>& xController = GetXController()) { if (const css::uno::Reference<css::frame::XFrame> xFrame = xController->getFrame()) { css::uno::Reference<css::awt::XWindow> xDockerWin = xFrame->getContainerWindow(); - mpWindow.set(FindSmGraphicWidgetWindow(VCLUnoHelper::GetWindow(xDockerWin))); + mpGraphicWindow.set(FindSmGraphicWindow(VCLUnoHelper::GetWindow(xDockerWin))); } } } - return mpWindow.get(); + return mpGraphicWindow.get(); +} + +vcl::Window* LokStarMathHelper::GetWidgetWindow() +{ + if (!mpWidgetWindow) + mpWidgetWindow.set(FindChildSmGraphicWidgetWindow(GetGraphicWindow())); + + return mpWidgetWindow.get(); } tools::Rectangle LokStarMathHelper::GetBoundingBox() @@ -115,7 +118,7 @@ tools::Rectangle LokStarMathHelper::GetBoundingBox() { if (vcl::Window* pRootWin = pIPClient->GetEditWin()) { - if (vcl::Window* pWindow = GetWindow()) + if (vcl::Window* pWindow = GetWidgetWindow()) { // In all cases, the following code fragment // returns the bounding box in twips. @@ -143,7 +146,7 @@ tools::Rectangle LokStarMathHelper::GetBoundingBox() bool LokStarMathHelper::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier, double fScaleX, double fScaleY) { - if (vcl::Window* pWindow = GetWindow()) + if (vcl::Window* pWindow = GetWidgetWindow()) { Point aMousePos(nX, nY); tools::Rectangle rBBox = GetBoundingBox(); diff --git a/starmath/source/utility.cxx b/starmath/source/utility.cxx index eab123d7829a..e8406c10380f 100644 --- a/starmath/source/utility.cxx +++ b/starmath/source/utility.cxx @@ -23,6 +23,9 @@ #include <dialog.hxx> #include <view.hxx> +#include <comphelper/lok.hxx> +#include <sfx2/lokcomponenthelpers.hxx> + // return pointer to active SmViewShell, if this is not possible // return 0 instead. //!! Since this method is based on the current focus it is somewhat @@ -30,7 +33,14 @@ SmViewShell * SmGetActiveView() { SfxViewShell *pView = SfxViewShell::Current(); - return dynamic_cast<SmViewShell*>( pView); + SmViewShell* pSmView = dynamic_cast<SmViewShell*>(pView); + if (!pSmView && comphelper::LibreOfficeKit::isActive()) + { + auto* pWindow = static_cast<SmGraphicWindow*>(LokStarMathHelper(pView).GetGraphicWindow()); + if (pWindow) + pSmView = &pWindow->GetGraphicWidget().GetView(); + } + return pSmView; } diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 4c732f1e5dee..0950722a0f59 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3399,7 +3399,7 @@ VclPtr<vcl::Window> SwXTextDocument::getDocWindow() if (VclPtr<vcl::Window> pWindow = LokChartHelper(pView).GetWindow()) return pWindow; - if (VclPtr<vcl::Window> pWindow = LokStarMathHelper(pView).GetWindow()) + if (VclPtr<vcl::Window> pWindow = LokStarMathHelper(pView).GetWidgetWindow()) return pWindow; if (pView)