Blob Blame History Raw
From a8b236d905a757af8028cc8ed14bbc7144e41072 Mon Sep 17 00:00:00 2001
From: Andrzej Hunt <andrzej@ahunt.org>
Date: Mon, 2 Nov 2015 13:24:12 +0100
Subject: [PATCH 277/398] sc lok: Cache viewdata zoom and reuse for cursor
 callback

As of a1605d6860e3c4510177c42ab6d2fda569506f57 we reset the zoom
level to the default when processing LOK mouse events. The exact
cell cursor position is dependent on the zoom level (due to the
rounding in the cell position summing calculations), hence we need
to make sure we have the correct zoom level for those calculations
(or else the rounding errors will result in incorrect cell cursor
positions). Caching the zoom level and reusing it only here seems
to be the most efficient way of solving this for now.

(An alternative would be to only send the cell ID in the callback,
 and have the frontend then request the pixel positions together
 with the current frontend zoom level - however especially for
 LOOL minimising the number of trips is probably wise.)

(cherry picked from commit fab3c48a0cd5a0517025993502a04358308fe5ef)

Change-Id: Iae3aabfd7ea9bec7057be7b63670885766870c4f
---
 sc/source/ui/inc/gridwin.hxx   | 10 ++++++++++
 sc/source/ui/view/gridwin.cxx  | 12 +++++++++---
 sc/source/ui/view/gridwin4.cxx |  6 +++---
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index b8425a8e34c3..747ce88c2038 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -200,6 +200,15 @@ class ScGridWindow : public vcl::Window, public DropTargetHelper, public DragSou
     bool                    bAutoMarkVisible:1;
     bool                    bListValButton:1;
 
+    // We cache the tiled rendering zoom level in order to be able to
+    // calculate the correct cell cursor position (which is dependent
+    // on the zoom level). The caching is necessary since
+    // ScModelObj::postMouseEvent resets the zoom level to the default,
+    // which means we have the default zoom level set during the
+    // cell cursor position calculations in updateLibreOfficeKitCellCursor().
+    Fraction                mTiledZoomX;
+    Fraction                mTiledZoomY;
+
     DECL_LINK( PopupModeEndHdl, void* );
     DECL_LINK( PopupSpellingHdl, SpellCallbackInfo* );
 
@@ -292,6 +301,7 @@ class ScGridWindow : public vcl::Window, public DropTargetHelper, public DragSou
 
     void            GetSelectionRects( ::std::vector< Rectangle >& rPixelRects );
 
+    void            updateLibreOfficeKitCellCursor();
 protected:
     virtual void    PrePaint(vcl::RenderContext& rRenderContext) SAL_OVERRIDE;
     virtual void    Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 7ab88c6c0eb1..dd958e519249 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5782,7 +5782,7 @@ bool ScGridWindow::InsideVisibleRange( SCCOL nPosX, SCROW nPosY )
     return maVisibleRange.isInside(nPosX, nPosY);
 }
 
-static void updateLibreOfficeKitCellCursor(ScViewData* pViewData, ScSplitPos eWhich) {
+void ScGridWindow::updateLibreOfficeKitCellCursor() {
     ScDocument* pDoc = pViewData->GetDocument();
     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
 
@@ -5791,8 +5791,12 @@ static void updateLibreOfficeKitCellCursor(ScViewData* pViewData, ScSplitPos eWh
 
     SCCOL nX = pViewData->GetCurX();
     SCROW nY = pViewData->GetCurY();
-    Point aScrPos = pViewData->GetScrPos( nX, nY, eWhich, true );
 
+    Fraction defaultZoomX = pViewData->GetZoomX();
+    Fraction defaultZoomY = pViewData->GetZoomX();
+    pViewData->SetZoom(mTiledZoomX, mTiledZoomY, true);
+
+    Point aScrPos = pViewData->GetScrPos( nX, nY, eWhich, true );
     long nSizeXPix;
     long nSizeYPix;
     pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
@@ -5802,6 +5806,8 @@ static void updateLibreOfficeKitCellCursor(ScViewData* pViewData, ScSplitPos eWh
     Rectangle aRect(Point(aScrPos.getX() / fPPTX, aScrPos.getY() / fPPTY),
                     Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY));
 
+    pViewData->SetZoom(defaultZoomX, defaultZoomY, true);
+
     pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_CELL_CURSOR, aRect.toString().getStr());
 
 }
@@ -5813,7 +5819,7 @@ void ScGridWindow::CursorChanged()
 
     UpdateCursorOverlay();
 
-    updateLibreOfficeKitCellCursor(pViewData, eWhich);
+    updateLibreOfficeKitCellCursor();
 }
 
 // #114409#
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index ceaf3d8d7c3a..cfdde43e1a04 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -955,11 +955,11 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
     // Similarly to Writer, we should set the mapmode once on the rDevice, and
     // not care about any zoom settings.
 
-    Fraction aFracX(long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth);
-    Fraction aFracY(long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight);
+    mTiledZoomX = Fraction(long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth);
+    mTiledZoomY = Fraction(long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight);
 
     // page break zoom, and aLogicMode in ScViewData
-    pViewData->SetZoom(aFracX, aFracY, true);
+    pViewData->SetZoom(mTiledZoomX, mTiledZoomY, true);
 
     double fTilePosXPixel = static_cast<double>(nTilePosX) * nOutputWidth / nTileWidth;
     double fTilePosYPixel = static_cast<double>(nTilePosY) * nOutputHeight / nTileHeight;
-- 
2.12.0