summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2020-04-08 00:47:09 +0200
committerEike Rathke <erack@redhat.com>2020-04-08 01:57:45 +0200
commitb1da67699bd05b26ee11460347ca7077d366c2fc (patch)
treec6f9b96bceac4fabe3748f66e52232684ef0f20d /sc/source/core
parentb3363960f97dcb7eaa10dfa708d71198a345924c (diff)
Resolves: tdf#131442 Sort must not contain matrix formula except 1x1 array
Change-Id: Idc7a9646a70c59fceee0b36426f38a938cf073ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91858 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/data/column.cxx8
-rw-r--r--sc/source/core/data/document.cxx5
-rw-r--r--sc/source/core/data/table2.cxx30
3 files changed, 31 insertions, 12 deletions
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 7fa1c4c30286..9388e01ee1f0 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -110,7 +110,8 @@ SCROW ScColumn::GetNextUnprotected( SCROW nRow, bool bUp ) const
return pAttrArray->GetNextUnprotected(nRow, bUp);
}
-sc::MatrixEdge ScColumn::GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sc::MatrixEdge nMask ) const
+sc::MatrixEdge ScColumn::GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sc::MatrixEdge nMask,
+ bool bNoMatrixAtAll ) const
{
using namespace sc;
@@ -163,6 +164,11 @@ sc::MatrixEdge ScColumn::GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sc::Matr
if (nEdges == MatrixEdge::Nothing)
continue;
+ // A 1x1 matrix array formula is OK even for no matrix at all.
+ if (bNoMatrixAtAll
+ && (nEdges != (MatrixEdge::Top | MatrixEdge::Left | MatrixEdge::Bottom | MatrixEdge::Right)))
+ return MatrixEdge::Inside; // per convention Inside
+
if (nEdges & MatrixEdge::Top)
bOpen = true; // top edge opens, keep on looking
else if (!bOpen)
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 4ecd59225f45..ad292b70b7e2 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -5323,7 +5323,8 @@ void ScDocument::UnlockTable(SCTAB nTab)
bool ScDocument::IsBlockEditable( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
SCCOL nEndCol, SCROW nEndRow,
- bool* pOnlyNotBecauseOfMatrix /* = NULL */ ) const
+ bool* pOnlyNotBecauseOfMatrix /* = NULL */,
+ bool bNoMatrixAtAll ) const
{
// import into read-only document is possible
if (!bImportingXML && !mbChangeReadOnlyEnabled && mpShell && mpShell->IsReadOnly())
@@ -5336,7 +5337,7 @@ bool ScDocument::IsBlockEditable( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
if (maTabs[nTab])
return maTabs[nTab]->IsBlockEditable( nStartCol, nStartRow, nEndCol,
- nEndRow, pOnlyNotBecauseOfMatrix );
+ nEndRow, pOnlyNotBecauseOfMatrix, bNoMatrixAtAll );
OSL_FAIL("wrong table number");
if ( pOnlyNotBecauseOfMatrix )
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index a4391ab7ec05..869d255b2b47 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2297,7 +2297,8 @@ void ScTable::FindMaxRotCol( RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nX1, SCC
}
}
-bool ScTable::HasBlockMatrixFragment( const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2 ) const
+bool ScTable::HasBlockMatrixFragment( const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2,
+ bool bNoMatrixAtAll ) const
{
using namespace sc;
@@ -2311,28 +2312,38 @@ bool ScTable::HasBlockMatrixFragment( const SCCOL nCol1, SCROW nRow1, const SCCO
if ( nCol1 == nMaxCol2 )
{ // left and right column
const MatrixEdge n = MatrixEdge::Left | MatrixEdge::Right;
- nEdges = aCol[nCol1].GetBlockMatrixEdges( nRow1, nRow2, n );
+ nEdges = aCol[nCol1].GetBlockMatrixEdges( nRow1, nRow2, n, bNoMatrixAtAll );
if ((nEdges != MatrixEdge::Nothing) && (((nEdges & n)!=n) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
return true; // left or right edge is missing or open
}
else
{ // left column
- nEdges = aCol[nCol1].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Left);
+ nEdges = aCol[nCol1].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Left, bNoMatrixAtAll);
if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Left)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
return true; // left edge missing or open
// right column
- nEdges = aCol[nMaxCol2].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Right);
+ nEdges = aCol[nMaxCol2].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Right, bNoMatrixAtAll);
if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Right)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
return true; // right edge is missing or open
}
- if ( nRow1 == nRow2 )
+ if (bNoMatrixAtAll)
+ {
+ for (SCCOL i=nCol1; i<=nMaxCol2; i++)
+ {
+ nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow2, MatrixEdge::Nothing, bNoMatrixAtAll);
+ if (nEdges != MatrixEdge::Nothing
+ && (nEdges != (MatrixEdge::Top | MatrixEdge::Left | MatrixEdge::Bottom | MatrixEdge::Right)))
+ return true;
+ }
+ }
+ else if ( nRow1 == nRow2 )
{ // Row on top and on bottom
bool bOpen = false;
const MatrixEdge n = MatrixEdge::Bottom | MatrixEdge::Top;
for ( SCCOL i=nCol1; i<=nMaxCol2; i++)
{
- nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow1, n );
+ nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow1, n, bNoMatrixAtAll );
if (nEdges != MatrixEdge::Nothing)
{
if ( (nEdges & n) != n )
@@ -2360,7 +2371,7 @@ bool ScTable::HasBlockMatrixFragment( const SCCOL nCol1, SCROW nRow1, const SCCO
bool bOpen = false;
for ( SCCOL i=nCol1; i<=nMaxCol2; i++)
{
- nEdges = aCol[i].GetBlockMatrixEdges( nR, nR, n );
+ nEdges = aCol[i].GetBlockMatrixEdges( nR, nR, n, bNoMatrixAtAll );
if ( nEdges != MatrixEdge::Nothing)
{
// in top row no top edge respectively
@@ -2399,7 +2410,8 @@ bool ScTable::HasSelectionMatrixFragment( const ScMarkData& rMark ) const
}
bool ScTable::IsBlockEditable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2,
- SCROW nRow2, bool* pOnlyNotBecauseOfMatrix /* = NULL */ ) const
+ SCROW nRow2, bool* pOnlyNotBecauseOfMatrix /* = NULL */,
+ bool bNoMatrixAtAll ) const
{
if ( !ValidColRow( nCol2, nRow2 ) )
{
@@ -2467,7 +2479,7 @@ bool ScTable::IsBlockEditable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2,
}
if ( bIsEditable )
{
- if ( HasBlockMatrixFragment( nCol1, nRow1, nCol2, nRow2 ) )
+ if (HasBlockMatrixFragment( nCol1, nRow1, nCol2, nRow2, bNoMatrixAtAll))
{
bIsEditable = false;
if ( pOnlyNotBecauseOfMatrix )