tdf#143445 DOC import: limit the usage of the CONTINUOUS_ENDNOTES compat flag

The bugdoc has 72 endnotes and not all of them were listed at the end
of the document, since commit 4814e8caa5f06c4fe438dfd7d7315e4a2410ea18
(tdf#124601 sw: add ContinuousEndnotes layout compat option,
2019-09-30).

The problem is that for simple documents the strategy to just place the
endnotes (in the form of footnotes) on the last page works, but this
approach breaks when the document is growing, since nobody moves the
endnotes from the former last page to the new last page. Additionally,
it's not trivial to know what the effective last page is, once you have
enough endnotes that the end of the body text is not on the last page.

Fix the problem by restricting when the DOC import sets this compat
flag. The limit is picked to be 2 endnotes, just because that keeps the
use-cases for continuous endnotes working.

A future solution would be to create a layout-level section at the end
of the document for such endnotes: that would allow them to be inline,
and we know how to keep endnotes inside a section & know how to keep a
section at the end of the document. But that would be a bit of a feature
work, let's keep this regression fix simple.

Change-Id: Ideea1c52f4e31ded3e28e9441aace2bc3857079e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152127
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/sw/qa/filter/ww8/data/3endnotes.doc b/sw/qa/filter/ww8/data/3endnotes.doc
new file mode 100644
index 0000000..fca1cb1
--- /dev/null
+++ b/sw/qa/filter/ww8/data/3endnotes.doc
Binary files differ
diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index b732a37..d9eaff9 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -24,6 +24,7 @@
#include <IDocumentLayoutAccess.hxx>
#include <rootfrm.hxx>
#include <pagefrm.hxx>
#include <ftnfrm.hxx>

namespace
{
@@ -278,6 +279,32 @@ CPPUNIT_TEST_FIXTURE(Test, testWrapThroughLayoutInCell)
    // i.e. layoutInCell was disabled, leading to bad layout in Word.
    assertXPath(pXmlDoc, "//wp:anchor", "layoutInCell", "1");
}

CPPUNIT_TEST_FIXTURE(Test, test3Endnotes)
{
    // Given a DOC file with 3 endnotes:
    createSwDoc("3endnotes.doc");

    // When laying out that document:
    calcLayout();

    // Then make sure that all 3 endnotes are on the last page, like in Word:
    SwDoc* pDoc = getSwDoc();
    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
    SwPageFrame* pPage = pLayout->GetLastPage();
    SwFootnoteContFrame* pFootnoteCont = pPage->FindFootnoteCont();
    int nEndnotes = 0;
    for (SwFrame* pLower = pFootnoteCont->GetLower(); pLower; pLower = pLower->GetNext())
    {
        ++nEndnotes;
    }
    // Without the accompanying fix in place, this test would have failed with:
    // - Expected: 3
    // - Actual  : 1
    // i.e. only 1 endnote was on the last page, the other 2 was not moved to the end of the
    // document, which is incorrect.
    CPPUNIT_ASSERT_EQUAL(3, nEndnotes);
}
}

CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/inc/ftnboss.hxx b/sw/source/core/inc/ftnboss.hxx
index e60ff97..109c9df 100644
--- a/sw/source/core/inc/ftnboss.hxx
+++ b/sw/source/core/inc/ftnboss.hxx
@@ -46,7 +46,7 @@ enum class SwNeighbourAdjust {

typedef std::vector<SwFootnoteFrame*> SwFootnoteFrames;

class SAL_DLLPUBLIC_RTTI SwFootnoteBossFrame: public SwLayoutFrame
class SW_DLLPUBLIC SwFootnoteBossFrame: public SwLayoutFrame
{
    // for private footnote operations
    friend class SwFrame;
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index b57678e..348d95d 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -5175,6 +5175,13 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const *pGloss)
        if( m_xWDop->nEdn )
            aInfo.m_nFootnoteOffset = m_xWDop->nEdn - 1;
        m_rDoc.SetEndNoteInfo( aInfo );

        if (m_xSBase->GetEndnoteCount() > 2)
        {
            // This compatibility flag only works in easy cases, disable it for anything non-trivial
            // for now.
            m_rDoc.getIDocumentSettingAccess().set(DocumentSettingId::CONTINUOUS_ENDNOTES, false);
        }
    }

    if (m_xWwFib->m_lcbPlcfhdd)
diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx
index 9b2fd39..621956be 100644
--- a/sw/source/filter/ww8/ww8scan.hxx
+++ b/sw/source/filter/ww8/ww8scan.hxx
@@ -1081,6 +1081,7 @@ public:
    ~WW8ScannerBase();
    bool AreThereFootnotes() const { return m_pFootnotePLCF->Count() > 0; };
    bool AreThereEndnotes()  const { return m_pEdnPLCF->Count() > 0; };
    tools::Long GetEndnoteCount()  const { return m_pEdnPLCF->Count(); };

    //If you use WW8Fc2Cp you are almost certainly doing the wrong thing
    //when it comes to fastsaved files, avoid like the plague. For export