summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-12-12 22:22:32 +0900
committerTomaž Vajngerl <quikee@gmail.com>2017-12-13 00:54:48 +0100
commit5217a2a0bf27e496cc429ee45dff7c239b466ae6 (patch)
treeb103a823e8c4bb144ea28c9d15286721088f16b9
parenteb002da913cd1745b039bbc7e519542d7990fb49 (diff)
tdf#114256 add cache criterium when to recalculate page range size
Page range size can only be valid for the input parameters, which includes the document size, which was not taken into account at all before. Now we look at all this parameters to decide if we need to recalculate or not. Change-Id: Ic52ad7516189b395c66f59aabc374c3da85f6a89 Reviewed-on: https://gerrit.libreoffice.org/46300 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--sc/source/ui/inc/printfun.hxx35
-rw-r--r--sc/source/ui/view/printfun.cxx61
2 files changed, 75 insertions, 21 deletions
diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx
index 34b2ecc2159e..2df47432c89a 100644
--- a/sc/source/ui/inc/printfun.hxx
+++ b/sc/source/ui/inc/printfun.hxx
@@ -97,6 +97,28 @@ public:
namespace sc
{
+struct PrintPageRangesInput
+{
+ bool m_bSkipEmpty;
+ bool m_bPrintArea;
+ SCROW m_nStartRow;
+ SCROW m_nEndRow;
+ SCCOL m_nStartCol;
+ SCCOL m_nEndCol;
+ SCTAB m_nPrintTab;
+ Size m_aDocSize;
+
+ PrintPageRangesInput()
+ : m_bSkipEmpty(false)
+ , m_bPrintArea(false)
+ , m_nStartRow(0)
+ , m_nEndRow(0)
+ , m_nStartCol(0)
+ , m_nEndCol(0)
+ , m_nPrintTab(0)
+ {}
+};
+
class PrintPageRanges
{
public:
@@ -110,12 +132,16 @@ public:
size_t m_nPagesY;
size_t m_nTotalY;
- bool m_bCalculated;
+ PrintPageRangesInput m_aInput;
+
+ bool checkIfAlreadyCalculatedAndSet(bool bSkipEmpty, bool bPrintArea,
+ SCROW nStartRow, SCROW nEndRow,
+ SCCOL nStartCol, SCCOL nEndCol,
+ SCTAB nPrintTab, Size const & aDocSize);
- void calculate(ScDocument* pDoc, ScPageTableParam const & rTableParam,
- ScPageAreaParam const & rAreaParam,
+ void calculate(ScDocument* pDoc, bool bSkipEmpty, bool bPrintArea,
SCROW nStartRow, SCROW nEndRow, SCCOL nStartCol, SCCOL nEndCol,
- SCTAB nPrintTab);
+ SCTAB nPrintTab, Size const & aDocSize);
};
}
@@ -137,6 +163,7 @@ struct ScPrintState // Save Variables from ScPrintFunc
// Additional state of page ranges
bool bSavedStateRanges;
+ sc::PrintPageRangesInput aPrintPageRangesInput;
size_t nTotalY;
std::vector<SCCOL> aPageEndX;
std::vector<SCROW> aPageEndY;
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 82d12a53b4f2..a009dca5b88e 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -262,7 +262,7 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter,
m_aRanges.m_aPageEndX = rState.aPageEndX;
m_aRanges.m_aPageEndY = rState.aPageEndY;
m_aRanges.m_aPageRows = rState.aPageRows;
- m_aRanges.m_bCalculated = true;
+ m_aRanges.m_aInput = rState.aPrintPageRangesInput;
}
aSrcOffset = pPrinter->PixelToLogic(pPrinter->GetPageOffsetPixel(), MapMode(MapUnit::Map100thMM));
@@ -326,7 +326,7 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
m_aRanges.m_aPageEndX = rState.aPageEndX;
m_aRanges.m_aPageEndY = rState.aPageEndY;
m_aRanges.m_aPageRows = rState.aPageRows;
- m_aRanges.m_bCalculated = true;
+ m_aRanges.m_aInput = rState.aPrintPageRangesInput;
}
Construct( pOptions );
@@ -353,6 +353,7 @@ void ScPrintFunc::GetPrintState(ScPrintState& rState, bool bSavePageRanges)
rState.aPageEndX = m_aRanges.m_aPageEndX;
rState.aPageEndY = m_aRanges.m_aPageEndY;
rState.aPageRows = m_aRanges.m_aPageRows;
+ rState.aPrintPageRangesInput = m_aRanges.m_aInput;
}
}
@@ -3003,9 +3004,7 @@ static void lcl_SetHidden( const ScDocument* pDoc, SCTAB nPrintTab, ScPageRowEnt
void ScPrintFunc::CalcPages() // calculates aPageRect and pages from nZoom
{
- pDoc->SetPageSize(nPrintTab, GetDocPageSize());
-
- m_aRanges.calculate(pDoc, aTableParam, aAreaParam, nStartRow, nEndRow, nStartCol, nEndCol, nPrintTab);
+ m_aRanges.calculate(pDoc, aTableParam.bSkipEmpty, aAreaParam.bPrintArea, nStartRow, nEndRow, nStartCol, nEndCol, nPrintTab, GetDocPageSize());
}
namespace sc
@@ -3015,26 +3014,56 @@ PrintPageRanges::PrintPageRanges()
: m_nPagesX(0)
, m_nPagesY(0)
, m_nTotalY(0)
- , m_bCalculated(false)
{}
-void PrintPageRanges::calculate(ScDocument* pDoc, ScPageTableParam const & rTableParam,
- ScPageAreaParam const & rAreaParam,
+bool PrintPageRanges::checkIfAlreadyCalculatedAndSet(
+ bool bSkipEmpty, bool bPrintArea,
+ SCROW nStartRow, SCROW nEndRow,
+ SCCOL nStartCol, SCCOL nEndCol,
+ SCTAB nPrintTab, Size const & rDocSize)
+{
+ if (bSkipEmpty == m_aInput.m_bSkipEmpty &&
+ bPrintArea == m_aInput.m_bPrintArea &&
+ nStartRow == m_aInput.m_nStartRow && nEndRow == m_aInput.m_nEndRow &&
+ nStartCol == m_aInput.m_nStartCol && nEndCol == m_aInput.m_nEndCol &&
+ nPrintTab == m_aInput.m_nPrintTab &&
+ rDocSize == m_aInput.m_aDocSize)
+ {
+ return true;
+ }
+
+ m_aInput.m_bSkipEmpty = bSkipEmpty;
+ m_aInput.m_bPrintArea = bPrintArea;
+ m_aInput.m_nStartRow = nStartRow;
+ m_aInput.m_nEndRow = nEndRow;
+ m_aInput.m_nStartCol = nStartCol;
+ m_aInput.m_nEndCol = nEndCol;
+ m_aInput.m_nPrintTab = nPrintTab;
+ m_aInput.m_aDocSize = Size(rDocSize);
+
+ return false;
+}
+void PrintPageRanges::calculate(ScDocument* pDoc,
+ bool bSkipEmpty, bool bPrintArea,
SCROW nStartRow, SCROW nEndRow,
SCCOL nStartCol, SCCOL nEndCol,
- SCTAB nPrintTab)
+ SCTAB nPrintTab, Size const & rDocSize)
{
// Already calculated?
- if (m_bCalculated)
+ if (checkIfAlreadyCalculatedAndSet(bSkipEmpty, bPrintArea,
+ nStartRow, nEndRow, nStartCol, nEndCol,
+ nPrintTab, rDocSize))
return;
+ pDoc->SetPageSize(nPrintTab, rDocSize);
+
// #i123672# use dynamic mem to react on size changes
if (m_aPageEndX.size() < MAXCOL+1)
{
m_aPageEndX.resize(MAXCOL+1, SCCOL());
}
- if (rAreaParam.bPrintArea)
+ if (bPrintArea)
{
ScRange aRange(nStartCol, nStartRow, nPrintTab, nEndCol, nEndRow, nPrintTab);
pDoc->UpdatePageBreaks(nPrintTab, &aRange);
@@ -3109,13 +3138,13 @@ void PrintPageRanges::calculate(ScDocument* pDoc, ScPageTableParam const & rTabl
m_aPageEndY[m_nTotalY] = nRow - 1;
++m_nTotalY;
- if (!rTableParam.bSkipEmpty || !pDoc->IsPrintEmpty(nPrintTab, nStartCol, nPageStartRow, nEndCol, nRow-1))
+ if (!bSkipEmpty || !pDoc->IsPrintEmpty(nPrintTab, nStartCol, nPageStartRow, nEndCol, nRow-1))
{
OSL_ENSURE(m_nPagesY < m_aPageRows.size(), "vector access error for rPageRows");
m_aPageRows[m_nPagesY].SetStartRow(nPageStartRow);
m_aPageRows[m_nPagesY].SetEndRow(nRow - 1);
m_aPageRows[m_nPagesY].SetPagesX(m_nPagesX);
- if (rTableParam.bSkipEmpty)
+ if (bSkipEmpty)
lcl_SetHidden(pDoc, nPrintTab, m_aPageRows[m_nPagesY], nStartCol, m_aPageEndX);
++m_nPagesY;
}
@@ -3149,19 +3178,17 @@ void PrintPageRanges::calculate(ScDocument* pDoc, ScPageTableParam const & rTabl
m_aPageEndY[m_nTotalY] = nEndRow;
++m_nTotalY;
- if (!rTableParam.bSkipEmpty || !pDoc->IsPrintEmpty(nPrintTab, nStartCol, nPageStartRow, nEndCol, nEndRow))
+ if (!bSkipEmpty || !pDoc->IsPrintEmpty(nPrintTab, nStartCol, nPageStartRow, nEndCol, nEndRow))
{
OSL_ENSURE(m_nPagesY < m_aPageRows.size(), "vector access error for maPageRows");
m_aPageRows[m_nPagesY].SetStartRow(nPageStartRow);
m_aPageRows[m_nPagesY].SetEndRow(nEndRow);
m_aPageRows[m_nPagesY].SetPagesX(m_nPagesX);
- if (rTableParam.bSkipEmpty)
+ if (bSkipEmpty)
lcl_SetHidden(pDoc, nPrintTab, m_aPageRows[m_nPagesY], nStartCol, m_aPageEndX);
++m_nPagesY;
}
}
-
- m_bCalculated = true;
}
} // end namespace sc