From ae5afe9bcebdd220a457829d47882fe8a0cf69fd Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Mon, 20 Oct 2014 22:05:51 +0200 Subject: compute page offset for mailmerge based on source document rather than target This removes another need for doing repeated and expensive layouts of the target document. Change-Id: Id78bc3ccc71c17e42f858dc9660866b9c94dea3a --- sw/source/core/doc/docnew.cxx | 21 ++++----------------- sw/source/uibase/dbui/dbmgr.cxx | 11 ++++++++++- 2 files changed, 14 insertions(+), 18 deletions(-) (limited to 'sw/source') diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index 066f62580303..70bda8ca87ff 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -932,7 +932,7 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const // 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) + SwPageDesc *const pTargetPageDesc, bool const bDeletePrevious, int pageOffset) { // GetEndOfExtras + 1 = StartOfContent == no content node! // @see IDocumentContentOperations::CopyRange @@ -973,7 +973,6 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu #endif SwWrtShell* pTargetShell = GetDocShell()->GetWrtShell(); - sal_uInt16 nPhysPageNumber = 0; if ( pTargetShell ) { #ifdef DBG_UTIL SAL_INFO( "sw.docappend", "Has target write shell" ); @@ -985,18 +984,6 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu OUString name = pTargetPageDesc->GetName(); pTargetShell->InsertPageBreak( &name, nStartPageNumber ); } - - // -1 for the page break + -1, becauce it's an offset - nPhysPageNumber = pTargetShell->GetPhyPageNum() - 2; - if (bDeletePrevious) - nPhysPageNumber--; - - // We always start on an odd physical page number - if (1 == nPhysPageNumber % 2) - nPhysPageNumber++; -#ifdef DBG_UTIL - SAL_INFO( "sw.docappend", "PPNo " << nPhysPageNumber ); -#endif } #ifdef DBG_UTIL SAL_INFO( "sw.docappend", "Nd: " << CNTNT_DOC( this ) ); @@ -1154,10 +1141,10 @@ else continue; #ifdef DBG_UTIL SAL_INFO( "sw.docappend", "PaAn: " << aAnchor.GetPageNum() - << " => " << aAnchor.GetPageNum() + nPhysPageNumber ); + << " => " << aAnchor.GetPageNum() + pageOffset ); #endif - if ( nPhysPageNumber ) - aAnchor.SetPageNum( aAnchor.GetPageNum() + nPhysPageNumber ); + if ( pageOffset != 0 ) + aAnchor.SetPageNum( aAnchor.GetPageNum() + pageOffset ); this->getIDocumentLayoutAccess().CopyLayoutFmt( rCpyFmt, aAnchor, true, true ); } } diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index c6f48fef5eb7..4a0740829142 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -979,6 +979,12 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, sal_Int32 nDocNo = 1; sal_Int32 nDocCount = 0; + // For single file mode, the number of pages in the target document so far, which is used + // by AppendDoc() to adjust position of page-bound objects. Getting this information directly + // from the target doc would require repeated layouts of the doc, which is expensive, but + // it can be manually computed from the source documents (for which we do layouts, so the page + // count is known, and there is a blank page between each of them in the target document). + int targetDocPageCount = 0; if( !IsMergeSilent() && bMergeShell && lcl_getCountFromResultSet( nDocCount, pImpl->pMergeData->xResultSet ) ) static_cast( pProgressDlg )->SetTotalCount( nDocCount ); @@ -1125,10 +1131,13 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) ) lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo ); + if( targetDocPageCount % 2 == 1 ) + ++targetDocPageCount; // Docs always start on odd pages (so offset must be even). SwNodeIndex appendedDocStart = pTargetDoc->AppendDoc(*rWorkShell.GetDoc(), - nStartingPageNo, pTargetPageDesc, nDocNo == 1); + nStartingPageNo, pTargetPageDesc, nDocNo == 1, targetDocPageCount); // #i72820# calculate layout to be able to find the correct page index pTargetShell->CalcLayout(); + targetDocPageCount += rWorkShell.GetPageCnt(); if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) ) lcl_SaveDoc( xTargetDocShell, "MergeDoc" ); if (bMergeShell) -- cgit