summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2014-10-20 15:13:03 +0200
committerLuboš Luňák <l.lunak@collabora.com>2014-11-14 13:25:00 +0100
commit708cada5d76a26b6b2ac2885bf6b48f1205f1dd5 (patch)
tree219c092e9ddd98139fbfba98d9b84eab0be0d517
parent6a3bc5f88114edf3c951c78d8e845cf99f82b5eb (diff)
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. Conflicts: sw/inc/doc.hxx sw/source/core/doc/docnew.cxx sw/source/ui/dbui/mmoutputpage.cxx sw/source/uibase/dbui/dbmgr.cxx sw/source/uibase/inc/mmconfigitem.hxx Change-Id: Ib09bd5f5a6a549c3d38ca40b0f32c0d2831fdd4c
-rw-r--r--sw/inc/doc.hxx2
-rw-r--r--sw/source/core/doc/docnew.cxx13
-rw-r--r--sw/source/ui/dbui/dbmgr.cxx10
-rw-r--r--sw/source/ui/dbui/mmoutputpage.cxx57
-rw-r--r--sw/source/ui/dbui/mmoutputpage.hxx4
-rw-r--r--sw/source/ui/inc/mmconfigitem.hxx4
6 files changed, 72 insertions, 18 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index a3ac7c58c37f..0d01946d4c6c 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -2077,7 +2077,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 cf518ed8ffed..a7f714df09f5 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -1156,7 +1156,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!
@@ -1245,6 +1245,9 @@ void SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNumber,
this->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
this->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 **
@@ -1357,6 +1360,12 @@ else
<< " EOE: " << GetNodes().GetEndOfExtras().GetIndex() );
#endif
GetNodes().Delete( aDelIdx, iDelNodes );
+ aStartAppendIndex = aFixupIdx;
+ }
+ else
+ {
+ aStartAppendIndex = aFixupIdx;
+ ++aStartAppendIndex;
}
}
@@ -1385,6 +1394,8 @@ else
if ( pTargetShell )
pTargetShell->EndAllAction();
+
+ return aStartAppendIndex;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/dbui/dbmgr.cxx b/sw/source/ui/dbui/dbmgr.cxx
index 755a4b298541..329f5963819b 100644
--- a/sw/source/ui/dbui/dbmgr.cxx
+++ b/sw/source/ui/dbui/dbmgr.cxx
@@ -1205,11 +1205,10 @@ sal_Bool SwNewDBMgr::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(),
- nStartingPageNo, pTargetPageDesc, nDocNo == 1);
+ SwNodeIndex appendedDocStart = pTargetDoc->AppendDoc(*rWorkShell.GetDoc(),
+ nStartingPageNo, pTargetPageDesc, nDocNo == 1 );
// #i72820# calculate layout to be able to find the correct page index
pTargetShell->CalcLayout();
@@ -1218,9 +1217,8 @@ sal_Bool SwNewDBMgr::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/ui/dbui/mmoutputpage.cxx b/sw/source/ui/dbui/mmoutputpage.cxx
index e2a697be7865..a6bea638abab 100644
--- a/sw/source/ui/dbui/mmoutputpage.cxx
+++ b/sw/source/ui/dbui/mmoutputpage.cxx
@@ -652,6 +652,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();
@@ -756,7 +800,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);
String sExtension = aURL.getExtension();
if(!sExtension.Len())
@@ -787,7 +830,7 @@ IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton)
sTargetTempURL, aOpt, sal_True );
pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
- (sal_uInt16)rInfo.nStartPageInTarget, (sal_uInt16)rInfo.nEndPageInTarget );
+ documentStartPageNumber( nDoc ), documentEndPageNumber( nDoc ));
pTargetView->GetWrtShell().EndAction();
//then save it
String sOutPath = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
@@ -903,12 +946,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::valueOf( rStartInfo.nStartPageInTarget ));
- sPages += OUString(" - ");
- sPages += OUString::valueOf( rEndInfo.nEndPageInTarget );
+ OUString sPages(OUString::number( documentStartPageNumber( nBegin )));
+ sPages += " - ";
+ sPages += OUString::number( documentEndPageNumber( nEnd - 1 ));
pTargetView->SetMailMergeConfigItem(&rConfigItem, 0, sal_False);
if(m_pTempPrinter)
@@ -1193,7 +1234,7 @@ IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton)
pTempView->GetDocShell()->LoadStylesFromFile(
sTargetTempURL, aOpt, sal_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 1956d2bd9691..15a2e50001d9 100644
--- a/sw/source/ui/dbui/mmoutputpage.hxx
+++ b/sw/source/ui/dbui/mmoutputpage.hxx
@@ -125,6 +125,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;
virtual void ActivatePage();
diff --git a/sw/source/ui/inc/mmconfigitem.hxx b/sw/source/ui/inc/mmconfigitem.hxx
index 8011cfe85570..0d774e261628 100644
--- a/sw/source/ui/inc/mmconfigitem.hxx
+++ b/sw/source/ui/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;
};