LibreOffice Module sw (master)  1
doctxm.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <limits.h>
21 #include <hintids.hxx>
23 #include <comphelper/classids.hxx>
24 #include <docsh.hxx>
25 #include <ndole.hxx>
26 #include <txttxmrk.hxx>
27 #include <fmtpdsc.hxx>
28 #include <frmatr.hxx>
29 #include <pagedesc.hxx>
30 #include <doc.hxx>
31 #include <IDocumentUndoRedo.hxx>
35 #include <IDocumentState.hxx>
38 #include <pagefrm.hxx>
39 #include <ndtxt.hxx>
40 #include <swtable.hxx>
41 #include <doctxm.hxx>
42 #include <txmsrt.hxx>
43 #include <rolbck.hxx>
44 #include <poolfmt.hxx>
45 #include <txtfrm.hxx>
46 #include <rootfrm.hxx>
47 #include <UndoAttribute.hxx>
48 #include <UndoSection.hxx>
49 #include <swundo.hxx>
50 #include <mdiexp.hxx>
51 #include <docary.hxx>
52 #include <charfmt.hxx>
53 #include <fchrfmt.hxx>
54 #include <fldbas.hxx>
55 #include <fmtfld.hxx>
56 #include <txtfld.hxx>
57 #include <expfld.hxx>
58 #include <mvsave.hxx>
59 #include <node2lay.hxx>
60 #include <SwStyleNameMapper.hxx>
61 #include <breakit.hxx>
62 #include <scriptinfo.hxx>
63 #include <calbck.hxx>
64 #include <ToxTextGenerator.hxx>
66 #include <frameformats.hxx>
67 #include <tools/datetimeutils.hxx>
68 #include <tools/globname.hxx>
69 #include <com/sun/star/embed/XEmbeddedObject.hpp>
70 #include <o3tl/safeint.hxx>
71 
72 #include <memory>
73 
74 using namespace ::com::sun::star;
75 
76 template<typename T, typename... Args> static
77 typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
78 MakeSwTOXSortTabBase(SwRootFrame const*const pLayout, Args&& ... args)
79 {
80  std::unique_ptr<T> pRet(new T(std::forward<Args>(args)...));
81  pRet->InitText(pLayout); // ensure it's expanded with the layout
82  return pRet;
83 }
84 
85 void SwDoc::GetTOIKeys(SwTOIKeyType eTyp, std::vector<OUString>& rArr,
86  SwRootFrame const& rLayout) const
87 {
88  rArr.clear();
89 
90  // Look up all Primary and Secondary via the Pool
91  for (const SfxPoolItem* pPoolItem : GetAttrPool().GetItemSurrogates(RES_TXTATR_TOXMARK))
92  {
93  const SwTOXMark* pItem = dynamic_cast<const SwTOXMark*>(pPoolItem);
94  if( !pItem )
95  continue;
96  const SwTOXType* pTOXType = pItem->GetTOXType();
97  if ( !pTOXType || pTOXType->GetType()!=TOX_INDEX )
98  continue;
99  const SwTextTOXMark* pMark = pItem->GetTextTOXMark();
100  if ( pMark && pMark->GetpTextNd() &&
101  pMark->GetpTextNd()->GetNodes().IsDocNodes() &&
102  (!rLayout.IsHideRedlines()
103  || !sw::IsMarkHintHidden(rLayout, *pMark->GetpTextNd(), *pMark)))
104  {
105  const OUString sStr = TOI_PRIMARY == eTyp
106  ? pItem->GetPrimaryKey()
107  : pItem->GetSecondaryKey();
108 
109  if( !sStr.isEmpty() )
110  rArr.push_back( sStr );
111  }
112  }
113 }
114 
116 sal_uInt16 SwDoc::GetCurTOXMark( const SwPosition& rPos,
117  SwTOXMarks& rArr )
118 {
119  // search on Position rPos for all SwTOXMarks
120  SwTextNode *const pTextNd = rPos.nNode.GetNode().GetTextNode();
121  if( !pTextNd || !pTextNd->GetpSwpHints() )
122  return 0;
123 
124  const SwpHints & rHts = *pTextNd->GetpSwpHints();
125  sal_Int32 nSttIdx;
126  const sal_Int32 *pEndIdx;
127 
128  const sal_Int32 nCurrentPos = rPos.nContent.GetIndex();
129 
130  for( size_t n = 0; n < rHts.Count(); ++n )
131  {
132  const SwTextAttr* pHt = rHts.Get(n);
133  if( RES_TXTATR_TOXMARK != pHt->Which() )
134  continue;
135  if( ( nSttIdx = pHt->GetStart() ) < nCurrentPos )
136  {
137  // also check the end
138  if( nullptr == ( pEndIdx = pHt->End() ) ||
139  *pEndIdx <= nCurrentPos )
140  continue; // keep searching
141  }
142  else if( nSttIdx > nCurrentPos )
143  // If Hint's Start is greater than rPos, break, because
144  // the attributes are sorted by Start!
145  break;
146 
147  SwTOXMark* pTMark = const_cast<SwTOXMark*>(&pHt->GetTOXMark());
148  rArr.push_back( pTMark );
149  }
150  return rArr.size();
151 }
152 
154 void SwDoc::DeleteTOXMark( const SwTOXMark* pTOXMark )
155 {
156  const SwTextTOXMark* pTextTOXMark = pTOXMark->GetTextTOXMark();
157  assert(pTextTOXMark);
158 
159  SwTextNode& rTextNd = const_cast<SwTextNode&>(pTextTOXMark->GetTextNode());
160  assert(rTextNd.GetpSwpHints());
161 
162  if (pTextTOXMark->HasDummyChar())
163  {
164  // tdf#106377 don't use SwUndoResetAttr, it uses NOTXTATRCHR
165  SwPaM tmp(rTextNd, pTextTOXMark->GetStart(),
166  rTextNd, pTextTOXMark->GetStart()+1);
167  assert(rTextNd.GetText()[pTextTOXMark->GetStart()] == CH_TXTATR_INWORD);
169  }
170  else
171  {
172  std::unique_ptr<SwRegHistory> aRHst;
173  if (GetIDocumentUndoRedo().DoesUndo())
174  {
175  // save attributes for Undo
176  SwUndoResetAttr* pUndo = new SwUndoResetAttr(
177  SwPosition( rTextNd, SwIndex( &rTextNd, pTextTOXMark->GetStart() ) ),
179  GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) );
180 
181  aRHst.reset(new SwRegHistory(rTextNd, &pUndo->GetHistory()));
182  rTextNd.GetpSwpHints()->Register(aRHst.get());
183  }
184 
185  rTextNd.DeleteAttribute( const_cast<SwTextTOXMark*>(pTextTOXMark) );
186 
187  if (GetIDocumentUndoRedo().DoesUndo())
188  {
189  if( rTextNd.GetpSwpHints() )
190  rTextNd.GetpSwpHints()->DeRegister();
191  }
192  }
193 
195 }
196 
197 namespace {
198 
200 class CompareNodeContent
201 {
202  sal_uLong nNode;
203  sal_Int32 nContent;
204 public:
205  CompareNodeContent( sal_uLong nNd, sal_Int32 nCnt )
206  : nNode( nNd ), nContent( nCnt ) {}
207 
208  bool operator==( const CompareNodeContent& rCmp ) const
209  { return nNode == rCmp.nNode && nContent == rCmp.nContent; }
210  bool operator!=( const CompareNodeContent& rCmp ) const
211  { return nNode != rCmp.nNode || nContent != rCmp.nContent; }
212  bool operator< ( const CompareNodeContent& rCmp ) const
213  { return nNode < rCmp.nNode ||
214  ( nNode == rCmp.nNode && nContent < rCmp.nContent); }
215  bool operator<=( const CompareNodeContent& rCmp ) const
216  { return nNode < rCmp.nNode ||
217  ( nNode == rCmp.nNode && nContent <= rCmp.nContent); }
218  bool operator> ( const CompareNodeContent& rCmp ) const
219  { return nNode > rCmp.nNode ||
220  ( nNode == rCmp.nNode && nContent > rCmp.nContent); }
221  bool operator>=( const CompareNodeContent& rCmp ) const
222  { return nNode > rCmp.nNode ||
223  ( nNode == rCmp.nNode && nContent >= rCmp.nContent); }
224 };
225 
226 }
227 
228 const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
229  SwTOXSearch eDir, bool bInReadOnly )
230 {
231  const SwTextTOXMark* pMark = rCurTOXMark.GetTextTOXMark();
232  OSL_ENSURE(pMark, "pMark==0 invalid TextTOXMark");
233 
234  const SwTextNode *pTOXSrc = pMark->GetpTextNd();
235 
236  CompareNodeContent aAbsIdx( pTOXSrc->GetIndex(), pMark->GetStart() );
237  CompareNodeContent aPrevPos( 0, 0 );
238  CompareNodeContent aNextPos( ULONG_MAX, SAL_MAX_INT32 );
239  CompareNodeContent aMax( 0, 0 );
240  CompareNodeContent aMin( ULONG_MAX, SAL_MAX_INT32 );
241 
242  const SwTOXMark* pNew = nullptr;
243  const SwTOXMark* pMax = &rCurTOXMark;
244  const SwTOXMark* pMin = &rCurTOXMark;
245 
246  const SwTOXType* pType = rCurTOXMark.GetTOXType();
247  SwTOXMarks aMarks;
248  SwTOXMark::InsertTOXMarks( aMarks, *pType );
249 
250  for(SwTOXMark* pTOXMark : aMarks)
251  {
252  if ( pTOXMark == &rCurTOXMark )
253  continue;
254 
255  pMark = pTOXMark->GetTextTOXMark();
256  if (!pMark)
257  continue;
258 
259  pTOXSrc = pMark->GetpTextNd();
260  if (!pTOXSrc)
261  continue;
262 
263  Point aPt;
264  std::pair<Point, bool> const tmp(aPt, false);
265  const SwContentFrame* pCFrame = pTOXSrc->getLayoutFrame(
266  getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, &tmp);
267  if (!pCFrame)
268  continue;
269 
270  if ( bInReadOnly || !pCFrame->IsProtected() )
271  {
272  CompareNodeContent aAbsNew( pTOXSrc->GetIndex(), pMark->GetStart() );
273  switch( eDir )
274  {
275  // The following (a bit more complicated) statements make it
276  // possible to also travel across Entries on the same (!)
277  // position. If someone has time, please feel free to optimize.
278  case TOX_SAME_PRV:
279  if (pTOXMark->GetText(nullptr) != rCurTOXMark.GetText(nullptr))
280  break;
281  [[fallthrough]];
282  case TOX_PRV:
283  if ( (aAbsNew < aAbsIdx && aAbsNew > aPrevPos) ||
284  (aAbsIdx == aAbsNew &&
285  (reinterpret_cast<sal_uLong>(&rCurTOXMark) > reinterpret_cast<sal_uLong>(pTOXMark) &&
286  (!pNew || aPrevPos < aAbsIdx || reinterpret_cast<sal_uLong>(pNew) < reinterpret_cast<sal_uLong>(pTOXMark) ) )) ||
287  (aPrevPos == aAbsNew && aAbsIdx != aAbsNew &&
288  reinterpret_cast<sal_uLong>(pTOXMark) > reinterpret_cast<sal_uLong>(pNew)) )
289  {
290  pNew = pTOXMark;
291  aPrevPos = aAbsNew;
292  if ( aAbsNew >= aMax )
293  {
294  aMax = aAbsNew;
295  pMax = pTOXMark;
296  }
297  }
298  break;
299 
300  case TOX_SAME_NXT:
301  if (pTOXMark->GetText(nullptr) != rCurTOXMark.GetText(nullptr))
302  break;
303  [[fallthrough]];
304  case TOX_NXT:
305  if ( (aAbsNew > aAbsIdx && aAbsNew < aNextPos) ||
306  (aAbsIdx == aAbsNew &&
307  (reinterpret_cast<sal_uLong>(&rCurTOXMark) < reinterpret_cast<sal_uLong>(pTOXMark) &&
308  (!pNew || aNextPos > aAbsIdx || reinterpret_cast<sal_uLong>(pNew) > reinterpret_cast<sal_uLong>(pTOXMark)) )) ||
309  (aNextPos == aAbsNew && aAbsIdx != aAbsNew &&
310  reinterpret_cast<sal_uLong>(pTOXMark) < reinterpret_cast<sal_uLong>(pNew)) )
311  {
312  pNew = pTOXMark;
313  aNextPos = aAbsNew;
314  if ( aAbsNew <= aMin )
315  {
316  aMin = aAbsNew;
317  pMin = pTOXMark;
318  }
319  }
320  break;
321  }
322  }
323  }
324 
325  // We couldn't find a successor
326  // Use minimum or maximum
327  if(!pNew)
328  {
329  switch(eDir)
330  {
331  case TOX_PRV:
332  case TOX_SAME_PRV:
333  pNew = pMax;
334  break;
335  case TOX_NXT:
336  case TOX_SAME_NXT:
337  pNew = pMin;
338  break;
339  default:
340  pNew = &rCurTOXMark;
341  }
342  }
343  return *pNew;
344 }
345 
347  const SwTOXBase& rTOX,
348  const SfxItemSet* pSet,
349  bool bExpand,
350  SwRootFrame const*const pLayout)
351 {
352  SwPaM aPam( rPos );
353  return InsertTableOf( aPam, rTOX, pSet, bExpand, pLayout );
354 }
355 
357  const SwTOXBase& rTOX,
358  const SfxItemSet* pSet,
359  bool bExpand,
360  SwRootFrame const*const pLayout )
361 {
362  assert(!bExpand || pLayout != nullptr);
364 
365  OUString sSectNm = GetUniqueTOXBaseName( *rTOX.GetTOXType(), rTOX.GetTOXName() );
366  SwSectionData aSectionData( SectionType::ToxContent, sSectNm );
367 
368  std::pair<SwTOXBase const*, sw::RedlineMode> const tmp(&rTOX,
369  pLayout && pLayout->IsHideRedlines()
372  SwTOXBaseSection *const pNewSection = dynamic_cast<SwTOXBaseSection *>(
373  InsertSwSection(aPam, aSectionData, & tmp, pSet, false));
374  if (pNewSection)
375  {
376  SwSectionNode *const pSectNd = pNewSection->GetFormat()->GetSectionNode();
377  pNewSection->SetTOXName(sSectNm); // rTOX may have had no name...
378 
379  if( bExpand )
380  {
381  // add value for 2nd parameter = true to
382  // indicate, that a creation of a new table of content has to be performed.
383  // Value of 1st parameter = default value.
384  pNewSection->Update( nullptr, pLayout, true );
385  }
386  else if( rTOX.GetTitle().getLength()==1 && IsInReading() )
387  // insert title of TOX
388  {
389  // then insert the headline section
390  SwNodeIndex aIdx( *pSectNd, +1 );
391 
392  SwTextNode* pHeadNd = GetNodes().MakeTextNode( aIdx,
393  getIDocumentStylePoolAccess().GetTextCollFromPool( RES_POOLCOLL_STANDARD ) );
394 
395  SwSectionData headerData( SectionType::ToxHeader, pNewSection->GetTOXName()+"_Head" );
396 
397  SwNodeIndex aStt( *pHeadNd ); --aIdx;
398  SwSectionFormat* pSectFormat = MakeSectionFormat();
400  aStt, *pSectFormat, headerData, nullptr, &aIdx, true, false);
401  }
402  }
403 
405 
406  return pNewSection;
407 }
408 
410  const SwTOXBase& rTOX,
411  const SfxItemSet* pSet )
412 {
413  // check for recursive TOX
414  SwNode* pNd = GetNodes()[ nSttNd ];
415  SwSectionNode* pSectNd = pNd->FindSectionNode();
416  while( pSectNd )
417  {
418  SectionType eT = pSectNd->GetSection().GetType();
420  return;
421  pSectNd = pSectNd->StartOfSectionNode()->FindSectionNode();
422  }
423 
424  const OUString sSectNm = GetUniqueTOXBaseName(*rTOX.GetTOXType(), rTOX.GetTOXName());
425 
426  SwSectionData aSectionData( SectionType::ToxContent, sSectNm );
427 
428  SwNodeIndex aStt( GetNodes(), nSttNd ), aEnd( GetNodes(), nEndNd );
429  SwSectionFormat* pFormat = MakeSectionFormat();
430  if(pSet)
431  pFormat->SetFormatAttr(*pSet);
432 
433  SwSectionNode *const pNewSectionNode =
434  GetNodes().InsertTextSection(aStt, *pFormat, aSectionData, &rTOX, &aEnd);
435  if (!pNewSectionNode)
436  {
437  DelSectionFormat( pFormat );
438  return;
439  }
440 
441  SwTOXBaseSection *const pNewSection(
442  dynamic_cast<SwTOXBaseSection*>(& pNewSectionNode->GetSection()));
443  if (pNewSection)
444  pNewSection->SetTOXName(sSectNm); // rTOX may have had no name...
445 }
446 
449 {
450  SwNode& rNd = rPos.nNode.GetNode();
451  SwSectionNode* pSectNd = rNd.FindSectionNode();
452  while( pSectNd )
453  {
454  SectionType eT = pSectNd->GetSection().GetType();
455  if( SectionType::ToxContent == eT )
456  {
457  OSL_ENSURE( dynamic_cast< const SwTOXBaseSection *>( &pSectNd->GetSection()) != nullptr,
458  "no TOXBaseSection!" );
459  SwTOXBaseSection& rTOXSect = static_cast<SwTOXBaseSection&>(
460  pSectNd->GetSection());
461  return &rTOXSect;
462  }
463  pSectNd = pSectNd->StartOfSectionNode()->FindSectionNode();
464  }
465  return nullptr;
466 }
467 
469 {
470  OSL_ENSURE( dynamic_cast<const SwTOXBaseSection*>( &rTOXBase) != nullptr, "no TOXBaseSection!" );
471  const SwTOXBaseSection& rTOXSect = static_cast<const SwTOXBaseSection&>(rTOXBase);
472  SwSectionFormat const * pFormat = rTOXSect.GetFormat();
473  OSL_ENSURE( pFormat, "invalid TOXBaseSection!" );
474  return pFormat->GetAttrSet();
475 }
476 
477 const SwTOXBase* SwDoc::GetDefaultTOXBase( TOXTypes eTyp, bool bCreate )
478 {
479  std::unique_ptr<SwTOXBase>* prBase = nullptr;
480  switch(eTyp)
481  {
482  case TOX_CONTENT: prBase = &mpDefTOXBases->pContBase; break;
483  case TOX_INDEX: prBase = &mpDefTOXBases->pIdxBase; break;
484  case TOX_USER: prBase = &mpDefTOXBases->pUserBase; break;
485  case TOX_TABLES: prBase = &mpDefTOXBases->pTableBase; break;
486  case TOX_OBJECTS: prBase = &mpDefTOXBases->pObjBase; break;
487  case TOX_ILLUSTRATIONS: prBase = &mpDefTOXBases->pIllBase; break;
488  case TOX_AUTHORITIES: prBase = &mpDefTOXBases->pAuthBase; break;
489  case TOX_BIBLIOGRAPHY: prBase = &mpDefTOXBases->pBiblioBase; break;
490  case TOX_CITATION: break;
491  }
492  if (!prBase)
493  return nullptr;
494  if(!(*prBase) && bCreate)
495  {
496  SwForm aForm(eTyp);
497  const SwTOXType* pType = GetTOXType(eTyp, 0);
498  prBase->reset(new SwTOXBase(pType, aForm, SwTOXElement::NONE, pType->GetTypeName()));
499  }
500  return prBase->get();
501 }
502 
504 {
505  std::unique_ptr<SwTOXBase>* prBase = nullptr;
506  switch(rBase.GetType())
507  {
508  case TOX_CONTENT: prBase = &mpDefTOXBases->pContBase; break;
509  case TOX_INDEX: prBase = &mpDefTOXBases->pIdxBase; break;
510  case TOX_USER: prBase = &mpDefTOXBases->pUserBase; break;
511  case TOX_TABLES: prBase = &mpDefTOXBases->pTableBase; break;
512  case TOX_OBJECTS: prBase = &mpDefTOXBases->pObjBase; break;
513  case TOX_ILLUSTRATIONS: prBase = &mpDefTOXBases->pIllBase; break;
514  case TOX_AUTHORITIES: prBase = &mpDefTOXBases->pAuthBase; break;
515  case TOX_BIBLIOGRAPHY: prBase = &mpDefTOXBases->pBiblioBase; break;
516  case TOX_CITATION: break;
517  }
518  if (!prBase)
519  return;
520  prBase->reset(new SwTOXBase(rBase));
521 }
522 
524 bool SwDoc::DeleteTOX( const SwTOXBase& rTOXBase, bool bDelNodes )
525 {
526  // We only delete the TOX, not the Nodes
527  bool bRet = false;
528  OSL_ENSURE( dynamic_cast<const SwTOXBaseSection*>( &rTOXBase) != nullptr, "no TOXBaseSection!" );
529 
530  const SwTOXBaseSection& rTOXSect = static_cast<const SwTOXBaseSection&>(rTOXBase);
531  SwSectionFormat const * pFormat = rTOXSect.GetFormat();
532  /* Save the start node of the TOX' section. */
533  SwSectionNode const * pMyNode = pFormat ? pFormat->GetSectionNode() : nullptr;
534  if (pMyNode)
535  {
537 
538  /* Save start node of section's surrounding. */
539  SwNode const * pStartNd = pMyNode->StartOfSectionNode();
540 
541  /* Look for the point where to move the cursors in the area to
542  delete to. This is done by first searching forward from the
543  end of the TOX' section. If no content node is found behind
544  the TOX one is searched before it. If this is not
545  successful, too, insert new text node behind the end of
546  the TOX' section. The cursors from the TOX' section will be
547  moved to the content node found or the new text node. */
548 
549  /* Set PaM to end of TOX' section and search following content node.
550  aSearchPam will contain the point where to move the cursors
551  to. */
552  SwPaM aSearchPam(*pMyNode->EndOfSectionNode());
553  SwPosition aEndPos(*pStartNd->EndOfSectionNode());
554  if (! aSearchPam.Move() /* no content node found */
555  || *aSearchPam.GetPoint() >= aEndPos /* content node found
556  outside surrounding */
557  )
558  {
559  /* Set PaM to beginning of TOX' section and search previous
560  content node */
561  SwPaM aTmpPam(*pMyNode);
562  aSearchPam = aTmpPam;
563  SwPosition aStartPos(*pStartNd);
564 
565  if ( ! aSearchPam.Move(fnMoveBackward) /* no content node found */
566  || *aSearchPam.GetPoint() <= aStartPos /* content node
567  found outside
568  surrounding */
569  )
570  {
571  /* There is no content node in the surrounding of
572  TOX'. Append text node behind TOX' section. */
573 
574  SwPosition aInsPos(*pMyNode->EndOfSectionNode());
576 
577  SwPaM aTmpPam1(aInsPos);
578  aSearchPam = aTmpPam1;
579  }
580  }
581 
582  /* PaM containing the TOX. */
583  SwPaM aPam(*pMyNode->EndOfSectionNode(), *pMyNode);
584 
585  /* Move cursors contained in TOX to the above calculated point. */
586  PaMCorrAbs(aPam, *aSearchPam.GetPoint());
587 
588  if( !bDelNodes )
589  {
590  SwSections aArr( 0 );
591  pFormat->GetChildSections( aArr, SectionSort::Not, false );
592  for( const auto pSect : aArr )
593  {
594  if( SectionType::ToxHeader == pSect->GetType() )
595  {
596  DelSectionFormat( pSect->GetFormat(), bDelNodes );
597  }
598  }
599  }
600 
601  DelSectionFormat( const_cast<SwSectionFormat *>(pFormat), bDelNodes );
602 
604  bRet = true;
605  }
606 
607  return bRet;
608 }
609 
611 sal_uInt16 SwDoc::GetTOXTypeCount(TOXTypes eTyp) const
612 {
613  sal_uInt16 nCnt = 0;
614  for( auto const & pTOXType : *mpTOXTypes )
615  if( eTyp == pTOXType->GetType() )
616  ++nCnt;
617  return nCnt;
618 }
619 
620 const SwTOXType* SwDoc::GetTOXType( TOXTypes eTyp, sal_uInt16 nId ) const
621 {
622  sal_uInt16 nCnt = 0;
623  for( auto const & pTOXType : *mpTOXTypes )
624  if( eTyp == pTOXType->GetType() && nCnt++ == nId )
625  return pTOXType.get();
626  return nullptr;
627 }
628 
630 {
631  SwTOXType * pNew = new SwTOXType( rTyp );
632  mpTOXTypes->emplace_back( pNew );
633  return pNew;
634 }
635 
636 OUString SwDoc::GetUniqueTOXBaseName( const SwTOXType& rType,
637  const OUString& sChkStr ) const
638 {
639  if( IsInMailMerge())
640  {
641  OUString newName = "MailMergeTOX"
642  + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
643  + OUString::number( mpSectionFormatTable->size() + 1 );
644  if( !sChkStr.isEmpty())
645  newName += sChkStr;
646  return newName;
647  }
648 
649  bool bUseChkStr = !sChkStr.isEmpty();
650  const OUString& aName( rType.GetTypeName() );
651  const sal_Int32 nNmLen = aName.getLength();
652 
654  const SwSectionFormats::size_type nFlagSize = ( mpSectionFormatTable->size() / 8 ) +2;
655  std::unique_ptr<sal_uInt8[]> pSetFlags(new sal_uInt8[ nFlagSize ]);
656  memset( pSetFlags.get(), 0, nFlagSize );
657 
658  for( auto pSectionFormat : *mpSectionFormatTable )
659  {
660  const SwSectionNode *pSectNd = pSectionFormat->GetSectionNode();
661  if ( !pSectNd )
662  continue;
663 
664  const SwSection& rSect = pSectNd->GetSection();
665  if (rSect.GetType()==SectionType::ToxContent)
666  {
667  const OUString& rNm = rSect.GetSectionName();
668  if ( rNm.startsWith(aName) )
669  {
670  // Calculate number and set the Flag
671  nNum = rNm.copy( nNmLen ).toInt32();
672  if( nNum-- && nNum < mpSectionFormatTable->size() )
673  pSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 ));
674  }
675  if ( bUseChkStr && sChkStr==rNm )
676  bUseChkStr = false;
677  }
678  }
679 
680  if( !bUseChkStr )
681  {
682  // All Numbers have been flagged accordingly, so get the right Number
683  nNum = mpSectionFormatTable->size();
684  for( SwSectionFormats::size_type n = 0; n < nFlagSize; ++n )
685  {
686  sal_uInt8 nTmp = pSetFlags[ n ];
687  if( nTmp != 0xff )
688  {
689  // so get the Number
690  nNum = n * 8;
691  while( nTmp & 1 )
692  {
693  ++nNum;
694  nTmp >>= 1;
695  }
696  break;
697  }
698  }
699  }
700  if ( bUseChkStr )
701  return sChkStr;
702  return aName + OUString::number( ++nNum );
703 }
704 
705 bool SwDoc::SetTOXBaseName(const SwTOXBase& rTOXBase, const OUString& rName)
706 {
707  OSL_ENSURE( dynamic_cast<const SwTOXBaseSection*>( &rTOXBase) != nullptr,
708  "no TOXBaseSection!" );
709  SwTOXBaseSection* pTOX = const_cast<SwTOXBaseSection*>(static_cast<const SwTOXBaseSection*>(&rTOXBase));
710 
711  if (GetUniqueTOXBaseName(*rTOXBase.GetTOXType(), rName) == rName)
712  {
713  pTOX->SetTOXName(rName);
714  pTOX->SetSectionName(rName);
716  return true;
717  }
718  return false;
719 }
720 
721 static const SwTextNode* lcl_FindChapterNode( const SwNode& rNd,
722  SwRootFrame const*const pLayout, sal_uInt8 const nLvl = 0 )
723 {
724  const SwNode* pNd = &rNd;
725  if( pNd->GetNodes().GetEndOfExtras().GetIndex() > pNd->GetIndex() )
726  {
727  // then find the "Anchor" (Body) position
728  Point aPt;
729  SwNode2Layout aNode2Layout( *pNd, pNd->GetIndex() );
730  const SwFrame* pFrame = aNode2Layout.GetFrame( &aPt );
731 
732  if( pFrame )
733  {
734  SwPosition aPos( *pNd );
735  pNd = GetBodyTextNode( *pNd->GetDoc(), aPos, *pFrame );
736  OSL_ENSURE( pNd, "Where's the paragraph?" );
737  }
738  }
739  return pNd ? pNd->FindOutlineNodeOfLevel(nLvl, pLayout) : nullptr;
740 }
741 
742 // Table of contents class
744  : SwTOXBase( rBase )
745  , SwSection( SectionType::ToxContent, OUString(), rFormat )
746 {
747  SetProtect( rBase.IsProtected() );
749 }
750 
752 {
753 }
754 
756 {
757  bool bRet = false;
758  const SwSectionNode* pSectNd = GetFormat()->GetSectionNode();
759  if( pSectNd )
760  {
761  rPos.nNode = *pSectNd;
762  SwContentNode* pCNd = pSectNd->GetDoc()->GetNodes().GoNext( &rPos.nNode );
763  rPos.nContent.Assign( pCNd, 0 );
764  bRet = true;
765  }
766  return bRet;
767 }
768 
771  SwRootFrame const*const pLayout,
772  const bool _bNewTOX)
773 {
774  if (!SwTOXBase::GetRegisteredIn()->HasWriterListeners() ||
775  !GetFormat())
776  {
777  return;
778  }
779  SwSectionNode const*const pSectNd(GetFormat()->GetSectionNode());
780  if (nullptr == pSectNd ||
781  !pSectNd->GetNodes().IsDocNodes() ||
782  IsHiddenFlag() ||
783  (pLayout->IsHideRedlines() && pSectNd->GetRedlineMergeFlag() == SwNode::Merge::Hidden))
784  {
785  return;
786  }
787 
788  if ( !mbKeepExpression )
789  {
790  maMSTOCExpression.clear();
791  }
792 
793  SwDoc* pDoc = const_cast<SwDoc*>(pSectNd->GetDoc());
794 
795  assert(pDoc); //Where is the document?
796 
797  if (pAttr && GetFormat())
798  pDoc->ChgFormat(*GetFormat(), *pAttr);
799 
800  // determine default page description, which will be used by the content nodes,
801  // if no appropriate one is found.
802  const SwPageDesc* pDefaultPageDesc;
803  {
804  pDefaultPageDesc =
805  pSectNd->GetSection().GetFormat()->GetPageDesc().GetPageDesc();
806  if ( !_bNewTOX && !pDefaultPageDesc )
807  {
808  // determine page description of table-of-content
809  size_t nPgDescNdIdx = pSectNd->GetIndex() + 1;
810  size_t* pPgDescNdIdx = &nPgDescNdIdx;
811  pDefaultPageDesc = pSectNd->FindPageDesc( pPgDescNdIdx );
812  if ( nPgDescNdIdx < pSectNd->GetIndex() )
813  {
814  pDefaultPageDesc = nullptr;
815  }
816  }
817  // consider end node of content section in the node array.
818  if ( !pDefaultPageDesc &&
819  ( pSectNd->EndOfSectionNode()->GetIndex() <
820  (pSectNd->GetNodes().GetEndOfContent().GetIndex() - 1) )
821  )
822  {
823  // determine page description of content after table-of-content
824  SwNodeIndex aIdx( *(pSectNd->EndOfSectionNode()) );
825  const SwContentNode* pNdAfterTOX = pSectNd->GetNodes().GoNext( &aIdx );
826  const SwAttrSet& aNdAttrSet = pNdAfterTOX->GetSwAttrSet();
827  const SvxBreak eBreak = aNdAttrSet.GetBreak().GetBreak();
828  if ( !( eBreak == SvxBreak::PageBefore ||
829  eBreak == SvxBreak::PageBoth )
830  )
831  {
832  pDefaultPageDesc = pNdAfterTOX->FindPageDesc();
833  }
834  }
835  // consider start node of content section in the node array.
836  if ( !pDefaultPageDesc &&
837  ( pSectNd->GetIndex() >
838  (pSectNd->GetNodes().GetEndOfContent().StartOfSectionIndex() + 1) )
839  )
840  {
841  // determine page description of content before table-of-content
842  SwNodeIndex aIdx( *pSectNd );
843  pDefaultPageDesc =
844  SwNodes::GoPrevious( &aIdx )->FindPageDesc();
845 
846  }
847  if ( !pDefaultPageDesc )
848  {
849  // determine default page description
850  pDefaultPageDesc = &pDoc->GetPageDesc( 0 );
851  }
852  }
853 
854  pDoc->getIDocumentState().SetModified();
855 
856  // get current Language
858  TOX_INDEX == GetTOXType()->GetType() ?
860  GetSortAlgorithm() );
861 
862  m_aSortArr.clear();
863 
864  // find the first layout node for this TOX, if it only find the content
865  // in his own chapter
866  const SwTextNode* pOwnChapterNode = IsFromChapter()
867  ? ::lcl_FindChapterNode( *pSectNd, pLayout )
868  : nullptr;
869 
870  SwNode2LayoutSaveUpperFrames aN2L(*pSectNd);
871  const_cast<SwSectionNode*>(pSectNd)->DelFrames();
872 
873  // This would be a good time to update the Numbering
874  pDoc->UpdateNumRule();
875 
877  UpdateMarks( aIntl, pOwnChapterNode, pLayout );
878 
880  UpdateOutline( pOwnChapterNode, pLayout );
881 
883  UpdateTemplate( pOwnChapterNode, pLayout );
884 
887  UpdateContent( SwTOXElement::Ole, pOwnChapterNode, pLayout );
888 
891  UpdateTable( pOwnChapterNode, pLayout );
892 
895  UpdateContent( SwTOXElement::Graphic, pOwnChapterNode, pLayout );
896 
897  if( !GetSequenceName().isEmpty() && !IsFromObjectNames() &&
900  UpdateSequence( pOwnChapterNode, pLayout );
901 
903  UpdateContent( SwTOXElement::Frame, pOwnChapterNode, pLayout );
904 
906  UpdateAuthorities( aIntl, pLayout );
907 
908  // Insert AlphaDelimiters if needed (just for keywords)
909  if( TOX_INDEX == SwTOXBase::GetType() &&
911  InsertAlphaDelimiter( aIntl );
912 
913  // remove old content an insert one empty textnode (to hold the layout!)
914  SwTextNode* pFirstEmptyNd;
915 
916  SwUndoUpdateIndex * pUndo(nullptr);
917  {
918  pDoc->getIDocumentRedlineAccess().DeleteRedline( *pSectNd, true, RedlineType::Any );
919 
920  SwNodeIndex aSttIdx( *pSectNd, +1 );
921  SwNodeIndex aEndIdx( *pSectNd->EndOfSectionNode() );
922  pFirstEmptyNd = pDoc->GetNodes().MakeTextNode( aEndIdx,
924 
925  {
926  // Task 70995 - save and restore PageDesc and Break Attributes
927  SwNodeIndex aNxtIdx( aSttIdx );
928  const SwContentNode* pCNd = aNxtIdx.GetNode().GetContentNode();
929  if( !pCNd )
930  pCNd = pDoc->GetNodes().GoNext( &aNxtIdx );
931  assert(pCNd != pFirstEmptyNd);
932  assert(pCNd->GetIndex() < pFirstEmptyNd->GetIndex());
933  if( pCNd->HasSwAttrSet() )
934  {
935  SfxItemSet aBrkSet( pDoc->GetAttrPool(), aBreakSetRange );
936  aBrkSet.Put( *pCNd->GetpSwAttrSet() );
937  if( aBrkSet.Count() )
938  pFirstEmptyNd->SetAttr( aBrkSet );
939  }
940  }
941 
942  if (pDoc->GetIDocumentUndoRedo().DoesUndo())
943  {
944  // note: this will first append a SwUndoDelSection from the ctor...
945  pUndo = new SwUndoUpdateIndex(*this);
946  // tdf#123313 insert Undo *after* all CrossRefBookmark Undos have
947  // been inserted by the Update*() functions
948  pDoc->GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndoUpdateIndex>(pUndo));
949  }
950  else
951  {
952  --aEndIdx;
953  SwPosition aPos( aEndIdx, SwIndex( pFirstEmptyNd, 0 ));
954  SwDoc::CorrAbs( aSttIdx, aEndIdx, aPos, true );
955 
956  // delete flys in whole range including start node which requires
957  // giving the node before start node as Mark parameter, hence -1.
958  // (flys must be deleted because the anchor nodes are removed)
959  DelFlyInRange( SwNodeIndex(aSttIdx, -1), aEndIdx );
960 
961  pDoc->GetNodes().Delete( aSttIdx, aEndIdx.GetIndex() - aSttIdx.GetIndex() );
962  }
963  }
964 
965  // insert title of TOX
966  if ( !GetTitle().isEmpty() )
967  {
968  // then insert the headline section
969  SwNodeIndex aIdx( *pSectNd, +1 );
970 
971  SwTextNode* pHeadNd = pDoc->GetNodes().MakeTextNode( aIdx,
973  pHeadNd->InsertText( GetTitle(), SwIndex( pHeadNd ) );
974 
975  SwSectionData headerData( SectionType::ToxHeader, GetTOXName()+"_Head" );
976 
977  SwNodeIndex aStt( *pHeadNd ); --aIdx;
978  SwSectionFormat* pSectFormat = pDoc->MakeSectionFormat();
979  pDoc->GetNodes().InsertTextSection(
980  aStt, *pSectFormat, headerData, nullptr, &aIdx, true, false);
981 
982  if (pUndo)
983  {
984  pUndo->TitleSectionInserted(*pSectFormat);
985  }
986  }
987 
988  // Sort the List of all TOC Marks and TOC Sections
989  std::vector<SwTextFormatColl*> aCollArr( GetTOXForm().GetFormMax(), nullptr );
990  SwNodeIndex aInsPos( *pFirstEmptyNd, 1 );
991  for( size_t nCnt = 0; nCnt < m_aSortArr.size(); ++nCnt )
992  {
993  ::SetProgressState( 0, pDoc->GetDocShell() );
994 
995  // Put the Text into the TOC
996  sal_uInt16 nLvl = m_aSortArr[ nCnt ]->GetLevel();
997  SwTextFormatColl* pColl = aCollArr[ nLvl ];
998  if( !pColl )
999  {
1000  pColl = GetTextFormatColl( nLvl );
1001  aCollArr[ nLvl ] = pColl;
1002  }
1003 
1004  // Generate: Set dynamic TabStops
1005  SwTextNode* pTOXNd = pDoc->GetNodes().MakeTextNode( aInsPos , pColl );
1006  m_aSortArr[ nCnt ]->pTOXNd = pTOXNd;
1007 
1008  // Generate: Evaluate Form and insert the place holder for the
1009  // page number. If it is a TOX_INDEX and the SwForm IsCommaSeparated()
1010  // then a range of entries must be generated into one paragraph
1011  size_t nRange = 1;
1012  if(TOX_INDEX == SwTOXBase::GetType() &&
1013  GetTOXForm().IsCommaSeparated() &&
1014  m_aSortArr[nCnt]->GetType() == TOX_SORT_INDEX)
1015  {
1016  const SwTOXMark& rMark = m_aSortArr[nCnt]->pTextMark->GetTOXMark();
1017  const OUString& sPrimKey = rMark.GetPrimaryKey();
1018  const OUString& sSecKey = rMark.GetSecondaryKey();
1019  const SwTOXMark* pNextMark = nullptr;
1020  while(m_aSortArr.size() > (nCnt + nRange)&&
1021  m_aSortArr[nCnt + nRange]->GetType() == TOX_SORT_INDEX &&
1022  nullptr != (pNextMark = &(m_aSortArr[nCnt + nRange]->pTextMark->GetTOXMark())) &&
1023  pNextMark->GetPrimaryKey() == sPrimKey &&
1024  pNextMark->GetSecondaryKey() == sSecKey)
1025  nRange++;
1026  }
1027  // pass node index of table-of-content section and default page description
1028  // to method <GenerateText(..)>.
1029  ::SetProgressState( 0, pDoc->GetDocShell() );
1030 
1031  std::shared_ptr<sw::ToxTabStopTokenHandler> tabStopTokenHandler =
1032  std::make_shared<sw::DefaultToxTabStopTokenHandler>(
1033  pSectNd->GetIndex(), *pDefaultPageDesc, GetTOXForm().IsRelTabPos(),
1037  sw::ToxTextGenerator ttgn(GetTOXForm(), tabStopTokenHandler);
1038  ttgn.GenerateText(GetFormat()->GetDoc(), m_aSortArr, nCnt, nRange, pLayout);
1039  nCnt += nRange - 1;
1040  }
1041 
1042  // delete the first dummy node and remove all Cursor into the previous node
1043  aInsPos = *pFirstEmptyNd;
1044  {
1045  SwPaM aCorPam( *pFirstEmptyNd );
1046  aCorPam.GetPoint()->nContent.Assign( pFirstEmptyNd, 0 );
1047  if( !aCorPam.Move( fnMoveForward ) )
1048  aCorPam.Move( fnMoveBackward );
1049  SwNodeIndex aEndIdx( aInsPos, 1 );
1050  SwDoc::CorrAbs( aInsPos, aEndIdx, *aCorPam.GetPoint(), true );
1051 
1052  // Task 70995 - save and restore PageDesc and Break Attributes
1053  if( pFirstEmptyNd->HasSwAttrSet() )
1054  {
1055  if( !GetTitle().isEmpty() )
1056  aEndIdx = *pSectNd;
1057  else
1058  aEndIdx = *pFirstEmptyNd;
1059  SwContentNode* pCNd = pDoc->GetNodes().GoNext( &aEndIdx );
1060  if( pCNd ) // Robust against defect documents, e.g. i60336
1061  pCNd->SetAttr( *pFirstEmptyNd->GetpSwAttrSet() );
1062  }
1063  }
1064 
1065  // now create the new Frames
1066  sal_uLong nIdx = pSectNd->GetIndex();
1067  // don't delete if index is empty
1068  if(nIdx + 2 < pSectNd->EndOfSectionIndex())
1069  pDoc->GetNodes().Delete( aInsPos );
1070 
1071  aN2L.RestoreUpperFrames( pDoc->GetNodes(), nIdx, nIdx + 1 );
1072  o3tl::sorted_vector<SwRootFrame*> aAllLayouts = pDoc->GetAllLayouts();
1073  for ( const auto& rpLayout : aAllLayouts )
1074  {
1075  SwFrame::CheckPageDescs( static_cast<SwPageFrame*>(rpLayout->Lower()) );
1076  }
1077 
1079 }
1080 
1082 {
1083  SwDoc* pDoc = GetFormat()->GetDoc();
1084  OUString sLastDeli;
1085  size_t i = 0;
1086  while( i < m_aSortArr.size() )
1087  {
1088  ::SetProgressState( 0, pDoc->GetDocShell() );
1089 
1090  sal_uInt16 nLevel = m_aSortArr[i]->GetLevel();
1091 
1092  // Skip AlphaDelimiter
1093  if( nLevel == FORM_ALPHA_DELIMITER )
1094  continue;
1095 
1096  const OUString sDeli = rIntl.GetIndexKey( m_aSortArr[i]->GetText(),
1097  m_aSortArr[i]->GetLocale() );
1098 
1099  // Do we already have a Delimiter?
1100  if( !sDeli.isEmpty() && sLastDeli != sDeli )
1101  {
1102  // We skip all that are less than a small Blank (these are special characters)
1103  if( ' ' <= sDeli[0] )
1104  {
1105  std::unique_ptr<SwTOXCustom> pCst(
1106  MakeSwTOXSortTabBase<SwTOXCustom>(nullptr,
1107  TextAndReading(sDeli, OUString()),
1109  rIntl, m_aSortArr[i]->GetLocale() ));
1110  m_aSortArr.insert( m_aSortArr.begin() + i, std::move(pCst));
1111  i++;
1112  }
1113  sLastDeli = sDeli;
1114  }
1115 
1116  // Skip until we get to the same or a lower Level
1117  do {
1118  i++;
1119  } while (i < m_aSortArr.size() && m_aSortArr[i]->GetLevel() > nLevel);
1120  }
1121 }
1122 
1125 {
1126  SwDoc* pDoc = GetFormat()->GetDoc();
1127  const OUString& rName = GetTOXForm().GetTemplate( nLevel );
1128  SwTextFormatColl* pColl = !rName.isEmpty() ? pDoc->FindTextFormatCollByName(rName) :nullptr;
1129  if( !pColl )
1130  {
1131  sal_uInt16 nPoolFormat = 0;
1132  const TOXTypes eMyType = SwTOXBase::GetType();
1133  switch( eMyType )
1134  {
1135  case TOX_INDEX: nPoolFormat = RES_POOLCOLL_TOX_IDXH; break;
1136  case TOX_USER:
1137  if( nLevel < 6 )
1138  nPoolFormat = RES_POOLCOLL_TOX_USERH;
1139  else
1140  nPoolFormat = RES_POOLCOLL_TOX_USER6 - 6;
1141  break;
1142  case TOX_ILLUSTRATIONS: nPoolFormat = RES_POOLCOLL_TOX_ILLUSH; break;
1143  case TOX_OBJECTS: nPoolFormat = RES_POOLCOLL_TOX_OBJECTH; break;
1144  case TOX_TABLES: nPoolFormat = RES_POOLCOLL_TOX_TABLESH; break;
1145  case TOX_AUTHORITIES:
1146  case TOX_BIBLIOGRAPHY:
1147  nPoolFormat = RES_POOLCOLL_TOX_AUTHORITIESH; break;
1148  case TOX_CITATION: break;
1149  case TOX_CONTENT:
1150  // There's a jump in the ContentArea!
1151  if( nLevel < 6 )
1152  nPoolFormat = RES_POOLCOLL_TOX_CNTNTH;
1153  else
1154  nPoolFormat = RES_POOLCOLL_TOX_CNTNT6 - 6;
1155  break;
1156  }
1157 
1158  if(eMyType == TOX_AUTHORITIES && nLevel)
1159  nPoolFormat = nPoolFormat + 1;
1160  else if(eMyType == TOX_INDEX && nLevel)
1161  {
1162  // pool: Level 1,2,3, Delimiter
1163  // SwForm: Delimiter, Level 1,2,3
1164  nPoolFormat += 1 == nLevel ? nLevel + 3 : nLevel - 1;
1165  }
1166  else
1167  nPoolFormat = nPoolFormat + nLevel;
1168  pColl = pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool( nPoolFormat );
1169  }
1170  return pColl;
1171 }
1172 
1175  const SwTextNode* pOwnChapterNode,
1176  SwRootFrame const*const pLayout)
1177 {
1178  const SwTOXType* pType = static_cast<SwTOXType*>( SwTOXBase::GetRegisteredIn() );
1179  if( !pType->HasWriterListeners() )
1180  return;
1181 
1182  SwDoc* pDoc = GetFormat()->GetDoc();
1183  TOXTypes eTOXTyp = GetTOXType()->GetType();
1184  SwIterator<SwTOXMark,SwTOXType> aIter( *pType );
1185 
1186  for (SwTOXMark* pMark = aIter.First(); pMark; pMark = aIter.Next())
1187  {
1188  ::SetProgressState( 0, pDoc->GetDocShell() );
1189 
1190  if (pMark->GetTOXType()->GetType() == eTOXTyp)
1191  {
1192  SwTextTOXMark *const pTextMark(pMark->GetTextTOXMark());
1193  if (nullptr == pTextMark)
1194  continue;
1195  const SwTextNode* pTOXSrc = pTextMark->GetpTextNd();
1196  // Only insert TOXMarks from the Doc, not from the
1197  // UNDO.
1198 
1199  // If selected use marks from the same chapter only
1200  if( pTOXSrc->GetNodes().IsDocNodes() &&
1201  pTOXSrc->GetText().getLength() && pTOXSrc->HasWriterListeners() &&
1203  (!IsFromChapter() || ::lcl_FindChapterNode(*pTOXSrc, pLayout) == pOwnChapterNode) &&
1204  !pTOXSrc->IsHiddenByParaField() &&
1205  !SwScriptInfo::IsInHiddenRange(*pTOXSrc, pTextMark->GetStart()) &&
1206  (!pLayout || !pLayout->IsHideRedlines()
1207  || !sw::IsMarkHintHidden(*pLayout, *pTOXSrc, *pTextMark)))
1208  {
1209  if(TOX_INDEX == eTOXTyp)
1210  {
1211  // index entry mark
1212  assert(g_pBreakIt);
1213  lang::Locale aLocale = g_pBreakIt->GetLocale(pTOXSrc->GetLang(pTextMark->GetStart()));
1214 
1215  InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
1216  GetOptions(), FORM_ENTRY, rIntl, aLocale ));
1218  !pTextMark->GetTOXMark().GetPrimaryKey().isEmpty())
1219  {
1220  InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
1221  GetOptions(), FORM_PRIMARY_KEY, rIntl, aLocale ));
1222  if (!pTextMark->GetTOXMark().GetSecondaryKey().isEmpty())
1223  {
1224  InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
1225  GetOptions(), FORM_SECONDARY_KEY, rIntl, aLocale ));
1226  }
1227  }
1228  }
1229  else if( TOX_USER == eTOXTyp ||
1230  pMark->GetLevel() <= GetLevel())
1231  { // table of content mark
1232  // also used for user marks
1233  InsertSorted(MakeSwTOXSortTabBase<SwTOXContent>(pLayout, *pTOXSrc, pTextMark, rIntl));
1234  }
1235  }
1236  }
1237  }
1238 }
1239 
1241 void SwTOXBaseSection::UpdateOutline( const SwTextNode* pOwnChapterNode,
1242  SwRootFrame const*const pLayout)
1243 {
1244  SwDoc* pDoc = GetFormat()->GetDoc();
1245  SwNodes& rNds = pDoc->GetNodes();
1246 
1247  const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds();
1248  for( auto pOutlineNode : rOutlNds )
1249  {
1250  ::SetProgressState( 0, pDoc->GetDocShell() );
1251  SwTextNode* pTextNd = pOutlineNode->GetTextNode();
1252  if( pTextNd && pTextNd->Len() && pTextNd->HasWriterListeners() &&
1253  o3tl::make_unsigned( pTextNd->GetAttrOutlineLevel()) <= GetLevel() &&
1254  pTextNd->getLayoutFrame(pLayout) &&
1255  !pTextNd->IsHiddenByParaField() &&
1256  !pTextNd->HasHiddenCharAttribute( true ) &&
1257  (!pLayout || !pLayout->IsHideRedlines()
1258  || static_cast<SwTextFrame*>(pTextNd->getLayoutFrame(pLayout))->GetTextNodeForParaProps() == pTextNd) &&
1259  ( !IsFromChapter() ||
1260  ::lcl_FindChapterNode(*pTextNd, pLayout) == pOwnChapterNode ))
1261  {
1262  InsertSorted(MakeSwTOXSortTabBase<SwTOXPara>(pLayout, *pTextNd, SwTOXElement::OutlineLevel));
1263  }
1264  }
1265 }
1266 
1268 void SwTOXBaseSection::UpdateTemplate(const SwTextNode* pOwnChapterNode,
1269  SwRootFrame const*const pLayout)
1270 {
1271  SwDoc* pDoc = GetFormat()->GetDoc();
1272  for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
1273  {
1274  const OUString sTmpStyleNames = GetStyleNames(i);
1275  if (sTmpStyleNames.isEmpty())
1276  continue;
1277 
1278  sal_Int32 nIndex = 0;
1279  while (nIndex >= 0)
1280  {
1282  sTmpStyleNames.getToken( 0, TOX_STYLE_DELIMITER, nIndex ));
1283  //TODO: no outline Collections in content indexes if OutlineLevels are already included
1284  if( !pColl ||
1288  continue;
1289 
1290  SwIterator<SwTextNode,SwFormatColl> aIter( *pColl );
1291  for( SwTextNode* pTextNd = aIter.First(); pTextNd; pTextNd = aIter.Next() )
1292  {
1293  ::SetProgressState( 0, pDoc->GetDocShell() );
1294 
1295  if (pTextNd->GetText().getLength() &&
1296  pTextNd->getLayoutFrame(pLayout) &&
1297  pTextNd->GetNodes().IsDocNodes() &&
1298  (!pLayout || !pLayout->IsHideRedlines()
1299  || static_cast<SwTextFrame*>(pTextNd->getLayoutFrame(pLayout))->GetTextNodeForParaProps() == pTextNd) &&
1300  (!IsFromChapter() || pOwnChapterNode ==
1301  ::lcl_FindChapterNode(*pTextNd, pLayout)))
1302  {
1303  InsertSorted(MakeSwTOXSortTabBase<SwTOXPara>(pLayout, *pTextNd, SwTOXElement::Template, i + 1));
1304  }
1305  }
1306  }
1307  }
1308 }
1309 
1311 void SwTOXBaseSection::UpdateSequence(const SwTextNode* pOwnChapterNode,
1312  SwRootFrame const*const pLayout)
1313 {
1314  SwDoc* pDoc = GetFormat()->GetDoc();
1316  if(!pSeqField)
1317  return;
1318 
1319  std::vector<SwFormatField*> vFields;
1320  pSeqField->GatherFields(vFields);
1321  for(auto pFormatField: vFields)
1322  {
1323  const SwTextField* pTextField = pFormatField->GetTextField();
1324  SwTextNode& rTextNode = pTextField->GetTextNode();
1325  ::SetProgressState( 0, pDoc->GetDocShell() );
1326 
1327  if (rTextNode.GetText().getLength() &&
1328  rTextNode.getLayoutFrame(pLayout) &&
1329  ( !IsFromChapter() ||
1330  ::lcl_FindChapterNode(rTextNode, pLayout) == pOwnChapterNode)
1331  && (!pLayout || !pLayout->IsHideRedlines()
1332  || !sw::IsFieldDeletedInModel(pDoc->getIDocumentRedlineAccess(), *pTextField)))
1333  {
1334  const SwSetExpField& rSeqField = dynamic_cast<const SwSetExpField&>(*(pFormatField->GetField()));
1335  const OUString sName = GetSequenceName()
1336  + OUStringChar(cSequenceMarkSeparator)
1337  + OUString::number( rSeqField.GetSeqNumber() );
1338  std::unique_ptr<SwTOXPara> pNew(new SwTOXPara( rTextNode, SwTOXElement::Sequence, 1, sName ));
1339  // set indexes if the number or the reference text are to be displayed
1340  if( GetCaptionDisplay() == CAPTION_TEXT )
1341  {
1342  pNew->SetStartIndex(
1343  SwGetExpField::GetReferenceTextPos( *pFormatField, *pDoc ));
1344  }
1345  else if(GetCaptionDisplay() == CAPTION_NUMBER)
1346  {
1347  pNew->SetEndIndex(pTextField->GetStart() + 1);
1348  }
1349  pNew->InitText(pLayout);
1350  InsertSorted(std::move(pNew));
1351  }
1352  }
1353 }
1354 
1356  SwRootFrame const*const pLayout)
1357 {
1358  SwDoc* pDoc = GetFormat()->GetDoc();
1359  SwFieldType* pAuthField = pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::TableOfAuthorities, OUString(), false);
1360  if(!pAuthField)
1361  return;
1362 
1363  std::vector<SwFormatField*> vFields;
1364  pAuthField->GatherFields(vFields);
1365  for(auto pFormatField: vFields)
1366  {
1367  const auto pTextField = pFormatField->GetTextField();
1368  const SwTextNode& rTextNode = pFormatField->GetTextField()->GetTextNode();
1369  ::SetProgressState( 0, pDoc->GetDocShell() );
1370 
1371  if (rTextNode.GetText().getLength() &&
1372  rTextNode.getLayoutFrame(pLayout) &&
1373  (!pLayout || !pLayout->IsHideRedlines()
1374  || !sw::IsFieldDeletedInModel(pDoc->getIDocumentRedlineAccess(), *pTextField)))
1375  {
1376  //#106485# the body node has to be used!
1377  SwContentFrame *const pFrame = rTextNode.getLayoutFrame(pLayout);
1378  SwPosition aFieldPos(rTextNode);
1379  const SwTextNode* pTextNode = nullptr;
1380  if(pFrame && !pFrame->IsInDocBody())
1381  pTextNode = GetBodyTextNode( *pDoc, aFieldPos, *pFrame );
1382  if(!pTextNode)
1383  pTextNode = &rTextNode;
1384 
1385  InsertSorted(MakeSwTOXSortTabBase<SwTOXAuthority>(pLayout, *pTextNode, *pFormatField, rIntl));
1386  }
1387  }
1388 }
1389 
1390 static SwTOOElements lcl_IsSOObject( const SvGlobalName& rFactoryNm )
1391 {
1392  static const struct SoObjType {
1393  SwTOOElements nFlag;
1394  // GlobalNameId
1395  struct {
1396  sal_uInt32 n1;
1397  sal_uInt16 n2, n3;
1398  sal_uInt8 b8, b9, b10, b11, b12, b13, b14, b15;
1399  } aGlNmIds[4];
1400  } aArr[] = {
1415  };
1416 
1417  for( SoObjType const & rArr : aArr )
1418  for (auto & rId : rArr.aGlNmIds)
1419  {
1420  if( !rId.n1 )
1421  break;
1422  SvGlobalName aGlbNm( rId.n1, rId.n2, rId.n3,
1423  rId.b8, rId.b9, rId.b10, rId.b11,
1424  rId.b12, rId.b13, rId.b14, rId.b15 );
1425  if( rFactoryNm == aGlbNm )
1426  {
1427  return rArr.nFlag;
1428  }
1429  }
1430 
1431  return SwTOOElements::NONE;
1432 }
1433 
1435  const SwTextNode* pOwnChapterNode,
1436  SwRootFrame const*const pLayout)
1437 {
1438  SwDoc* pDoc = GetFormat()->GetDoc();
1439  SwNodes& rNds = pDoc->GetNodes();
1440  // on the 1st Node of the 1st Section
1441  sal_uLong nIdx = rNds.GetEndOfAutotext().StartOfSectionIndex() + 2,
1442  nEndIdx = rNds.GetEndOfAutotext().GetIndex();
1443 
1444  while( nIdx < nEndIdx )
1445  {
1446  ::SetProgressState( 0, pDoc->GetDocShell() );
1447 
1448  SwNode* pNd = rNds[ nIdx ];
1449  SwContentNode* pCNd = nullptr;
1450  switch( eMyType )
1451  {
1452  case SwTOXElement::Frame:
1453  if( !pNd->IsNoTextNode() )
1454  {
1455  pCNd = pNd->GetContentNode();
1456  if( !pCNd )
1457  {
1458  SwNodeIndex aTmp( *pNd );
1459  pCNd = rNds.GoNext( &aTmp );
1460  }
1461  }
1462  break;
1463  case SwTOXElement::Graphic:
1464  if( pNd->IsGrfNode() )
1465  pCNd = static_cast<SwContentNode*>(pNd);
1466  break;
1467  case SwTOXElement::Ole:
1468  if( pNd->IsOLENode() )
1469  {
1470  bool bInclude = true;
1472  {
1473  SwOLENode* pOLENode = pNd->GetOLENode();
1474  SwTOOElements nMyOLEOptions = GetOLEOptions();
1475  SwOLEObj& rOLEObj = pOLENode->GetOLEObj();
1476 
1477  if( rOLEObj.IsOleRef() ) // Not yet loaded
1478  {
1479  SvGlobalName aTmpName( rOLEObj.GetOleRef()->getClassID() );
1480  SwTOOElements nObj = ::lcl_IsSOObject( aTmpName );
1481  bInclude = ( (nMyOLEOptions & SwTOOElements::Other) && SwTOOElements::NONE == nObj )
1482  || (nMyOLEOptions & nObj);
1483  }
1484  else
1485  {
1486  OSL_FAIL("OLE Object no loaded?");
1487  bInclude = false;
1488  }
1489  }
1490 
1491  if(bInclude)
1492  pCNd = static_cast<SwContentNode*>(pNd);
1493  }
1494  break;
1495  default: break;
1496  }
1497 
1498  if( pCNd )
1499  {
1500  // find node in body text
1501  int nSetLevel = USHRT_MAX;
1502 
1503  //#111105# tables of tables|illustrations|objects don't support hierarchies
1504  if( IsLevelFromChapter() &&
1508  {
1509  const SwTextNode* pOutlNd = ::lcl_FindChapterNode( *pCNd,
1510  pLayout, MAXLEVEL - 1);
1511  if( pOutlNd )
1512  {
1514  {
1515  nSetLevel = pOutlNd->GetTextColl()->GetAttrOutlineLevel();
1516  }
1517  }
1518  }
1519 
1520  if (pCNd->getLayoutFrame(pLayout)
1521  && (!pLayout || !pLayout->IsHideRedlines()
1523  && ( !IsFromChapter() ||
1524  ::lcl_FindChapterNode(*pCNd, pLayout) == pOwnChapterNode ))
1525  {
1526  std::unique_ptr<SwTOXPara> pNew( MakeSwTOXSortTabBase<SwTOXPara>(
1527  pLayout, *pCNd, eMyType,
1528  ( USHRT_MAX != nSetLevel )
1529  ? static_cast<sal_uInt16>(nSetLevel)
1530  : FORM_ALPHA_DELIMITER ) );
1531  InsertSorted( std::move(pNew) );
1532  }
1533  }
1534 
1535  nIdx = pNd->StartOfSectionNode()->EndOfSectionIndex() + 2; // 2 == End/Start Node
1536  }
1537 }
1538 
1540 void SwTOXBaseSection::UpdateTable(const SwTextNode* pOwnChapterNode,
1541  SwRootFrame const*const pLayout)
1542 {
1543  SwDoc* pDoc = GetFormat()->GetDoc();
1544  SwNodes& rNds = pDoc->GetNodes();
1545  const SwFrameFormats& rArr = *pDoc->GetTableFrameFormats();
1546 
1547  for( auto pFrameFormat : rArr )
1548  {
1549  ::SetProgressState( 0, pDoc->GetDocShell() );
1550 
1551  SwTable* pTmpTable = SwTable::FindTable( pFrameFormat );
1552  SwTableBox* pFBox;
1553  if( pTmpTable && nullptr != (pFBox = pTmpTable->GetTabSortBoxes()[0] ) &&
1554  pFBox->GetSttNd() && pFBox->GetSttNd()->GetNodes().IsDocNodes() )
1555  {
1556  const SwTableNode* pTableNd = pFBox->GetSttNd()->FindTableNode();
1557  SwNodeIndex aContentIdx( *pTableNd, 1 );
1558 
1559  SwContentNode* pCNd;
1560  while( nullptr != ( pCNd = rNds.GoNext( &aContentIdx ) ) &&
1561  aContentIdx.GetIndex() < pTableNd->EndOfSectionIndex() )
1562  {
1563  if (pCNd->getLayoutFrame(pLayout)
1564  && (!pLayout || !pLayout->IsHideRedlines()
1566  && (!IsFromChapter()
1567  || ::lcl_FindChapterNode(*pCNd, pLayout) == pOwnChapterNode))
1568  {
1569  std::unique_ptr<SwTOXTable> pNew(new SwTOXTable( *pCNd ));
1571  {
1572  const SwTextNode* pOutlNd =
1573  ::lcl_FindChapterNode(*pCNd, pLayout, MAXLEVEL - 1);
1574  if( pOutlNd )
1575  {
1577  {
1578  const int nTmp = pOutlNd->GetTextColl()->GetAttrOutlineLevel();
1579  pNew->SetLevel(static_cast<sal_uInt16>(nTmp));
1580  }
1581  }
1582  }
1583  pNew->InitText(pLayout);
1584  InsertSorted(std::move(pNew));
1585  break;
1586  }
1587  }
1588  }
1589  }
1590 }
1591 
1594 {
1595  if( m_aSortArr.empty() )
1596  return ;
1597 
1598  // Insert the current PageNumber into the TOC
1599  SwPageFrame* pCurrentPage = nullptr;
1600  sal_uInt16 nPage = 0;
1601  SwDoc* pDoc = GetFormat()->GetDoc();
1602 
1604  TOX_INDEX == GetTOXType()->GetType() ?
1606  GetSortAlgorithm() );
1607 
1608  for( size_t nCnt = 0; nCnt < m_aSortArr.size(); ++nCnt )
1609  {
1610  // Loop over all SourceNodes
1611 
1612  // process run in lines
1613  size_t nRange = 0;
1614  if(GetTOXForm().IsCommaSeparated() &&
1615  m_aSortArr[nCnt]->GetType() == TOX_SORT_INDEX)
1616  {
1617  const SwTOXMark& rMark = m_aSortArr[nCnt]->pTextMark->GetTOXMark();
1618  const OUString& sPrimKey = rMark.GetPrimaryKey();
1619  const OUString& sSecKey = rMark.GetSecondaryKey();
1620  const SwTOXMark* pNextMark = nullptr;
1621  while(m_aSortArr.size() > (nCnt + nRange)&&
1622  m_aSortArr[nCnt + nRange]->GetType() == TOX_SORT_INDEX &&
1623  nullptr != (pNextMark = &(m_aSortArr[nCnt + nRange]->pTextMark->GetTOXMark())) &&
1624  pNextMark->GetPrimaryKey() == sPrimKey &&
1625  pNextMark->GetSecondaryKey() == sSecKey)
1626  nRange++;
1627  }
1628  else
1629  nRange = 1;
1630 
1631  for(size_t nRunInEntry = nCnt; nRunInEntry < nCnt + nRange; ++nRunInEntry)
1632  {
1633  std::vector<sal_uInt16> aNums; // the PageNumber
1634  std::vector<SwPageDesc*> aDescs; // The PageDescriptors matching the PageNumbers
1635  std::vector<sal_uInt16> aMainNums; // contains page numbers of main entries
1636  SwTOXSortTabBase* pSortBase = m_aSortArr[nRunInEntry].get();
1637  size_t nSize = pSortBase->aTOXSources.size();
1638  for (size_t j = 0; j < nSize; ++j)
1639  {
1640  ::SetProgressState( 0, pDoc->GetDocShell() );
1641 
1642  SwTOXSource& rTOXSource = pSortBase->aTOXSources[j];
1643  if( rTOXSource.pNd )
1644  {
1645  SwContentFrame* pFrame = rTOXSource.pNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() );
1646  OSL_ENSURE( pFrame || pDoc->IsUpdateTOX(), "TOX, no Frame found");
1647  if( !pFrame )
1648  continue;
1649  if( pFrame->IsTextFrame() && static_cast<SwTextFrame*>(pFrame)->HasFollow() )
1650  {
1651  // find the right one
1652  SwTextFrame* pNext;
1653  TextFrameIndex const nPos(static_cast<SwTextFrame*>(pFrame)
1654  ->MapModelToView(static_cast<SwTextNode const*>(rTOXSource.pNd),
1655  rTOXSource.nPos));
1656  while( nullptr != ( pNext = static_cast<SwTextFrame*>(pFrame->GetFollow()) )
1657  && nPos >= pNext->GetOffset())
1658  pFrame = pNext;
1659  }
1660 
1661  SwPageFrame* pTmpPage = pFrame->FindPageFrame();
1662  if( pTmpPage != pCurrentPage )
1663  {
1664  nPage = pTmpPage->GetVirtPageNum();
1665  pCurrentPage = pTmpPage;
1666  }
1667 
1668  // Insert as sorted
1669  std::vector<sal_uInt16>::size_type i;
1670  for( i = 0; i < aNums.size() && aNums[i] < nPage; ++i )
1671  ;
1672 
1673  if( i >= aNums.size() || aNums[ i ] != nPage )
1674  {
1675  aNums.insert(aNums.begin() + i, nPage);
1676  aDescs.insert(aDescs.begin() + i, pCurrentPage->GetPageDesc() );
1677  }
1678  // is it a main entry?
1679  if(TOX_SORT_INDEX == pSortBase->GetType() &&
1680  rTOXSource.bMainEntry)
1681  {
1682  aMainNums.push_back(nPage);
1683  }
1684  }
1685  }
1686  // Insert the PageNumber into the TOC TextNode
1687  const SwTOXSortTabBase* pBase = m_aSortArr[ nCnt ].get();
1688  if(pBase->pTOXNd)
1689  {
1690  const SwTextNode* pTextNd = pBase->pTOXNd->GetTextNode();
1691  OSL_ENSURE( pTextNd, "no TextNode, wrong TOC" );
1692 
1693  UpdatePageNum_( const_cast<SwTextNode*>(pTextNd), aNums, aDescs, &aMainNums,
1694  aIntl );
1695  }
1696  }
1697  }
1698  // Delete the mapping array after setting the right PageNumber
1699  m_aSortArr.clear();
1700 }
1701 
1704 static bool lcl_HasMainEntry( const std::vector<sal_uInt16>* pMainEntryNums, sal_uInt16 nToFind )
1705 {
1706  if (!pMainEntryNums)
1707  return false;
1708 
1709  for( auto nMainEntry : *pMainEntryNums )
1710  if (nToFind == nMainEntry)
1711  return true;
1712  return false;
1713 }
1714 
1716  const std::vector<sal_uInt16>& rNums,
1717  const std::vector<SwPageDesc*>& rDescs,
1718  const std::vector<sal_uInt16>* pMainEntryNums,
1719  const SwTOXInternational& rIntl )
1720 {
1721  // collect starts end ends of main entry character style
1722  std::unique_ptr< std::vector<sal_uInt16> > xCharStyleIdx(pMainEntryNums ? new std::vector<sal_uInt16> : nullptr);
1723 
1724  OUString sSrchStr = OUStringChar(C_NUM_REPL) + S_PAGE_DELI + OUStringChar(C_NUM_REPL);
1725  sal_Int32 nStartPos = pNd->GetText().indexOf(sSrchStr);
1726  sSrchStr = OUStringChar(C_NUM_REPL) + OUStringChar(C_END_PAGE_NUM);
1727  sal_Int32 nEndPos = pNd->GetText().indexOf(sSrchStr);
1728 
1729  if (-1 == nEndPos || rNums.empty())
1730  return;
1731 
1732  if (-1 == nStartPos || nStartPos > nEndPos)
1733  nStartPos = nEndPos;
1734 
1735  sal_uInt16 nOld = rNums[0],
1736  nBeg = nOld,
1737  nCount = 0;
1738  OUString aNumStr( rDescs[0]->GetNumType().GetNumStr( nBeg ) );
1739  if( xCharStyleIdx && lcl_HasMainEntry( pMainEntryNums, nBeg ))
1740  {
1741  xCharStyleIdx->push_back( 0 );
1742  }
1743 
1744  // Delete place holder
1745  SwIndex aPos(pNd, nStartPos);
1746  SwCharFormat* pPageNoCharFormat = nullptr;
1747  SwpHints* pHints = pNd->GetpSwpHints();
1748  if(pHints)
1749  for(size_t nHintIdx = 0; nHintIdx < pHints->Count(); ++nHintIdx)
1750  {
1751  const SwTextAttr* pAttr = pHints->Get(nHintIdx);
1752  const sal_Int32 nTmpEnd = pAttr->End() ? *pAttr->End() : 0;
1753  if( nStartPos >= pAttr->GetStart() &&
1754  (nStartPos + 2) <= nTmpEnd &&
1755  pAttr->Which() == RES_TXTATR_CHARFMT)
1756  {
1757  pPageNoCharFormat = pAttr->GetCharFormat().GetCharFormat();
1758  break;
1759  }
1760  }
1761  pNd->EraseText(aPos, nEndPos - nStartPos + 2);
1762 
1763  std::vector<sal_uInt16>::size_type i;
1764  for( i = 1; i < rNums.size(); ++i)
1765  {
1766  SvxNumberType aType( rDescs[i]->GetNumType() );
1767  if( TOX_INDEX == SwTOXBase::GetType() )
1768  { // Summarize for the following
1769  // Add up all following
1770  // break up if main entry starts or ends and
1771  // insert a char style index
1772  bool bMainEntryChanges = lcl_HasMainEntry(pMainEntryNums, nOld)
1773  != lcl_HasMainEntry(pMainEntryNums, rNums[i]);
1774 
1775  if(nOld == rNums[i]-1 && !bMainEntryChanges &&
1777  nCount++;
1778  else
1779  {
1780  // Flush for the following old values
1782  {
1783  if ( nCount >= 1 )
1784  aNumStr += rIntl.GetFollowingText( nCount > 1 );
1785  }
1786  else if (nCount) //#58127# If nCount == 0, then the only PageNumber is already in aNumStr!
1787  {
1788  if (nCount == 1 )
1789  aNumStr += S_PAGE_DELI;
1790  else
1791  aNumStr += "-";
1792 
1793  aNumStr += aType.GetNumStr( nBeg + nCount );
1794  }
1795 
1796  // Create new String
1797  nBeg = rNums[i];
1798  aNumStr += S_PAGE_DELI;
1799  //the change of the character style must apply after sPageDeli is appended
1800  if (xCharStyleIdx && bMainEntryChanges)
1801  {
1802  xCharStyleIdx->push_back(aNumStr.getLength());
1803  }
1804  aNumStr += aType.GetNumStr( nBeg );
1805  nCount = 0;
1806  }
1807  nOld = rNums[i];
1808  }
1809  else
1810  { // Insert all Numbers
1811  aNumStr += aType.GetNumStr( rNums[i] );
1812  if (i+1 != rNums.size())
1813  aNumStr += S_PAGE_DELI;
1814  }
1815  }
1816  // Flush when ending and the following old values
1817  if( TOX_INDEX == SwTOXBase::GetType() )
1818  {
1820  {
1821  if( nCount >= 1 )
1822  aNumStr += rIntl.GetFollowingText( nCount > 1 );
1823  }
1824  else
1825  {
1826  if(nCount >= 2)
1827  aNumStr += "-";
1828  else if(nCount == 1)
1829  aNumStr += S_PAGE_DELI;
1830  //#58127# If nCount == 0, then the only PageNumber is already in aNumStr!
1831  if(nCount)
1832  aNumStr += rDescs[i-1]->GetNumType().GetNumStr( nBeg+nCount );
1833  }
1834  }
1836  if(pPageNoCharFormat)
1837  {
1838  SwFormatCharFormat aCharFormat( pPageNoCharFormat );
1839  pNd->InsertItem(aCharFormat, nStartPos, nStartPos + aNumStr.getLength(), SetAttrMode::DONTEXPAND);
1840  }
1841 
1842  // The main entries should get their character style
1843  if (xCharStyleIdx && !xCharStyleIdx->empty() && !GetMainEntryCharStyle().isEmpty())
1844  {
1845  // eventually the last index must me appended
1846  if (xCharStyleIdx->size()&0x01)
1847  xCharStyleIdx->push_back(aNumStr.getLength());
1848 
1849  // search by name
1850  SwDoc* pDoc = pNd->GetDoc();
1852  SwCharFormat* pCharFormat = nullptr;
1853  if(USHRT_MAX != nPoolId)
1854  pCharFormat = pDoc->getIDocumentStylePoolAccess().GetCharFormatFromPool(nPoolId);
1855  else
1856  pCharFormat = pDoc->FindCharFormatByName( GetMainEntryCharStyle() );
1857  if(!pCharFormat)
1858  pCharFormat = pDoc->MakeCharFormat(GetMainEntryCharStyle(), nullptr);
1859 
1860  // find the page numbers in aNumStr and set the character style
1861  sal_Int32 nOffset = pNd->GetText().getLength() - aNumStr.getLength();
1862  SwFormatCharFormat aCharFormat(pCharFormat);
1863  for (size_t j = 0; j < xCharStyleIdx->size(); j += 2)
1864  {
1865  sal_Int32 nStartIdx = (*xCharStyleIdx)[j] + nOffset;
1866  sal_Int32 nEndIdx = (*xCharStyleIdx)[j + 1] + nOffset;
1867  pNd->InsertItem(aCharFormat, nStartIdx, nEndIdx, SetAttrMode::DONTEXPAND);
1868  }
1869 
1870  }
1871 }
1872 
1873 void SwTOXBaseSection::InsertSorted(std::unique_ptr<SwTOXSortTabBase> pNew)
1874 {
1875  Range aRange(0, m_aSortArr.size());
1876  if( TOX_INDEX == SwTOXBase::GetType() && pNew->pTextMark )
1877  {
1878  const SwTOXMark& rMark = pNew->pTextMark->GetTOXMark();
1879  // Evaluate Key
1880  // Calculate the range where to insert
1881  if( !(GetOptions() & SwTOIOptions::KeyAsEntry) &&
1882  !rMark.GetPrimaryKey().isEmpty() )
1883  {
1884  aRange = GetKeyRange( rMark.GetPrimaryKey(),
1885  rMark.GetPrimaryKeyReading(),
1886  *pNew, FORM_PRIMARY_KEY, aRange );
1887 
1888  if( !rMark.GetSecondaryKey().isEmpty() )
1889  aRange = GetKeyRange( rMark.GetSecondaryKey(),
1890  rMark.GetSecondaryKeyReading(),
1891  *pNew, FORM_SECONDARY_KEY, aRange );
1892  }
1893  }
1894  // Search for identical entries and remove the trailing one
1896  {
1897  for(short i = static_cast<short>(aRange.Min()); i < static_cast<short>(aRange.Max()); ++i)
1898  {
1899  SwTOXSortTabBase* pOld = m_aSortArr[i].get();
1900  if (pOld->equivalent(*pNew))
1901  {
1902  if (pOld->sort_lt(*pNew))
1903  {
1904  return;
1905  }
1906  else
1907  {
1908  // remove the old content
1909  m_aSortArr.erase( m_aSortArr.begin() + i );
1910  aRange.Max()--;
1911  break;
1912  }
1913  }
1914  }
1915  }
1916 
1917  // find position and insert
1918  long i;
1919 
1920  for( i = aRange.Min(); i < aRange.Max(); ++i)
1921  { // Only check for same level
1922  SwTOXSortTabBase* pOld = m_aSortArr[i].get();
1923  if (pOld->equivalent(*pNew))
1924  {
1926  {
1927  // Own entry for double entries or keywords
1928  if( pOld->GetType() == TOX_SORT_CUSTOM &&
1930  continue;
1931 
1933  { // Own entry
1934  m_aSortArr.insert(m_aSortArr.begin() + i, std::move(pNew));
1935  return;
1936  }
1937  // If the own entry is already present, add it to the references list
1938  pOld->aTOXSources.push_back(pNew->aTOXSources[0]);
1939 
1940  return;
1941  }
1942 #if OSL_DEBUG_LEVEL > 0
1943  else
1944  OSL_FAIL("Bibliography entries cannot be found here");
1945 #endif
1946  }
1947  if (pNew->sort_lt(*pOld))
1948  break;
1949  }
1950  // Skip SubLevel
1951  while( TOX_INDEX == SwTOXBase::GetType() && i < aRange.Max() &&
1952  m_aSortArr[i]->GetLevel() > pNew->GetLevel() )
1953  i++;
1954 
1955  // Insert at position i
1956  m_aSortArr.insert(m_aSortArr.begin()+i, std::move(pNew));
1957 }
1958 
1960 Range SwTOXBaseSection::GetKeyRange(const OUString& rStr, const OUString& rStrReading,
1961  const SwTOXSortTabBase& rNew,
1962  sal_uInt16 nLevel, const Range& rRange )
1963 {
1964  const SwTOXInternational& rIntl = *rNew.pTOXIntl;
1965  TextAndReading aToCompare(rStr, rStrReading);
1966 
1968  {
1969  aToCompare.sText = rIntl.ToUpper( aToCompare.sText, 0 )
1970  + aToCompare.sText.copy(1);
1971  }
1972 
1973  OSL_ENSURE(rRange.Min() >= 0 && rRange.Max() >= 0, "Min Max < 0");
1974 
1975  const long nMin = rRange.Min();
1976  const long nMax = rRange.Max();
1977 
1978  long i;
1979 
1980  for( i = nMin; i < nMax; ++i)
1981  {
1982  SwTOXSortTabBase* pBase = m_aSortArr[i].get();
1983 
1984  if( rIntl.IsEqual( pBase->GetText(), pBase->GetLocale(),
1985  aToCompare, rNew.GetLocale() ) &&
1986  pBase->GetLevel() == nLevel )
1987  break;
1988  }
1989  if(i == nMax)
1990  { // If not already present, create and insert
1991  std::unique_ptr<SwTOXCustom> pKey(MakeSwTOXSortTabBase<SwTOXCustom>(
1992  nullptr, aToCompare, nLevel, rIntl, rNew.GetLocale() ));
1993  for(i = nMin; i < nMax; ++i)
1994  {
1995  if (nLevel == m_aSortArr[i]->GetLevel() && pKey->sort_lt(*m_aSortArr[i]))
1996  break;
1997  }
1998  m_aSortArr.insert(m_aSortArr.begin() + i, std::move(pKey));
1999  }
2000  const long nStart = i+1;
2001  const long nEnd = m_aSortArr.size();
2002 
2003  // Find end of range
2004  for(i = nStart; i < nEnd; ++i)
2005  {
2006  if(m_aSortArr[i]->GetLevel() <= nLevel)
2007  {
2008  return Range(nStart, i);
2009  }
2010  }
2011  return Range(nStart, nEnd);
2012 }
2013 
2015 {
2016  const SwTOXBaseSection *pSect = dynamic_cast<const SwTOXBaseSection*>(this);
2017  if (!pSect || !pSect->GetFormat())
2018  return false;
2019 
2020  const SwSectionNode* pSectNode = pSect->GetFormat()->GetSectionNode();
2021  if (!pSectNode)
2022  return false;
2023 
2024  const SwDocShell* pDocSh = pSectNode->GetDoc()->GetDocShell();
2025  if (!pDocSh)
2026  return false;
2027 
2028  if (pDocSh->IsReadOnly())
2029  return true;
2030 
2031  pSectNode = pSectNode->StartOfSectionNode()->FindSectionNode();
2032  if (!pSectNode)
2033  return false;
2034 
2035  return pSectNode->GetSection().IsProtectFlag();
2036 }
2037 
2039 {
2040  const SwTOXBaseSection *pSect = dynamic_cast<const SwTOXBaseSection*>(this);
2041  if(pSect && pSect->GetFormat())
2042  return &pSect->GetFormat()->GetAttrSet();
2043  return nullptr;
2044 }
2045 
2047 {
2048  SwTOXBaseSection *pSect = dynamic_cast<SwTOXBaseSection*>(this);
2049  if( pSect && pSect->GetFormat() )
2050  pSect->GetFormat()->SetFormatAttr( rSet );
2051 }
2052 
2053 bool SwTOXBase::GetInfo( SfxPoolItem& rInfo ) const
2054 {
2055  switch( rInfo.Which() )
2056  {
2057  case RES_CONTENT_VISIBLE:
2058  {
2059  const SwTOXBaseSection *pSect = dynamic_cast<const SwTOXBaseSection*>(this);
2060  if( pSect && pSect->GetFormat() )
2061  pSect->GetFormat()->GetInfo( rInfo );
2062  }
2063  return false;
2064  }
2065  return true;
2066 }
2067 
2068 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SwCharFormat * GetCharFormatFromPool(sal_uInt16 nId)=0
OUString GetNumStr(sal_Int32 nNo) const
SwSectionNode * FindSectionNode()
Search section node, in which it is.
Definition: ndsect.cxx:955
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
#define SO3_SM_CLASSID_60
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:682
SwSectionNode * InsertTextSection(SwNodeIndex const &rNdIdx, SwSectionFormat &rSectionFormat, SwSectionData const &, SwTOXBase const *const pTOXBase, SwNodeIndex const *const pEnde, bool const bInsAtStart=true, bool const bCreateFrames=true)
Insert a new SwSection.
Definition: ndsect.cxx:779
SvxBreak
const css::lang::Locale & GetLocale() const
Definition: txmsrt.hxx:182
OUString GetIndexKey(const TextAndReading &rTaR, const css::lang::Locale &rLcl) const
Definition: txmsrt.cxx:115
Base class of the Writer layout elements.
Definition: frame.hxx:297
const sal_Unicode C_NUM_REPL
Definition: tox.cxx:43
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
const SfxItemSet * GetAttrSet() const
Definition: doctxm.cxx:2038
TOXTypes
Definition: toxe.hxx:39
bool IsMarkHintHidden(SwRootFrame const &rLayout, SwTextNode const &rNode, SwTextAttrEnd const &rHint)
Definition: reffld.cxx:1103
void SetAttrSet(const SfxItemSet &)
Definition: doctxm.cxx:2046
std::vector< SwSection * > SwSections
Definition: section.hxx:42
bool IsInMailMerge() const
Definition: doc.hxx:959
sal_uLong GetIndex() const
Definition: node.hxx:282
bool operator<(const SwTextGlyphsKey &l, const SwTextGlyphsKey &r)
Definition: fntcache.cxx:128
bool operator>=(const BigInt &rVal1, const BigInt &rVal2)
OUString const & GetSecondaryKeyReading() const
Definition: tox.hxx:628
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:156
sal_Int32 nIndex
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
std::unique_ptr< SwDefTOXBase_Impl > mpDefTOXBases
Definition: doc.hxx:247
Marks a position in the document model.
Definition: pam.hxx:35
SwTOXElement GetCreateType() const
Definition: tox.hxx:671
bool IsInDocBody() const
Definition: frame.hxx:921
SwTOIOptions GetOptions() const
Definition: tox.hxx:710
SwOLENode * GetOLENode()
Inline methods from Node.hxx.
Definition: ndole.hxx:161
sal_uLong StartOfSectionIndex() const
Definition: node.hxx:673
SwPageDesc * GetPageDesc()
Definition: fmtpdsc.hxx:62
const SwOLEObj & GetOLEObj() const
Definition: ndole.hxx:112
SwCharFormat * MakeCharFormat(const OUString &rFormatName, SwCharFormat *pDerivedFrom, bool bBroadcast=false)
Definition: docfmt.cxx:842
const OUString & GetText() const
Definition: ndtxt.hxx:211
virtual const SwRootFrame * GetCurrentLayout() const =0
static void CheckPageDescs(SwPageFrame *pStart, bool bNotifyFields=true, SwPageFrame **ppPrev=nullptr)
Check all pages (starting from the given one) if they use the appropriate frame format.
Definition: pagechg.cxx:1003
virtual bool get(DocumentSettingId id) const override
Return the specified document setting.
OUString const & GetPrimaryKey() const
Definition: tox.hxx:604
SwDocShell * GetDocShell()
Definition: doc.hxx:1350
bool IsProtected() const
Definition: tox.hxx:502
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:219
Definition: toxe.hxx:25
const SwFrameFormats * GetTableFrameFormats() const
Definition: doc.hxx:810
void DelSectionFormat(SwSectionFormat *pFormat, bool bDelNodes=false)
Definition: ndsect.cxx:512
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
static SwTOXBase * GetCurTOX(const SwPosition &rPos)
Get current table of contents.
Definition: doctxm.cxx:448
SwTOOElements
Definition: tox.hxx:373
Definition: tox.hxx:276
SwNodeIndex nNode
Definition: pam.hxx:37
const SwTOXType * InsertTOXType(const SwTOXType &rTyp)
Definition: doctxm.cxx:629
int n1
void InsertAlphaDelimiter(const SwTOXInternational &rIntl)
Definition: doctxm.cxx:1081
SvxBreak GetBreak() const
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: doc.hxx:798
void SetSectionName(OUString const &rName)
Definition: section.hxx:170
const SwTextNode * GetBodyTextNode(const SwDoc &rDoc, SwPosition &rPos, const SwFrame &rFrame)
Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
Definition: expfld.cxx:163
static bool lcl_HasMainEntry(const std::vector< sal_uInt16 > *pMainEntryNums, sal_uInt16 nToFind)
Replace the PageNumber place holders.
Definition: doctxm.cxx:1704
SwHistory & GetHistory()
virtual void SetModified()=0
Must be called manually at changes of format.
sal_uInt16 GetType() const
Definition: txmsrt.hxx:142
sal_uIntPtr sal_uLong
std::vector< SwTOXMark * > SwTOXMarks
Definition: tox.hxx:44
Subgroup user indices.
Definition: poolfmt.hxx:382
OUString const & GetTemplate(sal_uInt16 nLevel) const
Definition: tox.hxx:642
#define SO3_SIMPRESS_CLASSID_30
#define RES_CONTENT_VISIBLE
Definition: hintids.hxx:402
#define SO3_SIMPRESS_CLASSID_60
const SwPageDesc * FindPageDesc(size_t *pPgDescNdIdx=nullptr) const
Search PageDesc with which this node is formatted.
Definition: node.cxx:465
virtual sal_uInt16 GetLevel() const =0
#define SO3_SCH_CLASSID_30
css::uno::Reference< css::embed::XEmbeddedObject > const & GetOleRef()
Definition: ndole.cxx:912
#define TOX_STYLE_DELIMITER
Definition: tox.hxx:386
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1148
sal_Int64 n
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:186
void TitleSectionInserted(SwSectionFormat &rSectionFormat)
Definition: unsect.cxx:545
static void InsertTOXMarks(SwTOXMarks &aMarks, const SwTOXType &rType)
Definition: tox.cxx:184
TElementType * Next()
Definition: calbck.hxx:373
This class generates text for the entries of a table of x.
tuple args
WW8LvlType GetNumType(sal_uInt8 nWwLevelNo)
Definition: ww8par2.cxx:868
#define SO3_SDRAW_CLASSID_50
bool IsHiddenByParaField() const
is the paragraph visible?
Definition: ndtxt.hxx:709
bool IsUpdateTOX() const
Definition: doc.hxx:948
virtual void DeleteRange(SwPaM &)=0
Delete a range SwFlyFrameFormat.
static SwContentNode * GoPrevious(SwNodeIndex *)
Definition: nodes.cxx:1294
bool HasDummyChar() const
Definition: txatbase.hxx:101
SwNode & GetNode() const
Definition: ndindex.hxx:119
void UpdateTemplate(const SwTextNode *pOwnChapterNode, SwRootFrame const *pLayout)
Generate table of contents from template areas.
Definition: doctxm.cxx:1268
SwSectionFormat * GetFormat()
Definition: section.hxx:337
bool operator<=(const BigInt &rVal1, const BigInt &rVal2)
bool IsTOXBaseInReadonly() const
Definition: doctxm.cxx:2014
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:143
#define SO3_SC_CLASSID_40
const SwTOXType * GetTOXType() const
Definition: tox.hxx:542
#define RES_TXTATR_CHARFMT
Definition: hintids.hxx:236
sal_uInt16 Which() const
Definition: txatbase.hxx:110
static const SwAttrSet & GetTOXBaseAttrSet(const SwTOXBase &rTOX)
Definition: doctxm.cxx:468
sal_uInt16 nLevel
Definition: tox.hxx:406
#define FORM_SECONDARY_KEY
Definition: tox.hxx:172
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:314
bool HasWriterListeners() const
Definition: calbck.hxx:208
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
OUString GetFollowingText(bool bMorePages) const
Definition: txmsrt.cxx:121
bool SetTOXBaseName(const SwTOXBase &rTOXBase, const OUString &rName)
Definition: doctxm.cxx:705
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:193
const SwSection & GetSection() const
Definition: node.hxx:541
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:356
#define SO3_SCH_CLASSID_40
void Delete(const SwNodeIndex &rPos, sal_uLong nNodes=1)
delete nodes
Definition: nodes.cxx:1065
OUString const & GetPrimaryKeyReading() const
Definition: tox.hxx:622
bool IsAssignedToListLevelOfOutlineStyle() const
Definition: fmtcol.hxx:109
static SwTOOElements lcl_IsSOObject(const SvGlobalName &rFactoryNm)
Definition: doctxm.cxx:1390
const SwTOXType * GetTOXType() const
Definition: tox.hxx:668
const SvxFormatBreakItem & GetBreak(bool=true) const
Definition: frmatr.hxx:62
#define CH_TXTATR_INWORD
Definition: hintids.hxx:137
SwTOXBaseSection * InsertTableOf(const SwPosition &rPos, const SwTOXBase &rTOX, const SfxItemSet *pSet=nullptr, bool bExpand=false, SwRootFrame const *pLayout=nullptr)
Definition: doctxm.cxx:346
int n2
const SwTOXMark & GetTOXMark() const
Definition: txatbase.hxx:212
SwIndex nContent
Definition: pam.hxx:38
#define SO3_SC_CLASSID_30
SwSectionNode * GetSectionNode()
Definition: section.cxx:1003
const OUString S_PAGE_DELI
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:425
SwTOXSearch
Definition: toxe.hxx:22
virtual bool equivalent(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:197
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:33
SwTOIKeyType
Definition: toxe.hxx:30
int nCount
bool IsEqual(const TextAndReading &rTaR1, const css::lang::Locale &rLocale1, const TextAndReading &rTaR2, const css::lang::Locale &rLocale2) const
Definition: txmsrt.hxx:92
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
Content 6th level.
Definition: poolfmt.hxx:389
bool IsTextFrame() const
Definition: frame.hxx:1212
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:95
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
const SwTextNode * pTOXNd
Definition: txmsrt.hxx:127
SwTextAttr * InsertItem(SfxPoolItem &rAttr, const sal_Int32 nStart, const sal_Int32 nEnd, const SetAttrMode nMode=SetAttrMode::DEFAULT)
create new text attribute from rAttr and insert it
Definition: thints.cxx:1255
SwSection * InsertSwSection(SwPaM const &rRange, SwSectionData &, std::pair< SwTOXBase const *, sw::RedlineMode > const *pTOXBase, SfxItemSet const *const pAttr, bool const bUpdate=true)
Definition: ndsect.cxx:151
bool DeleteTOX(const SwTOXBase &rTOXBase, bool bDelNodes)
Delete table of contents.
Definition: doctxm.cxx:524
sal_uInt16 GetTOXTypeCount(TOXTypes eTyp) const
Manage table of content types.
Definition: doctxm.cxx:611
bool IsProtectFlag() const
Definition: section.hxx:189
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
Definition: doclay.cxx:1666
const OUString & GetSequenceName() const
Definition: tox.hxx:505
#define SO3_SC_CLASSID_60
SwSectionFormat * MakeSectionFormat()
Definition: ndsect.cxx:505
OUString ToUpper(const OUString &rStr, sal_Int32 nPos) const
Definition: txmsrt.cxx:96
#define SO3_SCH_CLASSID_60
SwTOOElements GetOLEOptions() const
Definition: tox.hxx:478
virtual bool DoesUndo() const =0
Is Undo enabled?
const char * sName
OUString maMSTOCExpression
Definition: tox.hxx:422
TextFrameIndex GetOffset() const
Definition: txtfrm.hxx:428
void SetProgressState(long nPosition, SwDocShell const *pDocShell)
Definition: mainwn.cxx:82
Specific frame formats (frames, DrawObjects).
sal_uInt16 GetSeqNumber() const
Definition: expfld.hxx:244
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:163
#define SO3_SC_CLASSID_50
sal_uInt16 GetVirtPageNum() const
Definition: trvlfrm.cxx:1803
object index.
Definition: poolfmt.hxx:400
void UpdatePageNum()
Calculate PageNumber and insert after formatting.
Definition: doctxm.cxx:1593
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
Range GetKeyRange(const OUString &rStr, const OUString &rStrReading, const SwTOXSortTabBase &rNew, sal_uInt16 nLevel, const Range &rRange)
Find Key Range and insert if possible.
Definition: doctxm.cxx:1960
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:443
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:496
static sal_Int32 GetReferenceTextPos(const SwFormatField &rFormat, SwDoc &rDoc, sal_Int32 nHint=0)
Find the index of the reference text following the current field.
Definition: expfld.cxx:968
#define SO3_SM_CLASSID_50
#define SO3_SCH_CLASSID_50
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:1919
virtual void AppendUndo(std::unique_ptr< SwUndo > pUndo)=0
Add new Undo action.
std::vector< std::unique_ptr< SwTOXSortTabBase > > m_aSortArr
Definition: doctxm.hxx:36
size_t Count() const
Definition: ndhints.hxx:142
void DeRegister()
deregister the currently registered History
Definition: ndhints.hxx:197
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
#define SAL_MAX_INT32
const SwContentFrame * GetFollow() const
Definition: cntfrm.hxx:114
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
SwTOXBaseSection(SwTOXBase const &rBase, SwSectionFormat &rFormat)
Definition: doctxm.cxx:743
std::unique_ptr< SwTOXTypes > mpTOXTypes
Definition: doc.hxx:246
int i
SwTOXElement
Definition: tox.hxx:328
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
const OUString & GetSectionName() const
Definition: section.hxx:169
const SwPosition * GetPoint() const
Definition: pam.hxx:207
std::vector< SwSectionFormat * >::size_type size_type
Definition: docary.hxx:63
void UpdateOutline(const SwTextNode *pOwnChapterNode, SwRootFrame const *pLayout)
Generate table of contents from outline.
Definition: doctxm.cxx:1241
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:198
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:880
void SetProtect(bool const bFlag=true)
Definition: section.cxx:378
SwPageFrame * FindPageFrame()
Definition: frame.hxx:660
Text body.
Definition: poolfmt.hxx:251
TextFrameIndex MapModelToView(MergedPara const &, SwTextNode const *pNode, sal_Int32 nIndex)
Definition: txtfrm.cxx:1172
TElementType * First()
Definition: calbck.hxx:342
bool IsFromObjectNames() const
Definition: tox.hxx:496
bool IsHiddenFlag() const
Definition: section.hxx:188
virtual bool DeleteRedline(const SwPaM &rPam, bool bSaveInUndo, RedlineType nDelType)=0
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:129
bool SetPosAtStartEnd(SwPosition &rPos) const
Definition: doctxm.cxx:755
SwContentNode * GetContentNode()
Definition: node.hxx:615
const SvxPageUsage aArr[]
#define SO3_SIMPRESS_CLASSID_40
SwDoc * GetDoc()
Definition: node.hxx:702
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
void UpdateNumRule()
Definition: docnum.cxx:2586
OUString GetText(SwRootFrame const *pLayout) const
Definition: tox.cxx:165
Marks a character position inside a document model node.
Definition: index.hxx:37
void UpdateTable(const SwTextNode *pOwnChapterNode, SwRootFrame const *pLayout)
Collect table entries.
Definition: doctxm.cxx:1540
const OUString & GetTypeName() const
Definition: tox.hxx:660
const SwTextNode * GetpTextNd() const
Definition: txttxmrk.hxx:44
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:393
Definition: toxe.hxx:24
size
#define RES_TXTATR_TOXMARK
Definition: hintids.hxx:231
void GetTOIKeys(SwTOIKeyType eTyp, std::vector< OUString > &rArr, SwRootFrame const &rLayout) const
Definition: doctxm.cxx:85
const SwTOXInternational * pTOXIntl
Definition: txmsrt.hxx:129
Marks a node in the document model.
Definition: ndindex.hxx:31
const SwOutlineNodes & GetOutLineNds() const
Array of all OutlineNodes.
Definition: ndarr.hxx:231
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
SwTextFormatColl * GetTextFormatColl(sal_uInt16 nLevel)
Evaluate Template.
Definition: doctxm.cxx:1124
static std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type MakeSwTOXSortTabBase(SwRootFrame const *const pLayout, Args &&...args)
Definition: doctxm.cxx:78
OUString newName(const OUString &aNewPrefix, const OUString &aOldPrefix, const OUString &old_Name)
bool HasSwAttrSet() const
Definition: node.hxx:444
void Register(SwRegHistory *pHist)
register a History, which receives all attribute changes (for Undo)
Definition: ndhints.hxx:195
SectionType
Definition: section.hxx:46
void UpdateAuthorities(const SwTOXInternational &rIntl, SwRootFrame const *pLayout)
Definition: doctxm.cxx:1355
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:119
bool IsFromChapter() const
Definition: tox.hxx:493
sal_uInt16 GetLevel() const
Definition: tox.hxx:704
A page of the document layout.
Definition: pagefrm.hxx:40
const SwTOXMark & GotoTOXMark(const SwTOXMark &rCurTOXMark, SwTOXSearch eDir, bool bInReadOnly)
Definition: doctxm.cxx:228
const OUString & GetTitle() const
Definition: tox.hxx:674
virtual ~SwTOXBaseSection() override
Definition: doctxm.cxx:751
bool IsInReading() const
Definition: doc.hxx:953
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:404
SwCaptionDisplay GetCaptionDisplay() const
Definition: tox.hxx:508
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
bool IsReadOnly() const
const sal_Unicode C_END_PAGE_NUM
Definition: tox.cxx:44
bool operator!=(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
void UpdateSequence(const SwTextNode *pOwnChapterNode, SwRootFrame const *pLayout)
Generate content from sequence fields.
Definition: doctxm.cxx:1311
const OUString & GetSortAlgorithm() const
Definition: tox.hxx:519
void DeleteAttribute(SwTextAttr *const pTextAttr)
delete the attribute pTextAttr
Definition: thints.cxx:1666
user index 6..10.
Definition: poolfmt.hxx:412
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
std::unique_ptr< SwSectionFormats > mpSectionFormatTable
Definition: doc.hxx:241
void RestoreUpperFrames(SwNodes &rNds, sal_uLong nStt, sal_uLong nEnd)
Definition: node2lay.cxx:438
bool IsOleRef() const
To avoid unnecessary loading of object.
Definition: ndole.cxx:907
const SwTextNode & GetTextNode() const
Definition: txttxmrk.hxx:49
illustrations index.
Definition: poolfmt.hxx:396
void EraseText(const SwIndex &rIdx, const sal_Int32 nCount=SAL_MAX_INT32, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
delete text content ATTENTION: must not be called with a range that overlaps the start of an attribut...
Definition: ndtxt.cxx:2660
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2277
SwCharFormat * FindCharFormatByName(const OUString &rName) const
Definition: doc.hxx:770
long Max() const
const css::lang::Locale & GetLocale(const LanguageType aLang)
Definition: breakit.hxx:67
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:677
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
void DeleteTOXMark(const SwTOXMark *pTOXMark)
Delete table of contents Mark.
Definition: doctxm.cxx:154
OUString sText
Definition: txmsrt.hxx:60
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:334
bool IsRelTabPos() const
Definition: tox.hxx:307
#define SO3_SIMPRESS_CLASSID_50
void SetTOXName(const OUString &rSet)
Definition: tox.hxx:442
SwCharFormat * GetCharFormat() const
Definition: fchrfmt.hxx:70
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:439
const SwTextNode * FindOutlineNodeOfLevel(sal_uInt8 nLvl, SwRootFrame const *pLayout=nullptr) const
Definition: node.cxx:763
virtual bool SetAttr(const SfxPoolItem &)
made virtual
Definition: node.cxx:1496
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:67
void InsertSorted(std::unique_ptr< SwTOXSortTabBase > pBase)
Definition: doctxm.cxx:1873
void Update(const SfxItemSet *pAttr=nullptr, SwRootFrame const *pLayout=nullptr, const bool _bNewTOX=false)
Collect table of contents content.
Definition: doctxm.cxx:770
OUString GetUniqueTOXBaseName(const SwTOXType &rType, const OUString &sChkStr) const
Definition: doctxm.cxx:636
void CorrAbs(const SwNodeIndex &rOldNode, const SwPosition &rNewPos, const sal_Int32 nOffset=0, bool bMoveCursor=false)
Definition: doccorr.cxx:162
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
OUString const & GetSecondaryKey() const
Definition: tox.hxx:610
static const SwTextNode * lcl_FindChapterNode(const SwNode &rNd, SwRootFrame const *const pLayout, sal_uInt8 const nLvl=0)
Definition: doctxm.cxx:721
unsigned char sal_uInt8
static sal_uInt16 GetCurTOXMark(const SwPosition &rPos, SwTOXMarks &)
Get current table of contents Mark.
Definition: doctxm.cxx:116
TOXTypes GetType() const
Definition: tox.hxx:695
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:253
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
OUString const & GetStyleNames(sal_uInt16 nLevel) const
Definition: tox.hxx:483
#define SO3_SM_CLASSID_40
bool mbKeepExpression
Definition: tox.hxx:423
OUString aName
sal_Int32 GetIndex() const
Definition: index.hxx:95
OString DateTimeToOString(const DateTime &rDateTime)
LanguageType GetLanguage() const
Definition: tox.hxx:516
bool IsCommaSeparated() const
Definition: tox.hxx:310
SwNodes & GetNodes()
Definition: doc.hxx:405
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:185
LanguageType GetLang(const sal_Int32 nBegin, const sal_Int32 nLen=0, sal_uInt16 nScript=0) const
Definition: thints.cxx:3402
const SwModify * GetRegisteredIn() const
Definition: calbck.hxx:157
const sal_Int32 * End() const
Definition: txatbase.hxx:148
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
#define FORM_ALPHA_DELIMITER
Definition: tox.hxx:170
void PaMCorrAbs(const SwPaM &rRange, const SwPosition &rNewPos)
Function declarations so that everything below the CursorShell can move the Cursor once in a while...
Definition: doccorr.cxx:85
#define FORM_ENTRY
Definition: tox.hxx:173
tables index.
Definition: poolfmt.hxx:404
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:416
virtual bool AppendTextNode(SwPosition &rPos)=0
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: doctxm.cxx:2053
const OUString & GetMainEntryCharStyle() const
Definition: tox.hxx:462
TOXTypes GetType() const
Definition: tox.hxx:663
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:723
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
const char cSequenceMarkSeparator
Definition: swtypes.hxx:139
void UpdatePageNum_(SwTextNode *pNd, const std::vector< sal_uInt16 > &rNums, const std::vector< SwPageDesc * > &rDescs, const std::vector< sal_uInt16 > *pMainEntryNums, const SwTOXInternational &rIntl)
Definition: doctxm.cxx:1715
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:350
void ChgFormat(SwFormat &rFormat, const SfxItemSet &rSet)
Definition: docfmt.cxx:1853
void UpdateMarks(const SwTOXInternational &rIntl, const SwTextNode *pOwnChapterNode, SwRootFrame const *pLayout)
Create from Marks.
Definition: doctxm.cxx:1174
static bool IsInHiddenRange(const SwTextNode &rNode, sal_Int32 nPos)
Definition: porlay.cxx:1875
static SwTOIOptions GetOptions()
Definition: txmsrt.hxx:143
#define FORM_PRIMARY_KEY
Definition: tox.hxx:171
void DelFlyInRange(const SwNodeIndex &rMkNdIdx, const SwNodeIndex &rPtNdIdx, SwIndex const *const pMkIdx, SwIndex const *const pPtIdx)
Delete and move all Flys at the paragraph, that are within the selection.
Definition: docedt.cxx:202
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2313
Subgroup index tables.
Definition: poolfmt.hxx:367
Subgroup table of contents.
Definition: poolfmt.hxx:374
SwSectionNode * GetSectionNode()
Definition: node.hxx:607
const SwTextTOXMark * GetTextTOXMark() const
Definition: tox.hxx:137
virtual bool GetInfo(SfxPoolItem &) const override
Definition: section.cxx:836
long Min() const
SectionType GetType() const
Definition: section.hxx:171
const SwTOXType * GetTOXType(TOXTypes eTyp, sal_uInt16 nId) const
Definition: doctxm.cxx:620
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:116
const SwFormatPageDesc & GetPageDesc(bool=true) const
Definition: fmtpdsc.hxx:79
const SwForm & GetTOXForm() const
Definition: tox.hxx:686
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:179
#define SO3_SDRAW_CLASSID_60
int GetAttrOutlineLevel() const
Definition: fmtcol.cxx:582
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:161
void SetDefaultTOXBase(const SwTOXBase &rBase)
Definition: doctxm.cxx:503
TextAndReading const & GetText() const
Definition: txmsrt.hxx:176
#define FORM_TITLE
Definition: tox.hxx:169
index of authorities.
Definition: poolfmt.hxx:408
sal_uInt16 const aBreakSetRange[]
Definition: init.cxx:142
void GetChildSections(SwSections &rArr, SectionSort eSort=SectionSort::Not, bool bAllSections=true) const
Definition: section.cxx:883
#define SO3_SM_CLASSID_30
virtual bool sort_lt(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:223
Class for sorting directories.
Definition: txmsrt.hxx:120
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
Merge GetRedlineMergeFlag() const
Definition: node.hxx:97
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1277
void UpdateContent(SwTOXElement eType, const SwTextNode *pOwnChapterNode, SwRootFrame const *pLayout)
Definition: doctxm.cxx:1434
std::vector< SwTOXSource > aTOXSources
Definition: txmsrt.hxx:125
const SwTOXBase * GetDefaultTOXBase(TOXTypes eTyp, bool bCreate)
Definition: doctxm.cxx:477
sal_uInt16 Which() const
sal_uInt16 nPos
bool IsLevelFromChapter() const
Definition: tox.hxx:499
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1317
const OUString & GetTOXName() const
Definition: tox.hxx:441
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:836
SwTextNode * MakeTextNode(const SwNodeIndex &rWhere, SwTextFormatColl *pColl, bool bNewFrames=true)
Implementations of "Make...Node" are in the given .cxx-files.
Definition: ndtxt.cxx:104
bool IsProtected() const
Is the Frame or rather the Section in which it lies protected?
Definition: trvlfrm.cxx:1625
Base class of the Writer document model elements.
Definition: node.hxx:79
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:830