diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-01-18 16:48:54 +0100 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-03-24 22:40:47 +0100 |
commit | e817940a83ba7f2768acc245e005ca096d34776a (patch) | |
tree | 52a33b158aa509d68f8b1cdc6e7ae82b5ab24ed8 | |
parent | 435ca34e14af3a8a5bacd54a011adbe235ac772b (diff) |
MM: move SwPageDesc handling into SwDoc::AppendDoc
If you append a doc, you want to handle styles correctly. So it's
actually the correct way to handle the styles in AppendDoc.
The nDocNo is used instead of a boolean to speed up finding better
unique names in the mail merge case.
Change-Id: I4b16e89588164b9e0763759c7d719dfc204b63a1
-rw-r--r-- | sw/inc/doc.hxx | 3 | ||||
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 72 | ||||
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 73 |
3 files changed, 73 insertions, 75 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 5905a7b8f0a9..11d00389b00c 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1624,7 +1624,8 @@ public: SfxObjectShell* CreateCopy(bool bCallInitNew) const; SwNodeIndex AppendDoc(const SwDoc& rSource, sal_uInt16 nStartPageNumber, - SwPageDesc* pTargetPageDesc, bool bDeletePrevious = false, int physicalPageOffset = 0 ); + bool bDeletePrevious = false, int physicalPageOffset = 0, + const sal_uLong nDocNo = 1); /** * Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by default) diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index edb1aaba2f91..0975ad54177d 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -109,6 +109,7 @@ #include <fldbas.hxx> #include <wrtsh.hxx> #include <unocrsr.hxx> +#include <fmthdft.hxx> #include <cmdid.h> @@ -894,7 +895,7 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const SAL_INFO( "sw.createcopy", "CC-Nd-Src: " << CNTNT_DOC( this ) ); SAL_INFO( "sw.createcopy", "CC-Nd: " << CNTNT_DOC( pRet ) ); #endif - pRet->AppendDoc(*this, 0, nullptr, bCallInitNew); + pRet->AppendDoc(*this, 0, bCallInitNew, 0, 0); #ifdef DBG_UTIL SAL_INFO( "sw.createcopy", "CC-Nd: " << CNTNT_DOC( pRet ) ); #endif @@ -907,9 +908,45 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const return pRetShell; } +// save bulk letters as single documents +static OUString lcl_FindUniqueName(SwWrtShell* pTargetShell, const OUString& rStartingPageDesc, sal_uLong nDocNo ) +{ + do + { + OUString sTest = rStartingPageDesc; + sTest += OUString::number( nDocNo ); + if( !pTargetShell->FindPageDescByName( sTest ) ) + return sTest; + ++nDocNo; + } + while( true ); +} + +static void lcl_CopyFollowPageDesc( + SwWrtShell& rTargetShell, + const SwPageDesc& rSourcePageDesc, + const SwPageDesc& rTargetPageDesc, + const sal_uLong nDocNo ) +{ + //now copy the follow page desc, too + const SwPageDesc* pFollowPageDesc = rSourcePageDesc.GetFollow(); + OUString sFollowPageDesc = pFollowPageDesc->GetName(); + if( sFollowPageDesc != rSourcePageDesc.GetName() ) + { + SwDoc* pTargetDoc = rTargetShell.GetDoc(); + OUString sNewFollowPageDesc = lcl_FindUniqueName(&rTargetShell, sFollowPageDesc, nDocNo ); + SwPageDesc* pTargetFollowPageDesc = pTargetDoc->MakePageDesc(sNewFollowPageDesc); + + pTargetDoc->CopyPageDesc(*pFollowPageDesc, *pTargetFollowPageDesc, false); + SwPageDesc aDesc(rTargetPageDesc); + aDesc.SetFollow(pTargetFollowPageDesc); + pTargetDoc->ChgPageDesc(rTargetPageDesc.GetName(), aDesc); + } +} + // appends all pages of source SwDoc - based on SwFEShell::Paste( SwDoc* ) SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNumber, - SwPageDesc *const pTargetPageDesc, bool const bDeletePrevious, int pageOffset) + bool const bDeletePrevious, int pageOffset, const sal_uLong nDocNo) { // GetEndOfExtras + 1 = StartOfContent == no content node! // this ensures, that we have at least two nodes in the SwPaM. @@ -951,12 +988,43 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu #endif SwWrtShell* pTargetShell = GetDocShell()->GetWrtShell(); + SwPageDesc* pTargetPageDesc = nullptr; + if ( pTargetShell ) { #ifdef DBG_UTIL SAL_INFO( "sw.docappend", "Has target write shell" ); #endif pTargetShell->StartAllAction(); + if( nDocNo > 0 ) + { + // #i72517# put the styles to the target document + // 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( + pSourceShell->GetCurPageDesc()); + const OUString sStartingPageDesc = pSourcePageDesc->GetName(); + const SwFrameFormat& rMaster = pSourcePageDesc->GetMaster(); + const bool bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive() || + rMaster.GetFooter().IsActive(); + if( bPageStylesWithHeaderFooter ) + { + // create a new pagestyle + // copy the pagedesc from the current document to the new + // document and change the name of the to-be-applied style + OUString sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo ); + pTargetPageDesc = this->MakePageDesc( sNewPageDescName ); + if( pTargetPageDesc ) + { + this->CopyPageDesc( *pSourcePageDesc, *pTargetPageDesc, false ); + lcl_CopyFollowPageDesc( *pTargetShell, *pSourcePageDesc, *pTargetPageDesc, nDocNo ); + } + } + else + pTargetPageDesc = pTargetShell->FindPageDescByName( sStartingPageDesc ); + } + // Otherwise we have to handle SwPlaceholderNodes as first node if ( pTargetPageDesc ) { OUString name = pTargetPageDesc->GetName(); diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 5b3a653c0387..a032b8c0b2d7 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -787,41 +787,6 @@ SwDBManager::~SwDBManager() } } -// save bulk letters as single documents -static OUString lcl_FindUniqueName(SwWrtShell* pTargetShell, const OUString& rStartingPageDesc, sal_uLong nDocNo ) -{ - do - { - OUString sTest = rStartingPageDesc; - sTest += OUString::number( nDocNo ); - if( !pTargetShell->FindPageDescByName( sTest ) ) - return sTest; - ++nDocNo; - }while(true); -} - -static void lcl_CopyFollowPageDesc( - SwWrtShell& rTargetShell, - const SwPageDesc& rSourcePageDesc, - const SwPageDesc& rTargetPageDesc, - const sal_uLong nDocNo ) -{ - //now copy the follow page desc, too - const SwPageDesc* pFollowPageDesc = rSourcePageDesc.GetFollow(); - OUString sFollowPageDesc = pFollowPageDesc->GetName(); - if( sFollowPageDesc != rSourcePageDesc.GetName() ) - { - SwDoc* pTargetDoc = rTargetShell.GetDoc(); - OUString sNewFollowPageDesc = lcl_FindUniqueName(&rTargetShell, sFollowPageDesc, nDocNo ); - SwPageDesc* pTargetFollowPageDesc = pTargetDoc->MakePageDesc(sNewFollowPageDesc); - - pTargetDoc->CopyPageDesc(*pFollowPageDesc, *pTargetFollowPageDesc, false); - SwPageDesc aDesc(rTargetPageDesc); - aDesc.SetFollow(pTargetFollowPageDesc); - pTargetDoc->ChgPageDesc(rTargetPageDesc.GetName(), aDesc); - } -} - static void lcl_RemoveSectionLinks( SwWrtShell& rWorkShell ) { //reset all links of the sections of synchronized labels @@ -1073,10 +1038,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, SfxObjectShellRef xTargetDocShell = nullptr; std::unique_ptr< utl::TempFile > aTempFile; - OUString sModifiedStartingPageDesc; - OUString sStartingPageDesc; sal_uInt16 nStartingPageNo = 0; - bool bPageStylesWithHeaderFooter = false; vcl::Window *pSourceWindow = nullptr; VclPtr<CancelableDialog> pProgressDlg; @@ -1148,16 +1110,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, //determine the page style and number used at the start of the source document pSourceShell->SttEndDoc(true); nStartingPageNo = pSourceShell->GetVirtPageNum(); - sStartingPageDesc = sModifiedStartingPageDesc = pSourceShell->GetPageDesc( - pSourceShell->GetCurPageDesc()).GetName(); - - // #i72517# - const SwPageDesc* pSourcePageDesc = pSourceShell->FindPageDescByName( sStartingPageDesc ); - const SwFrameFormat& rMaster = pSourcePageDesc->GetMaster(); - bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive() || - rMaster.GetFooter().IsActive(); - - sModifiedStartingPageDesc = sStartingPageDesc; } // Progress, to prohibit KeyInputs @@ -1329,29 +1281,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, lcl_RemoveSectionLinks( rWorkShell ); } - // #i72517# put the styles to the target document - // if the source uses headers or footers each working document - // needs inidividual page styles - SwPageDesc* pTargetPageDesc = nullptr; - if( bPageStylesWithHeaderFooter ) - { - // create a new pagestyle - // copy the pagedesc from the current document to the new - // document and change the name of the to-be-applied style - OUString sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo ); - pTargetPageDesc = pTargetDoc->MakePageDesc( sNewPageDescName ); - const SwPageDesc* pWorkPageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc ); - - if(pWorkPageDesc && pTargetPageDesc) - { - pTargetDoc->CopyPageDesc( *pWorkPageDesc, *pTargetPageDesc, false ); - sModifiedStartingPageDesc = sNewPageDescName; - lcl_CopyFollowPageDesc( *pTargetShell, *pWorkPageDesc, *pTargetPageDesc, nDocNo ); - } - } - else - pTargetPageDesc = pTargetShell->FindPageDescByName( sModifiedStartingPageDesc ); - if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) ) lcl_SaveDebugDoc( xWorkDocSh, "WorkDoc", nDocNo ); @@ -1359,7 +1288,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, if( targetDocPageCount % 2 == 1 ) ++targetDocPageCount; // Docs always start on odd pages (so offset must be even). SwNodeIndex appendedDocStart = pTargetDoc->AppendDoc(*rWorkShell.GetDoc(), - nStartingPageNo, pTargetPageDesc, !bWorkDocInitialized, targetDocPageCount); + nStartingPageNo, !bWorkDocInitialized, targetDocPageCount, nDocNo); targetDocPageCount += rWorkShell.GetPageCnt(); if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) ) |