summaryrefslogtreecommitdiff
path: root/sc/source/core/data
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-11-11 11:08:55 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-11-11 17:24:53 +0100
commita8a064d11c05feed83f05b0ce8209f7054afd804 (patch)
tree3a64572d1d12d64b707c50607056f405c3615fcf /sc/source/core/data
parent33d966ecc1f9fc44016cdeeed15dbaf6bda68eda (diff)
sc: rowcol: tdf#50916 convert mark data structures
Change-Id: I9b706c9bcc2925f72cc024142ffe72af5ddea82a Reviewed-on: https://gerrit.libreoffice.org/82419 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/core/data')
-rw-r--r--sc/source/core/data/conditio.cxx2
-rw-r--r--sc/source/core/data/documen2.cxx1
-rw-r--r--sc/source/core/data/markarr.cxx25
-rw-r--r--sc/source/core/data/markdata.cxx45
-rw-r--r--sc/source/core/data/markmulti.cxx25
-rw-r--r--sc/source/core/data/table2.cxx2
6 files changed, 60 insertions, 40 deletions
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 97626a397e87..14302b32e90f 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -2231,7 +2231,7 @@ ScRangeList ScConditionalFormatList::GetCombinedRange() const
void ScConditionalFormatList::RemoveFromDocument(ScDocument* pDoc) const
{
ScRangeList aRange = GetCombinedRange();
- ScMarkData aMark;
+ ScMarkData aMark(pDoc->MaxRow(), pDoc->MaxCol());
aMark.MarkFromRangeList(aRange, true);
sal_uInt16 const pItems[2] = { sal_uInt16(ATTR_CONDITIONAL),0};
pDoc->ClearSelectionItems(pItems, aMark);
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index ca62ddab9235..7271fdef0d43 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -105,6 +105,7 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
pFormulaTrack( nullptr ),
pEOFormulaTrack( nullptr ),
pPreviewCellStyle( nullptr ),
+ maPreviewSelection(MAXROW, MAXCOL),
nUnoObjectId( 0 ),
nRangeOverflowType( 0 ),
aCurTextWidthCalcPos(MaxCol(),0,0),
diff --git a/sc/source/core/data/markarr.cxx b/sc/source/core/data/markarr.cxx
index 3db2c9544b2d..83aca1a37d2f 100644
--- a/sc/source/core/data/markarr.cxx
+++ b/sc/source/core/data/markarr.cxx
@@ -24,9 +24,10 @@
#include <osl/diagnose.h>
-ScMarkArray::ScMarkArray() :
+ScMarkArray::ScMarkArray(SCROW nMaxRow) :
nCount( 0 ),
- nLimit( 0 )
+ nLimit( 0 ),
+ mnMaxRow( nMaxRow )
{
// special case "no marks" with pData = NULL
}
@@ -56,7 +57,7 @@ void ScMarkArray::Reset( bool bMarked, SCSIZE nNeeded )
nLimit = nNeeded;
nCount = 1;
pData.reset( new ScMarkEntry[nNeeded] );
- pData[0].nRow = MAXROW;
+ pData[0].nRow = mnMaxRow;
pData[0].bMarked = bMarked;
}
@@ -111,7 +112,7 @@ void ScMarkArray::SetMarkArea( SCROW nStartRow, SCROW nEndRow, bool bMarked )
{
if (ValidRow(nStartRow) && ValidRow(nEndRow))
{
- if ((nStartRow == 0) && (nEndRow == MAXROW))
+ if ((nStartRow == 0) && (nEndRow == mnMaxRow))
{
Reset(bMarked);
}
@@ -143,7 +144,7 @@ void ScMarkArray::SetMarkArea( SCROW nStartRow, SCROW nEndRow, bool bMarked )
}
SCSIZE ni; // number of entries in beginning
- SCSIZE nInsert; // insert position (MAXROW+1 := no insert)
+ SCSIZE nInsert; // insert position (mnMaxRow+1 := no insert)
bool bCombined = false;
bool bSplit = false;
if ( nStartRow > 0 )
@@ -254,7 +255,7 @@ void ScMarkArray::Set( const std::vector<ScMarkEntry> & rMarkEntries )
nLimit = nCount;
pData.reset( new ScMarkEntry[nLimit] );
memcpy(pData.get(), rMarkEntries.data(), sizeof(ScMarkEntry) * rMarkEntries.size());
- pData[nCount-1] = ScMarkEntry{MAXROW, false};
+ pData[nCount-1] = ScMarkEntry{mnMaxRow, false};
}
bool ScMarkArray::IsAllMarked( SCROW nStartRow, SCROW nEndRow ) const
@@ -279,7 +280,7 @@ bool ScMarkArray::HasOneMark( SCROW& rStartRow, SCROW& rEndRow ) const
if ( pData[0].bMarked )
{
rStartRow = 0;
- rEndRow = MAXROW;
+ rEndRow = mnMaxRow;
bRet = true;
}
}
@@ -293,7 +294,7 @@ bool ScMarkArray::HasOneMark( SCROW& rStartRow, SCROW& rEndRow ) const
else
{
rStartRow = pData[0].nRow + 1;
- rEndRow = MAXROW;
+ rEndRow = mnMaxRow;
}
bRet = true;
}
@@ -335,6 +336,7 @@ ScMarkArray& ScMarkArray::operator=( const ScMarkArray& rOther )
pData.reset();
nCount = nLimit = rOther.nCount;
+ mnMaxRow = rOther.mnMaxRow;
return *this;
}
@@ -343,6 +345,7 @@ ScMarkArray& ScMarkArray::operator=(ScMarkArray&& rOther) noexcept
nCount = rOther.nCount;
nLimit = rOther.nLimit;
pData = std::move( rOther.pData );
+ mnMaxRow = rOther.mnMaxRow;
rOther.nCount = 0;
rOther.nLimit = 0;
return *this;
@@ -398,7 +401,7 @@ SCROW ScMarkArray::GetMarkEnd( SCROW nRow, bool bUp ) const
void ScMarkArray::Shift(SCROW nStartRow, long nOffset)
{
- if (!pData || nOffset == 0 || nStartRow > MAXROW)
+ if (!pData || nOffset == 0 || nStartRow > mnMaxRow)
return;
for (size_t i=0; i < nCount; ++i)
@@ -412,9 +415,9 @@ void ScMarkArray::Shift(SCROW nStartRow, long nOffset)
{
rEntry.nRow = 0;
}
- else if (rEntry.nRow > MAXROW)
+ else if (rEntry.nRow > mnMaxRow)
{
- rEntry.nRow = MAXROW;
+ rEntry.nRow = mnMaxRow;
}
}
}
diff --git a/sc/source/core/data/markdata.cxx b/sc/source/core/data/markdata.cxx
index 33c833e191ec..66f067648bb1 100644
--- a/sc/source/core/data/markdata.cxx
+++ b/sc/source/core/data/markdata.cxx
@@ -32,9 +32,11 @@
#include <mdds/flat_segment_tree.hpp>
-ScMarkData::ScMarkData() :
+ScMarkData::ScMarkData(SCROW nMaxRow, SCCOL nMaxCol) :
maTabMarked(),
- aMultiSel()
+ aMultiSel(nMaxRow, nMaxCol),
+ mnMaxRow(nMaxRow),
+ mnMaxCol(nMaxCol)
{
ResetMark();
}
@@ -47,7 +49,9 @@ ScMarkData::ScMarkData(const ScMarkData& rData) :
aTopEnvelope( rData.aTopEnvelope ),
aBottomEnvelope( rData.aBottomEnvelope ),
aLeftEnvelope( rData.aLeftEnvelope ),
- aRightEnvelope( rData.aRightEnvelope )
+ aRightEnvelope( rData.aRightEnvelope ),
+ mnMaxRow( rData.mnMaxRow ),
+ mnMaxCol( rData.mnMaxCol )
{
bMarked = rData.bMarked;
bMultiMarked = rData.bMultiMarked;
@@ -73,6 +77,8 @@ ScMarkData& ScMarkData::operator=(const ScMarkData& rData)
maTabMarked = rData.maTabMarked;
aMultiSel = rData.aMultiSel;
+ mnMaxRow = rData.mnMaxRow;
+ mnMaxCol = rData.mnMaxCol;
return *this;
}
@@ -305,10 +311,10 @@ bool ScMarkData::IsColumnMarked( SCCOL nCol ) const
if ( bMarked && !bMarkIsNeg &&
aMarkRange.aStart.Col() <= nCol && aMarkRange.aEnd.Col() >= nCol &&
- aMarkRange.aStart.Row() == 0 && aMarkRange.aEnd.Row() == MAXROW )
+ aMarkRange.aStart.Row() == 0 && aMarkRange.aEnd.Row() == mnMaxRow )
return true;
- if ( bMultiMarked && aMultiSel.IsAllMarked( nCol, 0, MAXROW ) )
+ if ( bMultiMarked && aMultiSel.IsAllMarked( nCol, 0, mnMaxRow ) )
return true;
return false;
@@ -320,7 +326,7 @@ bool ScMarkData::IsRowMarked( SCROW nRow ) const
//TODO: GetMarkRowRanges for completely marked rows
if ( bMarked && !bMarkIsNeg &&
- aMarkRange.aStart.Col() == 0 && aMarkRange.aEnd.Col() == MAXCOL &&
+ aMarkRange.aStart.Col() == 0 && aMarkRange.aEnd.Col() == mnMaxCol &&
aMarkRange.aStart.Row() <= nRow && aMarkRange.aEnd.Row() >= nRow )
return true;
@@ -359,7 +365,10 @@ void ScMarkData::MarkFromRangeList( const ScRangeList& rList, bool bReset )
/**
Optimise the case of constructing from a range list, speeds up import.
*/
-ScMarkData::ScMarkData(const ScRangeList& rList)
+ScMarkData::ScMarkData(SCROW nMaxRow, SCCOL nMaxCol, const ScRangeList& rList)
+ : aMultiSel(nMaxRow, nMaxCol),
+ mnMaxRow(nMaxRow),
+ mnMaxCol(nMaxCol)
{
ResetMark();
@@ -470,7 +479,7 @@ std::vector<sc::ColRowSpan> ScMarkData::GetMarkedRowSpans() const
typedef mdds::flat_segment_tree<SCCOLROW, bool> SpansType;
ScRangeList aRanges = GetMarkedRanges();
- SpansType aSpans(0, MAXROW+1, false);
+ SpansType aSpans(0, mnMaxRow+1, false);
SpansType::const_iterator itPos = aSpans.begin();
for (size_t i = 0, n = aRanges.size(); i < n; ++i)
@@ -493,7 +502,7 @@ std::vector<sc::ColRowSpan> ScMarkData::GetMarkedColSpans() const
{
// Use segment tree to merge marked with multi marked.
typedef mdds::flat_segment_tree<SCCOLROW, bool> SpansType;
- SpansType aSpans(0, MAXCOL+1, false);
+ SpansType aSpans(0, mnMaxCol+1, false);
SpansType::const_iterator itPos = aSpans.begin();
do
{
@@ -577,7 +586,7 @@ bool ScMarkData::IsAllMarked( const ScRange& rRange ) const
SCROW nEndRow = rRange.aEnd.Row();
bool bOk = true;
- if ( nStartCol == 0 && nEndCol == MAXCOL )
+ if ( nStartCol == 0 && nEndCol == mnMaxCol )
return aMultiSel.IsRowRangeMarked( nStartRow, nEndRow );
for (SCCOL nCol=nStartCol; nCol<=nEndCol && bOk; nCol++)
@@ -690,13 +699,13 @@ void ScMarkData::GetSelectionCover( ScRange& rRange )
SCCOL nStartCol = aMultiRange.aStart.Col(), nEndCol = aMultiRange.aEnd.Col();
PutInOrder( nStartCol, nEndCol );
nStartCol = ( nStartCol == 0 ) ? nStartCol : nStartCol - 1;
- nEndCol = ( nEndCol == MAXCOL ) ? nEndCol : nEndCol + 1;
+ nEndCol = ( nEndCol == mnMaxCol ) ? nEndCol : nEndCol + 1;
std::unique_ptr<ScFlatBoolRowSegments> pPrevColMarkedRows;
std::unique_ptr<ScFlatBoolRowSegments> pCurColMarkedRows;
std::unordered_map<SCROW,ScFlatBoolColSegments> aRowToColSegmentsInTopEnvelope;
std::unordered_map<SCROW,ScFlatBoolColSegments> aRowToColSegmentsInBottomEnvelope;
ScFlatBoolRowSegments aNoRowsMarked;
- aNoRowsMarked.setFalse( 0, MAXROW );
+ aNoRowsMarked.setFalse( 0, mnMaxRow );
bool bPrevColUnMarked = false;
@@ -707,7 +716,7 @@ void ScMarkData::GetSelectionCover( ScRange& rRange )
if ( !bCurColUnMarked )
{
pCurColMarkedRows.reset( new ScFlatBoolRowSegments() );
- pCurColMarkedRows->setFalse( 0, MAXROW );
+ pCurColMarkedRows->setFalse( 0, mnMaxRow );
ScMultiSelIter aMultiIter( aMultiSel, nCol );
ScFlatBoolRowSegments::ForwardIterator aPrevItr(
pPrevColMarkedRows ? *pPrevColMarkedRows
@@ -796,7 +805,7 @@ void ScMarkData::GetSelectionCover( ScRange& rRange )
lcl_AddRanges( rRange, aAddRange ); // Top envelope
aRowToColSegmentsInTopEnvelope[nTop - 1].setTrue( nCol, nCol );
}
- if( nBottom < MAXROW )
+ if( nBottom < mnMaxRow )
{
ScRange aAddRange(nCol, nBottom + 1, aMultiRange.aStart.Tab(),
nCol, nBottom + 1, aMultiRange.aStart.Tab());
@@ -805,7 +814,7 @@ void ScMarkData::GetSelectionCover( ScRange& rRange )
}
}
- while( nTopPrev <= MAXROW && nBottomPrev <= MAXROW && ( nCol > nStartCol ) )
+ while( nTopPrev <= mnMaxRow && nBottomPrev <= mnMaxRow && ( nCol > nStartCol ) )
{
bool bRangeMarked;
const bool bHasValue = aPrevItr1.getValue( nTopPrev, bRangeMarked );
@@ -833,7 +842,7 @@ void ScMarkData::GetSelectionCover( ScRange& rRange )
bool bRangeMarked = false;
ScFlatBoolRowSegments::ForwardIterator aPrevItr(
pPrevColMarkedRows ? *pPrevColMarkedRows : aNoRowsMarked);
- while( nTopPrev <= MAXROW && nBottomPrev <= MAXROW )
+ while( nTopPrev <= mnMaxRow && nBottomPrev <= mnMaxRow )
{
const bool bHasValue = aPrevItr.getValue(nTopPrev, bRangeMarked);
assert(bHasValue); (void)bHasValue;
@@ -909,12 +918,12 @@ void ScMarkData::GetSelectionCover( ScRange& rRange )
aTopEnvelope.push_back( ScRange( nCol1, nRow1 - 1, nTab1, nCol2, nRow1 - 1, nTab2 ) );
--nRow1New;
}
- if( nCol2 < MAXCOL )
+ if( nCol2 < mnMaxCol )
{
aRightEnvelope.push_back( ScRange( nCol2 + 1, nRow1, nTab1, nCol2 + 1, nRow2, nTab2 ) );
++nCol2New;
}
- if( nRow2 < MAXROW )
+ if( nRow2 < mnMaxRow )
{
aBottomEnvelope.push_back( ScRange( nCol1, nRow2 + 1, nTab1, nCol2, nRow2 + 1, nTab2 ) );
++nRow2New;
diff --git a/sc/source/core/data/markmulti.cxx b/sc/source/core/data/markmulti.cxx
index 644dfad21f6c..465d60546e9c 100644
--- a/sc/source/core/data/markmulti.cxx
+++ b/sc/source/core/data/markmulti.cxx
@@ -26,14 +26,19 @@
#include <algorithm>
-ScMultiSel::ScMultiSel()
+ScMultiSel::ScMultiSel(SCROW nMaxRow, SCCOL nMaxCol)
+ : aRowSel(nMaxRow),
+ mnMaxRow(nMaxRow),
+ mnMaxCol(nMaxCol)
{
}
ScMultiSel::ScMultiSel( const ScMultiSel& rOther )
+ : aRowSel(rOther.aRowSel)
{
- aRowSel = rOther.aRowSel;
aMultiSelContainer = rOther.aMultiSelContainer;
+ mnMaxRow = rOther.mnMaxRow;
+ mnMaxCol = rOther.mnMaxCol;
}
ScMultiSel::~ScMultiSel()
@@ -44,6 +49,8 @@ ScMultiSel& ScMultiSel::operator=(const ScMultiSel& rOther)
{
aRowSel = rOther.aRowSel;
aMultiSelContainer = rOther.aMultiSelContainer;
+ mnMaxRow = rOther.mnMaxRow;
+ mnMaxCol = rOther.mnMaxCol;
return *this;
}
@@ -175,7 +182,7 @@ SCROW ScMultiSel::GetNextMarked( SCCOL nCol, SCROW nRow, bool bUp ) const
void ScMultiSel::MarkAllCols( SCROW nStartRow, SCROW nEndRow )
{
- aMultiSelContainer.resize(MAXCOL+1);
+ aMultiSelContainer.resize(MAXCOL+1, ScMarkArray(mnMaxRow));
for ( SCCOL nCol = MAXCOL; nCol >= 0; --nCol )
{
aMultiSelContainer[nCol].SetMarkArea( nStartRow, nEndRow, true );
@@ -233,7 +240,7 @@ void ScMultiSel::SetMarkArea( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, S
}
if (nEndCol >= static_cast<SCCOL>(aMultiSelContainer.size()))
- aMultiSelContainer.resize(nEndCol+1);
+ aMultiSelContainer.resize(nEndCol+1, ScMarkArray(mnMaxRow));
for ( SCCOL nColIter = nEndCol; nColIter >= nStartCol; --nColIter )
aMultiSelContainer[nColIter].SetMarkArea( nStartRow, nEndRow, bMark );
}
@@ -295,7 +302,7 @@ void ScMultiSel::Set( ScRangeList const & rList )
++i;
}
- aMultiSelContainer.resize(nMaxCol+1);
+ aMultiSelContainer.resize(nMaxCol+1, ScMarkArray(mnMaxRow));
for (SCCOL nCol = 0; nCol<=nMaxCol; ++nCol)
if (!aMarkEntriesPerCol[nCol].empty())
{
@@ -320,7 +327,7 @@ bool ScMultiSel::IsRowRangeMarked( SCROW nStartRow, SCROW nEndRow ) const
ScMarkArray ScMultiSel::GetMarkArray( SCCOL nCol ) const
{
ScMultiSelIter aMultiIter( *this, nCol );
- ScMarkArray aMarkArray;
+ ScMarkArray aMarkArray(mnMaxRow);
SCROW nTop, nBottom;
while( aMultiIter.Next( nTop, nBottom ) )
aMarkArray.SetMarkArea( nTop, nBottom, true );
@@ -366,7 +373,7 @@ void ScMultiSel::ShiftCols(SCCOL nStartCol, long nColOffset)
nDestCol = MAXCOL;
}
if (nDestCol >= static_cast<SCCOL>(aMultiSelContainer.size()))
- aMultiSelContainer.resize(nDestCol);
+ aMultiSelContainer.resize(nDestCol, ScMarkArray(mnMaxRow));
aMultiSelContainer[nDestCol] = aSourceArray;
++nCol;
}
@@ -382,7 +389,7 @@ void ScMultiSel::ShiftCols(SCCOL nStartCol, long nColOffset)
rNewCol = rStartPos;
rNewCol.Intersect(rPrevPos);
if (nStartCol + nColOffset >= static_cast<SCCOL>(aNewMultiSel.aMultiSelContainer.size()))
- aNewMultiSel.aMultiSelContainer.resize(nStartCol + nColOffset);
+ aNewMultiSel.aMultiSelContainer.resize(nStartCol + nColOffset, ScMarkArray(mnMaxRow));
for (long i = 1; i < nColOffset; ++i)
aMultiSelContainer[nStartCol + i] = rNewCol;
}
@@ -418,7 +425,7 @@ ScMultiSelIter::ScMultiSelIter( const ScMultiSel& rMultiSel, SCCOL nCol ) :
if (bHasMarks1 && bHasMarks2)
{
pRowSegs.reset( new ScFlatBoolRowSegments);
- pRowSegs->setFalse( 0, MAXROW );
+ pRowSegs->setFalse( 0, rMultiSel.mnMaxRow );
{
ScMarkArrayIter aMarkIter( &rMultiSel.aRowSel );
SCROW nTop, nBottom;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index da2193a68160..2b300d8e0448 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1429,7 +1429,7 @@ const ScRangeList* ScTable::GetScenarioRanges() const
if (!pScenarioRanges)
{
const_cast<ScTable*>(this)->pScenarioRanges.reset(new ScRangeList);
- ScMarkData aMark;
+ ScMarkData aMark(pDocument->MaxRow(), pDocument->MaxCol());
MarkScenarioIn( aMark, ScScenarioFlags::NONE ); // always
aMark.FillRangeListWithMarks( pScenarioRanges.get(), false );
}