summaryrefslogtreecommitdiff
path: root/sc/source/ui/view/viewdata.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/ui/view/viewdata.cxx')
-rw-r--r--sc/source/ui/view/viewdata.cxx161
1 files changed, 109 insertions, 52 deletions
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index c034836d4d4a..7b35328f68bb 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -1696,50 +1696,32 @@ SCROW ScViewData::CellsAtY( SCsROW nPosY, SCsROW nDir, ScVSplitPos eWhichY, USHO
if (pView)
((ScViewData*)this)->aScrSize.Height() = pView->GetGridHeight(eWhichY);
- SCROW nY;
- USHORT nScrPosY = 0;
-
if (nScrSizeY == SC_SIZE_NONE) nScrSizeY = (USHORT) aScrSize.Height();
- if (nDir==1)
- nY = nPosY; // vorwaerts
- else
- nY = nPosY-1; // rueckwaerts
-
- BOOL bOut = FALSE;
- for ( ; nScrPosY<=nScrSizeY && !bOut; nY+=nDir )
- {
- SCsROW nRowNo = nY;
- if ( nRowNo < 0 || nRowNo > MAXROW )
- bOut = TRUE;
- else
- {
- USHORT nTSize = pDoc->GetRowHeight( nRowNo, nTabNo );
- if (nTSize)
- {
- long nSizeYPix = ToPixel( nTSize, nPPTY );
- nScrPosY = sal::static_int_cast<USHORT>( nScrPosY + (USHORT) nSizeYPix );
- }
- else if ( nDir == 1 && nRowNo < MAXROW )
- {
- // skip multiple hidden rows (forward only for now)
- SCROW nNext = pDoc->FirstVisibleRow(nRowNo + 1, MAXROW, nTabNo);
- if ( nNext > MAXROW )
- {
- // same behavior as without the optimization: set bOut with nY=MAXROW+1
- nY = MAXROW+1;
- bOut = TRUE;
- }
- else
- nY = nNext - 1; // +=nDir advances to next visible row
- }
- }
- }
+ SCROW nY;
if (nDir==1)
+ {
+ // forward
+ nY = nPosY;
+ long nScrPosY = 0;
+ AddPixelsWhile( nScrPosY, nScrSizeY, nY, MAXROW, nPPTY, pDoc, nTabNo);
+ // Original loop ended on last evaluated +1 or if that was MAXROW even
+ // on MAXROW+2.
+ nY += (nY == MAXROW ? 2 : 1);
nY -= nPosY;
+ }
else
+ {
+ // backward
+ nY = nPosY-1;
+ long nScrPosY = 0;
+ AddPixelsWhileBackward( nScrPosY, nScrSizeY, nY, 0, nPPTY, pDoc, nTabNo);
+ // Original loop ended on last evaluated -1 or if that was 0 even on
+ // -2.
+ nY -= (nY == 0 ? 2 : 1);
nY = (nPosY-1)-nY;
+ }
if (nY>0) --nY;
return nY;
@@ -1855,16 +1837,10 @@ BOOL ScViewData::GetPosFromPixel( long nClickX, long nClickY, ScSplitPos eWhich,
}
if (nClickY > 0)
- {
- while ( rPosY<=MAXROW && nClickY >= nScrY )
- {
- nScrY += ToPixel( pDoc->GetRowHeight( rPosY, nTabNo ), nPPTY );
- ++rPosY;
- }
- --rPosY;
- }
+ AddPixelsWhile( nScrY, nClickY, rPosY, MAXROW, nPPTY, pDoc, nTabNo );
else
{
+ /* TODO: could need some "SubPixelsWhileBackward" method */
while ( rPosY>0 && nClickY < nScrY )
{
--rPosY;
@@ -1984,20 +1960,24 @@ void ScViewData::SetPosY( ScVSplitPos eWhich, SCROW nNewPosY )
SCROW nOldPosY = pThisTab->nPosY[eWhich];
long nTPosY = pThisTab->nTPosY[eWhich];
long nPixPosY = pThisTab->nPixPosY[eWhich];
- SCROW i;
+ SCROW i, nHeightEndRow;
if ( nNewPosY > nOldPosY )
for ( i=nOldPosY; i<nNewPosY; i++ )
{
- long nThis = pDoc->GetRowHeight( i,nTabNo );
- nTPosY -= nThis;
- nPixPosY -= ToPixel(sal::static_int_cast<USHORT>(nThis), nPPTY);
+ long nThis = pDoc->GetRowHeight( i, nTabNo, NULL, &nHeightEndRow );
+ SCROW nRows = std::min( nNewPosY, nHeightEndRow + 1) - i;
+ i = nHeightEndRow;
+ nTPosY -= nThis * nRows;
+ nPixPosY -= ToPixel(sal::static_int_cast<USHORT>(nThis), nPPTY) * nRows;
}
else
for ( i=nNewPosY; i<nOldPosY; i++ )
{
- long nThis = pDoc->GetRowHeight( i,nTabNo );
- nTPosY += nThis;
- nPixPosY += ToPixel(sal::static_int_cast<USHORT>(nThis), nPPTY);
+ long nThis = pDoc->GetRowHeight( i, nTabNo, NULL, &nHeightEndRow );
+ SCROW nRows = std::min( nOldPosY, nHeightEndRow + 1) - i;
+ i = nHeightEndRow;
+ nTPosY += nThis * nRows;
+ nPixPosY += ToPixel(sal::static_int_cast<USHORT>(nThis), nPPTY) * nRows;
}
pThisTab->nPosY[eWhich] = nNewPosY;
@@ -3118,5 +3098,82 @@ ScAddress ScViewData::GetCurPos() const
}
+// static
+void ScViewData::AddPixelsWhile( long & rScrY, long nEndPixels, SCROW & rPosY,
+ SCROW nEndRow, double nPPTY, const ScDocument * pDoc, SCTAB nTabNo )
+{
+ SCROW nRow = rPosY;
+ while (rScrY <= nEndPixels && nRow <= nEndRow)
+ {
+ SCROW nHeightEndRow;
+ USHORT nHeight = pDoc->GetRowHeight( nRow, nTabNo, NULL, &nHeightEndRow);
+ if (nHeightEndRow > nEndRow)
+ nHeightEndRow = nEndRow;
+ if (!nHeight)
+ nRow = nHeightEndRow + 1;
+ else
+ {
+ SCROW nRows = nHeightEndRow - nRow + 1;
+ sal_Int64 nPixel = ToPixel( nHeight, nPPTY);
+ sal_Int64 nAdd = nPixel * nRows;
+ if (nAdd + rScrY > nEndPixels)
+ {
+ sal_Int64 nDiff = rScrY + nAdd - nEndPixels;
+ nRows -= static_cast<SCROW>(nDiff / nPixel);
+ nAdd = nPixel * nRows;
+ // We're looking for a value that satisfies loop condition.
+ if (nAdd + rScrY <= nEndPixels)
+ {
+ ++nRows;
+ nAdd += nPixel;
+ }
+ }
+ rScrY += static_cast<long>(nAdd);
+ nRow += nRows;
+ }
+ }
+ if (nRow > rPosY)
+ --nRow;
+ rPosY = nRow;
+}
+// static
+void ScViewData::AddPixelsWhileBackward( long & rScrY, long nEndPixels,
+ SCROW & rPosY, SCROW nStartRow, double nPPTY, const ScDocument * pDoc,
+ SCTAB nTabNo )
+{
+ SCROW nRow = rPosY;
+ while (rScrY <= nEndPixels && nRow >= nStartRow)
+ {
+ SCROW nHeightStartRow;
+ USHORT nHeight = pDoc->GetRowHeight( nRow, nTabNo, &nHeightStartRow, NULL);
+ if (nHeightStartRow < nStartRow)
+ nHeightStartRow = nStartRow;
+ if (!nHeight)
+ nRow = nHeightStartRow - 1;
+ else
+ {
+ SCROW nRows = nRow - nHeightStartRow + 1;
+ sal_Int64 nPixel = ToPixel( nHeight, nPPTY);
+ sal_Int64 nAdd = nPixel * nRows;
+ if (nAdd + rScrY > nEndPixels)
+ {
+ sal_Int64 nDiff = nAdd + rScrY - nEndPixels;
+ nRows -= static_cast<SCROW>(nDiff / nPixel);
+ nAdd = nPixel * nRows;
+ // We're looking for a value that satisfies loop condition.
+ if (nAdd + rScrY <= nEndPixels)
+ {
+ ++nRows;
+ nAdd += nPixel;
+ }
+ }
+ rScrY += static_cast<long>(nAdd);
+ nRow -= nRows;
+ }
+ }
+ if (nRow < rPosY)
+ ++nRow;
+ rPosY = nRow;
+}