From fab3c48a0cd5a0517025993502a04358308fe5ef Mon Sep 17 00:00:00 2001 From: Andrzej Hunt Date: Mon, 2 Nov 2015 13:24:12 +0100 Subject: 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.) 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(-) (limited to 'sc') diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx index c5db4f197f39..a6dcdf755b5d 100644 --- a/sc/source/ui/inc/gridwin.hxx +++ b/sc/source/ui/inc/gridwin.hxx @@ -199,6 +199,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_TYPED( PopupModeEndHdl, FloatingWindow*, void ); DECL_LINK_TYPED( PopupSpellingHdl, SpellCallbackInfo&, void ); @@ -291,6 +300,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) override; virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) override; diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 59bf9e00b09c..cdc12cabcd31 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -5775,7 +5775,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(); @@ -5784,8 +5784,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 ); @@ -5795,6 +5799,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()); } @@ -5806,7 +5812,7 @@ void ScGridWindow::CursorChanged() UpdateCursorOverlay(); - updateLibreOfficeKitCellCursor(pViewData, eWhich); + updateLibreOfficeKitCellCursor(); } void ScGridWindow::ImpCreateOverlayObjects() diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx index 51ae5fdc8397..e0f0a5182344 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -953,11 +953,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(nTilePosX) * nOutputWidth / nTileWidth; double fTilePosYPixel = static_cast(nTilePosY) * nOutputHeight / nTileHeight; -- cgit