summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2014-06-23 09:16:18 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2014-09-30 09:47:55 +0200
commite5da198776ecfcea6ff2f4ceed466fc0206a1ccb (patch)
tree3480fc7f6bdd51e767e3ae4cad0633f618e7350b
parent9b83dcd9f593950e41b9f3036f10c76de8d1c5d1 (diff)
Replace the whole content for copied documents
If the document is initialized in CreateCopy, it already contains the initial empty paragraph. So we have to delete the content from initial document, as we're going to replace the whole content with the pasted document. Change-Id: Ie6a64dcb070f7d611dfde97f2c1a721834b4167b Reviewed-on: https://gerrit.libreoffice.org/10963 Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com> Tested-by: Björn Michaelsen <bjoern.michaelsen@canonical.com> (cherry picked from commit ddffb797904c5ae1a5ab3bc66eeb9bfc168a0148) Conflicts: sw/inc/IDocumentContentOperations.hxx
-rw-r--r--sw/inc/IDocumentContentOperations.hxx34
-rw-r--r--sw/source/core/doc/docnew.cxx20
2 files changed, 44 insertions, 10 deletions
diff --git a/sw/inc/IDocumentContentOperations.hxx b/sw/inc/IDocumentContentOperations.hxx
index 6f0bf4067b53..bf53112e7516 100644
--- a/sw/inc/IDocumentContentOperations.hxx
+++ b/sw/inc/IDocumentContentOperations.hxx
@@ -62,11 +62,37 @@
, INS_FORCEHINTEXPAND = 0x04 // expand all hints at insert position
};
- public:
- /** Copying of a range within or to another document.
- The position can also be within the range!
+public:
+ /** Copy a selected content range to a position
+
+ The position can be in the same or in an another document. It can also
+ be within the range!
+
+ \warning The range has to include at least two nodes or has to be a
+ SwDoc::IsColumnSelection!
+
+ Normally this functions should work only with content nodes. But there
+ is a special case used by SwDoc::Paste, which starts the SwPaM at the
+ content start node. This position doesn't contain any content:
+
+ @code
+ SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 );
+ @endcode
+
+ This is important, because it prevents merging of the first node of
+ the range into the node pointed to by \p rPos.
+ As a result this keeps all properties of the first real content node,
+ which is the 2nd, including the Flys and the page description. In this
+ case the first (fake) node is silently dropped and all other nodes are
+ just copied.
+
+ @param rPam
+ The source node range to copy
+
+ @param rPos
+ The target copy destination
*/
- virtual bool CopyRange(SwPaM&, SwPosition&, const bool bCopyAll ) const = 0;
+ virtual bool CopyRange(SwPaM& rPam, SwPosition& rPos, const bool bCopyAll ) const = 0;
/** Delete section containing the node.
*/
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index b4b219d692ac..b916bd25a371 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -1144,6 +1144,12 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
// copy content
pRet->Paste( *this );
+ 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 );
@@ -1155,12 +1161,14 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
// copy document content - code from SwFEShell::Paste( SwDoc* )
void SwDoc::Paste( const SwDoc& rSource )
{
- // this has to be empty const sal_uInt16 nStartPageNumber = GetPhyPageNum();
- // until the end of the NodesArray
- SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 2 );
- SwPaM aCpyPam( aSourceIdx ); //DocStart
- SwNodeIndex aTargetIdx( GetNodes().GetEndOfExtras(), 2 );
- SwPaM aInsertPam( aTargetIdx ); //replaces PCURCRSR from SwFEShell::Paste()
+ // GetEndOfExtras + 1 = StartOfContent == no content node!
+ // this ensures, that we have at least two nodes in the SwPaM.
+ // @see IDocumentContentOperations::CopyRange
+ SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 );
+ SwPaM aCpyPam( aSourceIdx );
+
+ SwNodeIndex aTargetIdx( GetNodes().GetEndOfContent() );
+ SwPaM aInsertPam( aTargetIdx );
aCpyPam.SetMark();