sc/source/ui/drawfunc/fusel.cxx              |    3 -
 sc/source/ui/inc/viewdata.hxx                |    1 
 sc/source/ui/unoobj/docuno.cxx               |   12 +++-
 sc/source/ui/view/drawview.cxx               |   12 ++++
 sc/source/ui/view/gridwin4.cxx               |   70 ++++++++++++++++++++++++++-
 sc/source/ui/view/tabvwsh2.cxx               |    6 +-
 sc/source/ui/view/viewdata.cxx               |   15 +++++
 svx/source/sdr/contact/viewobjectcontact.cxx |    1 
 svx/source/svdraw/svdmrkv.cxx                |    3 -
 9 files changed, 116 insertions(+), 7 deletions(-)

New commits:
commit 345f9480618d0867f6b42a83a7ae1d62c8ef9c0c
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Jun 18 18:09:19 2020 +0530
Commit:     Dennis Francis <dennis.fran...@collabora.com>
CommitDate: Mon Jul 6 18:05:59 2020 +0200

    scPrintTwipsMsgs: Use print logical coordinates for draw objects
    
    as a result LOK_CALLBACK_GRAPHIC(_VIEW)_SELECTION messages will now be
    in print-twips.
    
    For tile-rendering, it needs the pixel-aligned coordinates of each
    object. The translation of print coordinates to pixel-aligned
    coordinates can be done behind the scenes by the
    ViewContact/ObjectContact/ViewObjectContact objects associated with the
    draw object which uses the cached "grid-offset" for each object
    (introduced in the patch "Refactor calc non-linear ViewToDevice
    transform"). For doing this, a subclass of FmFormView with a specialized
    "createViewSpecificObjectContact" method is used for tile-rendering. The
    createViewSpecificObjectContact creates a "proxy" object-contact object
    that delegates the grid-offsets queries to the actual ScDrawView
    generated ObjectContact. This is needed because currently there is no
    way to share the ObjectContact/ViewObjectContact instances between
    different SdrPaintWindow's without making changes ~everywhere.
    
    Change-Id: Ifdfb623c8d6dd81700ec4a5dfeeb6b2391a96154
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98166
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Dennis Francis <dennis.fran...@collabora.com>

diff --git a/sc/source/ui/drawfunc/fusel.cxx b/sc/source/ui/drawfunc/fusel.cxx
index bb82aa3459bd..e3c306574a73 100644
--- a/sc/source/ui/drawfunc/fusel.cxx
+++ b/sc/source/ui/drawfunc/fusel.cxx
@@ -338,7 +338,8 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt)
     }
 
     sal_uInt16 nDrgLog = sal_uInt16 ( 
pWindow->PixelToLogic(Size(SC_MINDRAGMOVE,0)).Width() );
-    Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
+    auto aLogicPosition = rMEvt.getLogicPosition();
+    Point aPnt(aLogicPosition ? *aLogicPosition : 
pWindow->PixelToLogic(rMEvt.GetPosPixel()));
 
     bool bCopy = false;
     ScViewData& rViewData = rViewShell.GetViewData();
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index f14b2be781db..b35724e4097e 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -606,6 +606,7 @@ public:
     Point           GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScVSplitPos 
eWhich ) const;
     /// returns the position (top-left corner) of the requested cell in print 
twips coordinates.
     Point           GetPrintTwipsPos( SCCOL nCol, SCROW nRow ) const;
+    Point           GetPrintTwipsPosFromTileTwips(const Point& rTileTwipsPos) 
const;
 
     /// return json for our cursor position.
     OString         describeCellCursor() const { return 
describeCellCursorAt(GetCurX(), GetCurY()); }
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 63aaf55bc3e6..20730f1912ea 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -909,12 +909,20 @@ void ScModelObj::setClientZoom(int nTilePixelWidth_, int 
nTilePixelHeight_, int
     if (!pViewData)
         return;
 
-    pViewData->SetZoom(Fraction(nTilePixelWidth_ * TWIPS_PER_PIXEL, 
nTileTwipWidth_),
-                       Fraction(nTilePixelHeight_ * TWIPS_PER_PIXEL, 
nTileTwipHeight_), true);
+    const Fraction newZoomX(nTilePixelWidth_ * TWIPS_PER_PIXEL, 
nTileTwipWidth_);
+    const Fraction newZoomY(nTilePixelHeight_ * TWIPS_PER_PIXEL, 
nTileTwipHeight_);
+
+    if (pViewData->GetZoomX() == newZoomX && pViewData->GetZoomY() == newZoomY)
+        return;
+
+    pViewData->SetZoom(newZoomX, newZoomY, true);
 
     // refresh our view's take on other view's cursors & selections
     pViewData->GetActiveWin()->updateKitOtherCursors();
     pViewData->GetActiveWin()->updateOtherKitSelections();
+
+    if (ScDrawView* pDrawView = pViewData->GetScDrawView())
+        pDrawView->resetGridOffsetsForAllSdrPageViews();
 }
 
 OUString ScModelObj::getRowColumnHeaders(const tools::Rectangle& rRectangle)
diff --git a/sc/source/ui/view/drawview.cxx b/sc/source/ui/view/drawview.cxx
index 992e716e0657..c7d12df62209 100644
--- a/sc/source/ui/view/drawview.cxx
+++ b/sc/source/ui/view/drawview.cxx
@@ -997,6 +997,11 @@ bool ScDrawView::calculateGridOffsetForSdrObject(
     SdrObject& rSdrObject,
     basegfx::B2DVector& rTarget) const
 {
+    if (comphelper::LibreOfficeKit::isActive() &&
+            !comphelper::LibreOfficeKit::isCompatFlagSet(
+                    comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
+        return false;
+
     ScGridWindow* pGridWin(pViewData->GetActiveWin());
 
     if(nullptr == pGridWin)
@@ -1179,6 +1184,13 @@ namespace sdr
 
         bool ObjectContactOfScDrawView::supportsGridOffsets() const
         {
+            // Except when scPrintTwipsMsgs flag is active,
+            // Calc in LOK mode directly sets pixel-aligned logical 
coordinates for draw-objects.
+            if (comphelper::LibreOfficeKit::isActive() &&
+                !comphelper::LibreOfficeKit::isCompatFlagSet(
+                    comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
+                return false;
+
             // no GridOffset support for printer
             if(isOutputToPrinter())
             {
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 2a1ac2439b65..b0b262f8f927 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -35,6 +35,11 @@
 #include <sfx2/lokhelper.hxx>
 
 #include <svx/svdview.hxx>
+#include <svx/svdpagv.hxx>
+#include <svx/sdrpagewindow.hxx>
+#include <svx/sdr/contact/objectcontactofpageview.hxx>
+#include <svx/sdr/contact/viewobjectcontact.hxx>
+#include <svx/sdr/contact/viewcontact.hxx>
 #include <tabvwsh.hxx>
 
 #include <gridwin.hxx>
@@ -1247,6 +1252,63 @@ namespace
         nTopLeftTileIndex = nStartIndex;
         nBottomRightTileIndex = nEndIndex;
     }
+
+    class ScLOKProxyObjectContact final : public 
sdr::contact::ObjectContactOfPageView
+    {
+    private:
+        sdr::contact::ObjectContact& mrRealObjectContact;
+
+    public:
+        explicit ScLOKProxyObjectContact(
+            sdr::contact::ObjectContact& rRealOC,
+            SdrPageWindow& rPageWindow,
+            const sal_Char* pDebugName) :
+            ObjectContactOfPageView(rPageWindow, pDebugName),
+            mrRealObjectContact(rRealOC)
+        {
+        }
+
+        virtual bool supportsGridOffsets() const override { return true; }
+
+        virtual void calculateGridOffsetForViewOjectContact(
+            basegfx::B2DVector& rTarget,
+            const sdr::contact::ViewObjectContact& rClient) const override
+        {
+            SdrObject* 
pTargetSdrObject(rClient.GetViewContact().TryToGetSdrObject());
+            if (pTargetSdrObject)
+                rTarget = 
pTargetSdrObject->GetViewContact().GetViewObjectContact(mrRealObjectContact).getGridOffset();
+        }
+    };
+
+    class ScLOKDrawView : public FmFormView
+    {
+    public:
+        ScLOKDrawView(OutputDevice* pOut, ScViewData* pData) :
+            FmFormView(*pData->GetDocument()->GetDrawLayer(), pOut),
+            pScDrawView(pData ? pData->GetScDrawView() : nullptr)
+        {
+        }
+
+        virtual sdr::contact::ObjectContact* createViewSpecificObjectContact(
+                SdrPageWindow& rPageWindow, const sal_Char* pDebugName) const 
override
+        {
+            if (!pScDrawView)
+                return SdrView::createViewSpecificObjectContact(rPageWindow, 
pDebugName);
+
+            SdrPageView* pPageView(pScDrawView->GetSdrPageView());
+            if (!pPageView)
+                return SdrView::createViewSpecificObjectContact(rPageWindow, 
pDebugName);
+
+            SdrPageWindow* pSdrPageWindow = pPageView->GetPageWindow(0);
+            if (!pSdrPageWindow)
+                return SdrView::createViewSpecificObjectContact(rPageWindow, 
pDebugName);
+
+            return new 
ScLOKProxyObjectContact(pSdrPageWindow->GetObjectContact(), rPageWindow, 
pDebugName);
+        }
+
+    private:
+        ScDrawView* pScDrawView;
+    };
 } // anonymous namespace
 
 void ScGridWindow::PaintTile( VirtualDevice& rDevice,
@@ -1367,7 +1429,12 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
     ScDrawLayer* pModel = pDoc->GetDrawLayer();
     if (pModel)
     {
-        mpLOKDrawView.reset(
+        bool bPrintTwipsMsgs = comphelper::LibreOfficeKit::isCompatFlagSet(
+                comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs);
+        mpLOKDrawView.reset(bPrintTwipsMsgs ?
+            new ScLOKDrawView(
+                &rDevice,
+                pViewData) :
             new FmFormView(
                 *pModel,
                 &rDevice));
@@ -1378,7 +1445,6 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
 
     // draw the content
     DrawContent(rDevice, aTabInfo, aOutputData, true);
-
     rDevice.SetMapMode(aOriginalMode);
 
     // Flag drawn formula cells "unchanged".
diff --git a/sc/source/ui/view/tabvwsh2.cxx b/sc/source/ui/view/tabvwsh2.cxx
index cee19352fdd8..d2efc23d5559 100644
--- a/sc/source/ui/view/tabvwsh2.cxx
+++ b/sc/source/ui/view/tabvwsh2.cxx
@@ -330,7 +330,11 @@ void ScTabViewShell::ExecDraw(SfxRequest& rReq)
         }
         else
         {
-            aInsertPos = GetViewData().getLOKVisibleArea().Center();
+            ScViewData& rViewData = GetViewData();
+            aInsertPos = rViewData.getLOKVisibleArea().Center();
+            if (comphelper::LibreOfficeKit::isCompatFlagSet(
+                    comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
+                aInsertPos = 
rViewData.GetPrintTwipsPosFromTileTwips(aInsertPos);
 
             aInsertPos.setX(sc::TwipsToHMM(aInsertPos.X()));
             aInsertPos.setY(sc::TwipsToHMM(aInsertPos.Y()));
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 887f4e632ce6..6632e51ee918 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -2434,6 +2434,21 @@ Point ScViewData::GetPrintTwipsPos(SCCOL nCol, SCROW 
nRow) const
     return Point(nPosX, nPosY);
 }
 
+Point ScViewData::GetPrintTwipsPosFromTileTwips(const Point& rTileTwipsPos) 
const
+{
+    const long nPixelX = static_cast<long>(rTileTwipsPos.X() * nPPTX);
+    const long nPixelY = static_cast<long>(rTileTwipsPos.Y() * nPPTY);
+    SCCOL nCol = 0;
+    SCROW nRow = 0;
+
+    // The following call (with bTestMerge = false) will not modify any 
members.
+    const_cast<ScViewData*>(this)->GetPosFromPixel(nPixelX, nPixelY, 
SC_SPLIT_TOPLEFT, nCol, nRow, false /* bTestMerge */);
+    const Point aPixCellPos = GetScrPos(nCol, nRow, SC_SPLIT_TOPLEFT, true /* 
bAllowNeg */);
+    const Point aTileTwipsCellPos(aPixCellPos.X() / nPPTX, aPixCellPos.Y() / 
nPPTY);
+    const Point aPrintTwipsCellPos = GetPrintTwipsPos(nCol, nRow);
+    return aPrintTwipsCellPos + (rTileTwipsPos - aTileTwipsCellPos);
+}
+
 OString ScViewData::describeCellCursorAt(SCCOL nX, SCROW nY, bool 
bPixelAligned) const
 {
     const bool bPosSizeInPixels = bPixelAligned;
diff --git a/svx/source/sdr/contact/viewobjectcontact.cxx 
b/svx/source/sdr/contact/viewobjectcontact.cxx
index d15ba27dd9f9..882b911a8fab 100644
--- a/svx/source/sdr/contact/viewobjectcontact.cxx
+++ b/svx/source/sdr/contact/viewobjectcontact.cxx
@@ -478,6 +478,7 @@ void ViewObjectContact::resetGridOffset()
 
     // also reset sequence to get a re-calculation when GridOffset changes
     mxPrimitive2DSequence.clear();
+    maObjectRange.reset();
 }
 
 }}
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index 326de3db561f..5b3a77e3e5a8 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -50,6 +50,7 @@
 #include <svx/sdr/table/tablecontroller.hxx>
 #include <svx/sdr/overlay/overlayselection.hxx>
 #include <svx/sdr/contact/viewcontact.hxx>
+#include <svx/sdr/contact/viewobjectcontact.hxx>
 #include <svx/sdrpaintwindow.hxx>
 #include <svx/sdrpagewindow.hxx>
 #include <svx/sdrhittesthelper.hxx>
@@ -2039,7 +2040,7 @@ bool SdrMarkView::getPossibleGridOffsetForSdrObject(
     const sdr::contact::ViewObjectContact& 
rVOC(pObj->GetViewContact().GetViewObjectContact(
         const_cast<sdr::contact::ObjectContact&>(rObjectContact)));
 
-    rObjectContact.calculateGridOffsetForViewOjectContact(rOffset, rVOC);
+    rOffset = rVOC.getGridOffset();
 
     return !rOffset.equalZero();
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to