[Libreoffice-commits] core.git: sc/source

Marco Cecchetti marco.cecchetti at collabora.com
Mon Oct 2 16:46:29 UTC 2017


 sc/source/ui/inc/viewdata.hxx  |    8 ++
 sc/source/ui/view/gridwin.cxx  |    7 ++
 sc/source/ui/view/viewdata.cxx |  129 ++++++++++++++++++++++++++---------------
 3 files changed, 97 insertions(+), 47 deletions(-)

New commits:
commit 31b7dc19c32f42197c481cb7d2f44c600b755e2b
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Wed Mar 29 13:42:35 2017 +0200

    lok - sc: make computation of cell cursor position faster
    
    Now the computation of the cell cursor position exploits the cached
    row/col positions in HeightHelper/WidthHelper.
    
    That makes navigating through arrow keys independent from the current
    cell cursor position: the cell cursor position is updated at the
    bottom of the document as fast as at the top even for very big
    spreadsheets.
    
    Change-Id: I2f23d4439f2157e702f09b56106bebdd0e0bbe86
    Reviewed-on: https://gerrit.libreoffice.org/40450
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Marco Cecchetti <mrcekets at gmail.com>

diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 63b863b87bf8..00b672930098 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -180,6 +180,9 @@ private:
     SCROW           nCurY;
     SCCOL           nOldCurX;
     SCROW           nOldCurY;
+    SCCOL           nLOKOldCurX;
+    SCROW           nLOKOldCurY;
+
     ScPositionHelper aWidthHelper;
     ScPositionHelper aHeightHelper;
 
@@ -337,6 +340,8 @@ public:
     SCROW           GetCurYForTab( SCTAB nTabIndex ) const;
     SCCOL           GetOldCurX() const;
     SCROW           GetOldCurY() const;
+    SCCOL           GetLOKOldCurX() const                   { return pThisTab->nLOKOldCurX; }
+    SCROW           GetLOKOldCurY() const                   { return pThisTab->nLOKOldCurY; }
     long            GetLOKDocWidthPixel() const             { return pThisTab->aWidthHelper.getPosition(pThisTab->nMaxTiledCol); }
     long            GetLOKDocHeightPixel() const            { return pThisTab->aHeightHelper.getPosition(pThisTab->nMaxTiledRow); }
 
@@ -367,6 +372,9 @@ public:
     void            SetCurYForTab( SCCOL nNewCurY, SCTAB nTabIndex );
     void            SetOldCursor( SCCOL nNewX, SCROW nNewY );
     void            ResetOldCursor();
+    void            SetLOKOldCurX( SCCOL nCurX )                    { pThisTab->nLOKOldCurX = nCurX; }
+    void            SetLOKOldCurY( SCROW nCurY )                    { pThisTab->nLOKOldCurY = nCurY; }
+
     void            SetHSplitMode( ScSplitMode eMode )              { pThisTab->eHSplitMode = eMode; }
     void            SetVSplitMode( ScSplitMode eMode )              { pThisTab->eVSplitMode = eMode; }
     void            SetHSplitPos( long nPos )                       { pThisTab->nHSplitPos = nPos; }
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 1726e25a1d46..42328999c762 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5561,6 +5561,13 @@ OString ScGridWindow::getCellCursor(const Fraction& rZoomX, const Fraction& rZoo
 
     pViewData->SetZoom(defaultZoomX, defaultZoomY, true);
 
+    pViewData->GetLOKWidthHelper().removeByIndex(pViewData->GetLOKOldCurX() - 1);
+    pViewData->GetLOKWidthHelper().insert(nX - 1, aScrPos.getX());
+    pViewData->SetLOKOldCurX(nX);
+    pViewData->GetLOKHeightHelper().removeByIndex(pViewData->GetLOKOldCurY() - 1);
+    pViewData->GetLOKHeightHelper().insert(nY - 1, aScrPos.getY());
+    pViewData->SetLOKOldCurY(nY);
+
     return aRect.toString();
 }
 
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 10a5d01144c0..bb8389d8a203 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -267,6 +267,8 @@ ScViewDataTable::ScViewDataTable() :
                 nCurY( 0 ),
                 nOldCurX( 0 ),
                 nOldCurY( 0 ),
+                nLOKOldCurX( 0 ),
+                nLOKOldCurY( 0 ),
                 nMaxTiledCol( 20 ),
                 nMaxTiledRow( 50 ),
                 bShowGrid( true ),
@@ -1935,76 +1937,109 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,
     sal_uInt16 nTSize;
     bool bIsTiledRendering = comphelper::LibreOfficeKit::isActive();
 
-    SCCOL   nPosX = GetPosX(eWhichX);
-    SCCOL   nX;
 
-    long nScrPosX=0;
-    if (nWhereX >= nPosX)
-        for (nX = nPosX; nX < nWhereX && (bAllowNeg || bIsTiledRendering || nScrPosX <= aScrSize.Width()); nX++)
+    SCCOL nPosX = GetPosX(eWhichX);
+    long nScrPosX = 0;
+
+    if (bAllowNeg || nWhereX >= nPosX)
+    {
+        SCROW nStartPosX = nPosX;
+        if (bIsTiledRendering)
         {
-            if ( nX > MAXCOL )
-                nScrPosX = 0x7FFFFFFF;
-            else
+            OSL_ENSURE(nPosX == 0, "Unsupported case.");
+            const auto& rNearest = pThisTab->aWidthHelper.getNearestByIndex(nWhereX - 1);
+            nStartPosX = rNearest.first + 1;
+            nScrPosX = rNearest.second;
+        }
+
+        if (nWhereX >= nStartPosX)
+        {
+            for (SCCOL nX = nStartPosX; nX < nWhereX && (bAllowNeg || bIsTiledRendering || nScrPosX <= aScrSize.Width()); nX++)
             {
-                nTSize = pDoc->GetColWidth( nX, nTabNo );
-                if (nTSize)
+                if ( nX > MAXCOL )
+                    nScrPosX = 0x7FFFFFFF;
+                else
                 {
-                    long nSizeXPix = ToPixel( nTSize, nPPTX );
-                    nScrPosX += nSizeXPix;
+                    nTSize = pDoc->GetColWidth( nX, nTabNo );
+                    if (nTSize)
+                    {
+                        long nSizeXPix = ToPixel( nTSize, nPPTX );
+                        nScrPosX += nSizeXPix;
+                    }
                 }
             }
         }
-    else if (bAllowNeg)
-        for (nX=nPosX; nX>nWhereX;)
+        else
         {
-            --nX;
-            nTSize = pDoc->GetColWidth( nX, nTabNo );
-            if (nTSize)
+            for (SCCOL nX = nStartPosX; nX > nWhereX;)
             {
-                long nSizeXPix = ToPixel( nTSize, nPPTX );
-                nScrPosX -= nSizeXPix;
+                --nX;
+                nTSize = pDoc->GetColWidth( nX, nTabNo );
+                if (nTSize)
+                {
+                    long nSizeXPix = ToPixel( nTSize, nPPTX );
+                    nScrPosX -= nSizeXPix;
+                }
             }
         }
 
-    SCROW   nPosY = GetPosY(eWhichY);
-    SCROW   nY;
+    }
+
+
+    SCROW nPosY = GetPosY(eWhichY);
+    long nScrPosY = 0;
 
-    long nScrPosY=0;
-    if (nWhereY >= nPosY)
-        for (nY = nPosY; nY < nWhereY && (bAllowNeg || bIsTiledRendering || nScrPosY <= aScrSize.Height()); nY++)
+    if (bAllowNeg || nWhereY >= nPosY)
+    {
+        SCROW nStartPosY = nPosY;
+        if (bIsTiledRendering)
         {
-            if ( nY > MAXROW )
-                nScrPosY = 0x7FFFFFFF;
-            else
+            OSL_ENSURE(nPosY == 0, "Unsupported case.");
+            const auto& rNearest = pThisTab->aHeightHelper.getNearestByIndex(nWhereY - 1);
+            nStartPosY = rNearest.first + 1;
+            nScrPosY = rNearest.second;
+        }
+
+        if (nWhereY >= nStartPosY)
+        {
+            for (SCROW nY = nStartPosY; nY < nWhereY && (bAllowNeg || bIsTiledRendering || nScrPosY <= aScrSize.Height()); nY++)
             {
-                nTSize = pDoc->GetRowHeight( nY, nTabNo );
-                if (nTSize)
-                {
-                    long nSizeYPix = ToPixel( nTSize, nPPTY );
-                    nScrPosY += nSizeYPix;
-                }
-                else if ( nY < MAXROW )
+                if ( nY > MAXROW )
+                    nScrPosY = 0x7FFFFFFF;
+                else
                 {
-                    // skip multiple hidden rows (forward only for now)
-                    SCROW nNext = pDoc->FirstVisibleRow(nY + 1, MAXROW, nTabNo);
-                    if ( nNext > MAXROW )
-                        nY = MAXROW;
-                    else
-                        nY = nNext - 1;     // +=nDir advances to next visible row
+                    nTSize = pDoc->GetRowHeight( nY, nTabNo );
+                    if (nTSize)
+                    {
+                        long nSizeYPix = ToPixel( nTSize, nPPTY );
+                        nScrPosY += nSizeYPix;
+                    }
+                    else if ( nY < MAXROW )
+                    {
+                        // skip multiple hidden rows (forward only for now)
+                        SCROW nNext = pDoc->FirstVisibleRow(nY + 1, MAXROW, nTabNo);
+                        if ( nNext > MAXROW )
+                            nY = MAXROW;
+                        else
+                            nY = nNext - 1;     // +=nDir advances to next visible row
+                    }
                 }
             }
         }
-    else if (bAllowNeg)
-        for (nY=nPosY; nY>nWhereY;)
+        else
         {
-            --nY;
-            nTSize = pDoc->GetRowHeight( nY, nTabNo );
-            if (nTSize)
+            for (SCROW nY = nStartPosY; nY > nWhereY;)
             {
-                long nSizeYPix = ToPixel( nTSize, nPPTY );
-                nScrPosY -= nSizeYPix;
+                --nY;
+                nTSize = pDoc->GetRowHeight( nY, nTabNo );
+                if (nTSize)
+                {
+                    long nSizeYPix = ToPixel( nTSize, nPPTY );
+                    nScrPosY -= nSizeYPix;
+                }
             }
         }
+    }
 
     if ( pDoc->IsLayoutRTL( nTabNo ) )
     {


More information about the Libreoffice-commits mailing list