sw/inc/ftninfo.hxx            |    5 +++++
 sw/source/core/doc/docftn.cxx |   19 +++++++++++++++++++
 sw/source/core/doc/docnew.cxx |    1 +
 3 files changed, 25 insertions(+)

New commits:
commit 90f19126fa405a0632eae4ee8525b66bbce12625
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed May 8 08:59:47 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed May 8 12:49:04 2024 +0200

    tdf#160984 sw continuous endnotes: introduce an endnote section
    
    Word lays out endnotes at the end of the document inline after body
    text, Writer puts them on one or more separate endnote pages.
    
    There was already an attempt in the past to resolve this difference, see
    commit 4814e8caa5f06c4fe438dfd7d7315e4a2410ea18 (tdf#124601 sw: add
    ContinuousEndnotes layout compat option, 2019-09-30). The approach back
    then was to map such endnotes to footnotes, so the extra, unwanted page
    doesn't appear. This turned out to be not working too well, the compat
    option is only enabled for DOC, and even there commit
    dc11f5b151e1a2ea2623fc8cf806a400763955d9 (tdf#143445 DOC import: limit
    the usage of the CONTINUOUS_ENDNOTES compat flag, 2023-05-23) limited
    the usage of the compat flag to 1 or 2 endnotes only.
    
    Coming back to this, try a new approach: create a section that more or
    less exists only at a layout level and put endnotes into that section.
    This allows reusing all the complex logic on how to lay out endnotes
    inline, on one or more pages. The plan is that this new approach is more
    robust, can replace the old continuous endnotes layout code and then can
    be enabled for DOCX as well.
    
    This commit just introduces the backing section format and SwSection for
    that special "endnotes section" (it's special because SwSection is
    usually owned by an SwSectionNode, but here there is no doc model node
    for the SwSection), SwFootnoteBossFrame::AppendFootnote() doesn't try to
    use the new SwEndNoteInfo::GetSwSection() yet.
    
    Change-Id: Ib32f04ceb6f46c682a5d36bdcea206d2c4017227
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167305
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/inc/ftninfo.hxx b/sw/inc/ftninfo.hxx
index 17742687c944..c5490ed885d0 100644
--- a/sw/inc/ftninfo.hxx
+++ b/sw/inc/ftninfo.hxx
@@ -28,12 +28,14 @@ class SwTextFormatColl;
 class SwPageDesc;
 class SwCharFormat;
 class SwDoc;
+class SwSection;
 
 class SW_DLLPUBLIC SwEndNoteInfo : public SwClient
 {
     mutable sw::WriterMultiListener m_aDepends;
     mutable SwTextFormatColl* m_pTextFormatColl;
     mutable SwPageDesc* m_pPageDesc;
+    mutable std::unique_ptr<SwSection> m_pSwSection;
     mutable SwCharFormat* m_pCharFormat;
     mutable SwCharFormat* m_pAnchorFormat;
     OUString m_sPrefix;
@@ -51,6 +53,9 @@ public:
     bool KnowsPageDesc() const;
     bool DependsOn(const SwPageDesc*) const;
 
+    SwSection* GetSwSection(SwDoc& rDoc) const;
+    void ResetSwSection();
+
     void SetFootnoteTextColl(SwTextFormatColl& rColl);
     SwTextFormatColl* GetFootnoteTextColl() const { return m_pTextFormatColl; 
} // can be 0.
 
diff --git a/sw/source/core/doc/docftn.cxx b/sw/source/core/doc/docftn.cxx
index 16f6694c94c5..f211dcdcc9f4 100644
--- a/sw/source/core/doc/docftn.cxx
+++ b/sw/source/core/doc/docftn.cxx
@@ -35,6 +35,8 @@
 #include <ndtxt.hxx>
 #include <poolfmt.hxx>
 #include <ftninfo.hxx>
+#include <fmtftntx.hxx>
+#include <unoprnms.hxx>
 
 SwEndNoteInfo& SwEndNoteInfo::operator=(const SwEndNoteInfo& rInfo)
 {
@@ -130,6 +132,23 @@ void SwEndNoteInfo::ChgPageDesc(SwPageDesc* pDesc)
     m_aDepends.StartListening(m_pPageDesc);
 }
 
+SwSection* SwEndNoteInfo::GetSwSection(SwDoc& rDoc) const
+{
+    if (!m_pSwSection)
+    {
+        SwSectionFormat* pFormat = rDoc.MakeSectionFormat();
+        pFormat->SetFormatName(UNO_NAME_ENDNOTE);
+        pFormat->SetFormatAttr(SwFormatEndAtTextEnd(FTNEND_ATTXTEND));
+        m_pSwSection.reset(new SwSection(SectionType::Content, 
pFormat->GetName(), *pFormat));
+    }
+    return m_pSwSection.get();
+}
+
+void SwEndNoteInfo::ResetSwSection()
+{
+    m_pSwSection.reset();
+}
+
 void SwEndNoteInfo::SetFootnoteTextColl(SwTextFormatColl& rFormat)
 {
     m_aDepends.EndListening(m_pTextFormatColl);
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index a56e7343e8f1..daef5f64be75 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -505,6 +505,7 @@ SwDoc::~SwDoc()
     // do not have any dependencies anymore.
     m_pNodes->DelNodes( SwNodeIndex(*m_pNodes), m_pNodes->Count() );
     rUndoNodes.DelNodes( SwNodeIndex( rUndoNodes ), rUndoNodes.Count() );
+    mpEndNoteInfo->ResetSwSection();
 
     // clear TOX after nodes - TOXMarks are gone now so SwTOXType has no 
clients
     for (const auto& pType : *mpTOXTypes)

Reply via email to