123792: corrections regarding copy-and-paste of annotation fields



git-svn-id: https://svn.apache.org/repos/asf/openoffice/branches/ooxml-osba@1552283 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/main/sw/inc/doc.hxx b/main/sw/inc/doc.hxx
index 3746c67..c1b8c79 100644
--- a/main/sw/inc/doc.hxx
+++ b/main/sw/inc/doc.hxx
@@ -1108,12 +1108,14 @@
 								const SwSelBoxes* pSelBoxes = 0,
 								SwFrmFmt *pParent = 0 );
 
-	void CopyWithFlyInFly( const SwNodeRange& rRg,
-                            const xub_StrLen nEndContentIndex,
-							const SwNodeIndex& rInsPos,
-							sal_Bool bMakeNewFrms = sal_True,
-							sal_Bool bDelRedlines = sal_True,
-							sal_Bool bCopyFlyAtFly = sal_False ) const;
+    void CopyWithFlyInFly(
+        const SwNodeRange& rRg,
+        const xub_StrLen nEndContentIndex,
+        const SwNodeIndex& rInsPos,
+        const SwPaM* pCopiedPaM = NULL,
+        const sal_Bool bMakeNewFrms = sal_True,
+        const sal_Bool bDelRedlines = sal_True,
+        const sal_Bool bCopyFlyAtFly = sal_False ) const;
 
     sal_Bool SetFlyFrmAttr( SwFrmFmt& rFlyFmt, SfxItemSet& rSet );
 
diff --git a/main/sw/source/core/doc/docbm.cxx b/main/sw/source/core/doc/docbm.cxx
index e176a9b..52abbbe 100644
--- a/main/sw/source/core/doc/docbm.cxx
+++ b/main/sw/source/core/doc/docbm.cxx
@@ -1360,38 +1360,33 @@
     const sal_Int32 nMarksCount = pMarkAccess->getAllMarksCount();
     for ( ; aSave.GetCount() < nMarksCount; aSave.IncCount() )
     {
-        bool bEqual = false;
-        bool bLower = false;
+        bool bMarkPosEqual = false;
         const ::sw::mark::IMark* pBkmk = (pMarkAccess->getAllMarksBegin() + aSave.GetCount())->get();
         if(pBkmk->GetMarkPos().nNode.GetIndex() == nNode
             && pBkmk->GetMarkPos().nContent.GetIndex() <= nCntnt)
         {
             if(pBkmk->GetMarkPos().nContent.GetIndex() < nCntnt)
             {
-                bLower = true; // a hint for the other position...
                 aSave.SetContent(pBkmk->GetMarkPos().nContent.GetIndex());
                 aSave.Add(rSaveArr);
             }
             else // if a bookmark position is equal nCntnt, the other position
-                bEqual = true; // has to decide if it is added to the array
+                bMarkPosEqual = true; // has to decide if it is added to the array
         }
 
         if(pBkmk->IsExpanded()
             && pBkmk->GetOtherMarkPos().nNode.GetIndex() == nNode
             && pBkmk->GetOtherMarkPos().nContent.GetIndex() <= nCntnt)
         {
-            if(bLower || pBkmk->GetOtherMarkPos().nContent.GetIndex() < nCntnt)
-            {
-                if(bEqual)
-                { // the other position is before, the (main) position is equal
-                    aSave.SetContent(pBkmk->GetMarkPos().nContent.GetIndex());
-                    aSave.Add(rSaveArr);
-                }
-                aSave.SetContent(pBkmk->GetOtherMarkPos().nContent.GetIndex());
-                aSave.IncType();
+            if(bMarkPosEqual)
+            { // the other position is before, the (main) position is equal
+                aSave.SetContent(pBkmk->GetMarkPos().nContent.GetIndex());
                 aSave.Add(rSaveArr);
-                aSave.DecType();
             }
+            aSave.SetContent(pBkmk->GetOtherMarkPos().nContent.GetIndex());
+            aSave.IncType();
+            aSave.Add(rSaveArr);
+            aSave.DecType();
         }
     }
 
diff --git a/main/sw/source/core/doc/doccomp.cxx b/main/sw/source/core/doc/doccomp.cxx
index b97c8c1..cc7d470 100644
--- a/main/sw/source/core/doc/doccomp.cxx
+++ b/main/sw/source/core/doc/doccomp.cxx
@@ -1354,8 +1354,11 @@
 
 }
 
-void SwCompareData::ShowDelete( const CompareData& rData, sal_uLong nStt,
-								sal_uLong nEnd, sal_uLong nInsPos )
+void SwCompareData::ShowDelete(
+    const CompareData& rData,
+    sal_uLong nStt,
+    sal_uLong nEnd,
+    sal_uLong nInsPos )
 {
 	SwNodeRange aRg(
 		((SwCompareLine*)rData.GetLine( nStt ))->GetNode(), 0,
diff --git a/main/sw/source/core/doc/doclay.cxx b/main/sw/source/core/doc/doclay.cxx
index b4570f6..b8a1acc 100644
--- a/main/sw/source/core/doc/doclay.cxx
+++ b/main/sw/source/core/doc/doclay.cxx
@@ -389,9 +389,11 @@
 |*
 |*************************************************************************/
 
-SwFrmFmt *SwDoc::CopyLayoutFmt( const SwFrmFmt& rSource,
-								const SwFmtAnchor& rNewAnchor,
-                                bool bSetTxtFlyAtt, bool bMakeFrms )
+SwFrmFmt *SwDoc::CopyLayoutFmt(
+    const SwFrmFmt& rSource,
+    const SwFmtAnchor& rNewAnchor,
+    bool bSetTxtFlyAtt,
+    bool bMakeFrms )
 {
     const bool bFly = RES_FLYFRMFMT == rSource.Which();
     const bool bDraw = RES_DRAWFRMFMT == rSource.Which();
@@ -497,7 +499,7 @@
 
 		// sorge dafuer das auch Fly's in Fly's kopiert werden
 		aIdx = *pSttNd->EndOfSectionNode();
-        pSrcDoc->CopyWithFlyInFly( aRg, 0, aIdx, sal_False, sal_True, sal_True );
+        pSrcDoc->CopyWithFlyInFly( aRg, 0, aIdx, NULL, sal_False, sal_True, sal_True );
 	}
 	else
 	{
diff --git a/main/sw/source/core/doc/tblcpy.cxx b/main/sw/source/core/doc/tblcpy.cxx
index fd7a137..e777e4e 100644
--- a/main/sw/source/core/doc/tblcpy.cxx
+++ b/main/sw/source/core/doc/tblcpy.cxx
@@ -561,7 +561,7 @@
 
 	SwNodeIndex aSavePos( aInsIdx, -1 );
     if( pRg.get() )
-        pCpyDoc->CopyWithFlyInFly( *pRg, 0, aInsIdx, sal_False );
+        pCpyDoc->CopyWithFlyInFly( *pRg, 0, aInsIdx, NULL, sal_False );
     else
 		pDoc->GetNodes().MakeTxtNode( aInsIdx, (SwTxtFmtColl*)pDoc->GetDfltTxtFmtColl() );
 	aSavePos++;
diff --git a/main/sw/source/core/doc/tblrwcl.cxx b/main/sw/source/core/doc/tblrwcl.cxx
index ec897da..36281be 100644
--- a/main/sw/source/core/doc/tblrwcl.cxx
+++ b/main/sw/source/core/doc/tblrwcl.cxx
@@ -2098,7 +2098,7 @@
                             *rpFndBox->GetBox()->GetSttNd()->EndOfSectionNode() );
                 SwNodeIndex aInsIdx( *pBox->GetSttNd(), 1 );
 
-                pFromDoc->CopyWithFlyInFly( aCpyRg, 0, aInsIdx, sal_False );
+                pFromDoc->CopyWithFlyInFly( aCpyRg, 0, aInsIdx, NULL, sal_False );
                 // den initialen TextNode loeschen
                 pCpyPara->pDoc->GetNodes().Delete( aInsIdx, 1 );
             }
diff --git a/main/sw/source/core/docnode/ndcopy.cxx b/main/sw/source/core/docnode/ndcopy.cxx
index 473abc8..214cfa6 100644
--- a/main/sw/source/core/docnode/ndcopy.cxx
+++ b/main/sw/source/core/docnode/ndcopy.cxx
@@ -132,7 +132,9 @@
     }
 
     // TODO: use SaveBookmark (from _DelBookmarks)
-    static void lcl_CopyBookmarks(const SwPaM& rPam, SwPaM& rCpyPam)
+    static void lcl_CopyBookmarks(
+        const SwPaM& rPam,
+        SwPaM& rCpyPam )
     {
         const SwDoc* pSrcDoc = rPam.GetDoc();
         SwDoc* pDestDoc =  rCpyPam.GetDoc();
@@ -1249,13 +1251,13 @@
 			if( aInsPos == pEnd->nNode )
 			{
 				SwNodeIndex aSaveIdx( aInsPos, -1 );
-                CopyWithFlyInFly( aRg, 0,aInsPos, bMakeNewFrms, sal_False );
+                CopyWithFlyInFly( aRg, 0, aInsPos, &rPam, bMakeNewFrms, sal_False );
 				aSaveIdx++;
 				pEnd->nNode = aSaveIdx;
 				pEnd->nContent.Assign( aSaveIdx.GetNode().GetTxtNode(), 0 );
 			}
 			else
-                CopyWithFlyInFly( aRg, pEnd->nContent.GetIndex(), aInsPos, bMakeNewFrms, sal_False );
+                CopyWithFlyInFly( aRg, pEnd->nContent.GetIndex(), aInsPos, &rPam, bMakeNewFrms, sal_False );
 
             bCopyBookmarks = false;
 
@@ -1322,22 +1324,27 @@
 
 //  ----- Copy-Methode vom SwDoc - "kopiere Fly's in Fly's" ------
 
-void SwDoc::CopyWithFlyInFly( const SwNodeRange& rRg, const xub_StrLen nEndContentIndex,
-							const SwNodeIndex& rInsPos, sal_Bool bMakeNewFrms,
-							sal_Bool bDelRedlines, sal_Bool bCopyFlyAtFly ) const
+void SwDoc::CopyWithFlyInFly(
+    const SwNodeRange& rRg,
+    const xub_StrLen nEndContentIndex,
+    const SwNodeIndex& rInsPos,
+    const SwPaM* pCopiedPaM,
+    const sal_Bool bMakeNewFrms,
+    const sal_Bool bDelRedlines,
+    const sal_Bool bCopyFlyAtFly ) const
 {
-	SwDoc* pDest = rInsPos.GetNode().GetDoc();
+    SwDoc* pDest = rInsPos.GetNode().GetDoc();
 
-	_SaveRedlEndPosForRestore aRedlRest( rInsPos, 0 );
+    _SaveRedlEndPosForRestore aRedlRest( rInsPos, 0 );
 
-	SwNodeIndex aSavePos( rInsPos, -1 );
-	sal_Bool bEndIsEqualEndPos = rInsPos == rRg.aEnd;
-	GetNodes()._CopyNodes( rRg, rInsPos, bMakeNewFrms, sal_True );
-	aSavePos++;
-	if( bEndIsEqualEndPos )
-		((SwNodeIndex&)rRg.aEnd) = aSavePos;
+    SwNodeIndex aSavePos( rInsPos, -1 );
+    sal_Bool bEndIsEqualEndPos = rInsPos == rRg.aEnd;
+    GetNodes()._CopyNodes( rRg, rInsPos, bMakeNewFrms, sal_True );
+    aSavePos++;
+    if( bEndIsEqualEndPos )
+        ((SwNodeIndex&)rRg.aEnd) = aSavePos;
 
-	aRedlRest.Restore();
+    aRedlRest.Restore();
 
 #ifdef DBG_UTIL
 	{
@@ -1363,21 +1370,23 @@
         CopyFlyInFlyImpl( rRg, nEndContentIndex, aSavePos, bCopyFlyAtFly );
     }
 
-	SwNodeRange aCpyRange( aSavePos, rInsPos );
+    SwNodeRange aCpyRange( aSavePos, rInsPos );
 
-	// dann kopiere noch alle Bookmarks
+    // dann kopiere noch alle Bookmarks
     if( getIDocumentMarkAccess()->getAllMarksCount() )
-	{
-		SwPaM aRgTmp( rRg.aStart, rRg.aEnd );
-		SwPaM aCpyTmp( aCpyRange.aStart, aCpyRange.aEnd );
+    {
+        SwPaM aRgTmp( rRg.aStart, rRg.aEnd );
+        SwPaM aCpyTmp( aCpyRange.aStart, aCpyRange.aEnd );
 
-		lcl_CopyBookmarks( aRgTmp, aCpyTmp );
-	}
+        lcl_CopyBookmarks(
+            pCopiedPaM != NULL ? *pCopiedPaM : aRgTmp,
+            aCpyTmp );
+    }
 
-	if( bDelRedlines && ( nsRedlineMode_t::REDLINE_DELETE_REDLINES & pDest->GetRedlineMode() ))
-		lcl_DeleteRedlines( rRg, aCpyRange );
+    if( bDelRedlines && ( nsRedlineMode_t::REDLINE_DELETE_REDLINES & pDest->GetRedlineMode() ))
+        lcl_DeleteRedlines( rRg, aCpyRange );
 
-	pDest->GetNodes()._DelDummyNodes( aCpyRange );
+    pDest->GetNodes()._DelDummyNodes( aCpyRange );
 }
 
 void lcl_ChainFmts( SwFlyFrmFmt *pSrc, SwFlyFrmFmt *pDest )
@@ -1396,9 +1405,11 @@
 	}
 }
 
-void SwDoc::CopyFlyInFlyImpl( const SwNodeRange& rRg,
-        const xub_StrLen nEndContentIndex, const SwNodeIndex& rStartIdx,
-        const bool bCopyFlyAtFly ) const
+void SwDoc::CopyFlyInFlyImpl(
+    const SwNodeRange& rRg,
+    const xub_StrLen nEndContentIndex,
+    const SwNodeIndex& rStartIdx,
+    const bool bCopyFlyAtFly ) const
 {
 	// Bug 22727: suche erst mal alle Flys zusammen, sortiere sie entsprechend
 	//			  ihrer Ordnungsnummer und kopiere sie erst dann. Damit wird
diff --git a/main/sw/source/core/docnode/section.cxx b/main/sw/source/core/docnode/section.cxx
index f40e47d..8a33d1e 100644
--- a/main/sw/source/core/docnode/section.cxx
+++ b/main/sw/source/core/docnode/section.cxx
@@ -1548,7 +1548,7 @@
 
 					SwTblNumFmtMerge aTNFM( *pSrcDoc, *pDoc );
 
-                    pSrcDoc->CopyWithFlyInFly( *pCpyRg, 0, rInsPos, bCreateFrm );
+                    pSrcDoc->CopyWithFlyInFly( *pCpyRg, 0, rInsPos, NULL, bCreateFrm );
 					aSave++;
 
 					if( !bCreateFrm )
diff --git a/main/sw/source/core/txtnode/atrftn.cxx b/main/sw/source/core/txtnode/atrftn.cxx
index 538714a..c424c23 100644
--- a/main/sw/source/core/txtnode/atrftn.cxx
+++ b/main/sw/source/core/txtnode/atrftn.cxx
@@ -282,7 +282,9 @@
 }
 
 // Die Fussnoten duplizieren
-void SwTxtFtn::CopyFtn(SwTxtFtn & rDest, SwTxtNode & rDestNode) const
+void SwTxtFtn::CopyFtn(
+    SwTxtFtn & rDest,
+    SwTxtNode & rDestNode ) const
 {
     if (m_pStartNode && !rDest.GetStartNode())
     {
@@ -306,7 +308,7 @@
 		SwNodeIndex aEnd( *aStart.GetNode().EndOfSectionNode() );
 		sal_uLong  nDestLen = aEnd.GetIndex() - aStart.GetIndex() - 1;
 
-        m_pTxtNode->GetDoc()->CopyWithFlyInFly( aRg, 0, aEnd, sal_True );
+        m_pTxtNode->GetDoc()->CopyWithFlyInFly( aRg, 0, aEnd, NULL, sal_True );
 
         // in case the destination section was not empty, delete the old nodes
         // before:   Src: SxxxE,  Dst: SnE
diff --git a/main/sw/source/core/txtnode/thints.cxx b/main/sw/source/core/txtnode/thints.cxx
index 24c3c00..f2e4473 100644
--- a/main/sw/source/core/txtnode/thints.cxx
+++ b/main/sw/source/core/txtnode/thints.cxx
@@ -1055,6 +1055,14 @@
     case RES_TXTATR_ANNOTATION:
         {
             pNew = new SwTxtAnnotationFld( static_cast<SwFmtFld &>(rNew), nStt );
+            if ( bIsCopy == COPY )
+            {
+                // On copy of the annotation field do not keep the annotated text range by removing
+                // the relation to its annotation mark (relation established via annotation field's name).
+                // If the annotation mark is also copied, the relation and thus the annotated text range will be reestablished,
+                // when the annotation mark is created and inserted into the document.
+                const_cast<SwPostItField*>(dynamic_cast< const SwPostItField* >(pNew->GetFmtFld().GetField()))->SetName( String() );
+            }
         }
         break;
 
@@ -2943,12 +2951,6 @@
                 case RES_POSTITFLD:
                     if ( pDoc->GetDocShell() )
                         pDoc->GetDocShell()->Broadcast( SwFmtFldHint( &((SwTxtFld*)pHint)->GetFmtFld(), SWFMTFLD_INSERTED ) );
-                    // For annotations on text ranges the corresponding annotation mark is created afterwards.
-                    // Thus, if there is already an annotation mark, clear the annotation's name in order to cut the relation
-                    if ( dynamic_cast< SwTxtAnnotationFld* >(pHint)->GetAnnotationMark( rNode.GetDoc() ) != NULL )
-                    {
-                        const_cast<SwPostItField*>(dynamic_cast< const SwPostItField* >(pHint->GetFmtFld().GetField()))->SetName( String() );
-                    }
                     break;
                 }
                 if( bInsFldType )
diff --git a/main/sw/source/core/undo/undobj.cxx b/main/sw/source/core/undo/undobj.cxx
index 7ee7981..5c79053 100644
--- a/main/sw/source/core/undo/undobj.cxx
+++ b/main/sw/source/core/undo/undobj.cxx
@@ -852,7 +852,7 @@
                     {
                         // delete annotation marks, if its end position is covered by the deletion
                         const SwPosition& rAnnotationEndPos = pBkmk->GetMarkEnd();
-                        if ( *pStt <= rAnnotationEndPos && rAnnotationEndPos <= *pEnd )
+                        if ( *pStt < rAnnotationEndPos && rAnnotationEndPos <= *pEnd )
                         {
                             bSavePos = true;
                             bSaveOtherPos = true;