summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2017-03-29 13:42:35 +0200
committerMarco Cecchetti <mrcekets@gmail.com>2017-10-02 18:46:00 +0200
commit31b7dc19c32f42197c481cb7d2f44c600b755e2b (patch)
treeeabaf30a1453fa7f185b492a78174fd0d48fbeb4 /sc
parent61ddf34cf72bdfb738706b0836d9ecb6c0186d5d (diff)
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@libreoffice.org> Reviewed-by: Marco Cecchetti <mrcekets@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/inc/viewdata.hxx8
-rw-r--r--sc/source/ui/view/gridwin.cxx7
-rw-r--r--sc/source/ui/view/viewdata.cxx129
3 files changed, 97 insertions, 47 deletions
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 ) )
{