26 #include <osl/diagnose.h>
29 css::uno::Reference< css::container::XStringKeyMap >
const & xPropertyBag,
32 :
maType(rType), mnPos(nPos), mnLen(nLen), mpSubList(nullptr)
39 css::uno::Reference< css::container::XStringKeyMap >
const & xPropertyBag,
45 if (pSubList !=
nullptr)
81 i.mpSubList =
i.mpSubList->Clone();
90 i.mpSubList =
nullptr;
105 if ( nPos >=
Count() )
107 const sal_Int32 nWrPos =
Pos( nPos );
108 if ( nWrPos <= rChk )
111 if( nWrPos + rLn <= rChk )
131 if( nPos ==
Count() )
134 sal_Int32 nWrPos =
Pos( nPos );
135 sal_Int32 nEnd = nWrPos +
Len( nPos );
139 if( nPos ==
Count() )
142 nWrPos =
Pos( nPos );
143 nEnd = nWrPos +
Len( nPos );
145 if( nEnd > rChk && nWrPos < rLn )
170 if( nRet < nChk && nRet +
Len( nPos ) <= nChk )
172 if( ++nPos <
Count() )
192 sal_uInt16 nMax =
Count();
203 return (rST.mnPos <= nValue && nValue < rST.mnPos + rST.mnLen)
204 || (rST.mnPos > nValue);
206 return static_cast<sal_uInt16
>(std::distance(
maList.begin(), aIter));
211 while( nMin <= nMax )
213 nMid = nMin + ( nMax - nMin ) / 2;
214 const sal_Int32 nTmp =
Pos( nMid );
220 else if( nTmp < nValue )
222 if( nTmp +
Len( nMid ) >= nValue )
271 const sal_Int32 nEnd = nPos - nDiff;
274 while( nLst <
Count() &&
Pos( nLst ) < nEnd )
278 const sal_Int32 nWrPos =
Pos( nLst - 1 );
279 if ( nWrPos <= nPos )
281 sal_Int32 nWrLen =
Len( nLst - 1 );
283 nWrLen = ( nEnd > nWrPos + nWrLen ) ?
288 maList[--nLst].mnLen = nWrLen;
298 SetInvalid( nPos ? nPos - 1 : nPos, nPos + 1 );
309 const sal_Int32 nEnd = nPos + nDiff;
321 const sal_Int32 nWrPos =
Pos( i );
325 const sal_Int32 nWrLen =
Len( i ) + nDiff;
326 maList[i++].mnLen = nWrLen;
335 maList[i++].mnPos += nDiff;
356 sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos ) ->
FreshState
362 ? (nCursorPos >
nPos + nLen || nCursorPos <
nPos)
365 : FreshState::NOTHING;
367 sal_Int32 nWrPos = 0;
368 sal_Int32 nWrEnd = rEnd;
372 nWrPos =
Pos( nCnt );
373 if( nWrPos < nPos && rStart > nWrPos )
377 while( nCnt <
Count() )
379 nWrPos =
Pos( nCnt );
380 if ( nWrPos >=
nPos )
382 nWrEnd = nWrPos + Len( nCnt++ );
385 if( nCnt <
Count() && nWrPos ==
nPos && Len( nCnt ) == nLen )
388 eRet = FreshState::FRESH;
392 if (FreshState::FRESH == eRet)
396 nWrEnd =
nPos + nLen;
404 nWrPos =
Pos( nCnt );
405 if( nWrPos < nPos && rStart > nWrPos )
409 while( nCnt <
Count() )
411 nWrPos =
Pos( nCnt );
412 if ( nWrPos >=
nPos )
414 nWrEnd = nWrPos + Len( nCnt++ );
437 const sal_Int32 nFirst =
Pos( 0 );
449 while( nLst <
Count() &&
Pos( nLst ) < nSplitPos )
453 sal_Int32 nWrPos =
Pos( nLst - 1 );
454 sal_Int32 nWrLen =
Len( nLst - 1 );
455 if ( nWrPos+nWrLen > nSplitPos )
457 nWrLen += nWrPos - nSplitPos;
458 maList[--nLst].mnPos = nSplitPos;
459 maList[nLst].mnLen = nWrLen;
470 pRet->
Invalidate_( nSplitPos ? nSplitPos - 1 : nSplitPos, nSplitPos );
482 for (nLst = 0; nLst <
Count(); ++nLst )
484 maList[nLst].mnPos -= nSplitPos;
495 sal_uInt16 nCnt =
Count();
496 pNext->
Move( 0, nInsertPos );
500 if( nCnt &&
Count() > nCnt )
502 sal_Int32 nWrPos =
Pos( nCnt );
503 sal_Int32 nWrLen =
Len( nCnt );
506 nWrPos += nInsertPos;
507 nWrLen -= nInsertPos;
508 maList[nCnt].mnPos = nWrPos;
509 maList[nCnt].mnLen = nWrLen;
511 if( nWrPos ==
Pos( nCnt - 1 ) +
Len( nCnt - 1 ) )
513 nWrLen +=
Len( nCnt - 1 );
514 maList[nCnt - 1].mnLen = nWrLen;
519 Invalidate( nInsertPos ? nInsertPos - 1 : nInsertPos, nInsertPos + 1 );
528 std::vector<SwWrongArea>::iterator
i =
maList.begin();
529 if ( nWhere >=
maList.size() )
533 maList.insert(i,
SwWrongArea( OUString(),
nullptr, nNewPos, nNewLen, pSubList ) );
537 void SwWrongList::Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator
const & endPos)
539 std::vector<SwWrongArea>::iterator
i =
maList.begin();
540 if ( nWhere >=
maList.size() )
544 maList.insert(i, startPos, endPos);
548 while ( startPos != endPos )
550 (*startPos).mpSubList =
nullptr;
557 if ( nIdx >=
maList.size() )
return;
558 std::vector<SwWrongArea>::iterator i1 =
maList.begin();
561 std::vector<SwWrongArea>::iterator i2 = i1;
562 if ( nIdx + nLen >= static_cast<sal_uInt16>(
maList.size()) )
567 std::vector<SwWrongArea>::iterator iLoop = i1;
568 while ( iLoop != i2 )
570 delete (*iLoop).mpSubList;
574 #if OSL_DEBUG_LEVEL > 0
575 const int nOldSize =
Count();
580 #if OSL_DEBUG_LEVEL > 0
581 OSL_ENSURE(
Count() + nLen == nOldSize,
"SwWrongList::Remove() trouble" );
586 std::vector<SwWrongArea>::const_iterator aEnd(
maList.end());
587 auto aDelIter = std::find_if(
maList.cbegin(), aEnd,
588 [nBegin](
const SwWrongArea& rST) {
return rST.mnPos >= nBegin; });
589 auto aIter = aDelIter;
594 aIter = std::find_if(aDelIter, aEnd,
600 aIter = std::find_if(aDelIter, aEnd,
605 auto nDel =
static_cast<sal_uInt16
>(std::distance(aDelIter, aIter));
608 auto nDelPos =
static_cast<sal_uInt16
>(std::distance(
maList.cbegin(), aDelIter));
615 [nBegin](
const SwWrongArea& rST) {
return rST.mnPos >= nBegin; });
616 return aIter !=
maList.end()
617 && nBegin == (*aIter).mnPos
618 && nEnd == (*aIter).mnPos + (*aIter).mnLen;
622 css::uno::Reference< css::container::XStringKeyMap >
const & xPropertyBag,
623 sal_Int32 nNewPos, sal_Int32 nNewLen )
626 [nNewPos](
const SwWrongArea& rST) {
return nNewPos <= rST.mnPos; });
627 if ( aIter !=
maList.end() && nNewPos == (*aIter).mnPos )
629 const sal_Int32 nSTPos = (*aIter).mnPos;
631 aIter = std::find_if(aIter,
maList.end(),
632 [nSTPos, nNewLen](
const SwWrongArea& rST) {
return rST.mnPos != nSTPos || nNewLen < rST.mnLen; });
642 : m_pGetWrongList(pGetWrongList)
643 , m_pMergedPara(rFrame.GetMergedPara())
646 , m_pWrongList(m_pMergedPara
648 : (rFrame.GetTextNodeFirst()->*pGetWrongList)())
653 : m_pGetWrongList(nullptr)
654 , m_pMergedPara(nullptr)
657 , m_pWrongList(&rWrongList)
681 while (m_CurrentExtent < m_pMergedPara->extents.size())
691 assert(0 < sal_Int32(rLen));
701 if (sal_Int32(rLen) < rExtent.
nEnd - nStart)
703 nLen = sal_Int32(rLen);
707 sal_Int32 nInLen(rLen);
708 nLen = rExtent.
nEnd - nStart;
720 if (nInLen <= rExtentEnd.
nEnd - rExtentEnd.
nStart)
726 nInLen -= rExtentEnd.
nEnd - rExtentEnd.
nStart;
729 if (pWrongList && pWrongList->
Check(nStart, nLen))
732 if (rExtent.
nStart <= nStart && nStart < rExtent.
nEnd)
735 sal_Int32
const nEnd(nStart + nLen);
737 TextFrameIndex
const nOrigLen(rLen);
738 if (nEnd <= rExtent.
nEnd)
750 || nEnd <= rExtentEnd.
nStart)
754 if (nEnd <= rExtentEnd.
nEnd)
774 sal_Int32 nStart(rStart);
775 sal_Int32 nLen(rLen);
794 while (m_CurrentExtent < m_pMergedPara->extents.size())
841 SwNode const* pNode(
nullptr);
842 sal_uInt16 InCurrentNode(0);
843 while (m_CurrentExtent < m_pMergedPara->extents.size())
846 if (rExtent.
pNode != pNode)
849 pNode = rExtent.
pNode;
852 for (; pWrongList && InCurrentNode < pWrongList->
Count(); ++InCurrentNode)
878 std::optional<std::pair<TextFrameIndex, TextFrameIndex>>
885 SwNode const* pNode(
nullptr);
886 sal_uInt16 InCurrentNode(0);
887 while (m_CurrentExtent < m_pMergedPara->extents.size())
890 if (rExtent.
pNode != pNode)
893 pNode = rExtent.
pNode;
896 for (; pWrongList && InCurrentNode < pWrongList->
Count(); ++InCurrentNode)
909 return std::optional<std::pair<TextFrameIndex, TextFrameIndex>>(
910 std::pair<TextFrameIndex, TextFrameIndex>(
912 std::max(rExtent.
nStart, pWrong->mnPos)),
914 std::min(pWrong->mnPos + pWrong->mnLen, rExtent.
nEnd))));
922 return std::optional<std::pair<TextFrameIndex, TextFrameIndex>>();
927 return std::optional<std::pair<TextFrameIndex, TextFrameIndex>>(
928 std::pair<TextFrameIndex, TextFrameIndex>(
932 return std::optional<std::pair<TextFrameIndex, TextFrameIndex>>();
sal_Int32 Pos(sal_uInt16 nIdx) const
Represents the visualization of a paragraph.
const SwWrongArea * GetWrongElement(TextFrameIndex nStart)
void Invalidate_(sal_Int32 nBegin, sal_Int32 nEnd)
FreshState Fresh(sal_Int32 &rStart, sal_Int32 &rEnd, sal_Int32 nPos, sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos)
Remove given range of entries.
void Move(sal_Int32 nPos, sal_Int32 nDiff)
Change all values after the given position.
SwWrongList const *const m_pWrongList
void InsertSubList(sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere, SwWrongList *pSubList)
WrongAreaLineType mLineType
Dialog to specify the properties of date form field.
static WrongAreaLineType getWrongAreaLineType(WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
WrongListIteratorBase(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
for the text frame
void RemoveEntry(sal_Int32 nBegin, sal_Int32 nEnd)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
virtual void CopyFrom(const SwWrongList &rCopy)
void Remove(sal_uInt16 nIdx, sal_uInt16 nLen)
void JoinList(SwWrongList *pNext, sal_Int32 nInsertPos)
std::vector< Extent > extents
virtual SwWrongList * Clone()
Describes a part of a single text node, which will be part of a text frame, even when redlines are hi...
sal_Int32 NextWrong(sal_Int32 nChk) const
Find next incorrectly selected position.
static Color getWrongAreaColor(WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
SwWrongList const *(SwTextNode::*const m_pGetWrongList)() const
SwWrongList * SplitList(sal_Int32 nSplitPos)
sw::MergedPara const *const m_pMergedPara
sal_Int32 Len(sal_uInt16 nIdx) const
bool LookForEntry(sal_Int32 nBegin, sal_Int32 nEnd)
void Invalidate(sal_Int32 nBegin, sal_Int32 nEnd)
bool Check(sal_Int32 &rChk, sal_Int32 &rLn) const
Calculate first incorrectly selected area.
sal_Int32 GetEndInv() const
WrongListIteratorCounter(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
bool Check(TextFrameIndex &rStart, TextFrameIndex &rLen)
SwTextNode is a paragraph in the document model.
WrongListType GetWrongListType() const
sal_Int32 GetBeginInv() const
WrongListIterator(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
for the text frame
sal_uInt16 GetWrongPos(sal_Int32 nValue) const
Find the first position that is greater or equal to the given value.
bool InWrongWord(sal_Int32 &rChk, sal_Int32 &rLn) const
If a word is incorrectly selected, this method returns begin and length of it.
static void ShiftLeft(sal_Int32 &rPos, sal_Int32 nStart, sal_Int32 nEnd)
const SwWrongArea * GetElement(sal_uInt16 nIdx) const
SwWrongList(const SwWrongList &rCpy)=delete
std::optional< std::pair< TextFrameIndex, TextFrameIndex > > GetElementAt(sal_uInt16 nIndex)
sal_uInt16 GetElementCount()
SwWrongArea(const OUString &rType, WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag, sal_Int32 nPos, sal_Int32 nLen)
std::vector< SwWrongArea > maList
TextFrameIndex m_CurrentIndex
void Insert(sal_uInt16 nWhere, std::vector< SwWrongArea >::iterator startPos, std::vector< SwWrongArea >::iterator const &endPos)
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
const sal_Int32 COMPLETE_STRING
void SetInvalid(sal_Int32 nBegin, sal_Int32 nEnd)
Base class of the Writer document model elements.