[Libreoffice-commits] core.git: Branch 'private/jmux/mailmerge-fixes' - sw/inc sw/source
Jan-Marek Glogowski
glogow at fbihome.de
Fri Jun 27 17:07:55 PDT 2014
sw/inc/doc.hxx | 3 +
sw/inc/fesh.hxx | 2
sw/source/core/doc/docnew.cxx | 100 +++++++++++++++++++++++++++------------
sw/source/core/frmedt/fecopy.cxx | 8 ++-
sw/source/uibase/dbui/dbmgr.cxx | 64 ++++++------------------
5 files changed, 97 insertions(+), 80 deletions(-)
New commits:
commit 414a112be566fe41256dfaaf8db8d3f110883cbe
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Sat Jun 28 01:41:17 2014 +0200
MM: introduce SwDoc::Append helper function
This drops all the specialized, workaround code from MM, introduced
to use the SwFEShell::Paste function.
There is still a little common codepath, therefore this adds
comments to always update both functions.
Change-Id: I704b3ef3257dd977dac95e16e25049ff8ade97ed
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index be6e30a..e98370f 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1883,7 +1883,10 @@ public:
::sw::MetaFieldManager & GetMetaFieldManager();
::sw::UndoManager & GetUndoManager();
::sw::UndoManager const& GetUndoManager() const;
+
SfxObjectShell* CreateCopy(bool bCallInitNew) const;
+ void Append( const SwDoc& rSource, int nStartPageNumber,
+ SwPageDesc* pTargetPageDesc, int nPhysPageNumber );
/**
* Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by default)
diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index 2660c5a..749e735 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -219,7 +219,7 @@ public:
/// Copy and Paste methods for internal clipboard.
bool Copy( SwDoc* pClpDoc, const OUString* pNewClpTxt = 0 );
- bool Paste( SwDoc* pClpDoc, bool bIncludingPageFrames = false, bool bIncludeFullDocument = false);
+ bool Paste( SwDoc* pClpDoc, bool bIncludingPageFrames = false );
/// Paste some pages into another doc - used in mailmerge.
bool PastePages( SwFEShell& rToFill, sal_uInt16 nStartPage, sal_uInt16 nEndPage);
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 463cb83..4047589 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -978,7 +978,8 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
SfxObjectShell* pRetShell = new SwDocShell( pRet, SFX_CREATE_MODE_STANDARD );
if( bCallInitNew )
{
- // it could happen that DoInitNew creates model, that increases the refcount of the object
+ // it could happen that DoInitNew creates model,
+ // that increases the refcount of the object
pRetShell->DoInitNew();
}
@@ -990,30 +991,54 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
pRet->ReplaceStyles(*this);
- // Based on the simplified codepath from SwFEShell::Paste()
+ pRet->Append(*this, 0, NULL, 0);
+ if ( bCallInitNew ) {
+ // delete leading page / initial content from target document
+ SwNodeIndex aDeleteIdx( pRet->GetNodes().GetEndOfExtras(), 2 );
+ pRet->GetNodes().Delete( aDeleteIdx, 1 );
+ }
+
+ // remove the temporary shell if it is there as it was done before
+ pRet->SetTmpDocShell( (SfxObjectShell*) NULL );
+
+ pRet->release();
+
+ return pRetShell;
+}
+
+// appends all pages of source SwDoc - based on SwFEShell::Paste( SwDoc* )
+void SwDoc::Append( const SwDoc& rSource, int nStartPageNumber,
+ SwPageDesc* pTargetPageDesc, int nPhysPageNumber )
+{
// GetEndOfExtras + 1 = StartOfContent
- SwNodeIndex aSourceIdx( GetNodes().GetEndOfExtras(), 1 );
- SwPaM aCpyPam( aSourceIdx ); // DocStart
+ SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 );
+ SwPaM aCpyPam( aSourceIdx ); //DocStart
- SwNodeIndex aTargetIdx( pRet->GetNodes().GetEndOfContent() );
- SwPaM aInsertPam( aTargetIdx );
+ // Append at the end of document / content
+ SwNodeIndex aTargetIdx( GetNodes().GetEndOfContent() );
+ SwPaM aInsertPam( aTargetIdx ); //replaces PCURCRSR from SwFEShell::Paste()
+ aTargetIdx--;
aCpyPam.SetMark();
aCpyPam.Move( fnMoveForward, fnGoDoc );
- pRet->LockExpFlds();
+ GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
+ LockExpFlds();
{
+ // **
+ // ** refer to SwFEShell::Paste, if you change the following code **
+ // **
+
SwPosition& rInsPos = *aInsertPam.GetPoint();
- SwPosition aInsertPosition( rInsPos );
{
SwNodeIndex aIndexBefore(rInsPos.nNode);
aIndexBefore--;
- CopyRange( aCpyPam, rInsPos, true );
+ rSource.CopyRange( aCpyPam, rInsPos, true );
// Note: aCpyPam is invalid now
++aIndexBefore;
@@ -1022,37 +1047,54 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
aPaM.GetDoc()->MakeUniqueNumRules(aPaM);
- // No need to update the rsid, as pRet is an empty doc
+ // Update the rsid of each pasted text node
+ SwNodes &rDestNodes = GetNodes();
+ sal_uLong const nEndIdx = aPaM.End()->nNode.GetIndex();
+
+ for (sal_uLong nIdx = aPaM.Start()->nNode.GetIndex();
+ nIdx <= nEndIdx; ++nIdx)
+ {
+ SwTxtNode *const pTxtNode = rDestNodes[nIdx]->GetTxtNode();
+ if ( pTxtNode )
+ UpdateParRsid( pTxtNode );
+ }
+ }
+
+ // update the PageDesc pool item
+ if ( nStartPageNumber || pTargetPageDesc ) {
+ SwTxtNode *aTxtNd = dynamic_cast< SwTxtNode* >( GetNodes().GoNext(&aTargetIdx) );
+ if ( aTxtNd ) {
+ SfxPoolItem *pNewItem = aTxtNd->GetAttr( RES_PAGEDESC ).Clone();
+ SwFmtPageDesc *aDesc = dynamic_cast< SwFmtPageDesc* >( pNewItem );
+ if ( aDesc ) {
+ if ( nStartPageNumber )
+ aDesc->SetNumOffset( nStartPageNumber );
+ if ( pTargetPageDesc )
+ aDesc->RegisterToPageDesc( *pTargetPageDesc );
+ aTxtNd->SetAttr( *aDesc );
+ }
+ delete pNewItem;
+ }
}
// additionally copy page bound frames
- for ( sal_uInt16 i = 0; i < GetSpzFrmFmts()->size(); ++i )
+ const SwFrmFmts *pSpzFrmFmts = rSource.GetSpzFrmFmts();
+ for ( sal_uInt16 i = 0; i < pSpzFrmFmts->size(); ++i )
{
- const SwFrmFmt& rCpyFmt = *(*GetSpzFrmFmts())[i];
+ const SwFrmFmt& rCpyFmt = *(*pSpzFrmFmts)[i];
SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() );
if (FLY_AT_PAGE != aAnchor.GetAnchorId())
continue;
- pRet->CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
+ if ( nStartPageNumber )
+ aAnchor.SetPageNum( aAnchor.GetPageNum() + nPhysPageNumber );
+ CopyLayoutFmt( rCpyFmt, aAnchor, true, true );
}
}
- pRet->UnlockExpFlds();
- pRet->UpdateFlds( NULL, false );
+ GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
- // End of SwFEShell::Paste() codepath
-
- if ( bCallInitNew ) {
- // delete leading page / initial content from target document
- SwNodeIndex aDeleteIdx( pRet->GetNodes().GetEndOfExtras(), 2 );
- pRet->GetNodes().Delete( aDeleteIdx, 1 );
- }
-
- // remove the temporary shell if it is there as it was done before
- pRet->SetTmpDocShell( (SfxObjectShell*)NULL );
-
- pRet->release();
-
- return pRetShell;
+ UnlockExpFlds();
+ UpdateFlds(NULL, false);
}
sal_uInt16 SwTxtFmtColls::GetPos(const SwTxtFmtColl* p) const
diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index 628d9c1..8debb4c 100644
--- a/sw/source/core/frmedt/fecopy.cxx
+++ b/sw/source/core/frmedt/fecopy.cxx
@@ -668,13 +668,13 @@ namespace {
typedef std::pair< PaMPtr, PositionPtr > Insertion;
}
-bool SwFEShell::Paste( SwDoc* pClpDoc, bool bIncludingPageFrames, bool bIncludeFullDocument )
+bool SwFEShell::Paste( SwDoc* pClpDoc, bool bIncludingPageFrames )
{
SET_CURR_SHELL( this );
OSL_ENSURE( pClpDoc, "no clipboard document" );
const sal_uInt16 nStartPageNumber = GetPhyPageNum();
// then till end of the nodes array
- SwNodeIndex aIdx( pClpDoc->GetNodes().GetEndOfExtras(), (bIncludeFullDocument) ? 1 : 2 );
+ SwNodeIndex aIdx( pClpDoc->GetNodes().GetEndOfExtras(), 2 );
SwPaM aCpyPam( aIdx ); //DocStart
// If there are table formulas in the area, then display the table first
@@ -1022,6 +1022,10 @@ bool SwFEShell::Paste( SwDoc* pClpDoc, bool bIncludingPageFrames, bool bIncludeF
GetDoc()->ClearBoxNumAttrs( rInsPos.nNode );
}
+ // **
+ // ** Update SwDoc::Append, if you change the following code **
+ // **
+
// find out if the clipboard document starts with a table
bool bStartWithTable = 0 != aCpyPam.Start()->nNode.GetNode().FindTableNode();
SwPosition aInsertPosition( rInsPos );
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 43dcc8d..52d4eeb 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -2760,6 +2760,10 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
//initiate SelectShell() to create sub shells
pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
SwWrtShell* pTargetShell = pTargetView->GetWrtShellPtr();
+ SwDoc* pTargetDoc = pTargetShell->GetDoc();
+
+ pTargetView->GetDocShell()->_LoadStyles( *rSourceView.GetDocShell(), true );
+
// #i63806#
const SwPageDesc* pSourcePageDesc = rSourceShell.FindPageDescByName( sStartingPageDesc );
const SwFrmFmt& rMaster = pSourcePageDesc->GetMaster();
@@ -2848,8 +2852,6 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
{
//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
-
- SwDoc* pTargetDoc = pTargetShell->GetDoc();
OUString sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
pTargetShell->GetDoc()->MakePageDesc( sNewPageDescName );
pTargetPageDesc = pTargetShell->FindPageDescByName( sNewPageDescName );
@@ -2862,65 +2864,31 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
lcl_CopyFollowPageDesc( *pTargetShell, *pWorkPageDesc, *pTargetPageDesc, nDocNo );
}
}
- if(nDocNo == 1 || bPageStylesWithHeaderFooter)
- pTargetView->GetDocShell()->_LoadStyles( *rSourceView.GetDocShell(), true );
- if(nDocNo > 1)
- pTargetShell->InsertPageBreak( &sModifiedStartingPageDesc, nStartingPageNo );
else
+ pTargetPageDesc = pTargetShell->FindPageDescByName( sModifiedStartingPageDesc );
+
+ if(nDocNo == 1)
pTargetShell->SetPageStyle(sModifiedStartingPageDesc);
sal_uInt16 nPageCountBefore = pTargetShell->GetPageCnt();
OSL_ENSURE(!pTargetShell->GetTableFmt(),"target document ends with a table - paragraph should be appended");
- bool para_added = false;
-
- //#i51359# add a second paragraph in case there's only one
- {
- SwNodeIndex aIdx( pWorkDoc->GetNodes().GetEndOfExtras(), 2 );
- SwPosition aTestPos( aIdx );
- SwCursor aTestCrsr( aTestPos, 0, false );
- if ( !aTestCrsr.MovePara(fnParaNext, fnParaStart) )
- {
- //append a paragraph
- pWorkDoc->AppendTxtNode( aTestPos );
- para_added = true;
- }
- }
#ifdef DBG_UTIL
if ( nDocNo <= MAX_DOC_DUMP )
lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo );
#endif
- SwNodeIndex fixupIdx( pTargetNodes->GetEndOfContent(), -1 );
- pTargetShell->Paste( rWorkShell.GetDoc(), true, true );
-
- if (bPageStylesWithHeaderFooter) {
- // set the real page desc and update the number offset for the pasted document
- fixupIdx += 2;
- SwTxtNode *aTxtNd = fixupIdx.GetNode().GetTxtNode();
- if ( aTxtNd ) {
- SfxPoolItem *pNewItem = aTxtNd->GetAttr( RES_PAGEDESC ).Clone();
- SwFmtPageDesc *aDesc = dynamic_cast< SwFmtPageDesc* >( pNewItem );
- if ( aDesc ) {
- aDesc->SetNumOffset( nStartingPageNo );
- aDesc->RegisterToPageDesc( *pTargetPageDesc );
- aTxtNd->SetAttr( *aDesc );
- }
- delete pNewItem;
- }
+ if (nDocNo == 1 ) {
+ pTargetDoc->Append( *(rWorkShell.GetDoc()), 0, pTargetPageDesc, 0 );
- // delete the leading empty page from InsertPageBreak
- fixupIdx -= 2;
- pTargetNodes->Delete( fixupIdx, 2 );
- }
-
- if ( para_added ) {
- // Move cursor to the start or Delete will assert because
- // of the cursors SwIndex ref on the deleting node.
- pTargetShell->SttEndDoc( true );
- SwNodeIndex aTargetIdx( pTargetNodes->GetEndOfContent(), -1 );
- pTargetNodes->Delete( aTargetIdx, 1 );
+ // delete the leading empty page from the initial SwDoc
+ pTargetShell->SttEndDoc( false );
+ SwNodeIndex aDeleteIdx( pTargetNodes->GetEndOfExtras(), 2 );
+ pTargetNodes->Delete( aDeleteIdx, 1 );
}
+ else
+ pTargetDoc->Append( *(rWorkShell.GetDoc()), nStartingPageNo,
+ pTargetPageDesc, pTargetShell->GetPhyPageNum() );
// #i72820# calculate layout to be able to find the correct page index
pTargetShell->CalcLayout();
More information about the Libreoffice-commits
mailing list