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