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