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 391ce12ab3b1da06bb1a5ecfdb5ec26052ac8f95
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: Tue May 31 09:21:15 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/+/135136
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 3c9a3db2417c..fbfa84fb0450 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -187,6 +187,7 @@ public:
     void testFormulaPosition();
     void testFormulaWizardSubformula();
     void testDiagonalBorders();
+    void testWholeDocBorders();
 
     /**
      * Make sure the sheet streams are invalidated properly.
@@ -318,6 +319,7 @@ public:
     CPPUNIT_TEST(testFormulaPosition);
     CPPUNIT_TEST(testFormulaWizardSubformula);
     CPPUNIT_TEST(testDiagonalBorders);
+    CPPUNIT_TEST(testWholeDocBorders);
     CPPUNIT_TEST(testJumpToPrecedentsDependents);
     CPPUNIT_TEST(testSetBackgroundColor);
     CPPUNIT_TEST(testRenameTable);
@@ -6299,6 +6301,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 f468ce96587f..5a4e62c4de00 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -1241,9 +1241,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);
@@ -1274,10 +1275,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 5943feb9e5f6..e42a6e69de4a 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2863,7 +2863,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 ed295dd1ae9bf01b493f782df05e9cb55ee1f5cb
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: Tue May 31 09:21:02 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/+/135072
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    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 1b84ae4616a5..f468ce96587f 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -1169,12 +1169,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 );
@@ -1194,34 +1194,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)
@@ -1242,10 +1242,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?
@@ -1259,7 +1259,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)
@@ -1272,11 +1272,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);
     }
 }
 

Reply via email to