tdf#125881 DOCX import: handle list level after tracked deletion

to avoid bad numbering (for example import "II.1" instead of "I.3").

Commit cbd894925e6b9869baedcd6476484c14d3a3df87
"tdf#125319 DOCX track changes: don't change numbering" fixed losing
numbering after tracked deletion (for example, during switching off the
Show Changes mode or by DOCX export of the attached test document), but
not handling list levels still changed the numbering.

Change-Id: I67cd9459bc44e9bb470bfed6834be2e88edfe0d0
Reviewed-on: https://gerrit.libreoffice.org/73978
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/uiwriter/data2/tdf125881.docx b/sw/qa/extras/uiwriter/data2/tdf125881.docx
new file mode 100644
index 0000000..569d048
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data2/tdf125881.docx
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index da18385..1be95f8 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1252,6 +1252,22 @@
            .is());
}

CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf125881_redline_list_level)
{
    load(DATA_DIRECTORY, "tdf125881.docx");

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

    // deleted paragraph gets the numbering of the next paragraph
    uno::Reference<beans::XPropertySet> xProps(getParagraph(8), uno::UNO_QUERY_THROW);
    CPPUNIT_ASSERT_MESSAGE("first paragraph after the first deletion: missing numbering",
                           xProps->getPropertyValue("NumberingRules").hasValue());

    // check numbering level at deletion (1 instead of 0)
    CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(getParagraph(8), "NumberingLevel"));
}

CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf125310)
{
    load(DATA_DIRECTORY, "tdf125310.fodt");
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index 94a361e..8548768 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -3029,7 +3029,7 @@

void DocumentRedlineManager::FinalizeImport()
{
    // tdf#118699 fix numbering after deletion of numbered list items
    // set correct numbering after deletion
    for( SwRedlineTable::size_type n = 0; n < mpRedlineTable->size(); ++n )
    {
        SwRangeRedline* pRedl = (*mpRedlineTable)[ n ];
@@ -3040,19 +3040,22 @@
                                ? pRedl->GetMark() : pRedl->GetPoint();
            SwTextNode* pDelNode = pStt->nNode.GetNode().GetTextNode();
            SwTextNode* pTextNode = pEnd->nNode.GetNode().GetTextNode();
            // avoid of incorrect numbering after the deletion

            if ( pDelNode->GetNumRule() && !pTextNode->GetNumRule() )
            {
                // remove numbering of the first deleted list item
                // tdf#118699 remove numbering of the first deleted list item
                const SwPaM aPam( *pStt, *pStt );
                m_rDoc.DelNumRules( aPam );
            }
            else if ( pDelNode->GetNumRule() != pTextNode->GetNumRule() )
            {
                // copy numbering to the first deleted list item
                // tdf#125319 copy numbering to the first deleted list item
                const SwPaM aPam( *pStt, *pStt );
                SwNumRule *pRule = pTextNode->GetNumRule();
                m_rDoc.SetNumRule( aPam, *pRule, false );

                // tdf#125881 copy also numbering level
                pDelNode->SetAttrListLevel( pTextNode->GetAttrListLevel() );
            }
        }
    }