34#include <bookmark.hxx>
43 sal_Int32 m_nFieldPos;
46 explicit FieldResult(sal_Int32
const nPos)
54 bool operator()(
const FieldResult &rOne,
const FieldResult &rTwo)
const
56 return rOne.m_nFieldPos < rTwo.m_nFieldPos;
70 block(sal_Int32 nStart, sal_Int32 nLen,
bool bVisible)
71 : m_nStart(nStart), m_nLen(nLen), m_bVisible(
bVisible)
79 explicit containsPos(
const sal_Int32 nPos)
83 bool operator() (
const block& rIn)
const
85 return m_nPos >= rIn.m_nStart &&
m_nPos < rIn.m_nStart + rIn.m_nLen;
94 const OUString& rNodeText = rNode.
GetText();
100 Range aRange( 0, rNodeText.isEmpty() ? 0 : rNodeText.getLength() - 1);
113 ::std::deque<::std::pair<sw::mark::IFieldmark const*, bool>> startedFields;
114 SwPaM cursor(rNode, 0);
117 sw::mark::IFieldmark
const* pFieldMark(
nullptr);
121 if (pFieldMark ==
nullptr
122 || pFieldMark->GetMarkStart().GetNode().GetTextNode()->GetText()[
123 pFieldMark->GetMarkStart().GetContentIndex()]
128 pFieldMark =
nullptr;
138 assert(pFieldMark->GetMarkStart().GetNode().GetTextNode()->GetText()[pFieldMark->GetMarkStart().GetContentIndex()] !=
CH_TXT_ATR_FORMELEMENT);
141 if (pFieldMark->GetMarkStart().GetNode() < rNode)
144 if (pFieldMark->GetMarkEnd().GetNode() < rNode)
151 startedFields.emplace_front(pFieldMark, sepPos.
GetNode() < rNode);
153 *cursor.
GetPoint() = pFieldMark->GetMarkStart();
160 ::std::optional<sal_Int32> oStartHidden;
161 if (!::std::all_of(startedFields.begin(), startedFields.end(),
162 [](
auto const& it) { return it.second; }))
164 oStartHidden.emplace(0);
174 startedFields.emplace_back(pFieldMark,
false);
177 oStartHidden.emplace(
i);
183 assert(startedFields.back().first->IsCoveringPosition(
SwPosition(rNode,
i)));
184 startedFields.back().second =
true;
185 assert(oStartHidden);
186 if (::std::all_of(startedFields.begin(), startedFields.end(),
187 [](
auto const& it) { return it.second; }))
190#if defined __GNUC__ && !defined __clang__ && __GNUC__ >= 11 && __GNUC__ <= 12
191#pragma GCC diagnostic push
192#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
195 aHiddenMulti.
Select({*oStartHidden,
i},
true);
196 oStartHidden.reset();
197#if defined __GNUC__ && !defined __clang__ && __GNUC__ >= 11 && __GNUC__ <= 12
198#pragma GCC diagnostic pop
206 startedFields.pop_back();
212 if (oStartHidden && rNode.
Len() != 0)
214 aHiddenMulti.
Select({*oStartHidden, rNode.
Len() - 1},
true);
234 std::vector<block> aBlocks;
236 sal_Int32 nShownStart = 0;
240 const sal_Int32 nHiddenStart = rRange.
Min();
241 const sal_Int32 nHiddenEnd = rRange.
Max() + 1;
242 const sal_Int32 nHiddenLen = nHiddenEnd - nHiddenStart;
244 const sal_Int32 nShownEnd = nHiddenStart;
245 const sal_Int32 nShownLen = nShownEnd - nShownStart;
248 aBlocks.emplace_back(nShownStart, nShownLen,
true);
251 aBlocks.emplace_back(nHiddenStart, nHiddenLen,
false);
253 nShownStart = nHiddenEnd;
256 sal_Int32 nTrailingShownLen = rNodeText.getLength() - nShownStart;
257 if (nTrailingShownLen)
258 aBlocks.emplace_back(nShownStart, nTrailingShownLen,
true);
265 for (
size_t i = 0; pSwpHints2 &&
i < pSwpHints2->
Count(); ++
i )
270 const sal_Int32 nDummyCharPos = pAttr->
GetStart();
273 std::vector<block>::iterator aFind = std::find_if(aBlocks.begin(),
274 aBlocks.end(), containsPos(nDummyCharPos));
275 if (aFind != aBlocks.end())
277 FieldResult aFieldResult(nDummyCharPos);
278 switch (pAttr->
Which())
284 aFieldResult.m_eType = FieldResult::FIELD;
293 static_txtattr_cast<SwTextField const*>(pAttr)->
294 GetFormatField().GetField()->ExpandField(
true, pLayout);
295 aFieldResult.m_eType = FieldResult::FIELD;
306 aFieldResult.m_eType = FieldResult::FOOTNOTE;
312 aFind->m_aAttrs.insert(aFieldResult);
321 SwPaM aPaM(rNode, 0, rNode, rNode.
Len());
322 std::vector<sw::mark::IFieldmark*> aNoTextFieldmarks =
325 for (sw::mark::IFieldmark *
const pMark : aNoTextFieldmarks)
327 const sal_Int32 nDummyCharPos = pMark->GetMarkStart().GetContentIndex();
330 std::vector<block>::iterator aFind = std::find_if(aBlocks.begin(), aBlocks.end(),
331 containsPos(nDummyCharPos));
332 if (aFind != aBlocks.end())
334 FieldResult aFieldResult(nDummyCharPos);
338 aFieldResult.m_eType = FieldResult::FIELD;
339 aFind->m_aAttrs.insert(aFieldResult);
347 sal_Int32 nOffset = 0;
348 for (
const auto& rBlock : aBlocks)
350 const sal_Int32 nBlockLen = rBlock.m_nLen;
353 const sal_Int32 nBlockStart = rBlock.m_nStart;
354 const sal_Int32 nBlockEnd = nBlockStart + nBlockLen;
356 if (!rBlock.m_bVisible)
358 sal_Int32
const modelBlockPos(nBlockEnd);
359 sal_Int32
const viewBlockPos(nBlockStart + nOffset);
360 m_aMap.emplace_back(modelBlockPos, viewBlockPos,
false);
363 nOffset -= nBlockLen;
367 for (
const auto& rAttr : rBlock.m_aAttrs)
369 sal_Int32
const modelFieldPos(rAttr.m_nFieldPos);
370 sal_Int32
const viewFieldPos(rAttr.m_nFieldPos + nOffset);
371 m_aMap.emplace_back(modelFieldPos, viewFieldPos,
true );
374 nOffset += rAttr.m_sExpand.getLength() - 1;
376 switch (rAttr.m_eType)
378 case FieldResult::FIELD:
381 case FieldResult::FOOTNOTE:
389 sal_Int32
const modelEndBlock(nBlockEnd);
390 sal_Int32
const viewFieldPos(nBlockEnd + nOffset);
391 m_aMap.emplace_back(modelEndBlock, viewFieldPos,
true);
402 [nModelPos](
const ConversionMapEntry& rEntry) { return rEntry.m_nModelPos >= nModelPos; });
403 if (aIter !=
m_aMap.end())
407 if (!aIter->m_bVisible)
408 return aIter->m_nViewPos;
413 const sal_Int32 nOffsetFromEnd = aIter->m_nModelPos - nModelPos;
414 return aIter->m_nViewPos - nOffsetFromEnd;
425 aRet.
mnPos = nViewPos;
429 [nViewPos](
const ConversionMapEntry& rEntry) { return rEntry.m_nViewPos > nViewPos; });
434 const sal_Int32 nPosModel = aIter->m_nModelPos;
435 const sal_Int32 nPosExpand = aIter->m_nViewPos;
440 const sal_Int32 nPrevPosModel = aIter->m_nModelPos;
441 const sal_Int32 nPrevPosExpand = aIter->m_nViewPos;
443 const sal_Int32 nLengthModel = nPosModel - nPrevPosModel;
444 const sal_Int32 nLengthExpand = nPosExpand - nPrevPosExpand;
446 const sal_Int32 nFieldLengthExpand = nLengthExpand - nLengthModel + 1;
447 const sal_Int32 nFieldEndExpand = nPrevPosExpand + nFieldLengthExpand;
450 if ( nFieldEndExpand <= nViewPos )
453 const sal_Int32 nDistToField = nViewPos - nFieldEndExpand + 1;
454 aRet.
mnPos = nPrevPosModel + nDistToField;
459 aRet.
mnPos = nPrevPosModel;
460 aRet.
mnSubPos = nViewPos - nPrevPosExpand;
Provides access to the marks of a document.
virtual std::vector<::sw::mark::IFieldmark * > getNoTextFieldmarksIn(const SwPaM &rPaM) const =0
virtual ::sw::mark::IFieldmark * getFieldmarkAt(const SwPosition &rPos) const =0
get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
virtual sw::mark::IFieldmark * getInnerFieldmarkFor(const SwPosition &pos) const =0
ModelPosition ConvertToModelPosition(sal_Int32 nViewPos) const
Converts a view position into a model position.
std::vector< sal_Int32 > m_FieldPositions
store positions of fields and footnotes for grammar checkers
sal_Int32 ConvertToViewPosition(sal_Int32 nModelPos) const
Converts a model position into a view position.
std::vector< sal_Int32 > m_FootnotePositions
const Range & GetRange(sal_Int32 nRange) const
sal_Int32 GetRangeCount() const
bool Select(sal_Int32 nIndex, bool bSelect=true)
bool IsSelected(sal_Int32 nIndex) const
IDocumentMarkAccess * getIDocumentMarkAccess()
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
PaM is Point and Mark: a selection of the document model.
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
const SwPosition * GetPoint() const
The root element of a Writer document layout.
static void selectHiddenTextProperty(const SwTextNode &rNode, MultiSelection &rHiddenMulti, std::vector< std::pair< sw::mark::IBookmark const *, MarkKind > > *pBookmarks)
static void selectRedLineDeleted(const SwTextNode &rNode, MultiSelection &rHiddenMulti, bool bSelect=true)
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
sal_Int32 GetStart() const
bool HasDummyChar() const
SwTextNode is a paragraph in the document model.
virtual sal_Int32 Len() const override
SwpHints * GetpSwpHints()
const OUString & GetText() const
An SwTextAttr container, stores all directly formatted text portions for a text node.
SwTextAttr * Get(size_t nPos) const
const EnumerationType m_eType
#define CH_TXT_ATR_FIELDSEP
#define CH_TXT_ATR_FORMELEMENT
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(59)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
#define CH_TXT_ATR_FIELDEND
#define CH_TXT_ATR_FIELDSTART
ExpandMode
Some helpers for converting model strings to view strings.
@ ReplaceMode
do not expand to content, but replace with zwsp
double getLength(const B2DPolygon &rCandidate)
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
OUString ExpandFieldmark(IFieldmark *pBM)
bool GoInContent(SwPaM &rPam, SwMoveFnCollection const &fnMove)
SwMoveFnCollection const & fnMoveBackward
For each expanded/hidden portion in the model string, there is an entry in the conversion map.
This struct defines a position in the model string.
Marks a position in the document model.
sal_Int32 GetContentIndex() const