LibreOffice Module sw (master)  1
tox.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 <hintids.hxx>
21 #include <swtypes.hxx>
22 #include <ndtxt.hxx>
23 #include <txttxmrk.hxx>
24 #include <tox.hxx>
25 #include <strings.hrc>
26 #include <doc.hxx>
27 #include <docary.hxx>
28 #include <paratr.hxx>
29 #include <editeng/tstpitem.hxx>
30 #include <hints.hxx>
31 #include <calbck.hxx>
32 
33 #include <optional>
34 #include <sal/log.hxx>
35 #include <osl/diagnose.h>
36 
37 #include <algorithm>
38 
39 
40 using namespace std;
41 
42 
43 const sal_Unicode C_NUM_REPL = '@';
45 const OUString S_PAGE_DELI(", ");
46 
47 
48 namespace
49 {
50 
51 void lcl_FillAuthPattern(SwFormTokens &rAuthTokens, sal_uInt16 nTypeId)
52 {
53  rAuthTokens.reserve(9); // Worst case: Start+Sep1+Auth+3*(Sep2+Auth)
54 
55  SwFormToken aStartToken( TOKEN_AUTHORITY );
56  aStartToken.nAuthorityField = AUTH_FIELD_IDENTIFIER;
57  rAuthTokens.push_back( aStartToken );
58  SwFormToken aSeparatorToken( TOKEN_TEXT );
59  aSeparatorToken.sText = ": ";
60  rAuthTokens.push_back( aSeparatorToken );
61 
62  --nTypeId; // compensate +1 offset introduced by caller
63 
64  SwFormToken aTextToken( TOKEN_TEXT );
65  aTextToken.sText = ", ";
66 
67  const ToxAuthorityField nVals[4] = {
72  };
73 
74  for(size_t i = 0; i < SAL_N_ELEMENTS(nVals); ++i)
75  {
76  if(nVals[i] == AUTH_FIELD_END)
77  break;
78  if( i > 0 )
79  rAuthTokens.push_back( aTextToken );
80 
81  // -> #i21237#
83 
84  aToken.nAuthorityField = nVals[i];
85  rAuthTokens.push_back(aToken);
86  // <- #i21237#
87  }
88 }
89 
90 }
91 
92 
96  , m_pTextAttr( nullptr ), m_nLevel( 0 )
97  , m_bAutoGenerated(false)
98  , m_bMainEntry(false)
99 { }
100 
103  , m_pTextAttr( nullptr )
104  , m_nLevel( 0 )
105  , m_bAutoGenerated(false)
106  , m_bMainEntry(false)
107 {
108  const_cast<SwTOXType*>(pTyp)->Add(this);
109 }
110 
113  , m_aPrimaryKey(rCopy.m_aPrimaryKey)
114  , m_aSecondaryKey(rCopy.m_aSecondaryKey)
115  , m_aTextReading(rCopy.m_aTextReading)
116  , m_aPrimaryKeyReading(rCopy.m_aPrimaryKeyReading)
117  , m_aSecondaryKeyReading(rCopy.m_aSecondaryKeyReading)
118  , m_pTextAttr(nullptr)
119  , m_nLevel(rCopy.m_nLevel)
120  , m_bAutoGenerated(rCopy.m_bAutoGenerated)
121  , m_bMainEntry(rCopy.m_bMainEntry)
122 {
123  if (auto pRegister = const_cast<SwTOXMark&>(rCopy).GetRegisteredIn())
124  pRegister->Add(this);
125  // Copy AlternativString
126  m_aAltText = rCopy.m_aAltText;
127 }
128 
130 {
131 }
132 
134 {
135  rType.Add(this);
136 }
137 
138 bool SwTOXMark::operator==( const SfxPoolItem& rAttr ) const
139 {
140  assert(SfxPoolItem::operator==(rAttr));
141  return GetRegisteredIn() == static_cast<const SwTOXMark&>(rAttr).GetRegisteredIn();
142 }
143 
145 {
146  return new SwTOXMark( *this );
147 }
148 
149 void SwTOXMark::SwClientNotify(const SwModify&, const SfxHint& rHint)
150 {
151  if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
152  {
153  NotifyClients(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
154  if (pLegacyHint->m_pOld && (RES_REMOVE_UNO_OBJECT == pLegacyHint->m_pOld->Which()))
155  SetXTOXMark(css::uno::Reference<css::text::XDocumentIndexMark>(nullptr));
156  } else if (auto pCollectHint = dynamic_cast<const sw::CollectTextMarksHint*>(&rHint))
157  {
158  if(GetTextTOXMark())
159  pCollectHint->m_rMarks.push_back(this);
160  }
161 }
162 
164 {
166  &static_cast<SwModify&>(*this) ); // cast to base class!
167  NotifyClients(&aMsgHint, &aMsgHint);
168 }
169 
170 OUString SwTOXMark::GetText(SwRootFrame const*const pLayout) const
171 {
172  if( !m_aAltText.isEmpty() )
173  return m_aAltText;
174 
176  {
177  const sal_Int32* pEndIdx = m_pTextAttr->GetEnd();
178  OSL_ENSURE( pEndIdx, "TOXMark without mark!");
179  if( pEndIdx )
180  {
181  const sal_Int32 nStt = m_pTextAttr->GetStart();
182  return m_pTextAttr->GetpTextNd()->GetExpandText(pLayout, nStt, *pEndIdx-nStt);
183  }
184  }
185 
186  return OUString();
187 }
188 
189 // Manage types of TOX
190 SwTOXType::SwTOXType(TOXTypes eTyp, const OUString& rName)
191  : m_aName(rName)
192  , m_eType(eTyp)
193 { }
194 
196  : m_aName(rCopy.m_aName)
197  , m_eType(rCopy.m_eType)
198 {
199  if (auto pRegister = const_cast<SwTOXType&>(rCopy).GetRegisteredIn())
200  pRegister->Add(this);
201 }
202 
203 static const char* STR_POOLCOLL_TOX_ARY[] =
204 {
205  // Subcategory Index-Directories
206  STR_POOLCOLL_TOX_IDXH,
207  STR_POOLCOLL_TOX_IDX1,
208  STR_POOLCOLL_TOX_IDX2,
209  STR_POOLCOLL_TOX_IDX3,
210  STR_POOLCOLL_TOX_IDXBREAK
211 };
212 
213 static const char* STR_POOLCOLL_TOX_CNTNT_ARY[] =
214 {
215  // Subcategory Tables of Contents
216  STR_POOLCOLL_TOX_CNTNTH,
217  STR_POOLCOLL_TOX_CNTNT1,
218  STR_POOLCOLL_TOX_CNTNT2,
219  STR_POOLCOLL_TOX_CNTNT3,
220  STR_POOLCOLL_TOX_CNTNT4,
221  STR_POOLCOLL_TOX_CNTNT5
222 };
223 
224 static const char* STR_POOLCOLL_TOX_CNTNT_EXTRA_ARY[] =
225 {
226  // Subcategory Table of Contents more Levels 5 - 10
227  STR_POOLCOLL_TOX_CNTNT6,
228  STR_POOLCOLL_TOX_CNTNT7,
229  STR_POOLCOLL_TOX_CNTNT8,
230  STR_POOLCOLL_TOX_CNTNT9,
231  STR_POOLCOLL_TOX_CNTNT10
232 };
233 
234 static const char* STR_POOLCOLL_TOX_USER_ARY[] =
235 {
236  // Subcategory User-Directories:
237  STR_POOLCOLL_TOX_USERH,
238  STR_POOLCOLL_TOX_USER1,
239  STR_POOLCOLL_TOX_USER2,
240  STR_POOLCOLL_TOX_USER3,
241  STR_POOLCOLL_TOX_USER4,
242  STR_POOLCOLL_TOX_USER5
243 };
244 
245 static const char* STR_POOLCOLL_TOX_USER_EXTRA_ARY[] =
246 {
247  // Subcategory User-Directories more Levels 5 - 10
248  STR_POOLCOLL_TOX_USER6,
249  STR_POOLCOLL_TOX_USER7,
250  STR_POOLCOLL_TOX_USER8,
251  STR_POOLCOLL_TOX_USER9,
252  STR_POOLCOLL_TOX_USER10
253 };
254 
255 static const char* STR_POOLCOLL_TOX_ILLUS_ARY[] =
256 {
257  // Illustrations Index
258  STR_POOLCOLL_TOX_ILLUSH,
259  STR_POOLCOLL_TOX_ILLUS1
260 };
261 
262 static const char* STR_POOLCOLL_TOX_OBJECT_ARY[] =
263 {
264  // Object Index
265  STR_POOLCOLL_TOX_OBJECTH,
266  STR_POOLCOLL_TOX_OBJECT1
267 };
268 
269 static const char* STR_POOLCOLL_TOX_TABLES_ARY[] =
270 {
271  // Tables Index
272  STR_POOLCOLL_TOX_TABLESH,
273  STR_POOLCOLL_TOX_TABLES1
274 };
275 
276 static const char* STR_POOLCOLL_TOX_AUTHORITIES_ARY[] =
277 {
278  // Index of Authorities
279  STR_POOLCOLL_TOX_AUTHORITIESH,
280  STR_POOLCOLL_TOX_AUTHORITIES1
281 };
282 
283 static const char* STR_POOLCOLL_TOX_CITATION_ARY[] =
284 {
285  STR_POOLCOLL_TOX_CITATION
286 };
287 
288 // Edit forms
289 SwForm::SwForm( TOXTypes eTyp ) // #i21237#
290  : m_eType( eTyp ), m_nFormMaxLevel( SwForm::GetFormMaxLevel( eTyp )),
291 // nFirstTabPos( lNumberIndent ),
292  m_bCommaSeparated(false)
293 {
294  //bHasFirstTabPos =
295  m_bIsRelTabPos = true;
296 
297  // The table of contents has a certain number of headlines + headings
298  // The user has 10 levels + headings
299  // Keyword has 3 levels + headings+ separator
300  // Indexes of tables, object illustrations and authorities consist of a heading and one level
301 
302  const char** pPoolId;
303  switch( m_eType )
304  {
305  case TOX_INDEX: pPoolId = STR_POOLCOLL_TOX_ARY; break;
306  case TOX_USER: pPoolId = STR_POOLCOLL_TOX_USER_ARY; break;
307  case TOX_CONTENT: pPoolId = STR_POOLCOLL_TOX_CNTNT_ARY; break;
308  case TOX_ILLUSTRATIONS: pPoolId = STR_POOLCOLL_TOX_ILLUS_ARY; break;
309  case TOX_OBJECTS : pPoolId = STR_POOLCOLL_TOX_OBJECT_ARY; break;
310  case TOX_TABLES : pPoolId = STR_POOLCOLL_TOX_TABLES_ARY; break;
311  case TOX_AUTHORITIES : pPoolId = STR_POOLCOLL_TOX_AUTHORITIES_ARY; break;
312  case TOX_CITATION : pPoolId = STR_POOLCOLL_TOX_CITATION_ARY; break;
313  default:
314  OSL_ENSURE( false, "invalid TOXTyp");
315  return ;
316  }
317 
318  SwFormTokens aTokens;
320  {
321  SwFormToken aLinkStt (TOKEN_LINK_START);
322  aLinkStt.sCharStyleName = SwResId(STR_POOLCHR_TOXJUMP);
323  aTokens.push_back(aLinkStt);
324  }
325 
326  if (TOX_CONTENT == m_eType)
327  {
328  aTokens.emplace_back(TOKEN_ENTRY_NO);
329  aTokens.emplace_back(TOKEN_ENTRY_TEXT);
330  }
331  else
332  aTokens.emplace_back(TOKEN_ENTRY);
333 
334  if (TOX_AUTHORITIES != m_eType)
335  {
336  SwFormToken aToken(TOKEN_TAB_STOP);
337  aToken.nTabStopPosition = 0;
338 
339  // #i36870# right aligned tab for all
340  aToken.cTabFillChar = '.';
341  aToken.eTabAlign = SvxTabAdjust::End;
342 
343  aTokens.push_back(aToken);
344  aTokens.emplace_back(TOKEN_PAGE_NUMS);
345  }
346 
348  aTokens.emplace_back(TOKEN_LINK_END);
349 
350  SetTemplate(0, SwResId(*pPoolId++));
351 
352  if(TOX_INDEX == m_eType)
353  {
354  for( sal_uInt16 i = 1; i < 5; ++i )
355  {
356  if(1 == i)
357  {
358  SwFormTokens aTmpTokens;
359  SwFormToken aTmpToken(TOKEN_ENTRY);
360  aTmpTokens.push_back(aTmpToken);
361 
362  SetPattern( i, aTmpTokens );
363  SetTemplate(i, SwResId(STR_POOLCOLL_TOX_IDXBREAK));
364  }
365  else
366  {
367  SetPattern( i, aTokens );
368  SetTemplate(i, SwResId(STR_POOLCOLL_TOX_ARY[i - 1]));
369  }
370  }
371  }
372  else
373  {
374  for (sal_uInt16 i = 1; i < GetFormMax(); ++i, ++pPoolId) // Number 0 is the title
375  {
376  if (TOX_AUTHORITIES == m_eType)
377  {
378  SwFormTokens aAuthTokens;
379  lcl_FillAuthPattern(aAuthTokens, i);
380  SetPattern(i, aAuthTokens);
381  }
382  else
383  SetPattern( i, aTokens );
384 
385  if( TOX_CONTENT == m_eType && 6 == i )
387  else if( TOX_USER == m_eType && 6 == i )
389  else if( TOX_AUTHORITIES == m_eType ) //reuse the same STR_POOLCOLL_TOX_AUTHORITIES1 id each time
390  pPoolId = STR_POOLCOLL_TOX_AUTHORITIES_ARY + 1;
391  SetTemplate(i, SwResId(*pPoolId));
392  }
393  }
394 }
395 
396 SwForm::SwForm(const SwForm& rForm)
397  : m_eType( rForm.m_eType )
398 {
399  *this = rForm;
400 }
401 
403 {
404  m_eType = rForm.m_eType;
406 // nFirstTabPos = rForm.nFirstTabPos;
407 // bHasFirstTabPos = rForm.bHasFirstTabPos;
410  for(sal_uInt16 i=0; i < m_nFormMaxLevel; ++i)
411  {
412  m_aPattern[i] = rForm.m_aPattern[i];
413  m_aTemplate[i] = rForm.m_aTemplate[i];
414  }
415  return *this;
416 }
417 
418 sal_uInt16 SwForm::GetFormMaxLevel( TOXTypes eTOXType )
419 {
420  switch( eTOXType )
421  {
422  case TOX_INDEX:
423  return 5;
424  case TOX_USER:
425  case TOX_CONTENT:
426  return MAXLEVEL + 1;
427  case TOX_ILLUSTRATIONS:
428  case TOX_OBJECTS:
429  case TOX_TABLES:
430  return 2;
431  case TOX_BIBLIOGRAPHY:
432  case TOX_CITATION:
433  case TOX_AUTHORITIES:
434  return AUTH_TYPE_END + 1;
435  }
436  return 0;
437 }
438 
439 void SwForm::AdjustTabStops( SwDoc const & rDoc ) // #i21237#
440 {
441  const sal_uInt16 nFormMax = GetFormMax();
442  for ( sal_uInt16 nLevel = 1; nLevel < nFormMax; ++nLevel )
443  {
444  SwTextFormatColl* pColl = rDoc.FindTextFormatCollByName( GetTemplate(nLevel) );
445  if( pColl == nullptr )
446  {
447  // Paragraph Style for this level has not been created.
448  // --> No need to propagate default values
449  continue;
450  }
451 
452  const SvxTabStopItem& rTabStops = pColl->GetTabStops(false);
453  const sal_uInt16 nTabCount = rTabStops.Count();
454  if (nTabCount != 0)
455  {
456  SwFormTokens aCurrentPattern = GetPattern(nLevel);
457  SwFormTokens::iterator aIt = aCurrentPattern.begin();
458 
459  bool bChanged = false;
460  for(sal_uInt16 nTab = 0; nTab < nTabCount; ++nTab)
461  {
462  const SvxTabStop& rTab = rTabStops[nTab];
463 
464  if ( rTab.GetAdjustment() == SvxTabAdjust::Default )
465  continue; // ignore the default tab stop
466 
467  aIt = find_if( aIt, aCurrentPattern.end(), SwFormTokenEqualToFormTokenType(TOKEN_TAB_STOP) );
468  if ( aIt != aCurrentPattern.end() )
469  {
470  bChanged = true;
471  aIt->nTabStopPosition = rTab.GetTabPos();
472  aIt->eTabAlign =
473  ( nTab == nTabCount - 1
474  && rTab.GetAdjustment() == SvxTabAdjust::Right )
475  ? SvxTabAdjust::End
476  : rTab.GetAdjustment();
477  aIt->cTabFillChar = rTab.GetFill();
478  ++aIt;
479  }
480  else
481  break; // no more tokens to replace
482  }
483 
484  if ( bChanged )
485  SetPattern( nLevel, aCurrentPattern );
486  }
487  }
488 }
489 
490 OUString SwForm::GetFormEntry() {return "<E>";}
491 OUString SwForm::GetFormTab() {return "<T>";}
492 OUString SwForm::GetFormPageNums() {return "<#>";}
493 OUString SwForm::GetFormLinkStt() {return "<LS>";}
494 OUString SwForm::GetFormLinkEnd() {return "<LE>";}
495 OUString SwForm::GetFormEntryNum() {return "<E#>";}
496 OUString SwForm::GetFormEntryText() {return "<ET>";}
497 OUString SwForm::GetFormChapterMark() {return "<C>";}
498 OUString SwForm::GetFormText() {return "<X>";}
499 OUString SwForm::GetFormAuth() {return "<A>";}
500 
501 SwTOXBase::SwTOXBase(const SwTOXType* pTyp, const SwForm& rForm,
502  SwTOXElement nCreaType, const OUString& rTitle )
503  : SwClient(const_cast<SwModify*>(static_cast<SwModify const *>(pTyp)))
504  , m_aForm(rForm)
505  , m_aTitle(rTitle)
506  , m_eLanguage(::GetAppLanguage())
507  , m_nCreateType(nCreaType)
508  , m_nOLEOptions(SwTOOElements::NONE)
509  , m_eCaptionDisplay(CAPTION_COMPLETE)
510  , m_bProtected( true )
511  , m_bFromChapter(false)
512  , m_bFromObjectNames(false)
513  , m_bLevelFromChapter(false)
514  , maMSTOCExpression()
515  , mbKeepExpression(true)
516 {
517  m_aData.nOptions = SwTOIOptions::NONE;
518 }
519 
520 SwTOXBase::SwTOXBase( const SwTOXBase& rSource, SwDoc* pDoc )
521  : SwClient( rSource.GetRegisteredInNonConst() )
522  , mbKeepExpression(true)
523 {
524  CopyTOXBase( pDoc, rSource );
525 }
526 
528 {
529  rType.Add( this );
530 }
531 
532 void SwTOXBase::CopyTOXBase( SwDoc* pDoc, const SwTOXBase& rSource )
533 {
535  SwTOXType* pType = const_cast<SwTOXType*>(rSource.GetTOXType());
536  if( pDoc &&
537  std::find_if(pDoc->GetTOXTypes().begin(), pDoc->GetTOXTypes().end(),
538  [=](const std::unique_ptr<SwTOXType> & p) { return p.get() == pType; })
539  == pDoc->GetTOXTypes().end())
540  {
541  // type not in pDoc, so create it now
542  const SwTOXTypes& rTypes = pDoc->GetTOXTypes();
543  bool bFound = false;
544  for( size_t n = rTypes.size(); n; )
545  {
546  const SwTOXType* pCmp = rTypes[ --n ].get();
547  if( pCmp->GetType() == pType->GetType() &&
548  pCmp->GetTypeName() == pType->GetTypeName() )
549  {
550  pType = const_cast<SwTOXType*>(pCmp);
551  bFound = true;
552  break;
553  }
554  }
555 
556  if( !bFound )
557  pType = const_cast<SwTOXType*>(pDoc->InsertTOXType( *pType ));
558  }
559  pType->Add( this );
560 
561  m_nCreateType = rSource.m_nCreateType;
562  m_aTitle = rSource.m_aTitle;
563  m_aForm = rSource.m_aForm;
566  m_bProtected = rSource.m_bProtected;
567  m_bFromChapter = rSource.m_bFromChapter;
572  m_nOLEOptions = rSource.m_nOLEOptions;
573  m_eLanguage = rSource.m_eLanguage;
576 
577  for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
578  m_aStyleNames[i] = rSource.m_aStyleNames[i];
579 
580  // it's the same data type!
581  m_aData.nOptions = rSource.m_aData.nOptions;
582 
583  if( !pDoc || pDoc->IsCopyIsMove() )
584  m_aName = rSource.GetTOXName();
585  else
586  m_aName = pDoc->GetUniqueTOXBaseName( *pType, rSource.GetTOXName() );
587 }
588 
589 // TOX specific functions
591 {
592 // if( GetTOXType()->GetType() == TOX_USER )
593 // delete aData.pTemplateName;
594 }
595 
596 void SwTOXBase::SetTitle(const OUString& rTitle)
597  { m_aTitle = rTitle; }
598 
599 void SwTOXBase::SetBookmarkName(const OUString& bName)
600 {
601  m_aBookmarkName = bName;
602 }
603 
604 void SwTOXBase::SetEntryTypeName(const OUString& sName)
605 {
606  m_aEntryTypeName = sName ;
607 }
608 
610 {
611  m_aForm = rSource.m_aForm;
612  m_aName = rSource.m_aName;
613  m_aTitle = rSource.m_aTitle;
617  for(sal_uInt16 nLevel = 0; nLevel < MAXLEVEL; nLevel++)
620  m_eLanguage = rSource.m_eLanguage;
622  m_aData = rSource.m_aData;
623  m_nCreateType = rSource.m_nCreateType;
624  m_nOLEOptions = rSource.m_nOLEOptions;
626  m_bProtected = rSource.m_bProtected;
627  m_bFromChapter = rSource.m_bFromChapter;
630 
631  if (rSource.GetAttrSet())
632  SetAttrSet(*rSource.GetAttrSet());
633 
634  return *this;
635 }
636 
637 OUString SwFormToken::GetString() const
638 {
639  OUString sToken;
640 
641  switch( eTokenType )
642  {
643  case TOKEN_ENTRY_NO:
644  sToken = SwForm::GetFormEntryNum();
645  break;
646  case TOKEN_ENTRY_TEXT:
647  sToken = SwForm::GetFormEntryText();
648  break;
649  case TOKEN_ENTRY:
650  sToken = SwForm::GetFormEntry();
651  break;
652  case TOKEN_TAB_STOP:
653  sToken = SwForm::GetFormTab();
654  break;
655  case TOKEN_TEXT:
656  // Return a Token only if Text is not empty!
657  if( sText.isEmpty() )
658  {
659  return OUString();
660  }
661  sToken = SwForm::GetFormText();
662  break;
663  case TOKEN_PAGE_NUMS:
664  sToken = SwForm::GetFormPageNums();
665  break;
666  case TOKEN_CHAPTER_INFO:
667  sToken = SwForm::GetFormChapterMark();
668  break;
669  case TOKEN_LINK_START:
670  sToken = SwForm::GetFormLinkStt();
671  break;
672  case TOKEN_LINK_END:
673  sToken = SwForm::GetFormLinkEnd();
674  break;
675  case TOKEN_AUTHORITY:
676  {
677  sToken = SwForm::GetFormAuth();
678  }
679  break;
680  case TOKEN_END:
681  break;
682  }
683 
684  OUString sData = " " + sCharStyleName + "," + OUString::number( nPoolId ) + ",";
685 
686  // TabStopPosition and TabAlign or ChapterInfoFormat
687  switch (eTokenType)
688  {
689  case TOKEN_TAB_STOP:
690  sData += OUString::number( nTabStopPosition ) + ","
691  + OUString::number( static_cast< sal_Int32 >(eTabAlign) ) + ","
692  + OUStringChar(cTabFillChar) + ","
693  + OUString::number( bWithTab ? 1 : 0 );
694  break;
695  case TOKEN_CHAPTER_INFO:
696  case TOKEN_ENTRY_NO:
697  // add also maximum permitted level
698  sData += OUString::number( nChapterFormat ) + ","
699  + OUString::number( nOutlineLevel );
700  break;
701  case TOKEN_TEXT:
702  sData += OUStringChar(TOX_STYLE_DELIMITER)
703  + sText.replaceAll(OUStringChar(TOX_STYLE_DELIMITER), "")
704  + OUStringChar(TOX_STYLE_DELIMITER);
705  break;
706  case TOKEN_AUTHORITY:
707  if (nAuthorityField<10)
708  {
709  sData = "0" + OUString::number( nAuthorityField ) + sData;
710  }
711  else
712  {
713  sData = OUString::number( nAuthorityField ) + sData;
714  }
715  break;
716  default:
717  break;
718  }
719 
720  return sToken.copy(0, sToken.getLength()-1) + sData + sToken.copy(sToken.getLength()-1);
721 }
722 
723 // -> #i21237#
724 
733 static FormTokenType lcl_GetTokenType(const OUString & sToken,
734  sal_Int32 & rTokenLen)
735 {
736  static struct
737  {
738  OUString sTokenStart;
739  sal_Int16 nTokenLength;
740  FormTokenType eTokenType;
741  } const aTokenArr[] = {
742  { SwForm::GetFormTab().copy(0, 2), 3, TOKEN_TAB_STOP },
743  { SwForm::GetFormPageNums().copy(0, 2), 3, TOKEN_PAGE_NUMS },
744  { SwForm::GetFormLinkStt().copy(0, 3), 4, TOKEN_LINK_START },
745  { SwForm::GetFormLinkEnd().copy(0, 3), 4, TOKEN_LINK_END },
746  { SwForm::GetFormEntryNum().copy(0, 3), 4, TOKEN_ENTRY_NO },
747  { SwForm::GetFormEntryText().copy(0, 3), 4, TOKEN_ENTRY_TEXT },
748  { SwForm::GetFormChapterMark().copy(0, 2), 3, TOKEN_CHAPTER_INFO },
749  { SwForm::GetFormText().copy(0, 2), 3, TOKEN_TEXT },
750  { SwForm::GetFormEntry().copy(0, 2), 3, TOKEN_ENTRY },
751  { SwForm::GetFormAuth().copy(0, 2), 5, TOKEN_AUTHORITY }
752  };
753 
754  for(const auto & i : aTokenArr)
755  {
756  if( sToken.startsWith( i.sTokenStart ) )
757  {
758  rTokenLen = i.nTokenLength;
759  return i.eTokenType;
760  }
761  }
762 
763  SAL_WARN("sw.core", "SwFormTokensHelper: invalid token");
764  return TOKEN_END;
765 }
766 
775 static OUString
776 lcl_SearchNextToken(const OUString & sPattern, sal_Int32 const nStt)
777 {
778  sal_Int32 nEnd = sPattern.indexOf( '>', nStt );
779  if (nEnd >= 0)
780  {
781  // apparently the TOX_STYLE_DELIMITER act as a bracketing for
782  // TOKEN_TEXT tokens so that the user can have '>' inside the text...
783  const sal_Int32 nTextSeparatorFirst = sPattern.indexOf( TOX_STYLE_DELIMITER, nStt );
784  if ( nTextSeparatorFirst >= 0
785  && nTextSeparatorFirst + 1 < sPattern.getLength()
786  && nTextSeparatorFirst < nEnd)
787  {
788  const sal_Int32 nTextSeparatorSecond = sPattern.indexOf( TOX_STYLE_DELIMITER,
789  nTextSeparatorFirst + 1 );
790  // Since nEnd>=0 we don't need to check if nTextSeparatorSecond<0!
791  if( nEnd < nTextSeparatorSecond )
792  nEnd = sPattern.indexOf( '>', nTextSeparatorSecond );
793  // FIXME: No check to verify that nEnd is still >=0?
794  assert(nEnd >= 0);
795  }
796 
797  ++nEnd;
798 
799  return sPattern.copy( nStt, nEnd - nStt );
800  }
801 
802  return OUString();
803 }
804 
813 static std::optional<SwFormToken>
814 lcl_BuildToken(const OUString & sPattern, sal_Int32 & nCurPatternPos)
815 {
816  OUString sToken( lcl_SearchNextToken(sPattern, nCurPatternPos) );
817  nCurPatternPos += sToken.getLength();
818  sal_Int32 nTokenLen = 0;
819  FormTokenType const eTokenType = lcl_GetTokenType(sToken, nTokenLen);
820  if (TOKEN_END == eTokenType) // invalid input? skip it
821  {
822  nCurPatternPos = sPattern.getLength();
823  return std::optional<SwFormToken>();
824  }
825 
826  // at this point sPattern contains the
827  // character style name, the PoolId, tab stop position, tab stop alignment, chapter info format
828  // the form is: CharStyleName, PoolId[, TabStopPosition|ChapterInfoFormat[, TabStopAlignment[, TabFillChar]]]
829  // in text tokens the form differs from the others: CharStyleName, PoolId[,\0xffinserted text\0xff]
830  SwFormToken eRet( eTokenType );
831  const OUString sAuthFieldEnum = sToken.copy( 2, 2 );
832  sToken = sToken.copy( nTokenLen, sToken.getLength() - nTokenLen - 1);
833 
834  sal_Int32 nIdx{ 0 };
835  eRet.sCharStyleName = sToken.getToken( 0, ',', nIdx );
836  OUString sTmp( sToken.getToken( 0, ',', nIdx ));
837  if( !sTmp.isEmpty() )
838  eRet.nPoolId = static_cast<sal_uInt16>(sTmp.toInt32());
839 
840  switch( eTokenType )
841  {
842 //i53420
843  case TOKEN_CHAPTER_INFO:
844 //i53420
845  case TOKEN_ENTRY_NO:
846  sTmp = sToken.getToken( 0, ',', nIdx ); // token 2
847  if( !sTmp.isEmpty() )
848  eRet.nChapterFormat = static_cast<sal_uInt16>(sTmp.toInt32());
849  sTmp = sToken.getToken( 0, ',', nIdx ); // token 3
850  if( !sTmp.isEmpty() )
851  eRet.nOutlineLevel = static_cast<sal_uInt16>(sTmp.toInt32()); //the maximum outline level to examine
852  break;
853 
854  case TOKEN_TEXT:
855  {
856  const sal_Int32 nStartText = sToken.indexOf( TOX_STYLE_DELIMITER );
857  if( nStartText>=0 && nStartText+1<sToken.getLength())
858  {
859  const sal_Int32 nEndText = sToken.indexOf( TOX_STYLE_DELIMITER,
860  nStartText + 1);
861  if( nEndText>=0 )
862  {
863  eRet.sText = sToken.copy( nStartText + 1,
864  nEndText - nStartText - 1);
865  }
866  }
867  }
868  break;
869 
870  case TOKEN_TAB_STOP:
871  sTmp = sToken.getToken( 0, ',', nIdx ); // token 2
872  if( !sTmp.isEmpty() )
873  eRet.nTabStopPosition = sTmp.toInt32();
874 
875  sTmp = sToken.getToken( 0, ',', nIdx ); // token 3
876  if( !sTmp.isEmpty() )
877  eRet.eTabAlign = static_cast<SvxTabAdjust>(sTmp.toInt32());
878 
879  sTmp = sToken.getToken( 0, ',', nIdx ); // token 4
880  if( !sTmp.isEmpty() )
881  eRet.cTabFillChar = sTmp[0];
882 
883  sTmp = sToken.getToken( 0, ',', nIdx ); // token 5
884  if( !sTmp.isEmpty() )
885  eRet.bWithTab = 0 != sTmp.toInt32();
886  break;
887 
888  case TOKEN_AUTHORITY:
889  eRet.nAuthorityField = static_cast<sal_uInt16>(sAuthFieldEnum.toInt32());
890  break;
891  default: break;
892  }
893  return eRet;
894 }
895 
896 SwFormTokensHelper::SwFormTokensHelper(const OUString & rPattern)
897 {
898  sal_Int32 nCurPatternPos = 0;
899 
900  while (nCurPatternPos < rPattern.getLength())
901  {
902  std::optional<SwFormToken> const oToken(
903  lcl_BuildToken(rPattern, nCurPatternPos));
904  if (oToken)
905  m_Tokens.push_back(*oToken);
906  }
907 }
908 
909 // <- #i21237#
910 
911 void SwForm::SetPattern(sal_uInt16 nLevel, const SwFormTokens& rTokens)
912 {
913  OSL_ENSURE(nLevel < GetFormMax(), "Index >= FORM_MAX");
914  m_aPattern[nLevel] = rTokens;
915 }
916 
917 void SwForm::SetPattern(sal_uInt16 nLevel, const OUString & rStr)
918 {
919  OSL_ENSURE(nLevel < GetFormMax(), "Index >= FORM_MAX");
920 
922  m_aPattern[nLevel] = aHelper.GetTokens();
923 }
924 
925 const SwFormTokens& SwForm::GetPattern(sal_uInt16 nLevel) const
926 {
927  OSL_ENSURE(nLevel < GetFormMax(), "Index >= FORM_MAX");
928  return m_aPattern[nLevel];
929 }
930 
931 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwFormTokens & GetTokens() const
Returns vector of tokens.
Definition: tox.hxx:298
std::vector< SwFormToken > SwFormTokens
Vector of tokens.
Definition: tox.hxx:274
SwCaptionDisplay m_eCaptionDisplay
Definition: tox.hxx:437
virtual void SwClientNotify(const SwModify &rModify, const SfxHint &rHint) override
Definition: tox.cxx:149
OUString m_aStyleNames[MAXLEVEL]
Definition: tox.hxx:424
const sal_Unicode C_NUM_REPL
Definition: tox.cxx:43
const SfxItemSet * GetAttrSet() const
Definition: doctxm.cxx:2069
TOXTypes
Definition: toxe.hxx:39
void SetAttrSet(const SfxItemSet &)
Definition: doctxm.cxx:2077
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
const SvxTabStopItem & GetTabStops(bool=true) const
Definition: paratr.hxx:214
SwTOXMark()
pool default constructor
Definition: tox.cxx:94
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
sal_uInt16 Count() const
OUString m_sSequenceName
Definition: tox.hxx:425
static OUString lcl_SearchNextToken(const OUString &sPattern, sal_Int32 const nStt)
Returns the string of a token.
Definition: tox.cxx:776
SwTextTOXMark * m_pTextAttr
Definition: tox.hxx:89
void SetPattern(sal_uInt16 nLevel, const SwFormTokens &rName)
Definition: tox.cxx:911
sal_uInt16 nOutlineLevel
Definition: tox.hxx:240
static const char * STR_POOLCOLL_TOX_CNTNT_EXTRA_ARY[]
Definition: tox.cxx:224
static const char * STR_POOLCOLL_TOX_ARY[]
Definition: tox.cxx:203
SwTOOElements
Definition: tox.hxx:398
Definition: tox.hxx:301
OUString m_aTitle
Definition: tox.hxx:418
const SwTOXType * InsertTOXType(const SwTOXType &rTyp)
Definition: doctxm.cxx:629
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: doc.hxx:796
OUString m_aBookmarkName
Definition: tox.hxx:419
SAL_DLLPRIVATE void SetXTOXMark(css::uno::Reference< css::text::XDocumentIndexMark > const &xMark)
Definition: tox.hxx:159
static OUString GetFormLinkStt()
Definition: tox.cxx:493
OUString const & GetTemplate(sal_uInt16 nLevel) const
Definition: tox.hxx:666
void SetTitle(const OUString &rTitle)
Definition: tox.cxx:596
#define TOX_STYLE_DELIMITER
Definition: tox.hxx:411
sal_Int64 n
Definition: doc.hxx:184
SwForm(TOXTypes eTOXType=TOX_CONTENT)
Definition: tox.cxx:289
static const char * STR_POOLCOLL_TOX_ILLUS_ARY[]
Definition: tox.cxx:255
static const char * STR_POOLCOLL_TOX_CNTNT_ARY[]
Definition: tox.cxx:213
union SwTOXBase::@30 m_aData
sal_uInt16 m_nFormMaxLevel
Definition: tox.hxx:307
sal_uInt16 GetFormMax() const
Definition: tox.hxx:677
static OUString GetFormTab()
Definition: tox.cxx:491
SwFormTokens m_Tokens
the tokens
Definition: tox.hxx:283
static const char * STR_POOLCOLL_TOX_OBJECT_ARY[]
Definition: tox.cxx:262
sal_uInt16 nLevel
Definition: tox.hxx:431
static std::optional< SwFormToken > lcl_BuildToken(const OUString &sPattern, sal_Int32 &nCurPatternPos)
Builds a token from its string representation.
Definition: tox.cxx:814
bool m_bFromChapter
Definition: tox.hxx:439
sal_uInt16 nPoolId
Definition: tox.hxx:237
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
bool bWithTab
Definition: tox.hxx:243
virtual ~SwTOXMark() override
Definition: tox.cxx:129
void InvalidateTOXMark()
Definition: tox.cxx:163
bool m_bLevelFromChapter
Definition: tox.hxx:442
sal_Unicode cTabFillChar
Definition: tox.hxx:242
SwTOIOptions nOptions
Definition: tox.hxx:432
static const char * STR_POOLCOLL_TOX_AUTHORITIES_ARY[]
Definition: tox.cxx:276
sal_uInt16 sal_Unicode
const SwTOXType * GetTOXType() const
Definition: tox.hxx:692
SwTOXElement m_nCreateType
Definition: tox.hxx:435
void RegisterToTOXType(SwTOXType &rMark)
Definition: tox.cxx:527
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void SetTemplate(sal_uInt16 nLevel, const OUString &rName)
Definition: tox.hxx:660
OUString sText
Definition: tox.hxx:233
sal_Int32 & GetTabPos()
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:95
static OUString GetFormEntry()
Definition: tox.cxx:490
static const char * STR_POOLCOLL_TOX_USER_EXTRA_ARY[]
Definition: tox.cxx:245
bool m_bProtected
Definition: tox.hxx:438
LanguageType m_eLanguage
Definition: tox.hxx:427
OUString maMSTOCExpression
Definition: tox.hxx:447
SvxTabAdjust & GetAdjustment()
static OUString GetFormEntryNum()
Definition: tox.cxx:495
#define SAL_N_ELEMENTS(arr)
virtual const sal_Int32 * GetEnd() const override
end position
Definition: atrtox.cxx:49
sal_Int32 m_nLevel
OUString m_aName
OUString GetString() const
Definition: tox.cxx:637
SwTOXType(TOXTypes eTyp, const OUString &aName)
Definition: tox.cxx:190
int i
SwTOXElement
Definition: tox.hxx:353
const OUString S_PAGE_DELI(", ")
FormTokenType eTokenType
Definition: tox.hxx:236
const SwFormTokens & GetPattern(sal_uInt16 nLevel) const
Definition: tox.cxx:925
OUString sCharStyleName
Definition: tox.hxx:234
bool m_bIsRelTabPos
Definition: tox.hxx:309
void SetBookmarkName(const OUString &bName)
Definition: tox.cxx:599
Any aHelper
void RegisterToTOXType(SwTOXType &rMark)
Definition: tox.cxx:133
OUString GetText(SwRootFrame const *pLayout) const
Definition: tox.cxx:170
SwTOXBase(const SwTOXType *pTyp, const SwForm &rForm, SwTOXElement nCreaType, const OUString &rTitle)
Definition: tox.cxx:501
const OUString & GetTypeName() const
Definition: tox.hxx:684
const SwTextNode * GetpTextNd() const
Definition: txttxmrk.hxx:44
static OUString GetFormChapterMark()
Definition: tox.cxx:497
SwTOOElements m_nOLEOptions
Definition: tox.hxx:436
SwForm & operator=(const SwForm &rForm)
Definition: tox.cxx:402
sal_uInt16 nChapterFormat
Definition: tox.hxx:239
sal_uInt16 nAuthorityField
Definition: tox.hxx:241
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
static sal_uInt16 GetFormMaxLevel(TOXTypes eType)
Definition: tox.cxx:418
virtual ~SwTOXBase() override
Definition: tox.cxx:590
SwForm m_aForm
Definition: tox.hxx:416
void SetEntryTypeName(const OUString &sName)
Definition: tox.cxx:604
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(179)
OUString m_sSortAlgorithm
Definition: tox.hxx:428
const sal_Unicode C_END_PAGE_NUM
Definition: tox.cxx:44
void CopyTOXBase(SwDoc *, const SwTOXBase &)
Definition: tox.cxx:532
const SwTOXTypes & GetTOXTypes() const
Definition: doc.hxx:976
void NotifyClients(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:167
ToxAuthorityField
Definition: toxe.hxx:82
SwTOXBase & operator=(const SwTOXBase &rSource)
Definition: tox.cxx:609
OUString m_aAltText
Definition: tox.hxx:80
bool m_bFromObjectNames
Definition: tox.hxx:440
OUString GetExpandText(SwRootFrame const *pLayout, const sal_Int32 nIdx=0, const sal_Int32 nLen=-1, const bool bWithNum=false, const bool bAddSpaceAfterListLabelStr=false, const bool bWithSpacesForLevel=false, const ExpandMode eAdditionalMode=ExpandMode::ExpandFootnote) const
add 4th optional parameter indicating, when that a spa...
Definition: ndtxt.cxx:3375
SwTwips nTabStopPosition
Definition: tox.hxx:235
OUString GetUniqueTOXBaseName(const SwTOXType &rType, const OUString &sChkStr) const
Definition: doctxm.cxx:636
sal_Unicode & GetFill()
static const char * STR_POOLCOLL_TOX_TABLES_ARY[]
Definition: tox.cxx:269
OUString m_aEntryTypeName
Definition: tox.hxx:420
bool IsCopyIsMove() const
Definition: doc.hxx:1368
LanguageType GetAppLanguage()
Definition: init.cxx:729
TOXTypes m_eType
Definition: tox.hxx:306
const SwModify * GetRegisteredIn() const
Definition: calbck.hxx:157
OUString m_sMainEntryCharStyle
Definition: tox.hxx:422
static const char * STR_POOLCOLL_TOX_USER_ARY[]
Definition: tox.cxx:234
OUString m_aTemplate[AUTH_TYPE_END+1]
Definition: tox.hxx:304
static OUString GetFormLinkEnd()
Definition: tox.cxx:494
void * p
static FormTokenType lcl_GetTokenType(const OUString &sToken, sal_Int32 &rTokenLen)
Returns the type of a token.
Definition: tox.cxx:733
static OUString GetFormText()
Definition: tox.cxx:498
static OUString GetFormEntryText()
Definition: tox.cxx:496
constexpr TypedWhichId< SwTOXMark > RES_TXTATR_TOXMARK(47)
virtual bool operator==(const SfxPoolItem &) const override
Definition: tox.cxx:138
TOXTypes GetType() const
Definition: tox.hxx:687
SvxTabAdjust eTabAlign
Definition: tox.hxx:238
#define SAL_WARN(area, stream)
static const char * STR_POOLCOLL_TOX_CITATION_ARY[]
Definition: tox.cxx:283
if(!pCandidateA->getEnd().equal(pCandidateB->getStart()))
const SwTextTOXMark * GetTextTOXMark() const
Definition: tox.hxx:154
const EnumerationType m_eType
SwFormTokens m_aPattern[AUTH_TYPE_END+1]
Definition: tox.hxx:303
Helper class that converts vectors of tokens to strings and vice versa.
Definition: tox.hxx:280
static OUString GetFormAuth()
Definition: tox.cxx:499
virtual SwTOXMark * Clone(SfxItemPool *pPool=nullptr) const override
Definition: tox.cxx:144
void AdjustTabStops(SwDoc const &rDoc)
Definition: tox.cxx:439
FormTokenType
Definition: tox.hxx:216
bool m_bCommaSeparated
Definition: tox.hxx:310
const OUString & GetTOXName() const
Definition: tox.hxx:464
SwFormTokensHelper(const OUString &rStr)
constructor
Definition: tox.cxx:896
OUString m_aName
Definition: tox.hxx:417
static OUString GetFormPageNums()
Definition: tox.cxx:492