sw/qa/extras/uiwriter/uiwriter2.cxx |   45 ++++++++++++++++++++++++++++++++++++
 sw/source/core/doc/tblrwcl.cxx      |   23 ++++++++++++++++--
 2 files changed, 65 insertions(+), 3 deletions(-)

New commits:
commit 9b762a82ffb09c55a00343d1202c64f35f17f147
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed Sep 22 16:26:18 2021 +0200
Commit:     Tünde Tóth <toth.tu...@nisz.hu>
CommitDate: Thu Oct 21 15:11:08 2021 +0200

    tdf#143358 sw: track insertion of empty table rows
    
    Insertion of empty table rows wasn't tracked, and
    inserting also text in the new rows and rejecting
    everything didn't reject the row insertion.
    
    Follow-up to commit 99059a1ececa3621c2fe46fabdd79eed9d626c42
    "tdf#143359 sw: track deletion of empty table rows".
    
    Note: as a workaround for tracking of the empty rows,
    i.e. rows without text content, add a redline with
    invisible text CH_TXT_TRACKED_DUMMY_CHAR in the first
    cell of the empty row.
    
    See also commit a483a44ca00f43a64ae51d62b8fbb4129a413f6d
    "tdf#143215 DOCX import: fix tracked empty row insertion/deletion",
    commit b50d386dfa70f7c1d4eb1a49091ec9dd782b767b
    "tdf#142701 track changes: fix layout regression of image deletion"
    and commit 05366b8e6683363688de8708a3d88cf144c7a2bf
    "tdf#60382 sw offapi: add change tracking of table/row deletion".
    
    Change-Id: I237d566a468f61f31fa19dd1d6d9bb559be99158
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122460
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit dbc82c02eb24ec1c97c6ee32069771d8deb394f9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123985
    Tested-by: Tünde Tóth <toth.tu...@nisz.hu>
    Reviewed-by: Tünde Tóth <toth.tu...@nisz.hu>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 2a0d66bab23e..daef23db226d 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -4016,6 +4016,51 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, 
testRedlineTableRowDeletionWithReject)
     assertXPath(pXmlDoc, "//page[1]//body/tab", 0);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testRedlineTableRowInsertionWithReject)
+{
+    // load a 1-row table, and insert a row with enabled change tracking
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf118311.fodt");
+
+    // turn on red-lining and show changes
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | 
RedlineFlags::ShowDelete
+                                                      | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+
+    // check table and its single row
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 1);
+
+    // insert rows before and after with enabled change tracking
+    // (HasTextChangesOnly property of the row will be false, and
+    // add dummy characters CH_TXT_TRACKED_DUMMY_CHAR)
+    dispatchCommand(mxComponent, ".uno:InsertRowsBefore", {});
+    dispatchCommand(mxComponent, ".uno:InsertRowsAfter", {});
+
+    SwEditShell* const pEditShell(pDoc->GetEditShell());
+    // This was 0 (not tracked row insertion)
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(2), 
pEditShell->GetRedlineCount());
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 3);
+
+    // reject redlines
+    pEditShell->RejectRedline(0);
+    pEditShell->RejectRedline(0);
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "//page[1]//body/tab");
+    // This was 3 (not rejected row insertion)
+    assertXPath(pXmlDoc, "//page[1]//body/tab/row", 1);
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf128603)
 {
     // Load the bugdoc, which has 3 textboxes.
diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx
index 76474bba91b6..e6c97a71139a 100644
--- a/sw/source/core/doc/tblrwcl.cxx
+++ b/sw/source/core/doc/tblrwcl.cxx
@@ -242,7 +242,7 @@ struct CpyPara
 
 }
 
-static void lcl_CopyRow(FndLine_ & rFndLine, CpyPara *const pCpyPara);
+static SwTableLine* lcl_CopyRow(FndLine_ & rFndLine, CpyPara *const pCpyPara);
 
 static void lcl_CopyCol( FndBox_ & rFndBox, CpyPara *const pCpyPara)
 {
@@ -377,7 +377,7 @@ static void lcl_CopyCol( FndBox_ & rFndBox, CpyPara *const 
pCpyPara)
     }
 }
 
-static void lcl_CopyRow(FndLine_& rFndLine, CpyPara *const pCpyPara)
+static SwTableLine* lcl_CopyRow(FndLine_& rFndLine, CpyPara *const pCpyPara)
 {
     SwTableLine* pNewLine = new SwTableLine(
                             
static_cast<SwTableLineFormat*>(rFndLine.GetLine()->GetFrameFormat()),
@@ -400,6 +400,8 @@ static void lcl_CopyRow(FndLine_& rFndLine, CpyPara *const 
pCpyPara)
     }
 
     pCpyPara->nDelBorderFlag &= 0xf8;
+
+    return pNewLine;
 }
 
 static void lcl_InsCol( FndLine_* pFndLn, CpyPara& rCpyPara, sal_uInt16 
nCpyCnt,
@@ -582,7 +584,22 @@ bool SwTable::InsertRow_( SwDoc* pDoc, const SwSelBoxes& 
rBoxes,
         if( bBehind )
             aCpyPara.nDelBorderFlag = 1;
         for (auto & rpFndLine : pFndBox->GetLines())
-            lcl_CopyRow( *rpFndLine, &aCpyPara );
+        {
+            SwTableLine* pNewTableLine = lcl_CopyRow( *rpFndLine, &aCpyPara );
+
+            // tracked insertion of empty table line
+            if ( pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
+            {
+                SvxPrintItem aSetTracking(RES_PRINT, false);
+                SwPosition aPos(*pNewTableLine->GetTabBoxes()[0]->GetSttNd());
+                SwCursor aCursor( aPos, nullptr );
+                SwNodeIndex 
aInsPos(*pNewTableLine->GetTabBoxes()[0]->GetSttNd(), 1 );
+                SwPaM aPaM(aInsPos);
+                pDoc->getIDocumentContentOperations().InsertString( aPaM,
+                        OUStringChar(CH_TXT_TRACKED_DUMMY_CHAR) );
+                pDoc->SetRowNotTracked( aCursor, aSetTracking );
+            }
+        }
     }
 
     // clean up this Line's structure once again, generally all of them

Reply via email to