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