summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-11-02 07:39:47 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-11-02 15:35:09 +0100
commit1f231147e021dae0cb94a88e762eb79ca29bf0d4 (patch)
treea0a8d13e71314a5a88c86767cd3ddac102c52569
parent80e09853e5f60f292d00e57b5f6d5f2962e49147 (diff)
Simplify LokStarMathHelper
SfxInPlaceClient seems to have everything needed to check the OLE bounds; OTOH, the embedded Math windows/widgets lack that info. Set SmGraphicWidget MapMode to pixels when lok is active, as other windows do. Change-Id: Ib9b76a51a2d9253c20b782e8c53fbfa5dc776eca Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142130 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142154 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r--include/sfx2/lokcomponenthelpers.hxx15
-rw-r--r--sfx2/source/view/lokstarmathhelper.cxx86
-rw-r--r--starmath/source/view.cxx3
3 files changed, 32 insertions, 72 deletions
diff --git a/include/sfx2/lokcomponenthelpers.hxx b/include/sfx2/lokcomponenthelpers.hxx
index 5f9f5d45d091..f45cff69a03d 100644
--- a/include/sfx2/lokcomponenthelpers.hxx
+++ b/include/sfx2/lokcomponenthelpers.hxx
@@ -17,10 +17,12 @@
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; }
namespace rtl { class OUString; }
namespace vcl { class Window; }
+class SfxInPlaceClient;
class SfxViewShell;
class VirtualDevice;
@@ -67,25 +69,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 rtl::OUString& cmd, const css::uno::Sequence<css::beans::PropertyValue>& rArguments);
+ void Dispatch(const rtl::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 7ebd822c7ed3..98397b55d4c7 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -308,7 +308,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();