Kaydet (Commit) b230f845 authored tarafından Marco Cecchetti's avatar Marco Cecchetti Kaydeden (comit) Marco Cecchetti

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/40448Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMarco Cecchetti <mrcekets@gmail.com>
üst a789ef3c
......@@ -131,6 +131,7 @@ certain functionality.
@li @c sc.core.formulagroup
@li @c sc.core.grouparealistener - sc::FormulaGroupAreaListener
@li @c sc.filter - Calc filter
@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
......
......@@ -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; }
......
......@@ -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;
}
......
......@@ -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() ).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment