xref: /AOO41X/main/sw/source/core/docnode/ndcopy.cxx (revision dec99bbd1eb6ae693d6ee672c1a69e3a32d917e7)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <editeng/brkitem.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #define _ZFORLIST_DECLARE_TABLE
30cdf0e10cSrcweir #include <hintids.hxx>
31cdf0e10cSrcweir #include <fmtpdsc.hxx>
32cdf0e10cSrcweir #include <fmtanchr.hxx>
33cdf0e10cSrcweir #include <fmtcntnt.hxx>
34cdf0e10cSrcweir #include <doc.hxx>
35cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
36cdf0e10cSrcweir #include <pam.hxx>
37cdf0e10cSrcweir #include <ndtxt.hxx>
38cdf0e10cSrcweir #include <fldbas.hxx>
39cdf0e10cSrcweir #include <swtable.hxx>
40cdf0e10cSrcweir #include <ddefld.hxx>
41cdf0e10cSrcweir #include <undobj.hxx>
42cdf0e10cSrcweir #include <IMark.hxx>
43cdf0e10cSrcweir #include <mvsave.hxx>
44cdf0e10cSrcweir #include <cellatr.hxx>
45cdf0e10cSrcweir #include <swtblfmt.hxx>
46cdf0e10cSrcweir #include <swddetbl.hxx>
47cdf0e10cSrcweir #include <docary.hxx>
48cdf0e10cSrcweir #include <fmtcnct.hxx>
49cdf0e10cSrcweir #include <redline.hxx>
50cdf0e10cSrcweir #include <paratr.hxx>
51cdf0e10cSrcweir #include <pagedesc.hxx>
52cdf0e10cSrcweir #include <poolfmt.hxx>
53cdf0e10cSrcweir #include <SwNodeNum.hxx>
54cdf0e10cSrcweir #ifndef DBG_UTIL
55cdf0e10cSrcweir #define CHECK_TABLE(t)
56cdf0e10cSrcweir #else
57cdf0e10cSrcweir #ifdef DEBUG
58cdf0e10cSrcweir #define CHECK_TABLE(t) (t).CheckConsistency();
59cdf0e10cSrcweir #else
60cdf0e10cSrcweir #define CHECK_TABLE(t)
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #endif
63cdf0e10cSrcweir 
64cdf0e10cSrcweir namespace
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     /*
67cdf0e10cSrcweir         The lcl_CopyBookmarks function has to copy bookmarks from the source to the destination nodes
68cdf0e10cSrcweir         array. It is called after a call of the _CopyNodes(..) function. But this function does not copy
69cdf0e10cSrcweir         every node (at least at the moment: 2/08/2006 ), section start and end nodes will not be copied if the corresponding end/start node is outside the copied pam.
70cdf0e10cSrcweir         The lcl_NonCopyCount function counts the number of these nodes, given the copied pam and a node
71cdf0e10cSrcweir         index inside the pam.
72cdf0e10cSrcweir         rPam is the original source pam, rLastIdx is the last calculated position, rDelCount the number
73cdf0e10cSrcweir         of "non-copy" nodes between rPam.Start() and rLastIdx.
74cdf0e10cSrcweir         nNewIdx is the new position of interest.
75cdf0e10cSrcweir     */
76cdf0e10cSrcweir 
lcl_NonCopyCount(const SwPaM & rPam,SwNodeIndex & rLastIdx,const sal_uLong nNewIdx,sal_uLong & rDelCount)77cdf0e10cSrcweir     static void lcl_NonCopyCount( const SwPaM& rPam, SwNodeIndex& rLastIdx, const sal_uLong nNewIdx, sal_uLong& rDelCount )
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         sal_uLong nStart = rPam.Start()->nNode.GetIndex();
80cdf0e10cSrcweir         sal_uLong nEnd = rPam.End()->nNode.GetIndex();
81cdf0e10cSrcweir         if( rLastIdx.GetIndex() < nNewIdx ) // Moving forward?
82cdf0e10cSrcweir         {
83cdf0e10cSrcweir             do // count "non-copy" nodes
84cdf0e10cSrcweir             {
85cdf0e10cSrcweir                 SwNode& rNode = rLastIdx.GetNode();
86cdf0e10cSrcweir                 if( ( rNode.IsSectionNode() && rNode.EndOfSectionIndex() >= nEnd )
87cdf0e10cSrcweir                     || ( rNode.IsEndNode() && rNode.StartOfSectionNode()->GetIndex() < nStart ) )
88cdf0e10cSrcweir                     ++rDelCount;
89cdf0e10cSrcweir                 rLastIdx++;
90cdf0e10cSrcweir             }
91cdf0e10cSrcweir             while( rLastIdx.GetIndex() < nNewIdx );
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir         else if( rDelCount ) // optimization: if there are no "non-copy" nodes until now,
94cdf0e10cSrcweir                              // no move backward needed
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             while( rLastIdx.GetIndex() > nNewIdx )
97cdf0e10cSrcweir             {
98cdf0e10cSrcweir                 SwNode& rNode = rLastIdx.GetNode();
99cdf0e10cSrcweir                 if( ( rNode.IsSectionNode() && rNode.EndOfSectionIndex() >= nEnd )
100cdf0e10cSrcweir                     || ( rNode.IsEndNode() && rNode.StartOfSectionNode()->GetIndex() < nStart ) )
101cdf0e10cSrcweir                     --rDelCount;
102cdf0e10cSrcweir                 rLastIdx--;
103cdf0e10cSrcweir             }
104cdf0e10cSrcweir         }
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
lcl_SetCpyPos(const SwPosition & rOrigPos,const SwPosition & rOrigStt,const SwPosition & rCpyStt,SwPosition & rChgPos,sal_uLong nDelCount)107cdf0e10cSrcweir     static void lcl_SetCpyPos( const SwPosition& rOrigPos,
108cdf0e10cSrcweir                         const SwPosition& rOrigStt,
109cdf0e10cSrcweir                         const SwPosition& rCpyStt,
110cdf0e10cSrcweir                         SwPosition& rChgPos,
111cdf0e10cSrcweir                         sal_uLong nDelCount )
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         sal_uLong nNdOff = rOrigPos.nNode.GetIndex();
114cdf0e10cSrcweir         nNdOff -= rOrigStt.nNode.GetIndex();
115cdf0e10cSrcweir         nNdOff -= nDelCount;
116cdf0e10cSrcweir         xub_StrLen nCntntPos = rOrigPos.nContent.GetIndex();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         // --> OD, AMA 2008-07-07 #b6713815#
119cdf0e10cSrcweir         // Always adjust <nNode> at to be changed <SwPosition> instance <rChgPos>
120cdf0e10cSrcweir         rChgPos.nNode = nNdOff + rCpyStt.nNode.GetIndex();
121cdf0e10cSrcweir         if( !nNdOff )
122cdf0e10cSrcweir         // <--
123cdf0e10cSrcweir         {
124cdf0e10cSrcweir             // dann nur den Content anpassen
125cdf0e10cSrcweir             if( nCntntPos > rOrigStt.nContent.GetIndex() )
126cdf0e10cSrcweir                 nCntntPos = nCntntPos - rOrigStt.nContent.GetIndex();
127cdf0e10cSrcweir             else
128cdf0e10cSrcweir                 nCntntPos = 0;
129cdf0e10cSrcweir             nCntntPos = nCntntPos + rCpyStt.nContent.GetIndex();
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir         rChgPos.nContent.Assign( rChgPos.nNode.GetNode().GetCntntNode(), nCntntPos );
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     // TODO: use SaveBookmark (from _DelBookmarks)
lcl_CopyBookmarks(const SwPaM & rPam,SwPaM & rCpyPam)135*dec99bbdSOliver-Rainer Wittmann     static void lcl_CopyBookmarks(
136*dec99bbdSOliver-Rainer Wittmann         const SwPaM& rPam,
137*dec99bbdSOliver-Rainer Wittmann         SwPaM& rCpyPam )
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         const SwDoc* pSrcDoc = rPam.GetDoc();
140cdf0e10cSrcweir         SwDoc* pDestDoc =  rCpyPam.GetDoc();
141cdf0e10cSrcweir         const IDocumentMarkAccess* const pSrcMarkAccess = pSrcDoc->getIDocumentMarkAccess();
142cdf0e10cSrcweir         ::sw::UndoGuard const undoGuard(pDestDoc->GetIDocumentUndoRedo());
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         const SwPosition &rStt = *rPam.Start(), &rEnd = *rPam.End();
145cdf0e10cSrcweir         SwPosition* pCpyStt = rCpyPam.Start();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         typedef ::std::vector< const ::sw::mark::IMark* > mark_vector_t;
148cdf0e10cSrcweir         mark_vector_t vMarksToCopy;
149*dec99bbdSOliver-Rainer Wittmann         for ( IDocumentMarkAccess::const_iterator_t ppMark = pSrcMarkAccess->getAllMarksBegin();
150*dec99bbdSOliver-Rainer Wittmann               ppMark != pSrcMarkAccess->getAllMarksEnd();
151cdf0e10cSrcweir               ppMark++ )
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             const ::sw::mark::IMark* const pMark = ppMark->get();
154*dec99bbdSOliver-Rainer Wittmann 
155cdf0e10cSrcweir             const SwPosition& rMarkStart = pMark->GetMarkStart();
156cdf0e10cSrcweir             const SwPosition& rMarkEnd = pMark->GetMarkEnd();
157*dec99bbdSOliver-Rainer Wittmann             // only include marks that are in the range and not touching both start and end
158*dec99bbdSOliver-Rainer Wittmann             // - not for annotation marks.
159*dec99bbdSOliver-Rainer Wittmann             const bool bIsNotOnBoundary =
160*dec99bbdSOliver-Rainer Wittmann                 pMark->IsExpanded()
161cdf0e10cSrcweir                 ? (rMarkStart != rStt || rMarkEnd != rEnd)  // rMarkStart != rMarkEnd
162cdf0e10cSrcweir                 : (rMarkStart != rStt && rMarkEnd != rEnd); // rMarkStart == rMarkEnd
163*dec99bbdSOliver-Rainer Wittmann             if ( rMarkStart >= rStt && rMarkEnd <= rEnd
164*dec99bbdSOliver-Rainer Wittmann                  && ( bIsNotOnBoundary
165*dec99bbdSOliver-Rainer Wittmann                       || IDocumentMarkAccess::GetType( *pMark ) == IDocumentMarkAccess::ANNOTATIONMARK ) )
166cdf0e10cSrcweir             {
167cdf0e10cSrcweir                 vMarksToCopy.push_back(pMark);
168cdf0e10cSrcweir             }
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir         // We have to count the "non-copied" nodes..
171cdf0e10cSrcweir         SwNodeIndex aCorrIdx(rStt.nNode);
172cdf0e10cSrcweir         sal_uLong nDelCount = 0;
173cdf0e10cSrcweir         for(mark_vector_t::const_iterator ppMark = vMarksToCopy.begin();
174cdf0e10cSrcweir             ppMark != vMarksToCopy.end();
175cdf0e10cSrcweir             ++ppMark)
176cdf0e10cSrcweir         {
177cdf0e10cSrcweir             const ::sw::mark::IMark* const pMark = *ppMark;
178cdf0e10cSrcweir             SwPaM aTmpPam(*pCpyStt);
179cdf0e10cSrcweir             lcl_NonCopyCount(rPam, aCorrIdx, pMark->GetMarkPos().nNode.GetIndex(), nDelCount);
180cdf0e10cSrcweir             lcl_SetCpyPos( pMark->GetMarkPos(), rStt, *pCpyStt, *aTmpPam.GetPoint(), nDelCount);
181cdf0e10cSrcweir             if(pMark->IsExpanded())
182cdf0e10cSrcweir             {
183cdf0e10cSrcweir                 aTmpPam.SetMark();
184cdf0e10cSrcweir                 lcl_NonCopyCount(rPam, aCorrIdx, pMark->GetOtherMarkPos().nNode.GetIndex(), nDelCount);
185cdf0e10cSrcweir                 lcl_SetCpyPos(pMark->GetOtherMarkPos(), rStt, *pCpyStt, *aTmpPam.GetMark(), nDelCount);
186cdf0e10cSrcweir             }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             ::sw::mark::IMark* const pNewMark = pDestDoc->getIDocumentMarkAccess()->makeMark(
189cdf0e10cSrcweir                 aTmpPam,
190cdf0e10cSrcweir                 pMark->GetName(),
191cdf0e10cSrcweir                 IDocumentMarkAccess::GetType(*pMark));
192cdf0e10cSrcweir             // Explicitly try to get exactly the same name as in the source
193cdf0e10cSrcweir             // because NavigatorReminders, DdeBookmarks etc. ignore the proposed name
194cdf0e10cSrcweir             pDestDoc->getIDocumentMarkAccess()->renameMark(pNewMark, pMark->GetName());
195cdf0e10cSrcweir             ::sw::mark::IBookmark* const pNewBookmark =
196cdf0e10cSrcweir                 dynamic_cast< ::sw::mark::IBookmark* const >(pNewMark);
197cdf0e10cSrcweir             if(pNewBookmark) /* copying additional attributes for bookmarks */
198cdf0e10cSrcweir             {
199cdf0e10cSrcweir                 const ::sw::mark::IBookmark* const pOldBookmark = dynamic_cast< const ::sw::mark::IBookmark* >(pMark);
200cdf0e10cSrcweir                 pNewBookmark->SetKeyCode(pOldBookmark->GetKeyCode());
201cdf0e10cSrcweir                 pNewBookmark->SetShortName(pOldBookmark->GetShortName());
202cdf0e10cSrcweir             }
203cdf0e10cSrcweir             ::sfx2::Metadatable const*const pMetadatable(
204cdf0e10cSrcweir                     dynamic_cast< ::sfx2::Metadatable const* >(pMark));
205cdf0e10cSrcweir             ::sfx2::Metadatable      *const pNewMetadatable(
206cdf0e10cSrcweir                     dynamic_cast< ::sfx2::Metadatable      * >(pNewMark));
207cdf0e10cSrcweir             if (pMetadatable && pNewMetadatable)
208cdf0e10cSrcweir             {
209cdf0e10cSrcweir                 pNewMetadatable->RegisterAsCopyOf(*pMetadatable);
210cdf0e10cSrcweir             }
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir // Struktur fuer das Mappen von alten und neuen Frame-Formaten an den
216cdf0e10cSrcweir // Boxen und Lines einer Tabelle
217cdf0e10cSrcweir 
218cdf0e10cSrcweir struct _MapTblFrmFmt
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	const SwFrmFmt *pOld, *pNew;
_MapTblFrmFmt_MapTblFrmFmt221cdf0e10cSrcweir 	_MapTblFrmFmt( const SwFrmFmt *pOldFmt, const SwFrmFmt*pNewFmt )
222cdf0e10cSrcweir 		: pOld( pOldFmt ), pNew( pNewFmt )
223cdf0e10cSrcweir 	{}
224cdf0e10cSrcweir };
225cdf0e10cSrcweir 
226cdf0e10cSrcweir SV_DECL_VARARR( _MapTblFrmFmts, _MapTblFrmFmt, 0, 10 )
227cdf0e10cSrcweir SV_IMPL_VARARR( _MapTblFrmFmts, _MapTblFrmFmt );
228cdf0e10cSrcweir 
MakeCopy(SwDoc * pDoc,const SwNodeIndex & rIdx) const229cdf0e10cSrcweir SwCntntNode* SwTxtNode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	// the Copy-Textnode is the Node with the Text, the Copy-Attrnode is the
232cdf0e10cSrcweir 	// node with the collection and hard attributes. Normally ist the same
233cdf0e10cSrcweir 	// node, but if insert a glossary without formatting, then the Attrnode
234cdf0e10cSrcweir 	// is the prev node of the destionation position in dest. document.
235cdf0e10cSrcweir 	SwTxtNode* pCpyTxtNd = (SwTxtNode*)this;
236cdf0e10cSrcweir 	SwTxtNode* pCpyAttrNd = pCpyTxtNd;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	// kopiere die Formate in das andere Dokument:
239cdf0e10cSrcweir 	SwTxtFmtColl* pColl = 0;
240cdf0e10cSrcweir 	if( pDoc->IsInsOnlyTextGlossary() )
241cdf0e10cSrcweir 	{
242cdf0e10cSrcweir 		SwNodeIndex aIdx( rIdx, -1 );
243cdf0e10cSrcweir 		if( aIdx.GetNode().IsTxtNode() )
244cdf0e10cSrcweir 		{
245cdf0e10cSrcweir 			pCpyAttrNd = aIdx.GetNode().GetTxtNode();
246cdf0e10cSrcweir 			pColl = &pCpyAttrNd->GetTxtColl()->GetNextTxtFmtColl();
247cdf0e10cSrcweir 		}
248cdf0e10cSrcweir 	}
249cdf0e10cSrcweir 	if( !pColl )
250cdf0e10cSrcweir 		pColl = pDoc->CopyTxtColl( *GetTxtColl() );
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	SwTxtNode* pTxtNd = pDoc->GetNodes().MakeTxtNode( rIdx, pColl );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     // METADATA: register copy
255cdf0e10cSrcweir     pTxtNd->RegisterAsCopyOf(*pCpyTxtNd);
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	// kopiere Attribute/Text
258cdf0e10cSrcweir     if( !pCpyAttrNd->HasSwAttrSet() )
259cdf0e10cSrcweir 		// wurde ein AttrSet fuer die Numerierung angelegt, so loesche diesen!
260cdf0e10cSrcweir 		pTxtNd->ResetAllAttr();
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 	// if Copy-Textnode unequal to Copy-Attrnode, then copy first
263cdf0e10cSrcweir 	// the attributes into the new Node.
264cdf0e10cSrcweir 	if( pCpyAttrNd != pCpyTxtNd )
265cdf0e10cSrcweir 	{
266cdf0e10cSrcweir 		pCpyAttrNd->CopyAttr( pTxtNd, 0, 0 );
267cdf0e10cSrcweir         if( pCpyAttrNd->HasSwAttrSet() )
268cdf0e10cSrcweir 		{
269cdf0e10cSrcweir 			SwAttrSet aSet( *pCpyAttrNd->GetpSwAttrSet() );
270cdf0e10cSrcweir 			aSet.ClearItem( RES_PAGEDESC );
271cdf0e10cSrcweir 			aSet.ClearItem( RES_BREAK );
272cdf0e10cSrcweir 			aSet.CopyToModify( *pTxtNd );
273cdf0e10cSrcweir 		}
274cdf0e10cSrcweir 	}
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 		// ??? reicht das ??? was ist mit PostIts/Feldern/FeldTypen ???
277cdf0e10cSrcweir     // --> OD 2008-11-18 #i96213# - force copy of all attributes
278cdf0e10cSrcweir     pCpyTxtNd->CopyText( pTxtNd, SwIndex( pCpyTxtNd ),
279cdf0e10cSrcweir         pCpyTxtNd->GetTxt().Len(), true );
280cdf0e10cSrcweir     // <--
281cdf0e10cSrcweir 
282cdf0e10cSrcweir //FEATURE::CONDCOLL
283cdf0e10cSrcweir 	if( RES_CONDTXTFMTCOLL == pColl->Which() )
284cdf0e10cSrcweir 		pTxtNd->ChkCondColl();
285cdf0e10cSrcweir //FEATURE::CONDCOLL
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	return pTxtNd;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
lcl_SrchNew(const _MapTblFrmFmt & rMap,void * pPara)291cdf0e10cSrcweir sal_Bool lcl_SrchNew( const _MapTblFrmFmt& rMap, void * pPara )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir 	if( rMap.pOld != *(const SwFrmFmt**)pPara )
294cdf0e10cSrcweir 		return sal_True;
295cdf0e10cSrcweir 	*((const SwFrmFmt**)pPara) = rMap.pNew;
296cdf0e10cSrcweir 	return sal_False;		// abbrechen, Pointer gefunden
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 
300cdf0e10cSrcweir struct _CopyTable
301cdf0e10cSrcweir {
302cdf0e10cSrcweir 	SwDoc* pDoc;
303cdf0e10cSrcweir 	sal_uLong nOldTblSttIdx;
304cdf0e10cSrcweir 	_MapTblFrmFmts& rMapArr;
305cdf0e10cSrcweir 	SwTableLine* pInsLine;
306cdf0e10cSrcweir 	SwTableBox* pInsBox;
307cdf0e10cSrcweir 	SwTableNode *pTblNd;
308cdf0e10cSrcweir 	const SwTable *pOldTable;
309cdf0e10cSrcweir 
_CopyTable_CopyTable310cdf0e10cSrcweir 	_CopyTable( SwDoc* pDc, _MapTblFrmFmts& rArr, sal_uLong nOldStt,
311cdf0e10cSrcweir 				SwTableNode& rTblNd, const SwTable* pOldTbl )
312cdf0e10cSrcweir 		: pDoc(pDc), nOldTblSttIdx(nOldStt), rMapArr(rArr),
313cdf0e10cSrcweir         pInsLine(0), pInsBox(0), pTblNd(&rTblNd), pOldTable( pOldTbl )
314cdf0e10cSrcweir 	{}
315cdf0e10cSrcweir };
316cdf0e10cSrcweir 
317cdf0e10cSrcweir sal_Bool lcl_CopyTblBox( const SwTableBox*& rpBox, void* pPara );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir sal_Bool lcl_CopyTblLine( const SwTableLine*& rpLine, void* pPara );
320cdf0e10cSrcweir 
lcl_CopyTblBox(const SwTableBox * & rpBox,void * pPara)321cdf0e10cSrcweir sal_Bool lcl_CopyTblBox( const SwTableBox*& rpBox, void* pPara )
322cdf0e10cSrcweir {
323cdf0e10cSrcweir 	_CopyTable* pCT = (_CopyTable*)pPara;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)rpBox->GetFrmFmt();
326cdf0e10cSrcweir 	pCT->rMapArr.ForEach( lcl_SrchNew, &pBoxFmt );
327cdf0e10cSrcweir 	if( pBoxFmt == rpBox->GetFrmFmt() )	// ein neues anlegen ??
328cdf0e10cSrcweir 	{
329cdf0e10cSrcweir 		const SfxPoolItem* pItem;
330cdf0e10cSrcweir 		if( SFX_ITEM_SET == pBoxFmt->GetItemState( RES_BOXATR_FORMULA, sal_False,
331cdf0e10cSrcweir 			&pItem ) && ((SwTblBoxFormula*)pItem)->IsIntrnlName() )
332cdf0e10cSrcweir 		{
333cdf0e10cSrcweir 			((SwTblBoxFormula*)pItem)->PtrToBoxNm( pCT->pOldTable );
334cdf0e10cSrcweir 		}
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 		pBoxFmt = pCT->pDoc->MakeTableBoxFmt();
337cdf0e10cSrcweir 		pBoxFmt->CopyAttrs( *rpBox->GetFrmFmt() );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 		if( rpBox->GetSttIdx() )
340cdf0e10cSrcweir 		{
341cdf0e10cSrcweir 			SvNumberFormatter* pN = pCT->pDoc->GetNumberFormatter( sal_False );
342cdf0e10cSrcweir 			if( pN && pN->HasMergeFmtTbl() && SFX_ITEM_SET == pBoxFmt->
343cdf0e10cSrcweir 				GetItemState( RES_BOXATR_FORMAT, sal_False, &pItem ) )
344cdf0e10cSrcweir 			{
345cdf0e10cSrcweir 				sal_uLong nOldIdx = ((SwTblBoxNumFormat*)pItem)->GetValue();
346cdf0e10cSrcweir 				sal_uLong nNewIdx = pN->GetMergeFmtIndex( nOldIdx );
347cdf0e10cSrcweir 				if( nNewIdx != nOldIdx )
348cdf0e10cSrcweir                     pBoxFmt->SetFmtAttr( SwTblBoxNumFormat( nNewIdx ));
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 			}
351cdf0e10cSrcweir 		}
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 		pCT->rMapArr.Insert( _MapTblFrmFmt( rpBox->GetFrmFmt(), pBoxFmt ),
354cdf0e10cSrcweir 								pCT->rMapArr.Count() );
355cdf0e10cSrcweir 	}
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 	sal_uInt16 nLines = rpBox->GetTabLines().Count();
358cdf0e10cSrcweir 	SwTableBox* pNewBox;
359cdf0e10cSrcweir 	if( nLines )
360cdf0e10cSrcweir 		pNewBox = new SwTableBox( pBoxFmt, nLines, pCT->pInsLine );
361cdf0e10cSrcweir 	else
362cdf0e10cSrcweir 	{
363a2e27fc1SJian Hong Cheng 		//Modified for i119955,2012.6.13
364a2e27fc1SJian Hong Cheng 		//Avoid overflow problem...
365a2e27fc1SJian Hong Cheng 		int nIn = rpBox->GetSttIdx() - pCT->nOldTblSttIdx;
366a2e27fc1SJian Hong Cheng 		if ( nIn > 0 )
367a2e27fc1SJian Hong Cheng 		{
368a2e27fc1SJian Hong Cheng 		//End
369cdf0e10cSrcweir 		SwNodeIndex aNewIdx( *pCT->pTblNd,
370cdf0e10cSrcweir 							rpBox->GetSttIdx() - pCT->nOldTblSttIdx );
371cdf0e10cSrcweir 		ASSERT( aNewIdx.GetNode().IsStartNode(), "Index nicht auf einem StartNode" );
372cdf0e10cSrcweir 		pNewBox = new SwTableBox( pBoxFmt, aNewIdx, pCT->pInsLine );
373cdf0e10cSrcweir         pNewBox->setRowSpan( rpBox->getRowSpan() );
374a2e27fc1SJian Hong Cheng 		//Modified for i119955,2012.6.13
375a2e27fc1SJian Hong Cheng 		}else
376a2e27fc1SJian Hong Cheng 		{
377a2e27fc1SJian Hong Cheng 			return sal_False;
378a2e27fc1SJian Hong Cheng 		}
379a2e27fc1SJian Hong Cheng 		//End
380cdf0e10cSrcweir 	}
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 	pCT->pInsLine->GetTabBoxes().C40_INSERT( SwTableBox, pNewBox,
383cdf0e10cSrcweir 					pCT->pInsLine->GetTabBoxes().Count() );
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	if( nLines )
386cdf0e10cSrcweir 	{
387cdf0e10cSrcweir 		_CopyTable aPara( *pCT );
388cdf0e10cSrcweir 		aPara.pInsBox = pNewBox;
389cdf0e10cSrcweir 		((SwTableBox*)rpBox)->GetTabLines().ForEach( &lcl_CopyTblLine, &aPara );
390cdf0e10cSrcweir 	}
391cdf0e10cSrcweir 	else if( pNewBox->IsInHeadline( &pCT->pTblNd->GetTable() ))
392cdf0e10cSrcweir 		// in der HeadLine sind die Absaetze mit BedingtenVorlage anzupassen
393cdf0e10cSrcweir 		pNewBox->GetSttNd()->CheckSectionCondColl();
394cdf0e10cSrcweir 	return sal_True;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
lcl_CopyTblLine(const SwTableLine * & rpLine,void * pPara)397cdf0e10cSrcweir sal_Bool lcl_CopyTblLine( const SwTableLine*& rpLine, void* pPara )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir 	_CopyTable* pCT = (_CopyTable*)pPara;
400cdf0e10cSrcweir 	SwTableLineFmt* pLineFmt = (SwTableLineFmt*)rpLine->GetFrmFmt();
401cdf0e10cSrcweir 	pCT->rMapArr.ForEach( lcl_SrchNew, &pLineFmt );
402cdf0e10cSrcweir 	if( pLineFmt == rpLine->GetFrmFmt() )	// ein neues anlegen ??
403cdf0e10cSrcweir 	{
404cdf0e10cSrcweir 		pLineFmt = pCT->pDoc->MakeTableLineFmt();
405cdf0e10cSrcweir 		pLineFmt->CopyAttrs( *rpLine->GetFrmFmt() );
406cdf0e10cSrcweir 		pCT->rMapArr.Insert( _MapTblFrmFmt( rpLine->GetFrmFmt(), pLineFmt ),
407cdf0e10cSrcweir 								pCT->rMapArr.Count());
408cdf0e10cSrcweir 	}
409cdf0e10cSrcweir 	SwTableLine* pNewLine = new SwTableLine( pLineFmt,
410cdf0e10cSrcweir 							rpLine->GetTabBoxes().Count(), pCT->pInsBox );
411cdf0e10cSrcweir 	// die neue Zeile in die Tabelle eintragen
412cdf0e10cSrcweir 	if( pCT->pInsBox )
413cdf0e10cSrcweir 	{
414cdf0e10cSrcweir 		pCT->pInsBox->GetTabLines().C40_INSERT( SwTableLine, pNewLine,
415cdf0e10cSrcweir 				pCT->pInsBox->GetTabLines().Count() );
416cdf0e10cSrcweir 	}
417cdf0e10cSrcweir 	else
418cdf0e10cSrcweir 	{
419cdf0e10cSrcweir 		pCT->pTblNd->GetTable().GetTabLines().C40_INSERT( SwTableLine, pNewLine,
420cdf0e10cSrcweir 				pCT->pTblNd->GetTable().GetTabLines().Count() );
421cdf0e10cSrcweir 	}
422cdf0e10cSrcweir 	pCT->pInsLine = pNewLine;
423cdf0e10cSrcweir 	((SwTableLine*)rpLine)->GetTabBoxes().ForEach( &lcl_CopyTblBox, pCT );
424cdf0e10cSrcweir 	return sal_True;
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
MakeCopy(SwDoc * pDoc,const SwNodeIndex & rIdx) const427cdf0e10cSrcweir SwTableNode* SwTableNode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
428cdf0e10cSrcweir {
429cdf0e10cSrcweir 	// in welchen Array steht ich denn Nodes, UndoNodes ??
430cdf0e10cSrcweir 	SwNodes& rNds = (SwNodes&)GetNodes();
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	{
433cdf0e10cSrcweir 		// nicht in Fussnoten kopieren !!
434cdf0e10cSrcweir /*
435cdf0e10cSrcweir !! Mal ohne Frames
436cdf0e10cSrcweir 		SwCntntNode* pCNd = pDoc->GetNodes()[ rIdx ]->GetCntntNode();
437cdf0e10cSrcweir 		SwFrm* pFrm;
438cdf0e10cSrcweir 		if( (pCNd && 0 != ( pFrm = pCNd->GetFrm()))
439cdf0e10cSrcweir 				? pFrm->FindFtnFrm()
440cdf0e10cSrcweir 				: rIdx < pDoc->GetNodes().EndOfInserts &&
441cdf0e10cSrcweir 					pDoc->GetNodes()[pDoc->GetNodes().EndOfInserts]->StartOfSection()
442cdf0e10cSrcweir 					< rIdx )
443cdf0e10cSrcweir */
444cdf0e10cSrcweir 		if( rIdx < pDoc->GetNodes().GetEndOfInserts().GetIndex() &&
445cdf0e10cSrcweir 			rIdx >= pDoc->GetNodes().GetEndOfInserts().StartOfSectionIndex() )
446cdf0e10cSrcweir 			return 0;
447cdf0e10cSrcweir 	}
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	// das TableFrmFmt kopieren
450cdf0e10cSrcweir 	String sTblName( GetTable().GetFrmFmt()->GetName() );
451cdf0e10cSrcweir 	if( !pDoc->IsCopyIsMove() )
452cdf0e10cSrcweir 	{
453cdf0e10cSrcweir 		const SwFrmFmts& rTblFmts = *pDoc->GetTblFrmFmts();
454cdf0e10cSrcweir 		for( sal_uInt16 n = rTblFmts.Count(); n; )
455cdf0e10cSrcweir 			if( rTblFmts[ --n ]->GetName() == sTblName )
456cdf0e10cSrcweir 			{
457cdf0e10cSrcweir 				sTblName = pDoc->GetUniqueTblName();
458cdf0e10cSrcweir 				break;
459cdf0e10cSrcweir 			}
460cdf0e10cSrcweir 	}
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 	SwFrmFmt* pTblFmt = pDoc->MakeTblFrmFmt( sTblName, pDoc->GetDfltFrmFmt() );
463cdf0e10cSrcweir 	pTblFmt->CopyAttrs( *GetTable().GetFrmFmt() );
464cdf0e10cSrcweir 	SwTableNode* pTblNd = new SwTableNode( rIdx );
465cdf0e10cSrcweir 	SwEndNode* pEndNd = new SwEndNode( rIdx, *pTblNd );
466cdf0e10cSrcweir 	SwNodeIndex aInsPos( *pEndNd );
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 	SwTable& rTbl = (SwTable&)pTblNd->GetTable();
469cdf0e10cSrcweir     rTbl.RegisterToFormat( *pTblFmt );
470cdf0e10cSrcweir 
471cdf0e10cSrcweir     rTbl.SetRowsToRepeat( GetTable().GetRowsToRepeat() );
472cdf0e10cSrcweir 	rTbl.SetTblChgMode( GetTable().GetTblChgMode() );
473cdf0e10cSrcweir 	rTbl.SetTableModel( GetTable().IsNewModel() );
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 	SwDDEFieldType* pDDEType = 0;
476cdf0e10cSrcweir 	if( IS_TYPE( SwDDETable, &GetTable() ))
477cdf0e10cSrcweir 	{
478cdf0e10cSrcweir 		// es wird eine DDE-Tabelle kopiert
479cdf0e10cSrcweir 		// ist im neuen Dokument ueberhaupt der FeldTyp vorhanden ?
480cdf0e10cSrcweir 		pDDEType = ((SwDDETable&)GetTable()).GetDDEFldType();
481cdf0e10cSrcweir 		if( pDDEType->IsDeleted() )
482cdf0e10cSrcweir 			pDoc->InsDeletedFldType( *pDDEType );
483cdf0e10cSrcweir 		else
484cdf0e10cSrcweir 			pDDEType = (SwDDEFieldType*)pDoc->InsertFldType( *pDDEType );
485cdf0e10cSrcweir 		ASSERT( pDDEType, "unbekannter FieldType" );
486cdf0e10cSrcweir 
487cdf0e10cSrcweir 		// tauschen am Node den Tabellen-Pointer aus
488cdf0e10cSrcweir 		SwDDETable* pNewTable = new SwDDETable( pTblNd->GetTable(), pDDEType );
489cdf0e10cSrcweir 		pTblNd->SetNewTable( pNewTable, sal_False );
490cdf0e10cSrcweir 	}
491cdf0e10cSrcweir 	// dann kopiere erstmal den Inhalt der Tabelle, die Zuordnung der
492cdf0e10cSrcweir 	// Boxen/Lines und das anlegen der Frames erfolgt spaeter
493cdf0e10cSrcweir 	SwNodeRange aRg( *this, +1, *EndOfSectionNode() );	// (wo stehe in denn nun ??)
494cdf0e10cSrcweir 
495cdf0e10cSrcweir     // If there is a table in this table, the table format for the outer table
496cdf0e10cSrcweir     // does not seem to be used, because the table does not have any contents yet
497cdf0e10cSrcweir     // (see IsUsed). Therefore the inner table gets the same name as the outer table.
498cdf0e10cSrcweir     // We have to make sure that the table node of the SwTable is accessible, even
499cdf0e10cSrcweir     // without any content in aSortCntBoxes. #i26629#
500cdf0e10cSrcweir     pTblNd->GetTable().SetTableNode( pTblNd );
501cdf0e10cSrcweir     rNds._Copy( aRg, aInsPos, sal_False );
502cdf0e10cSrcweir     pTblNd->GetTable().SetTableNode( 0 );
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	// Sonderbehandlung fuer eine einzelne Box
505cdf0e10cSrcweir 	if( 1 == GetTable().GetTabSortBoxes().Count() )
506cdf0e10cSrcweir 	{
507cdf0e10cSrcweir 		aRg.aStart.Assign( *pTblNd, 1 );
508cdf0e10cSrcweir 		aRg.aEnd.Assign( *pTblNd->EndOfSectionNode() );
509cdf0e10cSrcweir 		pDoc->GetNodes().SectionDown( &aRg, SwTableBoxStartNode );
510cdf0e10cSrcweir 	}
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 	// loesche alle Frames vom kopierten Bereich, diese werden beim
513cdf0e10cSrcweir 	// erzeugen des TableFrames angelegt !
514cdf0e10cSrcweir 	pTblNd->DelFrms();
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 	_MapTblFrmFmts aMapArr;
517cdf0e10cSrcweir 	_CopyTable aPara( pDoc, aMapArr, GetIndex(), *pTblNd, &GetTable() );
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 	((SwTable&)GetTable()).GetTabLines().ForEach( &lcl_CopyTblLine, &aPara );
520cdf0e10cSrcweir 
521cdf0e10cSrcweir     if( pDDEType )
522cdf0e10cSrcweir 		pDDEType->IncRefCnt();
523cdf0e10cSrcweir 
524cdf0e10cSrcweir     CHECK_TABLE( GetTable() );
525cdf0e10cSrcweir 	return pTblNd;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
CopyCollFmt(SwTxtNode & rDestNd)528cdf0e10cSrcweir void SwTxtNode::CopyCollFmt( SwTxtNode& rDestNd )
529cdf0e10cSrcweir {
530cdf0e10cSrcweir 	// kopiere die Formate in das andere Dokument:
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 	// Sonderbehandlung fuer PageBreak/PageDesc/ColBrk
533cdf0e10cSrcweir 	SwDoc* pDestDoc = rDestNd.GetDoc();
534cdf0e10cSrcweir 	SwAttrSet aPgBrkSet( pDestDoc->GetAttrPool(), aBreakSetRange );
535cdf0e10cSrcweir     const SwAttrSet* pSet;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     if( 0 != ( pSet = rDestNd.GetpSwAttrSet() ) )
538cdf0e10cSrcweir 	{
539cdf0e10cSrcweir 		// Sonderbehandlung fuer unsere Break-Attribute
540cdf0e10cSrcweir 		const SfxPoolItem* pAttr;
541cdf0e10cSrcweir 		if( SFX_ITEM_SET == pSet->GetItemState( RES_BREAK, sal_False, &pAttr ) )
542cdf0e10cSrcweir 			aPgBrkSet.Put( *pAttr );
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 		if( SFX_ITEM_SET == pSet->GetItemState( RES_PAGEDESC, sal_False, &pAttr ) )
545cdf0e10cSrcweir 			aPgBrkSet.Put( *pAttr );
546cdf0e10cSrcweir 	}
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 	rDestNd.ChgFmtColl( pDestDoc->CopyTxtColl( *GetTxtColl() ));
549cdf0e10cSrcweir     if( 0 != ( pSet = GetpSwAttrSet() ) )
550cdf0e10cSrcweir 		pSet->CopyToModify( rDestNd );
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 	if( aPgBrkSet.Count() )
553cdf0e10cSrcweir         rDestNd.SetAttr( aPgBrkSet );
554cdf0e10cSrcweir }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 
557cdf0e10cSrcweir //  ----- Copy-Methode vom SwDoc ------
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 	// verhinder das Kopieren in Fly's, die im Bereich verankert sind.
lcl_ChkFlyFly(SwDoc * pDoc,sal_uLong nSttNd,sal_uLong nEndNd,sal_uLong nInsNd)560cdf0e10cSrcweir sal_Bool lcl_ChkFlyFly( SwDoc* pDoc, sal_uLong nSttNd, sal_uLong nEndNd,
561cdf0e10cSrcweir 						sal_uLong nInsNd )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir 	const SwSpzFrmFmts& rFrmFmtTbl = *pDoc->GetSpzFrmFmts();
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < rFrmFmtTbl.Count(); ++n )
566cdf0e10cSrcweir 	{
567cdf0e10cSrcweir         SwFrmFmt const*const  pFmt = rFrmFmtTbl[n];
568cdf0e10cSrcweir         SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
569cdf0e10cSrcweir         SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
570cdf0e10cSrcweir         if (pAPos &&
571cdf0e10cSrcweir             ((FLY_AS_CHAR == pAnchor->GetAnchorId()) ||
572cdf0e10cSrcweir              (FLY_AT_CHAR == pAnchor->GetAnchorId()) ||
573cdf0e10cSrcweir              (FLY_AT_FLY  == pAnchor->GetAnchorId()) ||
574cdf0e10cSrcweir              (FLY_AT_PARA == pAnchor->GetAnchorId())) &&
575cdf0e10cSrcweir 			nSttNd <= pAPos->nNode.GetIndex() &&
576cdf0e10cSrcweir 			pAPos->nNode.GetIndex() < nEndNd )
577cdf0e10cSrcweir 		{
578cdf0e10cSrcweir 			const SwFmtCntnt& rCntnt = pFmt->GetCntnt();
579cdf0e10cSrcweir 			SwStartNode* pSNd;
580cdf0e10cSrcweir 			if( !rCntnt.GetCntntIdx() ||
581cdf0e10cSrcweir 				0 == ( pSNd = rCntnt.GetCntntIdx()->GetNode().GetStartNode() ))
582cdf0e10cSrcweir 				continue;
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 			if( pSNd->GetIndex() < nInsNd &&
585cdf0e10cSrcweir 				nInsNd < pSNd->EndOfSectionIndex() )
586cdf0e10cSrcweir 				return sal_True;		// nicht kopieren !!
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 			if( lcl_ChkFlyFly( pDoc, pSNd->GetIndex(),
589cdf0e10cSrcweir 						pSNd->EndOfSectionIndex(), nInsNd ) )
590cdf0e10cSrcweir 				return sal_True;		// nicht kopieren !!
591cdf0e10cSrcweir 		}
592cdf0e10cSrcweir 	}
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 	return sal_False;
595cdf0e10cSrcweir }
596cdf0e10cSrcweir 
lcl_DeleteRedlines(const SwPaM & rPam,SwPaM & rCpyPam)597cdf0e10cSrcweir void lcl_DeleteRedlines( const SwPaM& rPam, SwPaM& rCpyPam )
598cdf0e10cSrcweir {
599cdf0e10cSrcweir 	const SwDoc* pSrcDoc = rPam.GetDoc();
600cdf0e10cSrcweir 	const SwRedlineTbl& rTbl = pSrcDoc->GetRedlineTbl();
601cdf0e10cSrcweir 	if( rTbl.Count() )
602cdf0e10cSrcweir 	{
603cdf0e10cSrcweir 		SwDoc* pDestDoc = rCpyPam.GetDoc();
604cdf0e10cSrcweir 		SwPosition* pCpyStt = rCpyPam.Start(), *pCpyEnd = rCpyPam.End();
605cdf0e10cSrcweir 		SwPaM* pDelPam = 0;
606cdf0e10cSrcweir 		const SwPosition *pStt = rPam.Start(), *pEnd = rPam.End();
607cdf0e10cSrcweir         // We have to count the "non-copied" nodes
608cdf0e10cSrcweir         sal_uLong nDelCount = 0;
609cdf0e10cSrcweir         SwNodeIndex aCorrIdx( pStt->nNode );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 		sal_uInt16 n = 0;
612cdf0e10cSrcweir 		pSrcDoc->GetRedline( *pStt, &n );
613cdf0e10cSrcweir 		for( ; n < rTbl.Count(); ++n )
614cdf0e10cSrcweir 		{
615cdf0e10cSrcweir 			const SwRedline* pRedl = rTbl[ n ];
616cdf0e10cSrcweir 			if( nsRedlineType_t::REDLINE_DELETE == pRedl->GetType() && pRedl->IsVisible() )
617cdf0e10cSrcweir 			{
618cdf0e10cSrcweir 				const SwPosition *pRStt = pRedl->Start(), *pREnd = pRedl->End();
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 				SwComparePosition eCmpPos = ComparePosition( *pStt, *pEnd, *pRStt, *pREnd );
621cdf0e10cSrcweir 				switch( eCmpPos )
622cdf0e10cSrcweir 				{
623cdf0e10cSrcweir 				case POS_COLLIDE_END:
624cdf0e10cSrcweir 				case POS_BEFORE:				// Pos1 liegt vor Pos2
625cdf0e10cSrcweir 					break;
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 				case POS_COLLIDE_START:
628cdf0e10cSrcweir 				case POS_BEHIND:				// Pos1 liegt hinter Pos2
629cdf0e10cSrcweir 					n = rTbl.Count();
630cdf0e10cSrcweir 					break;
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 				default:
633cdf0e10cSrcweir 					{
634cdf0e10cSrcweir 						pDelPam = new SwPaM( *pCpyStt, pDelPam );
635cdf0e10cSrcweir 						if( *pStt < *pRStt )
636cdf0e10cSrcweir                         {
637cdf0e10cSrcweir                             lcl_NonCopyCount( rPam, aCorrIdx, pRStt->nNode.GetIndex(), nDelCount );
638cdf0e10cSrcweir 							lcl_SetCpyPos( *pRStt, *pStt, *pCpyStt,
639cdf0e10cSrcweir 											*pDelPam->GetPoint(), nDelCount );
640cdf0e10cSrcweir                         }
641cdf0e10cSrcweir 						pDelPam->SetMark();
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 						if( *pEnd < *pREnd )
644cdf0e10cSrcweir 							*pDelPam->GetPoint() = *pCpyEnd;
645cdf0e10cSrcweir 						else
646cdf0e10cSrcweir                         {
647cdf0e10cSrcweir                             lcl_NonCopyCount( rPam, aCorrIdx, pREnd->nNode.GetIndex(), nDelCount );
648cdf0e10cSrcweir 							lcl_SetCpyPos( *pREnd, *pStt, *pCpyStt,
649cdf0e10cSrcweir 											*pDelPam->GetPoint(), nDelCount );
650cdf0e10cSrcweir                         }
651cdf0e10cSrcweir 					}
652cdf0e10cSrcweir 				}
653cdf0e10cSrcweir 			}
654cdf0e10cSrcweir 		}
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 		if( pDelPam )
657cdf0e10cSrcweir 		{
658cdf0e10cSrcweir 			RedlineMode_t eOld = pDestDoc->GetRedlineMode();
659cdf0e10cSrcweir 			pDestDoc->SetRedlineMode_intern( (RedlineMode_t)(eOld | nsRedlineMode_t::REDLINE_IGNORE));
660cdf0e10cSrcweir 
661cdf0e10cSrcweir             ::sw::UndoGuard const undoGuard(pDestDoc->GetIDocumentUndoRedo());
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 			do {
664cdf0e10cSrcweir 				pDestDoc->DeleteAndJoin( *(SwPaM*)pDelPam->GetNext() );
665cdf0e10cSrcweir 				if( pDelPam->GetNext() == pDelPam )
666cdf0e10cSrcweir 					break;
667cdf0e10cSrcweir 				delete pDelPam->GetNext();
668cdf0e10cSrcweir 			} while( sal_True );
669cdf0e10cSrcweir 			delete pDelPam;
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 			pDestDoc->SetRedlineMode_intern( eOld );
672cdf0e10cSrcweir 		}
673cdf0e10cSrcweir 	}
674cdf0e10cSrcweir }
675cdf0e10cSrcweir 
lcl_DeleteRedlines(const SwNodeRange & rRg,SwNodeRange & rCpyRg)676cdf0e10cSrcweir void lcl_DeleteRedlines( const SwNodeRange& rRg, SwNodeRange& rCpyRg )
677cdf0e10cSrcweir {
678cdf0e10cSrcweir 	SwDoc* pSrcDoc = rRg.aStart.GetNode().GetDoc();
679cdf0e10cSrcweir 	if( pSrcDoc->GetRedlineTbl().Count() )
680cdf0e10cSrcweir 	{
681cdf0e10cSrcweir 		SwPaM aRgTmp( rRg.aStart, rRg.aEnd );
682cdf0e10cSrcweir 		SwPaM aCpyTmp( rCpyRg.aStart, rCpyRg.aEnd );
683cdf0e10cSrcweir 		lcl_DeleteRedlines( aRgTmp, aCpyTmp );
684cdf0e10cSrcweir 	}
685cdf0e10cSrcweir }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir // Kopieren eines Bereiches im oder in ein anderes Dokument !
688cdf0e10cSrcweir 
689cdf0e10cSrcweir bool
CopyRange(SwPaM & rPam,SwPosition & rPos,const bool bCopyAll) const690cdf0e10cSrcweir SwDoc::CopyRange( SwPaM& rPam, SwPosition& rPos, const bool bCopyAll ) const
691cdf0e10cSrcweir {
692cdf0e10cSrcweir 	const SwPosition *pStt = rPam.Start(), *pEnd = rPam.End();
693cdf0e10cSrcweir 
694cdf0e10cSrcweir 	SwDoc* pDoc = rPos.nNode.GetNode().GetDoc();
695cdf0e10cSrcweir     bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection();
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 	// kein Copy abfangen.
698cdf0e10cSrcweir 	if( !rPam.HasMark() || ( *pStt >= *pEnd && !bColumnSel ) )
699cdf0e10cSrcweir         return false;
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 	// verhinder das Kopieren in Fly's, die im Bereich verankert sind.
702cdf0e10cSrcweir 	if( pDoc == this )
703cdf0e10cSrcweir 	{
704cdf0e10cSrcweir 		// Start-/EndNode noch korrigieren
705cdf0e10cSrcweir 		sal_uLong nStt = pStt->nNode.GetIndex(),
706cdf0e10cSrcweir 				nEnd = pEnd->nNode.GetIndex(),
707cdf0e10cSrcweir 				nDiff = nEnd - nStt +1;
708cdf0e10cSrcweir 		SwNode* pNd = GetNodes()[ nStt ];
709cdf0e10cSrcweir 		if( pNd->IsCntntNode() && pStt->nContent.GetIndex() )
710cdf0e10cSrcweir 			++nStt, --nDiff;
711cdf0e10cSrcweir 		if( (pNd = GetNodes()[ nEnd ])->IsCntntNode() &&
712cdf0e10cSrcweir 			((SwCntntNode*)pNd)->Len() != pEnd->nContent.GetIndex() )
713cdf0e10cSrcweir 			--nEnd, --nDiff;
714cdf0e10cSrcweir 		if( nDiff &&
715cdf0e10cSrcweir 			lcl_ChkFlyFly( pDoc, nStt, nEnd, rPos.nNode.GetIndex() ) )
716cdf0e10cSrcweir         {
717cdf0e10cSrcweir             return false;
718cdf0e10cSrcweir         }
719cdf0e10cSrcweir 	}
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 	SwPaM* pRedlineRange = 0;
722cdf0e10cSrcweir 	if( pDoc->IsRedlineOn() ||
723cdf0e10cSrcweir 		(!pDoc->IsIgnoreRedline() && pDoc->GetRedlineTbl().Count() ) )
724cdf0e10cSrcweir 		pRedlineRange = new SwPaM( rPos );
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 	RedlineMode_t eOld = pDoc->GetRedlineMode();
727cdf0e10cSrcweir 
728cdf0e10cSrcweir     bool bRet = false;
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 	if( pDoc != this )
731cdf0e10cSrcweir     {   // ordinary copy
732cdf0e10cSrcweir         bRet = CopyImpl( rPam, rPos, true, bCopyAll, pRedlineRange );
733cdf0e10cSrcweir     }
734cdf0e10cSrcweir 	// Copy in sich selbst (ueber mehrere Nodes wird hier gesondert
735cdf0e10cSrcweir 	// behandelt; in einem TextNode wird normal behandelt)
736cdf0e10cSrcweir 	else if( ! ( *pStt <= rPos && rPos < *pEnd &&
737cdf0e10cSrcweir 			( pStt->nNode != pEnd->nNode ||
738cdf0e10cSrcweir 			  !pStt->nNode.GetNode().IsTxtNode() )) )
739cdf0e10cSrcweir     {   // ordinary copy
740cdf0e10cSrcweir         bRet = CopyImpl( rPam, rPos, true, bCopyAll, pRedlineRange );
741cdf0e10cSrcweir     }
742cdf0e10cSrcweir 	else
743cdf0e10cSrcweir 	{
744cdf0e10cSrcweir 		ASSERT( this == pDoc, " falscher Copy-Zweig!" );
745cdf0e10cSrcweir         ASSERT(false, "mst: i thought this could be dead code;"
746cdf0e10cSrcweir                 "please tell me what you did to get here!");
747cdf0e10cSrcweir 		pDoc->SetRedlineMode_intern((RedlineMode_t)(eOld | nsRedlineMode_t::REDLINE_IGNORE));
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 		// dann kopiere den Bereich im unteren DokumentBereich,
750cdf0e10cSrcweir 		// (mit Start/End-Nodes geklammert) und verschiebe diese
751cdf0e10cSrcweir 		// dann an die gewuenschte Stelle.
752cdf0e10cSrcweir 
753cdf0e10cSrcweir         SwUndoCpyDoc* pUndo = 0;
754cdf0e10cSrcweir 		SwPaM aPam( rPos );			// UndoBereich sichern
755cdf0e10cSrcweir         if (pDoc->GetIDocumentUndoRedo().DoesUndo())
756cdf0e10cSrcweir         {
757cdf0e10cSrcweir             pDoc->GetIDocumentUndoRedo().ClearRedo();
758cdf0e10cSrcweir 			pUndo = new SwUndoCpyDoc( aPam );
759cdf0e10cSrcweir 		}
760cdf0e10cSrcweir 
761cdf0e10cSrcweir         {
762cdf0e10cSrcweir             ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
763cdf0e10cSrcweir             SwStartNode* pSttNd = pDoc->GetNodes().MakeEmptySection(
764cdf0e10cSrcweir                                 SwNodeIndex( GetNodes().GetEndOfAutotext() ));
765cdf0e10cSrcweir             aPam.GetPoint()->nNode = *pSttNd->EndOfSectionNode();
766cdf0e10cSrcweir             // copy without Frames
767cdf0e10cSrcweir             pDoc->CopyImpl( rPam, *aPam.GetPoint(), false, bCopyAll, 0 );
768cdf0e10cSrcweir 
769cdf0e10cSrcweir             aPam.GetPoint()->nNode = pDoc->GetNodes().GetEndOfAutotext();
770cdf0e10cSrcweir             aPam.SetMark();
771cdf0e10cSrcweir             SwCntntNode* pNode =
772cdf0e10cSrcweir                 pDoc->GetNodes().GoPrevious( &aPam.GetMark()->nNode );
773cdf0e10cSrcweir             pNode->MakeEndIndex( &aPam.GetMark()->nContent );
774cdf0e10cSrcweir 
775cdf0e10cSrcweir             aPam.GetPoint()->nNode = *aPam.GetNode()->StartOfSectionNode();
776cdf0e10cSrcweir             pNode = pDoc->GetNodes().GoNext( &aPam.GetPoint()->nNode );
777cdf0e10cSrcweir             pNode->MakeStartIndex( &aPam.GetPoint()->nContent );
778cdf0e10cSrcweir             // move to desired position
779cdf0e10cSrcweir             pDoc->MoveRange( aPam, rPos, DOC_MOVEDEFAULT );
780cdf0e10cSrcweir 
781cdf0e10cSrcweir             pNode = aPam.GetCntntNode();
782cdf0e10cSrcweir             *aPam.GetPoint() = rPos;        // Cursor umsetzen fuers Undo !
783cdf0e10cSrcweir             aPam.SetMark();                 // auch den Mark umsetzen !!
784cdf0e10cSrcweir             aPam.DeleteMark();              // aber keinen Bereich makieren !!
785cdf0e10cSrcweir             pDoc->DeleteSection( pNode );           // Bereich wieder loeschen
786cdf0e10cSrcweir         }
787cdf0e10cSrcweir 
788cdf0e10cSrcweir         // if Undo is enabled, store the insertion range
789cdf0e10cSrcweir         if (pDoc->GetIDocumentUndoRedo().DoesUndo())
790cdf0e10cSrcweir         {
791cdf0e10cSrcweir 			pUndo->SetInsertRange( aPam );
792cdf0e10cSrcweir             pDoc->GetIDocumentUndoRedo().AppendUndo(pUndo);
793cdf0e10cSrcweir         }
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 		if( pRedlineRange )
796cdf0e10cSrcweir 		{
797cdf0e10cSrcweir 			pRedlineRange->SetMark();
798cdf0e10cSrcweir 			*pRedlineRange->GetPoint() = *aPam.GetPoint();
799cdf0e10cSrcweir 			*pRedlineRange->GetMark() = *aPam.GetMark();
800cdf0e10cSrcweir 		}
801cdf0e10cSrcweir 
802cdf0e10cSrcweir 		pDoc->SetModified();
803cdf0e10cSrcweir         bRet = true;
804cdf0e10cSrcweir     }
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 	pDoc->SetRedlineMode_intern( eOld );
807cdf0e10cSrcweir 	if( pRedlineRange )
808cdf0e10cSrcweir 	{
809cdf0e10cSrcweir 		if( pDoc->IsRedlineOn() )
810cdf0e10cSrcweir 			pDoc->AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_INSERT, *pRedlineRange ), true);
811cdf0e10cSrcweir 		else
812cdf0e10cSrcweir 			pDoc->SplitRedline( *pRedlineRange );
813cdf0e10cSrcweir 		delete pRedlineRange;
814cdf0e10cSrcweir 	}
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 	return bRet;
817cdf0e10cSrcweir }
818cdf0e10cSrcweir 
819cdf0e10cSrcweir // Kopieren eines Bereiches im oder in ein anderes Dokument !
820cdf0e10cSrcweir // Die Position darf nicht im Bereich liegen !!
821cdf0e10cSrcweir 
lcl_MarksWholeNode(const SwPaM & rPam)822cdf0e10cSrcweir bool lcl_MarksWholeNode(const SwPaM & rPam)
823cdf0e10cSrcweir {
824cdf0e10cSrcweir     bool bResult = false;
825cdf0e10cSrcweir     const SwPosition* pStt = rPam.Start();
826cdf0e10cSrcweir     const SwPosition* pEnd = rPam.End();
827cdf0e10cSrcweir 
828cdf0e10cSrcweir     if (NULL != pStt && NULL != pEnd)
829cdf0e10cSrcweir     {
830cdf0e10cSrcweir         const SwTxtNode* pSttNd = pStt->nNode.GetNode().GetTxtNode();
831cdf0e10cSrcweir         const SwTxtNode* pEndNd = pEnd->nNode.GetNode().GetTxtNode();
832cdf0e10cSrcweir 
833cdf0e10cSrcweir         if (NULL != pSttNd && NULL != pEndNd &&
834cdf0e10cSrcweir             pStt->nContent.GetIndex() == 0 &&
835cdf0e10cSrcweir             pEnd->nContent.GetIndex() == pEndNd->Len())
836cdf0e10cSrcweir         {
837cdf0e10cSrcweir             bResult = true;
838cdf0e10cSrcweir         }
839cdf0e10cSrcweir     }
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     return bResult;
842cdf0e10cSrcweir }
843cdf0e10cSrcweir 
844cdf0e10cSrcweir // --> OD 2009-08-25 #i86492#
lcl_ContainsOnlyParagraphsInList(const SwPaM & rPam)845cdf0e10cSrcweir bool lcl_ContainsOnlyParagraphsInList( const SwPaM& rPam )
846cdf0e10cSrcweir {
847cdf0e10cSrcweir     bool bRet = false;
848cdf0e10cSrcweir 
849cdf0e10cSrcweir     const SwTxtNode* pTxtNd = rPam.Start()->nNode.GetNode().GetTxtNode();
850cdf0e10cSrcweir     const SwTxtNode* pEndTxtNd = rPam.End()->nNode.GetNode().GetTxtNode();
851cdf0e10cSrcweir     if ( pTxtNd && pTxtNd->IsInList() &&
852cdf0e10cSrcweir          pEndTxtNd && pEndTxtNd->IsInList() )
853cdf0e10cSrcweir     {
854cdf0e10cSrcweir         bRet = true;
855cdf0e10cSrcweir         SwNodeIndex aIdx(rPam.Start()->nNode);
856cdf0e10cSrcweir 
857cdf0e10cSrcweir         do
858cdf0e10cSrcweir         {
859cdf0e10cSrcweir             aIdx++;
860cdf0e10cSrcweir             pTxtNd = aIdx.GetNode().GetTxtNode();
861cdf0e10cSrcweir 
862cdf0e10cSrcweir             if ( !pTxtNd || !pTxtNd->IsInList() )
863cdf0e10cSrcweir             {
864cdf0e10cSrcweir                 bRet = false;
865cdf0e10cSrcweir                 break;
866cdf0e10cSrcweir             }
867cdf0e10cSrcweir         } while ( pTxtNd && pTxtNd != pEndTxtNd );
868cdf0e10cSrcweir     }
869cdf0e10cSrcweir 
870cdf0e10cSrcweir 
871cdf0e10cSrcweir     return bRet;
872cdf0e10cSrcweir }
873cdf0e10cSrcweir // <--
874cdf0e10cSrcweir 
CopyImpl(SwPaM & rPam,SwPosition & rPos,const bool bMakeNewFrms,const bool bCopyAll,SwPaM * const pCpyRange) const875cdf0e10cSrcweir bool SwDoc::CopyImpl( SwPaM& rPam, SwPosition& rPos,
876cdf0e10cSrcweir         const bool bMakeNewFrms, const bool bCopyAll,
877cdf0e10cSrcweir         SwPaM *const pCpyRange ) const
878cdf0e10cSrcweir {
879cdf0e10cSrcweir 	SwDoc* pDoc = rPos.nNode.GetNode().GetDoc();
880cdf0e10cSrcweir     const bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection();
881cdf0e10cSrcweir 
882cdf0e10cSrcweir     SwPosition* pStt = rPam.Start();
883cdf0e10cSrcweir     SwPosition* pEnd = rPam.End();
884cdf0e10cSrcweir 
885cdf0e10cSrcweir 	// kein Copy abfangen.
886cdf0e10cSrcweir 	if( !rPam.HasMark() || ( *pStt >= *pEnd && !bColumnSel ) ||
887cdf0e10cSrcweir 		//JP 29.6.2001: 88963 - dont copy if inspos is in region of start to end
888cdf0e10cSrcweir 		//JP 15.11.2001: don't test inclusive the end, ever exclusive
889cdf0e10cSrcweir 		( pDoc == this && *pStt <= rPos && rPos < *pEnd ))
890cdf0e10cSrcweir     {
891cdf0e10cSrcweir         return false;
892cdf0e10cSrcweir     }
893cdf0e10cSrcweir 
894cdf0e10cSrcweir     const bool bEndEqualIns = pDoc == this && rPos == *pEnd;
895cdf0e10cSrcweir 
896cdf0e10cSrcweir 	// falls Undo eingeschaltet, erzeuge das UndoCopy-Objekt
897cdf0e10cSrcweir     SwUndoCpyDoc* pUndo = 0;
898cdf0e10cSrcweir 	SwPaM aCpyPam( rPos );
899cdf0e10cSrcweir 
900cdf0e10cSrcweir 	SwTblNumFmtMerge aTNFM( *this, *pDoc );
901cdf0e10cSrcweir 
902cdf0e10cSrcweir     if (pDoc->GetIDocumentUndoRedo().DoesUndo())
903cdf0e10cSrcweir     {
904cdf0e10cSrcweir         pUndo = new SwUndoCpyDoc( aCpyPam );
905cdf0e10cSrcweir         pDoc->GetIDocumentUndoRedo().AppendUndo( pUndo );
906cdf0e10cSrcweir     }
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 	RedlineMode_t eOld = pDoc->GetRedlineMode();
909cdf0e10cSrcweir 	pDoc->SetRedlineMode_intern((RedlineMode_t)(eOld | nsRedlineMode_t::REDLINE_IGNORE));
910cdf0e10cSrcweir 
911cdf0e10cSrcweir 
912cdf0e10cSrcweir 	// bewege den Pam von der Insert-Position ein zurueck, dadurch wird
913cdf0e10cSrcweir 	// die Position nicht "verschoben"
914cdf0e10cSrcweir 	aCpyPam.SetMark();
915cdf0e10cSrcweir 	sal_Bool bCanMoveBack = aCpyPam.Move( fnMoveBackward, fnGoCntnt );
916cdf0e10cSrcweir 	if( !bCanMoveBack )
917cdf0e10cSrcweir 		aCpyPam.GetPoint()->nNode--;
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 	SwNodeRange aRg( pStt->nNode, pEnd->nNode );
920cdf0e10cSrcweir 	SwNodeIndex aInsPos( rPos.nNode );
921cdf0e10cSrcweir     const bool bOneNode = pStt->nNode == pEnd->nNode;
922cdf0e10cSrcweir     SwTxtNode* pSttTxtNd = pStt->nNode.GetNode().GetTxtNode();
923cdf0e10cSrcweir     SwTxtNode* pEndTxtNd = pEnd->nNode.GetNode().GetTxtNode();
924cdf0e10cSrcweir     SwTxtNode* pDestTxtNd = aInsPos.GetNode().GetTxtNode();
925cdf0e10cSrcweir     bool bCopyCollFmt = !pDoc->IsInsOnlyTextGlossary() &&
926cdf0e10cSrcweir                         ( ( pDestTxtNd && !pDestTxtNd->GetTxt().Len() ) ||
927cdf0e10cSrcweir                           ( !bOneNode && !rPos.nContent.GetIndex() ) );
928cdf0e10cSrcweir     bool bCopyBookmarks = true;
929cdf0e10cSrcweir     sal_Bool bStartIsTxtNode = 0 != pSttTxtNd;
930cdf0e10cSrcweir 
931cdf0e10cSrcweir     // #i104585# copy outline num rule to clipboard (for ASCII filter)
932cdf0e10cSrcweir     if (pDoc->IsClipBoard() && GetOutlineNumRule())
933cdf0e10cSrcweir     {
934cdf0e10cSrcweir         pDoc->SetOutlineNumRule(*GetOutlineNumRule());
935cdf0e10cSrcweir     }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir     // --> OD 2009-08-25 #i86492#
938cdf0e10cSrcweir     // Correct the search for a previous list:
939cdf0e10cSrcweir     // First search for non-outline numbering list. Then search for non-outline
940cdf0e10cSrcweir     // bullet list.
941cdf0e10cSrcweir     // Keep also the <ListId> value for possible propagation.
942cdf0e10cSrcweir     String aListIdToPropagate;
943cdf0e10cSrcweir     const SwNumRule* pNumRuleToPropagate =
944cdf0e10cSrcweir         pDoc->SearchNumRule( rPos, false, true, false, 0, aListIdToPropagate, true );
945cdf0e10cSrcweir     if ( !pNumRuleToPropagate )
946cdf0e10cSrcweir     {
947cdf0e10cSrcweir         pNumRuleToPropagate =
948cdf0e10cSrcweir             pDoc->SearchNumRule( rPos, false, false, false, 0, aListIdToPropagate, true );
949cdf0e10cSrcweir     }
950cdf0e10cSrcweir     // <--
951cdf0e10cSrcweir     // --> OD 2009-08-25 #i86492#
952cdf0e10cSrcweir     // Do not propagate previous found list, if
953cdf0e10cSrcweir     // - destination is an empty paragraph which is not in a list and
954cdf0e10cSrcweir     // - source contains at least one paragraph which is not in a list
955cdf0e10cSrcweir     if ( pNumRuleToPropagate &&
956cdf0e10cSrcweir          pDestTxtNd && !pDestTxtNd->GetTxt().Len() && !pDestTxtNd->IsInList() &&
957cdf0e10cSrcweir          !lcl_ContainsOnlyParagraphsInList( rPam ) )
958cdf0e10cSrcweir     {
959cdf0e10cSrcweir         pNumRuleToPropagate = 0;
960cdf0e10cSrcweir     }
961cdf0e10cSrcweir     // <--
962cdf0e10cSrcweir 
963cdf0e10cSrcweir 	// Block, damit aus diesem gesprungen werden kann !!
964cdf0e10cSrcweir 	do {
965cdf0e10cSrcweir         if( pSttTxtNd )
966cdf0e10cSrcweir 		{
967cdf0e10cSrcweir 			// den Anfang nicht komplett kopieren ?
968cdf0e10cSrcweir 			if( !bCopyCollFmt || bColumnSel || pStt->nContent.GetIndex() )
969cdf0e10cSrcweir 			{
970cdf0e10cSrcweir 				SwIndex aDestIdx( rPos.nContent );
971cdf0e10cSrcweir 				sal_Bool bCopyOk = sal_False;
972cdf0e10cSrcweir                 if( !pDestTxtNd )
973cdf0e10cSrcweir 				{
974cdf0e10cSrcweir 					if( pStt->nContent.GetIndex() || bOneNode )
975cdf0e10cSrcweir                         pDestTxtNd = pDoc->GetNodes().MakeTxtNode( aInsPos,
976cdf0e10cSrcweir 							pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD));
977cdf0e10cSrcweir 					else
978cdf0e10cSrcweir 					{
979cdf0e10cSrcweir                         pDestTxtNd = static_cast<SwTxtNode*>(pSttTxtNd->MakeCopy( pDoc, aInsPos ));
980cdf0e10cSrcweir 						bCopyOk = sal_True;
981cdf0e10cSrcweir 					}
982cdf0e10cSrcweir                     aDestIdx.Assign( pDestTxtNd, 0 );
983cdf0e10cSrcweir                     bCopyCollFmt = true;
984cdf0e10cSrcweir 				}
985cdf0e10cSrcweir 				else if( !bOneNode || bColumnSel )
986cdf0e10cSrcweir 				{
987cdf0e10cSrcweir 					xub_StrLen nCntntEnd = pEnd->nContent.GetIndex();
988cdf0e10cSrcweir                     {
989cdf0e10cSrcweir                         ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
990cdf0e10cSrcweir                         pDoc->SplitNode( rPos, false );
991cdf0e10cSrcweir                     }
992cdf0e10cSrcweir 
993cdf0e10cSrcweir 					if( bCanMoveBack && rPos == *aCpyPam.GetPoint() )
994cdf0e10cSrcweir 					{
995cdf0e10cSrcweir 						// nach dem SplitNode, den CpyPam wieder richtig aufspannen
996cdf0e10cSrcweir 						aCpyPam.Move( fnMoveBackward, fnGoCntnt );
997cdf0e10cSrcweir 						aCpyPam.Move( fnMoveBackward, fnGoCntnt );
998cdf0e10cSrcweir 					}
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir                     pDestTxtNd = pDoc->GetNodes()[ aInsPos.GetIndex()-1 ]->GetTxtNode();
1001cdf0e10cSrcweir                     aDestIdx.Assign( pDestTxtNd, pDestTxtNd->GetTxt().Len() );
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir 					// korrigiere den Bereich wieder !!
1004cdf0e10cSrcweir 					if( bEndEqualIns )
1005cdf0e10cSrcweir 					{
1006cdf0e10cSrcweir 						sal_Bool bChg = pEnd != rPam.GetPoint();
1007cdf0e10cSrcweir 						if( bChg )
1008cdf0e10cSrcweir 							rPam.Exchange();
1009cdf0e10cSrcweir 						rPam.Move( fnMoveBackward, fnGoCntnt );
1010cdf0e10cSrcweir 						if( bChg )
1011cdf0e10cSrcweir 							rPam.Exchange();
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir 						aRg.aEnd = pEnd->nNode;
1014cdf0e10cSrcweir                         pEndTxtNd = pEnd->nNode.GetNode().GetTxtNode();
1015cdf0e10cSrcweir 					}
1016cdf0e10cSrcweir 					else if( rPos == *pEnd )		// Wurde das Ende auch verschoben
1017cdf0e10cSrcweir 					{
1018cdf0e10cSrcweir 						pEnd->nNode--;
1019cdf0e10cSrcweir                         pEnd->nContent.Assign( pDestTxtNd, nCntntEnd );
1020cdf0e10cSrcweir 						aRg.aEnd = pEnd->nNode;
1021cdf0e10cSrcweir                         pEndTxtNd = pEnd->nNode.GetNode().GetTxtNode();
1022cdf0e10cSrcweir 					}
1023cdf0e10cSrcweir 				}
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir 				/* #107213#: Safe numrule item at destination. */
1026cdf0e10cSrcweir                 // --> OD 2009-08-25 #i86492#
1027cdf0e10cSrcweir                 // Safe also <ListId> item of destination.
1028cdf0e10cSrcweir                 int aNumRuleState = SFX_ITEM_UNKNOWN;
1029cdf0e10cSrcweir 				SwNumRuleItem aNumRuleItem;
1030cdf0e10cSrcweir                 int aListIdState = SFX_ITEM_UNKNOWN;
1031cdf0e10cSrcweir                 SfxStringItem aListIdItem( RES_PARATR_LIST_ID, String() );
1032cdf0e10cSrcweir                 {
1033cdf0e10cSrcweir                     const SfxItemSet * pAttrSet = pDestTxtNd->GetpSwAttrSet();
1034cdf0e10cSrcweir                     if (pAttrSet != NULL)
1035cdf0e10cSrcweir                     {
1036cdf0e10cSrcweir                         const SfxPoolItem * pItem = NULL;
1037cdf0e10cSrcweir                         aNumRuleState = pAttrSet->GetItemState(RES_PARATR_NUMRULE, sal_False, &pItem);
1038cdf0e10cSrcweir                         if (SFX_ITEM_SET == aNumRuleState)
1039cdf0e10cSrcweir                             aNumRuleItem = *((SwNumRuleItem *) pItem);
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir                         aListIdState =
1042cdf0e10cSrcweir                             pAttrSet->GetItemState(RES_PARATR_LIST_ID, sal_False, &pItem);
1043cdf0e10cSrcweir                         if (SFX_ITEM_SET == aListIdState)
1044cdf0e10cSrcweir                         {
1045cdf0e10cSrcweir                             aListIdItem.SetValue( static_cast<const SfxStringItem*>(pItem)->GetValue() );
1046cdf0e10cSrcweir                         }
1047cdf0e10cSrcweir                     }
1048cdf0e10cSrcweir                 }
1049cdf0e10cSrcweir                 // <--
1050cdf0e10cSrcweir 				/* #107213# */
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 				if( !bCopyOk )
1053cdf0e10cSrcweir 				{
1054cdf0e10cSrcweir                     const xub_StrLen nCpyLen = ( (bOneNode)
1055cdf0e10cSrcweir                                            ? pEnd->nContent.GetIndex()
1056cdf0e10cSrcweir                                            : pSttTxtNd->GetTxt().Len() )
1057cdf0e10cSrcweir                                          - pStt->nContent.GetIndex();
1058cdf0e10cSrcweir                     pSttTxtNd->CopyText( pDestTxtNd, aDestIdx,
1059cdf0e10cSrcweir                                             pStt->nContent, nCpyLen );
1060cdf0e10cSrcweir 					if( bEndEqualIns )
1061cdf0e10cSrcweir 						pEnd->nContent -= nCpyLen;
1062cdf0e10cSrcweir 				}
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir 				if( bOneNode )
1065cdf0e10cSrcweir 				{
1066cdf0e10cSrcweir 					if( bCopyCollFmt )
1067cdf0e10cSrcweir 					{
1068cdf0e10cSrcweir                         pSttTxtNd->CopyCollFmt( *pDestTxtNd );
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir                         /* #107213# If only a part of one paragraph is copied
1071cdf0e10cSrcweir                            restore the numrule at the destination. */
1072cdf0e10cSrcweir                         // --> OD 2009-08-25 #i86492#
1073cdf0e10cSrcweir                         // restore also <ListId> item
1074cdf0e10cSrcweir                         if ( !lcl_MarksWholeNode(rPam) )
1075cdf0e10cSrcweir                         {
1076cdf0e10cSrcweir                             if (SFX_ITEM_SET == aNumRuleState)
1077cdf0e10cSrcweir                             {
1078cdf0e10cSrcweir                                 pDestTxtNd->SetAttr(aNumRuleItem);
1079cdf0e10cSrcweir                             }
1080cdf0e10cSrcweir                             else
1081cdf0e10cSrcweir                             {
1082cdf0e10cSrcweir                                 pDestTxtNd->ResetAttr(RES_PARATR_NUMRULE);
1083cdf0e10cSrcweir                             }
1084cdf0e10cSrcweir                             if (SFX_ITEM_SET == aListIdState)
1085cdf0e10cSrcweir                             {
1086cdf0e10cSrcweir                                 pDestTxtNd->SetAttr(aListIdItem);
1087cdf0e10cSrcweir                             }
1088cdf0e10cSrcweir                             else
1089cdf0e10cSrcweir                             {
1090cdf0e10cSrcweir                                 pDestTxtNd->ResetAttr(RES_PARATR_LIST_ID);
1091cdf0e10cSrcweir                             }
1092cdf0e10cSrcweir                         }
1093cdf0e10cSrcweir                     }
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir 					break;
1096cdf0e10cSrcweir 				}
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir 				aRg.aStart++;
1099cdf0e10cSrcweir 			}
1100cdf0e10cSrcweir 		}
1101cdf0e10cSrcweir         else if( pDestTxtNd )
1102cdf0e10cSrcweir 		{
1103cdf0e10cSrcweir             // Problems with insertion of table selections into "normal" text solved.
1104cdf0e10cSrcweir             // We have to set the correct PaM for Undo, if this PaM starts in a textnode,
1105cdf0e10cSrcweir             // the undo operation will try to merge this node after removing the table.
1106cdf0e10cSrcweir             // If we didn't split a textnode, the PaM should start at the inserted table node
1107cdf0e10cSrcweir             if( rPos.nContent.GetIndex() == pDestTxtNd->Len() )
1108cdf0e10cSrcweir 			{    // Insertion at the last position of a textnode (empty or not)
1109cdf0e10cSrcweir 				aInsPos++; // The table will be inserted behind the text node
1110cdf0e10cSrcweir 			}
1111cdf0e10cSrcweir 			else if( rPos.nContent.GetIndex() )
1112cdf0e10cSrcweir 			{   // Insertion in the middle of a text node, it has to be split
1113cdf0e10cSrcweir                 // (and joined from undo)
1114cdf0e10cSrcweir                 bStartIsTxtNode = sal_True;
1115cdf0e10cSrcweir 				// splitte den TextNode, bei dem Eingefuegt wird.
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 				xub_StrLen nCntntEnd = pEnd->nContent.GetIndex();
1118cdf0e10cSrcweir                 {
1119cdf0e10cSrcweir                     ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
1120cdf0e10cSrcweir                     pDoc->SplitNode( rPos, false );
1121cdf0e10cSrcweir                 }
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 				if( bCanMoveBack && rPos == *aCpyPam.GetPoint() )
1124cdf0e10cSrcweir 				{
1125cdf0e10cSrcweir 					// nach dem SplitNode, den CpyPam wieder richtig aufspannen
1126cdf0e10cSrcweir 					aCpyPam.Move( fnMoveBackward, fnGoCntnt );
1127cdf0e10cSrcweir 					aCpyPam.Move( fnMoveBackward, fnGoCntnt );
1128cdf0e10cSrcweir 				}
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 				// korrigiere den Bereich wieder !!
1131cdf0e10cSrcweir 				if( bEndEqualIns )
1132cdf0e10cSrcweir 					aRg.aEnd--;
1133cdf0e10cSrcweir 				else if( rPos == *pEnd )		// Wurde das Ende auch verschoben
1134cdf0e10cSrcweir 				{
1135cdf0e10cSrcweir 					rPos.nNode-=2;
1136cdf0e10cSrcweir 					rPos.nContent.Assign( rPos.nNode.GetNode().GetCntntNode(),
1137cdf0e10cSrcweir 											nCntntEnd );
1138cdf0e10cSrcweir 					rPos.nNode++;
1139cdf0e10cSrcweir 					aRg.aEnd--;
1140cdf0e10cSrcweir 				}
1141cdf0e10cSrcweir 			}
1142cdf0e10cSrcweir             else if( bCanMoveBack )
1143cdf0e10cSrcweir             {   //Insertion at the first position of a text node. It will not be splitted, the table
1144cdf0e10cSrcweir                 // will be inserted before the text node.
1145cdf0e10cSrcweir                 // See below, before the SetInsertRange funciton of the undo object will be called,
1146cdf0e10cSrcweir                 // the CpyPam would be moved to the next content position. This has to be avoided
1147cdf0e10cSrcweir                 // We want to be moved to the table node itself thus we have to set bCanMoveBack
1148cdf0e10cSrcweir                 // and to manipulate aCpyPam.
1149cdf0e10cSrcweir                 bCanMoveBack = false;
1150cdf0e10cSrcweir                 aCpyPam.GetPoint()->nNode--;
1151cdf0e10cSrcweir             }
1152cdf0e10cSrcweir 		}
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir         pDestTxtNd = aInsPos.GetNode().GetTxtNode();
1155cdf0e10cSrcweir         if( pEndTxtNd )
1156cdf0e10cSrcweir 		{
1157cdf0e10cSrcweir 			SwIndex aDestIdx( rPos.nContent );
1158cdf0e10cSrcweir             if( !pDestTxtNd )
1159cdf0e10cSrcweir 			{
1160cdf0e10cSrcweir                 pDestTxtNd = pDoc->GetNodes().MakeTxtNode( aInsPos,
1161cdf0e10cSrcweir 							pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD));
1162cdf0e10cSrcweir                 aDestIdx.Assign( pDestTxtNd, 0  );
1163cdf0e10cSrcweir 				aInsPos--;
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir                 // #112756# #98130# if we have to insert an extra text node
1166cdf0e10cSrcweir                 // at the destination, this node will be our new destination
1167cdf0e10cSrcweir                 // (text) node, and thus we set bStartisTxtNode to true. This
1168cdf0e10cSrcweir                 // will ensure that this node will be deleted during Undo
1169cdf0e10cSrcweir                 // using JoinNext.
1170cdf0e10cSrcweir                 DBG_ASSERT( !bStartIsTxtNode, "Oops, undo may be instable now." );
1171cdf0e10cSrcweir                 bStartIsTxtNode = sal_True;
1172cdf0e10cSrcweir 			}
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir 			/* #107213# Save numrule at destination */
1175cdf0e10cSrcweir             // --> OD 2009-08-25 #i86492#
1176cdf0e10cSrcweir             // Safe also <ListId> item of destination.
1177cdf0e10cSrcweir             int aNumRuleState = SFX_ITEM_UNKNOWN;
1178cdf0e10cSrcweir             SwNumRuleItem aNumRuleItem;
1179cdf0e10cSrcweir             int aListIdState = SFX_ITEM_UNKNOWN;
1180cdf0e10cSrcweir             SfxStringItem aListIdItem( RES_PARATR_LIST_ID, String() );
1181cdf0e10cSrcweir             {
1182cdf0e10cSrcweir                 const SfxItemSet* pAttrSet = pDestTxtNd->GetpSwAttrSet();
1183cdf0e10cSrcweir                 if (pAttrSet != NULL)
1184cdf0e10cSrcweir                 {
1185cdf0e10cSrcweir                     const SfxPoolItem * pItem = NULL;
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir                     aNumRuleState =
1188cdf0e10cSrcweir                         pAttrSet->GetItemState(RES_PARATR_NUMRULE, sal_False, &pItem);
1189cdf0e10cSrcweir                     if (SFX_ITEM_SET == aNumRuleState)
1190cdf0e10cSrcweir                         aNumRuleItem = *((SwNumRuleItem *) pItem);
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir                     aListIdState =
1193cdf0e10cSrcweir                         pAttrSet->GetItemState(RES_PARATR_LIST_ID, sal_False, &pItem);
1194cdf0e10cSrcweir                     if (SFX_ITEM_SET == aListIdState)
1195cdf0e10cSrcweir                         aListIdItem.SetValue( static_cast<const SfxStringItem*>(pItem)->GetValue() );
1196cdf0e10cSrcweir                 }
1197cdf0e10cSrcweir             }
1198cdf0e10cSrcweir             // <--
1199cdf0e10cSrcweir 			/* #107213# */
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir             const bool bEmptyDestNd = 0 == pDestTxtNd->GetTxt().Len();
1202cdf0e10cSrcweir             pEndTxtNd->CopyText( pDestTxtNd, aDestIdx, SwIndex( pEndTxtNd ),
1203cdf0e10cSrcweir 							pEnd->nContent.GetIndex() );
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir 			// auch alle FormatVorlagen kopieren
1206cdf0e10cSrcweir 			if( bCopyCollFmt && ( bOneNode || bEmptyDestNd ))
1207cdf0e10cSrcweir 			{
1208cdf0e10cSrcweir                 pEndTxtNd->CopyCollFmt( *pDestTxtNd );
1209cdf0e10cSrcweir 
1210cdf0e10cSrcweir                 if ( bOneNode )
1211cdf0e10cSrcweir 				{
1212cdf0e10cSrcweir 					/* #107213# If only a part of one paragraph is copied
1213cdf0e10cSrcweir                        restore the numrule at the destination. */
1214cdf0e10cSrcweir                     // --> OD 2009-08-25 #i86492#
1215cdf0e10cSrcweir                     // restore also <ListId> item
1216cdf0e10cSrcweir                     if ( !lcl_MarksWholeNode(rPam) )
1217cdf0e10cSrcweir                     {
1218cdf0e10cSrcweir                         if (SFX_ITEM_SET == aNumRuleState)
1219cdf0e10cSrcweir                         {
1220cdf0e10cSrcweir                             pDestTxtNd->SetAttr(aNumRuleItem);
1221cdf0e10cSrcweir                         }
1222cdf0e10cSrcweir                         else
1223cdf0e10cSrcweir                         {
1224cdf0e10cSrcweir                             pDestTxtNd->ResetAttr(RES_PARATR_NUMRULE);
1225cdf0e10cSrcweir                         }
1226cdf0e10cSrcweir                         if (SFX_ITEM_SET == aListIdState)
1227cdf0e10cSrcweir                         {
1228cdf0e10cSrcweir                             pDestTxtNd->SetAttr(aListIdItem);
1229cdf0e10cSrcweir                         }
1230cdf0e10cSrcweir                         else
1231cdf0e10cSrcweir                         {
1232cdf0e10cSrcweir                             pDestTxtNd->ResetAttr(RES_PARATR_LIST_ID);
1233cdf0e10cSrcweir                         }
1234cdf0e10cSrcweir                     }
1235cdf0e10cSrcweir 				}
1236cdf0e10cSrcweir 			}
1237cdf0e10cSrcweir 		}
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir 		if( bCopyAll || aRg.aStart != aRg.aEnd )
1240cdf0e10cSrcweir 		{
1241cdf0e10cSrcweir 			SfxItemSet aBrkSet( pDoc->GetAttrPool(), aBreakSetRange );
1242cdf0e10cSrcweir             if( pSttTxtNd && bCopyCollFmt && pDestTxtNd->HasSwAttrSet() )
1243cdf0e10cSrcweir 			{
1244cdf0e10cSrcweir                 aBrkSet.Put( *pDestTxtNd->GetpSwAttrSet() );
1245cdf0e10cSrcweir 				if( SFX_ITEM_SET == aBrkSet.GetItemState( RES_BREAK, sal_False ) )
1246cdf0e10cSrcweir                     pDestTxtNd->ResetAttr( RES_BREAK );
1247cdf0e10cSrcweir 				if( SFX_ITEM_SET == aBrkSet.GetItemState( RES_PAGEDESC, sal_False ) )
1248cdf0e10cSrcweir                     pDestTxtNd->ResetAttr( RES_PAGEDESC );
1249cdf0e10cSrcweir 			}
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir 			if( aInsPos == pEnd->nNode )
1252cdf0e10cSrcweir 			{
1253cdf0e10cSrcweir 				SwNodeIndex aSaveIdx( aInsPos, -1 );
1254*dec99bbdSOliver-Rainer Wittmann                 CopyWithFlyInFly( aRg, 0, aInsPos, &rPam, bMakeNewFrms, sal_False );
1255cdf0e10cSrcweir 				aSaveIdx++;
1256cdf0e10cSrcweir 				pEnd->nNode = aSaveIdx;
1257cdf0e10cSrcweir 				pEnd->nContent.Assign( aSaveIdx.GetNode().GetTxtNode(), 0 );
1258cdf0e10cSrcweir 			}
1259cdf0e10cSrcweir 			else
1260*dec99bbdSOliver-Rainer Wittmann                 CopyWithFlyInFly( aRg, pEnd->nContent.GetIndex(), aInsPos, &rPam, bMakeNewFrms, sal_False );
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir             bCopyBookmarks = false;
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir 			// harte Umbrueche wieder in den ersten Node setzen
1265cdf0e10cSrcweir             if( aBrkSet.Count() && 0 != ( pDestTxtNd = pDoc->GetNodes()[
1266cdf0e10cSrcweir 					aCpyPam.GetPoint()->nNode.GetIndex()+1 ]->GetTxtNode() ) )
1267cdf0e10cSrcweir 			{
1268cdf0e10cSrcweir                 pDestTxtNd->SetAttr( aBrkSet );
1269cdf0e10cSrcweir 			}
1270cdf0e10cSrcweir 		}
1271cdf0e10cSrcweir 	} while( sal_False );
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir 	// Position ummelden ( falls verschoben / im anderen Node )
1274cdf0e10cSrcweir 	rPos.nContent.Assign( rPos.nNode.GetNode().GetCntntNode(),
1275cdf0e10cSrcweir 							rPos.nContent.GetIndex() );
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir 	if( rPos.nNode != aInsPos )
1278cdf0e10cSrcweir 	{
1279cdf0e10cSrcweir 		aCpyPam.GetMark()->nNode = aInsPos;
1280cdf0e10cSrcweir 		aCpyPam.GetMark()->nContent.Assign( aCpyPam.GetCntntNode(sal_False), 0 );
1281cdf0e10cSrcweir 		rPos = *aCpyPam.GetMark();
1282cdf0e10cSrcweir 	}
1283cdf0e10cSrcweir 	else
1284cdf0e10cSrcweir 		*aCpyPam.GetMark() = rPos;
1285cdf0e10cSrcweir 
1286cdf0e10cSrcweir 	aCpyPam.Move( fnMoveForward, bCanMoveBack ? fnGoCntnt : fnGoNode );
1287cdf0e10cSrcweir 	aCpyPam.Exchange();
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir 	// dann kopiere noch alle Bookmarks
1290*dec99bbdSOliver-Rainer Wittmann     if( bCopyBookmarks && getIDocumentMarkAccess()->getAllMarksCount() )
1291cdf0e10cSrcweir 		lcl_CopyBookmarks( rPam, aCpyPam );
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir 	if( nsRedlineMode_t::REDLINE_DELETE_REDLINES & eOld )
1294cdf0e10cSrcweir 		lcl_DeleteRedlines( rPam, aCpyPam );
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir 	// falls Undo eingeschaltet ist, so speicher den eingefuegten Bereich
1297cdf0e10cSrcweir     if (pDoc->GetIDocumentUndoRedo().DoesUndo())
1298cdf0e10cSrcweir     {
1299cdf0e10cSrcweir 		pUndo->SetInsertRange( aCpyPam, sal_True, bStartIsTxtNode );
1300cdf0e10cSrcweir     }
1301cdf0e10cSrcweir 
1302cdf0e10cSrcweir 	if( pCpyRange )
1303cdf0e10cSrcweir 	{
1304cdf0e10cSrcweir 		pCpyRange->SetMark();
1305cdf0e10cSrcweir 		*pCpyRange->GetPoint() = *aCpyPam.GetPoint();
1306cdf0e10cSrcweir 		*pCpyRange->GetMark() = *aCpyPam.GetMark();
1307cdf0e10cSrcweir 	}
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir     if ( pNumRuleToPropagate )
1310cdf0e10cSrcweir     {
1311cdf0e10cSrcweir         // --> OD 2009-08-25 #i86492#
1312cdf0e10cSrcweir         // use <SwDoc::SetNumRule(..)>, because it also handles the <ListId>
1313cdf0e10cSrcweir //        pDoc->ReplaceNumRule(aCpyPam, *pNumRuleToPropagate);
1314cdf0e10cSrcweir         pDoc->SetNumRule( aCpyPam, *pNumRuleToPropagate, false,
1315cdf0e10cSrcweir                           aListIdToPropagate, sal_True, true );
1316cdf0e10cSrcweir     }
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir 	pDoc->SetRedlineMode_intern( eOld );
1319cdf0e10cSrcweir 	pDoc->SetModified();
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir     return true;
1322cdf0e10cSrcweir }
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir //  ----- Copy-Methode vom SwDoc - "kopiere Fly's in Fly's" ------
1326cdf0e10cSrcweir 
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) const1327*dec99bbdSOliver-Rainer Wittmann void SwDoc::CopyWithFlyInFly(
1328*dec99bbdSOliver-Rainer Wittmann     const SwNodeRange& rRg,
1329*dec99bbdSOliver-Rainer Wittmann     const xub_StrLen nEndContentIndex,
1330*dec99bbdSOliver-Rainer Wittmann     const SwNodeIndex& rInsPos,
1331*dec99bbdSOliver-Rainer Wittmann     const SwPaM* pCopiedPaM,
1332*dec99bbdSOliver-Rainer Wittmann     const sal_Bool bMakeNewFrms,
1333*dec99bbdSOliver-Rainer Wittmann     const sal_Bool bDelRedlines,
1334*dec99bbdSOliver-Rainer Wittmann     const sal_Bool bCopyFlyAtFly ) const
1335cdf0e10cSrcweir {
1336cdf0e10cSrcweir     SwDoc* pDest = rInsPos.GetNode().GetDoc();
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir     _SaveRedlEndPosForRestore aRedlRest( rInsPos, 0 );
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir     SwNodeIndex aSavePos( rInsPos, -1 );
1341cdf0e10cSrcweir     sal_Bool bEndIsEqualEndPos = rInsPos == rRg.aEnd;
1342cdf0e10cSrcweir     GetNodes()._CopyNodes( rRg, rInsPos, bMakeNewFrms, sal_True );
1343cdf0e10cSrcweir     aSavePos++;
1344cdf0e10cSrcweir     if( bEndIsEqualEndPos )
1345cdf0e10cSrcweir         ((SwNodeIndex&)rRg.aEnd) = aSavePos;
1346cdf0e10cSrcweir 
1347cdf0e10cSrcweir     aRedlRest.Restore();
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir #ifdef DBG_UTIL
1350cdf0e10cSrcweir 	{
1351cdf0e10cSrcweir 		//JP 17.06.99: Bug 66973 - check count only if the selection is in
1352cdf0e10cSrcweir 		//				the same (or no) section. Becaus not full selected
1353cdf0e10cSrcweir 		//				section are not copied.
1354cdf0e10cSrcweir 		const SwSectionNode* pSSectNd = rRg.aStart.GetNode().FindSectionNode();
1355cdf0e10cSrcweir 		SwNodeIndex aTmpI( rRg.aEnd, -1 );
1356cdf0e10cSrcweir 		const SwSectionNode* pESectNd = aTmpI.GetNode().FindSectionNode();
1357cdf0e10cSrcweir 		if( pSSectNd == pESectNd &&
1358cdf0e10cSrcweir 			!rRg.aStart.GetNode().IsSectionNode() &&
1359cdf0e10cSrcweir 			!aTmpI.GetNode().IsEndNode() )
1360cdf0e10cSrcweir 		{
1361cdf0e10cSrcweir 			ASSERT( rInsPos.GetIndex() - aSavePos.GetIndex() ==
1362cdf0e10cSrcweir 					rRg.aEnd.GetIndex() - rRg.aStart.GetIndex(),
1363cdf0e10cSrcweir 					"Es wurden zu wenig Nodes kopiert!" )
1364cdf0e10cSrcweir 		}
1365cdf0e10cSrcweir 	}
1366cdf0e10cSrcweir #endif
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir     {
1369cdf0e10cSrcweir         ::sw::UndoGuard const undoGuard(pDest->GetIDocumentUndoRedo());
1370cdf0e10cSrcweir         CopyFlyInFlyImpl( rRg, nEndContentIndex, aSavePos, bCopyFlyAtFly );
1371cdf0e10cSrcweir     }
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir     SwNodeRange aCpyRange( aSavePos, rInsPos );
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir     // dann kopiere noch alle Bookmarks
1376*dec99bbdSOliver-Rainer Wittmann     if( getIDocumentMarkAccess()->getAllMarksCount() )
1377cdf0e10cSrcweir     {
1378cdf0e10cSrcweir         SwPaM aRgTmp( rRg.aStart, rRg.aEnd );
1379cdf0e10cSrcweir         SwPaM aCpyTmp( aCpyRange.aStart, aCpyRange.aEnd );
1380cdf0e10cSrcweir 
1381*dec99bbdSOliver-Rainer Wittmann         lcl_CopyBookmarks(
1382*dec99bbdSOliver-Rainer Wittmann             pCopiedPaM != NULL ? *pCopiedPaM : aRgTmp,
1383*dec99bbdSOliver-Rainer Wittmann             aCpyTmp );
1384cdf0e10cSrcweir     }
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir     if( bDelRedlines && ( nsRedlineMode_t::REDLINE_DELETE_REDLINES & pDest->GetRedlineMode() ))
1387cdf0e10cSrcweir         lcl_DeleteRedlines( rRg, aCpyRange );
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir     pDest->GetNodes()._DelDummyNodes( aCpyRange );
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir 
lcl_ChainFmts(SwFlyFrmFmt * pSrc,SwFlyFrmFmt * pDest)1392cdf0e10cSrcweir void lcl_ChainFmts( SwFlyFrmFmt *pSrc, SwFlyFrmFmt *pDest )
1393cdf0e10cSrcweir {
1394cdf0e10cSrcweir 	SwFmtChain aSrc( pSrc->GetChain() );
1395cdf0e10cSrcweir 	if ( !aSrc.GetNext() )
1396cdf0e10cSrcweir 	{
1397cdf0e10cSrcweir 		aSrc.SetNext( pDest );
1398cdf0e10cSrcweir         pSrc->SetFmtAttr( aSrc );
1399cdf0e10cSrcweir 	}
1400cdf0e10cSrcweir 	SwFmtChain aDest( pDest->GetChain() );
1401cdf0e10cSrcweir 	if ( !aDest.GetPrev() )
1402cdf0e10cSrcweir 	{
1403cdf0e10cSrcweir 		aDest.SetPrev( pSrc );
1404cdf0e10cSrcweir         pDest->SetFmtAttr( aDest );
1405cdf0e10cSrcweir 	}
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir 
CopyFlyInFlyImpl(const SwNodeRange & rRg,const xub_StrLen nEndContentIndex,const SwNodeIndex & rStartIdx,const bool bCopyFlyAtFly) const1408*dec99bbdSOliver-Rainer Wittmann void SwDoc::CopyFlyInFlyImpl(
1409*dec99bbdSOliver-Rainer Wittmann     const SwNodeRange& rRg,
1410*dec99bbdSOliver-Rainer Wittmann     const xub_StrLen nEndContentIndex,
1411*dec99bbdSOliver-Rainer Wittmann     const SwNodeIndex& rStartIdx,
1412cdf0e10cSrcweir     const bool bCopyFlyAtFly ) const
1413cdf0e10cSrcweir {
1414cdf0e10cSrcweir 	// Bug 22727: suche erst mal alle Flys zusammen, sortiere sie entsprechend
1415cdf0e10cSrcweir 	//			  ihrer Ordnungsnummer und kopiere sie erst dann. Damit wird
1416cdf0e10cSrcweir 	//			  die Ordnungsnummer (wird nur im DrawModel verwaltet)
1417cdf0e10cSrcweir 	//			  beibehalten.
1418cdf0e10cSrcweir     SwDoc *const pDest = rStartIdx.GetNode().GetDoc();
1419cdf0e10cSrcweir 	_ZSortFlys aArr;
1420cdf0e10cSrcweir 	sal_uInt16 nArrLen = GetSpzFrmFmts()->Count();
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir     for ( sal_uInt16 n = 0; n < nArrLen; ++n )
1423cdf0e10cSrcweir     {
1424cdf0e10cSrcweir         SwFrmFmt const*const pFmt = (*GetSpzFrmFmts())[n];
1425cdf0e10cSrcweir         SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
1426cdf0e10cSrcweir         SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
1427cdf0e10cSrcweir         bool bAtCntnt = (pAnchor->GetAnchorId() == FLY_AT_PARA);
1428cdf0e10cSrcweir         if ( pAPos &&
1429cdf0e10cSrcweir              ( bAtCntnt ||
1430cdf0e10cSrcweir               (pAnchor->GetAnchorId() == FLY_AT_FLY) ||
1431cdf0e10cSrcweir               (pAnchor->GetAnchorId() == FLY_AT_CHAR)) &&
1432cdf0e10cSrcweir 			 (( bCopyFlyAtFly && FLY_AT_FLY == pAnchor->GetAnchorId() )
1433cdf0e10cSrcweir 					? rRg.aStart <= pAPos->nNode.GetIndex() + 1
1434cdf0e10cSrcweir 					: ( IsRedlineMove()
1435cdf0e10cSrcweir 							? rRg.aStart < pAPos->nNode
1436cdf0e10cSrcweir 							: rRg.aStart <= pAPos->nNode )) &&
1437cdf0e10cSrcweir 			 pAPos->nNode <= rRg.aEnd )
1438cdf0e10cSrcweir 		{
1439cdf0e10cSrcweir 			//frames at the last source node are not always copied:
1440cdf0e10cSrcweir             //- if the node is empty and is the last node of the document or a table cell
1441cdf0e10cSrcweir             //  or a text frame then tey have to be copied
1442cdf0e10cSrcweir             //- if the content index in this node is > 0 then paragph and frame bound objects are copied
1443cdf0e10cSrcweir             //- to-character bound objects are copied if their index is <= nEndContentIndex
1444cdf0e10cSrcweir             bool bAdd = false;
1445cdf0e10cSrcweir             if( pAPos->nNode < rRg.aEnd )
1446cdf0e10cSrcweir                 bAdd = true;
1447cdf0e10cSrcweir             if( !bAdd )
1448cdf0e10cSrcweir             {
1449cdf0e10cSrcweir                 bool bEmptyNode = false;
1450cdf0e10cSrcweir                 bool bLastNode = false;
1451cdf0e10cSrcweir                 // is the node empty?
1452cdf0e10cSrcweir                 const SwNodes& rNodes = pAPos->nNode.GetNodes();
1453cdf0e10cSrcweir                 SwTxtNode* pTxtNode;
1454cdf0e10cSrcweir                 if( 0 != ( pTxtNode = pAPos->nNode.GetNode().GetTxtNode() ))
1455cdf0e10cSrcweir                 {
1456cdf0e10cSrcweir                     bEmptyNode = !pTxtNode->GetTxt().Len();
1457cdf0e10cSrcweir                     if( bEmptyNode )
1458cdf0e10cSrcweir                     {
1459cdf0e10cSrcweir                         //last node information is only necessary to know for the last TextNode
1460cdf0e10cSrcweir                         SwNodeIndex aTmp( pAPos->nNode );
1461cdf0e10cSrcweir                         ++aTmp;//goto next node
1462cdf0e10cSrcweir                         while (aTmp.GetNode().IsEndNode())
1463cdf0e10cSrcweir                         {
1464cdf0e10cSrcweir                             if( aTmp == rNodes.GetEndOfContent().GetIndex() )
1465cdf0e10cSrcweir                             {
1466cdf0e10cSrcweir                                 bLastNode = true;
1467cdf0e10cSrcweir                                 break;
1468cdf0e10cSrcweir                             }
1469cdf0e10cSrcweir                             ++aTmp;
1470cdf0e10cSrcweir                         }
1471cdf0e10cSrcweir                     }
1472cdf0e10cSrcweir                 }
1473cdf0e10cSrcweir                 bAdd = bLastNode && bEmptyNode;
1474cdf0e10cSrcweir                 if( !bAdd )
1475cdf0e10cSrcweir                 {
1476cdf0e10cSrcweir                     if( bAtCntnt )
1477cdf0e10cSrcweir                         bAdd = nEndContentIndex > 0;
1478cdf0e10cSrcweir                     else
1479cdf0e10cSrcweir                         bAdd = pAPos->nContent <= nEndContentIndex;
1480cdf0e10cSrcweir                 }
1481cdf0e10cSrcweir             }
1482cdf0e10cSrcweir             if( bAdd )
1483cdf0e10cSrcweir                 aArr.Insert( _ZSortFly( pFmt, pAnchor, nArrLen + aArr.Count() ));
1484cdf0e10cSrcweir 		}
1485cdf0e10cSrcweir 	}
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir 	//Alle kopierten (also die neu erzeugten) Rahmen in ein weiteres Array
1488cdf0e10cSrcweir 	//stopfen. Dort sizten sie passend zu den Originalen, damit hinterher
1489cdf0e10cSrcweir 	//die Chains entsprechend aufgebaut werden koennen.
1490cdf0e10cSrcweir 	SvPtrarr aNewArr( 10, 10 );
1491cdf0e10cSrcweir 
1492cdf0e10cSrcweir     for ( sal_uInt16 n = 0; n < aArr.Count(); ++n )
1493cdf0e10cSrcweir     {
1494cdf0e10cSrcweir 		const _ZSortFly& rZSortFly = aArr[ n ];
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir         // --> OD 2006-01-04 #i59964#
1497cdf0e10cSrcweir         // correct determination of new anchor position
1498cdf0e10cSrcweir         SwFmtAnchor aAnchor( *rZSortFly.GetAnchor() );
1499cdf0e10cSrcweir         SwPosition* pNewPos = (SwPosition*)aAnchor.GetCntntAnchor();
1500cdf0e10cSrcweir         // for at-paragraph and at-character anchored objects the new anchor
1501cdf0e10cSrcweir         // position can *not* be determined by the difference of the current
1502cdf0e10cSrcweir         // anchor position to the start of the copied range, because not
1503cdf0e10cSrcweir         // complete selected sections in the copied range aren't copied - see
1504cdf0e10cSrcweir         // method <SwNodes::_CopyNodes(..)>.
1505cdf0e10cSrcweir         // Thus, the new anchor position in the destination document is found
1506cdf0e10cSrcweir         // by counting the text nodes.
1507cdf0e10cSrcweir         if ((aAnchor.GetAnchorId() == FLY_AT_PARA) ||
1508cdf0e10cSrcweir             (aAnchor.GetAnchorId() == FLY_AT_CHAR) )
1509cdf0e10cSrcweir         {
1510cdf0e10cSrcweir             // First, determine number of anchor text node in the copied range.
1511cdf0e10cSrcweir             // Note: The anchor text node *have* to be inside the copied range.
1512cdf0e10cSrcweir             sal_uLong nAnchorTxtNdNumInRange( 0L );
1513cdf0e10cSrcweir             bool bAnchorTxtNdFound( false );
1514cdf0e10cSrcweir             SwNodeIndex aIdx( rRg.aStart );
1515cdf0e10cSrcweir             while ( !bAnchorTxtNdFound && aIdx <= rRg.aEnd )
1516cdf0e10cSrcweir             {
1517cdf0e10cSrcweir                 if ( aIdx.GetNode().IsTxtNode() )
1518cdf0e10cSrcweir                 {
1519cdf0e10cSrcweir                     ++nAnchorTxtNdNumInRange;
1520cdf0e10cSrcweir                     bAnchorTxtNdFound = aAnchor.GetCntntAnchor()->nNode == aIdx;
1521cdf0e10cSrcweir                 }
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir                 ++aIdx;
1524cdf0e10cSrcweir             }
1525cdf0e10cSrcweir             if ( !bAnchorTxtNdFound )
1526cdf0e10cSrcweir             {
1527cdf0e10cSrcweir                 // This case can *not* happen, but to be robust take the first
1528cdf0e10cSrcweir                 // text node in the destination document.
1529cdf0e10cSrcweir                 ASSERT( false,
1530cdf0e10cSrcweir                         "<SwDoc::_CopyFlyInFly(..)> - anchor text node in copied range not found" );
1531cdf0e10cSrcweir                 nAnchorTxtNdNumInRange = 1;
1532cdf0e10cSrcweir             }
1533cdf0e10cSrcweir             // Second, search corresponding text node in destination document
1534cdf0e10cSrcweir             // by counting forward from start insert position <rStartIdx> the
1535cdf0e10cSrcweir             // determined number of text nodes.
1536cdf0e10cSrcweir             aIdx = rStartIdx;
1537cdf0e10cSrcweir             SwNodeIndex aAnchorNdIdx( rStartIdx );
1538cdf0e10cSrcweir             const SwNode& aEndOfContentNd =
1539cdf0e10cSrcweir                                     aIdx.GetNode().GetNodes().GetEndOfContent();
1540cdf0e10cSrcweir             while ( nAnchorTxtNdNumInRange > 0 &&
1541cdf0e10cSrcweir                     &(aIdx.GetNode()) != &aEndOfContentNd )
1542cdf0e10cSrcweir             {
1543cdf0e10cSrcweir                 if ( aIdx.GetNode().IsTxtNode() )
1544cdf0e10cSrcweir                 {
1545cdf0e10cSrcweir                     --nAnchorTxtNdNumInRange;
1546cdf0e10cSrcweir                     aAnchorNdIdx = aIdx;
1547cdf0e10cSrcweir                 }
1548cdf0e10cSrcweir 
1549cdf0e10cSrcweir                 ++aIdx;
1550cdf0e10cSrcweir             }
1551cdf0e10cSrcweir             if ( !aAnchorNdIdx.GetNode().IsTxtNode() )
1552cdf0e10cSrcweir             {
1553cdf0e10cSrcweir                 // This case can *not* happen, but to be robust take the first
1554cdf0e10cSrcweir                 // text node in the destination document.
1555cdf0e10cSrcweir                 ASSERT( false,
1556cdf0e10cSrcweir                         "<SwDoc::_CopyFlyInFly(..)> - found anchor node index isn't a text node" );
1557cdf0e10cSrcweir                 aAnchorNdIdx = rStartIdx;
1558cdf0e10cSrcweir                 while ( !aAnchorNdIdx.GetNode().IsTxtNode() )
1559cdf0e10cSrcweir                 {
1560cdf0e10cSrcweir                     ++aAnchorNdIdx;
1561cdf0e10cSrcweir                 }
1562cdf0e10cSrcweir             }
1563cdf0e10cSrcweir             // apply found anchor text node as new anchor position
1564cdf0e10cSrcweir             pNewPos->nNode = aAnchorNdIdx;
1565cdf0e10cSrcweir         }
1566cdf0e10cSrcweir         else
1567cdf0e10cSrcweir         {
1568cdf0e10cSrcweir             long nOffset = pNewPos->nNode.GetIndex() - rRg.aStart.GetIndex();
1569cdf0e10cSrcweir             SwNodeIndex aIdx( rStartIdx, nOffset );
1570cdf0e10cSrcweir             pNewPos->nNode = aIdx;
1571cdf0e10cSrcweir         }
1572cdf0e10cSrcweir         // <--
1573cdf0e10cSrcweir 		// die am Zeichen Flys wieder ans das vorgegebene Zeichen setzen
1574cdf0e10cSrcweir         if ((FLY_AT_CHAR == aAnchor.GetAnchorId()) &&
1575cdf0e10cSrcweir              pNewPos->nNode.GetNode().IsTxtNode() )
1576cdf0e10cSrcweir         {
1577cdf0e10cSrcweir             pNewPos->nContent.Assign( (SwTxtNode*)&pNewPos->nNode.GetNode(),
1578cdf0e10cSrcweir 										pNewPos->nContent.GetIndex() );
1579cdf0e10cSrcweir         }
1580cdf0e10cSrcweir 		else
1581cdf0e10cSrcweir         {
1582cdf0e10cSrcweir 			pNewPos->nContent.Assign( 0, 0 );
1583cdf0e10cSrcweir         }
1584cdf0e10cSrcweir 
1585cdf0e10cSrcweir 		// ueberpruefe Rekursion: Inhalt in "seinen eigenen" Frame
1586cdf0e10cSrcweir 		// kopieren. Dann nicht kopieren
1587cdf0e10cSrcweir 		sal_Bool bMakeCpy = sal_True;
1588cdf0e10cSrcweir 		if( pDest == this )
1589cdf0e10cSrcweir 		{
1590cdf0e10cSrcweir 			const SwFmtCntnt& rCntnt = rZSortFly.GetFmt()->GetCntnt();
1591cdf0e10cSrcweir 			const SwStartNode* pSNd;
1592cdf0e10cSrcweir 			if( rCntnt.GetCntntIdx() &&
1593cdf0e10cSrcweir 				0 != ( pSNd = rCntnt.GetCntntIdx()->GetNode().GetStartNode() ) &&
1594cdf0e10cSrcweir                 pSNd->GetIndex() < rStartIdx.GetIndex() &&
1595cdf0e10cSrcweir                 rStartIdx.GetIndex() < pSNd->EndOfSectionIndex() )
1596cdf0e10cSrcweir 			{
1597cdf0e10cSrcweir 				bMakeCpy = sal_False;
1598cdf0e10cSrcweir 				aArr.Remove( n, 1 );
1599cdf0e10cSrcweir 				--n;
1600cdf0e10cSrcweir 			}
1601cdf0e10cSrcweir 		}
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir 		// Format kopieren und den neuen Anker setzen
1604cdf0e10cSrcweir 		if( bMakeCpy )
1605cdf0e10cSrcweir 			aNewArr.Insert( pDest->CopyLayoutFmt( *rZSortFly.GetFmt(),
1606cdf0e10cSrcweir                         aAnchor, false, true ), aNewArr.Count() );
1607cdf0e10cSrcweir 	}
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir 	//Alle chains, die im Original vorhanden sind, soweit wie moeglich wieder
1610cdf0e10cSrcweir 	//aufbauen.
1611cdf0e10cSrcweir 	ASSERT( aArr.Count() == aNewArr.Count(), "Missing new Flys" );
1612cdf0e10cSrcweir 	if ( aArr.Count() == aNewArr.Count() )
1613cdf0e10cSrcweir 	{
1614cdf0e10cSrcweir         for ( sal_uInt16 n = 0; n < aArr.Count(); ++n )
1615cdf0e10cSrcweir 		{
1616cdf0e10cSrcweir 			const SwFrmFmt *pFmt = aArr[n].GetFmt();
1617cdf0e10cSrcweir 			const SwFmtChain &rChain = pFmt->GetChain();
1618cdf0e10cSrcweir 			int nCnt = 0 != rChain.GetPrev();
1619cdf0e10cSrcweir 			nCnt += rChain.GetNext() ? 1: 0;
1620cdf0e10cSrcweir 			for ( sal_uInt16 k = 0; nCnt && k < aArr.Count(); ++k )
1621cdf0e10cSrcweir 			{
1622cdf0e10cSrcweir 				const _ZSortFly &rTmp = aArr[k];
1623cdf0e10cSrcweir 				const SwFrmFmt *pTmp = rTmp.GetFmt();
1624cdf0e10cSrcweir 				if ( rChain.GetPrev() == pTmp )
1625cdf0e10cSrcweir 				{
1626cdf0e10cSrcweir 					::lcl_ChainFmts( (SwFlyFrmFmt*)aNewArr[k],
1627cdf0e10cSrcweir 									 (SwFlyFrmFmt*)aNewArr[n] );
1628cdf0e10cSrcweir 					--nCnt;
1629cdf0e10cSrcweir 				}
1630cdf0e10cSrcweir 				else if ( rChain.GetNext() == pTmp )
1631cdf0e10cSrcweir 				{
1632cdf0e10cSrcweir 					::lcl_ChainFmts( (SwFlyFrmFmt*)aNewArr[n],
1633cdf0e10cSrcweir 									 (SwFlyFrmFmt*)aNewArr[k] );
1634cdf0e10cSrcweir 					--nCnt;
1635cdf0e10cSrcweir 				}
1636cdf0e10cSrcweir 			}
1637cdf0e10cSrcweir 		}
1638cdf0e10cSrcweir 	}
1639cdf0e10cSrcweir }
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 
1643cdf0e10cSrcweir 
1644