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