include/sfx2/lokcomponenthelpers.hxx   |    6 +++
 sd/source/ui/unoidl/unomodel.cxx       |    2 +
 sfx2/source/view/lokstarmathhelper.cxx |   59 +++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+)

New commits:
commit f111677519a22fa3341938ab7de5b5de973350b1
Author:     Mike Kaganski <[email protected]>
AuthorDate: Tue Nov 22 17:40:26 2022 +0300
Commit:     Mike Kaganski <[email protected]>
CommitDate: Wed Nov 23 05:27:20 2022 +0100

    lok: draw Math in-place widget in sd
    
    Change-Id: If874c0227ec724fa5b1517080db252e64f9597c5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143121
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    (cherry picked from commit d19816350dba8daffa2deb495d4e697062579456)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143071
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/include/sfx2/lokcomponenthelpers.hxx 
b/include/sfx2/lokcomponenthelpers.hxx
index a58e154e36d6..1ab9a8fc9c91 100644
--- a/include/sfx2/lokcomponenthelpers.hxx
+++ b/include/sfx2/lokcomponenthelpers.hxx
@@ -81,7 +81,13 @@ public:
     bool postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, 
int nModifier,
                         double fPPTScaleX, double fPPTScaleY);
 
+    static void PaintAllInPlaceOnTile(VirtualDevice& rDevice, int 
nOutputWidth, int nOutputHeight,
+                                      int nTilePosX, int nTilePosY, 
tools::Long nTileWidth,
+                                      tools::Long nTileHeight);
+
 private:
+    void PaintTile(VirtualDevice& rDevice, const tools::Rectangle& rTileRect);
+
     const SfxViewShell* mpViewShell;
     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
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 122eed77f003..9bc5d2667fae 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2283,6 +2283,8 @@ void SdXImpressDocument::paintTile( VirtualDevice& 
rDevice,
 
     LokChartHelper::PaintAllChartsOnTile(rDevice, nOutputWidth, nOutputHeight,
                                          nTilePosX, nTilePosY, nTileWidth, 
nTileHeight);
+    LokStarMathHelper::PaintAllInPlaceOnTile(rDevice, nOutputWidth, 
nOutputHeight, nTilePosX,
+                                             nTilePosY, nTileWidth, 
nTileHeight);
 
     if(patchedPageWindow != nullptr)
         patchedPageWindow->unpatchPaintWindow(previousPaintWindow);
diff --git a/sfx2/source/view/lokstarmathhelper.cxx 
b/sfx2/source/view/lokstarmathhelper.cxx
index 5586068d88b7..9b2df19ecdec 100644
--- a/sfx2/source/view/lokstarmathhelper.cxx
+++ b/sfx2/source/view/lokstarmathhelper.cxx
@@ -15,10 +15,12 @@
 #include <sfx2/objsh.hxx>
 
 #include <comphelper/dispatchcommand.hxx>
+#include <comphelper/lok.hxx>
 #include <toolkit/helper/vclunohelper.hxx>
 #include <tools/fract.hxx>
 #include <tools/UnitConversion.hxx>
 #include <vcl/layout.hxx>
+#include <vcl/virdev.hxx>
 #include <vcl/window.hxx>
 
 #include <com/sun/star/embed/XEmbeddedObject.hpp>
@@ -185,4 +187,61 @@ bool LokStarMathHelper::postMouseEvent(int nType, int nX, 
int nY, int nCount, in
     return false;
 }
 
+void LokStarMathHelper::PaintTile(VirtualDevice& rDevice, const 
tools::Rectangle& rTileRect)
+{
+    const tools::Rectangle aMathRect = GetBoundingBox();
+    if (rTileRect.GetIntersection(aMathRect).IsEmpty())
+        return;
+
+    vcl::Window* pWidgetWindow = GetWidgetWindow();
+    if (!pWidgetWindow)
+        return;
+
+    Point aOffset(aMathRect.Left() - rTileRect.Left(), aMathRect.Top() - 
rTileRect.Top());
+
+    MapMode newMode = rDevice.GetMapMode();
+    newMode.SetOrigin(aOffset);
+    rDevice.SetMapMode(newMode); // Push/Pop is done in PaintAllInPlaceOnTile
+
+    pWidgetWindow->Paint(rDevice, {}); // SmGraphicWidget::Paint does not use 
the passed rectangle
+}
+
+void LokStarMathHelper::PaintAllInPlaceOnTile(VirtualDevice& rDevice, int 
nOutputWidth,
+                                              int nOutputHeight, int 
nTilePosX, int nTilePosY,
+                                              tools::Long nTileWidth, 
tools::Long nTileHeight)
+{
+    if (comphelper::LibreOfficeKit::isTiledAnnotations())
+        return;
+
+    SfxViewShell* pCurView = SfxViewShell::Current();
+    if (!pCurView)
+        return;
+    const ViewShellDocId nDocId = pCurView->GetDocId();
+    const int nPartForCurView = pCurView->getPart();
+
+    // Resizes the virtual device to contain the entries context
+    rDevice.SetOutputSizePixel({ nOutputWidth, nOutputHeight });
+
+    rDevice.Push(vcl::PushFlags::MAPMODE);
+    MapMode aMapMode(rDevice.GetMapMode());
+
+    // Scaling. Must convert from pixels to twips. We know that VirtualDevices 
use a DPI of 96.
+    const Fraction scale = conversionFract(o3tl::Length::px, 
o3tl::Length::twip);
+    const Fraction scaleX = Fraction(nOutputWidth, nTileWidth) * scale;
+    const Fraction scaleY = Fraction(nOutputHeight, nTileHeight) * scale;
+    aMapMode.SetScaleX(scaleX);
+    aMapMode.SetScaleY(scaleY);
+    aMapMode.SetMapUnit(MapUnit::MapTwip);
+    rDevice.SetMapMode(aMapMode);
+
+    const tools::Rectangle aTileRect(Point(nTilePosX, nTilePosY), 
Size(nTileWidth, nTileHeight));
+
+    for (SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell;
+         pViewShell = SfxViewShell::GetNext(*pViewShell))
+        if (pViewShell->GetDocId() == nDocId && pViewShell->getPart() == 
nPartForCurView)
+            LokStarMathHelper(pViewShell).PaintTile(rDevice, aTileRect);
+
+    rDevice.Pop();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to