LibreOffice Module sw (master)  1
findtxt.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 <memory>
21 
22 #include <com/sun/star/util/SearchFlags.hpp>
23 #include <com/sun/star/util/SearchResult.hpp>
24 #include <comphelper/lok.hxx>
25 #include <o3tl/safeint.hxx>
26 #include <rtl/ustrbuf.hxx>
27 #include <svx/svdview.hxx>
28 #include <svl/srchitem.hxx>
29 #include <sfx2/sfxsids.hrc>
30 #include <editeng/outliner.hxx>
31 #include <osl/diagnose.h>
32 
33 #include <wrtsh.hxx>
34 #include <txatritr.hxx>
35 #include <fldbas.hxx>
36 #include <fmtfld.hxx>
37 #include <txtfld.hxx>
38 #include <txtfrm.hxx>
39 #include <rootfrm.hxx>
40 #include <swcrsr.hxx>
41 #include <redline.hxx>
42 #include <doc.hxx>
43 #include <IDocumentUndoRedo.hxx>
44 #include <IDocumentState.hxx>
47 #include <dcontact.hxx>
48 #include <pamtyp.hxx>
49 #include <ndtxt.hxx>
50 #include <swundo.hxx>
51 #include <UndoInsert.hxx>
52 #include <breakit.hxx>
53 #include <docsh.hxx>
54 #include <PostItMgr.hxx>
55 #include <view.hxx>
56 
57 using namespace ::com::sun::star;
58 using namespace util;
59 
60 namespace {
61 
64 struct AmbiguousIndex
65 {
66 private:
67  sal_Int32 m_value;
68 
69 #ifndef NDEBUG
70  enum class tags : char { Any, Frame, Model };
71  tags m_tag;
72 #endif
73 
74 public:
75  AmbiguousIndex() : m_value(-1)
76 #ifndef NDEBUG
77  , m_tag(tags::Any)
78 #endif
79  {}
80  explicit AmbiguousIndex(sal_Int32 const value
81 #ifndef NDEBUG
82  , tags const tag
83 #endif
84  ) : m_value(value)
85 #ifndef NDEBUG
86  , m_tag(tag)
87 #endif
88  {}
89 
90  sal_Int32 & GetAnyIndex() { return m_value; }
91  sal_Int32 const& GetAnyIndex() const { return m_value; }
92  TextFrameIndex GetFrameIndex() const
93  {
94  assert(m_tag != tags::Model);
95  return TextFrameIndex(m_value);
96  }
97  sal_Int32 GetModelIndex() const
98  {
99  assert(m_tag != tags::Frame);
100  return m_value;
101  }
102  void SetFrameIndex(TextFrameIndex const value)
103  {
104 #ifndef NDEBUG
105  m_tag = tags::Frame;
106 #endif
107  m_value = sal_Int32(value);
108  }
109  void SetModelIndex(sal_Int32 const value)
110  {
111 #ifndef NDEBUG
112  m_tag = tags::Model;
113 #endif
114  m_value = value;
115  }
116 
117  bool operator ==(AmbiguousIndex const& rOther) const
118  {
119  assert(m_tag == tags::Any || rOther.m_tag == tags::Any || m_tag == rOther.m_tag);
120  return m_value == rOther.m_value;
121  }
122  bool operator <=(AmbiguousIndex const& rOther) const
123  {
124  assert(m_tag == tags::Any || rOther.m_tag == tags::Any || m_tag == rOther.m_tag);
125  return m_value <= rOther.m_value;
126  }
127  bool operator < (AmbiguousIndex const& rOther) const
128  {
129  assert(m_tag == tags::Any || rOther.m_tag == tags::Any || m_tag == rOther.m_tag);
130  return m_value < rOther.m_value;
131  }
132  AmbiguousIndex operator - (AmbiguousIndex const& rOther) const
133  {
134  assert(m_tag == tags::Any || rOther.m_tag == tags::Any || m_tag == rOther.m_tag);
135  return AmbiguousIndex(m_value - rOther.m_value
136 #ifndef NDEBUG
137  , std::max(m_tag, rOther.m_tag)
138 #endif
139  );
140  }
141 };
142 
143 class MaybeMergedIter
144 {
145  std::optional<sw::MergedAttrIter> m_oMergedIter;
146  SwTextNode const*const m_pNode;
147  size_t m_HintIndex;
148 
149 public:
150  MaybeMergedIter(SwTextFrame const*const pFrame, SwTextNode const*const pNode)
151  : m_pNode(pNode)
152  , m_HintIndex(0)
153  {
154  if (pFrame)
155  {
156  m_oMergedIter.emplace(*pFrame);
157  }
158  }
159 
160  SwTextAttr const* NextAttr(SwTextNode const*& rpNode)
161  {
162  if (m_oMergedIter)
163  {
164  return m_oMergedIter->NextAttr(&rpNode);
165  }
166  if (SwpHints const*const pHints = m_pNode->GetpSwpHints())
167  {
168  if (m_HintIndex < pHints->Count())
169  {
170  rpNode = m_pNode;
171  return pHints->Get(m_HintIndex++);
172  }
173  }
174  return nullptr;
175  }
176 };
177 
178 }
179 
180 static OUString
182  SwTextFrame const*const pFrame,
183  SwRootFrame const*const pLayout,
184  AmbiguousIndex const nStart, AmbiguousIndex & rEnd,
185  std::vector<AmbiguousIndex> &rArr,
186  bool const bRemoveSoftHyphen, bool const bRemoveCommentAnchors)
187 {
188  OUStringBuffer buf(pLayout ? pFrame->GetText() : rNd.GetText());
189  rArr.clear();
190 
191  MaybeMergedIter iter(pLayout ? pFrame : nullptr, pLayout ? nullptr : &rNd);
192 
193  AmbiguousIndex nSoftHyphen = nStart;
194  AmbiguousIndex nHintStart;
195  bool bNewHint = true;
196  bool bNewSoftHyphen = true;
197  const AmbiguousIndex nEnd = rEnd;
198  std::vector<AmbiguousIndex> aReplaced;
199  SwTextNode const* pNextHintNode(nullptr);
200  SwTextAttr const* pNextHint(iter.NextAttr(pNextHintNode));
201 
202  do
203  {
204  if ( bNewHint )
205  {
206  if (pLayout)
207  {
208  nHintStart.SetFrameIndex(pNextHint
209  ? pFrame->MapModelToView(pNextHintNode, pNextHint->GetStart())
210  : TextFrameIndex(-1));
211  }
212  else
213  {
214  nHintStart.SetModelIndex(pNextHint ? pNextHint->GetStart() : -1);
215  }
216  }
217 
218  if ( bNewSoftHyphen )
219  {
220  if (pLayout)
221  {
222  nSoftHyphen.SetFrameIndex(TextFrameIndex(bRemoveSoftHyphen
223  ? pFrame->GetText().indexOf(CHAR_SOFTHYPHEN, nSoftHyphen.GetAnyIndex())
224  : -1));
225  }
226  else
227  {
228  nSoftHyphen.SetModelIndex(bRemoveSoftHyphen
229  ? rNd.GetText().indexOf(CHAR_SOFTHYPHEN, nSoftHyphen.GetAnyIndex())
230  : -1);
231  }
232  }
233 
234  bNewHint = false;
235  bNewSoftHyphen = false;
236  AmbiguousIndex nStt;
237 
238  // Check if next stop is a hint.
239  if (0 <= nHintStart.GetAnyIndex()
240  && (-1 == nSoftHyphen.GetAnyIndex() || nHintStart < nSoftHyphen)
241  && nHintStart < nEnd )
242  {
243  nStt = nHintStart;
244  bNewHint = true;
245  }
246  // Check if next stop is a soft hyphen.
247  else if ( -1 != nSoftHyphen.GetAnyIndex()
248  && (-1 == nHintStart.GetAnyIndex() || nSoftHyphen < nHintStart)
249  && nSoftHyphen < nEnd)
250  {
251  nStt = nSoftHyphen;
252  bNewSoftHyphen = true;
253  }
254  // If nSoftHyphen == nHintStart, the current hint *must* be a hint with an end.
255  else if (-1 != nSoftHyphen.GetAnyIndex() && nSoftHyphen == nHintStart)
256  {
257  nStt = nSoftHyphen;
258  bNewHint = true;
259  bNewSoftHyphen = true;
260  }
261  else
262  break;
263 
264  AmbiguousIndex nCurrent(nStt);
265  nCurrent.GetAnyIndex() -= rArr.size();
266 
267  if ( bNewHint )
268  {
269  if (pNextHint && pNextHint->HasDummyChar() && (nStart <= nStt))
270  {
271  switch (pNextHint->Which())
272  {
273  case RES_TXTATR_FLYCNT:
274  case RES_TXTATR_FIELD:
275  case RES_TXTATR_REFMARK:
276  case RES_TXTATR_TOXMARK:
277  case RES_TXTATR_META:
279  {
280  // (1998) they are desired as separators and
281  // belong not any longer to a word.
282  // they should also be ignored at a
283  // beginning/end of a sentence if blank. Those are
284  // simply removed if first. If at the end, we keep the
285  // replacement and remove afterwards all at a string's
286  // end (might be normal 0x7f).
287  const bool bEmpty = pNextHint->Which() != RES_TXTATR_FIELD
288  || (static_txtattr_cast<SwTextField const*>(pNextHint)->GetFormatField().GetField()->ExpandField(true, pLayout).isEmpty());
289  if ( bEmpty && nStart == nCurrent )
290  {
291  rArr.push_back( nCurrent );
292  if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
293  {
294  --rEnd.GetAnyIndex();
295  }
296  buf.remove(nCurrent.GetAnyIndex(), 1);
297  }
298  else
299  {
300  if ( bEmpty )
301  aReplaced.push_back( nCurrent );
302  buf[nCurrent.GetAnyIndex()] = '\x7f';
303  }
304  }
305  break;
307  {
308  if( bRemoveCommentAnchors )
309  {
310  rArr.push_back( nCurrent );
311  if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
312  {
313  --rEnd.GetAnyIndex();
314  }
315  buf.remove( nCurrent.GetAnyIndex(), 1 );
316  }
317  }
318  break;
319  default:
320  OSL_FAIL( "unknown case in lcl_CleanStr" );
321  break;
322  }
323  }
324  pNextHint = iter.NextAttr(pNextHintNode);
325  }
326 
327  if ( bNewSoftHyphen )
328  {
329  rArr.push_back( nCurrent );
330 
331  // If the soft hyphen to be removed is past the end of the range we're searching in,
332  // don't adjust the end.
333  if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
334  {
335  --rEnd.GetAnyIndex();
336  }
337 
338  buf.remove(nCurrent.GetAnyIndex(), 1);
339  ++nSoftHyphen.GetAnyIndex();
340  }
341  }
342  while ( true );
343 
344  for (auto i = aReplaced.size(); i; )
345  {
346  const AmbiguousIndex nTmp = aReplaced[ --i ];
347  if (nTmp.GetAnyIndex() == buf.getLength() - 1)
348  {
349  buf.truncate(nTmp.GetAnyIndex());
350  rArr.push_back( nTmp );
351  --rEnd.GetAnyIndex();
352  }
353  }
354 
355  return buf.makeStringAndClear();
356 }
357 
358 static bool DoSearch(SwPaM & rSearchPam,
359  const i18nutil::SearchOptions2& rSearchOpt, utl::TextSearch& rSText,
360  SwMoveFnCollection const & fnMove,
361  bool bSrchForward, bool bRegSearch, bool bChkEmptyPara, bool bChkParaEnd,
362  AmbiguousIndex & nStart, AmbiguousIndex & nEnd, AmbiguousIndex nTextLen,
363  SwTextNode const* pNode, SwTextFrame const* pTextFrame,
364  SwRootFrame const* pLayout, SwPaM* pPam);
365 
366 namespace sw {
367 
368 // @param xSearchItem allocate in parent so we can do so outside the calling loop
369 bool FindTextImpl(SwPaM & rSearchPam,
370  const i18nutil::SearchOptions2& rSearchOpt, bool bSearchInNotes,
371  utl::TextSearch& rSText,
372  SwMoveFnCollection const & fnMove, const SwPaM & rRegion,
373  bool bInReadOnly, SwRootFrame const*const pLayout,
374  std::unique_ptr<SvxSearchItem>& xSearchItem)
375 {
376  if( rSearchOpt.searchString.isEmpty() )
377  return false;
378 
379  std::unique_ptr<SwPaM> pPam = sw::MakeRegion(fnMove, rRegion);
380  const bool bSrchForward = &fnMove == &fnMoveForward;
381  SwNodeIndex& rNdIdx = pPam->GetPoint()->nNode;
382  SwIndex& rContentIdx = pPam->GetPoint()->nContent;
383 
384  // If bFound is true then the string was found and is between nStart and nEnd
385  bool bFound = false;
386  // start position in text or initial position
387  bool bFirst = true;
388  SwContentNode * pNode;
389 
390  const bool bRegSearch = SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2;
391  const bool bChkEmptyPara = bRegSearch && 2 == rSearchOpt.searchString.getLength() &&
392  ( rSearchOpt.searchString == "^$" ||
393  rSearchOpt.searchString == "$^" );
394  const bool bChkParaEnd = bRegSearch && rSearchOpt.searchString == "$";
395 
396  if (!xSearchItem)
397  {
398  xSearchItem.reset(new SvxSearchItem(SID_SEARCH_ITEM)); // this is a very expensive operation (calling configmgr etc.)
399  xSearchItem->SetSearchOptions(rSearchOpt);
400  xSearchItem->SetBackward(!bSrchForward);
401  }
402 
403  // LanguageType eLastLang = 0;
404  while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
405  {
406  if( pNode->IsTextNode() )
407  {
408  SwTextNode& rTextNode = *pNode->GetTextNode();
409  SwTextFrame const*const pFrame(pLayout
410  ? static_cast<SwTextFrame const*>(rTextNode.getLayoutFrame(pLayout))
411  : nullptr);
412  assert(!pLayout || pFrame);
413  AmbiguousIndex nTextLen;
414  if (pLayout)
415  {
416  nTextLen.SetFrameIndex(TextFrameIndex(pFrame->GetText().getLength()));
417  }
418  else
419  {
420  nTextLen.SetModelIndex(rTextNode.GetText().getLength());
421  }
422  AmbiguousIndex nEnd;
423  if (pLayout
424  ? FrameContainsNode(*pFrame, pPam->GetMark()->nNode.GetIndex())
425  : rNdIdx == pPam->GetMark()->nNode)
426  {
427  if (pLayout)
428  {
429  nEnd.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->GetMark()));
430  }
431  else
432  {
433  nEnd.SetModelIndex(pPam->GetMark()->nContent.GetIndex());
434  }
435  }
436  else
437  {
438  if (bSrchForward)
439  {
440  nEnd = nTextLen;
441  }
442  else
443  {
444  if (pLayout)
445  {
446  nEnd.SetFrameIndex(TextFrameIndex(0));
447  }
448  else
449  {
450  nEnd.SetModelIndex(0);
451  }
452  }
453  }
454  AmbiguousIndex nStart;
455  if (pLayout)
456  {
457  nStart.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->GetPoint()));
458  }
459  else
460  {
461  nStart.SetModelIndex(rContentIdx.GetIndex());
462  }
463 
464  /* #i80135# */
465  // if there are SwPostItFields inside our current node text, we
466  // split the text into separate pieces and search for text inside
467  // the pieces as well as inside the fields
468  MaybeMergedIter iter(pLayout ? pFrame : nullptr, pLayout ? nullptr : &rTextNode);
469 
470  // count PostItFields by looping over all fields
471  std::vector<std::pair<SwTextAttr const*, AmbiguousIndex>> postits;
472  if (bSearchInNotes)
473  {
474  if (!bSrchForward)
475  {
476  std::swap(nStart, nEnd);
477  }
478 
479  SwTextNode const* pTemp(nullptr);
480  while (SwTextAttr const*const pTextAttr = iter.NextAttr(pTemp))
481  {
482  if ( pTextAttr->Which()==RES_TXTATR_ANNOTATION )
483  {
484  AmbiguousIndex aPos;
485  aPos.SetModelIndex(pTextAttr->GetStart());
486  if (pLayout)
487  {
488  aPos.SetFrameIndex(pFrame->MapModelToView(pTemp, aPos.GetModelIndex()));
489  }
490  if ((nStart <= aPos) && (aPos <= nEnd))
491  {
492  postits.emplace_back(pTextAttr, aPos);
493  }
494  }
495  }
496 
497  if (!bSrchForward)
498  {
499  std::swap(nStart, nEnd);
500  }
501 
502  }
503 
504  SwDocShell *const pDocShell = pNode->GetDoc().GetDocShell();
505  SwWrtShell *const pWrtShell = pDocShell ? pDocShell->GetWrtShell() : nullptr;
506  SwPostItMgr *const pPostItMgr = pWrtShell ? pWrtShell->GetPostItMgr() : nullptr;
507 
508  // If there is an active text edit, then search there.
509  bool bEndedTextEdit = false;
510  SdrView* pSdrView = pWrtShell ? pWrtShell->GetDrawView() : nullptr;
511  if (pSdrView)
512  {
513  // If the edited object is not anchored to this node, then ignore it.
514  SdrObject* pObject = pSdrView->GetTextEditObject();
515  if (pObject)
516  {
517  if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
518  {
519  const SwPosition* pPosition = pFrameFormat->GetAnchor().GetContentAnchor();
520  if (!pPosition || (pLayout
521  ? !FrameContainsNode(*pFrame, pPosition->nNode.GetIndex())
522  : pPosition->nNode.GetIndex() != pNode->GetIndex()))
523  pObject = nullptr;
524  }
525  }
526 
527  if (pObject)
528  {
529  sal_uInt16 nResult = pSdrView->GetTextEditOutlinerView()->StartSearchAndReplace(*xSearchItem);
530  if (!nResult)
531  {
532  // If not found, end the text edit.
533  pSdrView->SdrEndTextEdit();
534  const Point aPoint(pSdrView->GetAllMarkedRect().TopLeft());
535  pSdrView->UnmarkAll();
536  pWrtShell->CallSetCursor(&aPoint, true);
537  pWrtShell->Edit();
538  bEndedTextEdit = true;
539  }
540  else
541  {
542  bFound = true;
543  break;
544  }
545  }
546  }
547 
549  {
550  // Writer and editeng selections are not supported in parallel.
551  SvxSearchItem* pSearchItem = SwView::GetSearchItem();
552  // If we just finished search in shape text, don't attempt to do that again.
553  if (!bEndedTextEdit && !(pSearchItem && pSearchItem->GetCommand() == SvxSearchCmd::FIND_ALL))
554  {
555  // If there are any shapes anchored to this node, search there.
556  SwPaM aPaM(pNode->GetDoc().GetNodes().GetEndOfContent());
557  if (pLayout)
558  {
559  *aPaM.GetPoint() = pFrame->MapViewToModelPos(nStart.GetFrameIndex());
560  }
561  else
562  {
563  aPaM.GetPoint()->nNode = rTextNode;
564  aPaM.GetPoint()->nContent.Assign(
565  aPaM.GetPoint()->nNode.GetNode().GetTextNode(),
566  nStart.GetModelIndex());
567  }
568  aPaM.SetMark();
569  if (pLayout)
570  {
571  aPaM.GetMark()->nNode = (pFrame->GetMergedPara()
572  ? *pFrame->GetMergedPara()->pLastNode
573  : rTextNode)
574  .GetIndex() + 1;
575  }
576  else
577  {
578  aPaM.GetMark()->nNode = rTextNode.GetIndex() + 1;
579  }
580  aPaM.GetMark()->nContent.Assign(aPaM.GetMark()->nNode.GetNode().GetTextNode(), 0);
581  if (pNode->GetDoc().getIDocumentDrawModelAccess().Search(aPaM, *xSearchItem) && pSdrView)
582  {
583  if (SdrObject* pObject = pSdrView->GetTextEditObject())
584  {
585  if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
586  {
587  const SwPosition* pPosition = pFrameFormat->GetAnchor().GetContentAnchor();
588  if (pPosition)
589  {
590  // Set search position to the shape's anchor point.
591  *rSearchPam.GetPoint() = *pPosition;
592  rSearchPam.GetPoint()->nContent.Assign(pPosition->nNode.GetNode().GetContentNode(), 0);
593  rSearchPam.SetMark();
594  bFound = true;
595  break;
596  }
597  }
598  }
599  }
600  }
601  }
602 
603  // do we need to finish a note?
604  if (pPostItMgr && pPostItMgr->HasActiveSidebarWin())
605  {
606  if (bSearchInNotes)
607  {
608  if (!postits.empty())
609  {
610  if (bSrchForward)
611  {
612  postits.erase(postits.begin());
613  }
614  else
615  {
616  postits.pop_back(); // hope that's the right one?
617  }
618  }
619  //search inside, finish and put focus back into the doc
620  if (pPostItMgr->FinishSearchReplace(rSearchOpt,bSrchForward))
621  {
622  bFound = true ;
623  break;
624  }
625  }
626  else
627  {
628  pPostItMgr->SetActiveSidebarWin(nullptr);
629  }
630  }
631 
632  if (!postits.empty())
633  {
634  // now we have to split
635  AmbiguousIndex nStartInside;
636  AmbiguousIndex nEndInside;
637  sal_Int32 aLoop = bSrchForward ? 0 : postits.size();
638 
639  while ((0 <= aLoop) && (o3tl::make_unsigned(aLoop) <= postits.size()))
640  {
641  if (bSrchForward)
642  {
643  if (aLoop == 0)
644  {
645  nStartInside = nStart;
646  }
647  else if (pLayout)
648  {
649  nStartInside.SetFrameIndex(postits[aLoop - 1].second.GetFrameIndex() + TextFrameIndex(1));
650  }
651  else
652  {
653  nStartInside.SetModelIndex(postits[aLoop - 1].second.GetModelIndex() + 1);
654  }
655  nEndInside = static_cast<size_t>(aLoop) == postits.size()
656  ? nEnd
657  : postits[aLoop].second;
658  nTextLen = nEndInside - nStartInside;
659  }
660  else
661  {
662  nStartInside = static_cast<size_t>(aLoop) == postits.size()
663  ? nStart
664  : postits[aLoop].second;
665  if (aLoop == 0)
666  {
667  nEndInside = nEnd;
668  }
669  else if (pLayout)
670  {
671  nEndInside.SetFrameIndex(postits[aLoop - 1].second.GetFrameIndex() + TextFrameIndex(1));
672  }
673  else
674  {
675  nEndInside.SetModelIndex(postits[aLoop - 1].second.GetModelIndex() + 1);
676  }
677  nTextLen = nStartInside - nEndInside;
678  }
679  // search inside the text between a note
680  bFound = DoSearch( rSearchPam,
681  rSearchOpt, rSText, fnMove, bSrchForward,
682  bRegSearch, bChkEmptyPara, bChkParaEnd,
683  nStartInside, nEndInside, nTextLen,
684  pNode->GetTextNode(), pFrame, pLayout,
685  pPam.get() );
686  if ( bFound )
687  break;
688  else
689  {
690  // we should now be right in front of a note, search inside
691  if (bSrchForward
692  ? (static_cast<size_t>(aLoop) != postits.size())
693  : (aLoop != 0))
694  {
695  const SwTextAttr *const pTextAttr = bSrchForward
696  ? postits[aLoop].first
697  : postits[aLoop - 1].first;
698  if (pPostItMgr && pPostItMgr->SearchReplace(
699  static_txtattr_cast<SwTextField const*>(pTextAttr)->GetFormatField(),rSearchOpt,bSrchForward))
700  {
701  bFound = true ;
702  break;
703  }
704  }
705  }
706  aLoop = bSrchForward ? aLoop+1 : aLoop-1;
707  }
708  }
709  else
710  {
711  // if there is no SwPostItField inside or searching inside notes
712  // is disabled, we search the whole length just like before
713  bFound = DoSearch( rSearchPam,
714  rSearchOpt, rSText, fnMove, bSrchForward,
715  bRegSearch, bChkEmptyPara, bChkParaEnd,
716  nStart, nEnd, nTextLen,
717  pNode->GetTextNode(), pFrame, pLayout,
718  pPam.get() );
719  }
720  if (bFound)
721  break;
722  }
723  }
724  return bFound;
725 }
726 
727 } // namespace sw
728 
729 bool DoSearch(SwPaM & rSearchPam,
730  const i18nutil::SearchOptions2& rSearchOpt, utl::TextSearch& rSText,
731  SwMoveFnCollection const & fnMove, bool bSrchForward, bool bRegSearch,
732  bool bChkEmptyPara, bool bChkParaEnd,
733  AmbiguousIndex & nStart, AmbiguousIndex & nEnd, AmbiguousIndex const nTextLen,
734  SwTextNode const*const pNode, SwTextFrame const*const pFrame,
735  SwRootFrame const*const pLayout, SwPaM* pPam)
736 {
737  bool bFound = false;
738  SwNodeIndex& rNdIdx = pPam->GetPoint()->nNode;
739  OUString sCleanStr;
740  std::vector<AmbiguousIndex> aFltArr;
741  LanguageType eLastLang = LANGUAGE_SYSTEM;
742  // if the search string contains a soft hyphen,
743  // we don't strip them from the text:
744  bool bRemoveSoftHyphens = true;
745  // if the search string contains a comment, we don't strip them from the text
746  const bool bRemoveCommentAnchors = rSearchOpt.searchString.indexOf( CH_TXTATR_INWORD ) == -1;
747 
748  if ( bRegSearch )
749  {
750  if ( -1 != rSearchOpt.searchString.indexOf("\\xAD")
751  || -1 != rSearchOpt.searchString.indexOf("\\x{00AD}")
752  || -1 != rSearchOpt.searchString.indexOf("\\u00AD")
753  || -1 != rSearchOpt.searchString.indexOf("\\U000000AD")
754  || -1 != rSearchOpt.searchString.indexOf("\\N{SOFT HYPHEN}"))
755  {
756  bRemoveSoftHyphens = false;
757  }
758  }
759  else
760  {
761  if ( 1 == rSearchOpt.searchString.getLength() &&
762  CHAR_SOFTHYPHEN == rSearchOpt.searchString.toChar() )
763  bRemoveSoftHyphens = false;
764  }
765 
766  if( bSrchForward )
767  sCleanStr = lcl_CleanStr(*pNode, pFrame, pLayout, nStart, nEnd,
768  aFltArr, bRemoveSoftHyphens, bRemoveCommentAnchors);
769  else
770  sCleanStr = lcl_CleanStr(*pNode, pFrame, pLayout, nEnd, nStart,
771  aFltArr, bRemoveSoftHyphens, bRemoveCommentAnchors);
772 
773  std::unique_ptr<SwScriptIterator> pScriptIter;
774  sal_uInt16 nSearchScript = 0;
775  sal_uInt16 nCurrScript = 0;
776 
777  if (SearchAlgorithms2::APPROXIMATE == rSearchOpt.AlgorithmType2)
778  {
779  pScriptIter.reset(new SwScriptIterator(sCleanStr, nStart.GetAnyIndex(), bSrchForward));
780  nSearchScript = g_pBreakIt->GetRealScriptOfText( rSearchOpt.searchString, 0 );
781  }
782 
783  const AmbiguousIndex nStringEnd = nEnd;
784  bool bZeroMatch = false; // zero-length match, i.e. only $ anchor as regex
785  while ( ((bSrchForward && nStart < nStringEnd) ||
786  (!bSrchForward && nStringEnd < nStart)) && !bZeroMatch )
787  {
788  // SearchAlgorithms_APPROXIMATE works on a per word base so we have to
789  // provide the text searcher with the correct locale, because it uses
790  // the break-iterator
791  if ( pScriptIter )
792  {
793  nEnd.GetAnyIndex() = pScriptIter->GetScriptChgPos();
794  nCurrScript = pScriptIter->GetCurrScript();
795  if ( nSearchScript == nCurrScript )
796  {
797  const LanguageType eCurrLang = pLayout
798  ? pFrame->GetLangOfChar(bSrchForward
799  ? nStart.GetFrameIndex()
800  : nEnd.GetFrameIndex(),
801  0, true)
802  : pNode->GetLang(bSrchForward
803  ? nStart.GetModelIndex()
804  : nEnd.GetModelIndex());
805 
806  if ( eCurrLang != eLastLang )
807  {
808  const lang::Locale aLocale(
809  g_pBreakIt->GetLocale( eCurrLang ) );
810  rSText.SetLocale( utl::TextSearch::UpgradeToSearchOptions2( rSearchOpt), aLocale );
811  eLastLang = eCurrLang;
812  }
813  }
814  pScriptIter->Next();
815  }
816  AmbiguousIndex nProxyStart = nStart;
817  AmbiguousIndex nProxyEnd = nEnd;
818  if( nSearchScript == nCurrScript &&
819  (rSText.*fnMove.fnSearch)( sCleanStr, &nProxyStart.GetAnyIndex(), &nProxyEnd.GetAnyIndex(), nullptr) &&
820  !(bZeroMatch = (nProxyStart == nProxyEnd)))
821  {
822  nStart = nProxyStart;
823  nEnd = nProxyEnd;
824  // set section correctly
825  *rSearchPam.GetPoint() = *pPam->GetPoint();
826  rSearchPam.SetMark();
827 
828  // adjust start and end
829  if( !aFltArr.empty() )
830  {
831  // if backward search, switch positions temporarily
832  if (!bSrchForward) { std::swap(nStart, nEnd); }
833 
834  AmbiguousIndex nNew = nStart;
835  for (size_t n = 0; n < aFltArr.size() && aFltArr[ n ] <= nStart; ++n )
836  {
837  ++nNew.GetAnyIndex();
838  }
839 
840  nStart = nNew;
841  nNew = nEnd;
842  for( size_t n = 0; n < aFltArr.size() && aFltArr[ n ] < nEnd; ++n )
843  {
844  ++nNew.GetAnyIndex();
845  }
846 
847  nEnd = nNew;
848  // if backward search, switch positions temporarily
849  if( !bSrchForward ) { std::swap(nStart, nEnd); }
850  }
851  if (pLayout)
852  {
853  *rSearchPam.GetMark() = pFrame->MapViewToModelPos(nStart.GetFrameIndex());
854  *rSearchPam.GetPoint() = pFrame->MapViewToModelPos(nEnd.GetFrameIndex());
855  }
856  else
857  {
858  rSearchPam.GetMark()->nContent = nStart.GetModelIndex();
859  rSearchPam.GetPoint()->nContent = nEnd.GetModelIndex();
860  }
861 
862  // if backward search, switch point and mark
863  if( !bSrchForward )
864  rSearchPam.Exchange();
865  bFound = true;
866  break;
867  }
868  else
869  {
870  nEnd = nProxyEnd;
871  }
872  nStart = nEnd;
873  }
874 
875  pScriptIter.reset();
876 
877  if ( bFound )
878  return true;
879  else if ((bChkEmptyPara && !nStart.GetAnyIndex() && !nTextLen.GetAnyIndex())
880  || bChkParaEnd)
881  {
882  *rSearchPam.GetPoint() = *pPam->GetPoint();
883  if (pLayout)
884  {
885  *rSearchPam.GetPoint() = pFrame->MapViewToModelPos(
886  bChkParaEnd ? nTextLen.GetFrameIndex() : TextFrameIndex(0));
887  }
888  else
889  {
890  rSearchPam.GetPoint()->nContent = bChkParaEnd ? nTextLen.GetModelIndex() : 0;
891  }
892  rSearchPam.SetMark();
893  const SwNode *const pSttNd = bSrchForward
894  ? &rSearchPam.GetPoint()->nNode.GetNode() // end of the frame
895  : &rNdIdx.GetNode(); // keep the bug as-is for now...
896  /* FIXME: this condition does not work for !bSrchForward backward
897  * search, it probably never did. (pSttNd != &rNdIdx.GetNode())
898  * is never true in this case. */
899  if( (bSrchForward || pSttNd != &rNdIdx.GetNode()) &&
900  rSearchPam.Move(fnMoveForward, GoInContent) &&
901  (!bSrchForward || pSttNd != &rSearchPam.GetPoint()->nNode.GetNode()) &&
902  SwNodeOffset(1) == abs(rSearchPam.GetPoint()->nNode.GetIndex() -
903  rSearchPam.GetMark()->nNode.GetIndex()))
904  {
905  // if backward search, switch point and mark
906  if( !bSrchForward )
907  rSearchPam.Exchange();
908  return true;
909  }
910  }
911  return bFound;
912 }
913 
914 namespace {
915 
917 struct SwFindParaText : public SwFindParas
918 {
919  const i18nutil::SearchOptions2& m_rSearchOpt;
920  SwCursor& m_rCursor;
921  SwRootFrame const* m_pLayout;
922  utl::TextSearch m_aSText;
923  bool m_bReplace;
924  bool m_bSearchInNotes;
925 
926  SwFindParaText(const i18nutil::SearchOptions2& rOpt, bool bSearchInNotes,
927  bool bRepl, SwCursor& rCursor, SwRootFrame const*const pLayout)
928  : m_rSearchOpt( rOpt )
929  , m_rCursor( rCursor )
930  , m_pLayout(pLayout)
931  , m_aSText( utl::TextSearch::UpgradeToSearchOptions2(rOpt) )
932  , m_bReplace( bRepl )
933  , m_bSearchInNotes( bSearchInNotes )
934  {}
935  virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool bInReadOnly, std::unique_ptr<SvxSearchItem>& xSearchItem) override;
936  virtual bool IsReplaceMode() const override;
937  virtual ~SwFindParaText();
938 };
939 
940 }
941 
942 SwFindParaText::~SwFindParaText()
943 {
944 }
945 
946 int SwFindParaText::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
947  const SwPaM & rRegion, bool bInReadOnly,
948  std::unique_ptr<SvxSearchItem>& xSearchItem)
949 {
950  if( bInReadOnly && m_bReplace )
951  bInReadOnly = false;
952 
953  const bool bFnd = sw::FindTextImpl(rCursor, m_rSearchOpt, m_bSearchInNotes,
954  m_aSText, fnMove, rRegion, bInReadOnly, m_pLayout, xSearchItem);
955 
956  if( bFnd && m_bReplace ) // replace string
957  {
958  // use replace method in SwDoc
959  const bool bRegExp(SearchAlgorithms2::REGEXP == m_rSearchOpt.AlgorithmType2);
960  SwIndex& rSttCntIdx = rCursor.Start()->nContent;
961  const sal_Int32 nSttCnt = rSttCntIdx.GetIndex();
962  // add to shell-cursor-ring so that the regions will be moved eventually
963  SwPaM* pPrev(nullptr);
964  if( bRegExp )
965  {
966  pPrev = const_cast<SwPaM&>(rRegion).GetPrev();
967  const_cast<SwPaM&>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() );
968  }
969 
970  std::optional<OUString> xRepl;
971  if (bRegExp)
972  xRepl = sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout);
973  bool const bReplaced = sw::ReplaceImpl(rCursor,
974  xRepl ? *xRepl : m_rSearchOpt.replaceString,
975  bRegExp, m_rCursor.GetDoc(), m_pLayout);
976 
977  m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
978 
979  if( bRegExp )
980  {
981  // and remove region again
982  SwPaM* p;
983  SwPaM* pNext(const_cast<SwPaM*>(&rRegion));
984  do {
985  p = pNext;
986  pNext = p->GetNext();
987  p->MoveTo(const_cast<SwPaM*>(&rRegion));
988  } while( p != pPrev );
989  }
990  if (bRegExp && !bReplaced)
991  { // fdo#80715 avoid infinite loop if join failed
992  bool bRet = ((&fnMoveForward == &fnMove) ? &GoNextPara : &GoPrevPara)
993  (rCursor, fnMove);
994  (void) bRet;
995  assert(bRet); // if join failed, next node must be SwTextNode
996  }
997  else
998  rCursor.Start()->nContent = nSttCnt;
999  return FIND_NO_RING;
1000  }
1001  return bFnd ? FIND_FOUND : FIND_NOT_FOUND;
1002 }
1003 
1004 bool SwFindParaText::IsReplaceMode() const
1005 {
1006  return m_bReplace;
1007 }
1008 
1009 sal_uLong SwCursor::Find_Text( const i18nutil::SearchOptions2& rSearchOpt, bool bSearchInNotes,
1010  SwDocPositions nStart, SwDocPositions nEnd,
1011  bool& bCancel, FindRanges eFndRngs, bool bReplace,
1012  SwRootFrame const*const pLayout)
1013 {
1014  // switch off OLE-notifications
1015  SwDoc& rDoc = GetDoc();
1016  Link<bool,void> aLnk( rDoc.GetOle2Link() );
1017  rDoc.SetOle2Link( Link<bool,void>() );
1018 
1019  bool const bStartUndo = rDoc.GetIDocumentUndoRedo().DoesUndo() && bReplace;
1020  if (bStartUndo)
1021  {
1023  }
1024 
1025  bool bSearchSel = 0 != (rSearchOpt.searchFlag & SearchFlags::REG_NOT_BEGINOFLINE);
1026  if( bSearchSel )
1027  eFndRngs = static_cast<FindRanges>(eFndRngs | FindRanges::InSel);
1028  SwFindParaText aSwFindParaText(rSearchOpt, bSearchInNotes, bReplace, *this, pLayout);
1029  sal_uLong nRet = FindAll( aSwFindParaText, nStart, nEnd, eFndRngs, bCancel );
1030  rDoc.SetOle2Link( aLnk );
1031  if( nRet && bReplace )
1032  rDoc.getIDocumentState().SetModified();
1033 
1034  if (bStartUndo)
1035  {
1037  nRet, rSearchOpt.searchString, rSearchOpt.replaceString));
1038  rDoc.GetIDocumentUndoRedo().EndUndo( SwUndoId::REPLACE, & rewriter );
1039  }
1040  return nRet;
1041 }
1042 
1043 namespace sw {
1044 
1046  SwPaM & rCursor,
1047  OUString const& rReplacement,
1048  bool const bRegExp,
1049  SwDoc & rDoc,
1050  SwRootFrame const*const pLayout)
1051 {
1052  bool bReplaced(true);
1054 #if 0
1055  // FIXME there's some problem with multiple redlines here on Undo
1056  std::vector<std::shared_ptr<SwUnoCursor>> ranges;
1058  || !pLayout
1059  || !pLayout->IsHideRedlines()
1060  || sw::GetRanges(ranges, rDoc, rCursor))
1061  {
1062  bReplaced = rIDCO.ReplaceRange(rCursor, rReplacement, bRegExp);
1063  }
1064  else
1065  {
1066  assert(!ranges.empty());
1067  assert(ranges.front()->GetPoint()->nNode == ranges.front()->GetMark()->nNode);
1068  bReplaced = rIDCO.ReplaceRange(*ranges.front(), rReplacement, bRegExp);
1069  for (auto it = ranges.begin() + 1; it != ranges.end(); ++it)
1070  {
1071  bReplaced &= rIDCO.DeleteAndJoin(**it);
1072  }
1073  }
1074 #else
1076  if (pLayout && pLayout->IsHideRedlines()
1077  && !rIDRA.IsRedlineOn() // otherwise: ReplaceRange will handle it
1078  && (rIDRA.GetRedlineFlags() & RedlineFlags::ShowDelete)) // otherwise: ReplaceRange will DeleteRedline()
1079  {
1081  rIDRA.GetRedline(*rCursor.Start(), &tmp);
1082  while (tmp < rIDRA.GetRedlineTable().size())
1083  {
1084  SwRangeRedline const*const pRedline(rIDRA.GetRedlineTable()[tmp]);
1085  if (*rCursor.End() <= *pRedline->Start())
1086  {
1087  break;
1088  }
1089  if (*pRedline->End() <= *rCursor.Start())
1090  {
1091  ++tmp;
1092  continue;
1093  }
1094  if (pRedline->GetType() == RedlineType::Delete)
1095  {
1096  assert(*pRedline->Start() != *pRedline->End());
1097  // search in hidden layout can't overlap redlines
1098  assert(*rCursor.Start() <= *pRedline->Start() && *pRedline->End() <= *rCursor.End());
1099  SwPaM pam(*pRedline, nullptr);
1100  bReplaced &= rIDCO.DeleteAndJoin(pam);
1101  }
1102  else
1103  {
1104  ++tmp;
1105  }
1106  }
1107  }
1108  bReplaced &= rIDCO.ReplaceRange(rCursor, rReplacement, bRegExp);
1109 #endif
1110  return bReplaced;
1111 }
1112 
1113 std::optional<OUString> ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
1114  SwPaM *const pPam, SwRootFrame const*const pLayout)
1115 {
1116  std::optional<OUString> xRet;
1117  if( pPam && pPam->HasMark() &&
1118  SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2 )
1119  {
1120  SwContentNode const*const pTextNode = pPam->GetContentNode();
1121  SwContentNode const*const pMarkTextNode = pPam->GetContentNode(false);
1122  if (!pTextNode || !pTextNode->IsTextNode()
1123  || !pMarkTextNode || !pMarkTextNode->IsTextNode())
1124  {
1125  return xRet;
1126  }
1127  SwTextFrame const*const pFrame(pLayout
1128  ? static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(pLayout))
1129  : nullptr);
1130  const bool bParaEnd = rSearchOpt.searchString == "$" || rSearchOpt.searchString == "^$" || rSearchOpt.searchString == "$^";
1131  if (bParaEnd || (pLayout
1132  ? sw::FrameContainsNode(*pFrame, pPam->GetMark()->nNode.GetIndex())
1133  : pTextNode == pMarkTextNode))
1134  {
1136  SearchResult aResult;
1137  OUString aReplaceStr( rSearchOpt.replaceString );
1138  if (bParaEnd)
1139  {
1140  OUString const aStr("\\n");
1141  aResult.subRegExpressions = 1;
1142  aResult.startOffset = { 0 };
1143  aResult.endOffset = { aStr.getLength() };
1144  aSText.ReplaceBackReferences( aReplaceStr, aStr, aResult );
1145  xRet = aReplaceStr;
1146  }
1147  else
1148  {
1149  AmbiguousIndex nStart;
1150  AmbiguousIndex nEnd;
1151  if (pLayout)
1152  {
1153  nStart.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->Start()));
1154  nEnd.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->End()));
1155  }
1156  else
1157  {
1158  nStart.SetModelIndex(pPam->Start()->nContent.GetIndex());
1159  nEnd.SetModelIndex(pPam->End()->nContent.GetIndex());
1160  }
1161  std::vector<AmbiguousIndex> aFltArr;
1162  OUString const aStr = lcl_CleanStr(*pTextNode->GetTextNode(), pFrame, pLayout,
1163  nStart, nEnd, aFltArr, false, false);
1164  if (aSText.SearchForward(aStr, &nStart.GetAnyIndex(), &nEnd.GetAnyIndex(), &aResult))
1165  {
1166  aSText.ReplaceBackReferences( aReplaceStr, aStr, aResult );
1167  xRet = aReplaceStr;
1168  }
1169  }
1170  }
1171  }
1172  return xRet;
1173 }
1174 
1175 } // namespace sw
1176 
1177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::optional< OUString > ReplaceBackReferences(const i18nutil::SearchOptions2 &rSearchOpt, SwPaM *const pPam, SwRootFrame const *const pLayout)
Helperfunction to resolve backward references in regular expressions.
Definition: findtxt.cxx:1113
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:162
bool GoInContent(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:968
SwRewriter MakeUndoReplaceRewriter(sal_uLong const occurrences, OUString const &sOld, OUString const &sNew)
Definition: unins.cxx:531
bool GetRanges(std::vector< std::shared_ptr< SwUnoCursor >> &rRanges, SwDoc &rDoc, SwPaM const &rDelPam)
Definition: autofmt.cxx:1112
Marks a position in the document model.
Definition: pam.hxx:36
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false)
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Definition: pam.cxx:821
SdrView * GetDrawView()
Definition: vnew.cxx:373
LanguageType GetLangOfChar(TextFrameIndex nIndex, sal_uInt16 nScript, bool bNoChar=false) const
Definition: txtfrm.cxx:1346
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_METAFIELD(49)
const OUString & GetText() const
Definition: ndtxt.hxx:218
std::unique_ptr< SwPaM > MakeRegion(SwMoveFnCollection const &fnMove, const SwPaM &rOrigRg)
make a new region
Definition: pam.cxx:522
SwDocShell * GetDocShell()
Definition: doc.hxx:1351
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:226
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_META(48)
SwNodeIndex nNode
Definition: pam.hxx:38
static bool DoSearch(SwPaM &rSearchPam, const i18nutil::SearchOptions2 &rSearchOpt, utl::TextSearch &rSText, SwMoveFnCollection const &fnMove, bool bSrchForward, bool bRegSearch, bool bChkEmptyPara, bool bChkParaEnd, AmbiguousIndex &nStart, AmbiguousIndex &nEnd, AmbiguousIndex nTextLen, SwTextNode const *pNode, SwTextFrame const *pTextFrame, SwRootFrame const *pLayout, SwPaM *pPam)
Definition: findtxt.cxx:729
bool FrameContainsNode(SwContentFrame const &rFrame, SwNodeOffset nNodeIndex)
Definition: txtfrm.cxx:290
sal_Int32 StartSearchAndReplace(const SvxSearchItem &rSearchItem)
SdrTextObj * GetTextEditObject() const
virtual void SetModified()=0
Must be called manually at changes of format.
sal_uIntPtr sal_uLong
const SwPosition * GetMark() const
Definition: pam.hxx:210
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1210
sal_Int64 n
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:187
void SetOle2Link(const Link< bool, void > &rLink)
Definition: doc.hxx:1327
virtual bool Search(const SwPaM &rPaM, const SvxSearchItem &rSearchItem)=0
Searches text in shapes anchored inside rPaM.
SwNode & GetNode() const
Definition: ndindex.hxx:128
void SetActiveSidebarWin(sw::annotation::SwAnnotationWin *p)
Definition: PostItMgr.cxx:2194
Dialog to specify the properties of date form field.
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:144
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1296
SwNodeOffset abs(const SwNodeOffset &a)
Definition: nodeoffset.hxx:34
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
EmbeddedObjectRef * pObject
The root element of a Writer document layout.
Definition: rootfrm.hxx:81
void MoveTo(value_type *pDestRing)
Removes this item from its current ring container and adds it to another ring container.
Definition: ring.hxx:135
Find in selections.
sal_uInt16 GetRealScriptOfText(const OUString &rText, sal_Int32 nPos) const
Definition: breakit.cxx:83
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:155
#define CHAR_SOFTHYPHEN
Definition: swtypes.hxx:163
SwDocPositions
Definition: cshtyp.hxx:103
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:230
Used by the UI to modify the document model.
Definition: wrtsh.hxx:96
std::enable_if< std::is_signed< T >::value, SwNodeOffset >::type operator-(SwNodeOffset a, T n)
Definition: nodeoffset.hxx:29
#define CH_TXTATR_INWORD
Definition: hintids.hxx:174
static i18nutil::SearchOptions2 UpgradeToSearchOptions2(const i18nutil::SearchOptions &rOptions)
SwIndex nContent
Definition: pam.hxx:39
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:43
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1328
static bool IsRedlineOn(const RedlineFlags eM)
void Edit()
Definition: wrtsh1.cxx:183
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:33
FindRanges
Definition: cshtyp.hxx:90
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:161
SwFrameFormat * FindFrameFormat(SdrObject *pObj)
The Get reverse way: seeks the format to the specified object.
Definition: dcontact.cxx:121
void UnmarkAll()
virtual bool DoesUndo() const =0
Is Undo enabled?
SwPaM * GetNext()
Definition: pam.hxx:265
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:162
bool SearchForward(const OUString &rStr, sal_Int32 *pStart, sal_Int32 *pEnd, css::util::SearchResult *pRes=nullptr)
bool GoPrevPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1000
sal_uInt32 tag
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:502
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
Style of a layout element.
Definition: frmfmt.hxx:59
SwNodeIndex & Assign(SwNodes const &rNds, SwNodeOffset)
Definition: ndindex.hxx:281
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
TextFrameIndex MapModelToViewPos(SwPosition const &rPos) const
Definition: txtfrm.cxx:1270
int i
SvxSearchCmd GetCommand() const
SwDoc & GetDoc()
Definition: node.hxx:213
const SwPosition * GetPoint() const
Definition: pam.hxx:208
sal_uInt16 SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2 &rSearchOptions, bool bSrchForward)
Definition: PostItMgr.cxx:2315
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
#define LANGUAGE_SYSTEM
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(58)
Count
void Exchange()
Definition: pam.cxx:490
SwContentNode * GetContentNode()
Definition: node.hxx:625
SwNodeOffset GetIndex() const
Definition: node.hxx:292
vector_type::size_type size_type
Definition: docary.hxx:222
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:206
void SetLocale(const i18nutil::SearchOptions2 &rOpt, const css::lang::Locale &rLocale)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
Marks a character position inside a document model node.
Definition: index.hxx:33
static SvxSearchItem * GetSearchItem()
Definition: view.hxx:652
T m_value
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
Definition: docsh.hxx:225
const OutlinerView * GetTextEditOutlinerView() const
bool operator<(const wwFont &r1, const wwFont &r2)
Definition: wrtw8sty.cxx:849
Marks a node in the document model.
Definition: ndindex.hxx:30
virtual bool ReplaceRange(SwPaM &rPam, const OUString &rNewStr, const bool bRegExReplace)=0
Replace selected range in a TextNode with string.
T static_txtattr_cast(S *s)
Definition: txatbase.hxx:257
Text operation/manipulation interface.
bool ReplaceImpl(SwPaM &rCursor, OUString const &rReplacement, bool const bRegExp, SwDoc &rDoc, SwRootFrame const *const pLayout)
Definition: findtxt.cxx:1045
const tools::Rectangle & GetAllMarkedRect() const
show all deletes
const int FIND_NO_RING
Definition: swcrsr.hxx:37
const SwPosition * Start() const
Definition: pam.hxx:213
constexpr Point TopLeft() const
tools::Long CallSetCursor(const Point *pPt, bool bProp)
Definition: wrtsh.hxx:123
SW_DLLPUBLIC bool HasActiveSidebarWin() const
Definition: PostItMgr.cxx:2366
virtual const SwRangeRedline * GetRedline(const SwPosition &rPos, SwRedlineTable::size_type *pFndPos) const =0
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
const css::lang::Locale & GetLocale(const LanguageType aLang)
Definition: breakit.hxx:67
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:335
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:67
sal_uLong Find_Text(const i18nutil::SearchOptions2 &rSearchOpt, bool bSearchInNotes, SwDocPositions nStart, SwDocPositions nEnd, bool &bCancel, FindRanges, bool bReplace=false, SwRootFrame const *const pLayout=nullptr)
Definition: findtxt.cxx:1009
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
const int FIND_FOUND
Definition: swcrsr.hxx:36
sal_Int32 GetIndex() const
Definition: index.hxx:91
SwNodes & GetNodes()
Definition: doc.hxx:408
const SwPosition * End() const
Definition: pam.hxx:218
LanguageType GetLang(const sal_Int32 nBegin, const sal_Int32 nLen=0, sal_uInt16 nScript=0) const
Definition: thints.cxx:3433
bool GoNextPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1042
void * p
constexpr TypedWhichId< SwTOXMark > RES_TXTATR_TOXMARK(47)
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
Any value
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:421
const SwPostItMgr * GetPostItMgr() const
Definition: viewsh.hxx:561
const int FIND_NOT_FOUND
Definition: swcrsr.hxx:35
SwDoc & GetDoc() const
Definition: pam.hxx:244
bool FindTextImpl(SwPaM &rSearchPam, const i18nutil::SearchOptions2 &rSearchOpt, bool bSearchInNotes, utl::TextSearch &rSText, SwMoveFnCollection const &fnMove, const SwPaM &rRegion, bool bInReadOnly, SwRootFrame const *const pLayout, std::unique_ptr< SvxSearchItem > &xSearchItem)
Search.
Definition: findtxt.cxx:369
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:476
constexpr TypedWhichId< SwFormatRefMark > RES_TXTATR_REFMARK(RES_TXTATR_WITHEND_BEGIN)
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...
bool IsTextNode() const
Definition: node.hxx:646
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1249
aStr
static OUString lcl_CleanStr(const SwTextNode &rNd, SwTextFrame const *const pFrame, SwRootFrame const *const pLayout, AmbiguousIndex const nStart, AmbiguousIndex &rEnd, std::vector< AmbiguousIndex > &rArr, bool const bRemoveSoftHyphen, bool const bRemoveCommentAnchors)
Definition: findtxt.cxx:181
void ReplaceBackReferences(OUString &rReplaceStr, std::u16string_view rStr, const css::util::SearchResult &rResult) const
sal_uInt16 FinishSearchReplace(const i18nutil::SearchOptions2 &rSearchOptions, bool bSrchForward)
Definition: PostItMgr.cxx:2303
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:864
SearchText fnSearch
Definition: pamtyp.hxx:77
Base class of the Writer document model elements.
Definition: node.hxx:81
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo