sw/inc/cellatr.hxx                       |    1 +
 sw/qa/extras/uiwriter/data/tdf157132.odt |binary
 sw/qa/extras/uiwriter/uiwriter8.cxx      |   17 ++++++++++++++++-
 sw/source/core/attr/cellatr.cxx          |   12 ++++++++++++
 sw/source/core/table/swtable.cxx         |    2 +-
 5 files changed, 30 insertions(+), 2 deletions(-)

New commits:
commit 32ce5fe4ed19a79b6f15a5d4d1892e6cc8d778d9
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Nov 23 17:06:51 2023 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Nov 23 18:21:20 2023 +0100

    tdf#158336: Only Change current table
    
    For that, use the same logic as TryBoxNmToPtr
    
    Regression from 0c008ab081aa5bbf53f8562e95e547deae5afc2e
    "tdf#157132: restore behaviour for TBL_RELBOXNAME"
    
    Change-Id: I8f93ad3a9686001fd6bd7226400925e43b81ec23
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159865
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/inc/cellatr.hxx b/sw/inc/cellatr.hxx
index 2c00b5321190..54ddf2caa5ba 100644
--- a/sw/inc/cellatr.hxx
+++ b/sw/inc/cellatr.hxx
@@ -75,6 +75,7 @@ public:
         { return const_cast<SwTableBoxFormula*>(this)->GetTableBox(); }
 
     void TryBoxNmToPtr();
+    void TryRelBoxNm();
     void ToSplitMergeBoxNmWithHistory(SwTableFormulaUpdate& rUpdate, 
SwHistory* pHistory);
     void ChangeState()
     {
diff --git a/sw/qa/extras/uiwriter/data/tdf157132.odt 
b/sw/qa/extras/uiwriter/data/tdf157132.odt
index ddb9522bf835..3cfbec4d756b 100644
Binary files a/sw/qa/extras/uiwriter/data/tdf157132.odt and 
b/sw/qa/extras/uiwriter/data/tdf157132.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx 
b/sw/qa/extras/uiwriter/uiwriter8.cxx
index 41be9a196dfb..0fbb8e9fae81 100644
--- a/sw/qa/extras/uiwriter/uiwriter8.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter8.cxx
@@ -1517,7 +1517,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf157132)
     uno::Reference<container::XIndexAccess> 
xTables(xTextTablesSupplier->getTextTables(),
                                                     uno::UNO_QUERY);
 
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables->getCount());
 
     uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
 
@@ -1533,6 +1533,21 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf157132)
     CPPUNIT_ASSERT_EQUAL(OUString("6"), xCellA4->getString());
     uno::Reference<text::XTextRange> xCellA5(xTextTable->getCellByName("A5"), 
uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(OUString("7"), xCellA5->getString());
+
+    xTextTable.set(xTables->getByIndex(1), uno::UNO_QUERY);
+
+    xCellA2.set(xTextTable->getCellByName("A2"), uno::UNO_QUERY);
+
+    // tdf#158336: Without the fix in place, this test would have failed with
+    // - Expected: 2
+    // - Actual  : ** Expression is faulty **
+    CPPUNIT_ASSERT_EQUAL(OUString("2"), xCellA2->getString());
+    xCellA3.set(xTextTable->getCellByName("A3"), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("3"), xCellA3->getString());
+    xCellA4.set(xTextTable->getCellByName("A4"), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("6"), xCellA4->getString());
+    xCellA5.set(xTextTable->getCellByName("A5"), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("7"), xCellA5->getString());
 }
 
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf147938)
diff --git a/sw/source/core/attr/cellatr.cxx b/sw/source/core/attr/cellatr.cxx
index 9023cca2f793..19e7b2f39d53 100644
--- a/sw/source/core/attr/cellatr.cxx
+++ b/sw/source/core/attr/cellatr.cxx
@@ -104,6 +104,18 @@ void SwTableBoxFormula::TryBoxNmToPtr()
         BoxNmToPtr(&pTableNd->GetTable());
     }
 }
+
+void SwTableBoxFormula::TryRelBoxNm()
+{
+    const SwNode* pNd = GetNodeOfFormula();
+    if (!pNd || &pNd->GetNodes() != &pNd->GetDoc().GetNodes())
+        return;
+    if(const SwTableNode* pTableNd = pNd->FindTableNode())
+    {
+        ToRelBoxNm(&pTableNd->GetTable());
+    }
+}
+
 void SwTableBoxFormula::ToSplitMergeBoxNmWithHistory(SwTableFormulaUpdate& 
rUpdate, SwHistory* pHistory)
 {
     if(!pHistory)
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 8b8f449c7df9..cfa9f52a206c 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -1728,7 +1728,7 @@ void SwTable::UpdateFields(TableFormulaUpdateFlags eFlags)
             if(eFlags == TBL_BOXPTR)
                 pBoxFormula->TryBoxNmToPtr();
             else if(eFlags == TBL_RELBOXNAME)
-                pBoxFormula->ToRelBoxNm(this);
+                pBoxFormula->TryRelBoxNm();
             else
                 pBoxFormula->ChangeState();
         }

Reply via email to