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