xref: /aoo41x/main/sw/source/core/doc/doctxm.cxx (revision 808c4840)
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
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
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.
19efeef26fSAndrew Rist  *
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 
28cdf0e10cSrcweir #include <limits.h>
29cdf0e10cSrcweir #include <hintids.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #define _SVSTDARR_STRINGSSORT
32cdf0e10cSrcweir #include <svl/svstdarr.hxx>
33cdf0e10cSrcweir #include <editeng/langitem.hxx>
34cdf0e10cSrcweir #include <editeng/brkitem.hxx>
35cdf0e10cSrcweir #include <editeng/tstpitem.hxx>
36cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
37cdf0e10cSrcweir #include <sot/clsids.hxx>
38cdf0e10cSrcweir #include <docsh.hxx>
39cdf0e10cSrcweir #include <ndole.hxx>
40cdf0e10cSrcweir #include <txttxmrk.hxx>
41cdf0e10cSrcweir #include <fmtinfmt.hxx>
42cdf0e10cSrcweir #include <fmtpdsc.hxx>
43cdf0e10cSrcweir #include <frmfmt.hxx>
44cdf0e10cSrcweir #include <fmtfsize.hxx>
45cdf0e10cSrcweir #include <frmatr.hxx>
46cdf0e10cSrcweir #include <pagedesc.hxx>
47cdf0e10cSrcweir #include <doc.hxx>
48cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
49cdf0e10cSrcweir #include <pagefrm.hxx>
50cdf0e10cSrcweir #include <ndtxt.hxx>
51cdf0e10cSrcweir #include <swtable.hxx>
52cdf0e10cSrcweir #include <doctxm.hxx>
53cdf0e10cSrcweir #include <txmsrt.hxx>
54cdf0e10cSrcweir #include <rolbck.hxx>
55cdf0e10cSrcweir #include <poolfmt.hxx>
56cdf0e10cSrcweir #include <txtfrm.hxx>
57cdf0e10cSrcweir #include <rootfrm.hxx>
58cdf0e10cSrcweir #include <UndoAttribute.hxx>
59cdf0e10cSrcweir #include <swundo.hxx>
60cdf0e10cSrcweir #include <mdiexp.hxx>
61cdf0e10cSrcweir #include <docary.hxx>
62cdf0e10cSrcweir #include <charfmt.hxx>
63cdf0e10cSrcweir #include <fchrfmt.hxx>
64cdf0e10cSrcweir #include <fldbas.hxx>
65cdf0e10cSrcweir #include <fmtfld.hxx>
66cdf0e10cSrcweir #include <txtfld.hxx>
67cdf0e10cSrcweir #include <expfld.hxx>
68cdf0e10cSrcweir #include <chpfld.hxx>
69cdf0e10cSrcweir #include <mvsave.hxx>
70cdf0e10cSrcweir #include <node2lay.hxx>
71cdf0e10cSrcweir #include <SwStyleNameMapper.hxx>
72cdf0e10cSrcweir #include <breakit.hxx>
73cdf0e10cSrcweir #include <editsh.hxx>
74cdf0e10cSrcweir #include <scriptinfo.hxx>
75cdf0e10cSrcweir #include <switerator.hxx>
76cdf0e10cSrcweir 
77cdf0e10cSrcweir using namespace ::com::sun::star;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir const sal_Unicode cNumRepl		= '@';
80cdf0e10cSrcweir const sal_Unicode cEndPageNum 	= '~';
81cdf0e10cSrcweir const sal_Char __FAR_DATA sPageDeli[] = ", ";
82cdf0e10cSrcweir 
83cdf0e10cSrcweir SV_IMPL_PTRARR(SwTOXSortTabBases, SwTOXSortTabBasePtr)
84cdf0e10cSrcweir 
85cdf0e10cSrcweir TYPEINIT2( SwTOXBaseSection, SwTOXBase, SwSection );	// fuers RTTI
86cdf0e10cSrcweir 
87cdf0e10cSrcweir struct LinkStruct
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	SwFmtINetFmt	aINetFmt;
90cdf0e10cSrcweir 	xub_StrLen nStartTextPos, nEndTextPos;
91cdf0e10cSrcweir 
LinkStructLinkStruct92cdf0e10cSrcweir 	LinkStruct( const String& rURL, xub_StrLen nStart, xub_StrLen nEnd )
93cdf0e10cSrcweir 		: aINetFmt( rURL, aEmptyStr),
94cdf0e10cSrcweir 		nStartTextPos( nStart),
95cdf0e10cSrcweir 		nEndTextPos(nEnd) {}
96cdf0e10cSrcweir };
97cdf0e10cSrcweir 
98cdf0e10cSrcweir typedef LinkStruct* LinkStructPtr;
99cdf0e10cSrcweir SV_DECL_PTRARR(LinkStructArr, LinkStructPtr, 0, 5 )
SV_IMPL_PTRARR(LinkStructArr,LinkStructPtr)100cdf0e10cSrcweir SV_IMPL_PTRARR(LinkStructArr, LinkStructPtr)
101cdf0e10cSrcweir 
102cdf0e10cSrcweir sal_uInt16 SwDoc::GetTOIKeys( SwTOIKeyType eTyp, SvStringsSort& rArr ) const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	if( rArr.Count() )
105cdf0e10cSrcweir 		rArr.Remove( sal_uInt16(0), rArr.Count() );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	// dann mal ueber den Pool und alle Primary oder Secondary heraussuchen
108cdf0e10cSrcweir 	const SwTxtTOXMark* pMark;
109cdf0e10cSrcweir 	const SfxPoolItem* pItem;
110cdf0e10cSrcweir     const SwTOXType* pTOXType;
111cdf0e10cSrcweir 	sal_uInt32 i, nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_TOXMARK );
112cdf0e10cSrcweir 	for( i = 0; i < nMaxItems; ++i )
113cdf0e10cSrcweir 		if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_TOXMARK, i ) ) &&
114cdf0e10cSrcweir 			0!= ( pTOXType = ((SwTOXMark*)pItem)->GetTOXType()) &&
115cdf0e10cSrcweir             TOX_INDEX == pTOXType->GetType() &&
116cdf0e10cSrcweir 			0 != ( pMark = ((SwTOXMark*)pItem)->GetTxtTOXMark() ) &&
117cdf0e10cSrcweir 			pMark->GetpTxtNd() &&
118cdf0e10cSrcweir 			pMark->GetpTxtNd()->GetNodes().IsDocNodes() )
119cdf0e10cSrcweir 		{
120cdf0e10cSrcweir 			const String* pStr;
121cdf0e10cSrcweir 			if( TOI_PRIMARY == eTyp )
122cdf0e10cSrcweir 				pStr = &((SwTOXMark*)pItem)->GetPrimaryKey();
123cdf0e10cSrcweir 			else
124cdf0e10cSrcweir 				pStr = &((SwTOXMark*)pItem)->GetSecondaryKey();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 			if( pStr->Len() )
127cdf0e10cSrcweir 				rArr.Insert( (StringPtr)pStr );
128cdf0e10cSrcweir 		}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	return rArr.Count();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir /*--------------------------------------------------------------------
134cdf0e10cSrcweir 	 Beschreibung: aktuelle Verzeichnismarkierungen ermitteln
135cdf0e10cSrcweir  --------------------------------------------------------------------*/
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
GetCurTOXMark(const SwPosition & rPos,SwTOXMarks & rArr) const138cdf0e10cSrcweir sal_uInt16 SwDoc::GetCurTOXMark( const SwPosition& rPos,
139cdf0e10cSrcweir 								SwTOXMarks& rArr ) const
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     // search on Position rPos for all SwTOXMarks
142cdf0e10cSrcweir     SwTxtNode *const pTxtNd = rPos.nNode.GetNode().GetTxtNode();
143cdf0e10cSrcweir 	if( !pTxtNd || !pTxtNd->GetpSwpHints() )
144cdf0e10cSrcweir 		return 0;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	const SwpHints & rHts = *pTxtNd->GetpSwpHints();
147cdf0e10cSrcweir 	const SwTxtAttr* pHt;
148cdf0e10cSrcweir 	xub_StrLen nSttIdx;
149cdf0e10cSrcweir 	const xub_StrLen *pEndIdx;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	xub_StrLen nAktPos = rPos.nContent.GetIndex();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < rHts.Count(); ++n )
154cdf0e10cSrcweir 	{
155cdf0e10cSrcweir 		if( RES_TXTATR_TOXMARK != (pHt = rHts[n])->Which() )
156cdf0e10cSrcweir 			continue;
157cdf0e10cSrcweir 		if( ( nSttIdx = *pHt->GetStart() ) < nAktPos )
158cdf0e10cSrcweir 		{
159cdf0e10cSrcweir 			// pruefe Ende mit ab
16069a74367SOliver-Rainer Wittmann 			if( 0 == ( pEndIdx = pHt->End() ) ||
161cdf0e10cSrcweir 				*pEndIdx <= nAktPos )
162cdf0e10cSrcweir 				continue;		// weiter suchen
163cdf0e10cSrcweir 		}
164cdf0e10cSrcweir 		else if( nSttIdx > nAktPos )
165cdf0e10cSrcweir 			// ist Start vom Hint groesser als rPos, dann abbrechen. Denn
166cdf0e10cSrcweir 			// die Attribute sind nach Start sortiert !
167cdf0e10cSrcweir 			break;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 		const SwTOXMark* pTMark = &pHt->GetTOXMark();
170cdf0e10cSrcweir 		rArr.Insert( pTMark, rArr.Count() );
171cdf0e10cSrcweir 	}
172cdf0e10cSrcweir 	return rArr.Count();
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir /*--------------------------------------------------------------------
176cdf0e10cSrcweir 	 Beschreibung: Marke loeschen
177cdf0e10cSrcweir  --------------------------------------------------------------------*/
178cdf0e10cSrcweir 
DeleteTOXMark(const SwTOXMark * pTOXMark)179cdf0e10cSrcweir void SwDoc::DeleteTOXMark( const SwTOXMark* pTOXMark )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	// hole den TextNode und
182cdf0e10cSrcweir     const SwTxtTOXMark* pTxtTOXMark = pTOXMark->GetTxtTOXMark();
183cdf0e10cSrcweir 	ASSERT( pTxtTOXMark, "Kein TxtTOXMark, kann nicht geloescht werden" );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     SwTxtNode& rTxtNd = const_cast<SwTxtNode&>(pTxtTOXMark->GetTxtNode());
186cdf0e10cSrcweir 	ASSERT( rTxtNd.GetpSwpHints(), "kann nicht geloescht werden" );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     if (GetIDocumentUndoRedo().DoesUndo())
189cdf0e10cSrcweir     {
190cdf0e10cSrcweir         // save attributes for Undo
191cdf0e10cSrcweir         SwUndoResetAttr* pUndo = new SwUndoResetAttr(
192cdf0e10cSrcweir             SwPosition( rTxtNd, SwIndex( &rTxtNd, *pTxtTOXMark->GetStart() ) ),
193cdf0e10cSrcweir             RES_TXTATR_TOXMARK );
194cdf0e10cSrcweir         GetIDocumentUndoRedo().AppendUndo( pUndo );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         SwRegHistory aRHst( rTxtNd, &pUndo->GetHistory() );
197cdf0e10cSrcweir 		rTxtNd.GetpSwpHints()->Register( &aRHst );
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     rTxtNd.DeleteAttribute( const_cast<SwTxtTOXMark*>(pTxtTOXMark) );
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     if (GetIDocumentUndoRedo().DoesUndo())
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         if( rTxtNd.GetpSwpHints() )
205cdf0e10cSrcweir 			rTxtNd.GetpSwpHints()->DeRegister();
206cdf0e10cSrcweir 	}
207cdf0e10cSrcweir 	SetModified();
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir /*--------------------------------------------------------------------
211cdf0e10cSrcweir 	 Beschreibung: Traveln zwischen TOXMarks
212cdf0e10cSrcweir  --------------------------------------------------------------------*/
213cdf0e10cSrcweir 
214cdf0e10cSrcweir class CompareNodeCntnt
215cdf0e10cSrcweir {
216cdf0e10cSrcweir 	sal_uLong nNode;
217cdf0e10cSrcweir 	xub_StrLen nCntnt;
218cdf0e10cSrcweir public:
CompareNodeCntnt(sal_uLong nNd,xub_StrLen nCnt)219cdf0e10cSrcweir 	CompareNodeCntnt( sal_uLong nNd, xub_StrLen nCnt )
220cdf0e10cSrcweir 		: nNode( nNd ), nCntnt( nCnt ) {}
221cdf0e10cSrcweir 
operator ==(const CompareNodeCntnt & rCmp)222cdf0e10cSrcweir 	int operator==( const CompareNodeCntnt& rCmp )
223cdf0e10cSrcweir 		{ return nNode == rCmp.nNode && nCntnt == rCmp.nCntnt; }
operator !=(const CompareNodeCntnt & rCmp)224cdf0e10cSrcweir 	int operator!=( const CompareNodeCntnt& rCmp )
225cdf0e10cSrcweir 		{ return nNode != rCmp.nNode || nCntnt != rCmp.nCntnt; }
operator <(const CompareNodeCntnt & rCmp)226cdf0e10cSrcweir 	int operator< ( const CompareNodeCntnt& rCmp )
227cdf0e10cSrcweir 		{ return nNode < rCmp.nNode ||
228cdf0e10cSrcweir 			( nNode == rCmp.nNode && nCntnt < rCmp.nCntnt); }
operator <=(const CompareNodeCntnt & rCmp)229cdf0e10cSrcweir 	int operator<=( const CompareNodeCntnt& rCmp )
230cdf0e10cSrcweir 		{ return nNode < rCmp.nNode ||
231cdf0e10cSrcweir 			( nNode == rCmp.nNode && nCntnt <= rCmp.nCntnt); }
operator >(const CompareNodeCntnt & rCmp)232cdf0e10cSrcweir 	int operator> ( const CompareNodeCntnt& rCmp )
233cdf0e10cSrcweir 		{ return nNode > rCmp.nNode ||
234cdf0e10cSrcweir 			( nNode == rCmp.nNode && nCntnt > rCmp.nCntnt); }
operator >=(const CompareNodeCntnt & rCmp)235cdf0e10cSrcweir 	int operator>=( const CompareNodeCntnt& rCmp )
236cdf0e10cSrcweir 		{ return nNode > rCmp.nNode ||
237cdf0e10cSrcweir 			( nNode == rCmp.nNode && nCntnt >= rCmp.nCntnt); }
238cdf0e10cSrcweir };
239cdf0e10cSrcweir 
GotoTOXMark(const SwTOXMark & rCurTOXMark,SwTOXSearch eDir,sal_Bool bInReadOnly)240cdf0e10cSrcweir const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
241cdf0e10cSrcweir 									SwTOXSearch eDir, sal_Bool bInReadOnly )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir 	const SwTxtTOXMark* pMark = rCurTOXMark.GetTxtTOXMark();
244cdf0e10cSrcweir 	ASSERT(pMark, "pMark==0 Ungueltige TxtTOXMark");
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	const SwTxtNode *pTOXSrc = pMark->GetpTxtNd();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 	CompareNodeCntnt aAbsIdx( pTOXSrc->GetIndex(), *pMark->GetStart() );
249cdf0e10cSrcweir 	CompareNodeCntnt aPrevPos( 0, 0 );
250cdf0e10cSrcweir 	CompareNodeCntnt aNextPos( ULONG_MAX, STRING_NOTFOUND );
251cdf0e10cSrcweir 	CompareNodeCntnt aMax( 0, 0 );
252cdf0e10cSrcweir 	CompareNodeCntnt aMin( ULONG_MAX, STRING_NOTFOUND );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	const SwTOXMark*	pNew	= 0;
255cdf0e10cSrcweir 	const SwTOXMark*	pMax	= &rCurTOXMark;
256cdf0e10cSrcweir 	const SwTOXMark*	pMin	= &rCurTOXMark;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	const SwTOXType* pType = rCurTOXMark.GetTOXType();
259cdf0e10cSrcweir     SwTOXMarks aMarks;
260cdf0e10cSrcweir     SwTOXMark::InsertTOXMarks( aMarks, *pType );
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 	const SwTOXMark* pTOXMark;
263cdf0e10cSrcweir 	const SwCntntFrm* pCFrm;
264cdf0e10cSrcweir 	Point aPt;
26569a74367SOliver-Rainer Wittmann 	for( sal_uInt16 nMark=0; nMark<aMarks.Count(); nMark++ )
266cdf0e10cSrcweir 	{
267cdf0e10cSrcweir         pTOXMark = aMarks[nMark];
268cdf0e10cSrcweir 		if( pTOXMark != &rCurTOXMark &&
269cdf0e10cSrcweir 			0 != ( pMark = pTOXMark->GetTxtTOXMark()) &&
270cdf0e10cSrcweir 			0 != ( pTOXSrc = pMark->GetpTxtNd() ) &&
271cdf0e10cSrcweir 			0 != ( pCFrm = pTOXSrc->getLayoutFrm( GetCurrentLayout(), &aPt, 0, sal_False )) &&
272cdf0e10cSrcweir 			( bInReadOnly || !pCFrm->IsProtected() ))
273cdf0e10cSrcweir 		{
274cdf0e10cSrcweir 			CompareNodeCntnt aAbsNew( pTOXSrc->GetIndex(), *pMark->GetStart() );
275cdf0e10cSrcweir 			switch( eDir )
276cdf0e10cSrcweir 			{
277cdf0e10cSrcweir 				//Die untenstehenden etwas komplizierter ausgefallen Ausdruecke
278cdf0e10cSrcweir 				//dienen dazu auch ueber Eintraege auf der selben (!) Position
279cdf0e10cSrcweir 				//traveln zu koennen. Wenn einer Zeit hat mag er sie mal
280cdf0e10cSrcweir 				//optimieren.
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 			case TOX_SAME_PRV:
283cdf0e10cSrcweir 				if( pTOXMark->GetText() != rCurTOXMark.GetText() )
284cdf0e10cSrcweir 					break;
285cdf0e10cSrcweir 				/* no break here */
286cdf0e10cSrcweir 			case TOX_PRV:
287cdf0e10cSrcweir 				if ( (aAbsNew < aAbsIdx && aAbsNew > aPrevPos &&
288cdf0e10cSrcweir 					  aPrevPos != aAbsIdx && aAbsNew != aAbsIdx ) ||
289cdf0e10cSrcweir 					 (aAbsIdx == aAbsNew &&
290cdf0e10cSrcweir 					  (sal_uLong(&rCurTOXMark) > sal_uLong(pTOXMark) &&
291cdf0e10cSrcweir 					   (!pNew ||
292cdf0e10cSrcweir 						(pNew && (aPrevPos < aAbsIdx ||
293cdf0e10cSrcweir 								  sal_uLong(pNew) < sal_uLong(pTOXMark)))))) ||
294cdf0e10cSrcweir 					 (aPrevPos == aAbsNew && aAbsIdx != aAbsNew &&
295cdf0e10cSrcweir 					  sal_uLong(pTOXMark) > sal_uLong(pNew)) )
296cdf0e10cSrcweir 				{
297cdf0e10cSrcweir 					pNew = pTOXMark;
298cdf0e10cSrcweir 					aPrevPos = aAbsNew;
299cdf0e10cSrcweir 					if ( aAbsNew >= aMax )
300cdf0e10cSrcweir 					{
301cdf0e10cSrcweir 						aMax = aAbsNew;
302cdf0e10cSrcweir 						pMax = pTOXMark;
303cdf0e10cSrcweir 					}
304cdf0e10cSrcweir 				}
305cdf0e10cSrcweir 				break;
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 			case TOX_SAME_NXT:
308cdf0e10cSrcweir 				if( pTOXMark->GetText() != rCurTOXMark.GetText() )
309cdf0e10cSrcweir 					break;
310cdf0e10cSrcweir 				/* no break here */
311cdf0e10cSrcweir 			case TOX_NXT:
312cdf0e10cSrcweir 				if ( (aAbsNew > aAbsIdx && aAbsNew < aNextPos &&
313cdf0e10cSrcweir 					  aNextPos != aAbsIdx && aAbsNew != aAbsIdx ) ||
314cdf0e10cSrcweir 					 (aAbsIdx == aAbsNew &&
315cdf0e10cSrcweir 					  (sal_uLong(&rCurTOXMark) < sal_uLong(pTOXMark) &&
316cdf0e10cSrcweir 					   (!pNew ||
317cdf0e10cSrcweir 						(pNew && (aNextPos > aAbsIdx ||
318cdf0e10cSrcweir 								  sal_uLong(pNew) > sal_uLong(pTOXMark)))))) ||
319cdf0e10cSrcweir 					 (aNextPos == aAbsNew && aAbsIdx != aAbsNew &&
320cdf0e10cSrcweir 					  sal_uLong(pTOXMark) < sal_uLong(pNew)) )
321cdf0e10cSrcweir 				{
322cdf0e10cSrcweir 					pNew = pTOXMark;
323cdf0e10cSrcweir 					aNextPos = aAbsNew;
324cdf0e10cSrcweir 					if ( aAbsNew <= aMin )
325cdf0e10cSrcweir 					{
326cdf0e10cSrcweir 						aMin = aAbsNew;
327cdf0e10cSrcweir 						pMin = pTOXMark;
328cdf0e10cSrcweir 					}
329cdf0e10cSrcweir 				}
330cdf0e10cSrcweir 				break;
331cdf0e10cSrcweir 			}
332cdf0e10cSrcweir 		}
333cdf0e10cSrcweir 	}
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	// kein Nachfolger wurde gefunden
337cdf0e10cSrcweir 	// Min oder Max benutzen
338cdf0e10cSrcweir 	if(!pNew)
339cdf0e10cSrcweir 	{
340cdf0e10cSrcweir 		switch(eDir)
341cdf0e10cSrcweir 		{
342cdf0e10cSrcweir 		case TOX_PRV:
343cdf0e10cSrcweir 		case TOX_SAME_PRV:
344cdf0e10cSrcweir 			pNew = pMax;
345cdf0e10cSrcweir 			break;
346cdf0e10cSrcweir 		case TOX_NXT:
347cdf0e10cSrcweir 		case TOX_SAME_NXT:
348cdf0e10cSrcweir 			pNew = pMin;
349cdf0e10cSrcweir 			break;
350cdf0e10cSrcweir 		default:
351cdf0e10cSrcweir 			pNew = &rCurTOXMark;
352cdf0e10cSrcweir 		}
353cdf0e10cSrcweir 	}
354cdf0e10cSrcweir 	return *pNew;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 
InsertTableOf(const SwPosition & rPos,const SwTOXBase & rTOX,const SfxItemSet * pSet,sal_Bool bExpand)358cdf0e10cSrcweir const SwTOXBaseSection* SwDoc::InsertTableOf( const SwPosition& rPos,
359cdf0e10cSrcweir 												const SwTOXBase& rTOX,
360cdf0e10cSrcweir 												const SfxItemSet* pSet,
361cdf0e10cSrcweir 												sal_Bool bExpand )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir     GetIDocumentUndoRedo().StartUndo( UNDO_INSTOX, NULL );
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	String sSectNm( rTOX.GetTOXName() );
366cdf0e10cSrcweir 	sSectNm = GetUniqueTOXBaseName( *rTOX.GetTOXType(), &sSectNm );
367cdf0e10cSrcweir 	SwPaM aPam( rPos );
368cdf0e10cSrcweir     SwSectionData aSectionData( TOX_CONTENT_SECTION, sSectNm );
369cdf0e10cSrcweir     SwTOXBaseSection *const pNewSection = dynamic_cast<SwTOXBaseSection *>(
370cdf0e10cSrcweir         InsertSwSection( aPam, aSectionData, & rTOX, pSet, false ));
371cdf0e10cSrcweir     if (pNewSection)
372cdf0e10cSrcweir     {
373cdf0e10cSrcweir         SwSectionNode *const pSectNd = pNewSection->GetFmt()->GetSectionNode();
374cdf0e10cSrcweir         pNewSection->SetTOXName(sSectNm); // rTOX may have had no name...
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 		if( bExpand )
377cdf0e10cSrcweir         {
378cdf0e10cSrcweir             // OD 19.03.2003 #106329# - add value for 2nd parameter = true to
379cdf0e10cSrcweir             // indicate, that a creation of a new table of content has to be performed.
380cdf0e10cSrcweir             // Value of 1st parameter = default value.
381cdf0e10cSrcweir             pNewSection->Update( 0, true );
382cdf0e10cSrcweir         }
383cdf0e10cSrcweir 		else if( 1 == rTOX.GetTitle().Len() && IsInReading() )
384cdf0e10cSrcweir 		// insert title of TOX
385cdf0e10cSrcweir 		{
386cdf0e10cSrcweir 			// then insert the headline section
387cdf0e10cSrcweir 			SwNodeIndex aIdx( *pSectNd, +1 );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 			SwTxtNode* pHeadNd = GetNodes().MakeTxtNode( aIdx,
390cdf0e10cSrcweir 							GetTxtCollFromPool( RES_POOLCOLL_STANDARD ) );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir             String sNm( pNewSection->GetTOXName() );
393cdf0e10cSrcweir // ??Resource
394cdf0e10cSrcweir sNm.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "_Head" ));
395cdf0e10cSrcweir 
396cdf0e10cSrcweir             SwSectionData headerData( TOX_HEADER_SECTION, sNm );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 			SwNodeIndex aStt( *pHeadNd ); aIdx--;
399cdf0e10cSrcweir 			SwSectionFmt* pSectFmt = MakeSectionFmt( 0 );
400cdf0e10cSrcweir             GetNodes().InsertTextSection(
401cdf0e10cSrcweir                     aStt, *pSectFmt, headerData, 0, &aIdx, true, false);
402cdf0e10cSrcweir         }
403cdf0e10cSrcweir     }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     GetIDocumentUndoRedo().EndUndo( UNDO_INSTOX, NULL );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     return pNewSection;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 
InsertTableOf(sal_uLong nSttNd,sal_uLong nEndNd,const SwTOXBase & rTOX,const SfxItemSet * pSet)412cdf0e10cSrcweir const SwTOXBaseSection* SwDoc::InsertTableOf( sal_uLong nSttNd, sal_uLong nEndNd,
413cdf0e10cSrcweir 												const SwTOXBase& rTOX,
414cdf0e10cSrcweir 												const SfxItemSet* pSet )
415cdf0e10cSrcweir {
416cdf0e10cSrcweir 	// check for recursiv TOX
417cdf0e10cSrcweir 	SwNode* pNd = GetNodes()[ nSttNd ];
418cdf0e10cSrcweir 	SwSectionNode* pSectNd = pNd->FindSectionNode();
419cdf0e10cSrcweir 	while( pSectNd )
420cdf0e10cSrcweir 	{
421cdf0e10cSrcweir 		SectionType eT = pSectNd->GetSection().GetType();
422cdf0e10cSrcweir 		if( TOX_HEADER_SECTION == eT || TOX_CONTENT_SECTION == eT )
423cdf0e10cSrcweir 			return 0;
424cdf0e10cSrcweir         pSectNd = pSectNd->StartOfSectionNode()->FindSectionNode();
425cdf0e10cSrcweir 	}
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 	String sSectNm( rTOX.GetTOXName() );
428cdf0e10cSrcweir 	sSectNm = GetUniqueTOXBaseName(*rTOX.GetTOXType(), &sSectNm);
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     SwSectionData aSectionData( TOX_CONTENT_SECTION, sSectNm );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	SwNodeIndex aStt( GetNodes(), nSttNd ), aEnd( GetNodes(), nEndNd );
433cdf0e10cSrcweir 	SwSectionFmt* pFmt = MakeSectionFmt( 0 );
434cdf0e10cSrcweir 	if(pSet)
435cdf0e10cSrcweir         pFmt->SetFmtAttr(*pSet);
436cdf0e10cSrcweir 
437cdf0e10cSrcweir //	--aEnd;		// im InsertSection ist Ende inclusive
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     SwSectionNode *const pNewSectionNode =
440cdf0e10cSrcweir         GetNodes().InsertTextSection(aStt, *pFmt, aSectionData, &rTOX, &aEnd);
441cdf0e10cSrcweir     if (!pNewSectionNode)
442cdf0e10cSrcweir     {
443cdf0e10cSrcweir 		DelSectionFmt( pFmt );
444cdf0e10cSrcweir         return 0;
445cdf0e10cSrcweir     }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     SwTOXBaseSection *const pNewSection(
448cdf0e10cSrcweir         dynamic_cast<SwTOXBaseSection*>(& pNewSectionNode->GetSection()));
449cdf0e10cSrcweir     pNewSection->SetTOXName(sSectNm); // rTOX may have had no name...
450cdf0e10cSrcweir     return pNewSection;
451cdf0e10cSrcweir }
452cdf0e10cSrcweir 
453cdf0e10cSrcweir /*--------------------------------------------------------------------
454cdf0e10cSrcweir 	 Beschreibung: Aktuelles Verzeichnis ermitteln
455cdf0e10cSrcweir  --------------------------------------------------------------------*/
456cdf0e10cSrcweir 
GetCurTOX(const SwPosition & rPos) const457cdf0e10cSrcweir const SwTOXBase* SwDoc::GetCurTOX( const SwPosition& rPos ) const
458cdf0e10cSrcweir {
459cdf0e10cSrcweir 	const SwNode& rNd = rPos.nNode.GetNode();
460cdf0e10cSrcweir 	const SwSectionNode* pSectNd = rNd.FindSectionNode();
461cdf0e10cSrcweir 	while( pSectNd )
462cdf0e10cSrcweir 	{
463cdf0e10cSrcweir 		SectionType eT = pSectNd->GetSection().GetType();
464cdf0e10cSrcweir 		if( TOX_CONTENT_SECTION == eT )
465cdf0e10cSrcweir 		{
466cdf0e10cSrcweir 			ASSERT( pSectNd->GetSection().ISA( SwTOXBaseSection ),
467cdf0e10cSrcweir 					"keine TOXBaseSection!" );
468cdf0e10cSrcweir 			SwTOXBaseSection& rTOXSect = (SwTOXBaseSection&)
469cdf0e10cSrcweir 												pSectNd->GetSection();
470cdf0e10cSrcweir 			return &rTOXSect;
471cdf0e10cSrcweir 		}
472cdf0e10cSrcweir         pSectNd = pSectNd->StartOfSectionNode()->FindSectionNode();
473cdf0e10cSrcweir 	}
474cdf0e10cSrcweir 	return 0;
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
GetTOXBaseAttrSet(const SwTOXBase & rTOXBase) const477cdf0e10cSrcweir const SwAttrSet& SwDoc::GetTOXBaseAttrSet(const SwTOXBase& rTOXBase) const
478cdf0e10cSrcweir {
479cdf0e10cSrcweir 	ASSERT( rTOXBase.ISA( SwTOXBaseSection ), "no TOXBaseSection!" );
480cdf0e10cSrcweir 	const SwTOXBaseSection& rTOXSect = (const SwTOXBaseSection&)rTOXBase;
481cdf0e10cSrcweir 	SwSectionFmt* pFmt = rTOXSect.GetFmt();
482cdf0e10cSrcweir 	ASSERT( pFmt, "invalid TOXBaseSection!" );
483cdf0e10cSrcweir 	return pFmt->GetAttrSet();
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
GetDefaultTOXBase(TOXTypes eTyp,sal_Bool bCreate)486cdf0e10cSrcweir const SwTOXBase* SwDoc::GetDefaultTOXBase( TOXTypes eTyp, sal_Bool bCreate )
487cdf0e10cSrcweir {
488cdf0e10cSrcweir     SwTOXBase** prBase = 0;
489cdf0e10cSrcweir 	switch(eTyp)
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 	case  TOX_CONTENT: 			prBase = &pDefTOXBases->pContBase; break;
492cdf0e10cSrcweir 	case  TOX_INDEX:            prBase = &pDefTOXBases->pIdxBase;  break;
493cdf0e10cSrcweir 	case  TOX_USER:             prBase = &pDefTOXBases->pUserBase; break;
494cdf0e10cSrcweir 	case  TOX_TABLES:           prBase = &pDefTOXBases->pTblBase;  break;
495cdf0e10cSrcweir 	case  TOX_OBJECTS:          prBase = &pDefTOXBases->pObjBase;  break;
496cdf0e10cSrcweir 	case  TOX_ILLUSTRATIONS:    prBase = &pDefTOXBases->pIllBase;  break;
497cdf0e10cSrcweir 	case  TOX_AUTHORITIES:		prBase = &pDefTOXBases->pAuthBase; break;
498cdf0e10cSrcweir 	}
499cdf0e10cSrcweir 	if(!(*prBase) && bCreate)
500cdf0e10cSrcweir 	{
501cdf0e10cSrcweir 		SwForm aForm(eTyp);
502cdf0e10cSrcweir 		const SwTOXType* pType = GetTOXType(eTyp, 0);
503cdf0e10cSrcweir 		(*prBase) = new SwTOXBase(pType, aForm, 0, pType->GetTypeName());
504cdf0e10cSrcweir 	}
505cdf0e10cSrcweir 	return (*prBase);
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
SetDefaultTOXBase(const SwTOXBase & rBase)508cdf0e10cSrcweir void	SwDoc::SetDefaultTOXBase(const SwTOXBase& rBase)
509cdf0e10cSrcweir {
510cdf0e10cSrcweir     SwTOXBase** prBase = 0;
511cdf0e10cSrcweir 	switch(rBase.GetType())
512cdf0e10cSrcweir 	{
513cdf0e10cSrcweir 	case  TOX_CONTENT: 			prBase = &pDefTOXBases->pContBase; break;
514cdf0e10cSrcweir 	case  TOX_INDEX:            prBase = &pDefTOXBases->pIdxBase;  break;
515cdf0e10cSrcweir 	case  TOX_USER:             prBase = &pDefTOXBases->pUserBase; break;
516cdf0e10cSrcweir 	case  TOX_TABLES:           prBase = &pDefTOXBases->pTblBase;  break;
517cdf0e10cSrcweir 	case  TOX_OBJECTS:          prBase = &pDefTOXBases->pObjBase;  break;
518cdf0e10cSrcweir 	case  TOX_ILLUSTRATIONS:    prBase = &pDefTOXBases->pIllBase;  break;
519cdf0e10cSrcweir 	case  TOX_AUTHORITIES:		prBase = &pDefTOXBases->pAuthBase; break;
520cdf0e10cSrcweir 	}
521cdf0e10cSrcweir 	if(*prBase)
522cdf0e10cSrcweir 		delete (*prBase);
523cdf0e10cSrcweir 	(*prBase) = new SwTOXBase(rBase);
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir /*--------------------------------------------------------------------
527cdf0e10cSrcweir 	 Beschreibung: Verzeichnis loeschen
528cdf0e10cSrcweir  --------------------------------------------------------------------*/
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 
DeleteTOX(const SwTOXBase & rTOXBase,sal_Bool bDelNodes)531cdf0e10cSrcweir sal_Bool SwDoc::DeleteTOX( const SwTOXBase& rTOXBase, sal_Bool bDelNodes )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir     // its only delete the TOX, not the nodes
534cdf0e10cSrcweir     sal_Bool bRet = sal_False;
535cdf0e10cSrcweir     ASSERT( rTOXBase.ISA( SwTOXBaseSection ), "keine TOXBaseSection!" );
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     const SwTOXBaseSection& rTOXSect = (const SwTOXBaseSection&)rTOXBase;
538cdf0e10cSrcweir     SwSectionFmt* pFmt = rTOXSect.GetFmt();
539cdf0e10cSrcweir     if( pFmt )
540cdf0e10cSrcweir     {
541cdf0e10cSrcweir         GetIDocumentUndoRedo().StartUndo( UNDO_CLEARTOXRANGE, NULL );
542cdf0e10cSrcweir 
543cdf0e10cSrcweir 		/* Save the start node of the TOX' section. */
544cdf0e10cSrcweir 		SwSectionNode * pMyNode = pFmt->GetSectionNode();
545cdf0e10cSrcweir 		/* Save start node of section's surrounding. */
546cdf0e10cSrcweir         SwNode * pStartNd = pMyNode->StartOfSectionNode();
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 		/* Look for point where to move the cursors in the area to
549cdf0e10cSrcweir 		   delete to. This is done by first searching forward from the
550cdf0e10cSrcweir 		   end of the TOX' section. If no content node is found behind
551cdf0e10cSrcweir 		   the TOX one is searched before it. If this is not
552cdf0e10cSrcweir 		   successfull, too, insert new text node behind the end of
553cdf0e10cSrcweir 		   the TOX' section. The cursors from the TOX' section will be
554cdf0e10cSrcweir 		   moved to the content node found or the new text node. */
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 		/* Set PaM to end of TOX' section and search following content node.
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 		   aSearchPam will contain the point where to move the cursors
559cdf0e10cSrcweir 		   to. */
560cdf0e10cSrcweir 		SwPaM aSearchPam(*pMyNode->EndOfSectionNode());
561cdf0e10cSrcweir         SwPosition aEndPos(*pStartNd->EndOfSectionNode());
562cdf0e10cSrcweir 		if (! aSearchPam.Move() /* no content node found */
563cdf0e10cSrcweir 			|| *aSearchPam.GetPoint() >= aEndPos /* content node found
564cdf0e10cSrcweir 													outside surrounding */
565cdf0e10cSrcweir 			)
566cdf0e10cSrcweir 		{
567cdf0e10cSrcweir 			/* Set PaM to beginning of TOX' section and search previous
568cdf0e10cSrcweir 			   content node */
569cdf0e10cSrcweir 			SwPaM aTmpPam(*pMyNode);
570cdf0e10cSrcweir 			aSearchPam = aTmpPam;
571cdf0e10cSrcweir             SwPosition aStartPos(*pStartNd);
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 			if ( ! aSearchPam.Move(fnMoveBackward) /* no content node found */
574cdf0e10cSrcweir 				 || *aSearchPam.GetPoint() <= aStartPos  /* content node
575cdf0e10cSrcweir 															found outside
576cdf0e10cSrcweir 															surrounding */
577cdf0e10cSrcweir 				 )
578cdf0e10cSrcweir 			{
579cdf0e10cSrcweir 				/* There is no content node in the surrounding of
580cdf0e10cSrcweir 				   TOX'. Append text node behind TOX' section. */
581cdf0e10cSrcweir 
582cdf0e10cSrcweir                 SwPosition aInsPos(*pMyNode->EndOfSectionNode());
583cdf0e10cSrcweir 				AppendTxtNode(aInsPos);
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 				SwPaM aTmpPam1(aInsPos);
586cdf0e10cSrcweir 				aSearchPam = aTmpPam1;
587cdf0e10cSrcweir 			}
588cdf0e10cSrcweir 		}
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 		/* PaM containing the TOX. */
592cdf0e10cSrcweir 		SwPaM aPam(*pMyNode->EndOfSectionNode(), *pMyNode);
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 		/* Move cursors contained in TOX to point determined above. */
595cdf0e10cSrcweir 		PaMCorrAbs(aPam, *aSearchPam.GetPoint());
596cdf0e10cSrcweir 
597cdf0e10cSrcweir 		if( !bDelNodes )
598cdf0e10cSrcweir 		{
599cdf0e10cSrcweir 			SwSections aArr( 0, 4 );
600cdf0e10cSrcweir 			sal_uInt16 nCnt = pFmt->GetChildSections( aArr, SORTSECT_NOT, sal_False );
601cdf0e10cSrcweir 			for( sal_uInt16 n = 0; n < nCnt; ++n )
602cdf0e10cSrcweir 			{
603cdf0e10cSrcweir 				SwSection* pSect = aArr[ n ];
604cdf0e10cSrcweir 				if( TOX_HEADER_SECTION == pSect->GetType() )
605cdf0e10cSrcweir 				{
606cdf0e10cSrcweir 					DelSectionFmt( pSect->GetFmt(), bDelNodes );
607cdf0e10cSrcweir 				}
608cdf0e10cSrcweir 			}
609cdf0e10cSrcweir 		}
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 		DelSectionFmt( pFmt, bDelNodes );
612cdf0e10cSrcweir 
613cdf0e10cSrcweir         GetIDocumentUndoRedo().EndUndo( UNDO_CLEARTOXRANGE, NULL );
614cdf0e10cSrcweir 		bRet = sal_True;
615cdf0e10cSrcweir     }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir     return bRet;
618cdf0e10cSrcweir }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir /*--------------------------------------------------------------------
621cdf0e10cSrcweir 	 Beschreibung:	Verzeichnistypen verwalten
622cdf0e10cSrcweir  --------------------------------------------------------------------*/
623cdf0e10cSrcweir 
GetTOXTypeCount(TOXTypes eTyp) const624cdf0e10cSrcweir sal_uInt16 SwDoc::GetTOXTypeCount(TOXTypes eTyp) const
625cdf0e10cSrcweir {
626cdf0e10cSrcweir 	const SwTOXTypePtr * ppTTypes = pTOXTypes->GetData();
627cdf0e10cSrcweir 	sal_uInt16 nCnt = 0;
628cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < pTOXTypes->Count(); ++n, ++ppTTypes )
629cdf0e10cSrcweir 		if( eTyp == (*ppTTypes)->GetType() )
630cdf0e10cSrcweir 			++nCnt;
631cdf0e10cSrcweir 	return nCnt;
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
GetTOXType(TOXTypes eTyp,sal_uInt16 nId) const634cdf0e10cSrcweir const SwTOXType* SwDoc::GetTOXType( TOXTypes eTyp, sal_uInt16 nId ) const
635cdf0e10cSrcweir {
636cdf0e10cSrcweir 	const SwTOXTypePtr * ppTTypes = pTOXTypes->GetData();
637cdf0e10cSrcweir 	sal_uInt16 nCnt = 0;
638cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < pTOXTypes->Count(); ++n, ++ppTTypes )
639cdf0e10cSrcweir 		if( eTyp == (*ppTTypes)->GetType() && nCnt++ == nId )
640cdf0e10cSrcweir 			return (*ppTTypes);
641cdf0e10cSrcweir 	return 0;
642cdf0e10cSrcweir }
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 
InsertTOXType(const SwTOXType & rTyp)645cdf0e10cSrcweir const SwTOXType* SwDoc::InsertTOXType( const SwTOXType& rTyp )
646cdf0e10cSrcweir {
647cdf0e10cSrcweir 	SwTOXType * pNew = new SwTOXType( rTyp );
648cdf0e10cSrcweir 	pTOXTypes->Insert( pNew, pTOXTypes->Count() );
649cdf0e10cSrcweir 	return pNew;
650cdf0e10cSrcweir }
651cdf0e10cSrcweir 
GetUniqueTOXBaseName(const SwTOXType & rType,const String * pChkStr) const652cdf0e10cSrcweir String SwDoc::GetUniqueTOXBaseName( const SwTOXType& rType,
653cdf0e10cSrcweir 									const String* pChkStr ) const
654cdf0e10cSrcweir {
655cdf0e10cSrcweir 	sal_uInt16 n;
656cdf0e10cSrcweir 	const SwSectionNode* pSectNd;
657cdf0e10cSrcweir 	const SwSection* pSect;
658cdf0e10cSrcweir 
659cdf0e10cSrcweir 	if(pChkStr && !pChkStr->Len())
660cdf0e10cSrcweir 		pChkStr = 0;
661cdf0e10cSrcweir 	String aName( rType.GetTypeName() );
662cdf0e10cSrcweir 	xub_StrLen nNmLen = aName.Len();
663cdf0e10cSrcweir 
664cdf0e10cSrcweir     sal_uInt16 nNum = 0;
665cdf0e10cSrcweir     sal_uInt16 nTmp = 0;
666cdf0e10cSrcweir     sal_uInt16 nFlagSize = ( pSectionFmtTbl->Count() / 8 ) +2;
667cdf0e10cSrcweir 	sal_uInt8* pSetFlags = new sal_uInt8[ nFlagSize ];
668cdf0e10cSrcweir 	memset( pSetFlags, 0, nFlagSize );
669cdf0e10cSrcweir 
670cdf0e10cSrcweir 	for( n = 0; n < pSectionFmtTbl->Count(); ++n )
671cdf0e10cSrcweir 		if( 0 != ( pSectNd = (*pSectionFmtTbl)[ n ]->GetSectionNode( sal_False ) )&&
672cdf0e10cSrcweir 			 TOX_CONTENT_SECTION == (pSect = &pSectNd->GetSection())->GetType())
673cdf0e10cSrcweir 		{
674cdf0e10cSrcweir             const String& rNm = pSect->GetSectionName();
675cdf0e10cSrcweir 			if( rNm.Match( aName ) == nNmLen )
676cdf0e10cSrcweir 			{
677cdf0e10cSrcweir 				// Nummer bestimmen und das Flag setzen
678cdf0e10cSrcweir 				nNum = (sal_uInt16)rNm.Copy( nNmLen ).ToInt32();
679cdf0e10cSrcweir 				if( nNum-- && nNum < pSectionFmtTbl->Count() )
680cdf0e10cSrcweir 					pSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 ));
681cdf0e10cSrcweir 			}
682cdf0e10cSrcweir 			if( pChkStr && pChkStr->Equals( rNm ) )
683cdf0e10cSrcweir 				pChkStr = 0;
684cdf0e10cSrcweir 		}
685cdf0e10cSrcweir 
686cdf0e10cSrcweir 	if( !pChkStr )
687cdf0e10cSrcweir 	{
688cdf0e10cSrcweir 		// alle Nummern entsprechend geflag, also bestimme die richtige Nummer
689cdf0e10cSrcweir 		nNum = pSectionFmtTbl->Count();
690cdf0e10cSrcweir 		for( n = 0; n < nFlagSize; ++n )
691cdf0e10cSrcweir 			if( 0xff != ( nTmp = pSetFlags[ n ] ))
692cdf0e10cSrcweir 			{
693cdf0e10cSrcweir 				// also die Nummer bestimmen
694cdf0e10cSrcweir 				nNum = n * 8;
695cdf0e10cSrcweir 				while( nTmp & 1 )
696cdf0e10cSrcweir 					++nNum, nTmp >>= 1;
697cdf0e10cSrcweir 				break;
698cdf0e10cSrcweir 			}
699cdf0e10cSrcweir 	}
700cdf0e10cSrcweir 	delete [] pSetFlags;
701cdf0e10cSrcweir 	if( pChkStr )
702cdf0e10cSrcweir 		return *pChkStr;
703cdf0e10cSrcweir 	return aName += String::CreateFromInt32( ++nNum );
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
SetTOXBaseName(const SwTOXBase & rTOXBase,const String & rName)706cdf0e10cSrcweir sal_Bool SwDoc::SetTOXBaseName(const SwTOXBase& rTOXBase, const String& rName)
707cdf0e10cSrcweir {
708cdf0e10cSrcweir 	ASSERT( rTOXBase.ISA( SwTOXBaseSection ),
709cdf0e10cSrcweir 					"keine TOXBaseSection!" );
710cdf0e10cSrcweir 	SwTOXBaseSection* pTOX = (SwTOXBaseSection*)&rTOXBase;
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 	String sTmp = GetUniqueTOXBaseName(*rTOXBase.GetTOXType(), &rName);
713cdf0e10cSrcweir 	sal_Bool bRet = sTmp == rName;
714cdf0e10cSrcweir 	if(bRet)
715cdf0e10cSrcweir 	{
716cdf0e10cSrcweir 		pTOX->SetTOXName(rName);
717cdf0e10cSrcweir         pTOX->SetSectionName(rName);
718cdf0e10cSrcweir 		SetModified();
719cdf0e10cSrcweir 	}
720cdf0e10cSrcweir 	return bRet;
721cdf0e10cSrcweir }
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 
lcl_FindChapterNode(const SwNode & rNd,sal_uInt8 nLvl=0)724cdf0e10cSrcweir const SwTxtNode* lcl_FindChapterNode( const SwNode& rNd, sal_uInt8 nLvl = 0 )
725cdf0e10cSrcweir {
726cdf0e10cSrcweir 	const SwNode* pNd = &rNd;
727cdf0e10cSrcweir 	if( pNd->GetNodes().GetEndOfExtras().GetIndex() > pNd->GetIndex() )
728cdf0e10cSrcweir 	{
729cdf0e10cSrcweir 		// then find the "Anchor" (Body) position
730cdf0e10cSrcweir 		Point aPt;
731cdf0e10cSrcweir 		SwNode2Layout aNode2Layout( *pNd, pNd->GetIndex() );
732cdf0e10cSrcweir 		const SwFrm* pFrm = aNode2Layout.GetFrm( &aPt, 0, sal_False );
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 		if( pFrm )
735cdf0e10cSrcweir 		{
736cdf0e10cSrcweir 			SwPosition aPos( *pNd );
737cdf0e10cSrcweir 			pNd = GetBodyTxtNode( *pNd->GetDoc(), aPos, *pFrm );
738cdf0e10cSrcweir 			ASSERT( pNd,	"wo steht der Absatz" );
739cdf0e10cSrcweir 		}
740cdf0e10cSrcweir 	}
741cdf0e10cSrcweir 	return pNd ? pNd->FindOutlineNodeOfLevel( nLvl ) : 0;
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 
745cdf0e10cSrcweir /*--------------------------------------------------------------------
746cdf0e10cSrcweir 	 Beschreibung: Verzeichnis-Klasse
747cdf0e10cSrcweir  --------------------------------------------------------------------*/
748cdf0e10cSrcweir 
SwTOXBaseSection(SwTOXBase const & rBase,SwSectionFmt & rFmt)749cdf0e10cSrcweir SwTOXBaseSection::SwTOXBaseSection(SwTOXBase const& rBase, SwSectionFmt & rFmt)
750cdf0e10cSrcweir     : SwTOXBase( rBase )
751cdf0e10cSrcweir     , SwSection( TOX_CONTENT_SECTION, aEmptyStr, rFmt )
752cdf0e10cSrcweir {
753cdf0e10cSrcweir 	SetProtect( rBase.IsProtected() );
754cdf0e10cSrcweir     SetSectionName( GetTOXName() );
755cdf0e10cSrcweir }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 
~SwTOXBaseSection()758cdf0e10cSrcweir SwTOXBaseSection::~SwTOXBaseSection()
759cdf0e10cSrcweir {
7608c441fc6SJian Fang Zhang     aSortArr.DeleteAndDestroy( 0, aSortArr.Count() );  // i120680
761cdf0e10cSrcweir }
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 
SetPosAtStartEnd(SwPosition & rPos,sal_Bool bAtStart) const764cdf0e10cSrcweir sal_Bool SwTOXBaseSection::SetPosAtStartEnd( SwPosition& rPos, sal_Bool bAtStart ) const
765cdf0e10cSrcweir {
766cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
767cdf0e10cSrcweir 	const SwSectionNode* pSectNd = GetFmt()->GetSectionNode();
768cdf0e10cSrcweir 	if( pSectNd )
769cdf0e10cSrcweir 	{
770cdf0e10cSrcweir 		SwCntntNode* pCNd;
771cdf0e10cSrcweir 		xub_StrLen nC = 0;
772cdf0e10cSrcweir 		if( bAtStart )
773cdf0e10cSrcweir 		{
774cdf0e10cSrcweir 			rPos.nNode = *pSectNd;
775cdf0e10cSrcweir 			pCNd = pSectNd->GetDoc()->GetNodes().GoNext( &rPos.nNode );
776cdf0e10cSrcweir 		}
777cdf0e10cSrcweir 		else
778cdf0e10cSrcweir 		{
779cdf0e10cSrcweir 			rPos.nNode = *pSectNd->EndOfSectionNode();
780cdf0e10cSrcweir 			pCNd = pSectNd->GetDoc()->GetNodes().GoPrevious( &rPos.nNode );
781cdf0e10cSrcweir 			if( pCNd ) nC = pCNd->Len();
782cdf0e10cSrcweir 		}
783cdf0e10cSrcweir 		rPos.nContent.Assign( pCNd, nC );
784cdf0e10cSrcweir 		bRet = sal_True;
785cdf0e10cSrcweir 	}
786cdf0e10cSrcweir 	return bRet;
787cdf0e10cSrcweir }
788cdf0e10cSrcweir 
789cdf0e10cSrcweir /*--------------------------------------------------------------------
790cdf0e10cSrcweir 	 Beschreibung: Verzeichnisinhalt zusammensammeln
791cdf0e10cSrcweir  --------------------------------------------------------------------*/
792cdf0e10cSrcweir 
Update(const SfxItemSet * pAttr,const bool _bNewTOX)793cdf0e10cSrcweir void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
794cdf0e10cSrcweir                               const bool        _bNewTOX )//swmodtest 080307
795cdf0e10cSrcweir {
796f66c5aafSOliver-Rainer Wittmann     const SwSectionNode* pSectNd;
797f66c5aafSOliver-Rainer Wittmann     if( !SwTOXBase::GetRegisteredIn()->GetDepends() ||
798f66c5aafSOliver-Rainer Wittmann         !GetFmt() || 0 == (pSectNd = GetFmt()->GetSectionNode() ) ||
799f66c5aafSOliver-Rainer Wittmann         !pSectNd->GetNodes().IsDocNodes() ||
800f66c5aafSOliver-Rainer Wittmann         IsHiddenFlag() )
801f66c5aafSOliver-Rainer Wittmann     {
802f66c5aafSOliver-Rainer Wittmann         return;
803f66c5aafSOliver-Rainer Wittmann     }
804f66c5aafSOliver-Rainer Wittmann 
805f66c5aafSOliver-Rainer Wittmann     if ( !mbKeepExpression )
806f66c5aafSOliver-Rainer Wittmann     {
807f66c5aafSOliver-Rainer Wittmann         maMSTOCExpression = String();
808f66c5aafSOliver-Rainer Wittmann     }
809cdf0e10cSrcweir 
810f66c5aafSOliver-Rainer Wittmann     SwDoc* pDoc = (SwDoc*)pSectNd->GetDoc();
811cdf0e10cSrcweir 
812cdf0e10cSrcweir     DBG_ASSERT(pDoc != NULL, "Where is the document?");
813cdf0e10cSrcweir 
814f66c5aafSOliver-Rainer Wittmann     if(pAttr && pDoc && GetFmt())
815f66c5aafSOliver-Rainer Wittmann         pDoc->ChgFmt(*GetFmt(), *pAttr);
816cdf0e10cSrcweir 
817cdf0e10cSrcweir     // OD 18.03.2003 #106329# - determine default page description, which
818cdf0e10cSrcweir     // will be used by the content nodes, if no approriate one is found.
819cdf0e10cSrcweir     const SwPageDesc* pDefaultPageDesc;
820cdf0e10cSrcweir     {
821cdf0e10cSrcweir         pDefaultPageDesc =
822cdf0e10cSrcweir             pSectNd->GetSection().GetFmt()->GetPageDesc().GetPageDesc();
823cdf0e10cSrcweir         if ( !_bNewTOX && !pDefaultPageDesc )
824cdf0e10cSrcweir         {
825cdf0e10cSrcweir             // determine page description of table-of-content
826cdf0e10cSrcweir             sal_uInt32 nPgDescNdIdx = pSectNd->GetIndex() + 1;
827cdf0e10cSrcweir             sal_uInt32* pPgDescNdIdx = &nPgDescNdIdx;
828cdf0e10cSrcweir             pDefaultPageDesc = pSectNd->FindPageDesc( sal_False, pPgDescNdIdx );
829cdf0e10cSrcweir             if ( nPgDescNdIdx < pSectNd->GetIndex() )
830cdf0e10cSrcweir             {
831cdf0e10cSrcweir                 pDefaultPageDesc = 0;
832cdf0e10cSrcweir             }
833cdf0e10cSrcweir         }
834cdf0e10cSrcweir         // OD 28.04.2003 #109166# - consider end node of content section in the
835cdf0e10cSrcweir         // node array.
836cdf0e10cSrcweir         if ( !pDefaultPageDesc &&
837cdf0e10cSrcweir              ( pSectNd->EndOfSectionNode()->GetIndex() <
838cdf0e10cSrcweir                  (pSectNd->GetNodes().GetEndOfContent().GetIndex() - 1) )
839cdf0e10cSrcweir            )
840cdf0e10cSrcweir         {
841cdf0e10cSrcweir             // determine page description of content after table-of-content
842cdf0e10cSrcweir             SwNodeIndex aIdx( *(pSectNd->EndOfSectionNode()) );
843cdf0e10cSrcweir             const SwCntntNode* pNdAfterTOX = pSectNd->GetNodes().GoNext( &aIdx );
844cdf0e10cSrcweir             const SwAttrSet& aNdAttrSet = pNdAfterTOX->GetSwAttrSet();
845cdf0e10cSrcweir             const SvxBreak eBreak = aNdAttrSet.GetBreak().GetBreak();
846cdf0e10cSrcweir             if ( !( eBreak == SVX_BREAK_PAGE_BEFORE ||
847cdf0e10cSrcweir                     eBreak == SVX_BREAK_PAGE_BOTH )
848cdf0e10cSrcweir                )
849cdf0e10cSrcweir             {
850cdf0e10cSrcweir                 pDefaultPageDesc = pNdAfterTOX->FindPageDesc( sal_False );
851cdf0e10cSrcweir             }
852cdf0e10cSrcweir         }
853cdf0e10cSrcweir         // OD 28.04.2003 #109166# - consider start node of content section in
854cdf0e10cSrcweir         // the node array.
855cdf0e10cSrcweir         if ( !pDefaultPageDesc &&
856cdf0e10cSrcweir              ( pSectNd->GetIndex() >
857cdf0e10cSrcweir                  (pSectNd->GetNodes().GetEndOfContent().StartOfSectionIndex() + 1) )
858cdf0e10cSrcweir            )
859cdf0e10cSrcweir         {
860cdf0e10cSrcweir             // determine page description of content before table-of-content
861cdf0e10cSrcweir             SwNodeIndex aIdx( *pSectNd );
862cdf0e10cSrcweir             pDefaultPageDesc =
863cdf0e10cSrcweir                 pSectNd->GetNodes().GoPrevious( &aIdx )->FindPageDesc( sal_False );
864cdf0e10cSrcweir 
865cdf0e10cSrcweir         }
866cdf0e10cSrcweir         if ( !pDefaultPageDesc )
867cdf0e10cSrcweir         {
868cdf0e10cSrcweir             // determine default page description
869cdf0e10cSrcweir             pDefaultPageDesc =
870cdf0e10cSrcweir                 &const_cast<const SwDoc *>(pDoc)->GetPageDesc( 0 );
871cdf0e10cSrcweir         }
872cdf0e10cSrcweir     }
873cdf0e10cSrcweir 
874cdf0e10cSrcweir     pDoc->SetModified();
875cdf0e10cSrcweir 
876cdf0e10cSrcweir 	// get current Language
877cdf0e10cSrcweir     SwTOXInternational aIntl(  GetLanguage(),
878cdf0e10cSrcweir                                TOX_INDEX == GetTOXType()->GetType() ?
879cdf0e10cSrcweir                                GetOptions() : 0,
880cdf0e10cSrcweir                                GetSortAlgorithm() );
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 	aSortArr.DeleteAndDestroy( 0, aSortArr.Count() );
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 	// find the first layout node for this TOX, if it only find the content
885cdf0e10cSrcweir 	// in his own chapter
886cdf0e10cSrcweir 	const SwTxtNode* pOwnChapterNode = IsFromChapter()
887cdf0e10cSrcweir 			? ::lcl_FindChapterNode( *pSectNd, 0 )
888cdf0e10cSrcweir 			: 0;
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 	SwNode2Layout aN2L( *pSectNd );
891cdf0e10cSrcweir 	((SwSectionNode*)pSectNd)->DelFrms();
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 	// remove old content an insert one empty textnode (to hold the layout!)
894cdf0e10cSrcweir 	SwTxtNode* pFirstEmptyNd;
895cdf0e10cSrcweir 	{
896cdf0e10cSrcweir 		pDoc->DeleteRedline( *pSectNd, true, USHRT_MAX );
897cdf0e10cSrcweir 
898cdf0e10cSrcweir 		SwNodeIndex aSttIdx( *pSectNd, +1 );
899cdf0e10cSrcweir 		SwNodeIndex aEndIdx( *pSectNd->EndOfSectionNode() );
900cdf0e10cSrcweir 		pFirstEmptyNd = pDoc->GetNodes().MakeTxtNode( aEndIdx,
901cdf0e10cSrcweir 						pDoc->GetTxtCollFromPool( RES_POOLCOLL_TEXT ) );
902cdf0e10cSrcweir 
903cdf0e10cSrcweir 		{
904cdf0e10cSrcweir 			// Task 70995 - save and restore PageDesc and Break Attributes
905cdf0e10cSrcweir 			SwNodeIndex aNxtIdx( aSttIdx );
906cdf0e10cSrcweir 			const SwCntntNode* pCNd = aNxtIdx.GetNode().GetCntntNode();
907cdf0e10cSrcweir 			if( !pCNd )
908cdf0e10cSrcweir 				pCNd = pDoc->GetNodes().GoNext( &aNxtIdx );
909cdf0e10cSrcweir             if( pCNd->HasSwAttrSet() )
910cdf0e10cSrcweir 			{
911cdf0e10cSrcweir 				SfxItemSet aBrkSet( pDoc->GetAttrPool(), aBreakSetRange );
912cdf0e10cSrcweir 				aBrkSet.Put( *pCNd->GetpSwAttrSet() );
913cdf0e10cSrcweir 				if( aBrkSet.Count() )
914cdf0e10cSrcweir                     pFirstEmptyNd->SetAttr( aBrkSet );
915cdf0e10cSrcweir 			}
916cdf0e10cSrcweir 		}
917cdf0e10cSrcweir 		aEndIdx--;
918cdf0e10cSrcweir 		SwPosition aPos( aEndIdx, SwIndex( pFirstEmptyNd, 0 ));
919cdf0e10cSrcweir 		pDoc->CorrAbs( aSttIdx, aEndIdx, aPos, sal_True );
920cdf0e10cSrcweir 
921cdf0e10cSrcweir 		// delete all before
922cdf0e10cSrcweir 		DelFlyInRange( aSttIdx, aEndIdx );
923cdf0e10cSrcweir 		_DelBookmarks( aSttIdx, aEndIdx );
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 		pDoc->GetNodes().Delete( aSttIdx, aEndIdx.GetIndex() - aSttIdx.GetIndex() );
926cdf0e10cSrcweir 
927cdf0e10cSrcweir 	}
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 	//
930cdf0e10cSrcweir 	// insert title of TOX
931cdf0e10cSrcweir 	if( GetTitle().Len() )
932cdf0e10cSrcweir 	{
933cdf0e10cSrcweir 		// then insert the headline section
934cdf0e10cSrcweir 		SwNodeIndex aIdx( *pSectNd, +1 );
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 		SwTxtNode* pHeadNd = pDoc->GetNodes().MakeTxtNode( aIdx,
937cdf0e10cSrcweir 								GetTxtFmtColl( FORM_TITLE ) );
938cdf0e10cSrcweir         pHeadNd->InsertText( GetTitle(), SwIndex( pHeadNd ) );
939cdf0e10cSrcweir 
940cdf0e10cSrcweir 		String sNm( GetTOXName() );
941cdf0e10cSrcweir // ??Resource
942cdf0e10cSrcweir sNm.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "_Head" ));
943cdf0e10cSrcweir 
944cdf0e10cSrcweir         SwSectionData headerData( TOX_HEADER_SECTION, sNm );
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 		SwNodeIndex aStt( *pHeadNd ); aIdx--;
947cdf0e10cSrcweir 		SwSectionFmt* pSectFmt = pDoc->MakeSectionFmt( 0 );
948cdf0e10cSrcweir         pDoc->GetNodes().InsertTextSection(
949cdf0e10cSrcweir                 aStt, *pSectFmt, headerData, 0, &aIdx, true, false);
950cdf0e10cSrcweir 	}
951cdf0e10cSrcweir 
952cdf0e10cSrcweir 	// jetzt waere ein prima Zeitpunkt, um die Numerierung zu updaten
953cdf0e10cSrcweir 	pDoc->UpdateNumRule();
954cdf0e10cSrcweir 
955cdf0e10cSrcweir     if( GetCreateType() & nsSwTOXElement::TOX_MARK )
956cdf0e10cSrcweir 		UpdateMarks( aIntl, pOwnChapterNode );
957cdf0e10cSrcweir 
958cdf0e10cSrcweir     if( GetCreateType() & nsSwTOXElement::TOX_OUTLINELEVEL )
959cdf0e10cSrcweir 		UpdateOutline( pOwnChapterNode );
960cdf0e10cSrcweir 
961cdf0e10cSrcweir     if( GetCreateType() & nsSwTOXElement::TOX_TEMPLATE )
962cdf0e10cSrcweir 		UpdateTemplate( pOwnChapterNode );
963cdf0e10cSrcweir 
964cdf0e10cSrcweir     if( GetCreateType() & nsSwTOXElement::TOX_OLE ||
965cdf0e10cSrcweir 			TOX_OBJECTS == SwTOXBase::GetType())
966cdf0e10cSrcweir         UpdateCntnt( nsSwTOXElement::TOX_OLE, pOwnChapterNode );
967cdf0e10cSrcweir 
968cdf0e10cSrcweir     if( GetCreateType() & nsSwTOXElement::TOX_TABLE ||
969cdf0e10cSrcweir 			(TOX_TABLES == SwTOXBase::GetType() && IsFromObjectNames()) )
970cdf0e10cSrcweir 		UpdateTable( pOwnChapterNode );
971cdf0e10cSrcweir 
972cdf0e10cSrcweir     if( GetCreateType() & nsSwTOXElement::TOX_GRAPHIC ||
973cdf0e10cSrcweir 		(TOX_ILLUSTRATIONS == SwTOXBase::GetType() && IsFromObjectNames()))
974cdf0e10cSrcweir         UpdateCntnt( nsSwTOXElement::TOX_GRAPHIC, pOwnChapterNode );
975cdf0e10cSrcweir 
976cdf0e10cSrcweir 	if( GetSequenceName().Len() && !IsFromObjectNames() &&
977cdf0e10cSrcweir 		(TOX_TABLES == SwTOXBase::GetType() ||
978cdf0e10cSrcweir 		 TOX_ILLUSTRATIONS == SwTOXBase::GetType() ) )
979cdf0e10cSrcweir 		UpdateSequence( pOwnChapterNode );
980cdf0e10cSrcweir 
981cdf0e10cSrcweir     if( GetCreateType() & nsSwTOXElement::TOX_FRAME )
982cdf0e10cSrcweir         UpdateCntnt( nsSwTOXElement::TOX_FRAME, pOwnChapterNode );
983cdf0e10cSrcweir 
984cdf0e10cSrcweir 	if(TOX_AUTHORITIES == SwTOXBase::GetType())
985cdf0e10cSrcweir 		UpdateAuthorities( aIntl );
986cdf0e10cSrcweir 
987cdf0e10cSrcweir 	// Bei Bedarf Alphadelimitter einfuegen (nur bei Stichwoertern)
988cdf0e10cSrcweir 	//
989cdf0e10cSrcweir 	if( TOX_INDEX == SwTOXBase::GetType() &&
990cdf0e10cSrcweir         ( GetOptions() & nsSwTOIOptions::TOI_ALPHA_DELIMITTER ) )
991cdf0e10cSrcweir 		InsertAlphaDelimitter( aIntl );
992cdf0e10cSrcweir 
993cdf0e10cSrcweir 	// sortierte Liste aller Verzeichnismarken und Verzeichnisbereiche
994cdf0e10cSrcweir 	void* p = 0;
995cdf0e10cSrcweir 	String* pStr = 0;
996cdf0e10cSrcweir 	sal_uInt16 nCnt = 0, nFormMax = GetTOXForm().GetFormMax();
997cdf0e10cSrcweir 	SvStringsDtor aStrArr( (sal_uInt8)nFormMax );
998cdf0e10cSrcweir 	SvPtrarr aCollArr( (sal_uInt8)nFormMax );
999cdf0e10cSrcweir 	for( ; nCnt < nFormMax; ++nCnt )
1000cdf0e10cSrcweir 	{
1001cdf0e10cSrcweir 		aCollArr.Insert( p, nCnt );
1002cdf0e10cSrcweir 		aStrArr.Insert( pStr, nCnt );
1003cdf0e10cSrcweir 	}
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir 	SwNodeIndex aInsPos( *pFirstEmptyNd, 1 );
1006cdf0e10cSrcweir 	for( nCnt = 0; nCnt < aSortArr.Count(); ++nCnt )
1007cdf0e10cSrcweir 	{
1008cdf0e10cSrcweir 		::SetProgressState( 0, pDoc->GetDocShell() );
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir 		// setze den Text in das Verzeichniss
1011cdf0e10cSrcweir 		sal_uInt16 nLvl = aSortArr[ nCnt ]->GetLevel();
1012cdf0e10cSrcweir 		SwTxtFmtColl* pColl = (SwTxtFmtColl*)aCollArr[ nLvl ];
1013cdf0e10cSrcweir 		if( !pColl )
1014cdf0e10cSrcweir 		{
1015cdf0e10cSrcweir 			pColl = GetTxtFmtColl( nLvl );
1016cdf0e10cSrcweir 			aCollArr.Remove( nLvl );
1017cdf0e10cSrcweir 			p = pColl;
1018cdf0e10cSrcweir 			aCollArr.Insert( p , nLvl );
1019cdf0e10cSrcweir 		}
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir 		// Generierung: dynamische TabStops setzen
1022cdf0e10cSrcweir 		SwTxtNode* pTOXNd = pDoc->GetNodes().MakeTxtNode( aInsPos , pColl );
1023cdf0e10cSrcweir 		aSortArr[ nCnt ]->pTOXNd = pTOXNd;
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir 		// Generierung: Form auswerten und Platzhalter
1026cdf0e10cSrcweir 		//				fuer die Seitennummer eintragen
1027cdf0e10cSrcweir 		//if it is a TOX_INDEX and the SwForm IsCommaSeparated()
1028cdf0e10cSrcweir 		// then a range of entries must be generated into one paragraph
1029cdf0e10cSrcweir 		sal_uInt16 nRange = 1;
1030cdf0e10cSrcweir 		if(TOX_INDEX == SwTOXBase::GetType() &&
1031cdf0e10cSrcweir 				GetTOXForm().IsCommaSeparated() &&
1032cdf0e10cSrcweir 				aSortArr[nCnt]->GetType() == TOX_SORT_INDEX)
1033cdf0e10cSrcweir 		{
1034cdf0e10cSrcweir 			const SwTOXMark& rMark = aSortArr[nCnt]->pTxtMark->GetTOXMark();
1035cdf0e10cSrcweir 			const String sPrimKey = rMark.GetPrimaryKey();
1036cdf0e10cSrcweir 			const String sSecKey = rMark.GetSecondaryKey();
1037cdf0e10cSrcweir 			const SwTOXMark* pNextMark = 0;
1038cdf0e10cSrcweir 			while(aSortArr.Count() > (nCnt + nRange)&&
1039cdf0e10cSrcweir 					aSortArr[nCnt + nRange]->GetType() == TOX_SORT_INDEX &&
1040cdf0e10cSrcweir 					0 != (pNextMark = &(aSortArr[nCnt + nRange]->pTxtMark->GetTOXMark())) &&
1041cdf0e10cSrcweir 					pNextMark->GetPrimaryKey() == sPrimKey &&
1042cdf0e10cSrcweir 					pNextMark->GetSecondaryKey() == sSecKey)
1043cdf0e10cSrcweir 				nRange++;
1044cdf0e10cSrcweir 		}
1045cdf0e10cSrcweir         // OD 18.03.2003 #106329# - pass node index of table-of-content section
1046cdf0e10cSrcweir         // and default page description to method <GenerateText(..)>.
1047cdf0e10cSrcweir         GenerateText( nCnt, nRange, aStrArr, pSectNd->GetIndex(), pDefaultPageDesc );
1048cdf0e10cSrcweir 		nCnt += nRange - 1;
1049cdf0e10cSrcweir 	}
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir 	// delete the first dummy node and remove all Cursor into the prev node
1052cdf0e10cSrcweir 	aInsPos = *pFirstEmptyNd;
1053cdf0e10cSrcweir 	{
1054cdf0e10cSrcweir 		SwPaM aCorPam( *pFirstEmptyNd );
1055cdf0e10cSrcweir 		aCorPam.GetPoint()->nContent.Assign( pFirstEmptyNd, 0 );
1056cdf0e10cSrcweir 		if( !aCorPam.Move( fnMoveForward ) )
1057cdf0e10cSrcweir 			aCorPam.Move( fnMoveBackward );
1058cdf0e10cSrcweir 		SwNodeIndex aEndIdx( aInsPos, 1 );
1059cdf0e10cSrcweir 		pDoc->CorrAbs( aInsPos, aEndIdx, *aCorPam.GetPoint(), sal_True );
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 		// Task 70995 - save and restore PageDesc and Break Attributes
1062cdf0e10cSrcweir         if( pFirstEmptyNd->HasSwAttrSet() )
1063cdf0e10cSrcweir 		{
1064cdf0e10cSrcweir 			if( GetTitle().Len() )
1065cdf0e10cSrcweir 				aEndIdx = *pSectNd;
1066cdf0e10cSrcweir 			else
1067cdf0e10cSrcweir 				aEndIdx = *pFirstEmptyNd;
1068cdf0e10cSrcweir 			SwCntntNode* pCNd = pDoc->GetNodes().GoNext( &aEndIdx );
1069cdf0e10cSrcweir             if( pCNd ) // Robust against defect documents, e.g. i60336
1070cdf0e10cSrcweir                 pCNd->SetAttr( *pFirstEmptyNd->GetpSwAttrSet() );
1071cdf0e10cSrcweir 		}
1072cdf0e10cSrcweir 	}
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir 	// now create the new Frames
1075cdf0e10cSrcweir 	sal_uLong nIdx = pSectNd->GetIndex();
1076cdf0e10cSrcweir 	// don't delete if index is empty
1077cdf0e10cSrcweir 	if(nIdx + 2 < pSectNd->EndOfSectionIndex())
1078cdf0e10cSrcweir 		pDoc->GetNodes().Delete( aInsPos, 1 );
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir 	aN2L.RestoreUpperFrms( pDoc->GetNodes(), nIdx, nIdx + 1 );
1081cdf0e10cSrcweir 	std::set<SwRootFrm*> aAllLayouts = pDoc->GetAllLayouts();
1082cdf0e10cSrcweir 	for ( std::set<SwRootFrm*>::iterator pLayoutIter = aAllLayouts.begin(); pLayoutIter != aAllLayouts.end(); pLayoutIter++)
1083cdf0e10cSrcweir 	{
1084cdf0e10cSrcweir 		SwFrm::CheckPageDescs( (SwPageFrm*)(*pLayoutIter)->Lower() );
1085cdf0e10cSrcweir 	}//swmod 080310
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir 	SetProtect( SwTOXBase::IsProtected() );
1088cdf0e10cSrcweir }
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir /*--------------------------------------------------------------------
1091cdf0e10cSrcweir 	 Beschreibung: AlphaDelimitter einfuegen
1092cdf0e10cSrcweir  --------------------------------------------------------------------*/
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir 
InsertAlphaDelimitter(const SwTOXInternational & rIntl)1095cdf0e10cSrcweir void SwTOXBaseSection::InsertAlphaDelimitter( const SwTOXInternational& rIntl )
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1098cdf0e10cSrcweir 	String sDeli, sLastDeli;
1099cdf0e10cSrcweir 	sal_uInt16	i = 0;
1100cdf0e10cSrcweir 	while( i < aSortArr.Count() )
1101cdf0e10cSrcweir 	{
1102cdf0e10cSrcweir 		::SetProgressState( 0, pDoc->GetDocShell() );
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 		sal_uInt16 nLevel = aSortArr[i]->GetLevel();
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir 		// Alpha-Delimitter ueberlesen
1107cdf0e10cSrcweir 		if( nLevel == FORM_ALPHA_DELIMITTER )
1108cdf0e10cSrcweir 			continue;
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir         String sMyString, sMyStringReading;
1111cdf0e10cSrcweir         aSortArr[i]->GetTxt( sMyString, sMyStringReading );
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir         sDeli = rIntl.GetIndexKey( sMyString, sMyStringReading,
1114cdf0e10cSrcweir                                    aSortArr[i]->GetLocale() );
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir 		// Delimitter schon vorhanden ??
1117cdf0e10cSrcweir 		if( sDeli.Len() && sLastDeli != sDeli )
1118cdf0e10cSrcweir 		{
1119cdf0e10cSrcweir 			// alle kleiner Blank wollen wir nicht haben -> sind Sonderzeichen
1120cdf0e10cSrcweir 			if( ' ' <= sDeli.GetChar( 0 ) )
1121cdf0e10cSrcweir 			{
1122cdf0e10cSrcweir                 SwTOXCustom* pCst = new SwTOXCustom( sDeli, aEmptyStr, FORM_ALPHA_DELIMITTER,
1123cdf0e10cSrcweir                                                      rIntl, aSortArr[i]->GetLocale() );
1124cdf0e10cSrcweir 				aSortArr.Insert( pCst, i++ );
1125cdf0e10cSrcweir 			}
1126cdf0e10cSrcweir 			sLastDeli = sDeli;
1127cdf0e10cSrcweir 		}
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir 		// Skippen bis gleibhes oder kleineres Level erreicht ist
1130cdf0e10cSrcweir 		do {
1131cdf0e10cSrcweir 			i++;
1132cdf0e10cSrcweir 		} while (i < aSortArr.Count() && aSortArr[i]->GetLevel() > nLevel);
1133cdf0e10cSrcweir 	}
1134cdf0e10cSrcweir }
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir /*--------------------------------------------------------------------
1137cdf0e10cSrcweir 	 Beschreibung: Template  auswerten
1138cdf0e10cSrcweir  --------------------------------------------------------------------*/
1139cdf0e10cSrcweir 
GetTxtFmtColl(sal_uInt16 nLevel)1140cdf0e10cSrcweir SwTxtFmtColl* SwTOXBaseSection::GetTxtFmtColl( sal_uInt16 nLevel )
1141cdf0e10cSrcweir {
1142cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1143cdf0e10cSrcweir 	const String& rName = GetTOXForm().GetTemplate( nLevel );
1144cdf0e10cSrcweir 	SwTxtFmtColl* pColl = rName.Len() ? pDoc->FindTxtFmtCollByName(rName) :0;
1145cdf0e10cSrcweir 	if( !pColl )
1146cdf0e10cSrcweir 	{
1147cdf0e10cSrcweir         sal_uInt16 nPoolFmt = 0;
1148cdf0e10cSrcweir 		const TOXTypes eMyType = SwTOXBase::GetType();
1149cdf0e10cSrcweir 		switch( eMyType )
1150cdf0e10cSrcweir 		{
1151cdf0e10cSrcweir 		case TOX_INDEX:			nPoolFmt = RES_POOLCOLL_TOX_IDXH; 		break;
1152cdf0e10cSrcweir 		case TOX_USER:
1153cdf0e10cSrcweir 			if( nLevel < 6 )
1154cdf0e10cSrcweir 				nPoolFmt = RES_POOLCOLL_TOX_USERH;
1155cdf0e10cSrcweir 			else
1156cdf0e10cSrcweir 				nPoolFmt = RES_POOLCOLL_TOX_USER6 - 6;
1157cdf0e10cSrcweir 			break;
1158cdf0e10cSrcweir 		case TOX_ILLUSTRATIONS: nPoolFmt = RES_POOLCOLL_TOX_ILLUSH; 	break;
1159cdf0e10cSrcweir 		case TOX_OBJECTS:		nPoolFmt = RES_POOLCOLL_TOX_OBJECTH; 	break;
1160cdf0e10cSrcweir 		case TOX_TABLES:		nPoolFmt = RES_POOLCOLL_TOX_TABLESH; 	break;
1161cdf0e10cSrcweir 		case TOX_AUTHORITIES:	nPoolFmt = RES_POOLCOLL_TOX_AUTHORITIESH; break;
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir 		case TOX_CONTENT:
1164cdf0e10cSrcweir 			// im Content Bereich gibt es einen Sprung!
1165cdf0e10cSrcweir 			if( nLevel < 6 )
1166cdf0e10cSrcweir 				nPoolFmt = RES_POOLCOLL_TOX_CNTNTH;
1167cdf0e10cSrcweir 			else
1168cdf0e10cSrcweir 				nPoolFmt = RES_POOLCOLL_TOX_CNTNT6 - 6;
1169cdf0e10cSrcweir 			break;
1170cdf0e10cSrcweir 		}
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir 		if(eMyType == TOX_AUTHORITIES && nLevel)
1173cdf0e10cSrcweir 			nPoolFmt = nPoolFmt + 1;
1174cdf0e10cSrcweir 		else if(eMyType == TOX_INDEX && nLevel)
1175cdf0e10cSrcweir 		{
1176cdf0e10cSrcweir 			//pool: Level 1,2,3, Delimiter
1177cdf0e10cSrcweir 			//SwForm: Delimiter, Level 1,2,3
1178cdf0e10cSrcweir 			nPoolFmt += 1 == nLevel ? nLevel + 3 : nLevel - 1;
1179cdf0e10cSrcweir 		}
1180cdf0e10cSrcweir 		else
1181cdf0e10cSrcweir 			nPoolFmt = nPoolFmt + nLevel;
1182cdf0e10cSrcweir 		pColl = pDoc->GetTxtCollFromPool( nPoolFmt );
1183cdf0e10cSrcweir 	}
1184cdf0e10cSrcweir 	return pColl;
1185cdf0e10cSrcweir }
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir /*--------------------------------------------------------------------
1189cdf0e10cSrcweir 	 Beschreibung: Aus Markierungen erzeugen
1190cdf0e10cSrcweir  --------------------------------------------------------------------*/
1191cdf0e10cSrcweir 
UpdateMarks(const SwTOXInternational & rIntl,const SwTxtNode * pOwnChapterNode)1192cdf0e10cSrcweir void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
1193cdf0e10cSrcweir 									const SwTxtNode* pOwnChapterNode )
1194cdf0e10cSrcweir {
1195cdf0e10cSrcweir 	const SwTOXType* pType = (SwTOXType*) SwTOXBase::GetRegisteredIn();
1196cdf0e10cSrcweir 	if( !pType->GetDepends() )
1197cdf0e10cSrcweir 		return;
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1200cdf0e10cSrcweir 	TOXTypes eTOXTyp = GetTOXType()->GetType();
1201cdf0e10cSrcweir 	SwIterator<SwTOXMark,SwTOXType> aIter( *pType );
1202cdf0e10cSrcweir 
1203cdf0e10cSrcweir 	SwTxtTOXMark* pTxtMark;
1204cdf0e10cSrcweir 	SwTOXMark* pMark;
1205cdf0e10cSrcweir 	for( pMark = aIter.First(); pMark; pMark = aIter.Next() )
1206cdf0e10cSrcweir 	{
1207cdf0e10cSrcweir 		::SetProgressState( 0, pDoc->GetDocShell() );
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir 		if( pMark->GetTOXType()->GetType() == eTOXTyp &&
1210cdf0e10cSrcweir 			0 != ( pTxtMark = pMark->GetTxtTOXMark() ) )
1211cdf0e10cSrcweir 		{
1212cdf0e10cSrcweir 			const SwTxtNode* pTOXSrc = pTxtMark->GetpTxtNd();
1213cdf0e10cSrcweir 			// nur TOXMarks einfuegen die im Doc stehen
1214cdf0e10cSrcweir 			// nicht die, die im UNDO stehen
1215cdf0e10cSrcweir 			//
1216cdf0e10cSrcweir 			// if selected use marks from the same chapter only
1217cdf0e10cSrcweir 			if( pTOXSrc->GetNodes().IsDocNodes() &&
1218cdf0e10cSrcweir 				pTOXSrc->GetTxt().Len() && pTOXSrc->GetDepends() &&
1219cdf0e10cSrcweir                 pTOXSrc->getLayoutFrm( pDoc->GetCurrentLayout() ) &&
1220cdf0e10cSrcweir                (!IsFromChapter() || ::lcl_FindChapterNode( *pTOXSrc, 0 ) == pOwnChapterNode ) &&
1221cdf0e10cSrcweir                !pTOXSrc->HasHiddenParaField() &&
1222cdf0e10cSrcweir                !SwScriptInfo::IsInHiddenRange( *pTOXSrc, *pTxtMark->GetStart() ) )
1223cdf0e10cSrcweir 			{
1224cdf0e10cSrcweir 				SwTOXSortTabBase* pBase = 0;
1225cdf0e10cSrcweir 				if(TOX_INDEX == eTOXTyp)
1226cdf0e10cSrcweir 				{
1227cdf0e10cSrcweir 					// Stichwortverzeichnismarkierung
1228cdf0e10cSrcweir                     lang::Locale aLocale;
1229cdf0e10cSrcweir                     if ( pBreakIt->GetBreakIter().is() )
1230cdf0e10cSrcweir                     {
1231cdf0e10cSrcweir                         aLocale = pBreakIt->GetLocale(
1232cdf0e10cSrcweir                                         pTOXSrc->GetLang( *pTxtMark->GetStart() ) );
1233cdf0e10cSrcweir                     }
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir 					pBase = new SwTOXIndex( *pTOXSrc, pTxtMark,
1236cdf0e10cSrcweir                                             GetOptions(), FORM_ENTRY, rIntl, aLocale );
1237cdf0e10cSrcweir 					InsertSorted(pBase);
1238cdf0e10cSrcweir                     if(GetOptions() & nsSwTOIOptions::TOI_KEY_AS_ENTRY &&
1239cdf0e10cSrcweir 						pTxtMark->GetTOXMark().GetPrimaryKey().Len())
1240cdf0e10cSrcweir 					{
1241cdf0e10cSrcweir 						pBase = new SwTOXIndex( *pTOXSrc, pTxtMark,
1242cdf0e10cSrcweir                                                 GetOptions(), FORM_PRIMARY_KEY, rIntl, aLocale );
1243cdf0e10cSrcweir 						InsertSorted(pBase);
1244cdf0e10cSrcweir 						if(pTxtMark->GetTOXMark().GetSecondaryKey().Len())
1245cdf0e10cSrcweir 						{
1246cdf0e10cSrcweir 							pBase = new SwTOXIndex( *pTOXSrc, pTxtMark,
1247cdf0e10cSrcweir                                                     GetOptions(), FORM_SECONDARY_KEY, rIntl, aLocale );
1248cdf0e10cSrcweir 							InsertSorted(pBase);
1249cdf0e10cSrcweir 						}
1250cdf0e10cSrcweir 					}
1251cdf0e10cSrcweir 				}
1252cdf0e10cSrcweir 				else if( TOX_USER == eTOXTyp ||
1253cdf0e10cSrcweir 					pMark->GetLevel() <= GetLevel())
1254cdf0e10cSrcweir 				{	// Inhaltsberzeichnismarkierung
1255cdf0e10cSrcweir 					// also used for user marks
1256cdf0e10cSrcweir 					pBase = new SwTOXContent( *pTOXSrc, pTxtMark, rIntl );
1257cdf0e10cSrcweir 					InsertSorted(pBase);
1258cdf0e10cSrcweir 				}
1259cdf0e10cSrcweir 			}
1260cdf0e10cSrcweir 		}
1261cdf0e10cSrcweir 	}
1262cdf0e10cSrcweir }
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir /*--------------------------------------------------------------------
1266cdf0e10cSrcweir 	 Beschreibung:	Verzeichnisinhalt aus Gliederungsebene generieren
1267cdf0e10cSrcweir  --------------------------------------------------------------------*/
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir 
UpdateOutline(const SwTxtNode * pOwnChapterNode)1270cdf0e10cSrcweir void SwTOXBaseSection::UpdateOutline( const SwTxtNode* pOwnChapterNode )
1271cdf0e10cSrcweir {
1272cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1273cdf0e10cSrcweir 	SwNodes& rNds = pDoc->GetNodes();
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir 	const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds();
1276cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < rOutlNds.Count(); ++n )
1277cdf0e10cSrcweir 	{
1278cdf0e10cSrcweir 		::SetProgressState( 0, pDoc->GetDocShell() );
1279cdf0e10cSrcweir 		SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode();
1280cdf0e10cSrcweir 		if( pTxtNd && pTxtNd->Len() && pTxtNd->GetDepends() &&
1281cdf0e10cSrcweir 			//sal_uInt16(pTxtNd->GetTxtColl()->GetOutlineLevel()+1) <= GetLevel() &&	//#outline level,zhaojianwei
1282cdf0e10cSrcweir 			sal_uInt16( pTxtNd->GetAttrOutlineLevel()) <= GetLevel() &&	//<-end,zhaojianwei
1283cdf0e10cSrcweir 			pTxtNd->getLayoutFrm( pDoc->GetCurrentLayout() ) &&
1284cdf0e10cSrcweir            !pTxtNd->HasHiddenParaField() &&
1285cdf0e10cSrcweir            !pTxtNd->HasHiddenCharAttribute( true ) &&
1286cdf0e10cSrcweir             ( !IsFromChapter() ||
1287cdf0e10cSrcweir 			   ::lcl_FindChapterNode( *pTxtNd, 0 ) == pOwnChapterNode ))
1288cdf0e10cSrcweir 		{
1289cdf0e10cSrcweir             SwTOXPara * pNew = new SwTOXPara( *pTxtNd, nsSwTOXElement::TOX_OUTLINELEVEL );
1290cdf0e10cSrcweir 			InsertSorted( pNew );
1291cdf0e10cSrcweir 		}
1292cdf0e10cSrcweir 	}
1293cdf0e10cSrcweir }
1294cdf0e10cSrcweir 
1295cdf0e10cSrcweir /*--------------------------------------------------------------------
1296cdf0e10cSrcweir 	 Beschreibung: Verzeichnisinhalt aus Vorlagenbereichen generieren
1297cdf0e10cSrcweir  --------------------------------------------------------------------*/
1298cdf0e10cSrcweir 
UpdateTemplate(const SwTxtNode * pOwnChapterNode)1299cdf0e10cSrcweir void SwTOXBaseSection::UpdateTemplate( const SwTxtNode* pOwnChapterNode )
1300cdf0e10cSrcweir {
1301cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1302cdf0e10cSrcweir 	for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
1303cdf0e10cSrcweir 	{
1304cdf0e10cSrcweir 		String sTmpStyleNames = GetStyleNames(i);
1305cdf0e10cSrcweir 		sal_uInt16 nTokenCount = sTmpStyleNames.GetTokenCount(TOX_STYLE_DELIMITER);
1306cdf0e10cSrcweir 		for( sal_uInt16 nStyle = 0; nStyle < nTokenCount; ++nStyle )
1307cdf0e10cSrcweir 		{
1308cdf0e10cSrcweir 			SwTxtFmtColl* pColl = pDoc->FindTxtFmtCollByName(
1309cdf0e10cSrcweir 									sTmpStyleNames.GetToken( nStyle,
1310cdf0e10cSrcweir 													TOX_STYLE_DELIMITER ));
1311cdf0e10cSrcweir 			//TODO: no outline Collections in content indexes if OutlineLevels are already included
1312cdf0e10cSrcweir 			if( !pColl ||
1313cdf0e10cSrcweir 				( TOX_CONTENT == SwTOXBase::GetType() &&
1314cdf0e10cSrcweir                   GetCreateType() & nsSwTOXElement::TOX_OUTLINELEVEL &&
1315cdf0e10cSrcweir 				  //NO_NUMBERING != pColl->GetOutlineLevel() ) )//#outline level,zhaojianwei
1316cdf0e10cSrcweir 					pColl->IsAssignedToListLevelOfOutlineStyle()) )//<-end,zhaojianwei
1317cdf0e10cSrcweir 				  continue;
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir 			SwIterator<SwTxtNode,SwFmtColl> aIter( *pColl );
1320cdf0e10cSrcweir 			for( SwTxtNode* pTxtNd = aIter.First(); pTxtNd; pTxtNd = aIter.Next() )
1321cdf0e10cSrcweir 			{
1322cdf0e10cSrcweir 				::SetProgressState( 0, pDoc->GetDocShell() );
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir 				if( pTxtNd->GetTxt().Len() && pTxtNd->getLayoutFrm( pDoc->GetCurrentLayout() ) &&
1325cdf0e10cSrcweir 					pTxtNd->GetNodes().IsDocNodes() &&
1326cdf0e10cSrcweir 					( !IsFromChapter() || pOwnChapterNode ==
1327cdf0e10cSrcweir 						::lcl_FindChapterNode( *pTxtNd, 0 ) ) )
1328cdf0e10cSrcweir 				{
1329cdf0e10cSrcweir                     SwTOXPara * pNew = new SwTOXPara( *pTxtNd, nsSwTOXElement::TOX_TEMPLATE, i + 1 );
1330cdf0e10cSrcweir 					InsertSorted(pNew);
1331cdf0e10cSrcweir 				}
1332cdf0e10cSrcweir 			}
1333cdf0e10cSrcweir 		}
1334cdf0e10cSrcweir 	}
1335cdf0e10cSrcweir }
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir /* -----------------14.07.99 09:59-------------------
1338cdf0e10cSrcweir 	Description: generate content from sequence fields
1339cdf0e10cSrcweir  --------------------------------------------------*/
UpdateSequence(const SwTxtNode * pOwnChapterNode)1340cdf0e10cSrcweir void SwTOXBaseSection::UpdateSequence( const SwTxtNode* pOwnChapterNode )
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1343cdf0e10cSrcweir 	SwFieldType* pSeqFld = pDoc->GetFldType(RES_SETEXPFLD, GetSequenceName(), false);
1344cdf0e10cSrcweir 	if(!pSeqFld)
1345cdf0e10cSrcweir 		return;
1346cdf0e10cSrcweir 
1347cdf0e10cSrcweir 	SwIterator<SwFmtFld,SwFieldType> aIter( *pSeqFld );
1348cdf0e10cSrcweir 	for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
1349cdf0e10cSrcweir 	{
1350cdf0e10cSrcweir 		const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
1351cdf0e10cSrcweir 		if(!pTxtFld)
1352cdf0e10cSrcweir 			continue;
1353cdf0e10cSrcweir 		const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
1354cdf0e10cSrcweir 		::SetProgressState( 0, pDoc->GetDocShell() );
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir 		if( rTxtNode.GetTxt().Len() && rTxtNode.getLayoutFrm( pDoc->GetCurrentLayout() ) &&
1357cdf0e10cSrcweir 			rTxtNode.GetNodes().IsDocNodes() &&
1358cdf0e10cSrcweir 			( !IsFromChapter() ||
1359cdf0e10cSrcweir 				::lcl_FindChapterNode( rTxtNode, 0 ) == pOwnChapterNode ) )
1360cdf0e10cSrcweir 		{
1361cdf0e10cSrcweir             SwTOXPara * pNew = new SwTOXPara( rTxtNode, nsSwTOXElement::TOX_SEQUENCE, 1 );
1362cdf0e10cSrcweir 			//set indexes if the number or the reference text are to be displayed
1363cdf0e10cSrcweir 			if( GetCaptionDisplay() == CAPTION_TEXT )
1364cdf0e10cSrcweir 			{
1365cdf0e10cSrcweir 				pNew->SetStartIndex(
1366cdf0e10cSrcweir 					SwGetExpField::GetReferenceTextPos( *pFmtFld, *pDoc ));
1367cdf0e10cSrcweir 			}
1368cdf0e10cSrcweir 			else if(GetCaptionDisplay() == CAPTION_NUMBER)
1369cdf0e10cSrcweir 			{
1370cdf0e10cSrcweir 				pNew->SetEndIndex(*pTxtFld->GetStart() + 1);
1371cdf0e10cSrcweir 			}
1372cdf0e10cSrcweir 			InsertSorted(pNew);
1373cdf0e10cSrcweir 		}
1374cdf0e10cSrcweir 	}
1375cdf0e10cSrcweir }
1376cdf0e10cSrcweir 
UpdateAuthorities(const SwTOXInternational & rIntl)1377cdf0e10cSrcweir void SwTOXBaseSection::UpdateAuthorities( const SwTOXInternational& rIntl )
1378cdf0e10cSrcweir {
1379cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1380cdf0e10cSrcweir 	SwFieldType* pAuthFld = pDoc->GetFldType(RES_AUTHORITY, aEmptyStr, false);
1381cdf0e10cSrcweir 	if(!pAuthFld)
1382cdf0e10cSrcweir 		return;
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir 	SwIterator<SwFmtFld,SwFieldType> aIter( *pAuthFld );
1385cdf0e10cSrcweir 	for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
1386cdf0e10cSrcweir 	{
1387cdf0e10cSrcweir 		const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
1388cdf0e10cSrcweir 		//undo
1389cdf0e10cSrcweir 		if(!pTxtFld)
1390cdf0e10cSrcweir 			continue;
1391cdf0e10cSrcweir 		const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
1392cdf0e10cSrcweir 		::SetProgressState( 0, pDoc->GetDocShell() );
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir //		const SwTxtNode* pChapterCompareNode = 0;
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir 		if( rTxtNode.GetTxt().Len() && rTxtNode.getLayoutFrm( pDoc->GetCurrentLayout() ) &&
1397cdf0e10cSrcweir 			rTxtNode.GetNodes().IsDocNodes() /*&&
1398cdf0e10cSrcweir 			(!IsFromChapter() || pChapterCompareNode == pOwnChapterNode) */)
1399cdf0e10cSrcweir 		{
1400cdf0e10cSrcweir             //#106485# the body node has to be used!
1401cdf0e10cSrcweir             SwCntntFrm *pFrm = rTxtNode.getLayoutFrm( pDoc->GetCurrentLayout() );
1402cdf0e10cSrcweir             SwPosition aFldPos(rTxtNode);
1403cdf0e10cSrcweir             const SwTxtNode* pTxtNode = 0;
1404cdf0e10cSrcweir             if(pFrm && !pFrm->IsInDocBody())
1405cdf0e10cSrcweir                 pTxtNode = GetBodyTxtNode( *pDoc, aFldPos, *pFrm );
1406cdf0e10cSrcweir             if(!pTxtNode)
1407cdf0e10cSrcweir                 pTxtNode = &rTxtNode;
1408cdf0e10cSrcweir             SwTOXAuthority* pNew = new SwTOXAuthority( *pTxtNode, *pFmtFld, rIntl );
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir 			InsertSorted(pNew);
1411cdf0e10cSrcweir 		}
1412cdf0e10cSrcweir 	}
1413cdf0e10cSrcweir }
1414cdf0e10cSrcweir 
lcl_IsSOObject(const SvGlobalName & rFactoryNm)1415cdf0e10cSrcweir long lcl_IsSOObject( const SvGlobalName& rFactoryNm )
1416cdf0e10cSrcweir {
1417cdf0e10cSrcweir 	static struct _SoObjType {
1418cdf0e10cSrcweir 		long nFlag;
1419cdf0e10cSrcweir 		// GlobalNameId
1420cdf0e10cSrcweir 		struct _GlobalNameIds {
1421cdf0e10cSrcweir 			sal_uInt32 n1;
1422cdf0e10cSrcweir 			sal_uInt16 n2, n3;
1423cdf0e10cSrcweir 			sal_uInt8 b8, b9, b10, b11, b12, b13, b14, b15;
1424cdf0e10cSrcweir         } aGlNmIds[4];
1425cdf0e10cSrcweir 	} aArr[] = {
1426cdf0e10cSrcweir         { nsSwTOOElements::TOO_MATH,
1427cdf0e10cSrcweir           { {SO3_SM_CLASSID_60},{SO3_SM_CLASSID_50},
1428cdf0e10cSrcweir             {SO3_SM_CLASSID_40},{SO3_SM_CLASSID_30} } },
1429cdf0e10cSrcweir         { nsSwTOOElements::TOO_CHART,
1430cdf0e10cSrcweir           { {SO3_SCH_CLASSID_60},{SO3_SCH_CLASSID_50},
1431cdf0e10cSrcweir             {SO3_SCH_CLASSID_40},{SO3_SCH_CLASSID_30} } },
1432cdf0e10cSrcweir         { nsSwTOOElements::TOO_CALC,
1433cdf0e10cSrcweir           { {SO3_SC_CLASSID_60},{SO3_SC_CLASSID_50},
1434cdf0e10cSrcweir             {SO3_SC_CLASSID_40},{SO3_SC_CLASSID_30} } },
1435cdf0e10cSrcweir         { nsSwTOOElements::TOO_DRAW_IMPRESS,
1436cdf0e10cSrcweir           { {SO3_SIMPRESS_CLASSID_60},{SO3_SIMPRESS_CLASSID_50},
1437cdf0e10cSrcweir             {SO3_SIMPRESS_CLASSID_40},{SO3_SIMPRESS_CLASSID_30} } },
1438cdf0e10cSrcweir         { nsSwTOOElements::TOO_DRAW_IMPRESS,
1439cdf0e10cSrcweir           { {SO3_SDRAW_CLASSID_60},{SO3_SDRAW_CLASSID_50}}},
1440cdf0e10cSrcweir         { 0,{{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},
1441cdf0e10cSrcweir             {0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0} } }
1442cdf0e10cSrcweir 	};
1443cdf0e10cSrcweir 
1444cdf0e10cSrcweir 	long nRet = 0;
1445cdf0e10cSrcweir 	for( const _SoObjType* pArr = aArr; !nRet && pArr->nFlag; ++pArr )
1446cdf0e10cSrcweir         for ( int n = 0; n < 4; ++n )
1447cdf0e10cSrcweir 		{
1448cdf0e10cSrcweir 			const _SoObjType::_GlobalNameIds& rId = pArr->aGlNmIds[ n ];
1449cdf0e10cSrcweir 			if( !rId.n1 )
1450cdf0e10cSrcweir 				break;
1451cdf0e10cSrcweir 			SvGlobalName aGlbNm( rId.n1, rId.n2, rId.n3,
1452cdf0e10cSrcweir 						rId.b8, rId.b9, rId.b10, rId.b11,
1453cdf0e10cSrcweir 						rId.b12, rId.b13, rId.b14, rId.b15 );
1454cdf0e10cSrcweir 			if( rFactoryNm == aGlbNm )
1455cdf0e10cSrcweir 			{
1456cdf0e10cSrcweir 				nRet = pArr->nFlag;
1457cdf0e10cSrcweir 				break;
1458cdf0e10cSrcweir 			}
1459cdf0e10cSrcweir 		}
1460cdf0e10cSrcweir 
1461cdf0e10cSrcweir 	return nRet;
1462cdf0e10cSrcweir }
1463cdf0e10cSrcweir 
UpdateCntnt(SwTOXElement eMyType,const SwTxtNode * pOwnChapterNode)1464cdf0e10cSrcweir void SwTOXBaseSection::UpdateCntnt( SwTOXElement eMyType,
1465cdf0e10cSrcweir 									const SwTxtNode* pOwnChapterNode )
1466cdf0e10cSrcweir {
1467cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1468cdf0e10cSrcweir 	SwNodes& rNds = pDoc->GetNodes();
1469cdf0e10cSrcweir 	// auf den 1. Node der 1. Section
1470cdf0e10cSrcweir 	sal_uLong nIdx = rNds.GetEndOfAutotext().StartOfSectionIndex() + 2,
1471cdf0e10cSrcweir 		 nEndIdx = rNds.GetEndOfAutotext().GetIndex();
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir 	while( nIdx < nEndIdx )
1474cdf0e10cSrcweir 	{
1475cdf0e10cSrcweir 		::SetProgressState( 0, pDoc->GetDocShell() );
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir 		SwNode* pNd = rNds[ nIdx ];
1478cdf0e10cSrcweir 		SwCntntNode* pCNd = 0;
1479cdf0e10cSrcweir 		switch( eMyType )
1480cdf0e10cSrcweir 		{
1481cdf0e10cSrcweir         case nsSwTOXElement::TOX_FRAME:
1482cdf0e10cSrcweir 			if( !pNd->IsNoTxtNode() )
1483cdf0e10cSrcweir 			{
1484cdf0e10cSrcweir 				pCNd = pNd->GetCntntNode();
1485cdf0e10cSrcweir 				if( !pCNd )
1486cdf0e10cSrcweir 				{
1487cdf0e10cSrcweir 					SwNodeIndex aTmp( *pNd );
1488cdf0e10cSrcweir 					pCNd = rNds.GoNext( &aTmp );
1489cdf0e10cSrcweir 				}
1490cdf0e10cSrcweir 			}
1491cdf0e10cSrcweir 			break;
1492cdf0e10cSrcweir         case nsSwTOXElement::TOX_GRAPHIC:
1493cdf0e10cSrcweir 			if( pNd->IsGrfNode() )
1494cdf0e10cSrcweir 				pCNd = (SwCntntNode*)pNd;
1495cdf0e10cSrcweir 			break;
1496cdf0e10cSrcweir         case nsSwTOXElement::TOX_OLE:
1497cdf0e10cSrcweir 			if( pNd->IsOLENode() )
1498cdf0e10cSrcweir 			{
1499cdf0e10cSrcweir 				sal_Bool bInclude = sal_True;
1500cdf0e10cSrcweir 				if(TOX_OBJECTS == SwTOXBase::GetType())
1501cdf0e10cSrcweir 				{
1502cdf0e10cSrcweir 					SwOLENode* pOLENode = pNd->GetOLENode();
1503cdf0e10cSrcweir 					long nMyOLEOptions = GetOLEOptions();
1504cdf0e10cSrcweir 					SwOLEObj& rOLEObj = pOLENode->GetOLEObj();
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir 					if( rOLEObj.IsOleRef() )	//Noch nicht geladen
1507cdf0e10cSrcweir 					{
1508cdf0e10cSrcweir                         SvGlobalName aTmpName = SvGlobalName( rOLEObj.GetOleRef()->getClassID() );
1509cdf0e10cSrcweir                         long nObj = ::lcl_IsSOObject( aTmpName );
1510cdf0e10cSrcweir                         bInclude = ( (nMyOLEOptions & nsSwTOOElements::TOO_OTHER) && 0 == nObj)
1511cdf0e10cSrcweir                                                     || (0 != (nMyOLEOptions & nObj));
1512cdf0e10cSrcweir 					}
1513cdf0e10cSrcweir 					else
1514cdf0e10cSrcweir 					{
1515cdf0e10cSrcweir 						DBG_ERROR("OLE-object nicht geladen?");
1516cdf0e10cSrcweir 						bInclude = sal_False;
1517cdf0e10cSrcweir 					}
1518cdf0e10cSrcweir 				}
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir 				if(bInclude)
1521cdf0e10cSrcweir 					pCNd = (SwCntntNode*)pNd;
1522cdf0e10cSrcweir 			}
1523cdf0e10cSrcweir 			break;
1524cdf0e10cSrcweir         default: break;
1525cdf0e10cSrcweir 		}
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir 		if( pCNd )
1528cdf0e10cSrcweir 		{
1529cdf0e10cSrcweir 			//find node in body text
1530cdf0e10cSrcweir             int nSetLevel = USHRT_MAX;
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir             //#111105# tables of tables|illustrations|objects don't support hierarchies
1533cdf0e10cSrcweir             if( IsLevelFromChapter() &&
1534cdf0e10cSrcweir                     TOX_TABLES != SwTOXBase::GetType() &&
1535cdf0e10cSrcweir                     TOX_ILLUSTRATIONS != SwTOXBase::GetType() &&
1536cdf0e10cSrcweir                     TOX_OBJECTS != SwTOXBase::GetType() )
1537*808c4840SOliver-Rainer Wittmann             {
1538*808c4840SOliver-Rainer Wittmann                 const SwTxtNode* pOutlNd = ::lcl_FindChapterNode( *pCNd,
1539*808c4840SOliver-Rainer Wittmann                     MAXLEVEL - 1 );
1540*808c4840SOliver-Rainer Wittmann                 if ( pOutlNd )
1541*808c4840SOliver-Rainer Wittmann                 {
1542*808c4840SOliver-Rainer Wittmann                     if ( pOutlNd->GetTxtColl()->IsAssignedToListLevelOfOutlineStyle() )
1543*808c4840SOliver-Rainer Wittmann                     {
1544*808c4840SOliver-Rainer Wittmann                         nSetLevel = pOutlNd->GetTxtColl()->GetAttrOutlineLevel();
1545*808c4840SOliver-Rainer Wittmann                     }
1546*808c4840SOliver-Rainer Wittmann                 }
1547*808c4840SOliver-Rainer Wittmann             }
1548cdf0e10cSrcweir 
1549*808c4840SOliver-Rainer Wittmann             if ( pCNd->getLayoutFrm( pDoc->GetCurrentLayout() ) && ( !IsFromChapter() ||
1550*808c4840SOliver-Rainer Wittmann                                                                      ::lcl_FindChapterNode( *pCNd, 0 ) == pOwnChapterNode ) )
1551*808c4840SOliver-Rainer Wittmann             {
1552*808c4840SOliver-Rainer Wittmann                 SwTOXPara * pNew =
1553*808c4840SOliver-Rainer Wittmann                     new SwTOXPara(
1554*808c4840SOliver-Rainer Wittmann                         *pCNd,
1555*808c4840SOliver-Rainer Wittmann                         eMyType,
1556*808c4840SOliver-Rainer Wittmann                         ( USHRT_MAX != nSetLevel ) ? static_cast< sal_uInt16 >( nSetLevel ) : FORM_ALPHA_DELIMITTER );
1557*808c4840SOliver-Rainer Wittmann                 InsertSorted( pNew );
1558*808c4840SOliver-Rainer Wittmann             }
1559*808c4840SOliver-Rainer Wittmann         }
1560cdf0e10cSrcweir 
1561cdf0e10cSrcweir         nIdx = pNd->StartOfSectionNode()->EndOfSectionIndex() + 2;  // 2 == End-/StartNode
1562*808c4840SOliver-Rainer Wittmann     }
1563cdf0e10cSrcweir }
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir /*--------------------------------------------------------------------
1566cdf0e10cSrcweir 	 Beschreibung:	Tabelleneintraege zusammensuchen
1567cdf0e10cSrcweir  --------------------------------------------------------------------*/
1568cdf0e10cSrcweir 
UpdateTable(const SwTxtNode * pOwnChapterNode)1569cdf0e10cSrcweir void SwTOXBaseSection::UpdateTable( const SwTxtNode* pOwnChapterNode )
1570cdf0e10cSrcweir {
1571cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1572cdf0e10cSrcweir 	SwNodes& rNds = pDoc->GetNodes();
1573cdf0e10cSrcweir 	const SwFrmFmts& rArr = *pDoc->GetTblFrmFmts();
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < rArr.Count(); ++n )
1576cdf0e10cSrcweir 	{
1577cdf0e10cSrcweir 		::SetProgressState( 0, pDoc->GetDocShell() );
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir 		SwTable* pTmpTbl = SwTable::FindTable( rArr[ n ] );
1580cdf0e10cSrcweir 		SwTableBox* pFBox;
1581cdf0e10cSrcweir 		if( pTmpTbl && 0 != (pFBox = pTmpTbl->GetTabSortBoxes()[0] ) &&
1582cdf0e10cSrcweir 			pFBox->GetSttNd() && pFBox->GetSttNd()->GetNodes().IsDocNodes() )
1583cdf0e10cSrcweir 		{
1584cdf0e10cSrcweir 			const SwTableNode* pTblNd = pFBox->GetSttNd()->FindTableNode();
1585cdf0e10cSrcweir 			SwNodeIndex aCntntIdx( *pTblNd, 1 );
1586cdf0e10cSrcweir 
1587*808c4840SOliver-Rainer Wittmann             SwCntntNode* pCNd;
1588*808c4840SOliver-Rainer Wittmann             while (0 != ( pCNd = rNds.GoNext( &aCntntIdx ) ) &&
1589*808c4840SOliver-Rainer Wittmann                    aCntntIdx.GetIndex() < pTblNd->EndOfSectionIndex())
1590*808c4840SOliver-Rainer Wittmann             {
1591*808c4840SOliver-Rainer Wittmann                 if ( pCNd->getLayoutFrm( pDoc->GetCurrentLayout() )
1592*808c4840SOliver-Rainer Wittmann                      && ( !IsFromChapter()
1593*808c4840SOliver-Rainer Wittmann                           || ::lcl_FindChapterNode( *pCNd, 0 ) == pOwnChapterNode ) )
1594*808c4840SOliver-Rainer Wittmann                 {
1595*808c4840SOliver-Rainer Wittmann                     SwTOXTable * pNew = new SwTOXTable( *pCNd );
1596*808c4840SOliver-Rainer Wittmann                     if ( IsLevelFromChapter() && TOX_TABLES != SwTOXBase::GetType() )
1597cdf0e10cSrcweir                     {
1598*808c4840SOliver-Rainer Wittmann                         const SwTxtNode* pOutlNd = ::lcl_FindChapterNode( *pCNd, MAXLEVEL - 1 );
1599*808c4840SOliver-Rainer Wittmann                         if ( pOutlNd )
1600cdf0e10cSrcweir                         {
1601*808c4840SOliver-Rainer Wittmann                             if ( pOutlNd->GetTxtColl()->IsAssignedToListLevelOfOutlineStyle() )
1602*808c4840SOliver-Rainer Wittmann                             {
1603cdf0e10cSrcweir                                 const int nTmp = pOutlNd->GetTxtColl()->GetAttrOutlineLevel();
1604*808c4840SOliver-Rainer Wittmann                                 pNew->SetLevel( static_cast< sal_uInt16 >( nTmp ) );
1605*808c4840SOliver-Rainer Wittmann                             }
1606cdf0e10cSrcweir                         }
1607cdf0e10cSrcweir                     }
1608*808c4840SOliver-Rainer Wittmann                     InsertSorted( pNew );
1609*808c4840SOliver-Rainer Wittmann                     break;
1610*808c4840SOliver-Rainer Wittmann                 }
1611*808c4840SOliver-Rainer Wittmann             }
1612*808c4840SOliver-Rainer Wittmann         }
1613*808c4840SOliver-Rainer Wittmann     }
1614cdf0e10cSrcweir }
1615cdf0e10cSrcweir 
1616cdf0e10cSrcweir /*--------------------------------------------------------------------
1617cdf0e10cSrcweir 	 Beschreibung:	String generieren anhand der Form
1618cdf0e10cSrcweir 					SonderZeichen 0-31 und 255 entfernen
1619cdf0e10cSrcweir  --------------------------------------------------------------------*/
1620cdf0e10cSrcweir 
lcl_GetNumString(const SwTOXSortTabBase & rBase,sal_Bool bUsePrefix,sal_uInt8 nLevel)1621cdf0e10cSrcweir String lcl_GetNumString( const SwTOXSortTabBase& rBase, sal_Bool bUsePrefix, sal_uInt8 nLevel )
1622cdf0e10cSrcweir {
1623cdf0e10cSrcweir 	String sRet;
1624cdf0e10cSrcweir 
1625cdf0e10cSrcweir 	if( !rBase.pTxtMark && rBase.aTOXSources.Count() > 0 )
1626cdf0e10cSrcweir 	{	// nur wenn es keine Marke ist
1627cdf0e10cSrcweir 		const SwTxtNode* pNd = rBase.aTOXSources[0].pNd->GetTxtNode();
1628cdf0e10cSrcweir 		if( pNd )
1629cdf0e10cSrcweir 		{
1630cdf0e10cSrcweir 			const SwNumRule* pRule = pNd->GetNumRule();
1631cdf0e10cSrcweir 
1632cdf0e10cSrcweir             if( pRule && pNd->GetActualListLevel() < MAXLEVEL )
1633cdf0e10cSrcweir                 sRet = pNd->GetNumString(bUsePrefix, nLevel);
1634cdf0e10cSrcweir         }
1635cdf0e10cSrcweir 	}
1636cdf0e10cSrcweir 	return sRet;
1637cdf0e10cSrcweir }
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir // OD 18.03.2003 #106329# - add parameter <_TOXSectNdIdx> and <_pDefaultPageDesc>
1640cdf0e10cSrcweir // in order to control, which page description is used, no appropriate one is found.
GenerateText(sal_uInt16 nArrayIdx,sal_uInt16 nCount,SvStringsDtor &,const sal_uInt32 _nTOXSectNdIdx,const SwPageDesc * _pDefaultPageDesc)1641cdf0e10cSrcweir void SwTOXBaseSection::GenerateText( sal_uInt16 nArrayIdx,
1642cdf0e10cSrcweir                                      sal_uInt16 nCount,
1643cdf0e10cSrcweir                                      SvStringsDtor& ,
1644cdf0e10cSrcweir                                      const sal_uInt32   _nTOXSectNdIdx,
1645cdf0e10cSrcweir                                      const SwPageDesc*  _pDefaultPageDesc )
1646cdf0e10cSrcweir {
1647cdf0e10cSrcweir 	LinkStructArr	aLinkArr;
1648cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1649cdf0e10cSrcweir 	::SetProgressState( 0, pDoc->GetDocShell() );
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir 	//pTOXNd is only set at the first mark
1652cdf0e10cSrcweir 	SwTxtNode* pTOXNd = (SwTxtNode*)aSortArr[nArrayIdx]->pTOXNd;
1653cdf0e10cSrcweir 	String& rTxt = (String&)pTOXNd->GetTxt();
1654cdf0e10cSrcweir 	rTxt.Erase();
1655cdf0e10cSrcweir 	for(sal_uInt16 nIndex = nArrayIdx; nIndex < nArrayIdx + nCount; nIndex++)
1656cdf0e10cSrcweir 	{
1657cdf0e10cSrcweir 		if(nIndex > nArrayIdx)
1658cdf0e10cSrcweir 			rTxt.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " )); // comma separation
1659cdf0e10cSrcweir 		// String mit dem Pattern aus der Form initialisieren
1660cdf0e10cSrcweir 		const SwTOXSortTabBase& rBase = *aSortArr[nIndex];
1661cdf0e10cSrcweir 		sal_uInt16 nLvl = rBase.GetLevel();
1662cdf0e10cSrcweir 		ASSERT( nLvl < GetTOXForm().GetFormMax(), "ungueltiges FORM_LEVEL");
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir         SvxTabStopItem aTStops( 0, 0, SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP );
1665cdf0e10cSrcweir 		xub_StrLen nLinkStartPosition = STRING_NOTFOUND;
1666cdf0e10cSrcweir         String  sLinkCharacterStyle; //default to "Default" character style - which is none
1667cdf0e10cSrcweir 		String sURL;
1668cdf0e10cSrcweir 		// create an enumerator
1669cdf0e10cSrcweir         // #i21237#
1670cdf0e10cSrcweir         SwFormTokens aPattern = GetTOXForm().GetPattern(nLvl);
1671cdf0e10cSrcweir         SwFormTokens::iterator aIt = aPattern.begin();
1672cdf0e10cSrcweir 		// remove text from node
1673cdf0e10cSrcweir 		while(aIt != aPattern.end()) // #i21237#
1674cdf0e10cSrcweir 		{
1675cdf0e10cSrcweir 			SwFormToken aToken = *aIt; // #i21237#
1676cdf0e10cSrcweir 			xub_StrLen nStartCharStyle = rTxt.Len();
1677cdf0e10cSrcweir 			switch( aToken.eTokenType )
1678cdf0e10cSrcweir 			{
1679cdf0e10cSrcweir 			case TOKEN_ENTRY_NO:
1680cdf0e10cSrcweir 				// fuer Inhaltsverzeichnis Numerierung
1681cdf0e10cSrcweir                 rTxt.Insert( lcl_GetNumString( rBase, aToken.nChapterFormat == CF_NUMBER, static_cast<sal_uInt8>(aToken.nOutlineLevel - 1)) );
1682cdf0e10cSrcweir 				break;
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir 			case TOKEN_ENTRY_TEXT:
1685cdf0e10cSrcweir 				{
1686cdf0e10cSrcweir 					SwIndex aIdx( pTOXNd, rTxt.Len() );
1687cdf0e10cSrcweir 					rBase.FillText( *pTOXNd, aIdx );
1688cdf0e10cSrcweir 				}
1689cdf0e10cSrcweir 				break;
1690cdf0e10cSrcweir 
1691cdf0e10cSrcweir 			case TOKEN_ENTRY:
1692cdf0e10cSrcweir 				{
1693cdf0e10cSrcweir 					// fuer Inhaltsverzeichnis Numerierung
1694cdf0e10cSrcweir 					rTxt.Insert( lcl_GetNumString( rBase, sal_True, MAXLEVEL ));
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir 					SwIndex aIdx( pTOXNd, rTxt.Len() );
1697cdf0e10cSrcweir 					rBase.FillText( *pTOXNd, aIdx );
1698cdf0e10cSrcweir 				}
1699cdf0e10cSrcweir 				break;
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir 			case TOKEN_TAB_STOP:
1702cdf0e10cSrcweir                 if (aToken.bWithTab) // #i21237#
1703cdf0e10cSrcweir                     rTxt.Append('\t');
1704cdf0e10cSrcweir 				//
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir 				if(SVX_TAB_ADJUST_END > aToken.eTabAlign)
1707cdf0e10cSrcweir 				{
1708cdf0e10cSrcweir 					const SvxLRSpaceItem& rLR =
1709cdf0e10cSrcweir                         (SvxLRSpaceItem&)pTOXNd->
1710cdf0e10cSrcweir                         SwCntntNode::GetAttr( RES_LR_SPACE, sal_True );
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir 					long nTabPosition = aToken.nTabStopPosition;
1713cdf0e10cSrcweir 					if( !GetTOXForm().IsRelTabPos() && rLR.GetTxtLeft() )
1714cdf0e10cSrcweir 						nTabPosition -= rLR.GetTxtLeft();
1715cdf0e10cSrcweir 					aTStops.Insert( SvxTabStop( nTabPosition,
1716cdf0e10cSrcweir                                                 aToken.eTabAlign,
1717cdf0e10cSrcweir 												cDfltDecimalChar,
1718cdf0e10cSrcweir 												aToken.cTabFillChar ));
1719cdf0e10cSrcweir 				}
1720cdf0e10cSrcweir 				else
1721cdf0e10cSrcweir 				{
1722cdf0e10cSrcweir 					const SwPageDesc* pPageDesc = ((SwFmtPageDesc&)pTOXNd->
1723cdf0e10cSrcweir 								SwCntntNode::GetAttr( RES_PAGEDESC )).GetPageDesc();
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir 					sal_Bool bCallFindRect = sal_True;
1726cdf0e10cSrcweir 					long nRightMargin;
1727cdf0e10cSrcweir 					if( pPageDesc )
1728cdf0e10cSrcweir 					{
1729cdf0e10cSrcweir 						const SwFrm* pFrm = pTOXNd->getLayoutFrm( pDoc->GetCurrentLayout(), 0, 0, sal_True );
1730cdf0e10cSrcweir 						if( !pFrm || 0 == ( pFrm = pFrm->FindPageFrm() ) ||
1731cdf0e10cSrcweir 							pPageDesc != ((SwPageFrm*)pFrm)->GetPageDesc() )
1732cdf0e10cSrcweir 							// dann muss man ueber den PageDesc gehen
1733cdf0e10cSrcweir 							bCallFindRect = sal_False;
1734cdf0e10cSrcweir 					}
1735cdf0e10cSrcweir 
1736cdf0e10cSrcweir 					SwRect aNdRect;
1737cdf0e10cSrcweir 					if( bCallFindRect )
1738cdf0e10cSrcweir 						aNdRect = pTOXNd->FindLayoutRect( sal_True );
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir 					if( aNdRect.IsEmpty() )
1741cdf0e10cSrcweir 					{
1742cdf0e10cSrcweir 						// dann hilft alles nichts, wir muessen ueber die Seiten-
1743cdf0e10cSrcweir 						// vorlage gehen.
1744cdf0e10cSrcweir                         // OD 18.03.2003 #106329# - call
1745cdf0e10cSrcweir                         sal_uInt32 nPgDescNdIdx = pTOXNd->GetIndex() + 1;
1746cdf0e10cSrcweir                         sal_uInt32* pPgDescNdIdx = &nPgDescNdIdx;
1747cdf0e10cSrcweir                         pPageDesc = pTOXNd->FindPageDesc( sal_False, pPgDescNdIdx );
1748cdf0e10cSrcweir                         if ( !pPageDesc ||
1749cdf0e10cSrcweir                              *pPgDescNdIdx < _nTOXSectNdIdx )
1750cdf0e10cSrcweir                         {
1751cdf0e10cSrcweir                             // use default page description, if none is found
1752cdf0e10cSrcweir                             // or the found one is given by a node before the
1753cdf0e10cSrcweir                             // table-of-content section.
1754cdf0e10cSrcweir                             pPageDesc = _pDefaultPageDesc;
1755cdf0e10cSrcweir                         }
1756cdf0e10cSrcweir 
1757cdf0e10cSrcweir 						const SwFrmFmt& rPgDscFmt = pPageDesc->GetMaster();
1758cdf0e10cSrcweir 						nRightMargin = rPgDscFmt.GetFrmSize().GetWidth() -
1759cdf0e10cSrcweir 								 		rPgDscFmt.GetLRSpace().GetLeft() -
1760cdf0e10cSrcweir 								 		rPgDscFmt.GetLRSpace().GetRight();
1761cdf0e10cSrcweir 					}
1762cdf0e10cSrcweir 					else
1763cdf0e10cSrcweir 						nRightMargin = aNdRect.Width();
1764cdf0e10cSrcweir                     //#i24363# tab stops relative to indent
1765cdf0e10cSrcweir                     if( pDoc->get(IDocumentSettingAccess::TABS_RELATIVE_TO_INDENT) )
1766cdf0e10cSrcweir                     {
1767cdf0e10cSrcweir                         //left margin of paragraph style
1768cdf0e10cSrcweir                         const SvxLRSpaceItem& rLRSpace = pTOXNd->GetTxtColl()->GetLRSpace();
1769cdf0e10cSrcweir                         nRightMargin -= rLRSpace.GetLeft();
1770cdf0e10cSrcweir                         nRightMargin -= rLRSpace.GetTxtFirstLineOfst();
1771cdf0e10cSrcweir                     }
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir                     aTStops.Insert( SvxTabStop( nRightMargin, SVX_TAB_ADJUST_RIGHT,
1774cdf0e10cSrcweir 												cDfltDecimalChar,
1775cdf0e10cSrcweir 												aToken.cTabFillChar ));
1776cdf0e10cSrcweir 				}
1777cdf0e10cSrcweir 				break;
1778cdf0e10cSrcweir 
1779cdf0e10cSrcweir 			case TOKEN_TEXT:
1780cdf0e10cSrcweir 				rTxt.Append( aToken.sText );
1781cdf0e10cSrcweir 				break;
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir 			case TOKEN_PAGE_NUMS:
1784cdf0e10cSrcweir 					// Platzhalter fuer Seitennummer(n) es wird nur der erste beachtet
1785cdf0e10cSrcweir 					//
1786cdf0e10cSrcweir 				{
1787cdf0e10cSrcweir 					// Die Anzahl der gleichen Eintrage bestimmt die Seitennummern-Pattern
1788cdf0e10cSrcweir 					//
1789cdf0e10cSrcweir 					sal_uInt16 nSize = rBase.aTOXSources.Count();
1790cdf0e10cSrcweir 					if( nSize > 0 )
1791cdf0e10cSrcweir 					{
1792cdf0e10cSrcweir 						String aInsStr( cNumRepl );
1793cdf0e10cSrcweir 						for(sal_uInt16 i=1; i < nSize; ++i)
1794cdf0e10cSrcweir 						{
1795cdf0e10cSrcweir 							aInsStr.AppendAscii( sPageDeli );
1796cdf0e10cSrcweir 							aInsStr += cNumRepl;
1797cdf0e10cSrcweir 						}
1798cdf0e10cSrcweir 						aInsStr += cEndPageNum;
1799cdf0e10cSrcweir 						rTxt.Append( aInsStr );
1800cdf0e10cSrcweir 					}
1801cdf0e10cSrcweir //						// Tab entfernen, wenn keine Seitennummer
1802cdf0e10cSrcweir //					else if( rTxt.Len() && '\t' == rTxt.GetChar( rTxt.Len() - 1 ))
1803cdf0e10cSrcweir //						rTxt.Erase( rTxt.Len()-1, 1 );
1804cdf0e10cSrcweir 				}
1805cdf0e10cSrcweir 				break;
1806cdf0e10cSrcweir 
1807cdf0e10cSrcweir 			case TOKEN_CHAPTER_INFO:
1808cdf0e10cSrcweir 				{
1809cdf0e10cSrcweir 					// ein bischen trickreich: suche irgend einen Frame
1810cdf0e10cSrcweir 					const SwTOXSource* pTOXSource = 0;
1811cdf0e10cSrcweir 					if(rBase.aTOXSources.Count())
1812cdf0e10cSrcweir 						pTOXSource = &rBase.aTOXSources[0];
1813cdf0e10cSrcweir 
1814cdf0e10cSrcweir                     // --> OD 2008-02-14 #i53420#
1815cdf0e10cSrcweir //                    if( pTOXSource && pTOXSource->pNd
1816cdf0e10cSrcweir //                        pTOXSource->pNd->IsTxtNode() )
1817cdf0e10cSrcweir                     if ( pTOXSource && pTOXSource->pNd &&
1818cdf0e10cSrcweir                          pTOXSource->pNd->IsCntntNode() )
1819cdf0e10cSrcweir                     // <--
1820cdf0e10cSrcweir 					{
1821cdf0e10cSrcweir 						const SwCntntFrm* pFrm = pTOXSource->pNd->getLayoutFrm( pDoc->GetCurrentLayout() );
1822cdf0e10cSrcweir 						if( pFrm )
1823cdf0e10cSrcweir 						{
1824cdf0e10cSrcweir 							SwChapterFieldType aFldTyp;
1825cdf0e10cSrcweir 							SwChapterField aFld( &aFldTyp, aToken.nChapterFormat );
1826cdf0e10cSrcweir                             aFld.SetLevel( static_cast<sal_uInt8>(aToken.nOutlineLevel - 1) );
1827cdf0e10cSrcweir                             // --> OD 2008-02-14 #i53420#
1828cdf0e10cSrcweir //                            aFld.ChangeExpansion( pFrm, (SwTxtNode*)pTOXSource->pNd, sal_True );
1829cdf0e10cSrcweir                             aFld.ChangeExpansion( pFrm,
1830cdf0e10cSrcweir                                 dynamic_cast<const SwCntntNode*>(pTOXSource->pNd),
1831cdf0e10cSrcweir                                 sal_True );
1832cdf0e10cSrcweir                             // <--
1833cdf0e10cSrcweir                             //---> i89791
1834cdf0e10cSrcweir                             // OD 2008-06-26 - continue to support CF_NUMBER
1835cdf0e10cSrcweir                             // and CF_NUM_TITLE in order to handle ODF 1.0/1.1
1836cdf0e10cSrcweir                             // written by OOo 3.x in the same way as OOo 2.x
1837cdf0e10cSrcweir                             // would handle them.
1838cdf0e10cSrcweir                             if ( CF_NUM_NOPREPST_TITLE == aToken.nChapterFormat ||
1839cdf0e10cSrcweir                                  CF_NUMBER == aToken.nChapterFormat )
1840cdf0e10cSrcweir                                 rTxt.Insert(aFld.GetNumber()); //get the string number without pre/postfix
1841cdf0e10cSrcweir                             else if ( CF_NUMBER_NOPREPST == aToken.nChapterFormat ||
1842cdf0e10cSrcweir                                       CF_NUM_TITLE == aToken.nChapterFormat )
1843cdf0e10cSrcweir                             //<---
1844cdf0e10cSrcweir 							{
1845cdf0e10cSrcweir 								rTxt += aFld.GetNumber();
1846cdf0e10cSrcweir 								rTxt += ' ';
1847cdf0e10cSrcweir 								rTxt += aFld.GetTitle();
1848cdf0e10cSrcweir 							}
1849cdf0e10cSrcweir 							else if(CF_TITLE == aToken.nChapterFormat)
1850cdf0e10cSrcweir 								rTxt += aFld.GetTitle();
1851cdf0e10cSrcweir 						}
1852cdf0e10cSrcweir 					}
1853cdf0e10cSrcweir 				}
1854cdf0e10cSrcweir 				break;
1855cdf0e10cSrcweir 
1856cdf0e10cSrcweir 			case TOKEN_LINK_START:
1857cdf0e10cSrcweir 				nLinkStartPosition = rTxt.Len();
1858cdf0e10cSrcweir                 sLinkCharacterStyle = aToken.sCharStyleName;
1859cdf0e10cSrcweir             break;
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir 			case TOKEN_LINK_END:
1862cdf0e10cSrcweir 					//TODO: only paired start/end tokens are valid
1863cdf0e10cSrcweir 				if( STRING_NOTFOUND != nLinkStartPosition)
1864cdf0e10cSrcweir 				{
1865cdf0e10cSrcweir 					SwIndex aIdx( pTOXNd, nLinkStartPosition );
1866cdf0e10cSrcweir 					//pTOXNd->Erase( aIdx, SwForm::nFormLinkSttLen );
1867cdf0e10cSrcweir 					xub_StrLen nEnd = rTxt.Len();
1868cdf0e10cSrcweir 
1869cdf0e10cSrcweir 					if( !sURL.Len() )
1870cdf0e10cSrcweir 					{
1871cdf0e10cSrcweir 						sURL = rBase.GetURL();
1872cdf0e10cSrcweir 						if( !sURL.Len() )
1873cdf0e10cSrcweir 							break;
1874cdf0e10cSrcweir 					}
1875cdf0e10cSrcweir                     LinkStruct* pNewLink = new LinkStruct(sURL, nLinkStartPosition,
1876cdf0e10cSrcweir                                                     nEnd);
1877782a276cSOliver-Rainer Wittmann                     const sal_uInt16 nPoolId =
1878782a276cSOliver-Rainer Wittmann                             sLinkCharacterStyle.Len() == 0
1879782a276cSOliver-Rainer Wittmann                             ? USHRT_MAX
1880782a276cSOliver-Rainer Wittmann                             : SwStyleNameMapper::GetPoolIdFromUIName( sLinkCharacterStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
1881782a276cSOliver-Rainer Wittmann                     pNewLink->aINetFmt.SetVisitedFmtAndId( sLinkCharacterStyle, nPoolId );
1882782a276cSOliver-Rainer Wittmann                     pNewLink->aINetFmt.SetINetFmtAndId( sLinkCharacterStyle, nPoolId );
1883cdf0e10cSrcweir                     aLinkArr.Insert( pNewLink, aLinkArr.Count() );
1884cdf0e10cSrcweir 					nLinkStartPosition = STRING_NOTFOUND;
1885cdf0e10cSrcweir                     sLinkCharacterStyle.Erase();
1886cdf0e10cSrcweir 				}
1887cdf0e10cSrcweir 				break;
1888cdf0e10cSrcweir 
1889cdf0e10cSrcweir 			case TOKEN_AUTHORITY:
1890cdf0e10cSrcweir 				{
1891cdf0e10cSrcweir 					ToxAuthorityField eField = (ToxAuthorityField)aToken.nAuthorityField;
1892cdf0e10cSrcweir 					SwIndex aIdx( pTOXNd, rTxt.Len() );
1893cdf0e10cSrcweir 					rBase.FillText( *pTOXNd, aIdx, static_cast<sal_uInt16>(eField) );
1894cdf0e10cSrcweir 				}
1895cdf0e10cSrcweir 				break;
1896cdf0e10cSrcweir             case TOKEN_END: break;
1897cdf0e10cSrcweir 			}
1898cdf0e10cSrcweir 
1899cdf0e10cSrcweir 			if( aToken.sCharStyleName.Len() )
1900cdf0e10cSrcweir 			{
1901cdf0e10cSrcweir 				SwCharFmt* pCharFmt;
1902cdf0e10cSrcweir 				if(	USHRT_MAX != aToken.nPoolId )
1903cdf0e10cSrcweir 					pCharFmt = pDoc->GetCharFmtFromPool( aToken.nPoolId );
1904cdf0e10cSrcweir 				else
1905cdf0e10cSrcweir 					pCharFmt = pDoc->FindCharFmtByName( aToken.sCharStyleName);
1906cdf0e10cSrcweir 
1907cdf0e10cSrcweir                 if (pCharFmt)
1908cdf0e10cSrcweir                 {
1909cdf0e10cSrcweir                     SwFmtCharFmt aFmt( pCharFmt );
1910cdf0e10cSrcweir                     pTOXNd->InsertItem( aFmt, nStartCharStyle,
1911cdf0e10cSrcweir                         rTxt.Len(), nsSetAttrMode::SETATTR_DONTEXPAND );
1912cdf0e10cSrcweir                 }
1913cdf0e10cSrcweir             }
1914cdf0e10cSrcweir 
1915cdf0e10cSrcweir             aIt++; // #i21237#
1916cdf0e10cSrcweir 		}
1917cdf0e10cSrcweir 
1918cdf0e10cSrcweir         pTOXNd->SetAttr( aTStops );
1919cdf0e10cSrcweir 	}
1920cdf0e10cSrcweir 
1921cdf0e10cSrcweir 	if(aLinkArr.Count())
1922cdf0e10cSrcweir 		for(sal_uInt16 i = 0; i < aLinkArr.Count(); ++i )
1923cdf0e10cSrcweir 		{
1924cdf0e10cSrcweir 			LinkStruct* pTmp = aLinkArr.GetObject(i);
1925cdf0e10cSrcweir             pTOXNd->InsertItem( pTmp->aINetFmt, pTmp->nStartTextPos,
1926cdf0e10cSrcweir 							pTmp->nEndTextPos);
1927cdf0e10cSrcweir 		}
1928cdf0e10cSrcweir }
1929cdf0e10cSrcweir 
1930cdf0e10cSrcweir /*--------------------------------------------------------------------
1931cdf0e10cSrcweir 	 Beschreibung: Seitennummer errechnen und nach dem Formatieren
1932cdf0e10cSrcweir 				   eintragen
1933cdf0e10cSrcweir  --------------------------------------------------------------------*/
1934cdf0e10cSrcweir 
UpdatePageNum()1935cdf0e10cSrcweir void SwTOXBaseSection::UpdatePageNum()
1936cdf0e10cSrcweir {
1937cdf0e10cSrcweir 	if( !aSortArr.Count() )
1938cdf0e10cSrcweir 		return ;
1939cdf0e10cSrcweir 
1940cdf0e10cSrcweir 	// die aktuellen Seitennummern ins Verzeichnis eintragen
1941cdf0e10cSrcweir 	SwPageFrm*	pAktPage	= 0;
1942cdf0e10cSrcweir 	sal_uInt16		nPage		= 0;
1943cdf0e10cSrcweir 	SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir     SwTOXInternational aIntl( GetLanguage(),
1946cdf0e10cSrcweir                               TOX_INDEX == GetTOXType()->GetType() ?
1947cdf0e10cSrcweir                               GetOptions() : 0,
1948cdf0e10cSrcweir                               GetSortAlgorithm() );
1949cdf0e10cSrcweir 
1950cdf0e10cSrcweir 	for( sal_uInt16 nCnt = 0; nCnt < aSortArr.Count(); ++nCnt )
1951cdf0e10cSrcweir 	{
1952cdf0e10cSrcweir 		// Schleife ueber alle SourceNodes
1953cdf0e10cSrcweir 		SvUShorts aNums;		//Die Seitennummern
1954cdf0e10cSrcweir 		SvPtrarr  aDescs;		//Die PageDescriptoren passend zu den Seitennummern.
1955cdf0e10cSrcweir 		SvUShorts* pMainNums = 0; // contains page numbers of main entries
1956cdf0e10cSrcweir 
1957cdf0e10cSrcweir 		// process run in lines
1958cdf0e10cSrcweir 		sal_uInt16 nRange = 0;
1959cdf0e10cSrcweir 		if(GetTOXForm().IsCommaSeparated() &&
1960cdf0e10cSrcweir 				aSortArr[nCnt]->GetType() == TOX_SORT_INDEX)
1961cdf0e10cSrcweir 		{
1962cdf0e10cSrcweir 			const SwTOXMark& rMark = aSortArr[nCnt]->pTxtMark->GetTOXMark();
1963cdf0e10cSrcweir 			const String sPrimKey = rMark.GetPrimaryKey();
1964cdf0e10cSrcweir 			const String sSecKey = rMark.GetSecondaryKey();
1965cdf0e10cSrcweir 			const SwTOXMark* pNextMark = 0;
1966cdf0e10cSrcweir 			while(aSortArr.Count() > (nCnt + nRange)&&
1967cdf0e10cSrcweir 					aSortArr[nCnt + nRange]->GetType() == TOX_SORT_INDEX &&
1968cdf0e10cSrcweir 					0 != (pNextMark = &(aSortArr[nCnt + nRange]->pTxtMark->GetTOXMark())) &&
1969cdf0e10cSrcweir 					pNextMark->GetPrimaryKey() == sPrimKey &&
1970cdf0e10cSrcweir 					pNextMark->GetSecondaryKey() == sSecKey)
1971cdf0e10cSrcweir 				nRange++;
1972cdf0e10cSrcweir 		}
1973cdf0e10cSrcweir 		else
1974cdf0e10cSrcweir 			nRange = 1;
1975cdf0e10cSrcweir 
1976cdf0e10cSrcweir 		for(sal_uInt16 nRunInEntry = nCnt; nRunInEntry < nCnt + nRange; nRunInEntry++)
1977cdf0e10cSrcweir 		{
1978cdf0e10cSrcweir 			SwTOXSortTabBase* pSortBase = aSortArr[nRunInEntry];
1979cdf0e10cSrcweir 			sal_uInt16 nSize = pSortBase->aTOXSources.Count();
1980cdf0e10cSrcweir 			sal_uInt16 i;
1981cdf0e10cSrcweir 			for( sal_uInt16 j = 0; j < nSize; ++j )
1982cdf0e10cSrcweir 			{
1983cdf0e10cSrcweir 				::SetProgressState( 0, pDoc->GetDocShell() );
1984cdf0e10cSrcweir 
1985cdf0e10cSrcweir 				SwTOXSource& rTOXSource = pSortBase->aTOXSources[j];
1986cdf0e10cSrcweir 				if( rTOXSource.pNd )
1987cdf0e10cSrcweir 				{
1988cdf0e10cSrcweir 					SwCntntFrm* pFrm = rTOXSource.pNd->getLayoutFrm( pDoc->GetCurrentLayout() );
1989cdf0e10cSrcweir                     ASSERT( pFrm || pDoc->IsUpdateTOX(), "TOX, no Frame found");
1990cdf0e10cSrcweir                     if( !pFrm )
1991cdf0e10cSrcweir                         continue;
1992cdf0e10cSrcweir 					if( pFrm->IsTxtFrm() && ((SwTxtFrm*)pFrm)->HasFollow() )
1993cdf0e10cSrcweir 					{
1994cdf0e10cSrcweir 						// dann suche den richtigen heraus
1995cdf0e10cSrcweir 						SwTxtFrm* pNext = (SwTxtFrm*)pFrm;
1996cdf0e10cSrcweir 						while( 0 != ( pNext = (SwTxtFrm*)pFrm->GetFollow() )
1997cdf0e10cSrcweir 								&& rTOXSource.nPos >= pNext->GetOfst() )
1998cdf0e10cSrcweir 							pFrm = pNext;
1999cdf0e10cSrcweir 					}
2000cdf0e10cSrcweir 
2001cdf0e10cSrcweir 					SwPageFrm*	pTmpPage = pFrm->FindPageFrm();
2002cdf0e10cSrcweir 					if( pTmpPage != pAktPage )
2003cdf0e10cSrcweir 					{
2004cdf0e10cSrcweir 						nPage		= pTmpPage->GetVirtPageNum();
2005cdf0e10cSrcweir 						pAktPage	= pTmpPage;
2006cdf0e10cSrcweir 					}
2007cdf0e10cSrcweir 
2008cdf0e10cSrcweir 					// sortiert einfuegen
2009cdf0e10cSrcweir 					for( i = 0; i < aNums.Count() && aNums[i] < nPage; ++i )
2010cdf0e10cSrcweir 						;
2011cdf0e10cSrcweir 
2012cdf0e10cSrcweir 					if( i >= aNums.Count() || aNums[ i ] != nPage )
2013cdf0e10cSrcweir 					{
2014cdf0e10cSrcweir 						aNums.Insert( nPage, i );
2015cdf0e10cSrcweir 						aDescs.Insert( (void*)pAktPage->GetPageDesc(), i );
2016cdf0e10cSrcweir 					}
2017cdf0e10cSrcweir 					// is it a main entry?
2018cdf0e10cSrcweir 					if(TOX_SORT_INDEX == pSortBase->GetType() &&
2019cdf0e10cSrcweir 						rTOXSource.bMainEntry)
2020cdf0e10cSrcweir 					{
2021cdf0e10cSrcweir 						if(!pMainNums)
2022cdf0e10cSrcweir 							pMainNums = new SvUShorts;
2023cdf0e10cSrcweir 						pMainNums->Insert(nPage, pMainNums->Count());
2024cdf0e10cSrcweir 					}
2025cdf0e10cSrcweir 				}
2026cdf0e10cSrcweir 			}
2027cdf0e10cSrcweir 			// einfuegen der Seitennummer in den Verzeichnis-Text-Node
2028cdf0e10cSrcweir 			const SwTOXSortTabBase* pBase = aSortArr[ nCnt ];
2029cdf0e10cSrcweir 			if(pBase->pTOXNd)
2030cdf0e10cSrcweir 			{
2031cdf0e10cSrcweir 				const SwTxtNode* pTxtNd = pBase->pTOXNd->GetTxtNode();
2032cdf0e10cSrcweir 				ASSERT( pTxtNd, "kein TextNode, falsches Verzeichnis" );
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir 				_UpdatePageNum( (SwTxtNode*)pTxtNd, aNums, aDescs, pMainNums,
2035cdf0e10cSrcweir 								aIntl );
2036cdf0e10cSrcweir 			}
2037cdf0e10cSrcweir 			DELETEZ(pMainNums);
2038cdf0e10cSrcweir 			aNums.Remove(0, aNums.Count());
2039cdf0e10cSrcweir 		}
2040cdf0e10cSrcweir 	}
2041cdf0e10cSrcweir 	// nach dem Setzen der richtigen Seitennummer, das Mapping-Array
2042cdf0e10cSrcweir 	// wieder loeschen !!
2043cdf0e10cSrcweir 	aSortArr.DeleteAndDestroy( 0, aSortArr.Count() );
2044cdf0e10cSrcweir }
2045cdf0e10cSrcweir 
2046cdf0e10cSrcweir 
2047cdf0e10cSrcweir /*--------------------------------------------------------------------
2048cdf0e10cSrcweir 	 Beschreibung: Austausch der Seitennummer-Platzhalter
2049cdf0e10cSrcweir  --------------------------------------------------------------------*/
2050cdf0e10cSrcweir 
2051cdf0e10cSrcweir // search for the page no in the array of main entry page numbers
lcl_HasMainEntry(const SvUShorts * pMainEntryNums,sal_uInt16 nToFind)2052cdf0e10cSrcweir sal_Bool lcl_HasMainEntry( const SvUShorts* pMainEntryNums, sal_uInt16 nToFind )
2053cdf0e10cSrcweir {
2054cdf0e10cSrcweir 	for(sal_uInt16 i = 0; pMainEntryNums && i < pMainEntryNums->Count(); ++i)
2055cdf0e10cSrcweir 		if(nToFind == (*pMainEntryNums)[i])
2056cdf0e10cSrcweir 			return sal_True;
2057cdf0e10cSrcweir 	return sal_False;
2058cdf0e10cSrcweir }
2059cdf0e10cSrcweir 
_UpdatePageNum(SwTxtNode * pNd,const SvUShorts & rNums,const SvPtrarr & rDescs,const SvUShorts * pMainEntryNums,const SwTOXInternational & rIntl)2060cdf0e10cSrcweir void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
2061cdf0e10cSrcweir 									const SvUShorts& rNums,
2062cdf0e10cSrcweir 									const SvPtrarr & rDescs,
2063cdf0e10cSrcweir 									const SvUShorts* pMainEntryNums,
2064cdf0e10cSrcweir 									const SwTOXInternational& rIntl )
2065cdf0e10cSrcweir {
2066cdf0e10cSrcweir 	//collect starts end ends of main entry character style
2067cdf0e10cSrcweir 	SvUShorts* pCharStyleIdx = pMainEntryNums ? new SvUShorts : 0;
2068cdf0e10cSrcweir 
2069cdf0e10cSrcweir 	String sSrchStr( cNumRepl );
2070cdf0e10cSrcweir 	sSrchStr.AppendAscii( sPageDeli ) += cNumRepl;
2071cdf0e10cSrcweir 	xub_StrLen nStartPos = pNd->GetTxt().Search( sSrchStr );
2072cdf0e10cSrcweir 	( sSrchStr = cNumRepl ) += cEndPageNum;
2073cdf0e10cSrcweir 	xub_StrLen nEndPos = pNd->GetTxt().Search( sSrchStr );
2074cdf0e10cSrcweir 	sal_uInt16 i;
2075cdf0e10cSrcweir 
2076cdf0e10cSrcweir 	if( STRING_NOTFOUND == nEndPos || !rNums.Count() )
2077cdf0e10cSrcweir 		return;
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir 	if( STRING_NOTFOUND == nStartPos || nStartPos > nEndPos)
2080cdf0e10cSrcweir 		nStartPos = nEndPos;
2081cdf0e10cSrcweir 
2082cdf0e10cSrcweir 	sal_uInt16 nOld = rNums[0],
2083cdf0e10cSrcweir 		   nBeg = nOld,
2084cdf0e10cSrcweir 		   nCount  = 0;
2085cdf0e10cSrcweir 	String aNumStr( SvxNumberType( ((SwPageDesc*)rDescs[0])->GetNumType() ).
2086cdf0e10cSrcweir 					GetNumStr( nBeg ) );
2087cdf0e10cSrcweir 	if( pCharStyleIdx && lcl_HasMainEntry( pMainEntryNums, nBeg ))
2088cdf0e10cSrcweir 	{
2089cdf0e10cSrcweir 		sal_uInt16 nTemp = 0;
2090cdf0e10cSrcweir 		pCharStyleIdx->Insert( nTemp, pCharStyleIdx->Count());
2091cdf0e10cSrcweir 	}
2092cdf0e10cSrcweir 
2093cdf0e10cSrcweir 	// Platzhalter loeschen
2094cdf0e10cSrcweir 	SwIndex aPos(pNd, nStartPos);
2095cdf0e10cSrcweir 	SwCharFmt* pPageNoCharFmt = 0;
2096cdf0e10cSrcweir 	SwpHints* pHints = pNd->GetpSwpHints();
2097cdf0e10cSrcweir 	if(pHints)
2098cdf0e10cSrcweir 		for(sal_uInt16 nHintIdx = 0; nHintIdx < pHints->GetStartCount(); nHintIdx++)
2099cdf0e10cSrcweir 		{
2100cdf0e10cSrcweir 			SwTxtAttr* pAttr = pHints->GetStart(nHintIdx);
210169a74367SOliver-Rainer Wittmann 			const xub_StrLen nTmpEnd = pAttr->End() ? *pAttr->End() : 0;
2102cdf0e10cSrcweir 			if(	nStartPos >= *pAttr->GetStart() &&
2103cdf0e10cSrcweir 				(nStartPos + 2) <= nTmpEnd &&
2104cdf0e10cSrcweir 				pAttr->Which() == RES_TXTATR_CHARFMT)
2105cdf0e10cSrcweir 			{
2106cdf0e10cSrcweir 				pPageNoCharFmt = pAttr->GetCharFmt().GetCharFmt();
2107cdf0e10cSrcweir 				break;
2108cdf0e10cSrcweir 			}
2109cdf0e10cSrcweir 		}
2110cdf0e10cSrcweir     pNd->EraseText(aPos, nEndPos - nStartPos + 2);
2111cdf0e10cSrcweir 
2112cdf0e10cSrcweir 	for( i = 1; i < rNums.Count(); ++i)
2113cdf0e10cSrcweir 	{
2114cdf0e10cSrcweir 		SvxNumberType aType( ((SwPageDesc*)rDescs[i])->GetNumType() );
2115cdf0e10cSrcweir 		if( TOX_INDEX == SwTOXBase::GetType() )
2116cdf0e10cSrcweir 		{	// Zusammenfassen f. ff.
2117cdf0e10cSrcweir 			// Alle folgenden aufaddieren
2118cdf0e10cSrcweir 			// break up if main entry starts or ends and
2119cdf0e10cSrcweir 			// insert a char style index
2120cdf0e10cSrcweir 			sal_Bool bMainEntryChanges = lcl_HasMainEntry(pMainEntryNums, nOld)
2121cdf0e10cSrcweir 					!= lcl_HasMainEntry(pMainEntryNums, rNums[i]);
2122cdf0e10cSrcweir 
2123cdf0e10cSrcweir 			if(nOld == rNums[i]-1 && !bMainEntryChanges &&
2124cdf0e10cSrcweir                 0 != (GetOptions() & (nsSwTOIOptions::TOI_FF|nsSwTOIOptions::TOI_DASH)))
2125cdf0e10cSrcweir 				nCount++;
2126cdf0e10cSrcweir 			else
2127cdf0e10cSrcweir 			{
2128cdf0e10cSrcweir 				// ff. f. alten Wert flushen
2129cdf0e10cSrcweir                 if(GetOptions() & nsSwTOIOptions::TOI_FF)
2130cdf0e10cSrcweir 				{
2131cdf0e10cSrcweir 					if ( nCount >= 1 )
2132cdf0e10cSrcweir 						aNumStr += rIntl.GetFollowingText( nCount > 1 );
2133cdf0e10cSrcweir 				}
2134cdf0e10cSrcweir 				else
2135cdf0e10cSrcweir 				{
2136cdf0e10cSrcweir 					if(nCount >= 2 )
2137cdf0e10cSrcweir 						aNumStr += '-';
2138cdf0e10cSrcweir 					else if(nCount == 1 )
2139cdf0e10cSrcweir 						aNumStr.AppendAscii( sPageDeli );
2140cdf0e10cSrcweir //#58127# Wenn nCount == 0, dann steht die einzige Seitenzahl schon im aNumStr!
2141cdf0e10cSrcweir 					if(nCount)
2142cdf0e10cSrcweir 						aNumStr += aType.GetNumStr( nBeg + nCount );
2143cdf0e10cSrcweir 				}
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir 				// neuen String anlegen
2146cdf0e10cSrcweir 				nBeg	 = rNums[i];
2147cdf0e10cSrcweir 				aNumStr.AppendAscii( sPageDeli );
2148cdf0e10cSrcweir 				//the change of the character style must apply after sPageDeli is appended
2149cdf0e10cSrcweir 				if(pCharStyleIdx && bMainEntryChanges)
2150cdf0e10cSrcweir 					pCharStyleIdx->Insert(aNumStr.Len(),
2151cdf0e10cSrcweir 													pCharStyleIdx->Count());
2152cdf0e10cSrcweir 				aNumStr += aType.GetNumStr( nBeg );
2153cdf0e10cSrcweir 				nCount	 = 0;
2154cdf0e10cSrcweir 			}
2155cdf0e10cSrcweir 			nOld = rNums[i];
2156cdf0e10cSrcweir 		}
2157cdf0e10cSrcweir 		else
2158cdf0e10cSrcweir 		{	// Alle Nummern eintragen
2159cdf0e10cSrcweir 			aNumStr += aType.GetNumStr( sal_uInt16(rNums[i]) );
2160cdf0e10cSrcweir 			if(i != (rNums.Count()-1))
2161cdf0e10cSrcweir 				aNumStr.AppendAscii( sPageDeli );
2162cdf0e10cSrcweir 		}
2163cdf0e10cSrcweir 	}
2164cdf0e10cSrcweir 	// Bei Ende und ff. alten Wert flushen
2165cdf0e10cSrcweir 	if( TOX_INDEX == SwTOXBase::GetType() )
2166cdf0e10cSrcweir 	{
2167cdf0e10cSrcweir         if(GetOptions() & nsSwTOIOptions::TOI_FF)
2168cdf0e10cSrcweir 		{
2169cdf0e10cSrcweir 			if( nCount >= 1 )
2170cdf0e10cSrcweir 				aNumStr += rIntl.GetFollowingText( nCount > 1 );
2171cdf0e10cSrcweir 		}
2172cdf0e10cSrcweir 		else
2173cdf0e10cSrcweir 		{
2174cdf0e10cSrcweir 			if(nCount >= 2)
2175cdf0e10cSrcweir 				aNumStr +='-';
2176cdf0e10cSrcweir 			else if(nCount == 1)
2177cdf0e10cSrcweir 				aNumStr.AppendAscii( sPageDeli );
2178cdf0e10cSrcweir //#58127# Wenn nCount == 0, dann steht die einzige Seitenzahl schon im aNumStr!
2179cdf0e10cSrcweir 			if(nCount)
2180cdf0e10cSrcweir 				aNumStr += SvxNumberType( ((SwPageDesc*)rDescs[i-1])->
2181cdf0e10cSrcweir 								GetNumType() ).GetNumStr( nBeg+nCount );
2182cdf0e10cSrcweir 		}
2183cdf0e10cSrcweir 	}
2184cdf0e10cSrcweir     pNd->InsertText( aNumStr, aPos,
2185cdf0e10cSrcweir            static_cast<IDocumentContentOperations::InsertFlags>(
2186cdf0e10cSrcweir                IDocumentContentOperations::INS_EMPTYEXPAND |
2187cdf0e10cSrcweir                IDocumentContentOperations::INS_FORCEHINTEXPAND) );
2188cdf0e10cSrcweir 	if(pPageNoCharFmt)
2189cdf0e10cSrcweir 	{
2190cdf0e10cSrcweir         SwFmtCharFmt aCharFmt( pPageNoCharFmt );
2191cdf0e10cSrcweir         pNd->InsertItem(aCharFmt, nStartPos, nStartPos + aNumStr.Len(), nsSetAttrMode::SETATTR_DONTEXPAND);
2192cdf0e10cSrcweir     }
2193cdf0e10cSrcweir 
2194cdf0e10cSrcweir 	//now the main entries should get there character style
2195cdf0e10cSrcweir 	if(pCharStyleIdx && pCharStyleIdx->Count() && GetMainEntryCharStyle().Len())
2196cdf0e10cSrcweir 	{
2197cdf0e10cSrcweir 		// eventually the last index must me appended
2198cdf0e10cSrcweir 		if(pCharStyleIdx->Count()&0x01)
2199cdf0e10cSrcweir 			pCharStyleIdx->Insert(aNumStr.Len(), pCharStyleIdx->Count());
2200cdf0e10cSrcweir 
2201cdf0e10cSrcweir 		//search by name
2202cdf0e10cSrcweir 		SwDoc* pDoc = pNd->GetDoc();
2203cdf0e10cSrcweir 		sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( GetMainEntryCharStyle(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
2204cdf0e10cSrcweir 		SwCharFmt* pCharFmt = 0;
2205cdf0e10cSrcweir 		if(USHRT_MAX != nPoolId)
2206cdf0e10cSrcweir 			pCharFmt = pDoc->GetCharFmtFromPool(nPoolId);
2207cdf0e10cSrcweir 		else
2208cdf0e10cSrcweir 			pCharFmt = pDoc->FindCharFmtByName( GetMainEntryCharStyle() );
2209cdf0e10cSrcweir 		if(!pCharFmt)
2210cdf0e10cSrcweir 			pCharFmt = pDoc->MakeCharFmt(GetMainEntryCharStyle(), 0);
2211cdf0e10cSrcweir 
2212cdf0e10cSrcweir 		//find the page numbers in aNumStr and set the character style
2213cdf0e10cSrcweir 		xub_StrLen nOffset = pNd->GetTxt().Len() - aNumStr.Len();
2214cdf0e10cSrcweir 		SwFmtCharFmt aCharFmt(pCharFmt);
2215cdf0e10cSrcweir 		for(sal_uInt16 j = 0; j < pCharStyleIdx->Count(); j += 2)
2216cdf0e10cSrcweir 		{
2217cdf0e10cSrcweir 			xub_StrLen nStartIdx = (*pCharStyleIdx)[j] + nOffset;
2218cdf0e10cSrcweir 			xub_StrLen nEndIdx = (*pCharStyleIdx)[j + 1]  + nOffset;
2219cdf0e10cSrcweir             pNd->InsertItem(aCharFmt, nStartIdx, nEndIdx, nsSetAttrMode::SETATTR_DONTEXPAND);
2220cdf0e10cSrcweir 		}
2221cdf0e10cSrcweir 
2222cdf0e10cSrcweir 	}
2223cdf0e10cSrcweir 	delete pCharStyleIdx;
2224cdf0e10cSrcweir }
2225cdf0e10cSrcweir 
2226cdf0e10cSrcweir 
2227cdf0e10cSrcweir /*--------------------------------------------------------------------
2228cdf0e10cSrcweir 	 Beschreibung: Sortiert einfuegen in das SortArr
2229cdf0e10cSrcweir  --------------------------------------------------------------------*/
2230cdf0e10cSrcweir 
InsertSorted(SwTOXSortTabBase * pNew)2231cdf0e10cSrcweir void SwTOXBaseSection::InsertSorted(SwTOXSortTabBase* pNew)
2232cdf0e10cSrcweir {
2233cdf0e10cSrcweir 	Range aRange(0, aSortArr.Count());
2234cdf0e10cSrcweir 	if( TOX_INDEX == SwTOXBase::GetType() && pNew->pTxtMark )
2235cdf0e10cSrcweir 	{
2236cdf0e10cSrcweir 		const SwTOXMark& rMark = pNew->pTxtMark->GetTOXMark();
2237cdf0e10cSrcweir 		// Schluessel auswerten
2238cdf0e10cSrcweir 		// Den Bereich ermitteln, in dem einzufuegen ist
2239cdf0e10cSrcweir         if( 0 == (GetOptions() & nsSwTOIOptions::TOI_KEY_AS_ENTRY) &&
2240cdf0e10cSrcweir 			rMark.GetPrimaryKey().Len() )
2241cdf0e10cSrcweir 		{
2242cdf0e10cSrcweir             aRange = GetKeyRange( rMark.GetPrimaryKey(),
2243cdf0e10cSrcweir                                   rMark.GetPrimaryKeyReading(),
2244cdf0e10cSrcweir                                   *pNew, FORM_PRIMARY_KEY, aRange );
2245cdf0e10cSrcweir 
2246cdf0e10cSrcweir             if( rMark.GetSecondaryKey().Len() )
2247cdf0e10cSrcweir                 aRange = GetKeyRange( rMark.GetSecondaryKey(),
2248cdf0e10cSrcweir                                       rMark.GetSecondaryKeyReading(),
2249cdf0e10cSrcweir                                       *pNew, FORM_SECONDARY_KEY, aRange );
2250cdf0e10cSrcweir 		}
2251cdf0e10cSrcweir 	}
2252cdf0e10cSrcweir 	//search for identical entries and remove the trailing one
2253cdf0e10cSrcweir 	if(TOX_AUTHORITIES == SwTOXBase::GetType())
2254cdf0e10cSrcweir 	{
2255cdf0e10cSrcweir 		for(short i = (short)aRange.Min(); i < (short)aRange.Max(); ++i)
2256cdf0e10cSrcweir 		{
2257cdf0e10cSrcweir 			SwTOXSortTabBase* pOld = aSortArr[i];
2258cdf0e10cSrcweir 			if(*pOld == *pNew)
2259cdf0e10cSrcweir 			{
2260cdf0e10cSrcweir 				if(*pOld < *pNew)
2261cdf0e10cSrcweir 				{
2262cdf0e10cSrcweir 					delete pNew;
2263cdf0e10cSrcweir 					return;
2264cdf0e10cSrcweir 				}
2265cdf0e10cSrcweir 				else
2266cdf0e10cSrcweir 				{
2267cdf0e10cSrcweir 					// remove the old content
2268cdf0e10cSrcweir 					aSortArr.DeleteAndDestroy( i, 1 );
2269cdf0e10cSrcweir 					aRange.Max()--;
2270cdf0e10cSrcweir 					break;
2271cdf0e10cSrcweir 				}
2272cdf0e10cSrcweir 			}
2273cdf0e10cSrcweir 		}
2274cdf0e10cSrcweir 	}
2275cdf0e10cSrcweir 
2276cdf0e10cSrcweir 	// find position and insert
2277cdf0e10cSrcweir 	//
2278cdf0e10cSrcweir 	short i;
2279cdf0e10cSrcweir 
2280cdf0e10cSrcweir 	for( i = (short)aRange.Min(); i < (short)aRange.Max(); ++i)
2281cdf0e10cSrcweir 	{	// nur auf gleicher Ebene pruefen
2282cdf0e10cSrcweir 		//
2283cdf0e10cSrcweir 		SwTOXSortTabBase* pOld = aSortArr[i];
2284cdf0e10cSrcweir 		if(*pOld == *pNew)
2285cdf0e10cSrcweir 		{
2286cdf0e10cSrcweir 			if(TOX_AUTHORITIES != SwTOXBase::GetType())
2287cdf0e10cSrcweir 			{
2288cdf0e10cSrcweir 				// Eigener Eintrag fuer Doppelte oder Keywords
2289cdf0e10cSrcweir 				//
2290cdf0e10cSrcweir 				if( pOld->GetType() == TOX_SORT_CUSTOM &&
2291cdf0e10cSrcweir                     pNew->GetOptions() & nsSwTOIOptions::TOI_KEY_AS_ENTRY)
2292cdf0e10cSrcweir 					continue;
2293cdf0e10cSrcweir 
2294cdf0e10cSrcweir                 if(!(pNew->GetOptions() & nsSwTOIOptions::TOI_SAME_ENTRY))
2295cdf0e10cSrcweir 				{	// Eigener Eintrag
2296cdf0e10cSrcweir 					aSortArr.Insert(pNew, i );
2297cdf0e10cSrcweir 					return;
2298cdf0e10cSrcweir 				}
2299cdf0e10cSrcweir 				// Eintrag schon vorhanden in Referenzliste aufnehmen
2300cdf0e10cSrcweir 				pOld->aTOXSources.Insert( pNew->aTOXSources[0],
2301cdf0e10cSrcweir 											pOld->aTOXSources.Count() );
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir 				delete pNew;
2304cdf0e10cSrcweir 				return;
2305cdf0e10cSrcweir 			}
2306cdf0e10cSrcweir #ifdef DBG_UTIL
2307cdf0e10cSrcweir 			else
2308cdf0e10cSrcweir 				DBG_ERROR("Bibliography entries cannot be found here");
2309cdf0e10cSrcweir #endif
2310cdf0e10cSrcweir 		}
2311cdf0e10cSrcweir 		if(*pNew < *pOld)
2312cdf0e10cSrcweir 			break;
2313cdf0e10cSrcweir 	}
2314cdf0e10cSrcweir 	// SubLevel Skippen
2315cdf0e10cSrcweir 	while( TOX_INDEX == SwTOXBase::GetType() && i < aRange.Max() &&
2316cdf0e10cSrcweir 		  aSortArr[i]->GetLevel() > pNew->GetLevel() )
2317cdf0e10cSrcweir 		i++;
2318cdf0e10cSrcweir 
2319cdf0e10cSrcweir 	// An Position i wird eingefuegt
2320cdf0e10cSrcweir 	aSortArr.Insert(pNew, i );
2321cdf0e10cSrcweir }
2322cdf0e10cSrcweir 
2323cdf0e10cSrcweir /*--------------------------------------------------------------------
2324cdf0e10cSrcweir 	 Beschreibung: Schluessel-Bereich suchen und evtl einfuegen
2325cdf0e10cSrcweir  --------------------------------------------------------------------*/
2326cdf0e10cSrcweir 
GetKeyRange(const String & rStr,const String & rStrReading,const SwTOXSortTabBase & rNew,sal_uInt16 nLevel,const Range & rRange)2327cdf0e10cSrcweir Range SwTOXBaseSection::GetKeyRange(const String& rStr, const String& rStrReading,
2328cdf0e10cSrcweir                                     const SwTOXSortTabBase& rNew,
2329cdf0e10cSrcweir                                     sal_uInt16 nLevel, const Range& rRange )
2330cdf0e10cSrcweir {
2331cdf0e10cSrcweir     const SwTOXInternational& rIntl = *rNew.pTOXIntl;
2332cdf0e10cSrcweir 	String sToCompare(rStr);
2333cdf0e10cSrcweir     String sToCompareReading(rStrReading);
2334cdf0e10cSrcweir 
2335cdf0e10cSrcweir     if( 0 != (nsSwTOIOptions::TOI_INITIAL_CAPS & GetOptions()) )
2336cdf0e10cSrcweir 	{
2337cdf0e10cSrcweir 		String sUpper( rIntl.ToUpper( sToCompare, 0 ));
2338cdf0e10cSrcweir 		sToCompare.Erase( 0, 1 ).Insert( sUpper, 0 );
2339cdf0e10cSrcweir 	}
2340cdf0e10cSrcweir 
2341cdf0e10cSrcweir 	ASSERT(rRange.Min() >= 0 && rRange.Max() >= 0, "Min Max < 0");
2342cdf0e10cSrcweir 
2343cdf0e10cSrcweir 	const sal_uInt16 nMin = (sal_uInt16)rRange.Min();
2344cdf0e10cSrcweir 	const sal_uInt16 nMax = (sal_uInt16)rRange.Max();
2345cdf0e10cSrcweir 
2346cdf0e10cSrcweir     sal_uInt16 i;
2347cdf0e10cSrcweir 
2348cdf0e10cSrcweir 	for( i = nMin; i < nMax; ++i)
2349cdf0e10cSrcweir 	{
2350cdf0e10cSrcweir 		SwTOXSortTabBase* pBase = aSortArr[i];
2351cdf0e10cSrcweir 
2352cdf0e10cSrcweir         String sMyString, sMyStringReading;
2353cdf0e10cSrcweir         pBase->GetTxt( sMyString, sMyStringReading );
2354cdf0e10cSrcweir 
2355cdf0e10cSrcweir         if( rIntl.IsEqual( sMyString, sMyStringReading, pBase->GetLocale(),
2356cdf0e10cSrcweir                            sToCompare, sToCompareReading, rNew.GetLocale() )  &&
2357cdf0e10cSrcweir                     pBase->GetLevel() == nLevel )
2358cdf0e10cSrcweir 			break;
2359cdf0e10cSrcweir 	}
2360cdf0e10cSrcweir 	if(i == nMax)
2361cdf0e10cSrcweir 	{	// Falls nicht vorhanden erzeugen und einfuegen
2362cdf0e10cSrcweir 		//
2363cdf0e10cSrcweir         SwTOXCustom* pKey = new SwTOXCustom( sToCompare, sToCompareReading, nLevel, rIntl,
2364cdf0e10cSrcweir                                              rNew.GetLocale() );
2365cdf0e10cSrcweir 		for(i = nMin; i < nMax; ++i)
2366cdf0e10cSrcweir 		{
2367cdf0e10cSrcweir 			if(nLevel == aSortArr[i]->GetLevel() &&  *pKey < *(aSortArr[i]))
2368cdf0e10cSrcweir 				break;
2369cdf0e10cSrcweir 		}
2370cdf0e10cSrcweir 		aSortArr.Insert(pKey, i );
2371cdf0e10cSrcweir 	}
2372cdf0e10cSrcweir 	sal_uInt16 nStart = i+1;
2373cdf0e10cSrcweir 	sal_uInt16 nEnd   = aSortArr.Count();
2374cdf0e10cSrcweir 
2375cdf0e10cSrcweir 	// Ende des Bereiches suchen
2376cdf0e10cSrcweir 	for(i = nStart; i < aSortArr.Count(); ++i)
2377cdf0e10cSrcweir 	{
2378cdf0e10cSrcweir 		if(aSortArr[i]->GetLevel() <= nLevel)
2379cdf0e10cSrcweir 		{	nEnd = i;
2380cdf0e10cSrcweir 			break;
2381cdf0e10cSrcweir 		}
2382cdf0e10cSrcweir 	}
2383cdf0e10cSrcweir 	return Range(nStart, nEnd);
2384cdf0e10cSrcweir }
2385cdf0e10cSrcweir 
2386cdf0e10cSrcweir 
IsTOXBaseInReadonly() const2387cdf0e10cSrcweir sal_Bool SwTOXBase::IsTOXBaseInReadonly() const
2388cdf0e10cSrcweir {
2389cdf0e10cSrcweir 	const SwTOXBaseSection *pSect = PTR_CAST(SwTOXBaseSection, this);
2390cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2391cdf0e10cSrcweir 	const SwSectionNode* pSectNode;
2392cdf0e10cSrcweir 	if(pSect && pSect->GetFmt() &&
2393cdf0e10cSrcweir 			0 != (pSectNode = pSect->GetFmt()->GetSectionNode()))
2394cdf0e10cSrcweir 	{
2395cdf0e10cSrcweir 		const SwDocShell* pDocSh;
2396cdf0e10cSrcweir 		bRet = (0 != (pDocSh = pSectNode->GetDoc()->GetDocShell()) &&
2397cdf0e10cSrcweir 													pDocSh->IsReadOnly()) ||
2398cdf0e10cSrcweir             (0 != (pSectNode = pSectNode->StartOfSectionNode()->FindSectionNode())&&
2399cdf0e10cSrcweir 					pSectNode->GetSection().IsProtectFlag());
2400cdf0e10cSrcweir 
2401cdf0e10cSrcweir 	}
2402cdf0e10cSrcweir 	return bRet;
2403cdf0e10cSrcweir }
2404cdf0e10cSrcweir 
GetAttrSet() const2405cdf0e10cSrcweir const SfxItemSet* SwTOXBase::GetAttrSet() const
2406cdf0e10cSrcweir {
2407cdf0e10cSrcweir 	const SwTOXBaseSection *pSect = PTR_CAST(SwTOXBaseSection, this);
2408cdf0e10cSrcweir 	if(pSect && pSect->GetFmt())
2409cdf0e10cSrcweir 		return &pSect->GetFmt()->GetAttrSet();
2410cdf0e10cSrcweir 	return 0;
2411cdf0e10cSrcweir }
2412cdf0e10cSrcweir 
SetAttrSet(const SfxItemSet & rSet)2413cdf0e10cSrcweir void SwTOXBase::SetAttrSet( const SfxItemSet& rSet )
2414cdf0e10cSrcweir {
2415cdf0e10cSrcweir 	SwTOXBaseSection *pSect = PTR_CAST(SwTOXBaseSection, this);
2416cdf0e10cSrcweir 	if( pSect && pSect->GetFmt() )
2417cdf0e10cSrcweir         pSect->GetFmt()->SetFmtAttr( rSet );
2418cdf0e10cSrcweir }
2419cdf0e10cSrcweir 
GetInfo(SfxPoolItem & rInfo) const2420cdf0e10cSrcweir sal_Bool SwTOXBase::GetInfo( SfxPoolItem& rInfo ) const
2421cdf0e10cSrcweir {
2422cdf0e10cSrcweir 	switch( rInfo.Which() )
2423cdf0e10cSrcweir 	{
2424cdf0e10cSrcweir 	case RES_CONTENT_VISIBLE:
2425cdf0e10cSrcweir 		{
2426cdf0e10cSrcweir 			SwTOXBaseSection *pSect = PTR_CAST(SwTOXBaseSection, this);
2427cdf0e10cSrcweir 			if( pSect && pSect->GetFmt() )
2428cdf0e10cSrcweir 				pSect->GetFmt()->GetInfo( rInfo );
2429cdf0e10cSrcweir 		}
2430cdf0e10cSrcweir 		return sal_False;
2431cdf0e10cSrcweir 	}
2432cdf0e10cSrcweir 	return sal_True;
2433cdf0e10cSrcweir }
2434cdf0e10cSrcweir 
2435