LibreOffice Module sw (master) 1
thints.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 <sal/config.h>
21#include <sal/log.hxx>
22
24#include <hintids.hxx>
25#include <editeng/rsiditem.hxx>
26#include <osl/diagnose.h>
27#include <svl/whiter.hxx>
28#include <svl/itemiter.hxx>
30#include <editeng/langitem.hxx>
31#include <editeng/lrspitem.hxx>
32#include <txtinet.hxx>
33#include <txtflcnt.hxx>
34#include <fmtfld.hxx>
35#include <fmtrfmrk.hxx>
36#include <fmtanchr.hxx>
37#include <fmtinfmt.hxx>
38#include <txtatr.hxx>
39#include <fchrfmt.hxx>
40#include <fmtautofmt.hxx>
41#include <fmtflcnt.hxx>
42#include <fmtftn.hxx>
43#include <txttxmrk.hxx>
44#include <txtrfmrk.hxx>
45#include <txtftn.hxx>
46#include <textlinebreak.hxx>
47#include <txtfld.hxx>
48#include <txtannotationfld.hxx>
49#include <unotools/fltrcfg.hxx>
50#include <charfmt.hxx>
51#include <frmfmt.hxx>
52#include <ftnidx.hxx>
53#include <fmtruby.hxx>
54#include <fmtmeta.hxx>
57#include <breakit.hxx>
58#include <doc.hxx>
59#include <IDocumentUndoRedo.hxx>
63#include <fldbas.hxx>
64#include <pam.hxx>
65#include <ndtxt.hxx>
66#include <txtfrm.hxx>
67#include <rootfrm.hxx>
68#include <rolbck.hxx>
69#include <ddefld.hxx>
70#include <docufld.hxx>
71#include <expfld.hxx>
72#include <usrfld.hxx>
73#include <poolfmt.hxx>
74#include <istyleaccess.hxx>
75#include <docsh.hxx>
76#include <algorithm>
77#include <map>
78#include <memory>
79
80#include <rdfhelper.hxx>
81#include <hints.hxx>
82
83#ifdef DBG_UTIL
84#define CHECK Check(true);
85#define CHECK_NOTMERGED Check(false);
86#else
87#define CHECK_NOTMERGED
88#endif
89
90using namespace ::com::sun::star::i18n;
91
93 : m_rParent(rParent)
94 , m_pHistory(nullptr)
95 , m_bInSplitNode(false)
96 , m_bCalcHiddenParaField(false)
97 , m_bHiddenByParaField(false)
98 , m_bFootnote(false)
99 , m_bDDEFields(false)
100 , m_bStartMapNeedsSorting(false)
101 , m_bEndMapNeedsSorting(false)
102 , m_bWhichMapNeedsSorting(false)
103{
104}
105
106static void TextAttrDelete( SwDoc & rDoc, SwTextAttr * const pAttr )
107{
108 if (RES_TXTATR_META == pAttr->Which() ||
109 RES_TXTATR_METAFIELD == pAttr->Which())
110 {
111 static_txtattr_cast<SwTextMeta *>(pAttr)->ChgTextNode(nullptr); // prevents ASSERT
112 }
113 else if (pAttr->Which() == RES_TXTATR_CONTENTCONTROL)
114 {
115 static_txtattr_cast<SwTextContentControl*>(pAttr)->ChgTextNode(nullptr);
116 }
117 SwTextAttr::Destroy( pAttr, rDoc.GetAttrPool() );
118}
119
120static bool TextAttrContains(const sal_Int32 nPos, const SwTextAttrEnd * const pAttr)
121{
122 return (pAttr->GetStart() < nPos) && (nPos < *pAttr->End());
123}
124
125// a: |-----|
126// b:
127// |---| => valid: b before a
128// |-----| => valid: start == end; b before a
129// |---------| => invalid: overlap (1)
130// |-----------| => valid: same end; b around a
131// |-----------------| => valid: b around a
132// |---| => valid; same start; b within a
133// |-----| => valid; same start and end; b around or within a?
134// |-----------| => valid: same start: b around a
135// |-| => valid: b within a
136// |---| => valid: same end; b within a
137// |---------| => invalid: overlap (2)
138// |-----| => valid: end == start; b after a
139// |---| => valid: b after a
140// ===> 2 invalid overlap cases
141static
142bool isOverlap(const sal_Int32 nStart1, const sal_Int32 nEnd1,
143 const sal_Int32 nStart2, const sal_Int32 nEnd2)
144{
145 return
146 ((nStart1 > nStart2) && (nStart1 < nEnd2) && (nEnd1 > nEnd2)) // (1)
147 || ((nStart1 < nStart2) && (nStart2 < nEnd1) && (nEnd1 < nEnd2)); // (2)
148}
149
151static
152bool isNestedAny(const sal_Int32 nStart1, const sal_Int32 nEnd1,
153 const sal_Int32 nStart2, const sal_Int32 nEnd2)
154{
155 return ((nStart1 == nStart2) || (nEnd1 == nEnd2))
156 // same start/end: nested except if hint1 empty and hint2 not empty
157 ? (nStart1 != nEnd1) || (nStart2 == nEnd2)
158 : ((nStart1 < nStart2) ? (nEnd1 >= nEnd2) : (nEnd1 <= nEnd2));
159}
160
161static
162bool isSelfNestable(const sal_uInt16 nWhich)
163{
164 if ((RES_TXTATR_INETFMT == nWhich) ||
165 (RES_TXTATR_CJK_RUBY == nWhich) ||
166 (RES_TXTATR_INPUTFIELD == nWhich))
167 return false;
168 assert((RES_TXTATR_META == nWhich) ||
169 (RES_TXTATR_METAFIELD == nWhich) ||
170 (RES_TXTATR_CONTENTCONTROL == nWhich));
171 return true;
172}
173
174static
175bool isSplittable(const sal_uInt16 nWhich)
176{
177 if ((RES_TXTATR_INETFMT == nWhich) ||
178 (RES_TXTATR_CJK_RUBY == nWhich))
179 return true;
180 assert((RES_TXTATR_META == nWhich) ||
181 (RES_TXTATR_METAFIELD == nWhich) ||
182 (RES_TXTATR_INPUTFIELD == nWhich) ||
183 (RES_TXTATR_CONTENTCONTROL == nWhich));
184 return false;
185}
186
187namespace {
188
189enum Split_t { FAIL, SPLIT_NEW, SPLIT_OTHER };
190
191}
192
197static Split_t
198splitPolicy(const sal_uInt16 nWhichNew, const sal_uInt16 nWhichOther)
199{
200 if (!isSplittable(nWhichOther))
201 {
202 if (!isSplittable(nWhichNew))
203 return FAIL;
204 else
205 return SPLIT_NEW;
206 }
207 else
208 {
209 if ( RES_TXTATR_INPUTFIELD == nWhichNew )
210 return FAIL;
211 else if ( (RES_TXTATR_INETFMT == nWhichNew) &&
212 (RES_TXTATR_CJK_RUBY == nWhichOther) )
213 return SPLIT_NEW;
214 else
215 return SPLIT_OTHER;
216 }
217}
218
220{
221 ChgTextNode(&rNode);
222 SwCharFormat * const pFormat(
224 pFormat->Add( this );
225}
226
228{
229 ChgTextNode(&rNode);
230 SwCharFormat * const pFormat(
232 pFormat->Add( this );
233}
234
238static SwTextAttrNesting *
240 const sal_Int32 nStart, const sal_Int32 nEnd)
241{
242 SwTextAttr * const pNew( MakeTextAttr(
243 rNode.GetDoc(), rNesting.GetAttr(), nStart, nEnd ) );
244 switch (pNew->Which())
245 {
247 {
248 static_txtattr_cast<SwTextINetFormat*>(pNew)->InitINetFormat(rNode);
249 break;
250 }
252 {
253 static_txtattr_cast<SwTextRuby*>(pNew)->InitRuby(rNode);
254 break;
255 }
256 default:
257 assert(!"MakeTextAttrNesting: what the hell is that?");
258 break;
259 }
260 return static_txtattr_cast<SwTextAttrNesting*>(pNew);
261}
262
263typedef std::vector<SwTextAttrNesting *> NestList_t;
264
265static NestList_t::iterator
267 NestList_t::iterator const iter, sal_Int32 const nSplitPos,
268 bool const bSplitAtStart, bool const bOtherDummy)
269{
270 const sal_Int32 nStartPos( // skip other's dummy character!
271 (bSplitAtStart && bOtherDummy) ? nSplitPos + 1 : nSplitPos );
273 rNode, **iter, nStartPos, *(*iter)->GetEnd() ) );
274 (*iter)->SetEnd(nSplitPos);
275 return rSplits.insert(iter + 1, pNew);
276}
277
278static void
280 const sal_Int32 nNewStart,
281 const sal_Int32 nOtherStart, const sal_Int32 nOtherEnd, bool bOtherDummy)
282{
283 const bool bSplitAtStart(nNewStart < nOtherStart);
284 const sal_Int32 nSplitPos( bSplitAtStart ? nOtherStart : nOtherEnd );
285 // first find the portion that is split (not necessarily the last one!)
286 NestList_t::iterator const iter(
287 std::find_if( rSplits.begin(), rSplits.end(),
288 [nSplitPos](SwTextAttrEnd * const pAttr) {
289 return TextAttrContains(nSplitPos, pAttr);
290 } ) );
291 if (iter != rSplits.end()) // already split here?
292 {
293 lcl_DoSplitImpl(rSplits, rNode, iter, nSplitPos, bSplitAtStart, bOtherDummy);
294 }
295}
296
302{
303 Insert(& rNewHint);
304 NoteInHistory( & rNewHint, true );
305}
306
377bool
379{
380// INVARIANT: the nestable hints in the array are properly nested
381 const sal_uInt16 nNewWhich( rNewHint.Which() );
382 const sal_Int32 nNewStart( rNewHint.GetStart() );
383 const sal_Int32 nNewEnd ( *rNewHint.GetEnd() );
384 const bool bNewSelfNestable( isSelfNestable(nNewWhich) );
385
386 assert( (RES_TXTATR_INETFMT == nNewWhich) ||
387 (RES_TXTATR_CJK_RUBY == nNewWhich) ||
388 (RES_TXTATR_META == nNewWhich) ||
389 (RES_TXTATR_METAFIELD == nNewWhich) ||
390 (RES_TXTATR_CONTENTCONTROL == nNewWhich) ||
391 (RES_TXTATR_INPUTFIELD == nNewWhich));
392
393 NestList_t OverlappingExisting; // existing hints to be split
394 NestList_t OverwrittenExisting; // existing hints to be replaced
395 NestList_t SplitNew; // new hints to be inserted
396
397 SplitNew.push_back(& rNewHint);
398
399 // pass 1: split the inserted hint into fragments if necessary
400 for ( size_t i = 0; i < Count(); ++i )
401 {
402 SwTextAttr * const pOther = GetSortedByEnd(i);
403
404 if (pOther->IsNesting())
405 {
406 const sal_uInt16 nOtherWhich( pOther->Which() );
407 const sal_Int32 nOtherStart( pOther->GetStart() );
408 const sal_Int32 nOtherEnd ( *pOther->GetEnd() );
409 if (isOverlap(nNewStart, nNewEnd, nOtherStart, nOtherEnd ))
410 {
411 switch (splitPolicy(nNewWhich, nOtherWhich))
412 {
413 case FAIL:
414 SAL_INFO("sw.core", "cannot insert hint: overlap");
415 for (const auto& aSplit : SplitNew)
416 TextAttrDelete(rNode.GetDoc(), aSplit);
417 return false;
418 case SPLIT_NEW:
419 lcl_DoSplitNew(SplitNew, rNode, nNewStart,
420 nOtherStart, nOtherEnd, pOther->HasDummyChar());
421 break;
422 case SPLIT_OTHER:
423 OverlappingExisting.push_back(
424 static_txtattr_cast<SwTextAttrNesting*>(pOther));
425 break;
426 default:
427 assert(!"bad code monkey");
428 break;
429 }
430 }
431 else if (isNestedAny(nNewStart, nNewEnd, nOtherStart, nOtherEnd))
432 {
433 if (!bNewSelfNestable && (nNewWhich == nOtherWhich))
434 {
435 // ruby and hyperlink: if there is nesting, _overwrite_
436 OverwrittenExisting.push_back(
437 static_txtattr_cast<SwTextAttrNesting*>(pOther));
438 }
439 else if ((nNewStart == nOtherStart) && pOther->HasDummyChar())
440 {
441 if (rNewHint.HasDummyChar())
442 {
443 assert(!"ERROR: inserting duplicate CH_TXTATR hint");
444 return false;
445 } else if (nNewEnd < nOtherEnd) {
446 // other has dummy char, new is inside other, but
447 // new contains the other's dummy char?
448 // should be corrected because it may lead to problems
449 // in SwXMeta::createEnumeration
450 // SplitNew is sorted, so this is the first split
451 assert(SplitNew.front()->GetStart() == nNewStart);
452 SplitNew.front()->SetStart(nNewStart + 1);
453 }
454 }
455 }
456 }
457 }
458
459 // pass 1b: tragically need to check for fieldmarks here too
460 for (auto iter = SplitNew.begin(); iter != SplitNew.end(); ++iter)
461 {
462 SwPaM const temp(rNode, (*iter)->GetStart(), rNode, *(*iter)->GetEnd());
463 std::vector<std::pair<SwNodeOffset, sal_Int32>> Breaks;
464 sw::CalcBreaks(Breaks, temp, true);
465 if (!Breaks.empty())
466 {
467 if (!isSplittable(nNewWhich))
468 {
469 SAL_INFO("sw.core", "cannot insert hint: fieldmark overlap");
470 assert(SplitNew.size() == 1);
471 TextAttrDelete(rNode.GetDoc(), &rNewHint);
472 return false;
473 }
474 else
475 {
476 for (auto const& rPos : Breaks)
477 {
478 assert(rPos.first == rNode.GetIndex());
479 iter = lcl_DoSplitImpl(SplitNew, rNode, iter,
480 rPos.second, true, true);
481 }
482 }
483 }
484 }
485
486 assert((isSplittable(nNewWhich) || SplitNew.size() == 1) &&
487 "splitting the unsplittable ???");
488
489 // pass 2: split existing hints that overlap/nest with new hint
490 // do not iterate over hints array, but over remembered set of overlapping
491 // hints, to keep things simple w.r.t. insertion/removal
492 // N.B: if there is a hint that splits the inserted hint, then
493 // that hint would also have already split any hint in OverlappingExisting
494 // so any hint in OverlappingExisting can be split at most by one hint
495 // in SplitNew, or even not at all (this is not true for existing hints
496 // that go _around_ new hint, which is the reason d'^etre for pass 4)
497 for (auto& rpOther : OverlappingExisting)
498 {
499 const sal_Int32 nOtherStart( rpOther->GetStart() );
500 const sal_Int32 nOtherEnd ( *rpOther->GetEnd() );
501
502 for (const auto& rpNew : SplitNew)
503 {
504 const sal_Int32 nSplitNewStart( rpNew->GetStart() );
505 const sal_Int32 nSplitNewEnd ( *rpNew->GetEnd() );
506 // 4 cases: within, around, overlap l, overlap r, (OTHER: no action)
507 const bool bRemoveOverlap(
508 !bNewSelfNestable && (nNewWhich == rpOther->Which()) );
509
510 switch (ComparePosition(nSplitNewStart, nSplitNewEnd,
511 nOtherStart, nOtherEnd))
512 {
514 {
515 assert(!bRemoveOverlap &&
516 "this one should be in OverwrittenExisting?");
517 }
518 break;
521 {
522 assert(!"existing hint inside new hint: why?");
523 }
524 break;
526 {
527 Delete( rpOther ); // this also does NoteInHistory!
528 rpOther->SetStart(nSplitNewEnd);
529 InsertNesting( *rpOther );
530 if (!bRemoveOverlap)
531 {
532 if ( MAX_HINTS <= Count() )
533 {
534 SAL_INFO("sw.core", "hints array full :-(");
535 return false;
536 }
537 SwTextAttrNesting * const pOtherLeft(
538 MakeTextAttrNesting( rNode, *rpOther,
539 nOtherStart, nSplitNewEnd ) );
540 InsertNesting( *pOtherLeft );
541 }
542 }
543 break;
545 {
546 Delete( rpOther ); // this also does NoteInHistory!
547 rpOther->SetEnd(nSplitNewStart);
548 InsertNesting( *rpOther );
549 if (!bRemoveOverlap)
550 {
551 if ( MAX_HINTS <= Count() )
552 {
553 SAL_INFO("sw.core", "hints array full :-(");
554 return false;
555 }
556 SwTextAttrNesting * const pOtherRight(
557 MakeTextAttrNesting( rNode, *rpOther,
558 nSplitNewStart, nOtherEnd ) );
559 InsertNesting( *pOtherRight );
560 }
561 }
562 break;
563 default:
564 break; // overlap resolved by splitting new: nothing to do
565 }
566 }
567 }
568
569 if ( MAX_HINTS <= Count() || MAX_HINTS - Count() <= SplitNew.size() )
570 {
571 SAL_INFO("sw.core", "hints array full :-(");
572 return false;
573 }
574
575 // pass 3: insert new hints
576 for (const auto& rpHint : SplitNew)
577 {
578 InsertNesting(*rpHint);
579 }
580
581 // pass 4: handle overwritten hints
582 // RES_TXTATR_INETFMT and RES_TXTATR_CJK_RUBY should displace attributes
583 // of the same kind.
584 for (auto& rpOther : OverwrittenExisting)
585 {
586 const sal_Int32 nOtherStart( rpOther->GetStart() );
587 const sal_Int32 nOtherEnd ( *rpOther->GetEnd() );
588
589 // overwritten portion is given by start/end of inserted hint
590 if ((nNewStart <= nOtherStart) && (nOtherEnd <= nNewEnd))
591 {
592 Delete(rpOther);
593 rNode.DestroyAttr( rpOther );
594 }
595 else
596 {
597 assert((nOtherStart < nNewStart) || (nNewEnd < nOtherEnd));
598 // scenario: there is a RUBY, and contained within that a META;
599 // now a RUBY is inserted within the META => the existing RUBY is split:
600 // here it is not possible to simply insert the left/right fragment
601 // of the existing RUBY because they <em>overlap</em> with the META!
602 Delete( rpOther ); // this also does NoteInHistory!
603 if (nNewEnd < nOtherEnd)
604 {
605 SwTextAttrNesting * const pOtherRight(
607 rNode, *rpOther, nNewEnd, nOtherEnd ) );
608 bool const bSuccess( TryInsertNesting(rNode, *pOtherRight) );
609 SAL_WARN_IF(!bSuccess, "sw.core", "recursive call 1 failed?");
610 }
611 if (nOtherStart < nNewStart)
612 {
613 rpOther->SetEnd(nNewStart);
614 bool const bSuccess( TryInsertNesting(rNode, *rpOther) );
615 SAL_WARN_IF(!bSuccess, "sw.core", "recursive call 2 failed?");
616 }
617 else
618 {
619 rNode.DestroyAttr(rpOther);
620 }
621 }
622 }
623
624 return true;
625}
626
627// This function takes care for the following text attribute:
628// RES_TXTATR_CHARFMT, RES_TXTATR_AUTOFMT
629// These attributes have to be handled in a special way (Portion building).
630
631// The new attribute will be split by any existing RES_TXTATR_AUTOFMT or
632// RES_TXTATR_CHARFMT. The new attribute itself will
633// split any existing RES_TXTATR_AUTOFMT or RES_TXTATR_CHARFMT.
634
636 const SetAttrMode nMode )
637{
638 const sal_uInt16 nWhich = rNewHint.Which();
639
640 const sal_Int32 nThisStart = rNewHint.GetStart();
641 const sal_Int32 nThisEnd = *rNewHint.GetEnd();
642 const bool bNoLengthAttribute = nThisStart == nThisEnd;
643
644 std::vector<SwTextAttr*> aInsDelHints;
645
646 assert( RES_TXTATR_CHARFMT == rNewHint.Which() ||
647 RES_TXTATR_AUTOFMT == rNewHint.Which() );
648
649 // 2. Find the hints which cover the start and end position
650 // of the new hint. These hints have to be split into two portions:
651
652 if ( !bNoLengthAttribute ) // nothing to do for no length attributes
653 {
654 for ( size_t i = 0; i < Count(); ++i )
655 {
656 // we're modifying stuff here which affects the sorting, and we
657 // don't want it changing underneath us
659
660 if ( RES_TXTATR_CHARFMT != pOther->Which() &&
661 RES_TXTATR_AUTOFMT != pOther->Which() )
662 continue;
663
664 sal_Int32 nOtherStart = pOther->GetStart();
665 const sal_Int32 nOtherEnd = *pOther->GetEnd();
666
667 // Check if start of new attribute overlaps with pOther:
668 // Split pOther if necessary:
669 if ( nOtherStart < nThisStart && nThisStart < nOtherEnd )
670 {
671 SwTextAttr* pNewAttr = MakeTextAttr( rNode.GetDoc(),
672 pOther->GetAttr(), nOtherStart, nThisStart );
673 if ( RES_TXTATR_CHARFMT == pOther->Which() )
674 {
675 static_txtattr_cast<SwTextCharFormat*>(pNewAttr)->SetSortNumber(
676 static_txtattr_cast<SwTextCharFormat*>(pOther)->GetSortNumber() );
677 }
678 aInsDelHints.push_back( pNewAttr );
679
680 NoteInHistory( pOther );
681 pOther->SetStart(nThisStart);
682 NoteInHistory( pOther, true );
683
684 nOtherStart = nThisStart;
685 }
686
687 // Check if end of new attribute overlaps with pOther:
688 // Split pOther if necessary:
689 if ( nOtherStart < nThisEnd && nThisEnd < nOtherEnd )
690 {
691 SwTextAttr* pNewAttr = MakeTextAttr( rNode.GetDoc(),
692 pOther->GetAttr(), nOtherStart, nThisEnd );
693 if ( RES_TXTATR_CHARFMT == pOther->Which() )
694 {
695 static_txtattr_cast<SwTextCharFormat*>(pNewAttr)->SetSortNumber(
696 static_txtattr_cast<SwTextCharFormat*>(pOther)->GetSortNumber());
697 }
698 aInsDelHints.push_back( pNewAttr );
699
700 NoteInHistory( pOther );
701 pOther->SetStart(nThisEnd);
702 NoteInHistory( pOther, true );
703 }
704 }
705
706 // Insert the newly created attributes:
707 for ( const auto& rpHint : aInsDelHints )
708 {
709 Insert( rpHint );
710 NoteInHistory( rpHint, true );
711 }
712 }
713
714#ifdef DBG_UTIL
715 if( !rNode.GetDoc().IsInReading() )
716 CHECK_NOTMERGED; // ignore flags not set properly yet, don't check them
717#endif
718
719 // 4. Split rNewHint into 1 ... n new hints:
720
722 aBounds.insert( nThisStart );
723 aBounds.insert( nThisEnd );
724
725 if ( !bNoLengthAttribute ) // nothing to do for no length attributes
726 {
727 for ( size_t i = 0; i < Count(); ++i )
728 {
729 const SwTextAttr* pOther = Get(i);
730
731 if ( RES_TXTATR_CHARFMT != pOther->Which() &&
732 RES_TXTATR_AUTOFMT != pOther->Which() )
733 continue;
734
735 const sal_Int32 nOtherStart = pOther->GetStart();
736 const sal_Int32 nOtherEnd = *pOther->End();
737
738 if (nThisStart <= nOtherStart && nOtherStart <= nThisEnd)
739 aBounds.insert( nOtherStart );
740 if (nThisStart <= nOtherEnd && nOtherEnd <= nThisEnd)
741 aBounds.insert( nOtherEnd );
742 }
743 }
744
745 auto aStartIter = aBounds.lower_bound( nThisStart );
746 auto aEndIter = aBounds.upper_bound( nThisEnd );
747 sal_Int32 nPorStart = *aStartIter;
748 ++aStartIter;
749 bool bDestroyHint = true;
750
751 // Insert the 1...n new parts of the new attribute:
752
753 while ( aStartIter != aEndIter || bNoLengthAttribute )
754 {
755 OSL_ENSURE( bNoLengthAttribute || nPorStart < *aStartIter, "AUTOSTYLES: BuildPortion trouble" );
756
757 const sal_Int32 nPorEnd = bNoLengthAttribute ? nPorStart : *aStartIter;
758 aInsDelHints.clear();
759
760 // Get all hints that are in [nPorStart, nPorEnd[:
761 for ( size_t i = 0; i < Count(); ++i )
762 {
763 // we get called from TryInsertHint, which changes ordering
765
766 if ( RES_TXTATR_CHARFMT != pOther->Which() &&
767 RES_TXTATR_AUTOFMT != pOther->Which() )
768 continue;
769
770 const sal_Int32 nOtherStart = pOther->GetStart();
771
772 if ( nOtherStart > nPorStart )
773 break;
774
775 if ( pOther->GetEnd() && *pOther->GetEnd() == nPorEnd && nOtherStart == nPorStart )
776 {
777 OSL_ENSURE( *pOther->GetEnd() == nPorEnd, "AUTOSTYLES: BuildPortion trouble" );
778 aInsDelHints.push_back( pOther );
779 }
780 }
781
782 SwTextAttr* pNewAttr = nullptr;
783 if ( RES_TXTATR_CHARFMT == nWhich )
784 {
785 // pNewHint can be inserted after calculating the sort value.
786 // This should ensure, that pNewHint comes behind the already present
787 // character style
788 sal_uInt16 nCharStyleCount = 0;
789 for ( const auto& rpHint : aInsDelHints )
790 {
791 if ( RES_TXTATR_CHARFMT == rpHint->Which() )
792 {
793 // #i74589#
794 const SwFormatCharFormat& rOtherCharFormat = rpHint->GetCharFormat();
795 const SwFormatCharFormat& rThisCharFormat = rNewHint.GetCharFormat();
796 const bool bSameCharFormat = rOtherCharFormat.GetCharFormat() == rThisCharFormat.GetCharFormat();
797
798 // #i90311#
799 // Do not remove existing character format hint during XML import
800 if ( !rNode.GetDoc().IsInXMLImport() &&
801 ( !( SetAttrMode::DONTREPLACE & nMode ) ||
802 bNoLengthAttribute ||
803 bSameCharFormat ) )
804 {
805 // Remove old hint
806 Delete( rpHint );
807 rNode.DestroyAttr( rpHint );
808 }
809 else
810 ++nCharStyleCount;
811 }
812 else
813 {
814 // remove all attributes from auto styles, which are explicitly set in
815 // the new character format:
816 OSL_ENSURE( RES_TXTATR_AUTOFMT == rpHint->Which(), "AUTOSTYLES - Misc trouble" );
817 SwTextAttr* pOther = rpHint;
818 const std::shared_ptr<SfxItemSet> & pOldStyle = static_cast<const SwFormatAutoFormat&>(pOther->GetAttr()).GetStyleHandle();
819
820 // For each attribute in the automatic style check if it
821 // is also set the new character style:
822 SfxItemSet aNewSet( *pOldStyle->GetPool(),
824 SfxItemIter aItemIter( *pOldStyle );
825 const SfxPoolItem* pItem = aItemIter.GetCurItem();
826 do
827 {
828 if ( !CharFormat::IsItemIncluded( pItem->Which(), &rNewHint ) )
829 {
830 aNewSet.Put( *pItem );
831 }
832
833 pItem = aItemIter.NextItem();
834 } while (pItem);
835
836 // Remove old hint
837 Delete( pOther );
838 rNode.DestroyAttr( pOther );
839
840 // Create new AutoStyle
841 if ( aNewSet.Count() )
842 {
843 pNewAttr = MakeTextAttr( rNode.GetDoc(),
844 aNewSet, nPorStart, nPorEnd );
845 Insert( pNewAttr );
846 NoteInHistory( pNewAttr, true );
847 }
848 }
849 }
850
851 // If there is no current hint and start and end of rNewHint
852 // is ok, we do not need to create a new txtattr.
853 if ( nPorStart == nThisStart &&
854 nPorEnd == nThisEnd &&
855 !nCharStyleCount )
856 {
857 pNewAttr = &rNewHint;
858 bDestroyHint = false;
859 }
860 else
861 {
862 pNewAttr = MakeTextAttr( rNode.GetDoc(), rNewHint.GetAttr(),
863 nPorStart, nPorEnd );
864 static_txtattr_cast<SwTextCharFormat*>(pNewAttr)->SetSortNumber(nCharStyleCount);
865 }
866 }
867 else
868 {
869 // Find the current autostyle. Mix attributes if necessary.
870 SwTextAttr* pCurrentAutoStyle = nullptr;
871 SwTextAttr* pCurrentCharFormat = nullptr;
872 for ( const auto& rpHint : aInsDelHints )
873 {
874 if ( RES_TXTATR_AUTOFMT == rpHint->Which() )
875 pCurrentAutoStyle = rpHint;
876 else if ( RES_TXTATR_CHARFMT == rpHint->Which() )
877 pCurrentCharFormat = rpHint;
878 }
879
880 std::shared_ptr<SfxItemSet> pNewStyle = static_cast<const SwFormatAutoFormat&>(rNewHint.GetAttr()).GetStyleHandle();
881 if ( pCurrentAutoStyle )
882 {
883 const std::shared_ptr<SfxItemSet> & pCurrentStyle = static_cast<const SwFormatAutoFormat&>(pCurrentAutoStyle->GetAttr()).GetStyleHandle();
884
885 // Merge attributes
886 SfxItemSet aNewSet( *pCurrentStyle );
887 aNewSet.Put( *pNewStyle );
888
889 // #i75750# Remove attributes already set at whole paragraph
890 // #i81764# This should not be applied for no length attributes!!! <--
891 if ( !bNoLengthAttribute && rNode.HasSwAttrSet() && aNewSet.Count() )
892 {
893 SfxItemIter aIter2( aNewSet );
894 const SfxPoolItem* pItem = aIter2.GetCurItem();
895 const SfxItemSet& rWholeParaAttrSet = rNode.GetSwAttrSet();
896
897 do
898 {
899 const SfxPoolItem* pTmpItem = nullptr;
900 if ( SfxItemState::SET == rWholeParaAttrSet.GetItemState( pItem->Which(), false, &pTmpItem ) &&
901 pTmpItem == pItem )
902 {
903 // Do not clear item if the attribute is set in a character format:
904 if ( !pCurrentCharFormat || nullptr == CharFormat::GetItem( *pCurrentCharFormat, pItem->Which() ) )
905 aIter2.ClearItem();
906 }
907 }
908 while ((pItem = aIter2.NextItem()));
909 }
910
911 // Remove old hint
912 Delete( pCurrentAutoStyle );
913 rNode.DestroyAttr( pCurrentAutoStyle );
914
915 // Create new AutoStyle
916 if ( aNewSet.Count() )
917 pNewAttr = MakeTextAttr( rNode.GetDoc(), aNewSet,
918 nPorStart, nPorEnd );
919 }
920 else
921 {
922 // Remove any attributes which are already set at the whole paragraph:
923 bool bOptimizeAllowed = true;
924
925 // #i75750# Remove attributes already set at whole paragraph
926 // #i81764# This should not be applied for no length attributes!!! <--
927 if ( !bNoLengthAttribute && rNode.HasSwAttrSet() && pNewStyle->Count() )
928 {
929 std::unique_ptr<SfxItemSet> pNewSet;
930
931 SfxItemIter aIter2( *pNewStyle );
932 const SfxPoolItem* pItem = aIter2.GetCurItem();
933 const SfxItemSet& rWholeParaAttrSet = rNode.GetSwAttrSet();
934
935 do
936 {
937 const SfxPoolItem* pTmpItem = nullptr;
938 if ( SfxItemState::SET == rWholeParaAttrSet.GetItemState( pItem->Which(), false, &pTmpItem ) &&
939 pTmpItem == pItem )
940 {
941 // Do not clear item if the attribute is set in a character format:
942 if ( !pCurrentCharFormat || nullptr == CharFormat::GetItem( *pCurrentCharFormat, pItem->Which() ) )
943 {
944 if ( !pNewSet )
945 pNewSet = pNewStyle->Clone();
946 pNewSet->ClearItem( pItem->Which() );
947 }
948 }
949 }
950 while ((pItem = aIter2.NextItem()));
951
952 if ( pNewSet )
953 {
954 bOptimizeAllowed = false;
955 if ( pNewSet->Count() )
957 else
958 pNewStyle.reset();
959 }
960 }
961
962 // Create new AutoStyle
963 // If there is no current hint and start and end of rNewHint
964 // is ok, we do not need to create a new txtattr.
965 if ( bOptimizeAllowed &&
966 nPorStart == nThisStart &&
967 nPorEnd == nThisEnd )
968 {
969 pNewAttr = &rNewHint;
970 bDestroyHint = false;
971 }
972 else if ( pNewStyle )
973 {
974 pNewAttr = MakeTextAttr( rNode.GetDoc(), *pNewStyle,
975 nPorStart, nPorEnd );
976 }
977 }
978 }
979
980 if ( pNewAttr )
981 {
982 Insert( pNewAttr );
983// if ( bDestroyHint )
984 NoteInHistory( pNewAttr, true );
985 }
986
987 if ( !bNoLengthAttribute )
988 {
989 nPorStart = *aStartIter;
990 ++aStartIter;
991 }
992 else
993 break;
994 }
995
996 if ( bDestroyHint )
997 rNode.DestroyAttr( &rNewHint );
998}
999
1001{
1002 // this is intended _only_ for special-purpose redline attributes!
1003 switch (rAttr.Which())
1004 {
1005 case RES_CHRATR_COLOR:
1006 case RES_CHRATR_WEIGHT:
1009 case RES_CHRATR_POSTURE:
1014 case RES_CHRATR_CASEMAP:
1016 break;
1017 default:
1018 assert(!"unsupported redline attribute");
1019 break;
1020 }
1021
1022 // Put new attribute into pool
1023 // FIXME: this const_cast is evil!
1024 SfxPoolItem& rNew =
1025 const_cast<SfxPoolItem&>( rDoc.GetAttrPool().Put( rAttr ) );
1026 return new SwTextAttrEnd( rNew, 0, 0 );
1027}
1028
1029// create new text attribute
1031 SwDoc & rDoc,
1032 SfxPoolItem& rAttr,
1033 sal_Int32 const nStt,
1034 sal_Int32 const nEnd,
1035 CopyOrNewType const bIsCopy,
1036 SwTextNode *const pTextNode )
1037{
1038 if ( isCHRATR(rAttr.Which()) )
1039 {
1040 // Somebody wants to build a SwTextAttr for a character attribute.
1041 // Sorry, this is not allowed any longer.
1042 // You'll get a brand new autostyle attribute:
1044 aItemSet.Put( rAttr );
1045 return MakeTextAttr( rDoc, aItemSet, nStt, nEnd );
1046 }
1047 else if ( RES_TXTATR_AUTOFMT == rAttr.Which() &&
1048 static_cast<const SwFormatAutoFormat&>(rAttr).GetStyleHandle()->
1049 GetPool() != &rDoc.GetAttrPool() )
1050 {
1051 // If the attribute is an auto-style which refers to a pool that is
1052 // different from rDoc's pool, we have to correct this:
1053 const std::shared_ptr<SfxItemSet> & pAutoStyle = static_cast<const SwFormatAutoFormat&>(rAttr).GetStyleHandle();
1054 std::unique_ptr<const SfxItemSet> pNewSet(
1055 pAutoStyle->SfxItemSet::Clone( true, &rDoc.GetAttrPool() ));
1056 SwTextAttr* pNew = MakeTextAttr( rDoc, *pNewSet, nStt, nEnd );
1057 return pNew;
1058 }
1059
1060 // Put new attribute into pool
1061 // FIXME: this const_cast is evil!
1062 SfxPoolItem& rNew =
1063 const_cast<SfxPoolItem&>( rDoc.GetAttrPool().Put( rAttr ) );
1064
1065 SwTextAttr* pNew = nullptr;
1066 switch( rNew.Which() )
1067 {
1068 case RES_TXTATR_CHARFMT:
1069 {
1070 SwFormatCharFormat &rFormatCharFormat = static_cast<SwFormatCharFormat&>(rNew);
1071 if( !rFormatCharFormat.GetCharFormat() )
1072 {
1073 rFormatCharFormat.SetCharFormat( rDoc.GetDfltCharFormat() );
1074 }
1075
1076 pNew = new SwTextCharFormat( rFormatCharFormat, nStt, nEnd );
1077 }
1078 break;
1079 case RES_TXTATR_INETFMT:
1080 pNew = new SwTextINetFormat( static_cast<SwFormatINetFormat&>(rNew), nStt, nEnd );
1081 break;
1082
1083 case RES_TXTATR_FIELD:
1084 pNew = new SwTextField( static_cast<SwFormatField &>(rNew), nStt,
1085 rDoc.IsClipBoard() );
1086 break;
1087
1089 {
1090 pNew = new SwTextAnnotationField( static_cast<SwFormatField &>(rNew), nStt, rDoc.IsClipBoard() );
1091 if (bIsCopy == CopyOrNewType::Copy)
1092 {
1093 // On copy of the annotation field do not keep the annotated text range by removing
1094 // the relation to its annotation mark (relation established via annotation field's name).
1095 // If the annotation mark is also copied, the relation and thus the annotated text range will be reestablished,
1096 // when the annotation mark is created and inserted into the document.
1097 auto& pField = const_cast<SwPostItField&>(dynamic_cast<const SwPostItField&>(*(pNew->GetFormatField().GetField())));
1098 pField.SetName(OUString());
1099 pField.SetPostItId();
1100 }
1101 }
1102 break;
1103
1105 pNew = new SwTextInputField( static_cast<SwFormatField &>(rNew), nStt, nEnd,
1106 rDoc.IsClipBoard() );
1107 break;
1108
1109 case RES_TXTATR_FLYCNT:
1110 {
1111 // finally, copy the frame format (with content)
1112 pNew = new SwTextFlyCnt( static_cast<SwFormatFlyCnt&>(rNew), nStt );
1113 if ( static_cast<const SwFormatFlyCnt &>(rAttr).GetTextFlyCnt() )
1114 {
1115 // if it has an existing attr then the format must be copied
1116 static_cast<SwTextFlyCnt *>(pNew)->CopyFlyFormat( rDoc );
1117 }
1118 }
1119 break;
1120 case RES_TXTATR_FTN:
1121 pNew = new SwTextFootnote( static_cast<SwFormatFootnote&>(rNew), nStt );
1122 // copy note's SeqNo
1123 if( static_cast<SwFormatFootnote&>(rAttr).GetTextFootnote() )
1124 static_cast<SwTextFootnote*>(pNew)->SetSeqNo( static_cast<SwFormatFootnote&>(rAttr).GetTextFootnote()->GetSeqRefNo() );
1125 break;
1126 case RES_TXTATR_REFMARK:
1127 pNew = nStt == nEnd
1128 ? new SwTextRefMark( static_cast<SwFormatRefMark&>(rNew), nStt )
1129 : new SwTextRefMark( static_cast<SwFormatRefMark&>(rNew), nStt, &nEnd );
1130 break;
1131 case RES_TXTATR_TOXMARK:
1132 {
1133 SwTOXMark& rMark = static_cast<SwTOXMark&>(rNew);
1134
1135 // tdf#98868 if the SwTOXType is from a different document that the
1136 // target, re-register the TOXMark against a matching SwTOXType from
1137 // the target document instead
1138 const SwTOXType* pTOXType = rMark.GetTOXType();
1139 if (pTOXType && &pTOXType->GetDoc() != &rDoc)
1140 {
1141 SwTOXType* pToxType = SwHistorySetTOXMark::GetSwTOXType(rDoc, pTOXType->GetType(),
1142 pTOXType->GetTypeName());
1143 rMark.RegisterToTOXType(*pToxType);
1144 }
1145
1146 pNew = new SwTextTOXMark(rMark, nStt, &nEnd);
1147 break;
1148 }
1150 pNew = new SwTextRuby( static_cast<SwFormatRuby&>(rNew), nStt, nEnd );
1151 break;
1152 case RES_TXTATR_META:
1154 pNew = SwTextMeta::CreateTextMeta( rDoc.GetMetaFieldManager(), pTextNode,
1155 static_cast<SwFormatMeta&>(rNew), nStt, nEnd, bIsCopy == CopyOrNewType::Copy );
1156 break;
1158 pNew = new SwTextLineBreak(static_cast<SwFormatLineBreak&>(rNew), nStt);
1159 break;
1162 pTextNode, static_cast<SwFormatContentControl&>(rNew), nStt, nEnd,
1163 bIsCopy == CopyOrNewType::Copy);
1164 break;
1165 default:
1166 assert(RES_TXTATR_AUTOFMT == rNew.Which());
1167 pNew = new SwTextAttrEnd( rNew, nStt, nEnd );
1168 break;
1169 }
1170
1171 return pNew;
1172}
1173
1175 sal_Int32 nStt, sal_Int32 nEnd )
1176{
1177 IStyleAccess& rStyleAccess = rDoc.GetIStyleAccess();
1178 const std::shared_ptr<SfxItemSet> pAutoStyle = rStyleAccess.getAutomaticStyle( rSet, IStyleAccess::AUTO_STYLE_CHAR );
1179 SwFormatAutoFormat aNewAutoFormat;
1180 aNewAutoFormat.SetStyleHandle( pAutoStyle );
1181 SwTextAttr* pNew = MakeTextAttr( rDoc, aNewAutoFormat, nStt, nEnd );
1182 return pNew;
1183}
1184
1185// delete the text attribute and unregister its item at the pool
1187{
1188 if( !pAttr )
1189 return;
1190
1191 // some things need to be done before deleting the formatting attribute
1192 SwDoc& rDoc = GetDoc();
1193 switch( pAttr->Which() )
1194 {
1195 case RES_TXTATR_FLYCNT:
1196 {
1197 SwFrameFormat* pFormat = pAttr->GetFlyCnt().GetFrameFormat();
1198 if( pFormat ) // set to 0 by Undo?
1199 rDoc.getIDocumentLayoutAccess().DelLayoutFormat( pFormat );
1200 }
1201 break;
1202
1203 case RES_CHRATR_HIDDEN:
1205 break;
1206
1207 case RES_TXTATR_FTN:
1208 static_cast<SwTextFootnote*>(pAttr)->SetStartNode( nullptr );
1209 static_cast<SwFormatFootnote&>(pAttr->GetAttr()).InvalidateFootnote();
1210 break;
1211
1212 case RES_TXTATR_FIELD:
1215 if( !rDoc.IsInDtor() )
1216 {
1217 SwTextField *const pTextField(static_txtattr_cast<SwTextField*>(pAttr));
1218 SwFieldType* pFieldType = pAttr->GetFormatField().GetField()->GetTyp();
1219
1220 if (SwFieldIds::Dde != pFieldType->Which()
1221 && !pTextField->GetpTextNode())
1222 {
1223 break; // was not yet inserted
1224 }
1225
1226 //JP 06-08-95: DDE-fields are an exception
1227 assert(SwFieldIds::Dde == pFieldType->Which() ||
1228 this == pTextField->GetpTextNode());
1229
1230 // certain fields must update the SwDoc's calculation flags
1231
1232 // Certain fields (like HiddenParaField) must trigger recalculation of visible flag
1233 if (GetDoc().FieldCanHideParaWeight(pFieldType->Which()))
1235
1236 switch( pFieldType->Which() )
1237 {
1240 case SwFieldIds::GetExp:
1242 case SwFieldIds::SetExp:
1246 if( !rDoc.getIDocumentFieldsAccess().IsNewFieldLst() && GetNodes().IsDocNodes() )
1247 rDoc.getIDocumentFieldsAccess().InsDelFieldInFieldLst(false, *pTextField);
1248 break;
1249 case SwFieldIds::Dde:
1250 if (GetNodes().IsDocNodes() && pTextField->GetpTextNode())
1251 static_cast<SwDDEFieldType*>(pFieldType)->DecRefCnt();
1252 break;
1253 case SwFieldIds::Postit:
1254 {
1255 const_cast<SwFormatField&>(pAttr->GetFormatField()).Broadcast(
1257 break;
1258 }
1259 default: break;
1260 }
1261 }
1262 static_cast<SwFormatField&>(pAttr->GetAttr()).InvalidateField();
1263 break;
1264
1265 case RES_TXTATR_TOXMARK:
1266 static_cast<SwTOXMark&>(pAttr->GetAttr()).InvalidateTOXMark();
1267 break;
1268
1269 case RES_TXTATR_REFMARK:
1270 static_cast<SwFormatRefMark&>(pAttr->GetAttr()).InvalidateRefMark();
1271 break;
1272
1273 case RES_TXTATR_META:
1275 {
1276 auto pTextMeta = static_txtattr_cast<SwTextMeta*>(pAttr);
1277 SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(pTextMeta->GetAttr()) );
1278 if (::sw::Meta* pMeta = rFormatMeta.GetMeta())
1279 {
1280 if (SwDocShell* pDocSh = rDoc.GetDocShell())
1281 {
1282 static constexpr OUStringLiteral metaNS(u"urn:bails");
1283 const css::uno::Reference<css::rdf::XResource> xSubject = pMeta->MakeUnoObject();
1284 uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
1285 SwRDFHelper::clearStatements(xModel, metaNS, xSubject);
1286 }
1287 }
1288
1289 static_txtattr_cast<SwTextMeta*>(pAttr)->ChgTextNode(nullptr);
1290 }
1291 break;
1293 {
1294 static_txtattr_cast<SwTextContentControl*>(pAttr)->ChgTextNode(nullptr);
1295 break;
1296 }
1297
1298 default:
1299 break;
1300 }
1301
1302 SwTextAttr::Destroy( pAttr, rDoc.GetAttrPool() );
1303}
1304
1306 SfxPoolItem& rAttr,
1307 const sal_Int32 nStart,
1308 const sal_Int32 nEnd,
1309 const SetAttrMode nMode )
1310{
1311 // character attributes will be inserted as automatic styles:
1312 assert( !isCHRATR(rAttr.Which()) && "AUTOSTYLES - "
1313 "SwTextNode::InsertItem should not be called with character attributes");
1314
1315 SwTextAttr *const pNew =
1317 GetDoc(),
1318 rAttr,
1319 nStart,
1320 nEnd,
1322 this );
1323
1324 if ( pNew )
1325 {
1326 const bool bSuccess( InsertHint( pNew, nMode ) );
1327 // N.B.: also check that the hint is actually in the hints array,
1328 // because hints of certain types may be merged after successful
1329 // insertion, and thus destroyed!
1330 if (!bSuccess || !m_pSwpHints->Contains( pNew ))
1331 {
1332 return nullptr;
1333 }
1334 }
1335
1336 return pNew;
1337}
1338
1339// take ownership of pAttr; if insertion fails, delete pAttr
1340bool SwTextNode::InsertHint( SwTextAttr * const pAttr, const SetAttrMode nMode )
1341{
1342 bool bHiddenPara = false;
1343
1344 assert(pAttr && pAttr->GetStart() <= Len());
1345 assert(!pAttr->GetEnd() || (*pAttr->GetEnd() <= Len()));
1346
1347 // translate from SetAttrMode to InsertMode (for hints with CH_TXTATR)
1348 const SwInsertFlags nInsertFlags =
1354
1355 // need this after TryInsertHint, when pAttr may be deleted
1356 const sal_Int32 nStart( pAttr->GetStart() );
1357 const bool bDummyChar( pAttr->HasDummyChar() );
1358 if (bDummyChar)
1359 {
1360 SetAttrMode nInsMode = nMode;
1361 switch( pAttr->Which() )
1362 {
1363 case RES_TXTATR_FLYCNT:
1364 {
1365 SwTextFlyCnt *pFly = static_cast<SwTextFlyCnt *>(pAttr);
1366 SwFrameFormat* pFormat = pAttr->GetFlyCnt().GetFrameFormat();
1367 if( !(SetAttrMode::NOTXTATRCHR & nInsMode) )
1368 {
1369 // Need to insert char first, because SetAnchor() reads
1370 // GetStart().
1371 //JP 11.05.98: if the anchor is already set correctly,
1372 // fix it after inserting the char, so that clients don't
1373 // have to worry about it.
1374 const SwFormatAnchor* pAnchor = pFormat->GetItemIfSet( RES_ANCHOR, false );
1375
1376 SwContentIndex aIdx( this, pAttr->GetStart() );
1377 const OUString c(GetCharOfTextAttr(*pAttr));
1378 OUString const ins( InsertText(c, aIdx, nInsertFlags) );
1379 if (ins.isEmpty())
1380 {
1381 // do not record deletion of Format!
1382 ::sw::UndoGuard const ug(
1383 pFormat->GetDoc()->GetIDocumentUndoRedo());
1384 DestroyAttr(pAttr);
1385 return false; // text node full :(
1386 }
1387 nInsMode |= SetAttrMode::NOTXTATRCHR;
1388
1389 if (pAnchor &&
1390 (RndStdIds::FLY_AS_CHAR == pAnchor->GetAnchorId()) &&
1391 pAnchor->GetContentAnchor() &&
1392 pAnchor->GetContentAnchor()->GetNode() == *this &&
1393 pAnchor->GetContentAnchor()->nContent == aIdx )
1394 {
1395 --const_cast<SwContentIndex&>(
1396 pAnchor->GetContentAnchor()->nContent);
1397 }
1398 }
1399 pFly->SetAnchor( this );
1400
1401 // format pointer could have changed in SetAnchor,
1402 // when copying to other docs!
1403 pFormat = pAttr->GetFlyCnt().GetFrameFormat();
1404 SwDoc *pDoc = pFormat->GetDoc();
1405
1406 // OD 26.06.2003 - allow drawing objects in header/footer.
1407 // But don't allow control objects in header/footer
1408 if( RES_DRAWFRMFMT == pFormat->Which() &&
1409 pDoc->IsInHeaderFooter( pFormat->GetAnchor().GetContentAnchor()->GetNode() ) )
1410 {
1411 bool bCheckControlLayer = false;
1412 pFormat->CallSwClientNotify(sw::CheckDrawFrameFormatLayerHint(&bCheckControlLayer));
1413 if( bCheckControlLayer )
1414 {
1415 // This should not be allowed, prevent it here.
1416 // The dtor of the SwTextAttr does not delete the
1417 // char, so delete it explicitly here.
1418 if( SetAttrMode::NOTXTATRCHR & nInsMode )
1419 {
1420 // delete the char from the string
1421 assert(CH_TXTATR_BREAKWORD == m_Text[pAttr->GetStart()]
1422 || CH_TXTATR_INWORD == m_Text[pAttr->GetStart()]);
1423 m_Text = m_Text.replaceAt(pAttr->GetStart(), 1, u"");
1424 // Update SwIndexes
1425 SwContentIndex aTmpIdx( this, pAttr->GetStart() );
1426 Update(aTmpIdx, 1, UpdateMode::Negative);
1427 }
1428 // do not record deletion of Format!
1429 ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
1430 DestroyAttr( pAttr );
1431 return false;
1432 }
1433 }
1434 break;
1435 }
1436
1437 case RES_TXTATR_FTN :
1438 {
1439 // Footnotes: create text node and put it into Inserts-section
1440 SwDoc& rDoc = GetDoc();
1441 SwNodes &rNodes = rDoc.GetNodes();
1442
1443 // check that footnote is inserted into body or redline section
1444 if( StartOfSectionIndex() < rNodes.GetEndOfAutotext().GetIndex() )
1445 {
1446 // This should not be allowed, prevent it here.
1447 // The dtor of the SwTextAttr does not delete the
1448 // char, so delete it explicitly here.
1449 if( SetAttrMode::NOTXTATRCHR & nInsMode )
1450 {
1451 // delete the char from the string
1452 assert(CH_TXTATR_BREAKWORD == m_Text[pAttr->GetStart()]
1453 || CH_TXTATR_INWORD == m_Text[pAttr->GetStart()]);
1454 m_Text = m_Text.replaceAt(pAttr->GetStart(), 1, u"");
1455 // Update SwIndexes
1456 SwContentIndex aTmpIdx( this, pAttr->GetStart() );
1457 Update(aTmpIdx, 1, UpdateMode::Negative);
1458 }
1459 DestroyAttr( pAttr );
1460 return false;
1461 }
1462
1463 // is a new footnote being inserted?
1464 bool bNewFootnote = nullptr == static_cast<SwTextFootnote*>(pAttr)->GetStartNode();
1465 if( bNewFootnote )
1466 {
1467 static_cast<SwTextFootnote*>(pAttr)->MakeNewTextSection( GetNodes() );
1468 SwRegHistory* pHist = GetpSwpHints()
1469 ? GetpSwpHints()->GetHistory() : nullptr;
1470 if( pHist )
1471 pHist->ChangeNodeIndex( GetIndex() );
1472 }
1473 else if ( !GetpSwpHints() || !GetpSwpHints()->IsInSplitNode() )
1474 {
1475 // existing footnote: delete all layout frames of its
1476 // footnote section
1477 SwNodeOffset nSttIdx =
1478 static_cast<SwTextFootnote*>(pAttr)->GetStartNode()->GetIndex();
1479 SwNodeOffset nEndIdx = rNodes[ nSttIdx++ ]->EndOfSectionIndex();
1480 for( ; nSttIdx < nEndIdx; ++nSttIdx )
1481 {
1482 SwContentNode* pCNd = rNodes[ nSttIdx ]->GetContentNode();
1483 if( nullptr != pCNd )
1484 pCNd->DelFrames(nullptr);
1485 else if (SwTableNode *const pTable = rNodes[nSttIdx]->GetTableNode())
1486 {
1487 pTable->DelFrames();
1488 }
1489 }
1490 }
1491
1492 if( !(SetAttrMode::NOTXTATRCHR & nInsMode) )
1493 {
1494 // must insert first, to prevent identical indexes
1495 // that could later prevent insertion into SwDoc's
1496 // footnote array
1497 SwContentIndex aNdIdx( this, pAttr->GetStart() );
1498 const OUString c(GetCharOfTextAttr(*pAttr));
1499 OUString const ins( InsertText(c, aNdIdx, nInsertFlags) );
1500 if (ins.isEmpty())
1501 {
1502 DestroyAttr(pAttr);
1503 return false; // text node full :(
1504 }
1505 nInsMode |= SetAttrMode::NOTXTATRCHR;
1506 }
1507
1508 // insert into SwDoc's footnote index array
1509 SwTextFootnote* pTextFootnote = nullptr;
1510 if( !bNewFootnote )
1511 {
1512 // moving an existing footnote (e.g. SplitNode)
1513 for( size_t n = 0; n < rDoc.GetFootnoteIdxs().size(); ++n )
1514 if( pAttr == rDoc.GetFootnoteIdxs()[n] )
1515 {
1516 // assign new index by removing and re-inserting
1517 pTextFootnote = rDoc.GetFootnoteIdxs()[n];
1518 rDoc.GetFootnoteIdxs().erase( rDoc.GetFootnoteIdxs().begin() + n );
1519 break;
1520 }
1521 // if the Undo set the StartNode, the Index isn't
1522 // in the doc's array yet!
1523 }
1524 if( !pTextFootnote )
1525 pTextFootnote = static_cast<SwTextFootnote*>(pAttr);
1526
1527 // to update the numbers and for sorting, the Node must be set
1528 static_cast<SwTextFootnote*>(pAttr)->ChgTextNode( this );
1529
1530 // do not insert footnote in redline section into footnote array
1531 if( StartOfSectionIndex() > rNodes.GetEndOfRedlines().GetIndex() )
1532 {
1533 const bool bSuccess = rDoc.GetFootnoteIdxs().insert(pTextFootnote).second;
1534 OSL_ENSURE( bSuccess, "FootnoteIdx not inserted." );
1535 }
1536 rDoc.GetFootnoteIdxs().UpdateFootnote( *this );
1537 static_cast<SwTextFootnote*>(pAttr)->SetSeqRefNo();
1538 }
1539 break;
1540
1541 case RES_TXTATR_FIELD:
1542 {
1543 // trigger notification for relevant fields, like HiddenParaFields
1545 pAttr->GetFormatField().GetField()->GetTyp()->Which()))
1546 {
1547 bHiddenPara = true;
1548 }
1549 }
1550 break;
1552 {
1553 static_cast<SwTextLineBreak*>(pAttr)->SetTextNode(this);
1554 }
1555 break;
1556
1557 }
1558 // CH_TXTATR_* are inserted for SwTextHints without EndIndex
1559 // If the caller is SwTextNode::Copy, the char has already been copied,
1560 // and SETATTR_NOTXTATRCHR prevents inserting it again here.
1561 if( !(SetAttrMode::NOTXTATRCHR & nInsMode) )
1562 {
1563 SwContentIndex aIdx( this, pAttr->GetStart() );
1564 OUString const ins( InsertText(OUString(GetCharOfTextAttr(*pAttr)),
1565 aIdx, nInsertFlags) );
1566 if (ins.isEmpty())
1567 {
1568 DestroyAttr(pAttr);
1569 return false; // text node full :(
1570 }
1571
1572 // adjust end of hint to account for inserted CH_TXTATR
1573 const sal_Int32* pEnd(pAttr->GetEnd());
1574 if (pEnd)
1575 {
1576 pAttr->SetEnd(*pEnd + 1);
1577 }
1578
1579 if (pAttr->Which() == RES_TXTATR_CONTENTCONTROL)
1580 {
1581 // Content controls have a dummy character at their end as well.
1582 SwContentIndex aEndIdx(this, *pAttr->GetEnd());
1583 OUString aEnd
1584 = InsertText(OUString(GetCharOfTextAttr(*pAttr)), aEndIdx, nInsertFlags);
1585 if (aEnd.isEmpty())
1586 {
1587 DestroyAttr(pAttr);
1588 return false;
1589 }
1590
1591 pEnd = pAttr->GetEnd();
1592 if (pEnd)
1593 {
1594 pAttr->SetEnd(*pEnd + 1);
1595 }
1596 }
1597 }
1598 }
1599
1600 // handle attributes which provide content
1601 sal_Int32 nEnd = nStart;
1602 bool bInputFieldStartCharInserted = false;
1603 bool bInputFieldEndCharInserted = false;
1604 const bool bHasContent( pAttr->HasContent() );
1605 if ( bHasContent )
1606 {
1607 switch( pAttr->Which() )
1608 {
1610 {
1611 SwTextInputField* pTextInputField = dynamic_cast<SwTextInputField*>(pAttr);
1612 if ( pTextInputField )
1613 {
1614 if( !(SetAttrMode::NOTXTATRCHR & nMode) )
1615 {
1616 SwContentIndex aIdx( this, pAttr->GetStart() );
1617 const OUString aContent = OUStringChar(CH_TXT_ATR_INPUTFIELDSTART)
1618 + pTextInputField->GetFieldContent() + OUStringChar(CH_TXT_ATR_INPUTFIELDEND);
1619 InsertText( aContent, aIdx, nInsertFlags );
1620
1621 const sal_Int32* const pEnd(pAttr->GetEnd());
1622 assert(pEnd != nullptr);
1623 pAttr->SetEnd(*pEnd + aContent.getLength());
1624 nEnd = *pAttr->GetEnd();
1625 }
1626 else
1627 {
1628 // assure that CH_TXT_ATR_INPUTFIELDSTART and CH_TXT_ATR_INPUTFIELDEND are inserted.
1629 if ( m_Text[ pAttr->GetStart() ] != CH_TXT_ATR_INPUTFIELDSTART )
1630 {
1631 SwContentIndex aIdx( this, pAttr->GetStart() );
1632 InsertText( OUString(CH_TXT_ATR_INPUTFIELDSTART), aIdx, nInsertFlags );
1633 bInputFieldStartCharInserted = true;
1634 const sal_Int32* const pEnd(pAttr->GetEnd());
1635 assert(pEnd != nullptr);
1636 pAttr->SetEnd(*pEnd + 1);
1637 nEnd = *pAttr->GetEnd();
1638 }
1639
1640 const sal_Int32* const pEnd(pAttr->GetEnd());
1641 assert(pEnd != nullptr);
1642 if (m_Text[ *pEnd - 1 ] != CH_TXT_ATR_INPUTFIELDEND)
1643 {
1644 SwContentIndex aIdx( this, *pEnd );
1645 InsertText( OUString(CH_TXT_ATR_INPUTFIELDEND), aIdx, nInsertFlags );
1646 bInputFieldEndCharInserted = true;
1647 pAttr->SetEnd(*pEnd + 1);
1648 nEnd = *pAttr->GetEnd();
1649 }
1650 }
1651 }
1652 }
1653 break;
1654 default:
1655 break;
1656 }
1657 }
1658
1660
1661 // handle overlap with an existing InputField
1662 bool bInsertHint = true;
1663 {
1664 const SwTextInputField* pTextInputField = GetOverlappingInputField( *pAttr );
1665 if ( pTextInputField != nullptr )
1666 {
1667 if ( pAttr->End() == nullptr )
1668 {
1669 bInsertHint = false;
1670 DestroyAttr(pAttr);
1671 }
1672 else
1673 {
1674 if ( pAttr->GetStart() > pTextInputField->GetStart() )
1675 {
1676 pAttr->SetStart( pTextInputField->GetStart() );
1677 }
1678 if ( *(pAttr->End()) < *(pTextInputField->End()) )
1679 {
1680 pAttr->SetEnd(*(pTextInputField->End()));
1681 }
1682 }
1683 }
1684 }
1685
1686 if (bInsertHint)
1687 {
1688 // Handle the invariant that a plain text content control has the same character formatting
1689 // for all of its content.
1690 auto* pTextContentControl = static_txtattr_cast<SwTextContentControl*>(
1692 if (pTextContentControl)
1693 {
1694 auto& rFormatContentControl
1695 = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr());
1696 std::shared_ptr<SwContentControl> pContentControl
1697 = rFormatContentControl.GetContentControl();
1698 if (pAttr->End() != nullptr && pContentControl->GetPlainText())
1699 {
1700 if (pAttr->GetStart() > pTextContentControl->GetStart())
1701 {
1702 pAttr->SetStart(pTextContentControl->GetStart());
1703 }
1704 if (*pAttr->End() < *pTextContentControl->End())
1705 {
1706 pAttr->SetEnd(*pTextContentControl->End());
1707 }
1708 }
1709 }
1710 }
1711
1712 const bool bRet = bInsertHint
1713 && m_pSwpHints->TryInsertHint( pAttr, *this, nMode );
1714
1715 if ( !bRet )
1716 {
1717 if ( bDummyChar
1718 && !(SetAttrMode::NOTXTATRCHR & nMode) )
1719 {
1720 // undo insertion of dummy character
1721 // N.B. cannot insert the dummy character after inserting the hint,
1722 // because if the hint has no extent it will be moved in InsertText,
1723 // resulting in infinite recursion
1724 assert((CH_TXTATR_BREAKWORD == m_Text[nStart] ||
1725 CH_TXTATR_INWORD == m_Text[nStart] ));
1726 SwContentIndex aIdx( this, nStart );
1727 EraseText( aIdx, 1 );
1728 }
1729
1730 if ( bHasContent )
1731 {
1732 if ( !(SetAttrMode::NOTXTATRCHR & nMode)
1733 && (nEnd - nStart) > 0 )
1734 {
1735 SwContentIndex aIdx( this, nStart );
1736 EraseText( aIdx, (nEnd - nStart) );
1737 }
1738 else
1739 {
1740 if ( bInputFieldEndCharInserted
1741 && (nEnd - nStart) > 0 )
1742 {
1743 SwContentIndex aIdx( this, nEnd - 1 );
1744 EraseText( aIdx, 1 );
1745 }
1746
1747 if ( bInputFieldStartCharInserted )
1748 {
1749 SwContentIndex aIdx( this, nStart );
1750 EraseText( aIdx, 1 );
1751 }
1752 }
1753 }
1754 }
1755
1756 if ( bHiddenPara )
1757 {
1759 }
1760
1761 return bRet;
1762}
1763
1765{
1766 if ( !HasHints() )
1767 {
1768 OSL_FAIL("DeleteAttribute called, but text node without hints?");
1769 return;
1770 }
1771
1772 if ( pAttr->HasDummyChar() )
1773 {
1774 // copy index!
1775 const SwContentIndex aIdx( this, pAttr->GetStart() );
1776 // erase the CH_TXTATR, which will also delete pAttr
1777 EraseText( aIdx, 1 );
1778 }
1779 else if ( pAttr->HasContent() )
1780 {
1781 const SwContentIndex aIdx( this, pAttr->GetStart() );
1782 assert(pAttr->End() != nullptr);
1783 EraseText( aIdx, *pAttr->End() - pAttr->GetStart() );
1784 }
1785 else
1786 {
1787 // create MsgHint before start/end become invalid
1788 SwUpdateAttr aHint(
1789 pAttr->GetStart(),
1790 *pAttr->GetEnd(),
1791 pAttr->Which());
1792
1793 m_pSwpHints->Delete( pAttr );
1794 SwTextAttr::Destroy( pAttr, GetDoc().GetAttrPool() );
1795 CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aHint));
1796
1798 }
1799}
1800
1801//FIXME: this does NOT respect SORT NUMBER (for CHARFMT)!
1803 const sal_uInt16 nWhich,
1804 const sal_Int32 nStart,
1805 const sal_Int32 nEnd )
1806{
1807 if ( !HasHints() )
1808 return;
1809
1810 for ( size_t nPos = 0; m_pSwpHints && nPos < m_pSwpHints->Count(); ++nPos )
1811 {
1812 SwTextAttr * const pTextHt = m_pSwpHints->Get( nPos );
1813 const sal_Int32 nHintStart = pTextHt->GetStart();
1814 if (nStart < nHintStart)
1815 {
1816 break; // sorted by start
1817 }
1818 else if ( (nStart == nHintStart) && (nWhich == pTextHt->Which()) )
1819 {
1820 if ( nWhich == RES_CHRATR_HIDDEN )
1821 {
1822 assert(!"hey, that's a CHRATR! how did that get in?");
1824 }
1825 else if ( nWhich == RES_TXTATR_CHARFMT )
1826 {
1827 // Check if character format contains hidden attribute:
1828 const SwCharFormat* pFormat = pTextHt->GetCharFormat().GetCharFormat();
1829 if ( SfxItemState::SET == pFormat->GetItemState( RES_CHRATR_HIDDEN ) )
1831 }
1832 // #i75430# Recalc hidden flags if necessary
1833 else if ( nWhich == RES_TXTATR_AUTOFMT )
1834 {
1835 // Check if auto style contains hidden attribute:
1836 const SfxPoolItem* pHiddenItem = CharFormat::GetItem( *pTextHt, RES_CHRATR_HIDDEN );
1837 if ( pHiddenItem )
1839 // for auto styles DeleteAttributes is only called from Undo
1840 // so it shouldn't need to care about ignore start/end flags
1841 }
1842
1843 sal_Int32 const * const pEndIdx = pTextHt->GetEnd();
1844
1845 if ( pTextHt->HasDummyChar() )
1846 {
1847 // copy index!
1848 const SwContentIndex aIdx( this, nStart );
1849 // erase the CH_TXTATR, which will also delete pTextHt
1850 EraseText( aIdx, 1 );
1851 }
1852 else if ( pTextHt->HasContent() )
1853 {
1854 const SwContentIndex aIdx( this, nStart );
1855 OSL_ENSURE( pTextHt->End() != nullptr, "<SwTextNode::DeleteAttributes(..)> - missing End() at <SwTextAttr> instance which has content" );
1856 EraseText( aIdx, *pTextHt->End() - nStart );
1857 }
1858 else if( *pEndIdx == nEnd )
1859 {
1860 // Create MsgHint before Start and End are gone.
1861 // For HiddenParaFields it's not necessary to call
1862 // SetCalcHiddenParaField because the dtor does that.
1863 SwUpdateAttr aHint(
1864 nStart,
1865 *pEndIdx,
1866 nWhich);
1867
1868 m_pSwpHints->DeleteAtPos( nPos );
1869 SwTextAttr::Destroy( pTextHt, GetDoc().GetAttrPool() );
1870 CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aHint));
1871 }
1872 }
1873 }
1875}
1876
1877void SwTextNode::DelSoftHyph( const sal_Int32 nStt, const sal_Int32 nEnd )
1878{
1879 sal_Int32 nFndPos = nStt;
1880 sal_Int32 nEndPos = nEnd;
1881 for (;;)
1882 {
1883 nFndPos = m_Text.indexOf(CHAR_SOFTHYPHEN, nFndPos);
1884 if (nFndPos<0 || nFndPos>=nEndPos )
1885 {
1886 break;
1887 }
1888 const SwContentIndex aIdx( this, nFndPos );
1889 EraseText( aIdx, 1 );
1890 --nEndPos;
1891 }
1892}
1893
1894bool SwTextNode::IsIgnoredCharFormatForNumbering(const sal_uInt16 nWhich, bool bIsCharStyle)
1895{
1896 // LO can save the char background as either shading or highlight, so check which mode is currently chosen.
1897 // Shading does not affect the numbering. Highlighting does (but isn't allowed in a char style).
1898 if (nWhich == RES_CHRATR_BACKGROUND)
1899 return bIsCharStyle || SvtFilterOptions::Get().IsCharBackground2Shading();
1900
1901 return (nWhich == RES_CHRATR_UNDERLINE
1902 || nWhich == RES_CHRATR_ESCAPEMENT);
1903}
1904
1905// Set these attributes on SwTextNode. If they apply to the entire paragraph
1906// text, set them in the SwTextNode's item set (SwContentNode::SetAttr).
1908 const SfxItemSet& rSet,
1909 const sal_Int32 nStt,
1910 const sal_Int32 nEnd,
1911 const SetAttrMode nMode,
1912 SwTextAttr **ppNewTextAttr )
1913{
1914 if( !rSet.Count() )
1915 return false;
1916
1917 // split sets (for selection in nodes)
1918 const SfxItemSet* pSet = &rSet;
1920
1921 // entire paragraph
1922 if ( !nStt && (nEnd == m_Text.getLength()) &&
1923 !(nMode & SetAttrMode::NOFORMATATTR ) )
1924 {
1925 // if the node already has CharFormat hints, the new attributes must
1926 // be set as hints too to override those.
1927 bool bHasCharFormats = false;
1928 if ( HasHints() )
1929 {
1930 for ( size_t n = 0; n < m_pSwpHints->Count(); ++n )
1931 {
1932 if ( m_pSwpHints->Get( n )->IsCharFormatAttr() )
1933 {
1934 bHasCharFormats = true;
1935 break;
1936 }
1937 }
1938 }
1939
1940 if( !bHasCharFormats )
1941 {
1942 aTextSet.Put( rSet );
1943 // If there are any character attributes in rSet,
1944 // we want to set them at the paragraph:
1945 if( aTextSet.Count() != rSet.Count() )
1946 {
1947 const bool bRet = SetAttr( rSet );
1948 if( !aTextSet.Count() )
1949 return bRet;
1950 }
1951
1952 // check for auto style:
1953 if ( const SwFormatAutoFormat* pItem = aTextSet.GetItemIfSet( RES_TXTATR_AUTOFMT, false ) )
1954 {
1955 const bool bRet = SetAttr( *pItem->GetStyleHandle() );
1956 if( 1 == aTextSet.Count() )
1957 return bRet;
1958 }
1959
1960 // Continue with the text attributes:
1961 pSet = &aTextSet;
1962 }
1963 }
1964
1966
1968
1969 size_t nCount = 0;
1970 SfxItemIter aIter( *pSet );
1971 const SfxPoolItem* pItem = aIter.GetCurItem();
1972
1973 do
1974 {
1975 if (!IsInvalidItem(pItem))
1976 {
1977 const sal_uInt16 nWhich = pItem->Which();
1978 OSL_ENSURE( isCHRATR(nWhich) || isTXTATR(nWhich),
1979 "SwTextNode::SetAttr(): unknown attribute" );
1980 if ( isCHRATR(nWhich) || isTXTATR(nWhich) )
1981 {
1982 if ((RES_TXTATR_CHARFMT == nWhich) &&
1983 (GetDoc().GetDfltCharFormat() ==
1984 static_cast<const SwFormatCharFormat*>(pItem)->GetCharFormat()))
1985 {
1986 SwContentIndex aIndex( this, nStt );
1987 RstTextAttr( aIndex, nEnd - nStt, RES_TXTATR_CHARFMT );
1988 DontExpandFormat( aIndex.GetIndex() );
1989 }
1990 else
1991 {
1992 if (isCHRATR(nWhich) ||
1993 (RES_TXTATR_UNKNOWN_CONTAINER == nWhich))
1994 {
1995 aCharSet.Put( *pItem );
1996 }
1997 else
1998 {
1999
2000 SwTextAttr *const pNew = MakeTextAttr( GetDoc(),
2001 const_cast<SfxPoolItem&>(*pItem), nStt, nEnd );
2002 if ( pNew )
2003 {
2004 // store the first one we create into the pp
2005 if (ppNewTextAttr && !*ppNewTextAttr)
2006 *ppNewTextAttr = pNew;
2007 if ( nEnd != nStt && !pNew->GetEnd() )
2008 {
2009 OSL_FAIL("Attribute without end, but area marked");
2010 DestroyAttr( pNew ); // do not insert
2011 }
2012 else if ( InsertHint( pNew, nMode ) )
2013 {
2014 ++nCount;
2015 }
2016 }
2017 }
2018 }
2019 }
2020 }
2021 pItem = aIter.NextItem();
2022 } while(pItem);
2023
2024 if ( aCharSet.Count() )
2025 {
2026 SwTextAttr* pTmpNew = MakeTextAttr( GetDoc(), aCharSet, nStt, nEnd );
2027 if ( InsertHint( pTmpNew, nMode ) )
2028 {
2029 ++nCount;
2030 }
2031 }
2032
2034
2035 return nCount != 0;
2036}
2037
2038static void lcl_MergeAttr( SfxItemSet& rSet, const SfxPoolItem& rAttr )
2039{
2040 if ( RES_TXTATR_AUTOFMT == rAttr.Which() )
2041 {
2042 const SfxItemSet* pCFSet = CharFormat::GetItemSet( rAttr );
2043 if ( !pCFSet )
2044 return;
2045 SfxWhichIter aIter( *pCFSet );
2046 sal_uInt16 nWhich = aIter.FirstWhich();
2047 while( nWhich )
2048 {
2049 const SfxPoolItem* pItem = nullptr;
2050 if( ( nWhich < RES_CHRATR_END ||
2051 RES_TXTATR_UNKNOWN_CONTAINER == nWhich ) &&
2052 ( SfxItemState::SET == aIter.GetItemState( true, &pItem ) ) )
2053 rSet.Put( *pItem );
2054 nWhich = aIter.NextWhich();
2055 }
2056 }
2057 else
2058 rSet.Put( rAttr );
2059}
2060
2061static void lcl_MergeAttr_ExpandChrFormat( SfxItemSet& rSet, const SfxPoolItem& rAttr )
2062{
2063 if( RES_TXTATR_CHARFMT == rAttr.Which() ||
2064 RES_TXTATR_INETFMT == rAttr.Which() ||
2065 RES_TXTATR_AUTOFMT == rAttr.Which() )
2066 {
2067 const SfxItemSet* pCFSet = CharFormat::GetItemSet( rAttr );
2068
2069 if ( pCFSet )
2070 {
2071 SfxWhichIter aIter( *pCFSet );
2072 sal_uInt16 nWhich = aIter.FirstWhich();
2073 while( nWhich )
2074 {
2075 const SfxPoolItem* pItem = nullptr;
2076 if( ( nWhich < RES_CHRATR_END ||
2077 ( RES_TXTATR_AUTOFMT == rAttr.Which() && RES_TXTATR_UNKNOWN_CONTAINER == nWhich ) ) &&
2078 ( SfxItemState::SET == aIter.GetItemState( true, &pItem ) ) )
2079 rSet.Put( *pItem );
2080 nWhich = aIter.NextWhich();
2081 }
2082 }
2083 }
2084
2085/* If multiple attributes overlap, the last one wins!
2086 Probably this can only happen between a RES_TXTATR_INETFMT and one of the
2087 other hints, because BuildPortions ensures that CHARFMT/AUTOFMT don't
2088 overlap. But there may be multiple CHARFMT/AUTOFMT with exactly the same
2089 start/end, sorted by BuildPortions, in which case the same logic applies.
2090
2091 1234567890123456789
2092 |------------| Font1
2093 |------| Font2
2094 ^ ^
2095 |--| query range: -> Font2
2096*/
2097 // merge into set
2098 rSet.Put( rAttr );
2099}
2100
2101namespace {
2102
2103struct SwPoolItemEndPair
2104{
2105public:
2106 const SfxPoolItem* mpItem;
2107 sal_Int32 mnEndPos;
2108
2109 SwPoolItemEndPair() : mpItem( nullptr ), mnEndPos( 0 ) {};
2110};
2111
2112}
2113
2115 SfxItemSet& rSet )
2116{
2117 if ( !rTextNode.AreListLevelIndentsApplicable() )
2118 return;
2119
2120 const SwNumRule* pRule = rTextNode.GetNumRule();
2121 if ( pRule && rTextNode.GetActualListLevel() >= 0 )
2122 {
2123 const SwNumFormat& rFormat = pRule->Get(o3tl::narrowing<sal_uInt16>(rTextNode.GetActualListLevel()));
2125 {
2127 aLR.SetTextLeft( rFormat.GetIndentAt() );
2128 aLR.SetTextFirstLineOffset( static_cast<short>(rFormat.GetFirstLineIndent()) );
2129 rSet.Put( aLR );
2130 }
2131 }
2132}
2133
2134// request the attributes of the TextNode at the range
2135bool SwTextNode::GetParaAttr(SfxItemSet& rSet, sal_Int32 nStt, sal_Int32 nEnd,
2136 const bool bOnlyTextAttr, const bool bGetFromChrFormat,
2137 const bool bMergeIndentValuesOfNumRule,
2138 SwRootFrame const*const pLayout) const
2139{
2140 assert(!rSet.Count()); // handled inconsistently, typically an error?
2141
2142 if (pLayout && pLayout->HasMergedParas())
2143 {
2145 {
2146 return false; // ignore deleted node
2147 }
2148 }
2149
2150 // get the node's automatic attributes
2151 SfxItemSet aFormatSet( *rSet.GetPool(), rSet.GetRanges() );
2152 if (!bOnlyTextAttr)
2153 {
2154 SwTextNode const& rParaPropsNode(
2155 sw::GetAttrMerged(aFormatSet, *this, pLayout));
2156 if (bMergeIndentValuesOfNumRule)
2157 {
2158 lcl_MergeListLevelIndentAsLRSpaceItem(rParaPropsNode, aFormatSet);
2159 }
2160 }
2161
2162 if( HasHints() )
2163 {
2164 // First, check which text attributes are valid in the range.
2165 // cases:
2166 // Ambiguous, if
2167 // * the attribute is wholly contained in the range
2168 // * the attribute end is in the range
2169 // * the attribute start is in the range
2170 // Unambiguous (merge into set), if
2171 // * the attribute wholly contains the range
2172 // Ignored, if
2173 // * the attribute is wholly outside the range
2174
2175 void (*fnMergeAttr)( SfxItemSet&, const SfxPoolItem& )
2176 = bGetFromChrFormat ? &lcl_MergeAttr_ExpandChrFormat
2177 : &lcl_MergeAttr;
2178
2179 const size_t nSize = m_pSwpHints->Count();
2180
2181 if (nStt == nEnd) // no range:
2182 {
2183 for (size_t n = 0; n < nSize; ++n)
2184 {
2185 const SwTextAttr* pHt = m_pSwpHints->Get(n);
2186 const sal_Int32 nAttrStart = pHt->GetStart();
2187 if (nAttrStart > nEnd) // behind the range
2188 break;
2189
2190 const sal_Int32* pAttrEnd = pHt->End();
2191 if ( ! pAttrEnd ) // no attributes without end
2192 continue;
2193
2194 if( ( nAttrStart < nStt &&
2195 ( pHt->DontExpand() ? nStt < *pAttrEnd
2196 : nStt <= *pAttrEnd )) ||
2197 ( nStt == nAttrStart &&
2198 ( nAttrStart == *pAttrEnd || !nStt )))
2199 (*fnMergeAttr)( rSet, pHt->GetAttr() );
2200 }
2201 }
2202 else // a query range is defined
2203 {
2204 // #i75299#
2205 std::optional< std::vector< SwPoolItemEndPair > > pAttrArr;
2206
2207 const size_t coArrSz = RES_TXTATR_WITHEND_END - RES_CHRATR_BEGIN;
2208
2209 for (size_t n = 0; n < nSize; ++n)
2210 {
2211 const SwTextAttr* pHt = m_pSwpHints->Get(n);
2212 const sal_Int32 nAttrStart = pHt->GetStart();
2213 if (nAttrStart > nEnd) // outside, behind
2214 break;
2215
2216 const sal_Int32* pAttrEnd = pHt->End();
2217 if ( ! pAttrEnd ) // no attributes without end
2218 continue;
2219
2220 bool bChkInvalid = false;
2221 if (nAttrStart <= nStt) // before or exactly Start
2222 {
2223 if (*pAttrEnd <= nStt) // outside, before
2224 continue;
2225
2226 if (nEnd <= *pAttrEnd) // behind or exactly End
2227 (*fnMergeAttr)( aFormatSet, pHt->GetAttr() );
2228 else
2229// else if( pHt->GetAttr() != aFormatSet.Get( pHt->Which() ) )
2230 // ambiguous
2231 bChkInvalid = true;
2232 }
2233 else if (nAttrStart < nEnd // starts in the range
2234)// && pHt->GetAttr() != aFormatSet.Get( pHt->Which() ) )
2235 bChkInvalid = true;
2236
2237 if( bChkInvalid )
2238 {
2239 // ambiguous?
2240 std::optional< SfxItemIter > oItemIter;
2241 const SfxPoolItem* pItem = nullptr;
2242
2243 if ( RES_TXTATR_AUTOFMT == pHt->Which() )
2244 {
2245 const SfxItemSet* pAutoSet = CharFormat::GetItemSet( pHt->GetAttr() );
2246 if ( pAutoSet )
2247 {
2248 oItemIter.emplace( *pAutoSet );
2249 pItem = oItemIter->GetCurItem();
2250 }
2251 }
2252 else
2253 pItem = &pHt->GetAttr();
2254
2255 const sal_Int32 nHintEnd = *pAttrEnd;
2256
2257 for (; pItem; pItem = oItemIter ? oItemIter->NextItem() : nullptr)
2258 {
2259 const sal_uInt16 nHintWhich = pItem->Which();
2260 OSL_ENSURE(!isUNKNOWNATR(nHintWhich),
2261 "SwTextNode::GetAttr(): unknown attribute?");
2262
2263 if (!pAttrArr)
2264 {
2265 pAttrArr = std::vector< SwPoolItemEndPair >(coArrSz);
2266 }
2267
2268 std::vector< SwPoolItemEndPair >::iterator pPrev = pAttrArr->begin();
2269 if (isCHRATR(nHintWhich) ||
2270 isTXTATR_WITHEND(nHintWhich))
2271 {
2272 pPrev += nHintWhich - RES_CHRATR_BEGIN;
2273 }
2274 else
2275 {
2276 pPrev = pAttrArr->end();
2277 }
2278
2279 if( pPrev != pAttrArr->end() )
2280 {
2281 if( !pPrev->mpItem )
2282 {
2283 if ( bOnlyTextAttr || *pItem != aFormatSet.Get( nHintWhich ) )
2284 {
2285 if( nAttrStart > nStt )
2286 {
2287 rSet.InvalidateItem( nHintWhich );
2288 pPrev->mpItem = INVALID_POOL_ITEM;
2289 }
2290 else
2291 {
2292 pPrev->mpItem = pItem;
2293 pPrev->mnEndPos = nHintEnd;
2294 }
2295 }
2296 }
2297 else if( !IsInvalidItem(pPrev->mpItem) )
2298 {
2299 if( pPrev->mnEndPos == nAttrStart &&
2300 *pPrev->mpItem == *pItem )
2301 {
2302 pPrev->mpItem = pItem;
2303 pPrev->mnEndPos = nHintEnd;
2304 }
2305 else
2306 {
2307 rSet.InvalidateItem( nHintWhich );
2308 pPrev->mpItem = INVALID_POOL_ITEM;
2309 }
2310 }
2311 }
2312 } // end while
2313 }
2314 }
2315
2316 if (pAttrArr)
2317 {
2318 for (size_t n = 0; n < coArrSz; ++n)
2319 {
2320 const SwPoolItemEndPair& rItemPair = (*pAttrArr)[ n ];
2321 if( rItemPair.mpItem && !IsInvalidItem(rItemPair.mpItem) )
2322 {
2323 const sal_uInt16 nWh =
2324 o3tl::narrowing<sal_uInt16>(n + RES_CHRATR_BEGIN);
2325
2326 if (nEnd <= rItemPair.mnEndPos) // behind or exactly end
2327 {
2328 if( *rItemPair.mpItem != aFormatSet.Get( nWh ) )
2329 (*fnMergeAttr)( rSet, *rItemPair.mpItem );
2330 }
2331 else
2332 // ambiguous
2333 rSet.InvalidateItem( nWh );
2334 }
2335 }
2336 }
2337 }
2338 if( aFormatSet.Count() )
2339 {
2340 // remove all from the format-set that are also set in the text-set
2341 aFormatSet.Differentiate( rSet );
2342 }
2343 }
2344
2345 if (aFormatSet.Count())
2346 {
2347 // now "merge" everything
2348 rSet.Put( aFormatSet );
2349 }
2350
2351 return rSet.Count() != 0;
2352}
2353
2354namespace
2355{
2356
2357typedef std::pair<sal_Int32, sal_Int32> AttrSpan_t;
2358typedef std::multimap<AttrSpan_t, const SwTextAttr*> AttrSpanMap_t;
2359
2360struct IsAutoStyle
2361{
2362 bool
2363 operator()(const AttrSpanMap_t::value_type& i_rAttrSpan)
2364 const
2365 {
2366 return i_rAttrSpan.second && i_rAttrSpan.second->Which() == RES_TXTATR_AUTOFMT;
2367 }
2368};
2369
2373struct RemovePresentAttrs
2374{
2375 explicit RemovePresentAttrs(SfxItemSet& io_rAttrSet)
2376 : m_rAttrSet(io_rAttrSet)
2377 {
2378 }
2379
2380 void
2381 operator()(const AttrSpanMap_t::value_type& i_rAttrSpan)
2382 const
2383 {
2384 if (!i_rAttrSpan.second)
2385 {
2386 return;
2387 }
2388
2389 const SwTextAttr* const pAutoStyle(i_rAttrSpan.second);
2390 SfxItemIter aIter(m_rAttrSet);
2391 for (const SfxPoolItem* pItem(aIter.GetCurItem()); pItem; pItem = aIter.NextItem())
2392 {
2393 const sal_uInt16 nWhich(pItem->Which());
2394 if (CharFormat::IsItemIncluded(nWhich, pAutoStyle))
2395 {
2396 aIter.ClearItem();
2397 }
2398 }
2399 }
2400
2401private:
2402 SfxItemSet& m_rAttrSet;
2403};
2404
2411void
2412lcl_CollectHintSpans(const SwpHints& i_rHints, const sal_Int32 nLength,
2413 AttrSpanMap_t& o_rSpanMap)
2414{
2415 sal_Int32 nLastEnd(0);
2416
2417 for (size_t i = 0; i < i_rHints.Count(); ++i)
2418 {
2419 const SwTextAttr* pHint = i_rHints.Get(i);
2420 const sal_uInt16 nWhich(pHint->Which());
2421 if (nWhich == RES_TXTATR_CHARFMT || nWhich == RES_TXTATR_AUTOFMT)
2422 {
2423 const AttrSpan_t aSpan(pHint->GetStart(), *pHint->End());
2424 o_rSpanMap.emplace(aSpan, pHint);
2425
2426 // < not != because there may be multiple CHARFMT at same range
2427 if (nLastEnd < aSpan.first)
2428 {
2429 // insert dummy span covering the gap
2430 o_rSpanMap.emplace( AttrSpan_t(nLastEnd, aSpan.first), nullptr );
2431 }
2432
2433 nLastEnd = aSpan.second;
2434 }
2435 }
2436
2437 // no hints at the end (special case: no hints at all in i_rHints)
2438 if (nLastEnd != nLength && nLength != 0)
2439 {
2440 o_rSpanMap.emplace(AttrSpan_t(nLastEnd, nLength), nullptr);
2441 }
2442}
2443
2444void
2445lcl_FillWhichIds(const SfxItemSet& i_rAttrSet, std::vector<sal_uInt16>& o_rClearIds)
2446{
2447 o_rClearIds.reserve(i_rAttrSet.Count());
2448 SfxItemIter aIter(i_rAttrSet);
2449 for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
2450 {
2451 o_rClearIds.push_back(pItem->Which());
2452 }
2453}
2454
2455struct SfxItemSetClearer
2456{
2457 SfxItemSet & m_rItemSet;
2458 explicit SfxItemSetClearer(SfxItemSet & rItemSet) : m_rItemSet(rItemSet) { }
2459 void operator()(sal_uInt16 const nWhich) { m_rItemSet.ClearItem(nWhich); }
2460};
2461
2462}
2463
2467void
2469{
2470 typedef AttrSpanMap_t::iterator AttrSpanMap_iterator_t;
2471 AttrSpanMap_t aAttrSpanMap;
2472
2473 if (i_rAttrSet.Count() == 0)
2474 {
2475 return;
2476 }
2477
2478 // 1. Identify all spans in hints' array
2479
2480 lcl_CollectHintSpans(*m_pSwpHints, m_Text.getLength(), aAttrSpanMap);
2481
2482 // 2. Go through all spans and insert new attrs
2483
2484 AttrSpanMap_iterator_t aCurRange(aAttrSpanMap.begin());
2485 const AttrSpanMap_iterator_t aEnd(aAttrSpanMap.end());
2486 while (aCurRange != aEnd)
2487 {
2488 typedef std::pair<AttrSpanMap_iterator_t, AttrSpanMap_iterator_t>
2489 AttrSpanMapRange_t;
2490 AttrSpanMapRange_t aRange(aAttrSpanMap.equal_range(aCurRange->first));
2491
2492 // 2a. Collect attributes to insert
2493
2494 SfxItemSet aCurSet(i_rAttrSet);
2495 std::for_each(aRange.first, aRange.second, RemovePresentAttrs(aCurSet));
2496
2497 // 2b. Insert automatic style containing the collected attributes
2498
2499 if (aCurSet.Count() != 0)
2500 {
2501 AttrSpanMap_iterator_t aAutoStyleIt(
2502 std::find_if(aRange.first, aRange.second, IsAutoStyle()));
2503 if (aAutoStyleIt != aRange.second)
2504 {
2505 // there already is an automatic style on that span:
2506 // create new one and remove the original one
2507 SwTextAttr* const pAutoStyle(const_cast<SwTextAttr*>(aAutoStyleIt->second));
2508 const std::shared_ptr<SfxItemSet> pOldStyle(
2509 static_cast<const SwFormatAutoFormat&>(
2510 pAutoStyle->GetAttr()).GetStyleHandle());
2511 aCurSet.Put(*pOldStyle);
2512
2513 // remove the old hint
2514 m_pSwpHints->Delete(pAutoStyle);
2515 DestroyAttr(pAutoStyle);
2516 }
2517 m_pSwpHints->Insert(
2518 MakeTextAttr(GetDoc(), aCurSet,
2519 aCurRange->first.first, aCurRange->first.second));
2520 }
2521
2522 aCurRange = aRange.second;
2523 }
2524
2525 // hints were directly inserted, so need to fix the Ignore flags now
2526 m_pSwpHints->MergePortions(*this);
2527
2528 // 3. Clear items from the node
2529 std::vector<sal_uInt16> aClearedIds;
2530 lcl_FillWhichIds(i_rAttrSet, aClearedIds);
2531 ClearItemsFromAttrSet(aClearedIds);
2532}
2533
2535{
2536 SfxItemSet aThisSet( GetDoc().GetAttrPool(), aCharFormatSetRange );
2537 if( HasSwAttrSet() && GetpSwAttrSet()->Count() )
2538 aThisSet.Put( *GetpSwAttrSet() );
2539
2541
2542 if( pNd == this )
2543 {
2544 impl_FormatToTextAttr(aThisSet);
2545 }
2546 else
2547 {
2548 // There are five possible combinations of items from this and
2549 // pNd (pNd is the 'main' node):
2550
2551 // case pNd this action
2552
2553 // 1 - - do nothing
2554 // 2 - a convert item to attr of this
2555 // 3 a - convert item to attr of pNd
2556 // 4 a a clear item in this
2557 // 5 a b convert item to attr of this
2558
2560 if( pNd->HasSwAttrSet() && pNd->GetpSwAttrSet()->Count() )
2561 aNdSet.Put( *pNd->GetpSwAttrSet() );
2562
2563 pNd->GetOrCreateSwpHints();
2564
2565 std::vector<sal_uInt16> aProcessedIds;
2566
2567 if( aThisSet.Count() )
2568 {
2569 SfxItemIter aIter( aThisSet );
2570 const SfxPoolItem* pItem = aIter.GetCurItem(), *pNdItem = nullptr;
2571 SfxItemSet aConvertSet( GetDoc().GetAttrPool(), aCharFormatSetRange );
2572 std::vector<sal_uInt16> aClearWhichIds;
2573
2574 do
2575 {
2576 if( SfxItemState::SET == aNdSet.GetItemState( pItem->Which(), false, &pNdItem ) )
2577 {
2578 if (*pItem == *pNdItem) // 4
2579 {
2580 aClearWhichIds.push_back( pItem->Which() );
2581 }
2582 else // 5
2583 {
2584 aConvertSet.Put(*pItem);
2585 }
2586 aProcessedIds.push_back(pItem->Which());
2587 }
2588 else // 2
2589 {
2590 aConvertSet.Put(*pItem);
2591 }
2592
2593 pItem = aIter.NextItem();
2594 } while (pItem);
2595
2596 // 4/ clear items of this that are set with the same value on pNd
2597 ClearItemsFromAttrSet( aClearWhichIds );
2598
2599 // 2, 5/ convert all other items to attrs
2600 impl_FormatToTextAttr(aConvertSet);
2601 }
2602
2603 {
2604 std::for_each(aProcessedIds.begin(), aProcessedIds.end(),
2605 SfxItemSetClearer(aNdSet));
2606
2607 // 3/ convert items to attrs
2608 pNd->impl_FormatToTextAttr(aNdSet);
2609
2610 if( aNdSet.Count() )
2611 {
2612 SwFormatChg aTmp1( pNd->GetFormatColl() );
2613 pNd->CallSwClientNotify(sw::LegacyModifyHint(&aTmp1, &aTmp1));
2614 }
2615 }
2616 }
2617
2619
2620 pNd->TryDeleteSwpHints();
2621}
2622
2624{
2625 m_bDDEFields = m_bFootnote = false;
2626 const size_t nSize = Count();
2627 for( size_t nPos = 0; nPos < nSize; ++nPos )
2628 {
2629 const SwTextAttr* pAttr = Get( nPos );
2630 switch( pAttr->Which() )
2631 {
2632 case RES_TXTATR_FTN:
2633 m_bFootnote = true;
2634 if ( m_bDDEFields )
2635 return;
2636 break;
2637 case RES_TXTATR_FIELD:
2638 {
2639 const SwField* pField = pAttr->GetFormatField().GetField();
2640 if( SwFieldIds::Dde == pField->GetTyp()->Which() )
2641 {
2642 m_bDDEFields = true;
2643 if ( m_bFootnote )
2644 return;
2645 }
2646 }
2647 break;
2648 }
2649 }
2650}
2651
2653{
2654 m_bCalcHiddenParaField = false;
2655 const bool bOldHiddenByParaField = m_bHiddenByParaField;
2656 bool bNewHiddenByParaField = false;
2657 int nNewResultWeight = 0;
2658 const size_t nSize = Count();
2659 const SwTextAttr* pTextHt;
2660
2661 for (size_t nPos = 0; nPos < nSize; ++nPos)
2662 {
2663 pTextHt = Get(nPos);
2664 const sal_uInt16 nWhich = pTextHt->Which();
2665
2666 if (RES_TXTATR_FIELD == nWhich)
2667 {
2668 // see also SwTextFrame::IsHiddenNow()
2669 const SwFormatField& rField = pTextHt->GetFormatField();
2670 int nCurWeight = m_rParent.GetDoc().FieldCanHideParaWeight(rField.GetField()->GetTyp()->Which());
2671 if (nCurWeight > nNewResultWeight)
2672 {
2673 nNewResultWeight = nCurWeight;
2674 bNewHiddenByParaField = m_rParent.GetDoc().FieldHidesPara(*rField.GetField());
2675 }
2676 else if (nCurWeight == nNewResultWeight && bNewHiddenByParaField)
2677 {
2678 // Currently, for both supported hiding types (HiddenPara, Database), "Don't hide"
2679 // takes precedence - i.e., if there's a "Don't hide" field of that weight, we only
2680 // care about fields of higher weight.
2681 bNewHiddenByParaField = m_rParent.GetDoc().FieldHidesPara(*rField.GetField());
2682 }
2683 }
2684 }
2685 SetHiddenByParaField(bNewHiddenByParaField);
2686 return bOldHiddenByParaField != bNewHiddenByParaField;
2687}
2688
2689void SwpHints::NoteInHistory( SwTextAttr *pAttr, const bool bNew )
2690{
2691 if ( m_pHistory ) { m_pHistory->AddHint( pAttr, bNew ); }
2692}
2693
2694namespace {
2695struct Portion {
2696 SwTextAttr* pTextAttr;
2697 int nKey;
2698 bool isRsidOnlyAutoFormat;
2699};
2700typedef std::vector< Portion > PortionMap;
2701enum MergeResult { MATCH, DIFFER_ONLY_RSID, DIFFER };
2702}
2703
2704static MergeResult lcl_Compare_Attributes(
2705 int i, int j,
2706 const std::pair< PortionMap::const_iterator, PortionMap::const_iterator >& aRange1,
2707 const std::pair< PortionMap::const_iterator, PortionMap::const_iterator >& aRange2,
2708 std::vector<bool>& RsidOnlyAutoFormatFlagMap);
2709
2711{
2712 if ( !Count() )
2713 return false;
2714
2715 // sort before merging
2716 Resort();
2717
2718 bool bRet = false;
2719 PortionMap aPortionMap;
2720 aPortionMap.reserve(Count() + 1);
2721 std::vector<bool> RsidOnlyAutoFormatFlagMap;
2722 RsidOnlyAutoFormatFlagMap.resize(Count() + 1);
2723 sal_Int32 nLastPorStart = COMPLETE_STRING;
2724 sal_Int32 nKey = 0;
2725
2726 // get portions by start position:
2727 for ( size_t i = 0; i < Count(); ++i )
2728 {
2729 SwTextAttr *pHt = Get( i );
2730 if ( RES_TXTATR_CHARFMT != pHt->Which() &&
2731 RES_TXTATR_AUTOFMT != pHt->Which() )
2732 //&&
2733 //RES_TXTATR_INETFMT != pHt->Which() )
2734 continue;
2735
2736 bool isRsidOnlyAutoFormat(false);
2737 // check for RSID-only AUTOFMT
2738 if (RES_TXTATR_AUTOFMT == pHt->Which())
2739 {
2740 std::shared_ptr<SfxItemSet> const & pSet(
2741 pHt->GetAutoFormat().GetStyleHandle());
2742 if ((pSet->Count() == 1) && pSet->GetItem(RES_CHRATR_RSID, false))
2743 {
2744 // fdo#70201: eliminate no-extent RSID-only AUTOFMT
2745 // could be produced by ReplaceText or (maybe?) RstAttr
2746 if (pHt->GetStart() == *pHt->GetEnd())
2747 {
2748 DeleteAtPos(i); // kill it without History!
2749 SwTextAttr::Destroy(pHt, rNode.GetDoc().GetAttrPool());
2750 --i;
2751 continue;
2752 }
2753 // fdo#52028: this one has _only_ RSID => ignore it completely
2754 if (!pHt->IsFormatIgnoreStart() || !pHt->IsFormatIgnoreEnd())
2755 {
2756 NoteInHistory(pHt);
2757 pHt->SetFormatIgnoreStart(true);
2758 pHt->SetFormatIgnoreEnd (true);
2759 NoteInHistory(pHt, true);
2760 }
2761 isRsidOnlyAutoFormat = true;
2762 }
2763 }
2764
2765 if (pHt->GetStart() == *pHt->GetEnd())
2766 {
2767 // no-length hints are a disease. ignore them here.
2768 // the SwAttrIter::SeekFwd will not call Rst/Chg for them.
2769 continue;
2770 }
2771
2772 const sal_Int32 nPorStart = pHt->GetStart();
2773 if (nPorStart != nLastPorStart)
2774 ++nKey;
2775 nLastPorStart = nPorStart;
2776 aPortionMap.push_back(Portion {pHt, nKey, isRsidOnlyAutoFormat});
2777 RsidOnlyAutoFormatFlagMap[nKey] = isRsidOnlyAutoFormat;
2778 }
2779
2780 // we add data strictly in-order, so we can binary-search the vector
2781 auto equal_range = [&aPortionMap](int i)
2782 {
2783 Portion key { nullptr, i, false };
2784 return std::equal_range(aPortionMap.begin(), aPortionMap.end(), key,
2785 [] (const Portion& lhs, const Portion& rhs) -> bool
2786 {
2787 return lhs.nKey < rhs.nKey;
2788 });
2789 };
2790
2791 // check if portion i can be merged with portion i+1:
2792 // note: need to include i=0 to set IgnoreStart and j=nKey+1 to reset
2793 // IgnoreEnd at first / last portion
2794 int i = 0;
2795 int j = i + 1;
2796 while ( i <= nKey )
2797 {
2798 std::pair< PortionMap::const_iterator, PortionMap::const_iterator > aRange1 = equal_range( i );
2799 std::pair< PortionMap::const_iterator, PortionMap::const_iterator > aRange2 = equal_range( j );
2800
2801 MergeResult eMerge = lcl_Compare_Attributes(i, j, aRange1, aRange2, RsidOnlyAutoFormatFlagMap);
2802
2803 if (MATCH == eMerge)
2804 {
2805 // important: delete second range so any IgnoreStart on the first
2806 // range is still valid
2807 // erase all elements with key i + 1
2808 sal_Int32 nNewPortionEnd = 0;
2809 for ( auto aIter2 = aRange2.first; aIter2 != aRange2.second; ++aIter2 )
2810 {
2811 SwTextAttr *const p2 = aIter2->pTextAttr;
2812 nNewPortionEnd = *p2->GetEnd();
2813
2814 const size_t nCountBeforeDelete = Count();
2815 Delete( p2 );
2816
2817 // robust: check if deletion actually took place before destroying attribute:
2818 if ( Count() < nCountBeforeDelete )
2819 rNode.DestroyAttr( p2 );
2820 }
2821 aPortionMap.erase( aRange2.first, aRange2.second );
2822 ++j;
2823
2824 // change all attributes with key i
2825 aRange1 = equal_range( i );
2826 for ( auto aIter1 = aRange1.first; aIter1 != aRange1.second; ++aIter1 )
2827 {
2828 SwTextAttr *const p1 = aIter1->pTextAttr;
2829 NoteInHistory( p1 );
2830 p1->SetEnd(nNewPortionEnd);
2831 NoteInHistory( p1, true );
2832 bRet = true;
2833 }
2834
2835 if (bRet)
2836 {
2837 Resort();
2838 }
2839 }
2840 else
2841 {
2842 // when not merging the ignore flags need to be either set or reset
2843 // (reset too in case one of the autofmts was recently changed)
2844 bool const bSetIgnoreFlag(DIFFER_ONLY_RSID == eMerge);
2845 for (auto aIter1 = aRange1.first; aIter1 != aRange1.second; ++aIter1)
2846 {
2847 if (!aIter1->isRsidOnlyAutoFormat) // already set above, don't change
2848 {
2849 SwTextAttr *const pCurrent(aIter1->pTextAttr);
2850 if (pCurrent->IsFormatIgnoreEnd() != bSetIgnoreFlag)
2851 {
2852 NoteInHistory(pCurrent);
2853 pCurrent->SetFormatIgnoreEnd(bSetIgnoreFlag);
2854 NoteInHistory(pCurrent, true);
2855 }
2856 }
2857 }
2858 for (auto aIter2 = aRange2.first; aIter2 != aRange2.second; ++aIter2)
2859 {
2860 if (!aIter2->isRsidOnlyAutoFormat) // already set above, don't change
2861 {
2862 SwTextAttr *const pCurrent(aIter2->pTextAttr);
2863 if (pCurrent->IsFormatIgnoreStart() != bSetIgnoreFlag)
2864 {
2865 NoteInHistory(pCurrent);
2866 pCurrent->SetFormatIgnoreStart(bSetIgnoreFlag);
2867 NoteInHistory(pCurrent, true);
2868 }
2869 }
2870 }
2871 i = j; // ++i not enough: i + 1 may have been deleted (MATCH)!
2872 ++j;
2873 }
2874 }
2875
2876 return bRet;
2877}
2878
2879
2880static MergeResult lcl_Compare_Attributes(
2881 int i, int j,
2882 const std::pair< PortionMap::const_iterator, PortionMap::const_iterator >& aRange1,
2883 const std::pair< PortionMap::const_iterator, PortionMap::const_iterator >& aRange2,
2884 std::vector<bool>& RsidOnlyAutoFormatFlagMap)
2885{
2886 PortionMap::const_iterator aIter1 = aRange1.first;
2887 PortionMap::const_iterator aIter2 = aRange2.first;
2888
2889 size_t const nAttributesInPor1 = std::distance(aRange1.first, aRange1.second);
2890 size_t const nAttributesInPor2 = std::distance(aRange2.first, aRange2.second);
2891 bool const isRsidOnlyAutoFormat1 = i < sal_Int32(RsidOnlyAutoFormatFlagMap.size()) && RsidOnlyAutoFormatFlagMap[i];
2892 bool const isRsidOnlyAutoFormat2 = j < sal_Int32(RsidOnlyAutoFormatFlagMap.size()) && RsidOnlyAutoFormatFlagMap[j];
2893
2894 // if both have one they could be equal, but not if only one has it
2895 bool const bSkipRsidOnlyAutoFormat(nAttributesInPor1 != nAttributesInPor2);
2896
2897 // this loop needs to handle the case where one has a CHARFMT and the
2898 // other CHARFMT + RSID-only AUTOFMT, so...
2899 // want to skip over RSID-only AUTOFMT here, hence the -1
2900 if (!((nAttributesInPor1 - (isRsidOnlyAutoFormat1 ? 1 : 0)) ==
2901 (nAttributesInPor2 - (isRsidOnlyAutoFormat2 ? 1 : 0))
2902 && (nAttributesInPor1 != 0 || nAttributesInPor2 != 0)))
2903 {
2904 return DIFFER;
2905 }
2906
2907 MergeResult eMerge(MATCH);
2908
2909 // _if_ there is one element more either in aRange1 or aRange2
2910 // it _must_ be an RSID-only AUTOFMT, which can be ignored here...
2911 // But if both have RSID-only AUTOFMT they could be equal, no skip!
2912 while (aIter1 != aRange1.second || aIter2 != aRange2.second)
2913 {
2914 // first of all test if there's no gap (before skipping stuff!)
2915 if (aIter1 != aRange1.second && aIter2 != aRange2.second &&
2916 *aIter1->pTextAttr->End() < aIter2->pTextAttr->GetStart())
2917 {
2918 return DIFFER;
2919 }
2920 // skip it - cannot be equal if bSkipRsidOnlyAutoFormat is set
2921 if (bSkipRsidOnlyAutoFormat
2922 && aIter1 != aRange1.second && aIter1->isRsidOnlyAutoFormat)
2923 {
2924 assert(DIFFER != eMerge);
2925 eMerge = DIFFER_ONLY_RSID;
2926 ++aIter1;
2927 continue;
2928 }
2929 if (bSkipRsidOnlyAutoFormat
2930 && aIter2 != aRange2.second && aIter2->isRsidOnlyAutoFormat)
2931 {
2932 assert(DIFFER != eMerge);
2933 eMerge = DIFFER_ONLY_RSID;
2934 ++aIter2;
2935 continue;
2936 }
2937 assert(aIter1 != aRange1.second && aIter2 != aRange2.second);
2938 SwTextAttr const*const p1 = aIter1->pTextAttr;
2939 SwTextAttr const*const p2 = aIter2->pTextAttr;
2940 if (p1->Which() != p2->Which())
2941 {
2942 return DIFFER;
2943 }
2944 if (!(*p1 == *p2))
2945 {
2946 // fdo#52028: for auto styles, check if they differ only
2947 // in the RSID, which should have no effect on text layout
2948 if (RES_TXTATR_AUTOFMT != p1->Which())
2949 return DIFFER;
2950
2951 const SfxItemSet& rSet1 = *p1->GetAutoFormat().GetStyleHandle();
2952 const SfxItemSet& rSet2 = *p2->GetAutoFormat().GetStyleHandle();
2953
2954 // sadly SfxItemSet::operator== does not seem to work?
2955 SfxItemIter iter1(rSet1);
2956 SfxItemIter iter2(rSet2);
2957 for (SfxPoolItem const* pItem1 = iter1.GetCurItem(),
2958 * pItem2 = iter2.GetCurItem();;)
2959 {
2960 if (pItem1 && pItem1->Which() == RES_CHRATR_RSID)
2961 pItem1 = iter1.NextItem();
2962 if (pItem2 && pItem2->Which() == RES_CHRATR_RSID)
2963 pItem2 = iter2.NextItem();
2964 if (!pItem1 && !pItem2)
2965 {
2966 eMerge = DIFFER_ONLY_RSID;
2967 break;
2968 }
2969 if (!pItem1 || !pItem2)
2970 {
2971 return DIFFER;
2972 }
2973 if (pItem1 != pItem2) // all are poolable
2974 {
2975 assert(IsInvalidItem(pItem1) || IsInvalidItem(pItem2) || pItem1->Which() != pItem2->Which() || *pItem1 != *pItem2);
2976 return DIFFER;
2977 }
2978 pItem1 = iter1.NextItem();
2979 pItem2 = iter2.NextItem();
2980 }
2981 }
2982 ++aIter1;
2983 ++aIter2;
2984 }
2985 return eMerge;
2986}
2987
2988
2989// check if there is already a character format and adjust the sort numbers
2990static void lcl_CheckSortNumber( const SwpHints& rHints, SwTextCharFormat& rNewCharFormat )
2991{
2992 const sal_Int32 nHtStart = rNewCharFormat.GetStart();
2993 const sal_Int32 nHtEnd = *rNewCharFormat.GetEnd();
2994 sal_uInt16 nSortNumber = 0;
2995
2996 for ( size_t i = 0; i < rHints.Count(); ++i )
2997 {
2998 const SwTextAttr* pOtherHt = rHints.Get(i);
2999
3000 const sal_Int32 nOtherStart = pOtherHt->GetStart();
3001
3002 if ( nOtherStart > nHtStart )
3003 break;
3004
3005 if ( RES_TXTATR_CHARFMT == pOtherHt->Which() )
3006 {
3007 const sal_Int32 nOtherEnd = *pOtherHt->End();
3008
3009 if ( nOtherStart == nHtStart && nOtherEnd == nHtEnd )
3010 {
3011 nSortNumber = static_txtattr_cast<const SwTextCharFormat*>(pOtherHt)->GetSortNumber() + 1;
3012 }
3013 }
3014 }
3015
3016 if ( nSortNumber > 0 )
3017 rNewCharFormat.SetSortNumber( nSortNumber );
3018}
3019
3020/*
3021 * Try to insert the new hint.
3022 * Depending on the type of the hint, this either always succeeds, or may fail.
3023 * Depending on the type of the hint, other hints may be deleted or
3024 * overwritten.
3025 * The return value indicates successful insertion.
3026 */
3028 SwTextAttr* const pHint,
3029 SwTextNode &rNode,
3030 const SetAttrMode nMode )
3031{
3032 if ( MAX_HINTS <= Count() ) // we're sorry, this flight is overbooked...
3033 {
3034 OSL_FAIL("hints array full :-(");
3035 rNode.DestroyAttr(pHint);
3036 return false;
3037 }
3038
3039 const sal_Int32 *pHtEnd = pHint->GetEnd();
3040 const sal_uInt16 nWhich = pHint->Which();
3041 std::vector<sal_uInt16> aWhichSublist;
3042
3043 switch( nWhich )
3044 {
3045 case RES_TXTATR_CHARFMT:
3046 {
3047 // Check if character format contains hidden attribute:
3048 const SwCharFormat* pFormat = pHint->GetCharFormat().GetCharFormat();
3049 if ( SfxItemState::SET == pFormat->GetItemState( RES_CHRATR_HIDDEN ) )
3050 rNode.SetCalcHiddenCharFlags();
3051
3052 static_txtattr_cast<SwTextCharFormat*>(pHint)->ChgTextNode( &rNode );
3053 break;
3054 }
3055 // #i75430# Recalc hidden flags if necessary
3056 case RES_TXTATR_AUTOFMT:
3057 {
3058 std::shared_ptr<SfxItemSet> const & pSet( pHint->GetAutoFormat().GetStyleHandle() );
3059 if (pHint->GetStart() == *pHint->GetEnd())
3060 {
3061 if (pSet->Count() == 1 && pSet->GetItem(RES_CHRATR_RSID, false))
3062 { // empty range RSID-only hints could cause trouble, there's no
3063 rNode.DestroyAttr(pHint); // need for them so don't insert
3064 return false;
3065 }
3066 }
3067 // Check if auto style contains hidden attribute:
3068 const SfxPoolItem* pHiddenItem = CharFormat::GetItem( *pHint, RES_CHRATR_HIDDEN );
3069 if ( pHiddenItem )
3070 rNode.SetCalcHiddenCharFlags();
3071
3072 // fdo#71556: populate aWhichFormatAttr member of SwMsgPoolItem
3073 const WhichRangesContainer& pRanges = pSet->GetRanges();
3074 for(auto const & rPair : pRanges)
3075 {
3076 const sal_uInt16 nBeg = rPair.first;
3077 const sal_uInt16 nEnd = rPair.second;
3078 for( sal_uInt16 nSubElem = nBeg; nSubElem <= nEnd; ++nSubElem )
3079 if( pSet->HasItem( nSubElem ) )
3080 aWhichSublist.push_back( nSubElem );
3081 }
3082 break;
3083 }
3084 case RES_TXTATR_INETFMT:
3085 static_txtattr_cast<SwTextINetFormat*>(pHint)->InitINetFormat(rNode);
3086 break;
3087
3088 case RES_TXTATR_FIELD:
3091 {
3092 SwTextField *const pTextField(static_txtattr_cast<SwTextField*>(pHint));
3093 bool bDelFirst = nullptr != pTextField->GetpTextNode();
3094 pTextField->ChgTextNode( &rNode );
3095 SwDoc& rDoc = rNode.GetDoc();
3096 const SwField* pField = pTextField->GetFormatField().GetField();
3097
3099 {
3100 // certain fields must update the SwDoc's calculation flags
3101 switch( pField->GetTyp()->Which() )
3102 {
3104 case SwFieldIds::SetExp:
3109 {
3110 if( bDelFirst )
3111 rDoc.getIDocumentFieldsAccess().InsDelFieldInFieldLst(false, *pTextField);
3112 if( rNode.GetNodes().IsDocNodes() )
3113 rDoc.getIDocumentFieldsAccess().InsDelFieldInFieldLst(true, *pTextField);
3114 }
3115 break;
3116 case SwFieldIds::Dde:
3117 if( rNode.GetNodes().IsDocNodes() )
3118 static_cast<SwDDEFieldType*>(pField->GetTyp())->IncRefCnt();
3119 break;
3120 default: break;
3121 }
3122 }
3123
3124 // insert into real document's nodes-array?
3125 if( rNode.GetNodes().IsDocNodes() )
3126 {
3127 bool bInsFieldType = false;
3128 switch( pField->GetTyp()->Which() )
3129 {
3130 case SwFieldIds::SetExp:
3131 bInsFieldType = static_cast<SwSetExpFieldType*>(pField->GetTyp())->IsDeleted();
3132 if( nsSwGetSetExpType::GSE_SEQ & static_cast<SwSetExpFieldType*>(pField->GetTyp())->GetType() )
3133 {
3134 // register the field at its FieldType before setting
3135 // the sequence reference number!
3136 SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(
3137 rDoc.getIDocumentFieldsAccess().InsertFieldType( *pField->GetTyp() ) );
3138 if( pFieldType != pField->GetTyp() )
3139 {
3140 SwFormatField* pFormatField = const_cast<SwFormatField*>(&pTextField->GetFormatField());
3141 pFormatField->RegisterToFieldType( *pFieldType );
3142 pFormatField->GetField()->ChgTyp( pFieldType );
3143 }
3144 pFieldType->SetSeqRefNo( *const_cast<SwSetExpField*>(static_cast<const SwSetExpField*>(pField)) );
3145 }
3146 break;
3147 case SwFieldIds::User:
3148 bInsFieldType = static_cast<SwUserFieldType*>(pField->GetTyp())->IsDeleted();
3149 break;
3150
3151 case SwFieldIds::Dde:
3153 static_cast<SwDDEFieldType*>(pField->GetTyp())->IncRefCnt();
3154 bInsFieldType = static_cast<SwDDEFieldType*>(pField->GetTyp())->IsDeleted();
3155 break;
3156
3157 case SwFieldIds::Postit:
3158 if ( rDoc.GetDocShell() )
3159 {
3160 rDoc.GetDocShell()->Broadcast( SwFormatFieldHint(
3162 }
3163 break;
3164 default: break;
3165 }
3166 if( bInsFieldType )
3168 }
3169 }
3170 break;
3171 case RES_TXTATR_FTN :
3172 static_cast<SwTextFootnote*>(pHint)->ChgTextNode( &rNode );
3173 break;
3174 case RES_TXTATR_REFMARK:
3175 static_txtattr_cast<SwTextRefMark*>(pHint)->ChgTextNode( &rNode );
3176 if( rNode.GetNodes().IsDocNodes() )
3177 {
3178 // search for a reference with the same name
3179 SwTextAttr* pTmpHt;
3180 for( size_t n = 0, nEnd = Count(); n < nEnd; ++n )
3181 {
3182 const sal_Int32 *pTmpHtEnd;
3183 const sal_Int32 *pTmpHintEnd;
3184 if (RES_TXTATR_REFMARK == (pTmpHt = Get(n))->Which() &&
3185 pHint->GetAttr() == pTmpHt->GetAttr() &&
3186 nullptr != ( pTmpHtEnd = pTmpHt->GetEnd() ) &&
3187 nullptr != ( pTmpHintEnd = pHint->GetEnd() ) )
3188 {
3190 pTmpHt->GetStart(), *pTmpHtEnd,
3191 pHint->GetStart(), *pTmpHintEnd );
3192 bool bDelOld = true, bChgStart = false, bChgEnd = false;
3193 switch( eCmp )
3194 {
3196 case SwComparePosition::Behind: bDelOld = false; break;
3197
3198 case SwComparePosition::Outside: bChgStart = bChgEnd = true; break;
3199
3201 case SwComparePosition::OverlapBefore: bChgStart = true; break;
3203 case SwComparePosition::OverlapBehind: bChgEnd = true; break;
3204 default: break;
3205 }
3206
3207 if( bChgStart )
3208 {
3209 pHint->SetStart( pTmpHt->GetStart() );
3210 }
3211 if( bChgEnd )
3212 pHint->SetEnd(*pTmpHtEnd);
3213
3214 if( bDelOld )
3215 {
3216 NoteInHistory( pTmpHt );
3217 rNode.DestroyAttr( Cut( n-- ) );
3218 --nEnd;
3219 }
3220 }
3221 }
3222 }
3223 break;
3224 case RES_TXTATR_TOXMARK:
3225 static_txtattr_cast<SwTextTOXMark*>(pHint)->ChgTextNode( &rNode );
3226 break;
3227
3229 static_txtattr_cast<SwTextRuby*>(pHint)->InitRuby(rNode);
3230 break;
3231
3232 case RES_TXTATR_META:
3234 static_txtattr_cast<SwTextMeta *>(pHint)->ChgTextNode( &rNode );
3235 break;
3236
3238 static_txtattr_cast<SwTextContentControl*>(pHint)->ChgTextNode( &rNode );
3239 break;
3240
3241 case RES_CHRATR_HIDDEN:
3242 rNode.SetCalcHiddenCharFlags();
3243 break;
3244 }
3245
3246 if( SetAttrMode::DONTEXPAND & nMode )
3247 pHint->SetDontExpand( true );
3248
3249 // special handling for SwTextAttrs without end:
3250 // 1) they cannot overlap
3251 // 2) if two fields are adjacent, they must not be merged into one
3252 // this is guaranteed by inserting a CH_TXTATR_* into the paragraph text!
3253 sal_Int32 nHtStart = pHint->GetStart();
3254 if( !pHtEnd )
3255 {
3256 Insert( pHint );
3257 NoteInHistory(pHint, true);
3258 CalcFlags();
3259#ifdef DBG_UTIL
3260 if( !rNode.GetDoc().IsInReading() )
3261 CHECK;
3262#endif
3263 // ... and notify listeners
3264 if(rNode.HasWriterListeners())
3265 {
3266 SwUpdateAttr aHint(
3267 nHtStart,
3268 nHtStart,
3269 nWhich);
3270
3271 rNode.TriggerNodeUpdate(sw::LegacyModifyHint(&aHint, &aHint));
3272 }
3273
3274 return true;
3275 }
3276
3277 // from here on, pHint is known to have an end index!
3278
3279 if( *pHtEnd < nHtStart )
3280 {
3281 assert(*pHtEnd >= nHtStart);
3282
3283 // just swap the nonsense:
3284 pHint->SetStart(*pHtEnd);
3285 pHint->SetEnd(nHtStart);
3286 nHtStart = pHint->GetStart();
3287 }
3288
3289 // I need this value later on for notification but the pointer may become invalid
3290 const sal_Int32 nHintEnd = *pHtEnd;
3291 const bool bNoHintAdjustMode = bool(SetAttrMode::NOHINTADJUST & nMode);
3292
3293 // handle nesting attributes: inserting may fail due to overlap!
3294 if (pHint->IsNesting())
3295 {
3296 const bool bRet(
3297 TryInsertNesting(rNode, *static_txtattr_cast<SwTextAttrNesting*>(pHint)));
3298 if (!bRet) return false;
3299 }
3300 // Currently REFMARK and TOXMARK have OverlapAllowed set to true.
3301 // These attributes may be inserted directly.
3302 // Also attributes without length may be inserted directly.
3303 // SETATTR_NOHINTADJUST is set e.g., during undo.
3304 // Portion building in not necessary during XML import.
3305 else if ( !bNoHintAdjustMode &&
3306 !pHint->IsOverlapAllowedAttr() &&
3307 !rNode.GetDoc().IsInXMLImport() &&
3308 ( RES_TXTATR_AUTOFMT == nWhich ||
3309 RES_TXTATR_CHARFMT == nWhich ) )
3310 {
3311 assert( nWhich != RES_TXTATR_AUTOFMT ||
3312 static_cast<const SwFormatAutoFormat&>(pHint->GetAttr()).GetStyleHandle()->GetPool() ==
3313 &rNode.GetDoc().GetAttrPool());
3314
3315 BuildPortions( rNode, *pHint, nMode );
3316
3317 if ( nHtStart < nHintEnd ) // skip merging for 0-length attributes
3318 MergePortions( rNode );
3319 }
3320 else
3321 {
3322 // There may be more than one character style at the current position.
3323 // Take care of the sort number.
3324 // FME 2007-11-08 #i82989# in NOHINTADJUST mode, we want to insert
3325 // character attributes directly
3326 if (!bNoHintAdjustMode
3327 && ( (RES_TXTATR_CHARFMT == nWhich)
3328 // tdf#149978 also for import of automatic styles, could be produced by non-LO application
3329 || (RES_TXTATR_AUTOFMT == nWhich && rNode.GetDoc().IsInXMLImport())))
3330 {
3331 BuildPortions( rNode, *pHint, nMode );
3332 }
3333 else
3334 {
3335 // #i82989# Check sort numbers in NoHintAdjustMode
3336 if ( RES_TXTATR_CHARFMT == nWhich )
3337 lcl_CheckSortNumber(*this, *static_txtattr_cast<SwTextCharFormat*>(pHint));
3338
3339 Insert( pHint );
3340 NoteInHistory( pHint, true );
3341 }
3342 }
3343
3344 // ... and notify listeners
3345 if ( rNode.HasWriterListeners() )
3346 {
3347 const SwUpdateAttr aHint(nHtStart, nHintEnd, nWhich, std::move(aWhichSublist));
3348 rNode.TriggerNodeUpdate(sw::LegacyModifyHint(&aHint, &aHint));
3349 }
3350
3351#ifdef DBG_UTIL
3352 if( !bNoHintAdjustMode && !rNode.GetDoc().IsInReading() )
3353 CHECK;
3354#endif
3355
3356 return true;
3357}
3358
3359void SwpHints::DeleteAtPos( const size_t nPos )
3360{
3361 assert(!m_bStartMapNeedsSorting && "deleting at pos and the list needs sorting?");
3362
3363 SwTextAttr *pHint = Get(nPos);
3364 assert( pHint->m_pHints == this );
3365 // ChainDelete( pHint );
3366 NoteInHistory( pHint );
3367
3368 // optimization: nPos is the position in the Starts array
3369 SwTextAttr *pHt = m_HintsByStart[ nPos ];
3370 m_HintsByStart.erase( m_HintsByStart.begin() + nPos );
3371
3375 ResortEndMap();
3378
3379 auto findIt = std::lower_bound(m_HintsByEnd.begin(), m_HintsByEnd.end(), pHt, CompareSwpHtEnd());
3380 assert(*findIt == pHt);
3381 m_HintsByEnd.erase(findIt);
3382
3383 auto findIt2 = std::lower_bound(m_HintsByWhichAndStart.begin(), m_HintsByWhichAndStart.end(), pHt, CompareSwpHtWhichStart());
3384 assert(*findIt2 == pHt);
3385 m_HintsByWhichAndStart.erase(findIt2);
3386
3387 pHt->m_pHints = nullptr;
3388
3389 if( pHint->Which() == RES_TXTATR_FIELD )
3390 {
3391 SwTextField *const pTextField(static_txtattr_cast<SwTextField*>(pHint));
3392 const SwFieldType* pFieldTyp = pTextField->GetFormatField().GetField()->GetTyp();
3393 if( SwFieldIds::Dde == pFieldTyp->Which() )
3394 {
3395 const SwTextNode* pNd = pTextField->GetpTextNode();
3396 if( pNd && pNd->GetNodes().IsDocNodes() )
3397 const_cast<SwDDEFieldType*>(static_cast<const SwDDEFieldType*>(pFieldTyp))->DecRefCnt();
3398 pTextField->ChgTextNode(nullptr);
3399 }
3400 else if (m_bHiddenByParaField
3401 && m_rParent.GetDoc().FieldCanHideParaWeight(pFieldTyp->Which()))
3402 {
3404 }
3405 }
3406 else if ( pHint->Which() == RES_TXTATR_ANNOTATION )
3407 {
3408 SwTextField *const pTextField(static_txtattr_cast<SwTextField*>(pHint));
3409 const_cast<SwFormatField&>(pTextField->GetFormatField()).Broadcast(
3411 }
3412
3413 CalcFlags();
3414 CHECK_NOTMERGED; // called from BuildPortions
3415}
3416
3419void SwpHints::Delete( SwTextAttr const * pTextHt )
3420{
3421 const size_t nPos = GetIndexOf( pTextHt );
3422 assert(SAL_MAX_SIZE != nPos);
3423 if( SAL_MAX_SIZE != nPos )
3424 DeleteAtPos( nPos );
3425}
3426
3427void SwTextNode::ClearSwpHintsArr( bool bDelFields )
3428{
3429 if ( !HasHints() )
3430 return;
3431
3432 size_t nPos = 0;
3433 while ( nPos < m_pSwpHints->Count() )
3434 {
3435 SwTextAttr* pDel = m_pSwpHints->Get( nPos );
3436 bool bDel = false;
3437
3438 switch( pDel->Which() )
3439 {
3440 case RES_TXTATR_FLYCNT:
3441 case RES_TXTATR_FTN:
3442 break;
3443
3444 case RES_TXTATR_FIELD:
3447 if( bDelFields )
3448 bDel = true;
3449 break;
3450 default:
3451 bDel = true; break;
3452 }
3453
3454 if( bDel )
3455 {
3456 m_pSwpHints->DeleteAtPos( nPos );
3457 DestroyAttr( pDel );
3458 }
3459 else
3460 ++nPos;
3461 }
3462}
3463
3464LanguageType SwTextNode::GetLang( const sal_Int32 nBegin, const sal_Int32 nLen,
3465 sal_uInt16 nScript ) const
3466{
3468
3469 if ( ! nScript )
3470 {
3471 nScript = g_pBreakIt->GetRealScriptOfText( m_Text, nBegin );
3472 }
3473
3474 // #i91465# Consider nScript if pSwpHints == 0
3475 const sal_uInt16 nWhichId = GetWhichOfScript( RES_CHRATR_LANGUAGE, nScript );
3476
3477 if ( HasHints() )
3478 {
3479 const sal_Int32 nEnd = nBegin + nLen;
3480 const size_t nSize = m_pSwpHints->Count();
3481 for ( size_t i = 0; i < nSize; ++i )
3482 {
3483 const SwTextAttr *pHt = m_pSwpHints->Get(i);
3484 const sal_Int32 nAttrStart = pHt->GetStart();
3485 if( nEnd < nAttrStart )
3486 break;
3487
3488 const sal_uInt16 nWhich = pHt->Which();
3489
3490 if( nWhichId == nWhich ||
3491 ( ( pHt->IsCharFormatAttr() || RES_TXTATR_AUTOFMT == nWhich ) && CharFormat::IsItemIncluded( nWhichId, pHt ) ) )
3492 {
3493 const sal_Int32 *pEndIdx = pHt->End();
3494 // do the attribute and the range overlap?
3495 if( !pEndIdx )
3496 continue;
3497 if( nLen )
3498 {
3499 if( nAttrStart >= nEnd || nBegin >= *pEndIdx )
3500 continue;
3501 }
3502 else if( nBegin != nAttrStart || ( nAttrStart != *pEndIdx && nBegin ))
3503 {
3504 if( nAttrStart >= nBegin )
3505 continue;
3506 if( pHt->DontExpand() ? nBegin >= *pEndIdx : nBegin > *pEndIdx)
3507 continue;
3508 }
3509 const SfxPoolItem* pItem = CharFormat::GetItem( *pHt, nWhichId );
3510 const LanguageType nLng = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
3511
3512 // does the attribute completely cover the range?
3513 if( nAttrStart <= nBegin && nEnd <= *pEndIdx )
3514 nRet = nLng;
3515 else if( LANGUAGE_DONTKNOW == nRet )
3516 nRet = nLng; // partial overlap, the first one wins
3517 }
3518 }
3519 }
3520 if( LANGUAGE_DONTKNOW == nRet )
3521 {
3522 nRet = static_cast<const SvxLanguageItem&>(GetSwAttrSet().Get( nWhichId )).GetLanguage();
3523 if( LANGUAGE_DONTKNOW == nRet )
3524 nRet = GetAppLanguage();
3525 }
3526 return nRet;
3527}
3528
3530{
3532 switch ( rAttr.Which() )
3533 {
3534 case RES_TXTATR_REFMARK:
3535 case RES_TXTATR_TOXMARK:
3537 cRet = CH_TXTATR_INWORD;
3538 break;
3539
3540 case RES_TXTATR_FIELD:
3541 case RES_TXTATR_FLYCNT:
3542 case RES_TXTATR_FTN:
3543 case RES_TXTATR_META:
3546 {
3547 cRet = CH_TXTATR_BREAKWORD;
3548 }
3549 break;
3551 {
3552 cRet = CH_TXTATR_NEWLINE;
3553 }
3554 break;
3555
3556 default:
3557 assert(!"GetCharOfTextAttr: unknown attr");
3558 break;
3559 }
3560 return cRet;
3561}
3562
3563/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XSLTFilter & m_rParent
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:34
virtual void InsDeletedFieldType(SwFieldType &)=0
virtual void InsDelFieldInFieldLst(bool bIns, const SwTextField &rField)=0
virtual bool IsNewFieldLst() const =0
virtual SwFieldType * InsertFieldType(const SwFieldType &)=0
virtual void DelLayoutFormat(SwFrameFormat *pFormat)=0
virtual SwCharFormat * GetCharFormatFromPool(sal_uInt16 nId)=0
virtual std::shared_ptr< SfxItemSet > getAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily, const OUString *pParentName=nullptr)=0
void ClearItem()
const SfxPoolItem * GetCurItem() const
const SfxPoolItem * NextItem()
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
const WhichRangesContainer & GetRanges() const
SfxItemPool * GetPool() const
sal_uInt16 Count() const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void Differentiate(const SfxItemSet &rSet)
void InvalidateItem(sal_uInt16 nWhich)
sal_uInt16 Which() const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
sal_uInt16 FirstWhich()
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 NextWhich()
bool IsCharBackground2Shading() const
static SvtFilterOptions & Get()
void SetTextLeft(const tools::Long nL, const sal_uInt16 nProp=100)
void SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp=100)
tools::Long GetIndentAt() const
tools::Long GetFirstLineIndent() const
SvxNumPositionAndSpaceMode GetPositionAndSpaceMode() const
sal_uInt16 GetRealScriptOfText(const OUString &rText, sal_Int32 nPos) const
Definition: breakit.cxx:84
Represents the style of a text portion.
Definition: charfmt.hxx:27
Marks a character position inside a document model content node (SwContentNode)
SwFormatColl * GetFormatColl() const
Definition: node.hxx:476
bool HasSwAttrSet() const
Definition: node.hxx:473
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:742
void DelFrames(SwRootFrame const *pLayout)
Method deletes all views of document for the node.
Definition: node.cxx:1424
sal_uInt16 ClearItemsFromAttrSet(const std::vector< sal_uInt16 > &rWhichIds)
There some functions that like to remove items from the internal SwAttrSet (handle):
Definition: node.cxx:1786
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:472
void DecRefCnt()
Definition: ddefld.hxx:98
Definition: doc.hxx:192
bool IsInReading() const
Definition: doc.hxx:958
bool FieldHidesPara(const SwField &rField) const
Definition: doc.cxx:1349
const SwCharFormat * GetDfltCharFormat() const
Definition: doc.hxx:757
bool IsInDtor() const
Definition: doc.hxx:408
bool IsClipBoard() const
Definition: doc.hxx:967
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:145
SwNodes & GetNodes()
Definition: doc.hxx:413
IStyleAccess & GetIStyleAccess()
Definition: doc.hxx:761
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:358
bool IsInXMLImport() const
Definition: doc.hxx:974
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:406
SwFootnoteIdxs & GetFootnoteIdxs()
Definition: doc.hxx:638
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:427
int FieldCanHideParaWeight(SwFieldIds eFieldId) const
Definition: doc.cxx:1334
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1322
::sw::MetaFieldManager & GetMetaFieldManager()
Definition: doc.cxx:129
SwDocShell * GetDocShell()
Definition: doc.hxx:1355
bool IsInHeaderFooter(const SwNode &) const
Definition: doclay.cxx:1550
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:242
SwFieldIds Which() const
Definition: fldbas.hxx:273
Base class of all fields.
Definition: fldbas.hxx:292
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:402
SwFieldType * GetTyp() const
Definition: fldbas.hxx:398
void UpdateFootnote(const SwNode &rStt)
Definition: ftnidx.cxx:59
FlyAnchors.
Definition: fmtanchr.hxx:37
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:67
const SwPosition * GetContentAnchor() const
Definition: fmtanchr.hxx:69
void SetStyleHandle(const std::shared_ptr< SfxItemSet > &pHandle)
Definition: fmtautofmt.hxx:48
const std::shared_ptr< SfxItemSet > & GetStyleHandle() const
Definition: fmtautofmt.hxx:49
SwCharFormat * GetCharFormat() const
Definition: fchrfmt.hxx:70
void SetCharFormat(SwFormat *pFormat)
Definition: fchrfmt.hxx:65
SfxPoolItem subclass that wraps an SwContentControl.
const std::shared_ptr< SwContentControl > & GetContentControl() const
const SwField * GetField() const
Definition: fmtfld.hxx:130
void RegisterToFieldType(SwFieldType &)
Definition: atrfld.cxx:171
Format of a fly content.
Definition: fmtflcnt.hxx:33
SwFrameFormat * GetFrameFormat() const
Definition: fmtflcnt.hxx:45
const SwTextFootnote * GetTextFootnote() const
Definition: fmtftn.hxx:85
SfxPoolItem subclass that wraps an SwLineBreakClear.
::sw::Meta * GetMeta()
Definition: fmtmeta.hxx:122
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:139
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:387
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:83
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
Templatized version of GetItemState() to directly return the correct type.
Definition: format.hxx:111
Style of a layout element.
Definition: frmfmt.hxx:62
static SwTOXType * GetSwTOXType(SwDoc &rDoc, TOXTypes eTOXTypes, const OUString &rTOXName)
Definition: rolbck.cxx:380
void Add(SwClient *pDepend)
Definition: calbck.cxx:172
bool HasWriterListeners() const
Definition: calbck.hxx:202
SwStartNode * GetStartNode()
Definition: node.hxx:619
SwNodeOffset GetIndex() const
Definition: node.hxx:296
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:721
SwDoc & GetDoc()
Definition: node.hxx:217
SwNodeOffset StartOfSectionIndex() const
Definition: node.hxx:701
Merge GetRedlineMergeFlag() const
Definition: node.hxx:100
IStyleAccess & getIDocumentStyleAccess()
Provides access to the document automatic styles interface.
Definition: node.cxx:2153
SwTableNode * GetTableNode()
Definition: node.hxx:627
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:158
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2531
SwNode & GetEndOfRedlines() const
Section for all Redlines.
Definition: ndarr.hxx:160
const SwNumFormat & Get(sal_uInt16 i) const
Definition: number.cxx:87
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
void SetName(const OUString &rStr)
Definition: docufld.cxx:1824
static void clearStatements(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType, const css::uno::Reference< css::rdf::XResource > &xSubject)
Remove all statements in the graph of type rType, if any exists.
Definition: rdfhelper.cxx:149
void ChangeNodeIndex(SwNodeOffset nNew)
Definition: rolbck.hxx:435
void AddHint(SwTextAttr *pHt, const bool bNew)
Definition: rolbck.cxx:1430
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
bool HasMergedParas() const
Definition: rootfrm.hxx:425
void SetSeqRefNo(SwSetExpField &rField)
Definition: expfld.cxx:575
void RegisterToTOXType(SwTOXType &rMark)
Definition: tox.cxx:141
const SwTOXType * GetTOXType() const
Definition: tox.hxx:576
const OUString & GetTypeName() const
Definition: tox.hxx:690
TOXTypes GetType() const
Definition: tox.hxx:693
SwDoc & GetDoc() const
Definition: tox.hxx:183
virtual const sal_Int32 * GetEnd() const override
end position
Definition: txatbase.cxx:77
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
static void Destroy(SwTextAttr *pToDestroy, SfxItemPool &rPool)
destroy instance
Definition: txatbase.cxx:58
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
void SetFormatIgnoreStart(bool bFlag)
Definition: txatbase.hxx:110
bool IsOverlapAllowedAttr() const
Definition: txatbase.hxx:102
virtual const sal_Int32 * GetEnd() const
end position
Definition: txatbase.cxx:48
bool IsFormatIgnoreStart() const
Definition: txatbase.hxx:108
bool IsNesting() const
Definition: txatbase.hxx:106
const sal_Int32 * End() const
Definition: txatbase.hxx:156
const SwFormatFlyCnt & GetFlyCnt() const
Definition: txatbase.hxx:226
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:187
virtual void SetEnd(sal_Int32)
Definition: txatbase.cxx:53
void SetFormatIgnoreEnd(bool bFlag)
Definition: txatbase.hxx:111
void SetStart(sal_Int32 n)
start position
Definition: txatbase.hxx:87
bool IsCharFormatAttr() const
Definition: txatbase.hxx:101
bool DontExpand() const
Definition: txatbase.hxx:98
const SwFormatAutoFormat & GetAutoFormat() const
Definition: txatbase.hxx:193
bool HasContent() const
Definition: txatbase.hxx:112
void SetDontExpand(bool bDontExpand)
Definition: txatbase.hxx:179
bool HasDummyChar() const
Definition: txatbase.hxx:107
sal_uInt16 Which() const
Definition: txatbase.hxx:116
SwpHints * m_pHints
Definition: txatbase.hxx:67
bool IsFormatIgnoreEnd() const
Definition: txatbase.hxx:109
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
void SetSortNumber(sal_uInt16 nSortNumber)
Definition: txtatr.hxx:48
static SwTextContentControl * CreateTextContentControl(SwTextNode *pTargetTextNode, SwFormatContentControl &rAttr, sal_Int32 nStart, sal_Int32 nEnd, bool bIsCopy)
void ChgTextNode(SwTextNode *pNew)
Definition: txtfld.hxx:58
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
void SetAnchor(const SwTextNode *pNode)
SetAnchor() is called by SwTextNode::InsertHint() and sets the anchor position in the SwFlyFrameForma...
Definition: atrflyin.cxx:126
sal_uInt16 GetSeqRefNo() const
Definition: txtftn.hxx:64
SAL_DLLPRIVATE void InitINetFormat(SwTextNode &rNode)
Definition: thints.cxx:219
void ChgTextNode(SwTextNode *pNew)
Definition: txtinet.hxx:48
OUString GetFieldContent() const
Definition: atrfld.cxx:691
SwTextAttr subclass that tracks the location of the wrapped SwFormatLineBreak.
static SwTextMeta * CreateTextMeta(::sw::MetaFieldManager &i_rTargetDocManager, SwTextNode *const i_pTargetTextNode, SwFormatMeta &i_rAttr, sal_Int32 const i_nStart, sal_Int32 const i_nEnd, bool const i_bIsCopy)
Definition: txtatr2.cxx:258
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:86
OUString m_Text
Definition: ndtxt.hxx:102
void DeleteAttributes(const sal_uInt16 nWhich, const sal_Int32 nStart, const sal_Int32 nEnd=0)
delete all attributes of type nWhich at nStart (opt. end nEnd)
Definition: thints.cxx:1802
const SwTextInputField * GetOverlappingInputField(const SwTextAttr &rTextAttr) const
Definition: ndtxt.cxx:1781
virtual sal_Int32 Len() const override
Definition: ndtxt.cxx:275
void RstTextAttr(const SwContentIndex &rIdx, const sal_Int32 nLen, const sal_uInt16 nWhich=0, const SfxItemSet *pSet=nullptr, const bool bInclRefToxMark=false, const bool bExactRange=false)
delete all attributes.
Definition: txtedt.cxx:367
SwpHints & GetOrCreateSwpHints()
Definition: ndtxt.hxx:853
bool GetParaAttr(SfxItemSet &rSet, sal_Int32 nStt, sal_Int32 nEnd, const bool bOnlyTextAttr=false, const bool bGetFromChrFormat=true, const bool bMergeIndentValuesOfNumRule=false, SwRootFrame const *pLayout=nullptr) const
Query the attributes of textnode over the range.
Definition: thints.cxx:2135
void DeleteAttribute(SwTextAttr *const pTextAttr)
delete the attribute pTextAttr
Definition: thints.cxx:1764
void DestroyAttr(SwTextAttr *pAttr)
Definition: thints.cxx:1186
SwTextAttr * InsertItem(SfxPoolItem &rAttr, const sal_Int32 nStart, const sal_Int32 nEnd, const SetAttrMode nMode=SetAttrMode::DEFAULT)
create new text attribute from rAttr and insert it
Definition: thints.cxx:1305
void FormatToTextAttr(SwTextNode *pNd)
Convey attributes of an AttrSet (AutoFormat) to SwpHintsArray.
Definition: thints.cxx:2534
void DelSoftHyph(const sal_Int32 nStart, const sal_Int32 nEnd)
Definition: thints.cxx:1877
void TryDeleteSwpHints()
Definition: ndtxt.hxx:862
void ClearSwpHintsArr(bool bDelFields)
Definition: thints.cxx:3427
virtual bool SetAttr(const SfxPoolItem &) override
overriding to handle change of certain paragraph attributes
Definition: ndtxt.cxx:4990
std::unique_ptr< SwpHints > m_pSwpHints
May be 0.
Definition: ndtxt.hxx:96
void EraseText(const SwContentIndex &rIdx, const sal_Int32 nCount=SAL_MAX_INT32, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
delete text content ATTENTION: must not be called with a range that overlaps the start of an attribut...
Definition: ndtxt.cxx:2724
SwTextAttr * GetTextAttrAt(sal_Int32 const nIndex, sal_uInt16 const nWhich, enum GetTextAttrMode const eMode=DEFAULT) const
get the innermost text attribute covering position nIndex.
Definition: ndtxt.cxx:1763
bool HasHints() const
Definition: ndtxt.hxx:232
OUString InsertText(const OUString &rStr, const SwContentIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2322
void SetCalcHiddenCharFlags() const
Definition: ndtxt.hxx:756
static bool IsIgnoredCharFormatForNumbering(const sal_uInt16 nWhich, bool bIsCharStyle=false)
In MS Word, the font underline setting of the paragraph end position won't affect the formatting of n...
Definition: thints.cxx:1894
SwNumRule * GetNumRule(bool bInParent=true) const
Returns numbering rule of this text node.
Definition: ndtxt.cxx:2870
int GetActualListLevel(SwListRedlineType eRedline=SwListRedlineType::SHOW) const
Returns the actual list level of this text node, when it is a list item.
Definition: ndtxt.cxx:4186
void SetCalcHiddenParaField()
set CalcVisible flags
Definition: ndtxt.hxx:740
virtual void Update(SwContentIndex const &rPos, const sal_Int32 nChangeLen, UpdateMode eMode) override
override SwContentIndexReg
Definition: ndtxt.cxx:1226
SAL_DLLPRIVATE void impl_FormatToTextAttr(const SfxItemSet &i_rAttrSet)
Does the hard work of SwTextNode::FormatToTextAttr: the real conversion of items to automatic styles.
Definition: thints.cxx:2468
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:230
bool AreListLevelIndentsApplicable() const
Determines, if the list level indent attributes can be applied to the paragraph.
Definition: ndtxt.cxx:4552
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5363
bool InsertHint(SwTextAttr *const pAttr, const SetAttrMode nMode=SetAttrMode::DEFAULT)
Insert pAttr into hints array.
Definition: thints.cxx:1340
LanguageType GetLang(const sal_Int32 nBegin, const sal_Int32 nLen=0, sal_uInt16 nScript=0) const
Definition: thints.cxx:3464
@ PARENT
EXPAND : (Start < nIndex <= End)
Definition: ndtxt.hxx:380
bool DontExpandFormat(sal_Int32 nContentIdx, bool bFlag=true, bool bFormatToTextAttributes=true)
When appropriate set DontExpand-flag at INet or character styles respectively.
Definition: ndtxt.cxx:1643
SAL_DLLPRIVATE void InitRuby(SwTextNode &rNode)
Definition: thints.cxx:227
void ChgTextNode(SwTextNode *pNew)
Definition: txtatr.hxx:87
The shared part of a user field.
Definition: usrfld.hxx:35
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:68
SW_DLLPUBLIC void ResortWhichMap() const
Definition: ndhints.cxx:454
bool m_bFootnote
footnotes
Definition: ndhints.hxx:89
std::vector< SwTextAttr * > m_HintsByWhichAndStart
Definition: ndhints.hxx:78
std::vector< SwTextAttr * > m_HintsByEnd
Definition: ndhints.hxx:77
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
bool m_bEndMapNeedsSorting
Definition: ndhints.hxx:93
SwTextAttr * GetWithoutResorting(size_t nPos) const
Definition: ndhints.hxx:152
bool CalcHiddenParaField() const
Definition: thints.cxx:2652
void Delete(SwTextAttr const *pTextHt)
Delete the given Hint. The Hint must actually be in the array!
Definition: thints.cxx:3419
bool m_bDDEFields
the TextNode has DDE fields
Definition: ndhints.hxx:90
size_t GetIndexOf(const SwTextAttr *pHt) const
Definition: ndhints.cxx:482
SwTextAttr * Cut(const size_t nPosInStart)
Definition: ndhints.hxx:185
void SetHiddenByParaField(const bool bNew) const
Definition: ndhints.hxx:111
bool m_bHiddenByParaField
Definition: ndhints.hxx:88
void InsertNesting(SwTextAttrNesting &rNewHint)
Insert nesting hint into the hints array.
Definition: thints.cxx:301
SW_DLLPUBLIC void Resort() const
Definition: ndhints.cxx:412
size_t Count() const
Definition: ndhints.hxx:142
static const size_t MAX_HINTS
Definition: ndhints.hxx:74
SwpHints(const SwTextNode &rParent)
Definition: thints.cxx:92
SwTextAttr * GetSortedByEnd(size_t nPos) const
Definition: ndhints.hxx:158
bool m_bCalcHiddenParaField
Definition: ndhints.hxx:85
bool TryInsertNesting(SwTextNode &rNode, SwTextAttrNesting &rNewHint)
The following hints correspond to well-formed XML elements in ODF: RES_TXTATR_INETFMT,...
Definition: thints.cxx:378
const SwTextNode & m_rParent
Definition: ndhints.hxx:70
void Insert(SwTextAttr *pHt)
Definition: ndhints.cxx:145
bool m_bWhichMapNeedsSorting
Definition: ndhints.hxx:94
std::vector< SwTextAttr * > m_HintsByStart
Definition: ndhints.hxx:76
SwRegHistory * m_pHistory
for Undo
Definition: ndhints.hxx:80
bool MergePortions(SwTextNode &rNode)
Definition: thints.cxx:2710
void NoteInHistory(SwTextAttr *pAttr, const bool bNew=false)
records a new attribute in m_pHistory.
Definition: thints.cxx:2689
void DeleteAtPos(size_t nPos)
Definition: thints.cxx:3359
bool m_bStartMapNeedsSorting
Definition: ndhints.hxx:92
void CalcFlags()
Definition: thints.cxx:2623
bool TryInsertHint(SwTextAttr *const pHint, SwTextNode &rNode, const SetAttrMode nMode=SetAttrMode::DEFAULT)
try to insert the hint
Definition: thints.cxx:3027
SW_DLLPUBLIC void ResortStartMap() const
Definition: ndhints.cxx:434
SW_DLLPUBLIC void ResortEndMap() const
Definition: ndhints.cxx:444
SwRegHistory * GetHistory() const
Definition: ndhints.hxx:198
void BuildPortions(SwTextNode &rNode, SwTextAttr &rNewHint, const SetAttrMode nMode)
Definition: thints.cxx:635
const_iterator upper_bound(const Value &x) const
const_iterator begin() const
size_type erase(const Value &x)
std::pair< const_iterator, bool > insert(Value &&x)
const_iterator lower_bound(const Value &x) const
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:325
int nCount
float u
std::deque< AttacherIndex_Impl > aIndex
@ Database
For old documents the Field-Which IDs must be preserved !!!
#define CH_TXT_ATR_INPUTFIELDSTART
Definition: hintids.hxx:177
constexpr TypedWhichId< SvxCrossedOutItem > RES_CHRATR_CROSSEDOUT(5)
bool isTXTATR_WITHEND(const sal_uInt16 nWhich)
Definition: hintids.hxx:483
bool isTXTATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:491
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(59)
constexpr TypedWhichId< SvxUnderlineItem > RES_CHRATR_UNDERLINE(14)
bool isUNKNOWNATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:519
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:479
constexpr sal_uInt16 RES_CHRATR_END(46)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_LANGUAGE(10)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_WEIGHT(15)
constexpr sal_uInt16 RES_TXTATR_WITHEND_END(57)
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CTL_WEIGHT(31)
constexpr TypedWhichId< SvxCharHiddenItem > RES_CHRATR_HIDDEN(37)
constexpr TypedWhichId< SvxEscapementItem > RES_CHRATR_ESCAPEMENT(6)
constexpr TypedWhichId< SwFormatAnchor > RES_ANCHOR(104)
constexpr sal_uInt16 RES_TXTATR_BEGIN(RES_CHRATR_END)
constexpr TypedWhichId< SvxBrushItem > RES_CHRATR_BACKGROUND(21)
constexpr TypedWhichId< SvxCaseMapItem > RES_CHRATR_CASEMAP(RES_CHRATR_BEGIN)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CTL_POSTURE(30)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(159)
constexpr sal_uInt16 RES_CHRATR_BEGIN(HINT_BEGIN)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
constexpr TypedWhichId< SwFormatContentControl > RES_TXTATR_CONTENTCONTROL(56)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(58)
constexpr TypedWhichId< SwFormatLineBreak > RES_TXTATR_LINEBREAK(61)
constexpr TypedWhichId< SvxRsidItem > RES_CHRATR_RSID(39)
#define CH_TXTATR_INWORD
Definition: hintids.hxx:174
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_METAFIELD(49)
constexpr TypedWhichId< SvXMLAttrContainerItem > RES_TXTATR_UNKNOWN_CONTAINER(54)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
constexpr TypedWhichId< SwFormatRefMark > RES_TXTATR_REFMARK(RES_TXTATR_WITHEND_BEGIN)
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_META(48)
#define CH_TXT_ATR_INPUTFIELDEND
Definition: hintids.hxx:178
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_CJK_POSTURE(25)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
constexpr TypedWhichId< SwTOXMark > RES_TXTATR_TOXMARK(47)
constexpr TypedWhichId< SwFormatRuby > RES_TXTATR_CJK_RUBY(53)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
constexpr TypedWhichId< SvxColorItem > RES_CHRATR_COLOR(3)
constexpr sal_uInt16 RES_TXTATR_END(RES_TXTATR_NOEND_END)
#define CH_TXTATR_NEWLINE
Definition: hintids.hxx:176
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:173
sal_uInt16 GetWhichOfScript(sal_uInt16 nWhich, sal_uInt16 nScript)
Definition: hints.cxx:194
WhichRangesContainer const aCharFormatSetRange(svl::Items< RES_CHRATR_BEGIN, RES_CHRATR_END-1, RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1 >)
LanguageType GetAppLanguage()
Definition: init.cxx:725
WhichRangesContainer const aCharAutoFormatSetRange(svl::Items< RES_CHRATR_BEGIN, RES_CHRATR_END-1, RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER, RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1 >)
sal_Int64 n
#define LANGUAGE_DONTKNOW
sal_uInt16 nPos
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
Returns the item set associated with a character/inet/auto style.
Definition: atrstck.cxx:133
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
Extracts pool item of type nWhich from rAttr.
Definition: atrstck.cxx:157
bool IsItemIncluded(const sal_uInt16 nWhich, const SwTextAttr *pAttr)
Checks if item is included in character/inet/auto style.
Definition: atrstck.cxx:177
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
size
int i
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:205
Count
SwTextNode const & GetAttrMerged(SfxItemSet &rFormatSet, SwTextNode const &rNode, SwRootFrame const *pLayout)
Definition: txtfrm.cxx:370
void CalcBreaks(std::vector< std::pair< SwNodeOffset, sal_Int32 > > &rBreaks, SwPaM const &rPam, bool const isOnlyFieldmarks)
CopyOrNewType
Definition: ndhints.hxx:33
SwComparePosition ComparePosition(const T &rStt1, const T &rEnd1, const T &rStt2, const T &rEnd2)
Definition: pam.hxx:122
SwComparePosition
Definition: pam.hxx:109
@ OverlapBehind
Pos1 overlaps Pos2 at the end.
@ CollideEnd
Pos1 end touches at Pos2 start.
@ Behind
Pos1 behind Pos2.
@ OverlapBefore
Pos1 overlaps Pos2 at the beginning.
@ Outside
Pos2 completely contained in Pos1.
@ Before
Pos1 before Pos2.
@ Inside
Pos1 completely contained in Pos2.
@ CollideStart
Pos1 start touches at Pos2 end.
@ Equal
Pos1 is as large as Pos2.
@ RES_POOLCHR_INET_NORMAL
Internet normal.
Definition: poolfmt.hxx:120
@ RES_POOLCHR_RUBYTEXT
Rubytext.
Definition: poolfmt.hxx:129
#define INVALID_POOL_ITEM
bool IsInvalidItem(const SfxPoolItem *pItem)
static SfxItemSet & rSet
SwNode & GetNode() const
Definition: pam.hxx:80
SwContentIndex nContent
Definition: pam.hxx:39
Reference< XModel > xModel
SetAttrMode
Definition: swtypes.hxx:133
@ NOHINTEXPAND
for Undo, translated to SwInsertFlags::NOHINTEXPAND
@ FORCEHINTEXPAND
Force hint expand (only matters for hints with CH_TXTATR).
@ IS_COPY
The inserted item is a copy – intended for use in ndtxt.cxx.
@ NOHINTADJUST
attention: NOHINTADJUST prevents MergePortions! when using this need to pay attention to ignore start...
#define CHAR_SOFTHYPHEN
Definition: swtypes.hxx:163
constexpr sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:57
static bool isNestedAny(const sal_Int32 nStart1, const sal_Int32 nEnd1, const sal_Int32 nStart2, const sal_Int32 nEnd2)
#i106930#: now asymmetric: empty hint1 is not nested, but empty hint2 is
Definition: thints.cxx:152
static bool TextAttrContains(const sal_Int32 nPos, const SwTextAttrEnd *const pAttr)
Definition: thints.cxx:120
static void lcl_MergeAttr_ExpandChrFormat(SfxItemSet &rSet, const SfxPoolItem &rAttr)
Definition: thints.cxx:2061
static void TextAttrDelete(SwDoc &rDoc, SwTextAttr *const pAttr)
Definition: thints.cxx:106
#define CHECK
Definition: thints.cxx:84
sal_Unicode GetCharOfTextAttr(const SwTextAttr &rAttr)
Definition: thints.cxx:3529
SwTextAttr * MakeTextAttr(SwDoc &rDoc, SfxPoolItem &rAttr, sal_Int32 const nStt, sal_Int32 const nEnd, CopyOrNewType const bIsCopy, SwTextNode *const pTextNode)
if COPY then pTextNode must be given!
Definition: thints.cxx:1030
static bool isSplittable(const sal_uInt16 nWhich)
Definition: thints.cxx:175
static bool isOverlap(const sal_Int32 nStart1, const sal_Int32 nEnd1, const sal_Int32 nStart2, const sal_Int32 nEnd2)
Definition: thints.cxx:142
static void lcl_MergeListLevelIndentAsLRSpaceItem(const SwTextNode &rTextNode, SfxItemSet &rSet)
Definition: thints.cxx:2114
static MergeResult lcl_Compare_Attributes(int i, int j, const std::pair< PortionMap::const_iterator, PortionMap::const_iterator > &aRange1, const std::pair< PortionMap::const_iterator, PortionMap::const_iterator > &aRange2, std::vector< bool > &RsidOnlyAutoFormatFlagMap)
Definition: thints.cxx:2880
static void lcl_MergeAttr(SfxItemSet &rSet, const SfxPoolItem &rAttr)
Definition: thints.cxx:2038
static void lcl_DoSplitNew(NestList_t &rSplits, SwTextNode &rNode, const sal_Int32 nNewStart, const sal_Int32 nOtherStart, const sal_Int32 nOtherEnd, bool bOtherDummy)
Definition: thints.cxx:279
SwTextAttr * MakeRedlineTextAttr(SwDoc &rDoc, SfxPoolItem const &rAttr)
create redline dummy text hint that must not be inserted into hints array
Definition: thints.cxx:1000
std::vector< SwTextAttrNesting * > NestList_t
Definition: thints.cxx:263
#define CHECK_NOTMERGED
Definition: thints.cxx:85
static void lcl_CheckSortNumber(const SwpHints &rHints, SwTextCharFormat &rNewCharFormat)
Definition: thints.cxx:2990
static NestList_t::iterator lcl_DoSplitImpl(NestList_t &rSplits, SwTextNode &rNode, NestList_t::iterator const iter, sal_Int32 const nSplitPos, bool const bSplitAtStart, bool const bOtherDummy)
Definition: thints.cxx:266
static Split_t splitPolicy(const sal_uInt16 nWhichNew, const sal_uInt16 nWhichOther)
Calculate splitting policy for overlapping hints, based on what kind of hint is inserted,...
Definition: thints.cxx:198
static bool isSelfNestable(const sal_uInt16 nWhich)
Definition: thints.cxx:162
static SwTextAttrNesting * MakeTextAttrNesting(SwTextNode &rNode, SwTextAttrNesting &rNesting, const sal_Int32 nStart, const sal_Int32 nEnd)
Create a new nesting text hint.
Definition: thints.cxx:239
sal_uInt16 sal_Unicode