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