sc/inc/document.hxx              |    3 +--
 sc/inc/table.hxx                 |    2 +-
 sc/source/core/data/document.cxx |    4 ++--
 sc/source/core/data/table2.cxx   |   31 ++++---------------------------
 sc/source/ui/view/viewdata.cxx   |   30 ++++++++++++++++++------------
 5 files changed, 26 insertions(+), 44 deletions(-)

New commits:
commit 34c6d02661949fcc9c15bd77d6e837623bbddcdb
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sat Jun 25 15:44:25 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Jun 25 21:42:46 2022 +0200

    tdf#149647 LibreOffice Calc cursor not positioned correctly
    
    Revert the offending commit
        commit feec8e3c34e08b621098a17f1011dccd0b4f7f4c
        reduce iteration in ScViewData::GetScrPos
    
    Change-Id: Id1df2bf7f87e6b800b40871c1472ed466b7eb6a0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136442
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 294d7deadecc..cf9be32b9332 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1972,8 +1972,7 @@ public:
      * specified height.
      */
     SCROW                       GetRowForHeight( SCTAB nTab, tools::Long 
nHeight ) const;
-    tools::Long                 GetScaledRowHeight( SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab,
-                                    double fScale, const tools::Long* 
pnMaxHeight = nullptr ) const;
+    tools::Long                 GetScaledRowHeight( SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab, double fScale ) const;
     SC_DLLPUBLIC tools::Long    GetColOffset( SCCOL nCol, SCTAB nTab, bool 
bHiddenAsZero = true ) const;
     SC_DLLPUBLIC tools::Long    GetRowOffset( SCROW nRow, SCTAB nTab, bool 
bHiddenAsZero = true ) const;
 
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index da1c0a4d4e98..c6c3bd031cb3 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -854,7 +854,7 @@ public:
     tools::Long     GetColWidth( SCCOL nStartCol, SCCOL nEndCol ) const;
     sal_uInt16 GetRowHeight( SCROW nRow, SCROW* pStartRow, SCROW* pEndRow, 
bool bHiddenAsZero = true ) const;
     tools::Long     GetRowHeight( SCROW nStartRow, SCROW nEndRow, bool 
bHiddenAsZero = true ) const;
-    tools::Long     GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double 
fScale, const tools::Long* pnMaxHeight = nullptr ) const;
+    tools::Long     GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double 
fScale ) const;
     tools::Long     GetColOffset( SCCOL nCol, bool bHiddenAsZero = true ) 
const;
     tools::Long     GetRowOffset( SCROW nRow, bool bHiddenAsZero = true ) 
const;
 
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index db6500e5b390..9c6f040961f1 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -4253,7 +4253,7 @@ SCROW ScDocument::GetRowForHeight( SCTAB nTab, 
tools::Long nHeight ) const
 }
 
 tools::Long ScDocument::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow,
-        SCTAB nTab, double fScale, const tools::Long* pnMaxHeight ) const
+        SCTAB nTab, double fScale ) const
 {
     // faster for a single row
     if (nStartRow == nEndRow)
@@ -4264,7 +4264,7 @@ tools::Long ScDocument::GetScaledRowHeight( SCROW 
nStartRow, SCROW nEndRow,
         return 0;
 
     if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab] )
-        return maTabs[nTab]->GetScaledRowHeight( nStartRow, nEndRow, fScale, 
pnMaxHeight );
+        return maTabs[nTab]->GetScaledRowHeight( nStartRow, nEndRow, fScale);
 
     OSL_FAIL("wrong sheet number");
     return 0;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index a8b5882a54ea..c7c8a92b03dc 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -3605,7 +3605,7 @@ tools::Long ScTable::GetRowHeight( SCROW nStartRow, SCROW 
nEndRow, bool bHiddenA
         return (nEndRow - nStartRow + 1) * 
static_cast<tools::Long>(ScGlobal::nStdRowHeight);
 }
 
-tools::Long ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, 
double fScale, const tools::Long* pnMaxHeight ) const
+tools::Long ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, 
double fScale ) const
 {
     OSL_ENSURE(ValidRow(nStartRow) && ValidRow(nEndRow),"wrong row number");
 
@@ -3632,21 +3632,8 @@ tools::Long ScTable::GetScaledRowHeight( SCROW 
nStartRow, SCROW nEndRow, double
                     SCROW nSegmentEnd = std::min( nLastRow, 
aSegmentIter.getLastPos() );
 
                     // round-down a single height value, multiply resulting 
(pixel) values
-                    const tools::Long nOneHeight = static_cast<tools::Long>( 
nRowVal * fScale );
-                    // sometimes scaling results in zero height
-                    if (nOneHeight)
-                    {
-                        SCROW nRowsInSegment = nSegmentEnd + 1 - nRow;
-                        if (pnMaxHeight)
-                        {
-                            nRowsInSegment = std::min(nRowsInSegment, 
static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
-                            nHeight += nOneHeight * nRowsInSegment;
-                            if (nHeight > *pnMaxHeight)
-                                return nHeight;
-                        }
-                        else
-                            nHeight += nOneHeight * nRowsInSegment;
-                    }
+                    tools::Long nOneHeight = static_cast<tools::Long>( nRowVal 
* fScale );
+                    nHeight += nOneHeight * ( nSegmentEnd + 1 - nRow );
 
                     nRow = nSegmentEnd + 1;
                 }
@@ -3656,17 +3643,7 @@ tools::Long ScTable::GetScaledRowHeight( SCROW 
nStartRow, SCROW nEndRow, double
         return nHeight;
     }
     else
-    {
-        const tools::Long nOneHeight = 
static_cast<tools::Long>(ScGlobal::nStdRowHeight * fScale);
-        SCROW nRowsInSegment = nEndRow - nStartRow + 1;
-        if (pnMaxHeight)
-        {
-            nRowsInSegment = std::min(nRowsInSegment, 
static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
-            return nOneHeight * nRowsInSegment;
-        }
-        else
-            return static_cast<tools::Long>(nRowsInSegment * nOneHeight);
-    }
+        return static_cast<tools::Long>((nEndRow - nStartRow + 1) * 
ScGlobal::nStdRowHeight * fScale);
 }
 
 sal_uInt16 ScTable::GetOriginalHeight( SCROW nRow ) const       // non-0 even 
if hidden
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 69ebe09d22d4..0ef96d96c7ae 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -2415,10 +2415,9 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW 
nWhereY, ScSplitPos eWhich,
         const_cast<ScViewData*>(this)->aScrSize.setHeight( 
pView->GetGridHeight(eWhichY) );
     }
 
-    tools::Long nTSize;
+    sal_uInt16 nTSize;
     bool bIsTiledRendering = comphelper::LibreOfficeKit::isActive();
 
-
     SCCOL nPosX = GetPosX(eWhichX, nForTab);
     tools::Long nScrPosX = 0;
 
@@ -2495,20 +2494,27 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW 
nWhereY, ScSplitPos eWhich,
 
         if (nWhereY >= nStartPosY)
         {
-            if (bAllowNeg || bIsTiledRendering || nScrPosY <= 
aScrSize.Height())
+            for (SCROW nY = nStartPosY; nY < nWhereY && (bAllowNeg || 
bIsTiledRendering || nScrPosY <= aScrSize.Height()); nY++)
             {
-                if (nWhereY - 1 > mrDoc.MaxRow())
+                if ( nY > mrDoc.MaxRow() )
                     nScrPosY = 0x7FFFFFFF;
-                else if (bAllowNeg || bIsTiledRendering)
-                {
-                    tools::Long nSizeYPix = 
mrDoc.GetScaledRowHeight(nStartPosY, nWhereY - 1, nForTab, nPPTY);
-                    nScrPosY += nSizeYPix;
-                }
                 else
                 {
-                    tools::Long nMaxHeight = aScrSize.getHeight() - nScrPosY;
-                    tools::Long nSizeYPix = 
mrDoc.GetScaledRowHeight(nStartPosY, nWhereY - 1, nForTab, nPPTY, &nMaxHeight);
-                    nScrPosY += nSizeYPix;
+                    nTSize = mrDoc.GetRowHeight( nY, nTabNo );
+                    if (nTSize)
+                    {
+                        tools::Long nSizeYPix = ToPixel( nTSize, nPPTY );
+                        nScrPosY += nSizeYPix;
+                    }
+                    else if ( nY < mrDoc.MaxRow() )
+                    {
+                        // skip multiple hidden rows (forward only for now)
+                        SCROW nNext = mrDoc.FirstVisibleRow(nY + 1, 
mrDoc.MaxRow(), nTabNo);
+                        if ( nNext > mrDoc.MaxRow() )
+                            nY = mrDoc.MaxRow();
+                        else
+                            nY = nNext - 1;     // +=nDir advances to next 
visible row
+                    }
                 }
             }
         }

Reply via email to