tdf#120338 DOCX: add rejection of paragraph formatting changes

using imported change tracking data, instead of doing nothing
for the user request.

Change-Id: I37775ae2d9b78fe3a31541a331f686af9ca9094f
Reviewed-on: https://gerrit.libreoffice.org/75089
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/uiwriter/data2/tdf120338.docx b/sw/qa/extras/uiwriter/data2/tdf120338.docx
new file mode 100644
index 0000000..94e0023
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data2/tdf120338.docx
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index dfa9800..64352b0 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1649,4 +1649,33 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testImageCommentAtChar)
                         pDoc->getIDocumentMarkAccess()->getAnnotationMarksCount());
}

CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf120338)
{
    load(DATA_DIRECTORY, "tdf120338.docx");

    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
    CPPUNIT_ASSERT(pTextDoc);

    CPPUNIT_ASSERT_EQUAL(sal_Int32(1),
                         getProperty<sal_Int32>(getParagraph(2), "ParaAdjust")); // right
    CPPUNIT_ASSERT_EQUAL(sal_Int32(1),
                         getProperty<sal_Int32>(getParagraph(3), "ParaAdjust")); // right
    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
                         getProperty<sal_Int32>(getParagraph(4), "ParaAdjust")); // left
    CPPUNIT_ASSERT_EQUAL(sal_Int32(1),
                         getProperty<sal_Int32>(getParagraph(5), "ParaAdjust")); // right

    // reject tracked paragraph adjustments
    lcl_dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {});

    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
                         getProperty<sal_Int32>(getParagraph(2), "ParaAdjust")); // left
    CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
                         getProperty<sal_Int32>(getParagraph(3), "ParaAdjust")); // center
    CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
                         getProperty<sal_Int32>(getParagraph(4), "ParaAdjust")); // center
    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
                         getProperty<sal_Int32>(getParagraph(5), "ParaAdjust")); // left
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index e46de6b..d2d0adde 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -648,6 +648,7 @@ namespace

        case RedlineType::Format:
        case RedlineType::FmtColl:
        case RedlineType::ParagraphFormat:
            {
                // tdf#52391 instead of hidden acception at the requested
                // rejection, remove direct text formatting to get the potential
@@ -659,6 +660,36 @@ namespace
                    SwPaM aPam( *(pRedl->Start()), *(pRedl->End()) );
                    rDoc.ResetAttrs(aPam);
                }
                else if ( pRedl->GetType() == RedlineType::ParagraphFormat )
                {
                    // handle paragraph formatting changes
                    // (range is only a full paragraph or a part of it)
                    const SwPosition* pStt = pRedl->Start();
                    SwTextNode* pTNd = pStt->nNode.GetNode().GetTextNode();
                    if( pTNd )
                    {
                        // expand range to the whole paragraph
                        // and reset only the paragraph attributes
                        SwPaM aPam( *pTNd, pTNd->GetText().getLength() );
                        std::set<sal_uInt16> aResetAttrsArray;

                        sal_uInt16 aResetableSetRange[] = {
                                RES_PARATR_LINESPACING, RES_PARATR_OUTLINELEVEL,
                                RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1,
                                0
                        };

                        const sal_uInt16 *pUShorts = aResetableSetRange;
                        while (*pUShorts)
                        {
                            for (sal_uInt16 i = pUShorts[0]; i <= pUShorts[1]; ++i)
                                aResetAttrsArray.insert( aResetAttrsArray.end(), i );
                            pUShorts += 2;
                        }

                        rDoc.ResetAttrs(aPam, false, aResetAttrsArray);
                    }
                }

                if( pRedl->GetExtraData() )
                    pRedl->GetExtraData()->Reject( *pRedl );