tdf#153437 sc: fix broken formatting without performance regression
Follow-up to commit 7be7e1ff95af485a9cb00748800d3d084f96387c
"tdf#153437 sc: fix broken formatting at Undo of row/column insertion"
by replacing that with a better version without performance
regression. This keeps the original performance fix of
commit 2e86718626a07e1656661df3ad69a64848bf4614
"don't allocate unnecessary columns when inserting a row"
related to the support of 16k columns.
The previous fix used extra memory to fix the broken formatting
of the cells. I have now solved the error in tdf#153437 without
taking extra memory. It doesn't change the reserved cells, it just
deletes a row from the default attribute of the cells when deleting
rows, so they don't slip. When deleting a column, the last column
in the still reserved area loses its formatting. I copied the default value back here, as the other columns have this value.
Change-Id: I35da1cb79ff4e3493e91d29766cc2b81412080eb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152742
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit c61f5a5d55c07721f044befc1f6efa0231cd92f6)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152814
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153494
Tested-by: Jenkins
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 949ca30..87d3dc7 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -171,6 +171,7 @@ public:
bool TestInsertRow( SCSIZE nSize ) const;
void InsertRow( SCROW nStartRow, SCSIZE nSize );
void DeleteRow( SCROW nStartRow, SCSIZE nSize );
};
// Use protected inheritance to prevent publishing some internal ScColumnData
@@ -1054,4 +1055,9 @@ inline void ScColumnData::InsertRow( SCROW nStartRow, SCSIZE nSize )
pAttrArray->InsertRow( nStartRow, nSize );
}
inline void ScColumnData::DeleteRow(SCROW nStartRow, SCSIZE nSize)
{
pAttrArray->DeleteRow( nStartRow, nSize );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 6cb5384..3080256 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1851,13 +1851,11 @@ void ScTable::UpdateReference(
}
else
{
// When deleting row(s) or column(s), allocate the last column
// before updating the references
if (nDx < 0 || nDy < 0)
CreateColumnIfNotExists(rDocument.MaxCol());
for (SCCOL col : GetColumnsRange(0, rDocument.MaxCol()))
bUpdated |= CreateColumnIfNotExists(col).UpdateReference(rCxt, pUndoDoc);
for (SCCOL col : GetAllocatedColumnsRange(0, rDocument.MaxCol()))
bUpdated |= aCol[col].UpdateReference(rCxt, pUndoDoc);
// When deleting row(s), delete same row from the default attribute
if (nDy < 0)
aDefaultColData.DeleteRow(nRow1+nDy, -nDy);
}
if ( bIncludeDraw )
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 9a163e2..a4758d0 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -400,6 +400,9 @@ void ScTable::DeleteCol(
{
for (SCCOL nCol = nStartCol + nSize; nCol < aCol.size(); ++nCol)
aCol[nCol].SwapCol(aCol[nCol - nSize]);
// When delete column(s), inicialize the last columns from the default attributes
for (SCCOL nCol = aCol.size() - nSize; nCol < aCol.size(); ++nCol)
aCol[nCol].Init(nCol, aCol[nCol].GetTab(), rDocument, false);
}
else
{