sc/inc/attarray.hxx | 2 - sc/qa/unit/ucalc.cxx | 74 +++++++++++++++++++++++++++++++++++++++ sc/source/core/data/attarray.cxx | 35 ++++++++---------- sc/source/core/data/table2.cxx | 2 - 4 files changed, 92 insertions(+), 21 deletions(-)
New commits: commit 970ff17f47731be788ec34c0c8ddf3fb2c24ceac Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Mon May 30 16:33:15 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Mon May 30 21:20:54 2022 +0200 fix setting cell borders for unallocated cells First of all, it should not be clamped to allocated columns. Second, 06d3294502413a231e5c5265609862c7f67a2f2b incorrectly handled unallocated columns by setting the attribute for all rows, instead of handling the inner ones differently. Change-Id: I3115b314971f8c152cbdeda674863a8a78ee12eb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135131 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 9f8fad755ea1..a83b5482647f 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -157,6 +157,7 @@ public: void testFormulaPosition(); void testFormulaWizardSubformula(); void testDiagonalBorders(); + void testWholeDocBorders(); /** * Make sure the sheet streams are invalidated properly. @@ -290,6 +291,7 @@ public: CPPUNIT_TEST(testFormulaPosition); CPPUNIT_TEST(testFormulaWizardSubformula); CPPUNIT_TEST(testDiagonalBorders); + CPPUNIT_TEST(testWholeDocBorders); CPPUNIT_TEST(testJumpToPrecedentsDependents); CPPUNIT_TEST(testSetBackgroundColor); CPPUNIT_TEST(testRenameTable); @@ -6310,6 +6312,78 @@ void Test::testDiagonalBorders() m_pDoc->DeleteTab(0); } +void Test::testWholeDocBorders() +{ + m_pDoc->InsertTab(0, "Borders"); + + // Set outside border to be on all sides, and inside borders to be only vertical. + // This should result in edge borders of the spreadsheets being set, but internal + // borders between cells should be only vertical, not horizontal. + ::editeng::SvxBorderLine line(nullptr, 50, SvxBorderLineStyle::SOLID); + SvxBoxItem borderItem(ATTR_BORDER); + borderItem.SetLine(&line, SvxBoxItemLine::LEFT); + borderItem.SetLine(&line, SvxBoxItemLine::RIGHT); + borderItem.SetLine(&line, SvxBoxItemLine::TOP); + borderItem.SetLine(&line, SvxBoxItemLine::BOTTOM); + SvxBoxInfoItem boxInfoItem(ATTR_BORDER); + boxInfoItem.SetLine(&line, SvxBoxInfoItemLine::VERT); + + ScMarkData mark( m_pDoc->GetSheetLimits(), ScRange( 0, 0, 0, m_pDoc->MaxCol(), m_pDoc->MaxRow(), 0 )); + m_pDoc->ApplySelectionFrame( mark, borderItem, &boxInfoItem ); + + const ScPatternAttr* attr; + attr = m_pDoc->GetPattern( 0, 0, 0 ); + CPPUNIT_ASSERT(attr); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetTop()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetLeft()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetRight()); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetBottom()); + + attr = m_pDoc->GetPattern( 1, 0, 0 ); + CPPUNIT_ASSERT(attr); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetTop()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetLeft()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetRight()); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetBottom()); + + attr = m_pDoc->GetPattern( 0, 1, 0 ); + CPPUNIT_ASSERT(attr); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetTop()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetLeft()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetRight()); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetBottom()); + + attr = m_pDoc->GetPattern( 1, 1, 0 ); + CPPUNIT_ASSERT(attr); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetTop()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetLeft()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetRight()); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetBottom()); + + attr = m_pDoc->GetPattern( m_pDoc->MaxCol(), 0, 0 ); + CPPUNIT_ASSERT(attr); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetTop()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetLeft()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetRight()); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetBottom()); + + attr = m_pDoc->GetPattern( 0, m_pDoc->MaxRow(), 0 ); + CPPUNIT_ASSERT(attr); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetTop()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetLeft()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetRight()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetBottom()); + + attr = m_pDoc->GetPattern( m_pDoc->MaxCol(), m_pDoc->MaxRow(), 0 ); + CPPUNIT_ASSERT(attr); + CPPUNIT_ASSERT(!attr->GetItem(ATTR_BORDER).GetTop()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetLeft()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetRight()); + CPPUNIT_ASSERT(attr->GetItem(ATTR_BORDER).GetBottom()); + + m_pDoc->DeleteTab(0); +} + void Test::testSetStringAndNote() { m_pDoc->InsertTab(0, "Test"); diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index 935a46a017be..356786667032 100644 --- a/sc/source/core/data/attarray.cxx +++ b/sc/source/core/data/attarray.cxx @@ -1234,9 +1234,10 @@ bool ScAttrArray::ApplyFrame( const SvxBoxItem& rBoxItem, void ScAttrArray::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight) { + SetDefaultIfNotInit(); if (nStartRow == nEndRow) ApplyFrame(rLineOuter, pLineInner, nStartRow, nEndRow, bLeft, nDistRight, true, 0); - else if ( !mvData.empty() ) + else { ApplyFrame(rLineOuter, pLineInner, nStartRow, nStartRow, bLeft, nDistRight, true, nEndRow-nStartRow); @@ -1267,10 +1268,6 @@ void ScAttrArray::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfo ApplyFrame(rLineOuter, pLineInner, nEndRow, nEndRow, bLeft, nDistRight, false, 0); } - else - { - ApplyFrame(rLineOuter, pLineInner, nStartRow, nEndRow, bLeft, nDistRight, true, 0); - } } bool ScAttrArray::HasAttrib_Impl(const ScPatternAttr* pPattern, HasAttrFlags nMask, SCROW nRow1, SCROW nRow2, SCSIZE i) const diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 4e1d1f4da99d..8193d4e4328e 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -2855,7 +2855,7 @@ void ScTable::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem { PutInOrder(nStartCol, nEndCol); PutInOrder(nStartRow, nEndRow); - nEndCol = ClampToAllocatedColumns(nEndCol); + CreateColumnIfNotExists(nEndCol); for (SCCOL i=nStartCol; i<=nEndCol; i++) aCol[i].ApplyBlockFrame(rLineOuter, pLineInner, nStartRow, nEndRow, (i==nStartCol), nEndCol-i); commit 3e738f53a69e474f22b4d6599ce16e5fe3d691df Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Mon May 30 15:29:49 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Mon May 30 21:20:39 2022 +0200 first arg of ApplyFrame is never null e4008dc0c3b43c9eacdd88511075be2b88 did this for ApplyBlockFrame() but didn't chagne ApplyFrame() which is only called from there. Change-Id: I9f1dce3dc7fda23b42e90432c13dfca0aa7f267e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135130 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/inc/attarray.hxx b/sc/inc/attarray.hxx index f4028b844c62..868118796560 100644 --- a/sc/inc/attarray.hxx +++ b/sc/inc/attarray.hxx @@ -102,7 +102,7 @@ friend class ScDocumentIterator; friend class ScAttrIterator; friend class ScHorizontalAttrIterator; - bool ApplyFrame( const SvxBoxItem* pLineOuter, const SvxBoxInfoItem* pLineInner, + bool ApplyFrame( const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom ); diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index 2f7e686ac383..935a46a017be 100644 --- a/sc/source/core/data/attarray.cxx +++ b/sc/source/core/data/attarray.cxx @@ -1162,12 +1162,12 @@ void ScAttrArray::MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLine // ApplyFrame - on an entry into the array -bool ScAttrArray::ApplyFrame( const SvxBoxItem* pBoxItem, +bool ScAttrArray::ApplyFrame( const SvxBoxItem& rBoxItem, const SvxBoxInfoItem* pBoxInfoItem, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight, bool bTop, SCROW nDistBottom ) { - OSL_ENSURE( pBoxItem && pBoxInfoItem, "Missing line attributes!" ); + OSL_ENSURE( pBoxInfoItem, "Missing line attributes!" ); const ScPatternAttr* pPattern = GetPattern( nStartRow ); const SvxBoxItem* pOldFrame = &pPattern->GetItemSet().Get( ATTR_BORDER ); @@ -1187,34 +1187,34 @@ bool ScAttrArray::ApplyFrame( const SvxBoxItem* pBoxItem, if( bLeft && nDistRight==0) { if ( pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::LEFT) ) - aNewFrame.SetLine( pBoxItem->GetLeft(), SvxBoxItemLine::RIGHT ); + aNewFrame.SetLine( rBoxItem.GetLeft(), SvxBoxItemLine::RIGHT ); if ( pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::RIGHT) ) - aNewFrame.SetLine( pBoxItem->GetRight(), SvxBoxItemLine::LEFT ); + aNewFrame.SetLine( rBoxItem.GetRight(), SvxBoxItemLine::LEFT ); } else { if ( (nDistRight==0) ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::LEFT) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::VERT) ) - aNewFrame.SetLine( (nDistRight==0) ? pBoxItem->GetLeft() : pBoxInfoItem->GetVert(), + aNewFrame.SetLine( (nDistRight==0) ? rBoxItem.GetLeft() : pBoxInfoItem->GetVert(), SvxBoxItemLine::RIGHT ); if ( bLeft ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::RIGHT) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::VERT) ) - aNewFrame.SetLine( bLeft ? pBoxItem->GetRight() : pBoxInfoItem->GetVert(), + aNewFrame.SetLine( bLeft ? rBoxItem.GetRight() : pBoxInfoItem->GetVert(), SvxBoxItemLine::LEFT ); } } else { if ( bLeft ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::LEFT) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::VERT) ) - aNewFrame.SetLine( bLeft ? pBoxItem->GetLeft() : pBoxInfoItem->GetVert(), + aNewFrame.SetLine( bLeft ? rBoxItem.GetLeft() : pBoxInfoItem->GetVert(), SvxBoxItemLine::LEFT ); if ( (nDistRight==0) ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::RIGHT) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::VERT) ) - aNewFrame.SetLine( (nDistRight==0) ? pBoxItem->GetRight() : pBoxInfoItem->GetVert(), + aNewFrame.SetLine( (nDistRight==0) ? rBoxItem.GetRight() : pBoxInfoItem->GetVert(), SvxBoxItemLine::RIGHT ); } if ( bTop ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::TOP) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::HORI) ) - aNewFrame.SetLine( bTop ? pBoxItem->GetTop() : pBoxInfoItem->GetHori(), + aNewFrame.SetLine( bTop ? rBoxItem.GetTop() : pBoxInfoItem->GetHori(), SvxBoxItemLine::TOP ); if ( (nDistBottom==0) ? pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::BOTTOM) : pBoxInfoItem->IsValid(SvxBoxInfoItemValidFlags::HORI) ) - aNewFrame.SetLine( (nDistBottom==0) ? pBoxItem->GetBottom() : pBoxInfoItem->GetHori(), + aNewFrame.SetLine( (nDistBottom==0) ? rBoxItem.GetBottom() : pBoxInfoItem->GetHori(), SvxBoxItemLine::BOTTOM ); if (aNewFrame == *pOldFrame) @@ -1235,10 +1235,10 @@ void ScAttrArray::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfo SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight) { if (nStartRow == nEndRow) - ApplyFrame(&rLineOuter, pLineInner, nStartRow, nEndRow, bLeft, nDistRight, true, 0); + ApplyFrame(rLineOuter, pLineInner, nStartRow, nEndRow, bLeft, nDistRight, true, 0); else if ( !mvData.empty() ) { - ApplyFrame(&rLineOuter, pLineInner, nStartRow, nStartRow, bLeft, nDistRight, + ApplyFrame(rLineOuter, pLineInner, nStartRow, nStartRow, bLeft, nDistRight, true, nEndRow-nStartRow); if ( nEndRow > nStartRow+1 ) // inner part available? @@ -1252,7 +1252,7 @@ void ScAttrArray::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfo for (SCSIZE i=nStartIndex; i<=nEndIndex;) { nTmpEnd = std::min( static_cast<SCROW>(nEndRow-1), mvData[i].nEndRow ); - bool bChanged = ApplyFrame(&rLineOuter, pLineInner, nTmpStart, nTmpEnd, + bool bChanged = ApplyFrame(rLineOuter, pLineInner, nTmpStart, nTmpEnd, bLeft, nDistRight, false, nEndRow - nTmpEnd); nTmpStart = nTmpEnd+1; if (bChanged) @@ -1265,11 +1265,11 @@ void ScAttrArray::ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfo } } - ApplyFrame(&rLineOuter, pLineInner, nEndRow, nEndRow, bLeft, nDistRight, false, 0); + ApplyFrame(rLineOuter, pLineInner, nEndRow, nEndRow, bLeft, nDistRight, false, 0); } else { - ApplyFrame(&rLineOuter, pLineInner, nStartRow, nEndRow, bLeft, nDistRight, true, 0); + ApplyFrame(rLineOuter, pLineInner, nStartRow, nEndRow, bLeft, nDistRight, true, 0); } }