[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - sw/source

Michael Weghorn (via logerrit) logerrit at kemper.freedesktop.org
Wed Oct 16 11:12:42 UTC 2019


 sw/source/core/doc/docnew.cxx |   33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

New commits:
commit d13d12101bb556da494ae0590ee47c1a2ba602b5
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Tue Oct 15 09:03:51 2019 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Wed Oct 16 13:12:06 2019 +0200

    tdf#128148 SwDoc::Append: Copy page descs if any has header/footer
    
    Don't only check the first SwPageDesc, but also its
    follows whether they have a header or footer and copy
    the page styles in this case, since otherwise the
    header/footer content can be wrong if the first page's
    page style doesn't have header/footer but a following
    one does.
    
    Change-Id: If5ef76a7faf93ad533976b501f35f171336615c8
    Reviewed-on: https://gerrit.libreoffice.org/80814
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>
    (cherry picked from commit 9271152c5fb64a698de167861e39f6b073a60ad6)
    Reviewed-on: https://gerrit.libreoffice.org/80859

diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 613c0b50aa48..c41dcdd325c0 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -19,6 +19,8 @@
 
 #include <config_features.h>
 
+#include <unordered_set>
+
 #include <doc.hxx>
 #include <dcontact.hxx>
 #include <proofreadingiterator.hxx>
@@ -933,6 +935,25 @@ static OUString lcl_FindUniqueName(SwWrtShell* pTargetShell, const OUString& rSt
     while( true );
 }
 
+/** Returns whether the passed SwPageDesc& or any of its (transitive) follows
+   contains a header or footer. */
+static bool lcl_PageDescOrFollowContainsHeaderFooter(const SwPageDesc& rPageDesc)
+{
+    // remember already checked page descs to avoid cycle
+    std::unordered_set<const SwPageDesc*> aCheckedPageDescs;
+    const SwPageDesc* pCurPageDesc = &rPageDesc;
+    while (aCheckedPageDescs.count(pCurPageDesc) == 0)
+    {
+        const SwFrameFormat& rMaster = pCurPageDesc->GetMaster();
+        if (rMaster.GetHeader().IsActive() || rMaster.GetFooter().IsActive())
+            return true;
+
+        aCheckedPageDescs.insert(pCurPageDesc);
+        pCurPageDesc = pCurPageDesc->GetFollow();
+    }
+    return false;
+}
+
 static void lcl_CopyFollowPageDesc(
                             SwWrtShell& rTargetShell,
                             const SwPageDesc& rSourcePageDesc,
@@ -1032,12 +1053,10 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
             // if the source uses headers or footers the target document
             // needs inidividual page styles
             const SwWrtShell *pSourceShell = rSource.GetDocShell()->GetWrtShell();
-            const SwPageDesc *pSourcePageDesc = &pSourceShell->GetPageDesc(
+            const SwPageDesc rSourcePageDesc = pSourceShell->GetPageDesc(
                                                     pSourceShell->GetCurPageDesc());
-            const OUString sStartingPageDesc = pSourcePageDesc->GetName();
-            const SwFrameFormat& rMaster = pSourcePageDesc->GetMaster();
-            const bool bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive() ||
-                                                     rMaster.GetFooter().IsActive();
+            const OUString sStartingPageDesc = rSourcePageDesc.GetName();
+            const bool bPageStylesWithHeaderFooter = lcl_PageDescOrFollowContainsHeaderFooter(rSourcePageDesc);
             if( bPageStylesWithHeaderFooter )
             {
                 // create a new pagestyle
@@ -1047,8 +1066,8 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
                 pTargetPageDesc = MakePageDesc( sNewPageDescName );
                 if( pTargetPageDesc )
                 {
-                    CopyPageDesc( *pSourcePageDesc, *pTargetPageDesc, false );
-                    lcl_CopyFollowPageDesc( *pTargetShell, *pSourcePageDesc, *pTargetPageDesc, nDocNo );
+                    CopyPageDesc( rSourcePageDesc, *pTargetPageDesc, false );
+                    lcl_CopyFollowPageDesc( *pTargetShell, rSourcePageDesc, *pTargetPageDesc, nDocNo );
                 }
             }
             else


More information about the Libreoffice-commits mailing list