From a305a2c91420652db450b7f8edd140e1d69f42cf Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Mon, 20 Oct 2014 15:13:03 +0200 Subject: use bookmarks to mark mailmerge parts in a mailmerge document (fdo#80823) Instead of page numbers, which - was somewhat fragile (and broken, as it was actually off-by-one) - required repeated re-layout of the increasingly large document, making mailmerge awfully slow. The re-layout is not removed by this commit, as it needs further checking whether it can be removed. See the bugreport for details. Change-Id: Ib09bd5f5a6a549c3d38ca40b0f32c0d2831fdd4c --- sw/source/ui/dbui/mmoutputpage.cxx | 55 +++++++++++++++++++++++++++++++++----- sw/source/ui/dbui/mmoutputpage.hxx | 4 +++ 2 files changed, 52 insertions(+), 7 deletions(-) (limited to 'sw/source/ui') diff --git a/sw/source/ui/dbui/mmoutputpage.cxx b/sw/source/ui/dbui/mmoutputpage.cxx index 17f3b7e384fd..0034007605a6 100644 --- a/sw/source/ui/dbui/mmoutputpage.cxx +++ b/sw/source/ui/dbui/mmoutputpage.cxx @@ -553,6 +553,50 @@ IMPL_LINK_NOARG(SwMailMergeOutputPage, SaveCancelHdl_Impl) return 0; } +int SwMailMergeOutputPage::documentStartPageNumber( int document ) const +{ + SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); + SwView* pTargetView = rConfigItem.GetTargetView(); + assert( pTargetView ); + SwCrsrShell& shell = pTargetView->GetWrtShell(); + const SwDocMergeInfo& info = rConfigItem.GetDocumentMergeInfo( document ); + sal_uInt16 page, dummy; + shell.Push(); + shell.GotoMark( info.startPageInTarget ); + shell.GetPageNum( page, dummy ); + shell.Pop(false); + return page; +} + +int SwMailMergeOutputPage::documentEndPageNumber( int document ) const +{ + SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); + SwView* pTargetView = rConfigItem.GetTargetView(); + assert( pTargetView ); + SwWrtShell& shell = pTargetView->GetWrtShell(); + if( document < int( rConfigItem.GetMergedDocumentCount()) - 1 ) + { + // Go to the page before the starting page of the next merged document. + const SwDocMergeInfo& info = rConfigItem.GetDocumentMergeInfo( document + 1 ); + sal_uInt16 page, dummy; + shell.Push(); + shell.GotoMark( info.startPageInTarget ); + shell.EndPrvPg(); + shell.GetPageNum( page, dummy ); + shell.Pop(false); + return page; + } + else + { // This is the last merged document, so it ends on the page at which the document ends. + sal_uInt16 page, dummy; + shell.Push(); + shell.SttEndDoc( false ); // go to doc end + shell.GetPageNum( page, dummy ); + shell.Pop(false); + return page; + } +} + IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton) { SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); @@ -655,7 +699,6 @@ IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton) for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc) { - SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc); INetURLObject aURL(sPath); OUString sExtension = aURL.getExtension(); if (sExtension.isEmpty()) @@ -686,7 +729,7 @@ IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton) pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true ); pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(), - (sal_uInt16)rInfo.nStartPageInTarget, (sal_uInt16)rInfo.nEndPageInTarget ); + documentStartPageNumber( nDoc ), documentEndPageNumber( nDoc )); pTargetView->GetWrtShell().EndAction(); //then save it OUString sOutPath = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI); @@ -801,12 +844,10 @@ IMPL_LINK_NOARG(SwMailMergeOutputPage, PrintHdl_Impl) nEnd = rConfigItem.GetMergedDocumentCount(); } rConfigItem.SetPrintRange( (sal_uInt16)nBegin, (sal_uInt16)nEnd ); - SwDocMergeInfo& rStartInfo = rConfigItem.GetDocumentMergeInfo(nBegin); - SwDocMergeInfo& rEndInfo = rConfigItem.GetDocumentMergeInfo(nEnd - 1); - OUString sPages(OUString::number( rStartInfo.nStartPageInTarget )); + OUString sPages(OUString::number( documentStartPageNumber( nBegin ))); sPages += " - "; - sPages += OUString::number( rEndInfo.nEndPageInTarget ); + sPages += OUString::number( documentEndPageNumber( nEnd - 1 )); pTargetView->SetMailMergeConfigItem(&rConfigItem, 0, false); if(m_pTempPrinter) @@ -1092,7 +1133,7 @@ IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton) pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc()); pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true ); pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(), - (sal_uInt16)rInfo.nStartPageInTarget, (sal_uInt16)rInfo.nEndPageInTarget ); + documentStartPageNumber( nDoc ), documentEndPageNumber( nDoc )); pTargetView->GetWrtShell().EndAction(); //then save it diff --git a/sw/source/ui/dbui/mmoutputpage.hxx b/sw/source/ui/dbui/mmoutputpage.hxx index 735501688d3e..a31ddeaa3564 100644 --- a/sw/source/ui/dbui/mmoutputpage.hxx +++ b/sw/source/ui/dbui/mmoutputpage.hxx @@ -116,6 +116,10 @@ class SwMailMergeOutputPage : public svt::OWizardPage DECL_LINK(SendDocumentsHdl_Impl, PushButton*); DECL_LINK(DocumentSelectionHdl_Impl, RadioButton*); DECL_LINK(SaveCancelHdl_Impl, void *); + + int documentStartPageNumber( int document ) const; + int documentEndPageNumber( int document ) const; + protected: virtual bool canAdvance() const SAL_OVERRIDE; virtual void ActivatePage() SAL_OVERRIDE; -- cgit