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;
353 const bool bNeedsLink
355 if (bNeedsLink)
356 {
357 SwFormToken aLinkStt (TOKEN_LINK_START);
358 aLinkStt.sCharStyleName = SwResId(STR_POOLCHR_TOXJUMP);
359 aTokens.push_back(aLinkStt);
360 }
361
362 if (TOX_CONTENT == m_eType)
363 {
364 aTokens.emplace_back(TOKEN_ENTRY_NO);
365 aTokens.emplace_back(TOKEN_ENTRY_TEXT);
366 }
367 else
368 aTokens.emplace_back(TOKEN_ENTRY);
369
371 {
373 aToken.nTabStopPosition = 0;
374
375 // #i36870# right aligned tab for all
376 aToken.cTabFillChar = '.';
377 aToken.eTabAlign = SvxTabAdjust::End;
378
379 aTokens.push_back(aToken);
380 aTokens.emplace_back(TOKEN_PAGE_NUMS);
381 }
382
383 if (bNeedsLink)
384 aTokens.emplace_back(TOKEN_LINK_END);
385
386 SetTemplate(0, SwResId(*pPoolId++));
387
388 if(TOX_INDEX == m_eType)
389 {
390 for( sal_uInt16 i = 1; i < 5; ++i )
391 {
392 if(1 == i)
393 {
394 SwFormTokens aTmpTokens;
395 SwFormToken aTmpToken(TOKEN_ENTRY);
396 aTmpTokens.push_back(aTmpToken);
397
398 SetPattern( i, std::move(aTmpTokens) );
399 SetTemplate(i, SwResId(STR_POOLCOLL_TOX_IDXBREAK));
400 }
401 else
402 {
403 SetPattern( i, std::vector(aTokens) );
405 }
406 }
407 }
408 else
409 {
410 for (sal_uInt16 i = 1; i < GetFormMax(); ++i, ++pPoolId) // Number 0 is the title
411 {
413 {
414 SwFormTokens aAuthTokens;
415 lcl_FillAuthPattern(aAuthTokens, i);
416 SetPattern(i, std::move(aAuthTokens));
417 }
418 else
419 SetPattern( i, std::vector(aTokens) );
420
421 if( TOX_CONTENT == m_eType && 6 == i )
423 else if( TOX_USER == m_eType && 6 == i )
425 else if( TOX_AUTHORITIES == m_eType ) //reuse the same STR_POOLCOLL_TOX_AUTHORITIES1 id each time
427 SetTemplate(i, SwResId(*pPoolId));
428 }
429 }
430}
431
433 : m_eType( rForm.m_eType )
434{
435 *this = rForm;
436}
437
439{
440 m_eType = rForm.m_eType;
442// nFirstTabPos = rForm.nFirstTabPos;
443// bHasFirstTabPos = rForm.bHasFirstTabPos;
446 for(sal_uInt16 i=0; i < m_nFormMaxLevel; ++i)
447 {
448 m_aPattern[i] = rForm.m_aPattern[i];
449 m_aTemplate[i] = rForm.m_aTemplate[i];
450 }
451 return *this;
452}
453
454sal_uInt16 SwForm::GetFormMaxLevel( TOXTypes eTOXType )
455{
456 switch( eTOXType )
457 {
458 case TOX_INDEX:
459 return 5;
460 case TOX_USER:
461 case TOX_CONTENT:
462 return MAXLEVEL + 1;
464 case TOX_OBJECTS:
465 case TOX_TABLES:
466 return 2;
467 case TOX_BIBLIOGRAPHY:
468 case TOX_CITATION:
469 case TOX_AUTHORITIES:
470 return AUTH_TYPE_END + 1;
471 }
472 return 0;
473}
474
475void SwForm::AdjustTabStops( SwDoc const & rDoc ) // #i21237#
476{
477 const sal_uInt16 nFormMax = GetFormMax();
478 for ( sal_uInt16 nLevel = 1; nLevel < nFormMax; ++nLevel )
479 {
481 if( pColl == nullptr )
482 {
483 // Paragraph Style for this level has not been created.
484 // --> No need to propagate default values
485 continue;
486 }
487
488 const SvxTabStopItem& rTabStops = pColl->GetTabStops(false);
489 const sal_uInt16 nTabCount = rTabStops.Count();
490 if (nTabCount != 0)
491 {
492 SwFormTokens aCurrentPattern = GetPattern(nLevel);
493 SwFormTokens::iterator aIt = aCurrentPattern.begin();
494
495 bool bChanged = false;
496 for(sal_uInt16 nTab = 0; nTab < nTabCount; ++nTab)
497 {
498 const SvxTabStop& rTab = rTabStops[nTab];
499
500 if ( rTab.GetAdjustment() == SvxTabAdjust::Default )
501 continue; // ignore the default tab stop
502
503 aIt = find_if( aIt, aCurrentPattern.end(), SwFormTokenEqualToFormTokenType(TOKEN_TAB_STOP) );
504 if ( aIt != aCurrentPattern.end() )
505 {
506 bChanged = true;
507 aIt->nTabStopPosition = rTab.GetTabPos();
508 aIt->eTabAlign =
509 ( nTab == nTabCount - 1
510 && rTab.GetAdjustment() == SvxTabAdjust::Right )
511 ? SvxTabAdjust::End
512 : rTab.GetAdjustment();
513 aIt->cTabFillChar = rTab.GetFill();
514 ++aIt;
515 }
516 else
517 break; // no more tokens to replace
518 }
519
520 if ( bChanged )
521 SetPattern( nLevel, std::move(aCurrentPattern) );
522 }
523 }
524}
525
526OUString SwForm::GetFormEntry() {return "<E>";}
527OUString SwForm::GetFormTab() {return "<T>";}
528OUString SwForm::GetFormPageNums() {return "<#>";}
529OUString SwForm::GetFormLinkStt() {return "<LS>";}
530OUString SwForm::GetFormLinkEnd() {return "<LE>";}
531OUString SwForm::GetFormEntryNum() {return "<E#>";}
532OUString SwForm::GetFormEntryText() {return "<ET>";}
533OUString SwForm::GetFormChapterMark() {return "<C>";}
534OUString SwForm::GetFormText() {return "<X>";}
535OUString SwForm::GetFormAuth() {return "<A>";}
536
537SwTOXBase::SwTOXBase(const SwTOXType* pTyp, const SwForm& rForm,
538 SwTOXElement nCreaType, OUString aTitle )
539 : SwClient(const_cast<sw::BroadcastingModify*>(static_cast<sw::BroadcastingModify const *>(pTyp)))
540 , m_aForm(rForm)
541 , m_aTitle(std::move(aTitle))
542 , m_eLanguage(::GetAppLanguage())
543 , m_nCreateType(nCreaType)
544 , m_nOLEOptions(SwTOOElements::NONE)
545 , m_eCaptionDisplay(CAPTION_COMPLETE)
546 , m_bProtected( true )
547 , m_bFromChapter(false)
548 , m_bFromObjectNames(false)
549 , m_bLevelFromChapter(false)
550 , maMSTOCExpression()
551 , mbKeepExpression(true)
552{
553 m_aData.nOptions = SwTOIOptions::NONE;
554}
555
556SwTOXBase::SwTOXBase( const SwTOXBase& rSource, SwDoc* pDoc )
557 : SwClient( rSource.GetRegisteredInNonConst() )
558 , mbKeepExpression(true)
559{
560 CopyTOXBase( pDoc, rSource );
561}
562
564{
565 rType.Add( this );
566}
567
568void SwTOXBase::CopyTOXBase( SwDoc* pDoc, const SwTOXBase& rSource )
569{
571 SwTOXType* pType = const_cast<SwTOXType*>(rSource.GetTOXType());
572 if( pDoc &&
573 std::find_if(pDoc->GetTOXTypes().begin(), pDoc->GetTOXTypes().end(),
574 [=](const std::unique_ptr<SwTOXType> & p) { return p.get() == pType; })
575 == pDoc->GetTOXTypes().end())
576 {
577 // type not in pDoc, so create it now
578 const SwTOXTypes& rTypes = pDoc->GetTOXTypes();
579 bool bFound = false;
580 for( size_t n = rTypes.size(); n; )
581 {
582 const SwTOXType* pCmp = rTypes[ --n ].get();
583 if( pCmp->GetType() == pType->GetType() &&
584 pCmp->GetTypeName() == pType->GetTypeName() )
585 {
586 pType = const_cast<SwTOXType*>(pCmp);
587 bFound = true;
588 break;
589 }
590 }
591
592 if( !bFound )
593 pType = const_cast<SwTOXType*>(pDoc->InsertTOXType( *pType ));
594 }
595 pType->Add( this );
596
598 m_aTitle = rSource.m_aTitle;
599 m_aForm = rSource.m_aForm;
601 m_bProtected = rSource.m_bProtected;
608 m_eLanguage = rSource.m_eLanguage;
611
612 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
613 m_aStyleNames[i] = rSource.m_aStyleNames[i];
614
615 // it's the same data type!
616 m_aData.nOptions = rSource.m_aData.nOptions;
617
618 if( !pDoc || pDoc->IsCopyIsMove() )
619 m_aName = rSource.GetTOXName();
620 else
621 m_aName = pDoc->GetUniqueTOXBaseName( *pType, rSource.GetTOXName() );
622}
623
624// TOX specific functions
626{
627// if( GetTOXType()->GetType() == TOX_USER )
628// delete aData.pTemplateName;
629}
630
631void SwTOXBase::SetTitle(const OUString& rTitle)
632 { m_aTitle = rTitle; }
633
634void SwTOXBase::SetBookmarkName(const OUString& bName)
635{
636 m_aBookmarkName = bName;
637}
638
640{
641 m_aForm = rSource.m_aForm;
642 m_aName = rSource.m_aName;
643 m_aTitle = rSource.m_aTitle;
646 for(sal_uInt16 nLevel = 0; nLevel < MAXLEVEL; nLevel++)
649 m_eLanguage = rSource.m_eLanguage;
651 m_aData = rSource.m_aData;
655 m_bProtected = rSource.m_bProtected;
659
660 if (rSource.GetAttrSet())
661 SetAttrSet(*rSource.GetAttrSet());
662
663 return *this;
664}
665
667{
668 OUString sToken;
669
670 switch( eTokenType )
671 {
672 case TOKEN_ENTRY_NO:
673 sToken = SwForm::GetFormEntryNum();
674 break;
675 case TOKEN_ENTRY_TEXT:
676 sToken = SwForm::GetFormEntryText();
677 break;
678 case TOKEN_ENTRY:
679 sToken = SwForm::GetFormEntry();
680 break;
681 case TOKEN_TAB_STOP:
682 sToken = SwForm::GetFormTab();
683 break;
684 case TOKEN_TEXT:
685 // Return a Token only if Text is not empty!
686 if( sText.isEmpty() )
687 {
688 return OUString();
689 }
690 sToken = SwForm::GetFormText();
691 break;
692 case TOKEN_PAGE_NUMS:
693 sToken = SwForm::GetFormPageNums();
694 break;
697 break;
698 case TOKEN_LINK_START:
699 sToken = SwForm::GetFormLinkStt();
700 break;
701 case TOKEN_LINK_END:
702 sToken = SwForm::GetFormLinkEnd();
703 break;
704 case TOKEN_AUTHORITY:
705 {
706 sToken = SwForm::GetFormAuth();
707 }
708 break;
709 case TOKEN_END:
710 break;
711 }
712
713 OUString sData = " " + sCharStyleName + "," + OUString::number( nPoolId ) + ",";
714
715 // TabStopPosition and TabAlign or ChapterInfoFormat
716 switch (eTokenType)
717 {
718 case TOKEN_TAB_STOP:
719 sData += OUString::number( nTabStopPosition ) + ","
720 + OUString::number( static_cast< sal_Int32 >(eTabAlign) ) + ","
721 + OUStringChar(cTabFillChar) + ","
722 + OUString::number( bWithTab ? 1 : 0 );
723 break;
725 case TOKEN_ENTRY_NO:
726 // add also maximum permitted level
727 sData += OUString::number( nChapterFormat ) + ","
728 + OUString::number( nOutlineLevel );
729 break;
730 case TOKEN_TEXT:
731 sData += OUStringChar(TOX_STYLE_DELIMITER)
732 + sText.replaceAll(OUStringChar(TOX_STYLE_DELIMITER), "")
733 + OUStringChar(TOX_STYLE_DELIMITER);
734 break;
735 case TOKEN_AUTHORITY:
736 if (nAuthorityField<10)
737 {
738 sData = "0" + OUString::number( nAuthorityField ) + sData;
739 }
740 else
741 {
742 sData = OUString::number( nAuthorityField ) + sData;
743 }
744 break;
745 default:
746 break;
747 }
748
749 return sToken.subView(0, sToken.getLength()-1) + sData + sToken.subView(sToken.getLength()-1);
750}
751
752// -> #i21237#
753
762static FormTokenType lcl_GetTokenType(std::u16string_view sToken,
763 sal_Int32 & rTokenLen)
764{
765 static struct
766 {
767 OUString sTokenStart;
768 sal_Int16 nTokenLength;
769 FormTokenType eTokenType;
770 } const aTokenArr[] = {
771 { SwForm::GetFormTab().copy(0, 2), 3, TOKEN_TAB_STOP },
772 { SwForm::GetFormPageNums().copy(0, 2), 3, TOKEN_PAGE_NUMS },
773 { SwForm::GetFormLinkStt().copy(0, 3), 4, TOKEN_LINK_START },
774 { SwForm::GetFormLinkEnd().copy(0, 3), 4, TOKEN_LINK_END },
775 { SwForm::GetFormEntryNum().copy(0, 3), 4, TOKEN_ENTRY_NO },
776 { SwForm::GetFormEntryText().copy(0, 3), 4, TOKEN_ENTRY_TEXT },
778 { SwForm::GetFormText().copy(0, 2), 3, TOKEN_TEXT },
779 { SwForm::GetFormEntry().copy(0, 2), 3, TOKEN_ENTRY },
780 { SwForm::GetFormAuth().copy(0, 2), 5, TOKEN_AUTHORITY }
781 };
782
783 for(const auto & i : aTokenArr)
784 {
785 if( o3tl::starts_with( sToken, i.sTokenStart ) )
786 {
787 rTokenLen = i.nTokenLength;
788 return i.eTokenType;
789 }
790 }
791
792 SAL_WARN("sw.core", "SwFormTokensHelper: invalid token");
793 return TOKEN_END;
794}
795
804static std::u16string_view
805lcl_SearchNextToken(std::u16string_view sPattern, sal_Int32 const nStt)
806{
807 size_t nEnd = sPattern.find( u'>', nStt );
808 if (nEnd != std::u16string_view::npos)
809 {
810 // apparently the TOX_STYLE_DELIMITER act as a bracketing for
811 // TOKEN_TEXT tokens so that the user can have '>' inside the text...
812 const size_t nTextSeparatorFirst = sPattern.find( TOX_STYLE_DELIMITER, nStt );
813 if ( nTextSeparatorFirst != std::u16string_view::npos
814 && nTextSeparatorFirst + 1 < sPattern.size()
815 && nTextSeparatorFirst < nEnd)
816 {
817 const size_t nTextSeparatorSecond = sPattern.find( TOX_STYLE_DELIMITER,
818 nTextSeparatorFirst + 1 );
819 // Since nEnd>=0 we don't need to check if nTextSeparatorSecond==std::u16string_view::npos!
820 if( nEnd < nTextSeparatorSecond )
821 nEnd = sPattern.find( '>', nTextSeparatorSecond );
822 // FIXME: No check to verify that nEnd is still >=0?
823 assert(nEnd != std::u16string_view::npos);
824 }
825
826 ++nEnd;
827
828 return sPattern.substr( nStt, nEnd - nStt );
829 }
830
831 return std::u16string_view();
832}
833
842static std::optional<SwFormToken>
843lcl_BuildToken(std::u16string_view sPattern, size_t & nCurPatternPos)
844{
845 std::u16string_view sToken( lcl_SearchNextToken(sPattern, nCurPatternPos) );
846 nCurPatternPos += sToken.size();
847 sal_Int32 nTokenLen = 0;
848 FormTokenType const eTokenType = lcl_GetTokenType(sToken, nTokenLen);
849 if (TOKEN_END == eTokenType) // invalid input? skip it
850 {
851 nCurPatternPos = sPattern.size();
852 return std::optional<SwFormToken>();
853 }
854
855 // at this point sPattern contains the
856 // character style name, the PoolId, tab stop position, tab stop alignment, chapter info format
857 // the form is: CharStyleName, PoolId[, TabStopPosition|ChapterInfoFormat[, TabStopAlignment[, TabFillChar]]]
858 // in text tokens the form differs from the others: CharStyleName, PoolId[,\0xffinserted text\0xff]
859 SwFormToken eRet( eTokenType );
860 const std::u16string_view sAuthFieldEnum = sToken.substr( 2, 2 );
861 sToken = sToken.substr( nTokenLen, sToken.size() - nTokenLen - 1);
862
863 sal_Int32 nIdx{ 0 };
864 eRet.sCharStyleName = o3tl::getToken(sToken, 0, ',', nIdx );
865 std::u16string_view sTmp( o3tl::getToken(sToken, 0, ',', nIdx ));
866 if( !sTmp.empty() )
867 eRet.nPoolId = o3tl::narrowing<sal_uInt16>(o3tl::toInt32(sTmp));
868
869 switch( eTokenType )
870 {
871//i53420
873//i53420
874 case TOKEN_ENTRY_NO:
875 sTmp = o3tl::getToken(sToken, 0, ',', nIdx ); // token 2
876 if( !sTmp.empty() )
877 eRet.nChapterFormat = o3tl::narrowing<sal_uInt16>(o3tl::toInt32(sTmp));
878 sTmp = o3tl::getToken(sToken, 0, ',', nIdx ); // token 3
879 if( !sTmp.empty() )
880 eRet.nOutlineLevel = o3tl::narrowing<sal_uInt16>(o3tl::toInt32(sTmp)); //the maximum outline level to examine
881 break;
882
883 case TOKEN_TEXT:
884 {
885 const size_t nStartText = sToken.find( TOX_STYLE_DELIMITER );
886 if( nStartText != std::u16string_view::npos && nStartText+1<sToken.size())
887 {
888 const size_t nEndText = sToken.find( TOX_STYLE_DELIMITER,
889 nStartText + 1);
890 if( nEndText != std::u16string_view::npos )
891 {
892 eRet.sText = sToken.substr( nStartText + 1,
893 nEndText - nStartText - 1);
894 }
895 }
896 }
897 break;
898
899 case TOKEN_TAB_STOP:
900 sTmp = o3tl::getToken(sToken, 0, ',', nIdx ); // token 2
901 if( !sTmp.empty() )
902 eRet.nTabStopPosition = o3tl::toInt32(sTmp);
903
904 sTmp = o3tl::getToken(sToken, 0, ',', nIdx ); // token 3
905 if( !sTmp.empty() )
906 eRet.eTabAlign = static_cast<SvxTabAdjust>(o3tl::toInt32(sTmp));
907
908 sTmp = o3tl::getToken(sToken, 0, ',', nIdx ); // token 4
909 if( !sTmp.empty() )
910 eRet.cTabFillChar = sTmp[0];
911
912 sTmp = o3tl::getToken(sToken, 0, ',', nIdx ); // token 5
913 if( !sTmp.empty() )
914 eRet.bWithTab = 0 != o3tl::toInt32(sTmp);
915 break;
916
917 case TOKEN_AUTHORITY:
918 eRet.nAuthorityField = o3tl::narrowing<sal_uInt16>(o3tl::toInt32(sAuthFieldEnum));
919 break;
920 default: break;
921 }
922 return eRet;
923}
924
925SwFormTokensHelper::SwFormTokensHelper(std::u16string_view aPattern)
926{
927 size_t nCurPatternPos = 0;
928
929 while (nCurPatternPos < aPattern.size())
930 {
931 std::optional<SwFormToken> const oToken(
932 lcl_BuildToken(aPattern, nCurPatternPos));
933 if (oToken)
934 m_Tokens.push_back(*oToken);
935 }
936}
937
938// <- #i21237#
939
940void SwForm::SetPattern(sal_uInt16 nLevel, SwFormTokens&& rTokens)
941{
942 OSL_ENSURE(nLevel < GetFormMax(), "Index >= FORM_MAX");
943 m_aPattern[nLevel] = std::move(rTokens);
944}
945
946void SwForm::SetPattern(sal_uInt16 nLevel, std::u16string_view aStr)
947{
948 OSL_ENSURE(nLevel < GetFormMax(), "Index >= FORM_MAX");
949
951 m_aPattern[nLevel] = aHelper.GetTokens();
952}
953
954const SwFormTokens& SwForm::GetPattern(sal_uInt16 nLevel) const
955{
956 OSL_ENSURE(nLevel < GetFormMax(), "Index >= FORM_MAX");
957 return m_aPattern[nLevel];
958}
959
960/* 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:197
const SwTOXType * InsertTOXType(const SwTOXType &rTyp)
Definition: doctxm.cxx:630
bool IsCopyIsMove() const
Definition: doc.hxx:1390
const SwTOXTypes & GetTOXTypes() const
Definition: doc.hxx:994
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: doc.hxx:814
OUString GetUniqueTOXBaseName(const SwTOXType &rType, const OUString &sChkStr) const
Definition: doctxm.cxx:637
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:925
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:954
static sal_uInt16 GetFormMaxLevel(TOXTypes eType)
Definition: tox.cxx:454
TOXTypes m_eType
Definition: tox.hxx:318
SwForm & operator=(const SwForm &rForm)
Definition: tox.cxx:438
static OUString GetFormPageNums()
Definition: tox.cxx:528
void AdjustTabStops(SwDoc const &rDoc)
Definition: tox.cxx:475
static OUString GetFormEntry()
Definition: tox.cxx:526
OUString const & GetTemplate(sal_uInt16 nLevel) const
Definition: tox.hxx:672
bool m_bCommaSeparated
Definition: tox.hxx:322
static OUString GetFormTab()
Definition: tox.cxx:527
sal_uInt16 GetFormMax() const
Definition: tox.hxx:683
static OUString GetFormEntryText()
Definition: tox.cxx:532
OUString m_aTemplate[AUTH_TYPE_END+1]
Definition: tox.hxx:316
static OUString GetFormLinkEnd()
Definition: tox.cxx:530
static OUString GetFormText()
Definition: tox.cxx:534
static OUString GetFormChapterMark()
Definition: tox.cxx:533
void SetTemplate(sal_uInt16 nLevel, const OUString &rName)
Definition: tox.hxx:666
void SetPattern(sal_uInt16 nLevel, SwFormTokens &&rName)
Definition: tox.cxx:940
static OUString GetFormEntryNum()
Definition: tox.cxx:531
static OUString GetFormLinkStt()
Definition: tox.cxx:529
SwForm(TOXTypes eTOXType=TOX_CONTENT)
Definition: tox.cxx:323
static OUString GetFormAuth()
Definition: tox.cxx:535
const SvxTabStopItem & GetTabStops(bool=true) const
Definition: paratr.hxx:237
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
static bool IsInHiddenRange(const SwTextNode &rNode, sal_Int32 nPos)
Definition: porlay.cxx:2139
OUString m_aBookmarkName
Definition: tox.hxx:430
OUString m_aName
Definition: tox.hxx:428
union SwTOXBase::@27 m_aData
OUString m_sSortAlgorithm
Definition: tox.hxx:438
SwCaptionDisplay m_eCaptionDisplay
Definition: tox.hxx:447
sal_uInt16 nLevel
Definition: tox.hxx:441
SwTOXElement m_nCreateType
Definition: tox.hxx:445
void SetAttrSet(const SfxItemSet &)
Definition: doctxm.cxx:2127
void CopyTOXBase(SwDoc *, const SwTOXBase &)
Definition: tox.cxx:568
SwTOXBase(const SwTOXType *pTyp, const SwForm &rForm, SwTOXElement nCreaType, OUString aTitle)
Definition: tox.cxx:537
bool m_bLevelFromChapter
Definition: tox.hxx:452
const OUString & GetTOXName() const
Definition: tox.hxx:481
const SfxItemSet * GetAttrSet() const
Definition: doctxm.cxx:2119
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:563
void SetBookmarkName(const OUString &bName)
Definition: tox.cxx:634
SwTOXBase & operator=(const SwTOXBase &rSource)
Definition: tox.cxx:639
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:631
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:625
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:61
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:3505
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:1228
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:741
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:1140
OUString m_aName
sal_uInt16 nChapterFormat
Definition: tox.hxx:251
OUString GetString() const
Definition: tox.cxx:666
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:168
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:805
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:762
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:843
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:121
@ 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