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  if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
297  {
298  --rEnd.GetAnyIndex();
299  }
300  buf.remove(nCurrent.GetAnyIndex(), 1);
301  }
302  else
303  {
304  if ( bEmpty )
305  aReplaced.push_back( nCurrent );
306  buf[nCurrent.GetAnyIndex()] = '\x7f';
307  }
308  }
309  break;
311  {
312  if( bRemoveCommentAnchors )
313  {
314  rArr.push_back( nCurrent );
315  if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
316  {
317  --rEnd.GetAnyIndex();
318  }
319  buf.remove( nCurrent.GetAnyIndex(), 1 );
320  }
321  }
322  break;
323  default:
324  OSL_FAIL( "unknown case in lcl_CleanStr" );
325  break;
326  }
327  }
328  pNextHint = iter.NextAttr(pNextHintNode);
329  }
330 
331  if ( bNewSoftHyphen )
332  {
333  rArr.push_back( nCurrent );
334 
335  // If the soft hyphen to be removed is past the end of the range we're searching in,
336  // don't adjust the end.
337  if (rEnd.GetAnyIndex() > nCurrent.GetAnyIndex())
338  {
339  --rEnd.GetAnyIndex();
340  }
341 
342  buf.remove(nCurrent.GetAnyIndex(), 1);
343  ++nSoftHyphen.GetAnyIndex();
344  }
345  }
346  while ( true );
347 
348  for (auto i = aReplaced.size(); i; )
349  {
350  const AmbiguousIndex nTmp = aReplaced[ --i ];
351  if (nTmp.GetAnyIndex() == buf.getLength() - 1)
352  {
353  buf.truncate(nTmp.GetAnyIndex());
354  rArr.push_back( nTmp );
355  --rEnd.GetAnyIndex();
356  }
357  }
358 
359  return buf.makeStringAndClear();
360 }
361 
362 static bool DoSearch(SwPaM & rSearchPam,
363  const i18nutil::SearchOptions2& rSearchOpt, utl::TextSearch& rSText,
364  SwMoveFnCollection const & fnMove,
365  bool bSrchForward, bool bRegSearch, bool bChkEmptyPara, bool bChkParaEnd,
366  AmbiguousIndex & nStart, AmbiguousIndex & nEnd, AmbiguousIndex nTextLen,
367  SwTextNode const* pNode, SwTextFrame const* pTextFrame,
368  SwRootFrame const* pLayout, SwPaM* pPam);
369 
370 namespace sw {
371 
372 bool FindTextImpl(SwPaM & rSearchPam,
373  const i18nutil::SearchOptions2& rSearchOpt, bool bSearchInNotes,
374  utl::TextSearch& rSText,
375  SwMoveFnCollection const & fnMove, const SwPaM & rRegion,
376  bool bInReadOnly, SwRootFrame const*const pLayout)
377 {
378  if( rSearchOpt.searchString.isEmpty() )
379  return false;
380 
381  std::unique_ptr<SwPaM> pPam = sw::MakeRegion(fnMove, rRegion);
382  const bool bSrchForward = &fnMove == &fnMoveForward;
383  SwNodeIndex& rNdIdx = pPam->GetPoint()->nNode;
384  SwIndex& rContentIdx = pPam->GetPoint()->nContent;
385 
386  // If bFound is true then the string was found and is between nStart and nEnd
387  bool bFound = false;
388  // start position in text or initial position
389  bool bFirst = true;
390  SwContentNode * pNode;
391 
392  const bool bRegSearch = SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2;
393  const bool bChkEmptyPara = bRegSearch && 2 == rSearchOpt.searchString.getLength() &&
394  ( rSearchOpt.searchString == "^$" ||
395  rSearchOpt.searchString == "$^" );
396  const bool bChkParaEnd = bRegSearch && rSearchOpt.searchString == "$";
397 
398  SvxSearchItem aSearchItem(SID_SEARCH_ITEM); // this is a very expensive operation (calling configmgr etc.)
399  aSearchItem.SetSearchOptions(rSearchOpt);
400  aSearchItem.SetBackward(!bSrchForward);
401 
402  // LanguageType eLastLang = 0;
403  while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
404  {
405  if( pNode->IsTextNode() )
406  {
407  SwTextNode& rTextNode = *pNode->GetTextNode();
408  SwTextFrame const*const pFrame(pLayout
409  ? static_cast<SwTextFrame const*>(rTextNode.getLayoutFrame(pLayout))
410  : nullptr);
411  assert(!pLayout || pFrame);
412  AmbiguousIndex nTextLen;
413  if (pLayout)
414  {
415  nTextLen.SetFrameIndex(TextFrameIndex(pFrame->GetText().getLength()));
416  }
417  else
418  {
419  nTextLen.SetModelIndex(rTextNode.GetText().getLength());
420  }
421  AmbiguousIndex nEnd;
422  if (pLayout
423  ? FrameContainsNode(*pFrame, pPam->GetMark()->nNode.GetIndex())
424  : rNdIdx == pPam->GetMark()->nNode)
425  {
426  if (pLayout)
427  {
428  nEnd.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->GetMark()));
429  }
430  else
431  {
432  nEnd.SetModelIndex(pPam->GetMark()->nContent.GetIndex());
433  }
434  }
435  else
436  {
437  if (bSrchForward)
438  {
439  nEnd = nTextLen;
440  }
441  else
442  {
443  if (pLayout)
444  {
445  nEnd.SetFrameIndex(TextFrameIndex(0));
446  }
447  else
448  {
449  nEnd.SetModelIndex(0);
450  }
451  }
452  }
453  AmbiguousIndex nStart;
454  if (pLayout)
455  {
456  nStart.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->GetPoint()));
457  }
458  else
459  {
460  nStart.SetModelIndex(rContentIdx.GetIndex());
461  }
462 
463  /* #i80135# */
464  // if there are SwPostItFields inside our current node text, we
465  // split the text into separate pieces and search for text inside
466  // the pieces as well as inside the fields
467  MaybeMergedIter iter(pLayout ? pFrame : nullptr, pLayout ? nullptr : &rTextNode);
468 
469  // count PostItFields by looping over all fields
470  std::vector<std::pair<SwTextAttr const*, AmbiguousIndex>> postits;
471  if (bSearchInNotes)
472  {
473  if (!bSrchForward)
474  {
475  std::swap(nStart, nEnd);
476  }
477 
478  SwTextNode const* pTemp(nullptr);
479  while (SwTextAttr const*const pTextAttr = iter.NextAttr(pTemp))
480  {
481  if ( pTextAttr->Which()==RES_TXTATR_ANNOTATION )
482  {
483  AmbiguousIndex aPos;
484  aPos.SetModelIndex(pTextAttr->GetStart());
485  if (pLayout)
486  {
487  aPos.SetFrameIndex(pFrame->MapModelToView(pTemp, aPos.GetModelIndex()));
488  }
489  if ((nStart <= aPos) && (aPos <= nEnd))
490  {
491  postits.emplace_back(pTextAttr, aPos);
492  }
493  }
494  }
495 
496  if (!bSrchForward)
497  {
498  std::swap(nStart, nEnd);
499  }
500 
501  }
502 
503  SwDocShell *const pDocShell = pNode->GetDoc()->GetDocShell();
504  SwWrtShell *const pWrtShell = pDocShell ? pDocShell->GetWrtShell() : nullptr;
505  SwPostItMgr *const pPostItMgr = pWrtShell ? pWrtShell->GetPostItMgr() : nullptr;
506 
507  // If there is an active text edit, then search there.
508  bool bEndedTextEdit = false;
509  SdrView* pSdrView = pWrtShell ? pWrtShell->GetDrawView() : nullptr;
510  if (pSdrView)
511  {
512  // If the edited object is not anchored to this node, then ignore it.
513  SdrObject* pObject = pSdrView->GetTextEditObject();
514  if (pObject)
515  {
516  if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
517  {
518  const SwPosition* pPosition = pFrameFormat->GetAnchor().GetContentAnchor();
519  if (!pPosition || (pLayout
520  ? !FrameContainsNode(*pFrame, pPosition->nNode.GetIndex())
521  : pPosition->nNode.GetIndex() != pNode->GetIndex()))
522  pObject = nullptr;
523  }
524  }
525 
526  if (pObject)
527  {
528  sal_uInt16 nResult = pSdrView->GetTextEditOutlinerView()->StartSearchAndReplace(aSearchItem);
529  if (!nResult)
530  {
531  // If not found, end the text edit.
532  pSdrView->SdrEndTextEdit();
533  const Point aPoint(pSdrView->GetAllMarkedRect().TopLeft());
534  pSdrView->UnmarkAll();
535  pWrtShell->CallSetCursor(&aPoint, true);
536  pWrtShell->Edit();
537  bEndedTextEdit = true;
538  }
539  else
540  {
541  bFound = true;
542  break;
543  }
544  }
545  }
546 
548  {
549  // Writer and editeng selections are not supported in parallel.
550  SvxSearchItem* pSearchItem = SwView::GetSearchItem();
551  // If we just finished search in shape text, don't attempt to do that again.
552  if (!bEndedTextEdit && !(pSearchItem && pSearchItem->GetCommand() == SvxSearchCmd::FIND_ALL))
553  {
554  // If there are any shapes anchored to this node, search there.
555  SwPaM aPaM(pNode->GetDoc()->GetNodes().GetEndOfContent());
556  if (pLayout)
557  {
558  *aPaM.GetPoint() = pFrame->MapViewToModelPos(nStart.GetFrameIndex());
559  }
560  else
561  {
562  aPaM.GetPoint()->nNode = rTextNode;
563  aPaM.GetPoint()->nContent.Assign(
564  aPaM.GetPoint()->nNode.GetNode().GetTextNode(),
565  nStart.GetModelIndex());
566  }
567  aPaM.SetMark();
568  if (pLayout)
569  {
570  aPaM.GetMark()->nNode = (pFrame->GetMergedPara()
571  ? *pFrame->GetMergedPara()->pLastNode
572  : rTextNode)
573  .GetIndex() + 1;
574  }
575  else
576  {
577  aPaM.GetMark()->nNode = rTextNode.GetIndex() + 1;
578  }
579  aPaM.GetMark()->nContent.Assign(aPaM.GetMark()->nNode.GetNode().GetTextNode(), 0);
580  if (pNode->GetDoc()->getIDocumentDrawModelAccess().Search(aPaM, aSearchItem) && pSdrView)
581  {
582  if (SdrObject* pObject = pSdrView->GetTextEditObject())
583  {
584  if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
585  {
586  const SwPosition* pPosition = pFrameFormat->GetAnchor().GetContentAnchor();
587  if (pPosition)
588  {
589  // Set search position to the shape's anchor point.
590  *rSearchPam.GetPoint() = *pPosition;
591  rSearchPam.GetPoint()->nContent.Assign(pPosition->nNode.GetNode().GetContentNode(), 0);
592  rSearchPam.SetMark();
593  bFound = true;
594  break;
595  }
596  }
597  }
598  }
599  }
600  }
601 
602  // do we need to finish a note?
603  if (pPostItMgr && pPostItMgr->HasActiveSidebarWin())
604  {
605  if (bSearchInNotes)
606  {
607  if (!postits.empty())
608  {
609  if (bSrchForward)
610  {
611  postits.erase(postits.begin());
612  }
613  else
614  {
615  postits.pop_back(); // hope that's the right one?
616  }
617  }
618  //search inside, finish and put focus back into the doc
619  if (pPostItMgr->FinishSearchReplace(rSearchOpt,bSrchForward))
620  {
621  bFound = true ;
622  break;
623  }
624  }
625  else
626  {
627  pPostItMgr->SetActiveSidebarWin(nullptr);
628  }
629  }
630 
631  if (!postits.empty())
632  {
633  // now we have to split
634  AmbiguousIndex nStartInside;
635  AmbiguousIndex nEndInside;
636  sal_Int32 aLoop = bSrchForward ? 0 : postits.size();
637 
638  while ((0 <= aLoop) && (o3tl::make_unsigned(aLoop) <= postits.size()))
639  {
640  if (bSrchForward)
641  {
642  if (aLoop == 0)
643  {
644  nStartInside = nStart;
645  }
646  else if (pLayout)
647  {
648  nStartInside.SetFrameIndex(postits[aLoop - 1].second.GetFrameIndex() + TextFrameIndex(1));
649  }
650  else
651  {
652  nStartInside.SetModelIndex(postits[aLoop - 1].second.GetModelIndex() + 1);
653  }
654  nEndInside = static_cast<size_t>(aLoop) == postits.size()
655  ? nEnd
656  : postits[aLoop].second;
657  nTextLen = nEndInside - nStartInside;
658  }
659  else
660  {
661  nStartInside = static_cast<size_t>(aLoop) == postits.size()
662  ? nStart
663  : postits[aLoop].second;
664  if (aLoop == 0)
665  {
666  nEndInside = nEnd;
667  }
668  else if (pLayout)
669  {
670  nEndInside.SetFrameIndex(postits[aLoop - 1].second.GetFrameIndex() + TextFrameIndex(1));
671  }
672  else
673  {
674  nEndInside.SetModelIndex(postits[aLoop - 1].second.GetModelIndex() + 1);
675  }
676  nTextLen = nStartInside - nEndInside;
677  }
678  // search inside the text between a note
679  bFound = DoSearch( rSearchPam,
680  rSearchOpt, rSText, fnMove, bSrchForward,
681  bRegSearch, bChkEmptyPara, bChkParaEnd,
682  nStartInside, nEndInside, nTextLen,
683  pNode->GetTextNode(), pFrame, pLayout,
684  pPam.get() );
685  if ( bFound )
686  break;
687  else
688  {
689  // we should now be right in front of a note, search inside
690  if (bSrchForward
691  ? (static_cast<size_t>(aLoop) != postits.size())
692  : (aLoop != 0))
693  {
694  const SwTextAttr *const pTextAttr = bSrchForward
695  ? postits[aLoop].first
696  : postits[aLoop - 1].first;
697  if (pPostItMgr && pPostItMgr->SearchReplace(
698  static_txtattr_cast<SwTextField const*>(pTextAttr)->GetFormatField(),rSearchOpt,bSrchForward))
699  {
700  bFound = true ;
701  break;
702  }
703  }
704  }
705  aLoop = bSrchForward ? aLoop+1 : aLoop-1;
706  }
707  }
708  else
709  {
710  // if there is no SwPostItField inside or searching inside notes
711  // is disabled, we search the whole length just like before
712  bFound = DoSearch( rSearchPam,
713  rSearchOpt, rSText, fnMove, bSrchForward,
714  bRegSearch, bChkEmptyPara, bChkParaEnd,
715  nStart, nEnd, nTextLen,
716  pNode->GetTextNode(), pFrame, pLayout,
717  pPam.get() );
718  }
719  if (bFound)
720  break;
721  }
722  }
723  return bFound;
724 }
725 
726 } // namespace sw
727 
728 bool DoSearch(SwPaM & rSearchPam,
729  const i18nutil::SearchOptions2& rSearchOpt, utl::TextSearch& rSText,
730  SwMoveFnCollection const & fnMove, bool bSrchForward, bool bRegSearch,
731  bool bChkEmptyPara, bool bChkParaEnd,
732  AmbiguousIndex & nStart, AmbiguousIndex & nEnd, AmbiguousIndex const nTextLen,
733  SwTextNode const*const pNode, SwTextFrame const*const pFrame,
734  SwRootFrame const*const pLayout, SwPaM* pPam)
735 {
736  bool bFound = false;
737  SwNodeIndex& rNdIdx = pPam->GetPoint()->nNode;
738  OUString sCleanStr;
739  std::vector<AmbiguousIndex> aFltArr;
740  LanguageType eLastLang = LANGUAGE_SYSTEM;
741  // if the search string contains a soft hyphen,
742  // we don't strip them from the text:
743  bool bRemoveSoftHyphens = true;
744  // if the search string contains a comment, we don't strip them from the text
745  const bool bRemoveCommentAnchors = rSearchOpt.searchString.indexOf( CH_TXTATR_INWORD ) == -1;
746 
747  if ( bRegSearch )
748  {
749  if ( -1 != rSearchOpt.searchString.indexOf("\\xAD")
750  || -1 != rSearchOpt.searchString.indexOf("\\x{00AD}")
751  || -1 != rSearchOpt.searchString.indexOf("\\u00AD")
752  || -1 != rSearchOpt.searchString.indexOf("\\U000000AD")
753  || -1 != rSearchOpt.searchString.indexOf("\\N{SOFT HYPHEN}"))
754  {
755  bRemoveSoftHyphens = false;
756  }
757  }
758  else
759  {
760  if ( 1 == rSearchOpt.searchString.getLength() &&
761  CHAR_SOFTHYPHEN == rSearchOpt.searchString.toChar() )
762  bRemoveSoftHyphens = false;
763  }
764 
765  if( bSrchForward )
766  sCleanStr = lcl_CleanStr(*pNode, pFrame, pLayout, nStart, nEnd,
767  aFltArr, bRemoveSoftHyphens, bRemoveCommentAnchors);
768  else
769  sCleanStr = lcl_CleanStr(*pNode, pFrame, pLayout, nEnd, nStart,
770  aFltArr, bRemoveSoftHyphens, bRemoveCommentAnchors);
771 
772  std::unique_ptr<SwScriptIterator> pScriptIter;
773  sal_uInt16 nSearchScript = 0;
774  sal_uInt16 nCurrScript = 0;
775 
776  if (SearchAlgorithms2::APPROXIMATE == rSearchOpt.AlgorithmType2)
777  {
778  pScriptIter.reset(new SwScriptIterator(sCleanStr, nStart.GetAnyIndex(), bSrchForward));
779  nSearchScript = g_pBreakIt->GetRealScriptOfText( rSearchOpt.searchString, 0 );
780  }
781 
782  const AmbiguousIndex nStringEnd = nEnd;
783  bool bZeroMatch = false; // zero-length match, i.e. only $ anchor as regex
784  while ( ((bSrchForward && nStart < nStringEnd) ||
785  (!bSrchForward && nStringEnd < nStart)) && !bZeroMatch )
786  {
787  // SearchAlgorithms_APPROXIMATE works on a per word base so we have to
788  // provide the text searcher with the correct locale, because it uses
789  // the break-iterator
790  if ( pScriptIter )
791  {
792  nEnd.GetAnyIndex() = pScriptIter->GetScriptChgPos();
793  nCurrScript = pScriptIter->GetCurrScript();
794  if ( nSearchScript == nCurrScript )
795  {
796  const LanguageType eCurrLang = pLayout
797  ? pFrame->GetLangOfChar(bSrchForward
798  ? nStart.GetFrameIndex()
799  : nEnd.GetFrameIndex(),
800  0, true)
801  : pNode->GetLang(bSrchForward
802  ? nStart.GetModelIndex()
803  : nEnd.GetModelIndex());
804 
805  if ( eCurrLang != eLastLang )
806  {
807  const lang::Locale aLocale(
808  g_pBreakIt->GetLocale( eCurrLang ) );
809  rSText.SetLocale( utl::TextSearch::UpgradeToSearchOptions2( rSearchOpt), aLocale );
810  eLastLang = eCurrLang;
811  }
812  }
813  pScriptIter->Next();
814  }
815  AmbiguousIndex nProxyStart = nStart;
816  AmbiguousIndex nProxyEnd = nEnd;
817  if( nSearchScript == nCurrScript &&
818  (rSText.*fnMove.fnSearch)( sCleanStr, &nProxyStart.GetAnyIndex(), &nProxyEnd.GetAnyIndex(), nullptr) &&
819  !(bZeroMatch = (nProxyStart == nProxyEnd)))
820  {
821  nStart = nProxyStart;
822  nEnd = nProxyEnd;
823  // set section correctly
824  *rSearchPam.GetPoint() = *pPam->GetPoint();
825  rSearchPam.SetMark();
826 
827  // adjust start and end
828  if( !aFltArr.empty() )
829  {
830  // if backward search, switch positions temporarily
831  if (!bSrchForward) { std::swap(nStart, nEnd); }
832 
833  AmbiguousIndex nNew = nStart;
834  for (size_t n = 0; n < aFltArr.size() && aFltArr[ n ] <= nStart; ++n )
835  {
836  ++nNew.GetAnyIndex();
837  }
838 
839  nStart = nNew;
840  nNew = nEnd;
841  for( size_t n = 0; n < aFltArr.size() && aFltArr[ n ] < nEnd; ++n )
842  {
843  ++nNew.GetAnyIndex();
844  }
845 
846  nEnd = nNew;
847  // if backward search, switch positions temporarily
848  if( !bSrchForward ) { std::swap(nStart, nEnd); }
849  }
850  if (pLayout)
851  {
852  *rSearchPam.GetMark() = pFrame->MapViewToModelPos(nStart.GetFrameIndex());
853  *rSearchPam.GetPoint() = pFrame->MapViewToModelPos(nEnd.GetFrameIndex());
854  }
855  else
856  {
857  rSearchPam.GetMark()->nContent = nStart.GetModelIndex();
858  rSearchPam.GetPoint()->nContent = nEnd.GetModelIndex();
859  }
860 
861  // if backward search, switch point and mark
862  if( !bSrchForward )
863  rSearchPam.Exchange();
864  bFound = true;
865  break;
866  }
867  else
868  {
869  nEnd = nProxyEnd;
870  }
871  nStart = nEnd;
872  }
873 
874  pScriptIter.reset();
875 
876  if ( bFound )
877  return true;
878  else if ((bChkEmptyPara && !nStart.GetAnyIndex() && !nTextLen.GetAnyIndex())
879  || bChkParaEnd)
880  {
881  *rSearchPam.GetPoint() = *pPam->GetPoint();
882  if (pLayout)
883  {
884  *rSearchPam.GetPoint() = pFrame->MapViewToModelPos(
885  bChkParaEnd ? nTextLen.GetFrameIndex() : TextFrameIndex(0));
886  }
887  else
888  {
889  rSearchPam.GetPoint()->nContent = bChkParaEnd ? nTextLen.GetModelIndex() : 0;
890  }
891  rSearchPam.SetMark();
892  const SwNode *const pSttNd = bSrchForward
893  ? &rSearchPam.GetPoint()->nNode.GetNode() // end of the frame
894  : &rNdIdx.GetNode(); // keep the bug as-is for now...
895  /* FIXME: this condition does not work for !bSrchForward backward
896  * search, it probably never did. (pSttNd != &rNdIdx.GetNode())
897  * is never true in this case. */
898  if( (bSrchForward || pSttNd != &rNdIdx.GetNode()) &&
899  rSearchPam.Move(fnMoveForward, GoInContent) &&
900  (!bSrchForward || pSttNd != &rSearchPam.GetPoint()->nNode.GetNode()) &&
901  1 == std::abs(static_cast<int>(rSearchPam.GetPoint()->nNode.GetIndex() -
902  rSearchPam.GetMark()->nNode.GetIndex())))
903  {
904  // if backward search, switch point and mark
905  if( !bSrchForward )
906  rSearchPam.Exchange();
907  return true;
908  }
909  }
910  return bFound;
911 }
912 
913 namespace {
914 
916 struct SwFindParaText : public SwFindParas
917 {
918  const i18nutil::SearchOptions2& m_rSearchOpt;
919  SwCursor& m_rCursor;
920  SwRootFrame const* m_pLayout;
921  utl::TextSearch m_aSText;
922  bool m_bReplace;
923  bool m_bSearchInNotes;
924 
925  SwFindParaText(const i18nutil::SearchOptions2& rOpt, bool bSearchInNotes,
926  bool bRepl, SwCursor& rCursor, SwRootFrame const*const pLayout)
927  : m_rSearchOpt( rOpt )
928  , m_rCursor( rCursor )
929  , m_pLayout(pLayout)
930  , m_aSText( utl::TextSearch::UpgradeToSearchOptions2(rOpt) )
931  , m_bReplace( bRepl )
932  , m_bSearchInNotes( bSearchInNotes )
933  {}
934  virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool bInReadOnly) override;
935  virtual bool IsReplaceMode() const override;
936  virtual ~SwFindParaText();
937 };
938 
939 }
940 
941 SwFindParaText::~SwFindParaText()
942 {
943 }
944 
945 int SwFindParaText::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
946  const SwPaM & rRegion, bool bInReadOnly)
947 {
948  if( bInReadOnly && m_bReplace )
949  bInReadOnly = false;
950 
951  const bool bFnd = sw::FindTextImpl(rCursor, m_rSearchOpt, m_bSearchInNotes,
952  m_aSText, fnMove, rRegion, bInReadOnly, m_pLayout);
953 
954  if( bFnd && m_bReplace ) // replace string
955  {
956  // use replace method in SwDoc
957  const bool bRegExp(SearchAlgorithms2::REGEXP == m_rSearchOpt.AlgorithmType2);
958  SwIndex& rSttCntIdx = rCursor.Start()->nContent;
959  const sal_Int32 nSttCnt = rSttCntIdx.GetIndex();
960  // add to shell-cursor-ring so that the regions will be moved eventually
961  SwPaM* pPrev(nullptr);
962  if( bRegExp )
963  {
964  pPrev = const_cast<SwPaM&>(rRegion).GetPrev();
965  const_cast<SwPaM&>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() );
966  }
967 
968  std::optional<OUString> xRepl;
969  if (bRegExp)
970  xRepl = sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout);
971  bool const bReplaced = sw::ReplaceImpl(rCursor,
972  xRepl ? *xRepl : m_rSearchOpt.replaceString,
973  bRegExp, *m_rCursor.GetDoc(), m_pLayout);
974 
975  m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
976 
977  if( bRegExp )
978  {
979  // and remove region again
980  SwPaM* p;
981  SwPaM* pNext(const_cast<SwPaM*>(&rRegion));
982  do {
983  p = pNext;
984  pNext = p->GetNext();
985  p->MoveTo(const_cast<SwPaM*>(&rRegion));
986  } while( p != pPrev );
987  }
988  if (bRegExp && !bReplaced)
989  { // fdo#80715 avoid infinite loop if join failed
990  bool bRet = ((&fnMoveForward == &fnMove) ? &GoNextPara : &GoPrevPara)
991  (rCursor, fnMove);
992  (void) bRet;
993  assert(bRet); // if join failed, next node must be SwTextNode
994  }
995  else
996  rCursor.Start()->nContent = nSttCnt;
997  return FIND_NO_RING;
998  }
999  return bFnd ? FIND_FOUND : FIND_NOT_FOUND;
1000 }
1001 
1002 bool SwFindParaText::IsReplaceMode() const
1003 {
1004  return m_bReplace;
1005 }
1006 
1007 sal_uLong SwCursor::Find_Text( const i18nutil::SearchOptions2& rSearchOpt, bool bSearchInNotes,
1008  SwDocPositions nStart, SwDocPositions nEnd,
1009  bool& bCancel, FindRanges eFndRngs, bool bReplace,
1010  SwRootFrame const*const pLayout)
1011 {
1012  // switch off OLE-notifications
1013  SwDoc* pDoc = GetDoc();
1014  Link<bool,void> aLnk( pDoc->GetOle2Link() );
1015  pDoc->SetOle2Link( Link<bool,void>() );
1016 
1017  bool const bStartUndo = pDoc->GetIDocumentUndoRedo().DoesUndo() && bReplace;
1018  if (bStartUndo)
1019  {
1020  pDoc->GetIDocumentUndoRedo().StartUndo( SwUndoId::REPLACE, nullptr );
1021  }
1022 
1023  bool bSearchSel = 0 != (rSearchOpt.searchFlag & SearchFlags::REG_NOT_BEGINOFLINE);
1024  if( bSearchSel )
1025  eFndRngs = static_cast<FindRanges>(eFndRngs | FindRanges::InSel);
1026  SwFindParaText aSwFindParaText(rSearchOpt, bSearchInNotes, bReplace, *this, pLayout);
1027  sal_uLong nRet = FindAll( aSwFindParaText, nStart, nEnd, eFndRngs, bCancel );
1028  pDoc->SetOle2Link( aLnk );
1029  if( nRet && bReplace )
1030  pDoc->getIDocumentState().SetModified();
1031 
1032  if (bStartUndo)
1033  {
1035  nRet, rSearchOpt.searchString, rSearchOpt.replaceString));
1036  pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::REPLACE, & rewriter );
1037  }
1038  return nRet;
1039 }
1040 
1041 namespace sw {
1042 
1044  SwPaM & rCursor,
1045  OUString const& rReplacement,
1046  bool const bRegExp,
1047  SwDoc & rDoc,
1048  SwRootFrame const*const pLayout)
1049 {
1050  bool bReplaced(true);
1052 #if 0
1053  // FIXME there's some problem with multiple redlines here on Undo
1054  std::vector<std::shared_ptr<SwUnoCursor>> ranges;
1056  || !pLayout
1057  || !pLayout->IsHideRedlines()
1058  || sw::GetRanges(ranges, rDoc, rCursor))
1059  {
1060  bReplaced = rIDCO.ReplaceRange(rCursor, rReplacement, bRegExp);
1061  }
1062  else
1063  {
1064  assert(!ranges.empty());
1065  assert(ranges.front()->GetPoint()->nNode == ranges.front()->GetMark()->nNode);
1066  bReplaced = rIDCO.ReplaceRange(*ranges.front(), rReplacement, bRegExp);
1067  for (auto it = ranges.begin() + 1; it != ranges.end(); ++it)
1068  {
1069  bReplaced &= rIDCO.DeleteAndJoin(**it);
1070  }
1071  }
1072 #else
1074  if (pLayout && pLayout->IsHideRedlines()
1075  && !rIDRA.IsRedlineOn() // otherwise: ReplaceRange will handle it
1076  && (rIDRA.GetRedlineFlags() & RedlineFlags::ShowDelete)) // otherwise: ReplaceRange will DeleteRedline()
1077  {
1079  rIDRA.GetRedline(*rCursor.Start(), &tmp);
1080  while (tmp < rIDRA.GetRedlineTable().size())
1081  {
1082  SwRangeRedline const*const pRedline(rIDRA.GetRedlineTable()[tmp]);
1083  if (*rCursor.End() <= *pRedline->Start())
1084  {
1085  break;
1086  }
1087  if (*pRedline->End() <= *rCursor.Start())
1088  {
1089  ++tmp;
1090  continue;
1091  }
1092  if (pRedline->GetType() == RedlineType::Delete)
1093  {
1094  assert(*pRedline->Start() != *pRedline->End());
1095  // search in hidden layout can't overlap redlines
1096  assert(*rCursor.Start() <= *pRedline->Start() && *pRedline->End() <= *rCursor.End());
1097  SwPaM pam(*pRedline, nullptr);
1098  bReplaced &= rIDCO.DeleteAndJoin(pam);
1099  }
1100  else
1101  {
1102  ++tmp;
1103  }
1104  }
1105  }
1106  bReplaced &= rIDCO.ReplaceRange(rCursor, rReplacement, bRegExp);
1107 #endif
1108  return bReplaced;
1109 }
1110 
1111 std::optional<OUString> ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
1112  SwPaM *const pPam, SwRootFrame const*const pLayout)
1113 {
1114  std::optional<OUString> xRet;
1115  if( pPam && pPam->HasMark() &&
1116  SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2 )
1117  {
1118  SwContentNode const*const pTextNode = pPam->GetContentNode();
1119  SwContentNode const*const pMarkTextNode = pPam->GetContentNode(false);
1120  if (!pTextNode || !pTextNode->IsTextNode()
1121  || !pMarkTextNode || !pMarkTextNode->IsTextNode())
1122  {
1123  return xRet;
1124  }
1125  SwTextFrame const*const pFrame(pLayout
1126  ? static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(pLayout))
1127  : nullptr);
1128  const bool bParaEnd = rSearchOpt.searchString == "$" || rSearchOpt.searchString == "^$" || rSearchOpt.searchString == "$^";
1129  if (bParaEnd || (pLayout
1130  ? sw::FrameContainsNode(*pFrame, pPam->GetMark()->nNode.GetIndex())
1131  : pTextNode == pMarkTextNode))
1132  {
1134  SearchResult aResult;
1135  OUString aReplaceStr( rSearchOpt.replaceString );
1136  if (bParaEnd)
1137  {
1138  OUString const aStr("\\n");
1139  aResult.subRegExpressions = 1;
1140  aResult.startOffset.realloc(1);
1141  aResult.endOffset.realloc(1);
1142  aResult.startOffset[0] = 0;
1143  aResult.endOffset[0] = aStr.getLength();
1144  aSText.ReplaceBackReferences( aReplaceStr, aStr, aResult );
1145  xRet = aReplaceStr;
1146  }
1147  else
1148  {
1149  OUString const aStr(pLayout
1150  ? pFrame->GetText()
1151  : pTextNode->GetTextNode()->GetText());
1152  AmbiguousIndex nStart;
1153  AmbiguousIndex nEnd;
1154  if (pLayout)
1155  {
1156  nStart.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->Start()));
1157  nEnd.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->End()));
1158  }
1159  else
1160  {
1161  nStart.SetModelIndex(pPam->Start()->nContent.GetIndex());
1162  nEnd.SetModelIndex(pPam->End()->nContent.GetIndex());
1163  }
1164  if (aSText.SearchForward(aStr, &nStart.GetAnyIndex(), &nEnd.GetAnyIndex(), &aResult))
1165  {
1166  aSText.ReplaceBackReferences( aReplaceStr, aStr, aResult );
1167  xRet = aReplaceStr;
1168  }
1169  }
1170  }
1171  }
1172  return xRet;
1173 }
1174 
1175 } // namespace sw
1176 
1177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:1111
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:525
bool GetRanges(std::vector< std::shared_ptr< SwUnoCursor >> &rRanges, SwDoc &rDoc, SwPaM const &rDelPam)
Definition: autofmt.cxx:1117
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:1333
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:1348
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:728
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:1190
sal_Int64 n
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:184
void SetOle2Link(const Link< bool, void > &rLink)
Definition: doc.hxx:1324
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:2134
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:1283
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:80
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:170
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:372
#define CH_TXTATR_INWORD
Definition: hintids.hxx:171
static i18nutil::SearchOptions2 UpgradeToSearchOptions2(const i18nutil::SearchOptions &rOptions)
SwIndex nContent
Definition: pam.hxx:38
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1325
static bool IsRedlineOn(const RedlineFlags eM)
void Edit()
Definition: wrtsh1.cxx:152
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:1259
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:2255
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:33
static SvxSearchItem * GetSearchItem()
Definition: view.hxx:634
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:1043
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:2306
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:1007
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:91
SwNodes & GetNodes()
Definition: doc.hxx:403
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:417
const SwPostItMgr * GetPostItMgr() const
Definition: viewsh.hxx:557
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:1238
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:2243
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:844
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