tdf#160984 sw continuous endnotes: add a way to find the endnote section start

Existing code with endnotes on separate page at the end of the document
works by searching for a current or next page that is an endnote page in
SwFootnoteBossFrame::AppendFootnote(), and in case none is found, then
an endnote page is created.

Add similar infrastructure for the inline endnotes case: here we want to
find the first page that has an endnotes section, which also requires
being able to tell if a section is an endnotes one.

The newly introduced SwPageFrame::GetEndNoteSection() is not yet used in
SwFootnoteBossFrame::AppendFootnote(), though.

Change-Id: Ib08267f9bf6c7b06576624e3fa8e90e8b8b1b232
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167371
Reviewed-by: Miklos Vajna <[email protected]>
Tested-by: Jenkins
diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index 23d77b1..be55221 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -204,6 +204,7 @@ public:
    bool IsEndNotePage() const                      { return m_bEndNotePage; }
    void SetFootnotePage( bool b )                       { m_bFootnotePage = b; }
    void SetEndNotePage( bool b )                   { m_bEndNotePage = b; }
    SwSectionFrame* GetEndNoteSection();

    sal_uInt16 GetPhyPageNum() const        { return m_nPhyPageNum;}
    void SetPhyPageNum( sal_uInt16 nNum )   { m_nPhyPageNum = nNum;}
diff --git a/sw/source/core/inc/sectfrm.hxx b/sw/source/core/inc/sectfrm.hxx
index 9dbf9f4..12646d0 100644
--- a/sw/source/core/inc/sectfrm.hxx
+++ b/sw/source/core/inc/sectfrm.hxx
@@ -52,6 +52,8 @@ class SAL_DLLPUBLIC_RTTI SwSectionFrame final: public SwLayoutFrame, public SwFl
    SwSection* m_pSection;
    bool m_bFootnoteAtEnd; // footnotes at the end of section
    bool m_bEndnAtEnd; // endnotes at the end of section
    /// If this is a section for endnotes, then the SwSection is not backed by an SwSectionNode.
    bool m_bEndNoteSection = false;
    bool m_bContentLock; // content locked
    bool m_bOwnFootnoteNum; // special numbering of footnotes
    bool m_bFootnoteLock; // ftn, don't leave this section bwd
@@ -171,6 +173,8 @@ public:

    void SetFootnoteLock( bool bNew ) { m_bFootnoteLock = bNew; }
    bool IsFootnoteLock() const { return m_bFootnoteLock; }
    void SetEndNoteSection(bool bEndNoteSection) { m_bEndNoteSection = bEndNoteSection; }
    bool IsEndNoteSection() const { return m_bEndNoteSection; }
};

inline const SwSectionFrame *SwSectionFrame::GetFollow() const
diff --git a/sw/source/core/layout/findfrm.cxx b/sw/source/core/layout/findfrm.cxx
index a86a7af..60ca1fe 100644
--- a/sw/source/core/layout/findfrm.cxx
+++ b/sw/source/core/layout/findfrm.cxx
@@ -65,6 +65,29 @@ SwContentFrame *SwPageFrame::FindLastBodyContent()
    return pRet;
}

SwSectionFrame* SwPageFrame::GetEndNoteSection()
{
    SwLayoutFrame* pBody = FindBodyCont();
    if (!pBody)
    {
        return nullptr;
    }

    SwFrame* pLast = pBody->GetLastLower();
    if (!pLast || !pLast->IsSctFrame())
    {
        return nullptr;
    }

    auto pLastSection = static_cast<SwSectionFrame*>(pLast);
    if (!pLastSection->IsEndNoteSection())
    {
        return nullptr;
    }

    return pLastSection;
}

/**
 * Checks if the frame contains one or more ContentFrame's anywhere in his
 * subsidiary structure; if so the first found ContentFrame is returned.
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 3967a1f..78278da 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -94,6 +94,7 @@ SwSectionFrame::SwSectionFrame( SwSectionFrame &rSect, bool bMaster ) :
    m_bOwnFootnoteNum( false ),
    m_bFootnoteLock( false )
{
    m_bEndNoteSection = rSect.m_bEndNoteSection;
    StartListening(rSect.GetFormat()->GetNotifier());

    mnFrameType = SwFrameType::Section;