Blame SOURCES/0277-sc-lok-Cache-viewdata-zoom-and-reuse-for-cursor-call.patch

135360
From a8b236d905a757af8028cc8ed14bbc7144e41072 Mon Sep 17 00:00:00 2001
135360
From: Andrzej Hunt <andrzej@ahunt.org>
135360
Date: Mon, 2 Nov 2015 13:24:12 +0100
135360
Subject: [PATCH 277/398] sc lok: Cache viewdata zoom and reuse for cursor
135360
 callback
135360
135360
As of a1605d6860e3c4510177c42ab6d2fda569506f57 we reset the zoom
135360
level to the default when processing LOK mouse events. The exact
135360
cell cursor position is dependent on the zoom level (due to the
135360
rounding in the cell position summing calculations), hence we need
135360
to make sure we have the correct zoom level for those calculations
135360
(or else the rounding errors will result in incorrect cell cursor
135360
positions). Caching the zoom level and reusing it only here seems
135360
to be the most efficient way of solving this for now.
135360
135360
(An alternative would be to only send the cell ID in the callback,
135360
 and have the frontend then request the pixel positions together
135360
 with the current frontend zoom level - however especially for
135360
 LOOL minimising the number of trips is probably wise.)
135360
135360
(cherry picked from commit fab3c48a0cd5a0517025993502a04358308fe5ef)
135360
135360
Change-Id: Iae3aabfd7ea9bec7057be7b63670885766870c4f
135360
---
135360
 sc/source/ui/inc/gridwin.hxx   | 10 ++++++++++
135360
 sc/source/ui/view/gridwin.cxx  | 12 +++++++++---
135360
 sc/source/ui/view/gridwin4.cxx |  6 +++---
135360
 3 files changed, 22 insertions(+), 6 deletions(-)
135360
135360
diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
135360
index b8425a8e34c3..747ce88c2038 100644
135360
--- a/sc/source/ui/inc/gridwin.hxx
135360
+++ b/sc/source/ui/inc/gridwin.hxx
135360
@@ -200,6 +200,15 @@ class ScGridWindow : public vcl::Window, public DropTargetHelper, public DragSou
135360
     bool                    bAutoMarkVisible:1;
135360
     bool                    bListValButton:1;
135360
 
135360
+    // We cache the tiled rendering zoom level in order to be able to
135360
+    // calculate the correct cell cursor position (which is dependent
135360
+    // on the zoom level). The caching is necessary since
135360
+    // ScModelObj::postMouseEvent resets the zoom level to the default,
135360
+    // which means we have the default zoom level set during the
135360
+    // cell cursor position calculations in updateLibreOfficeKitCellCursor().
135360
+    Fraction                mTiledZoomX;
135360
+    Fraction                mTiledZoomY;
135360
+
135360
     DECL_LINK( PopupModeEndHdl, void* );
135360
     DECL_LINK( PopupSpellingHdl, SpellCallbackInfo* );
135360
 
135360
@@ -292,6 +301,7 @@ class ScGridWindow : public vcl::Window, public DropTargetHelper, public DragSou
135360
 
135360
     void            GetSelectionRects( ::std::vector< Rectangle >& rPixelRects );
135360
 
135360
+    void            updateLibreOfficeKitCellCursor();
135360
 protected:
135360
     virtual void    PrePaint(vcl::RenderContext& rRenderContext) SAL_OVERRIDE;
135360
     virtual void    Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
135360
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
135360
index 7ab88c6c0eb1..dd958e519249 100644
135360
--- a/sc/source/ui/view/gridwin.cxx
135360
+++ b/sc/source/ui/view/gridwin.cxx
135360
@@ -5782,7 +5782,7 @@ bool ScGridWindow::InsideVisibleRange( SCCOL nPosX, SCROW nPosY )
135360
     return maVisibleRange.isInside(nPosX, nPosY);
135360
 }
135360
 
135360
-static void updateLibreOfficeKitCellCursor(ScViewData* pViewData, ScSplitPos eWhich) {
135360
+void ScGridWindow::updateLibreOfficeKitCellCursor() {
135360
     ScDocument* pDoc = pViewData->GetDocument();
135360
     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
135360
 
135360
@@ -5791,8 +5791,12 @@ static void updateLibreOfficeKitCellCursor(ScViewData* pViewData, ScSplitPos eWh
135360
 
135360
     SCCOL nX = pViewData->GetCurX();
135360
     SCROW nY = pViewData->GetCurY();
135360
-    Point aScrPos = pViewData->GetScrPos( nX, nY, eWhich, true );
135360
 
135360
+    Fraction defaultZoomX = pViewData->GetZoomX();
135360
+    Fraction defaultZoomY = pViewData->GetZoomX();
135360
+    pViewData->SetZoom(mTiledZoomX, mTiledZoomY, true);
135360
+
135360
+    Point aScrPos = pViewData->GetScrPos( nX, nY, eWhich, true );
135360
     long nSizeXPix;
135360
     long nSizeYPix;
135360
     pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
135360
@@ -5802,6 +5806,8 @@ static void updateLibreOfficeKitCellCursor(ScViewData* pViewData, ScSplitPos eWh
135360
     Rectangle aRect(Point(aScrPos.getX() / fPPTX, aScrPos.getY() / fPPTY),
135360
                     Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY));
135360
 
135360
+    pViewData->SetZoom(defaultZoomX, defaultZoomY, true);
135360
+
135360
     pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_CELL_CURSOR, aRect.toString().getStr());
135360
 
135360
 }
135360
@@ -5813,7 +5819,7 @@ void ScGridWindow::CursorChanged()
135360
 
135360
     UpdateCursorOverlay();
135360
 
135360
-    updateLibreOfficeKitCellCursor(pViewData, eWhich);
135360
+    updateLibreOfficeKitCellCursor();
135360
 }
135360
 
135360
 // #114409#
135360
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
135360
index ceaf3d8d7c3a..cfdde43e1a04 100644
135360
--- a/sc/source/ui/view/gridwin4.cxx
135360
+++ b/sc/source/ui/view/gridwin4.cxx
135360
@@ -955,11 +955,11 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
135360
     // Similarly to Writer, we should set the mapmode once on the rDevice, and
135360
     // not care about any zoom settings.
135360
 
135360
-    Fraction aFracX(long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth);
135360
-    Fraction aFracY(long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight);
135360
+    mTiledZoomX = Fraction(long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth);
135360
+    mTiledZoomY = Fraction(long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight);
135360
 
135360
     // page break zoom, and aLogicMode in ScViewData
135360
-    pViewData->SetZoom(aFracX, aFracY, true);
135360
+    pViewData->SetZoom(mTiledZoomX, mTiledZoomY, true);
135360
 
135360
     double fTilePosXPixel = static_cast<double>(nTilePosX) * nOutputWidth / nTileWidth;
135360
     double fTilePosYPixel = static_cast<double>(nTilePosY) * nOutputHeight / nTileHeight;
135360
-- 
135360
2.12.0
135360