diff options
-rw-r--r-- | include/sfx2/lokcomponenthelpers.hxx | 15 | ||||
-rw-r--r-- | sfx2/source/view/lokstarmathhelper.cxx | 86 | ||||
-rw-r--r-- | starmath/source/view.cxx | 3 |
3 files changed, 32 insertions, 72 deletions
diff --git a/include/sfx2/lokcomponenthelpers.hxx b/include/sfx2/lokcomponenthelpers.hxx index ea81ea8f87c1..b26cd0a13fb8 100644 --- a/include/sfx2/lokcomponenthelpers.hxx +++ b/include/sfx2/lokcomponenthelpers.hxx @@ -18,8 +18,10 @@ namespace com::sun::star::beans { struct PropertyValue; } namespace com::sun::star::frame { class XController; } namespace com::sun::star::frame { class XDispatch; } +namespace com::sun::star::frame { class XFrame; } namespace com::sun::star::uno { template<class E> class Sequence; } +class SfxInPlaceClient; class SfxViewShell; class VirtualDevice; @@ -66,25 +68,20 @@ public: class SFX2_DLLPUBLIC LokStarMathHelper { public: - LokStarMathHelper(const SfxViewShell* pViewShell) - : mpViewShell(pViewShell) - { - } + LokStarMathHelper(const SfxViewShell* pViewShell); vcl::Window* GetGraphicWindow(); vcl::Window* GetWidgetWindow(); - void Dispatch(const OUString& cmd, const css::uno::Sequence<css::beans::PropertyValue>& rArguments); + void Dispatch(const OUString& cmd, const css::uno::Sequence<css::beans::PropertyValue>& rArguments) const; bool postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier, double fScaleX = 1.0, double fScaleY = 1.0); private: - css::uno::Reference<css::frame::XController>& GetXController(); - tools::Rectangle GetBoundingBox(); - const SfxViewShell* mpViewShell; - css::uno::Reference<css::frame::XController> mxController; + const SfxInPlaceClient* mpIPClient = nullptr; // not nullptr when the object is valid + css::uno::Reference<css::frame::XFrame> mxFrame; // not empty when the object is valid VclPtr<vcl::Window> mpGraphicWindow; VclPtr<vcl::Window> mpWidgetWindow; }; diff --git a/sfx2/source/view/lokstarmathhelper.cxx b/sfx2/source/view/lokstarmathhelper.cxx index 9a704683aaec..fb30d9cee449 100644 --- a/sfx2/source/view/lokstarmathhelper.cxx +++ b/sfx2/source/view/lokstarmathhelper.cxx @@ -23,9 +23,10 @@ #include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -css::uno::Reference<css::frame::XController>& LokStarMathHelper::GetXController() +LokStarMathHelper::LokStarMathHelper(const SfxViewShell* pViewShell) + : mpViewShell(pViewShell) { - if (!mxController && mpViewShell) + if (mpViewShell) { if (const SfxInPlaceClient* pIPClient = mpViewShell->GetIPClient()) { @@ -34,22 +35,27 @@ css::uno::Reference<css::frame::XController>& LokStarMathHelper::GetXController( css::uno::Reference<css::lang::XServiceInfo> xComp(xEmbObj->getComponent(), css::uno::UNO_QUERY); if (xComp && xComp->supportsService("com.sun.star.formula.FormulaProperties")) + { if (css::uno::Reference<css::frame::XModel> xModel{ xComp, css::uno::UNO_QUERY }) - mxController = xModel->getCurrentController(); + { + if (auto xController = xModel->getCurrentController()) + { + mpIPClient = pIPClient; + mxFrame = xController->getFrame(); + } + } + } } } } - - return mxController; } -void LokStarMathHelper::Dispatch(const OUString& cmd, - const css::uno::Sequence<css::beans::PropertyValue>& rArguments) +void LokStarMathHelper::Dispatch( + const OUString& cmd, const css::uno::Sequence<css::beans::PropertyValue>& rArguments) const { - if (const css::uno::Reference<css::frame::XController>& xController = GetXController()) - if (const css::uno::Reference<css::frame::XFrame> xFrame = xController->getFrame()) - comphelper::dispatchCommand(cmd, xFrame, rArguments); + if (mxFrame) + comphelper::dispatchCommand(cmd, mxFrame, rArguments); } namespace @@ -98,13 +104,10 @@ vcl::Window* LokStarMathHelper::GetGraphicWindow() { if (!mpGraphicWindow) { - if (const css::uno::Reference<css::frame::XController>& xController = GetXController()) + if (mxFrame) { - if (const css::uno::Reference<css::frame::XFrame> xFrame = xController->getFrame()) - { - css::uno::Reference<css::awt::XWindow> xDockerWin = xFrame->getContainerWindow(); - mpGraphicWindow.set(FindSmGraphicWindow(VCLUnoHelper::GetWindow(xDockerWin))); - } + css::uno::Reference<css::awt::XWindow> xDockerWin = mxFrame->getContainerWindow(); + mpGraphicWindow.set(FindSmGraphicWindow(VCLUnoHelper::GetWindow(xDockerWin))); } } @@ -119,59 +122,18 @@ vcl::Window* LokStarMathHelper::GetWidgetWindow() return mpWidgetWindow.get(); } -tools::Rectangle LokStarMathHelper::GetBoundingBox() -{ - if (mpViewShell) - { - if (SfxInPlaceClient* pIPClient = mpViewShell->GetIPClient()) - { - if (vcl::Window* pRootWin = pIPClient->GetEditWin()) - { - if (vcl::Window* pWindow = GetWidgetWindow()) - { - // In all cases, the following code fragment - // returns the bounding box in twips. - // Note: the correct mapmode (representing document zoom) is provided by - // GraphicWindow, not WidgetWindow - const MapMode& aMapMode = GetGraphicWindow()->GetMapMode(); - const auto & [ m, d ] - = o3tl::getConversionMulDiv(o3tl::Length::px, o3tl::Length::twip); - const Fraction& scaleX = aMapMode.GetScaleX(); - const Fraction& scaleY = aMapMode.GetScaleY(); - const auto nXNum = m * scaleX.GetDenominator(); - const auto nXDen = d * scaleX.GetNumerator(); - const auto nYNum = m * scaleY.GetDenominator(); - const auto nYDen = d * scaleY.GetNumerator(); - - Point aOffset - = pWindow->GetOffsetPixelFrom(*pRootWin).scale(nXNum, nXDen, nYNum, nYDen); - Size aSize = pWindow->GetSizePixel().scale(nXNum, nXDen, nYNum, nYDen); - return { aOffset, aSize }; - } - } - } - } - return {}; -} - bool LokStarMathHelper::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, - int nModifier, double fScaleX, double fScaleY) + int nModifier, double /*fScaleX*/, double /*fScaleY*/) { if (vcl::Window* pWindow = GetWidgetWindow()) { Point aMousePos(nX, nY); - tools::Rectangle rBBox = GetBoundingBox(); + tools::Rectangle rBBox = mpIPClient->GetObjArea(); if (rBBox.Contains(aMousePos)) { - int nWinX = nX - rBBox.Left(); - int nWinY = nY - rBBox.Top(); - - // window expects pixels, but the conversion factor - // can depend on the client zoom - Point aPos(nWinX * fScaleX, nWinY * fScaleY); - - LokMouseEventData aMouseEventData(nType, aPos, nCount, MouseEventModifiers::SIMPLECLICK, - nButtons, nModifier); + aMousePos -= rBBox.TopLeft(); + LokMouseEventData aMouseEventData( + nType, aMousePos, nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier); SfxLokHelper::postMouseEventAsync(pWindow, aMouseEventData); return true; diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx index 21ff5afce349..dd6e5f40b3b7 100644 --- a/starmath/source/view.cxx +++ b/starmath/source/view.cxx @@ -309,7 +309,8 @@ void SmGraphicWidget::SetDrawingArea(weld::DrawingArea* pDrawingArea) rDevice.SetBackground(SM_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor); const Fraction aFraction(1, 1); - rDevice.SetMapMode(MapMode(MapUnit::Map100thMM, Point(), aFraction, aFraction)); + MapUnit unit = comphelper::LibreOfficeKit::isActive() ? MapUnit::MapPixel : MapUnit::Map100thMM; + rDevice.SetMapMode(MapMode(unit, Point(), aFraction, aFraction)); SetTotalSize(); |