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

Marco Cecchetti marco.cecchetti at collabora.com
Thu Jun 7 20:13:32 UTC 2018


 sc/source/ui/inc/viewdata.hxx  |    4 +-
 sc/source/ui/unoobj/docuno.cxx |   25 +++++++++++---
 sc/source/ui/view/viewdata.cxx |   69 +++++++++++++++++++----------------------
 3 files changed, 55 insertions(+), 43 deletions(-)

New commits:
commit 2a7f74900fb646235b74d4c9bd4690e44edc3ed4
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Tue May 8 18:36:00 2018 +0200

    lok: sc: scroll issue
    
    Problem:
    
    users A and B open the same empty document, and the initial document
    height is the same for both views, say 100 rows;
    user A goes to row 1000 and enters some text
    user B is not able to scroll below row 100
    
    Change-Id: I68efe03473c6f82d68182a951034d2e95ffa7765
    Reviewed-on: https://gerrit.libreoffice.org/53996
    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 6bc447966c1e..4efc30615852 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -134,10 +134,11 @@ private:
         bool operator() (const value_type& rValue1, const value_type& rValue2) const;
     };
 
+    const index_type MAX_INDEX;
     std::set<value_type, Comp> mData;
 
 public:
-    ScPositionHelper();
+    ScPositionHelper(bool bColumn);
 
     void insert(index_type nIndex, long nPos);
     void removeByIndex(index_type nIndex);
@@ -146,6 +147,7 @@ public:
     const value_type& getNearestByIndex(index_type nIndex) const;
     const value_type& getNearestByPosition(long nPos) const;
     long getPosition(index_type nIndex) const;
+    long computePosition(index_type nIndex, const std::function<long (index_type)>& getSizePx);
 };
 
 class ScBoundsProvider
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 8120b782547a..968439bfdcf0 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -607,14 +607,29 @@ Size ScModelObj::getDocumentSize()
 
     rDoc.GetTiledRenderingArea(nTab, nEndCol, nEndRow);
 
-    pViewData->SetMaxTiledCol(nEndCol);
-    pViewData->SetMaxTiledRow(nEndRow);
+    const ScDocument* pThisDoc = &rDoc;
 
-    if (pViewData->GetLOKDocWidthPixel() > 0 && pViewData->GetLOKDocHeightPixel() > 0)
+    auto GetColWidthPx = [pThisDoc, nTab](SCCOL nCol) {
+        const sal_uInt16 nSize = pThisDoc->GetColWidth(nCol, nTab);
+        return ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+    };
+
+    long nDocWidthPixel = pViewData->GetLOKWidthHelper().computePosition(nEndCol, GetColWidthPx);
+
+
+    auto GetRowHeightPx = [pThisDoc, nTab](SCROW nRow) {
+        const sal_uInt16 nSize = pThisDoc->GetRowHeight(nRow, nTab);
+        return ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+    };
+
+    long nDocHeightPixel = pViewData->GetLOKHeightHelper().computePosition(nEndRow, GetRowHeightPx);
+
+
+    if (nDocWidthPixel > 0 && nDocHeightPixel > 0)
     {
         // convert to twips
-        aSize.setWidth(pViewData->GetLOKDocWidthPixel() * TWIPS_PER_PIXEL);
-        aSize.setHeight(pViewData->GetLOKDocHeightPixel() * TWIPS_PER_PIXEL);
+        aSize.setWidth(nDocWidthPixel * TWIPS_PER_PIXEL);
+        aSize.setHeight(nDocHeightPixel * TWIPS_PER_PIXEL);
     }
     else
     {
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 69fce5476d8f..eacb5d5dc087 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -104,7 +104,8 @@ bool ScPositionHelper::Comp::operator() (const value_type& rValue1, const value_
     }
 }
 
-ScPositionHelper::ScPositionHelper()
+ScPositionHelper::ScPositionHelper(bool bColumn)
+    : MAX_INDEX(bColumn ? MAXCOL : MAXTILEDROW)
 {
     mData.insert(std::make_pair(-1, 0));
 }
@@ -231,6 +232,32 @@ long ScPositionHelper::getPosition(index_type nIndex) const
     return it->second;
 }
 
+long ScPositionHelper::computePosition(index_type nIndex, const std::function<long (index_type)>& getSizePx)
+{
+    if (nIndex < 0) nIndex = 0;
+    if (nIndex > MAX_INDEX) nIndex = MAX_INDEX;
+
+    const auto& rNearest = getNearestByIndex(nIndex);
+    index_type nStartIndex = rNearest.first;
+    long nTotalPixels = rNearest.second;
+
+    if (nStartIndex < nIndex)
+    {
+        for (index_type nIdx = nStartIndex + 1; nIdx <= nIndex; ++nIdx)
+        {
+            nTotalPixels += getSizePx(nIdx);
+        }
+    }
+    else
+    {
+        for (index_type nIdx = nStartIndex; nIdx > nIndex; --nIdx)
+        {
+            nTotalPixels -= getSizePx(nIdx);
+        }
+    }
+    return nTotalPixels;
+}
+
 ScBoundsProvider::ScBoundsProvider(ScDocument* pD, SCTAB nT, bool bColHeader)
     : pDoc(pD)
     , nTab(nT)
@@ -448,6 +475,8 @@ ScViewDataTable::ScViewDataTable() :
                 nOldCurY( 0 ),
                 nLOKOldCurX( 0 ),
                 nLOKOldCurY( 0 ),
+                aWidthHelper(true),
+                aHeightHelper(false),
                 nMaxTiledCol( 20 ),
                 nMaxTiledRow( 50 ),
                 bShowGrid( true ),
@@ -1384,24 +1413,7 @@ void ScViewData::SetMaxTiledCol( SCCOL nNewMaxCol )
         return nSizePx;
     };
 
-    const auto& rNearest = GetLOKWidthHelper().getNearestByIndex(nNewMaxCol);
-    SCCOL nStartCol = rNearest.first;
-    long nTotalPixels = rNearest.second;
-
-    if (nStartCol < nNewMaxCol)
-    {
-        for (SCCOL nCol = nStartCol + 1; nCol <= nNewMaxCol; ++nCol)
-        {
-            nTotalPixels += GetColWidthPx(nCol);
-        }
-    }
-    else
-    {
-        for (SCCOL nCol = nStartCol; nCol > nNewMaxCol; --nCol)
-        {
-            nTotalPixels -= GetColWidthPx(nCol);
-        }
-    }
+    long nTotalPixels = GetLOKWidthHelper().computePosition(nNewMaxCol, GetColWidthPx);
 
     SAL_INFO("sc.lok.docsize", "ScViewData::SetMaxTiledCol: nNewMaxCol: "
             << nNewMaxCol << ", nTotalPixels: " << nTotalPixels);
@@ -1427,24 +1439,7 @@ void ScViewData::SetMaxTiledRow( SCROW nNewMaxRow )
         return nSizePx;
     };
 
-    const auto& rNearest = GetLOKHeightHelper().getNearestByIndex(nNewMaxRow);
-    SCROW nStartRow = rNearest.first;
-    long nTotalPixels = rNearest.second;
-
-    if (nStartRow < nNewMaxRow)
-    {
-        for (SCROW nRow = nStartRow + 1; nRow <= nNewMaxRow; ++nRow)
-        {
-            nTotalPixels += GetRowHeightPx(nRow);
-        }
-    }
-    else
-    {
-        for (SCROW nRow = nStartRow; nRow > nNewMaxRow; --nRow)
-        {
-            nTotalPixels -= GetRowHeightPx(nRow);
-        }
-    }
+    long nTotalPixels = GetLOKHeightHelper().computePosition(nNewMaxRow, GetRowHeightPx);
 
     SAL_INFO("sc.lok.docsize", "ScViewData::SetMaxTiledRow: nNewMaxRow: "
             << nNewMaxRow << ", nTotalPixels: " << nTotalPixels);


More information about the Libreoffice-commits mailing list