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

Marco Cecchetti marco.cecchetti at collabora.com
Mon Oct 2 16:45:14 UTC 2017


 include/sal/log-areas.dox      |    1 
 sc/source/ui/inc/viewdata.hxx  |    7 ++-
 sc/source/ui/unoobj/docuno.cxx |   20 +++++++--
 sc/source/ui/view/viewdata.cxx |   90 ++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 110 insertions(+), 8 deletions(-)

New commits:
commit b230f845e794641721254e0a95b006eb3588aa0c
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Wed Mar 29 12:55:12 2017 +0200

    lok - sc: document size as sum of row heights/col widths in pixel
    
    Grid lines, cursor overlay, row/col headers are all computed by
    summing up row heights / col widths converted to pixels.
    
    On the contrary the document size was converted to pixel only at the
    end after having summed up heights/widths in twips.
    
    All that lead to have a document height/width greater than the
    position of the last row/col, with the scrolling in online going
    unplesantly far beyond the last row/column.
    
    This patch change the way the document size is computed, so that the
    spreadsheet height/width matches the position of the last row/column.
    
    Moreover it exploits the cache-like structure for row/col positions
    introduced in a previous commit.
    
    Change-Id: Ibb2cc6a7b592e359a0b1202dc9bea1dd4c421354
    Reviewed-on: https://gerrit.libreoffice.org/40448
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Marco Cecchetti <mrcekets at gmail.com>

diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
index e1f826e6ec70..c4ae03e79a48 100644
--- a/include/sal/log-areas.dox
+++ b/include/sal/log-areas.dox
@@ -131,6 +131,7 @@ certain functionality.
 @li @c sc.core.formulagroup
 @li @c sc.core.grouparealistener - sc::FormulaGroupAreaListener
 @li @c sc.filter - Calc filter
+ at li @c sc.lok.docsize
 @li @c sc.lok.poshelper
 @li @c sc.opencl - OpenCL-related stuff in general
 @li @c sc.opencl.source - Generated OpenCL source code
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index dbda16afe2f2..0b3fbb2f61b3 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -337,6 +337,9 @@ public:
     SCROW           GetCurYForTab( SCTAB nTabIndex ) const;
     SCCOL           GetOldCurX() const;
     SCROW           GetOldCurY() const;
+    long            GetLOKDocWidthPixel() const             { return pThisTab->aWidthHelper.getPosition(pThisTab->nMaxTiledCol); }
+    long            GetLOKDocHeightPixel() const            { return pThisTab->aHeightHelper.getPosition(pThisTab->nMaxTiledRow); }
+
     ScPositionHelper& GetLOKWidthHelper()                   { return pThisTab->aWidthHelper; }
     ScPositionHelper& GetLOKHeightHelper()                  { return pThisTab->aHeightHelper; }
 
@@ -367,8 +370,8 @@ public:
     void            SetVSplitPos( long nPos )                       { pThisTab->nVSplitPos = nPos; }
     void            SetFixPosX( SCCOL nPos )                        { pThisTab->nFixPosX = nPos; }
     void            SetFixPosY( SCROW nPos )                        { pThisTab->nFixPosY = nPos; }
-    void            SetMaxTiledCol( SCCOL nCol )                    { pThisTab->nMaxTiledCol = nCol; }
-    void            SetMaxTiledRow( SCROW nRow )                    { pThisTab->nMaxTiledRow = nRow; }
+    void            SetMaxTiledCol( SCCOL nCol );
+    void            SetMaxTiledRow( SCROW nRow );
 
     void            SetPagebreakMode( bool bSet );
     void            SetPasteMode ( ScPasteFlags nFlags )            { nPasteFlags = nFlags; }
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 265334a5eef8..ba1508c5195a 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -551,7 +551,7 @@ Size ScModelObj::getDocumentSize()
 {
     Size aSize(10, 10); // minimum size
 
-    const ScViewData* pViewData = ScDocShell::GetViewData();
+    ScViewData* pViewData = ScDocShell::GetViewData();
     if (!pViewData)
         return aSize;
 
@@ -562,9 +562,21 @@ Size ScModelObj::getDocumentSize()
 
     rDoc.GetTiledRenderingArea(nTab, nEndCol, nEndRow);
 
-    // convert to twips
-    aSize.setWidth(rDoc.GetColWidth(0, nEndCol, nTab));
-    aSize.setHeight(rDoc.GetRowHeight(0, nEndRow, nTab));
+    pViewData->SetMaxTiledCol(nEndCol);
+    pViewData->SetMaxTiledRow(nEndRow);
+
+    if (pViewData->GetLOKDocWidthPixel() > 0 && pViewData->GetLOKDocHeightPixel() > 0)
+    {
+        // convert to twips
+        aSize.setWidth(pViewData->GetLOKDocWidthPixel() * TWIPS_PER_PIXEL);
+        aSize.setHeight(pViewData->GetLOKDocHeightPixel() * TWIPS_PER_PIXEL);
+    }
+    else
+    {
+        // convert to twips
+        aSize.setWidth(rDoc.GetColWidth(0, nEndCol, nTab));
+        aSize.setHeight(rDoc.GetRowHeight(0, nEndRow, nTab));
+    }
 
     return aSize;
 }
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index af65ac0af798..88d2c8e56418 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -1163,9 +1163,95 @@ void ScViewData::SetCurYForTab( SCCOL nNewCurY, SCTAB nTabIndex )
     maTabData[nTabIndex]->nCurY = nNewCurY;
 }
 
+void ScViewData::SetMaxTiledCol( SCCOL nNewMaxCol )
+{
+    if (nNewMaxCol < 0)
+        nNewMaxCol = 0;
+    if (nNewMaxCol > MAXCOL)
+        nNewMaxCol = MAXCOL;
+
+    const SCTAB nTab = GetTabNo();
+    ScDocument* pThisDoc = pDoc;
+    auto GetColWidthPx = [pThisDoc, nTab](SCCOL nCol) {
+        const sal_uInt16 nSize = pThisDoc->GetColWidth(nCol, nTab);
+        const long nSizePx = ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+        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);
+        }
+    }
+
+    SAL_INFO("sc.lok.docsize", "ScViewData::SetMaxTiledCol: nNewMaxCol: "
+            << nNewMaxCol << ", nTotalPixels: " << nTotalPixels);
+
+    GetLOKWidthHelper().removeByIndex(pThisTab->nMaxTiledCol);
+    GetLOKWidthHelper().insert(nNewMaxCol, nTotalPixels);
+
+    pThisTab->nMaxTiledCol = nNewMaxCol;
+}
+
+void ScViewData::SetMaxTiledRow( SCROW nNewMaxRow )
+{
+    if (nNewMaxRow < 0)
+        nNewMaxRow = 0;
+    if (nNewMaxRow > MAXTILEDROW)
+        nNewMaxRow = MAXTILEDROW;
+
+    const SCTAB nTab = GetTabNo();
+    ScDocument* pThisDoc = pDoc;
+    auto GetRowHeightPx = [pThisDoc, nTab](SCROW nRow) {
+        const sal_uInt16 nSize = pThisDoc->GetRowHeight(nRow, nTab);
+        const long nSizePx = ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+        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);
+        }
+    }
+
+    SAL_INFO("sc.lok.docsize", "ScViewData::SetMaxTiledRow: nNewMaxRow: "
+            << nNewMaxRow << ", nTotalPixels: " << nTotalPixels);
+
+    GetLOKHeightHelper().removeByIndex(pThisTab->nMaxTiledRow);
+    GetLOKHeightHelper().insert(nNewMaxRow, nTotalPixels);
+
+    pThisTab->nMaxTiledRow = nNewMaxRow;
+}
+
 tools::Rectangle ScViewData::GetEditArea( ScSplitPos eWhich, SCCOL nPosX, SCROW nPosY,
-                                    vcl::Window* pWin, const ScPatternAttr* pPattern,
-                                    bool bForceToTop )
+                                          vcl::Window* pWin, const ScPatternAttr* pPattern,
+                                          bool bForceToTop )
 {
     return ScEditUtil( pDoc, nPosX, nPosY, nTabNo, GetScrPos(nPosX,nPosY,eWhich,true),
                         pWin, nPPTX, nPPTY, GetZoomX(), GetZoomY() ).


More information about the Libreoffice-commits mailing list