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

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