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