[Libreoffice-commits] core.git: Branch 'distro/lhm/libreoffice-6-1+backports' - sw/source
Michael Weghorn (via logerrit)
logerrit at kemper.freedesktop.org
Wed Oct 16 05:33:17 UTC 2019
sw/source/core/doc/docnew.cxx | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
New commits:
commit ee249c921373288914cbf555279b5df56bbae199
Author: Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Tue Oct 15 09:03:51 2019 +0200
Commit: Michael Weghorn <m.weghorn at posteo.de>
CommitDate: Wed Oct 16 07:32:32 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/80860
Reviewed-by: Michael Weghorn <m.weghorn at posteo.de>
Tested-by: Michael Weghorn <m.weghorn at posteo.de>
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 6940e86acc94..32c97b5a1cb4 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>
@@ -936,6 +938,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,
@@ -1035,12 +1056,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
@@ -1050,8 +1069,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