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