diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2018-09-26 14:42:44 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-10-04 11:05:28 +0200 |
commit | 12db0c2a7b240b73a9445fffa026c4d1c349814c (patch) | |
tree | fd16ade5b0343652e1fea49dbdfedee6a53ac705 /sw | |
parent | 7239716e4307a348d818606340e34b4fc6ceb282 (diff) |
sw: fix copying of PageDesc follows in SwDoc::AppendDoc
The problem in the bugdoc is that there are 2 styles; "First Page"
has "Default Style" as the follow, and vice versa.
When the "First Page" style is copied, its follow is copied as well, but
the follow of the follow doesn't point to the *new* "First PageN" style
that was just created, but the original "First Page" one.
Change-Id: Ie5b0064581a585a3a545360ea5c05f60652f0d4e
Reviewed-on: https://gerrit.libreoffice.org/60993
Tested-by: Jenkins
Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
(cherry picked from commit a6a4fa526b8ad19ff6d44a89ee56d4268c8e90be)
Reviewed-on: https://gerrit.libreoffice.org/61062
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index 07fca37917bb..6940e86acc94 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -943,19 +943,45 @@ static void lcl_CopyFollowPageDesc( const sal_uLong nDocNo ) { //now copy the follow page desc, too - const SwPageDesc* pFollowPageDesc = rSourcePageDesc.GetFollow(); - OUString sFollowPageDesc = pFollowPageDesc->GetName(); - if( sFollowPageDesc != rSourcePageDesc.GetName() ) + // note: these may at any point form a cycle, so a loop is needed and it + // must be detected that the last iteration closes the cycle and doesn't + // copy the first page desc of the cycle again. + std::map<OUString, OUString> followMap{ { rSourcePageDesc.GetName(), rTargetPageDesc.GetName() } }; + SwPageDesc const* pCurSourcePageDesc(&rSourcePageDesc); + SwPageDesc const* pCurTargetPageDesc(&rTargetPageDesc); + do { + const SwPageDesc* pFollowPageDesc = pCurSourcePageDesc->GetFollow(); + OUString sFollowPageDesc = pFollowPageDesc->GetName(); + if (sFollowPageDesc == pCurSourcePageDesc->GetName()) + { + break; + } SwDoc* pTargetDoc = rTargetShell.GetDoc(); - OUString sNewFollowPageDesc = lcl_FindUniqueName(&rTargetShell, sFollowPageDesc, nDocNo ); - SwPageDesc* pTargetFollowPageDesc = pTargetDoc->MakePageDesc(sNewFollowPageDesc); - - pTargetDoc->CopyPageDesc(*pFollowPageDesc, *pTargetFollowPageDesc, false); - SwPageDesc aDesc(rTargetPageDesc); + SwPageDesc* pTargetFollowPageDesc(nullptr); + auto const itMapped(followMap.find(sFollowPageDesc)); + if (itMapped == followMap.end()) + { + OUString sNewFollowPageDesc = lcl_FindUniqueName(&rTargetShell, sFollowPageDesc, nDocNo); + pTargetFollowPageDesc = pTargetDoc->MakePageDesc(sNewFollowPageDesc); + pTargetDoc->CopyPageDesc(*pFollowPageDesc, *pTargetFollowPageDesc, false); + } + else + { + pTargetFollowPageDesc = pTargetDoc->FindPageDesc(itMapped->second); + } + SwPageDesc aDesc(*pCurTargetPageDesc); aDesc.SetFollow(pTargetFollowPageDesc); - pTargetDoc->ChgPageDesc(rTargetPageDesc.GetName(), aDesc); + pTargetDoc->ChgPageDesc(pCurTargetPageDesc->GetName(), aDesc); + if (itMapped != followMap.end()) + { + break; // was already copied + } + pCurSourcePageDesc = pCurSourcePageDesc->GetFollow(); + pCurTargetPageDesc = pTargetFollowPageDesc; + followMap[pCurSourcePageDesc->GetName()] = pCurTargetPageDesc->GetName(); } + while (true); } // appends all pages of source SwDoc - based on SwFEShell::Paste( SwDoc* ) |