diff options
-rw-r--r-- | sw/inc/doc.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 13 | ||||
-rw-r--r-- | sw/source/ui/dbui/mmoutputpage.cxx | 55 | ||||
-rw-r--r-- | sw/source/ui/dbui/mmoutputpage.hxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 9 | ||||
-rw-r--r-- | sw/source/uibase/inc/mmconfigitem.hxx | 4 |
6 files changed, 70 insertions, 17 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index eb1a240b62f7..8a382e1b19d0 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1659,7 +1659,7 @@ public: ::sw::UndoManager const& GetUndoManager() const; SfxObjectShell* CreateCopy(bool bCallInitNew) const; - void AppendDoc(const SwDoc& rSource, sal_uInt16 nStartPageNumber, + SwNodeIndex AppendDoc(const SwDoc& rSource, sal_uInt16 nStartPageNumber, SwPageDesc* pTargetPageDesc, bool bDeletePrevious = false ); /** diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index a8405d551317..066f62580303 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -931,7 +931,7 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const } // appends all pages of source SwDoc - based on SwFEShell::Paste( SwDoc* ) -void SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNumber, +SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNumber, SwPageDesc *const pTargetPageDesc, bool const bDeletePrevious) { // GetEndOfExtras + 1 = StartOfContent == no content node! @@ -1020,6 +1020,9 @@ void SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNumber, this->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL ); this->getIDocumentFieldsAccess().LockExpFlds(); + // Position where the appended doc starts. Will be filled in later (uses GetEndOfContent() because SwNodeIndex has no default ctor). + SwNodeIndex aStartAppendIndex( GetNodes().GetEndOfContent() ); + { // ** // ** refer to SwFEShell::Paste, if you change the following code ** @@ -1132,6 +1135,12 @@ else << " EOE: " << GetNodes().GetEndOfExtras().GetIndex() ); #endif GetNodes().Delete( aDelIdx, iDelNodes ); + aStartAppendIndex = aFixupIdx; + } + else + { + aStartAppendIndex = aFixupIdx; + ++aStartAppendIndex; } } @@ -1160,6 +1169,8 @@ else if ( pTargetShell ) pTargetShell->EndAllAction(); + + return aStartAppendIndex; } sal_uInt16 SwTxtFmtColls::GetPos(const SwTxtFmtColl* p) const 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; diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 6f17f51875fb..c6f48fef5eb7 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -1123,12 +1123,10 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, else pTargetPageDesc = pTargetShell->FindPageDescByName( sModifiedStartingPageDesc ); - sal_uInt16 nStartPage = pTargetShell->GetPageCnt(); if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) ) lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo ); - pTargetDoc->AppendDoc(*rWorkShell.GetDoc(), + SwNodeIndex appendedDocStart = pTargetDoc->AppendDoc(*rWorkShell.GetDoc(), nStartingPageNo, pTargetPageDesc, nDocNo == 1); - // #i72820# calculate layout to be able to find the correct page index pTargetShell->CalcLayout(); if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) ) @@ -1136,9 +1134,8 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, if (bMergeShell) { SwDocMergeInfo aMergeInfo; - aMergeInfo.nStartPageInTarget = nStartPage; - aMergeInfo.nEndPageInTarget = - nStartPage + pSourceShell->GetPageCnt() - 1; + aMergeInfo.startPageInTarget = pTargetDoc->getIDocumentMarkAccess()->makeMark( appendedDocStart, "MailMergeInternalStart" + OUString::number( nStartRow ), + IDocumentMarkAccess::UNO_BOOKMARK ); aMergeInfo.nDBRow = nStartRow; rMergeDescriptor.pMailMergeConfigItem->AddMergedDocument( aMergeInfo ); } diff --git a/sw/source/uibase/inc/mmconfigitem.hxx b/sw/source/uibase/inc/mmconfigitem.hxx index feeaed83610f..8117cfd01ca4 100644 --- a/sw/source/uibase/inc/mmconfigitem.hxx +++ b/sw/source/uibase/inc/mmconfigitem.hxx @@ -38,11 +38,11 @@ namespace com{namespace sun{namespace star{ class SwMailMergeConfigItem_Impl; class SwView; +namespace sw { namespace mark { class IMark; }} struct SwDocMergeInfo { - long nStartPageInTarget; - long nEndPageInTarget; + sw::mark::IMark* startPageInTarget; long nDBRow; }; |