summaryrefslogtreecommitdiff
path: root/sw/source/uibase
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2014-06-28 01:41:17 +0200
committerBjörn Michaelsen <bjoern.michaelsen@canonical.com>2014-09-10 11:06:01 +0000
commitc808802e94eba48dc23d7fca133ed35c17feb163 (patch)
tree8faaf4dfaec9a046137d57eb084d0d74f9afca66 /sw/source/uibase
parent8e174eab91acec0f1578af4dac23be76dce700af (diff)
MM: introduce SwDoc::Append helper function
This drops all the specialized, workaround code from MM, introduced to use the SwFEShell::Paste function and additionally merges and renames SwDoc::Paste into SwDoc::Append. There is still a little common codepath, therefore this adds comments to always update both functions. Change-Id: I704b3ef3257dd977dac95e16e25049ff8ade97ed Reviewed-on: https://gerrit.libreoffice.org/10967 Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com> Tested-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Diffstat (limited to 'sw/source/uibase')
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx114
1 files changed, 22 insertions, 92 deletions
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 20bcefb26d46..7b013a7cf678 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -885,7 +885,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
// in case of creating a single resulting file this has to be created here
SwWrtShell* pTargetShell = 0;
SwDoc* pTargetDoc = 0;
- SwNodes* pTargetNodes = 0;
// the shell will be explicitly closed at the end of the method, but it is
// still more safe to use SfxObjectShellLock here
@@ -897,6 +896,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
OUString sStartingPageDesc;
sal_uInt16 nStartingPageNo = 0;
bool bPageStylesWithHeaderFooter = false;
+
if(bAsSingleFile || rMergeDescriptor.bCreateSingleFile)
{
// create a target docshell to put the merged document into
@@ -910,7 +910,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
pTargetShell = pTargetView->GetWrtShellPtr();
pTargetDoc = pTargetShell->GetDoc();
- pTargetNodes = &pTargetDoc->GetNodes();
+
//copy the styles from the source to the target document
pTargetView->GetDocShell()->_LoadStyles( *pSourceDocSh, true );
//determine the page style and number used at the start of the source document
@@ -1050,66 +1050,32 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
}
// insert the document into the target document
- rWorkShell.SttEndDoc(false);
- rWorkShell.SttEndDoc(true);
- rWorkShell.SelAll();
- pTargetShell->SwCrsrShell::SttEndDoc( false );
- //#i72517# the headers and footers are still those from the source - update in case of fields inside header/footer
- if( !nDocNo && bPageStylesWithHeaderFooter )
- pTargetShell->GetView().GetDocShell()->_LoadStyles( *rWorkShell.GetView().GetDocShell(), true );
+
//#i72517# put the styles to the target document
//if the source uses headers or footers each new copy need to copy a new page styles
+ SwPageDesc* pTargetPageDesc;
if(bPageStylesWithHeaderFooter)
{
//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
- SwPageDesc* pSourcePageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc );
OUString sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
- pTargetDoc->MakePageDesc( sNewPageDescName );
- SwPageDesc* pTargetPageDesc = pTargetShell->FindPageDescByName( sNewPageDescName );
- if(pSourcePageDesc && pTargetPageDesc)
+ pTargetPageDesc = pTargetDoc->MakePageDesc( sNewPageDescName );
+ const SwPageDesc* pWorkPageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc );
+
+ if(pWorkPageDesc && pTargetPageDesc)
{
- pTargetDoc->CopyPageDesc( *pSourcePageDesc, *pTargetPageDesc, false );
+ pTargetDoc->CopyPageDesc( *pWorkPageDesc, *pTargetPageDesc, false );
sModifiedStartingPageDesc = sNewPageDescName;
- lcl_CopyFollowPageDesc( *pTargetShell, *pSourcePageDesc, *pTargetPageDesc, nDocNo );
+ lcl_CopyFollowPageDesc( *pTargetShell, *pWorkPageDesc, *pTargetPageDesc, nDocNo );
}
}
-
- if(nDocNo > 1)
- pTargetShell->InsertPageBreak( &sModifiedStartingPageDesc, nStartingPageNo );
else
- pTargetShell->SetPageStyle(sModifiedStartingPageDesc);
- OSL_ENSURE(!pTargetShell->GetTableFmt(),"target document ends with a table - paragraph should be appended");
+ pTargetPageDesc = pTargetShell->FindPageDescByName( sModifiedStartingPageDesc );
- //#i51359# add a second paragraph in case there's only one
- bool para_added = false;
- {
- SwNodeIndex aIdx( pWorkDoc->GetNodes().GetEndOfExtras(), 2 );
- SwPosition aTestPos( aIdx );
- SwCursor aTestCrsr(aTestPos,0,false);
- if(!aTestCrsr.MovePara(fnParaNext, fnParaStart))
- {
- //append a paragraph
- pWorkDoc->getIDocumentContentOperations().AppendTxtNode( aTestPos );
- para_added = true;
- }
- }
- pTargetShell->Paste( rWorkShell.GetDoc(), true );
-
- 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 );
- }
+ pTargetDoc->Append( *(rWorkShell.GetDoc()), nStartingPageNo, pTargetPageDesc, nDocNo == 1 );
- //convert fields in page styles (header/footer - has to be done after the first document has been pasted
- if(1 == nDocNo)
- {
- pTargetShell->CalcLayout();
- pTargetShell->ConvertFieldsToText();
- }
+ // #i72820# calculate layout to be able to find the correct page index
+ pTargetShell->CalcLayout();
}
else
{
@@ -2775,7 +2741,8 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
SwWrtShell* pTargetShell = pTargetView->GetWrtShellPtr();
SwDoc* pTargetDoc = pTargetShell->GetDoc();
- SwNodes* pTargetNodes = &pTargetDoc->GetNodes();
+
+ pTargetView->GetDocShell()->_LoadStyles( *rSourceView.GetDocShell(), true );
// #i63806#
const SwPageDesc* pSourcePageDesc = rSourceShell.FindPageDescByName( sStartingPageDesc );
@@ -2852,21 +2819,16 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
}
// insert the document into the target document
- rWorkShell.SttEndDoc(false);
- rWorkShell.SttEndDoc(true);
- rWorkShell.SelAll();
- pTargetShell->SttEndDoc(false);
//#i63806# put the styles to the target document
//if the source uses headers or footers each new copy need to copy a new page styles
+ SwPageDesc* pTargetPageDesc;
if(bPageStylesWithHeaderFooter)
{
//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
-
OUString sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
- pTargetShell->GetDoc()->MakePageDesc( sNewPageDescName );
- SwPageDesc* pTargetPageDesc = pTargetShell->FindPageDescByName( sNewPageDescName );
+ pTargetPageDesc = pTargetDoc->MakePageDesc( sNewPageDescName );
const SwPageDesc* pWorkPageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc );
if(pWorkPageDesc && pTargetPageDesc)
@@ -2876,50 +2838,20 @@ 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
- pTargetShell->SetPageStyle(sModifiedStartingPageDesc);
+ pTargetPageDesc = pTargetShell->FindPageDescByName( 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->getIDocumentContentOperations().AppendTxtNode( aTestPos );
- para_added = true;
- }
- }
#ifdef DBG_UTIL
if ( nDocNo <= MAX_DOC_DUMP )
lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo );
#endif
- pTargetShell->Paste( rWorkShell.GetDoc(), true );
-
- 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 );
- }
+ pTargetDoc->Append( *(rWorkShell.GetDoc()), nStartingPageNo, pTargetPageDesc, nDocNo == 1 );
- //convert fields in page styles (header/footer - has to be done after the first document has been pasted
- if(1 == nDocNo)
- {
- pTargetShell->CalcLayout();
- pTargetShell->ConvertFieldsToText();
- }
+ // #i72820# calculate layout to be able to find the correct page index
+ pTargetShell->CalcLayout();
#ifdef DBG_UTIL
if ( nDocNo <= MAX_DOC_DUMP )
lcl_SaveDoc( xTargetDocShell, "MergeDoc" );
@@ -2928,8 +2860,6 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
// add the document info to the config item
SwDocMergeInfo aMergeInfo;
aMergeInfo.nStartPageInTarget = nPageCountBefore;
- //#i72820# calculate layout to be able to find the correct page index
- pTargetShell->CalcLayout();
aMergeInfo.nEndPageInTarget = pTargetShell->GetPageCnt();
aMergeInfo.nDBRow = nStartRow;
rMMConfig.AddMergedDocument( aMergeInfo );