LibreOffice Module sw (master)  1
findattr.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 <com/sun/star/lang/Locale.hpp>
21 #include <com/sun/star/util/SearchAlgorithms2.hpp>
22 #include <com/sun/star/util/SearchFlags.hpp>
24 #include <i18nutil/searchopt.hxx>
25 #include <unotools/syslocale.hxx>
26 #include <hintids.hxx>
27 #include <svl/itemiter.hxx>
28 #include <svl/whiter.hxx>
29 #include <editeng/colritem.hxx>
30 #include <editeng/fontitem.hxx>
31 #include <fmtpdsc.hxx>
32 #include <txatbase.hxx>
33 #include <charfmt.hxx>
34 #include <crsrsh.hxx>
35 #include <doc.hxx>
36 #include <IDocumentUndoRedo.hxx>
37 #include <IDocumentState.hxx>
38 #include <swcrsr.hxx>
39 #include <ndtxt.hxx>
40 #include <pamtyp.hxx>
41 #include <txtfrm.hxx>
42 #include <swundo.hxx>
43 #include <boost/optional.hpp>
44 
45 #include <algorithm>
46 #include <memory>
47 
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::util;
51 
52 typedef std::set<SwFormat*> SwpFormats;
53 
54 // Special case for SvxFontItem: only compare the name
55 static bool CmpAttr( const SfxPoolItem& rItem1, const SfxPoolItem& rItem2 )
56 {
57  switch( rItem1.Which() )
58  {
59  case RES_CHRATR_FONT:
60  return static_cast<const SvxFontItem&>(rItem1).GetFamilyName() ==
61  static_cast<const SvxFontItem&>(rItem2).GetFamilyName();
62 
63  case RES_CHRATR_COLOR:
64  return static_cast<const SvxColorItem&>(rItem1).GetValue().IsRGBEqual(
65  static_cast<const SvxColorItem&>(rItem2).GetValue() );
66  case RES_PAGEDESC:
67  bool bNumOffsetEqual = false;
68  ::boost::optional<sal_uInt16> const oNumOffset1 =
69  static_cast<const SwFormatPageDesc&>(rItem1).GetNumOffset();
70  ::boost::optional<sal_uInt16> const oNumOffset2 =
71  static_cast<const SwFormatPageDesc&>(rItem2).GetNumOffset();
72  if (!oNumOffset1 && !oNumOffset2)
73  {
74  bNumOffsetEqual = true;
75  }
76  else if (oNumOffset1 && oNumOffset2)
77  {
78  bNumOffsetEqual = oNumOffset1.get() == oNumOffset2.get();
79  }
80  else
81  {
82  bNumOffsetEqual = false;
83  }
84 
85  if (!bNumOffsetEqual)
86  return false;
87 
88  return static_cast<const SwFormatPageDesc&>(rItem1).GetPageDesc() == static_cast<const SwFormatPageDesc&>(rItem2).GetPageDesc();
89  }
90  return rItem1 == rItem2;
91 }
92 
93 const SwTextAttr* GetFrwrdTextHint( const SwpHints& rHtsArr, size_t& rPos,
94  sal_Int32 nContentPos )
95 {
96  while( rPos < rHtsArr.Count() )
97  {
98  const SwTextAttr *pTextHt = rHtsArr.Get( rPos++ );
99  // the start of an attribute has to be in the section
100  if( pTextHt->GetStart() >= nContentPos )
101  return pTextHt; // valid text attribute
102  }
103  return nullptr; // invalid text attribute
104 }
105 
106 const SwTextAttr* GetBkwrdTextHint( const SwpHints& rHtsArr, size_t& rPos,
107  sal_Int32 nContentPos )
108 {
109  while( rPos > 0 )
110  {
111  const SwTextAttr *pTextHt = rHtsArr.Get( --rPos );
112  // the start of an attribute has to be in the section
113  if( pTextHt->GetStart() < nContentPos )
114  return pTextHt; // valid text attribute
115  }
116  return nullptr; // invalid text attribute
117 }
118 
119 static void lcl_SetAttrPam( SwPaM& rPam, sal_Int32 nStart, const sal_Int32* pEnd,
120  const bool bSaveMark )
121 {
122  sal_Int32 nContentPos;
123  if( bSaveMark )
124  nContentPos = rPam.GetMark()->nContent.GetIndex();
125  else
126  nContentPos = rPam.GetPoint()->nContent.GetIndex();
127  bool bTstEnd = rPam.GetPoint()->nNode == rPam.GetMark()->nNode;
128 
129  SwContentNode* pCNd = rPam.GetContentNode();
130  rPam.GetPoint()->nContent.Assign( pCNd, nStart );
131  rPam.SetMark(); // Point == GetMark
132 
133  // Point points to end of search area or end of attribute
134  if( pEnd )
135  {
136  if( bTstEnd && *pEnd > nContentPos )
137  rPam.GetPoint()->nContent = nContentPos;
138  else
139  rPam.GetPoint()->nContent = *pEnd;
140  }
141 }
142 
143 // TODO: provide documentation
156 static bool lcl_SearchAttr( const SwTextNode& rTextNd, SwPaM& rPam,
157  const SfxPoolItem& rCmpItem,
158  SwMoveFnCollection const & fnMove)
159 {
160  if ( !rTextNd.HasHints() )
161  return false;
162 
163  const SwTextAttr *pTextHt = nullptr;
164  bool bForward = &fnMove == &fnMoveForward;
165  size_t nPos = bForward ? 0 : rTextNd.GetSwpHints().Count();
166  sal_Int32 nContentPos = rPam.GetPoint()->nContent.GetIndex();
167 
168  while( nullptr != ( pTextHt=(*fnMove.fnGetHint)(rTextNd.GetSwpHints(),nPos,nContentPos)))
169  if (pTextHt->Which() == rCmpItem.Which())
170  {
171  lcl_SetAttrPam( rPam, pTextHt->GetStart(), pTextHt->End(), bForward );
172  return true;
173  }
174  return false;
175 }
176 
179 {
180  sal_uInt16 nWhich;
181  sal_Int32 nStt;
182  sal_Int32 nEnd;
183 
184  SwSrchChrAttr(): nWhich(0), nStt(0), nEnd(0) {}
185 
186  SwSrchChrAttr( const SfxPoolItem& rItem,
187  sal_Int32 nStart, sal_Int32 nAnyEnd )
188  : nWhich( rItem.Which() ), nStt( nStart ), nEnd( nAnyEnd )
189  {}
190 };
191 
193 {
195  sal_Int32 m_nNodeStart;
196  sal_Int32 m_nNodeEnd;
197  sal_uInt16 m_nArrStart, m_nArrLen;
198  sal_uInt16 m_nFound, m_nStackCount;
200  bool const m_bNoColls;
201  bool const m_bForward;
202 
203 public:
204  SwAttrCheckArr( const SfxItemSet& rSet, bool bForward, bool bNoCollections );
205  ~SwAttrCheckArr();
206 
207  void SetNewSet( const SwTextNode& rTextNd, const SwPaM& rPam );
208 
210  sal_uInt16 Count() const { return m_aComapeSet.Count(); }
211  bool Found() const { return m_nFound == m_aComapeSet.Count(); }
212  bool CheckStack();
213 
214  sal_Int32 Start() const;
215  sal_Int32 End() const;
216 
217  sal_Int32 GetNdStt() const { return m_nNodeStart; }
218  sal_Int32 GetNdEnd() const { return m_nNodeEnd; }
219 
220  bool SetAttrFwd( const SwTextAttr& rAttr );
221  bool SetAttrBwd( const SwTextAttr& rAttr );
222 };
223 
225  bool bNoCollections )
226  : m_nNodeStart(0)
227  , m_nNodeEnd(0)
228  , m_nFound(0)
229  , m_nStackCount(0)
230  , m_aComapeSet( *rSet.GetPool(), svl::Items<RES_CHRATR_BEGIN, RES_TXTATR_END-1>{} )
231  , m_bNoColls(bNoCollections)
232  , m_bForward(bFwd)
233 {
234  m_aComapeSet.Put( rSet, false );
235 
236  // determine area of Fnd/Stack array (Min/Max)
237  SfxItemIter aIter( m_aComapeSet );
238  m_nArrStart = m_aComapeSet.GetWhichByPos( aIter.GetFirstPos() );
239  m_nArrLen = m_aComapeSet.GetWhichByPos( aIter.GetLastPos() ) - m_nArrStart+1;
240 
241  char* pFndChar = new char[ m_nArrLen * sizeof(SwSrchChrAttr) ];
242  char* pStackChar = new char[ m_nArrLen * sizeof(SwSrchChrAttr) ];
243 
244  m_pFindArr = reinterpret_cast<SwSrchChrAttr*>(pFndChar);
245  m_pStackArr = reinterpret_cast<SwSrchChrAttr*>(pStackChar);
246 }
247 
249 {
250  delete[] reinterpret_cast<char*>(m_pFindArr);
251  delete[] reinterpret_cast<char*>(m_pStackArr);
252 }
253 
254 void SwAttrCheckArr::SetNewSet( const SwTextNode& rTextNd, const SwPaM& rPam )
255 {
256  std::fill(m_pFindArr, m_pFindArr + m_nArrLen, SwSrchChrAttr());
258  m_nFound = 0;
259  m_nStackCount = 0;
260 
261  if( m_bForward )
262  {
264  m_nNodeEnd = rPam.GetPoint()->nNode == rPam.GetMark()->nNode
265  ? rPam.GetMark()->nContent.GetIndex()
266  : rTextNd.GetText().getLength();
267  }
268  else
269  {
270  m_nNodeEnd = rPam.GetPoint()->nContent.GetIndex();
271  m_nNodeStart = rPam.GetPoint()->nNode == rPam.GetMark()->nNode
272  ? rPam.GetMark()->nContent.GetIndex()
273  : 0;
274  }
275 
276  if( m_bNoColls && !rTextNd.HasSwAttrSet() )
277  return ;
278 
279  const SfxItemSet& rSet = rTextNd.GetSwAttrSet();
280 
281  SfxItemIter aIter( m_aComapeSet );
282  const SfxPoolItem* pItem = aIter.GetCurItem();
283  const SfxPoolItem* pFndItem;
284  sal_uInt16 nWhich;
285 
286  do
287  {
288  if( IsInvalidItem( pItem ) )
289  {
290  nWhich = m_aComapeSet.GetWhichByPos( aIter.GetCurPos() );
291  if( RES_TXTATR_END <= nWhich )
292  break; // end of text attributes
293 
294  if( SfxItemState::SET == rSet.GetItemState( nWhich, !m_bNoColls, &pFndItem )
295  && !CmpAttr( *pFndItem, rSet.GetPool()->GetDefaultItem( nWhich ) ))
296  {
297  m_pFindArr[ nWhich - m_nArrStart ] =
298  SwSrchChrAttr( *pFndItem, m_nNodeStart, m_nNodeEnd );
299  m_nFound++;
300  }
301  }
302  else
303  {
304  if( RES_TXTATR_END <= (nWhich = pItem->Which() ))
305  break; // end of text attributes
306 
307  if( CmpAttr( rSet.Get( nWhich, !m_bNoColls ), *pItem ) )
308  {
309  m_pFindArr[ nWhich - m_nArrStart ] =
311  m_nFound++;
312  }
313  }
314 
315  pItem = aIter.NextItem();
316  } while (pItem);
317 }
318 
319 static bool
320 lcl_IsAttributeIgnorable(sal_Int32 const nNdStart, sal_Int32 const nNdEnd,
321  SwSrchChrAttr const& rTmp)
322 {
323  // #i115528#: if there is a paragraph attribute, it has been added by the
324  // SwAttrCheckArr ctor, and nFound is 1.
325  // if the paragraph is entirely covered by hints that override the paragraph
326  // attribute, then this function must find an attribute to decrement nFound!
327  // so check for an empty search range, let attributes that start/end there
328  // cover it, and hope for the best...
329  return ((nNdEnd == nNdStart)
330  ? ((rTmp.nEnd < nNdStart) || (nNdEnd < rTmp.nStt))
331  : ((rTmp.nEnd <= nNdStart) || (nNdEnd <= rTmp.nStt)));
332 }
333 
335 {
336  SwSrchChrAttr aTmp( rAttr.GetAttr(), rAttr.GetStart(), rAttr.GetAnyEnd() );
337 
338  // ignore all attributes not in search range
340  {
341  return Found();
342  }
343 
344  const SfxPoolItem* pItem;
345  // here we explicitly also search in character templates
346  sal_uInt16 nWhch = rAttr.Which();
347  std::unique_ptr<SfxWhichIter> pIter;
348  const SfxPoolItem* pTmpItem = nullptr;
349  const SfxItemSet* pSet = nullptr;
350  if( RES_TXTATR_CHARFMT == nWhch || RES_TXTATR_AUTOFMT == nWhch )
351  {
352  if( m_bNoColls && RES_TXTATR_CHARFMT == nWhch )
353  return Found();
354  pTmpItem = nullptr;
355  pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
356  if ( pSet )
357  {
358  pIter.reset(new SfxWhichIter( *pSet ));
359  nWhch = pIter->FirstWhich();
360  while( nWhch &&
361  SfxItemState::SET != pSet->GetItemState( nWhch, true, &pTmpItem ) )
362  nWhch = pIter->NextWhich();
363  if( !nWhch )
364  pTmpItem = nullptr;
365  }
366  }
367  else
368  pTmpItem = &rAttr.GetAttr();
369 
370  while( pTmpItem )
371  {
372  SfxItemState eState = m_aComapeSet.GetItemState( nWhch, false, &pItem );
373  if( SfxItemState::DONTCARE == eState || SfxItemState::SET == eState )
374  {
375  sal_uInt16 n;
376  SwSrchChrAttr* pCmp;
377 
378  // first delete all up to start position that are already invalid
379  SwSrchChrAttr* pArrPtr;
380  if( m_nFound )
381  for( pArrPtr = m_pFindArr, n = 0; n < m_nArrLen;
382  ++n, ++pArrPtr )
383  if( pArrPtr->nWhich && pArrPtr->nEnd <= aTmp.nStt )
384  {
385  pArrPtr->nWhich = 0; // deleted
386  m_nFound--;
387  }
388 
389  // delete all up to start position that are already invalid and
390  // move all "open" ones (= stick out over start position) from stack
391  // into FndSet
392  if( m_nStackCount )
393  for( pArrPtr = m_pStackArr, n=0; n < m_nArrLen; ++n, ++pArrPtr )
394  {
395  if( !pArrPtr->nWhich )
396  continue;
397 
398  if( pArrPtr->nEnd <= aTmp.nStt )
399  {
400  pArrPtr->nWhich = 0; // deleted
401  if( !--m_nStackCount )
402  break;
403  }
404  else if( pArrPtr->nStt <= aTmp.nStt )
405  {
406  if( ( pCmp = &m_pFindArr[ n ])->nWhich )
407  {
408  if( pCmp->nEnd < pArrPtr->nEnd ) // extend
409  pCmp->nEnd = pArrPtr->nEnd;
410  }
411  else
412  {
413  *pCmp = *pArrPtr;
414  m_nFound++;
415  }
416  pArrPtr->nWhich = 0;
417  if( !--m_nStackCount )
418  break;
419  }
420  }
421 
422  bool bContinue = false;
423 
424  if( SfxItemState::DONTCARE == eState )
425  {
426  // Will the attribute become valid?
427  if( !CmpAttr( m_aComapeSet.GetPool()->GetDefaultItem( nWhch ),
428  *pTmpItem ))
429  {
430  // search attribute and extend if needed
431  if( !( pCmp = &m_pFindArr[ nWhch - m_nArrStart ])->nWhich )
432  {
433  *pCmp = aTmp; // not found, insert
434  m_nFound++;
435  }
436  else if( pCmp->nEnd < aTmp.nEnd ) // extend?
437  pCmp->nEnd = aTmp.nEnd;
438 
439  bContinue = true;
440  }
441  }
442  // Will the attribute become valid?
443  else if( CmpAttr( *pItem, *pTmpItem ) )
444  {
445  m_pFindArr[ nWhch - m_nArrStart ] = aTmp;
446  ++m_nFound;
447  bContinue = true;
448  }
449 
450  // then is has to go on the stack
451  if( !bContinue && ( pCmp = &m_pFindArr[ nWhch - m_nArrStart ])->nWhich )
452  {
453  // exists on stack, only if it is even bigger
454  if( pCmp->nEnd > aTmp.nEnd )
455  {
456  OSL_ENSURE( !m_pStackArr[ nWhch - m_nArrStart ].nWhich,
457  "slot on stack is still in use" );
458 
459  if( aTmp.nStt <= pCmp->nStt )
460  pCmp->nStt = aTmp.nEnd;
461  else
462  pCmp->nEnd = aTmp.nStt;
463 
464  m_pStackArr[ nWhch - m_nArrStart ] = *pCmp;
465  m_nStackCount++;
466  }
467  pCmp->nWhich = 0;
468  m_nFound--;
469  }
470  }
471  if( pIter )
472  {
473  assert(pSet && "otherwise no pIter");
474  nWhch = pIter->NextWhich();
475  while( nWhch &&
476  SfxItemState::SET != pSet->GetItemState( nWhch, true, &pTmpItem ) )
477  nWhch = pIter->NextWhich();
478  if( !nWhch )
479  break;
480  }
481  else
482  break;
483  }
484  pIter.reset();
485  return Found();
486 }
487 
489 {
490  SwSrchChrAttr aTmp( rAttr.GetAttr(), rAttr.GetStart(), rAttr.GetAnyEnd() );
491 
492  // ignore all attributes not in search range
494  {
495  return Found();
496  }
497 
498  const SfxPoolItem* pItem;
499  // here we explicitly also search in character templates
500  sal_uInt16 nWhch = rAttr.Which();
501  std::unique_ptr<SfxWhichIter> pIter;
502  const SfxPoolItem* pTmpItem = nullptr;
503  const SfxItemSet* pSet = nullptr;
504  if( RES_TXTATR_CHARFMT == nWhch || RES_TXTATR_AUTOFMT == nWhch )
505  {
506  if( m_bNoColls && RES_TXTATR_CHARFMT == nWhch )
507  return Found();
508 
509  pSet = CharFormat::GetItemSet( rAttr.GetAttr() );
510  if ( pSet )
511  {
512  pIter.reset( new SfxWhichIter( *pSet ) );
513  nWhch = pIter->FirstWhich();
514  while( nWhch &&
515  SfxItemState::SET != pSet->GetItemState( nWhch, true, &pTmpItem ) )
516  nWhch = pIter->NextWhich();
517  if( !nWhch )
518  pTmpItem = nullptr;
519  }
520  }
521  else
522  pTmpItem = &rAttr.GetAttr();
523 
524  while( pTmpItem )
525  {
526  SfxItemState eState = m_aComapeSet.GetItemState( nWhch, false, &pItem );
527  if( SfxItemState::DONTCARE == eState || SfxItemState::SET == eState )
528  {
529  sal_uInt16 n;
530  SwSrchChrAttr* pCmp;
531 
532  // first delete all up to start position that are already invalid
533  SwSrchChrAttr* pArrPtr;
534  if( m_nFound )
535  for( pArrPtr = m_pFindArr, n = 0; n < m_nArrLen; ++n, ++pArrPtr )
536  if( pArrPtr->nWhich && pArrPtr->nStt >= aTmp.nEnd )
537  {
538  pArrPtr->nWhich = 0; // deleted
539  m_nFound--;
540  }
541 
542  // delete all up to start position that are already invalid and
543  // move all "open" ones (= stick out over start position) from stack
544  // into FndSet
545  if( m_nStackCount )
546  for( pArrPtr = m_pStackArr, n = 0; n < m_nArrLen; ++n, ++pArrPtr )
547  {
548  if( !pArrPtr->nWhich )
549  continue;
550 
551  if( pArrPtr->nStt >= aTmp.nEnd )
552  {
553  pArrPtr->nWhich = 0; // deleted
554  if( !--m_nStackCount )
555  break;
556  }
557  else if( pArrPtr->nEnd >= aTmp.nEnd )
558  {
559  if( ( pCmp = &m_pFindArr[ n ])->nWhich )
560  {
561  if( pCmp->nStt > pArrPtr->nStt ) // extend
562  pCmp->nStt = pArrPtr->nStt;
563  }
564  else
565  {
566  *pCmp = *pArrPtr;
567  m_nFound++;
568  }
569  pArrPtr->nWhich = 0;
570  if( !--m_nStackCount )
571  break;
572  }
573  }
574 
575  bool bContinue = false;
576  if( SfxItemState::DONTCARE == eState )
577  {
578  // Will the attribute become valid?
579  if( !CmpAttr( m_aComapeSet.GetPool()->GetDefaultItem( nWhch ),
580  *pTmpItem ) )
581  {
582  // search attribute and extend if needed
583  if( !( pCmp = &m_pFindArr[ nWhch - m_nArrStart ])->nWhich )
584  {
585  *pCmp = aTmp; // not found, insert
586  m_nFound++;
587  }
588  else if( pCmp->nStt > aTmp.nStt ) // extend?
589  pCmp->nStt = aTmp.nStt;
590 
591  bContinue = true;
592  }
593  }
594  // Will the attribute become valid?
595  else if( CmpAttr( *pItem, *pTmpItem ))
596  {
597  m_pFindArr[ nWhch - m_nArrStart ] = aTmp;
598  ++m_nFound;
599  bContinue = true;
600  }
601 
602  // then is has to go on the stack
603  if( !bContinue && ( pCmp = &m_pFindArr[ nWhch - m_nArrStart ])->nWhich )
604  {
605  // exists on stack, only if it is even bigger
606  if( pCmp->nStt < aTmp.nStt )
607  {
608  OSL_ENSURE( !m_pStackArr[ nWhch - m_nArrStart ].nWhich,
609  "slot on stack is still in use" );
610 
611  if( aTmp.nEnd <= pCmp->nEnd )
612  pCmp->nEnd = aTmp.nStt;
613  else
614  pCmp->nStt = aTmp.nEnd;
615 
616  m_pStackArr[ nWhch - m_nArrStart ] = *pCmp;
617  m_nStackCount++;
618  }
619  pCmp->nWhich = 0;
620  m_nFound--;
621  }
622  }
623  if( pIter )
624  {
625  assert(pSet && "otherwise no pIter");
626  nWhch = pIter->NextWhich();
627  while( nWhch &&
628  SfxItemState::SET != pSet->GetItemState( nWhch, true, &pTmpItem ) )
629  nWhch = pIter->NextWhich();
630  if( !nWhch )
631  break;
632  }
633  else
634  break;
635  }
636  pIter.reset();
637  return Found();
638 }
639 
640 sal_Int32 SwAttrCheckArr::Start() const
641 {
642  sal_Int32 nStart = m_nNodeStart;
643  SwSrchChrAttr* pArrPtr = m_pFindArr;
644  for( sal_uInt16 n = 0; n < m_nArrLen; ++n, ++pArrPtr )
645  if( pArrPtr->nWhich && pArrPtr->nStt > nStart )
646  nStart = pArrPtr->nStt;
647 
648  return nStart;
649 }
650 
651 sal_Int32 SwAttrCheckArr::End() const
652 {
653  SwSrchChrAttr* pArrPtr = m_pFindArr;
654  sal_Int32 nEnd = m_nNodeEnd;
655  for( sal_uInt16 n = 0; n < m_nArrLen; ++n, ++pArrPtr )
656  if( pArrPtr->nWhich && pArrPtr->nEnd < nEnd )
657  nEnd = pArrPtr->nEnd;
658 
659  return nEnd;
660 }
661 
663 {
664  if( !m_nStackCount )
665  return false;
666 
667  sal_uInt16 n;
668  const sal_Int32 nSttPos = Start();
669  const sal_Int32 nEndPos = End();
670  SwSrchChrAttr* pArrPtr;
671  for( pArrPtr = m_pStackArr, n = 0; n < m_nArrLen; ++n, ++pArrPtr )
672  {
673  if( !pArrPtr->nWhich )
674  continue;
675 
676  if( m_bForward ? pArrPtr->nEnd <= nSttPos : pArrPtr->nStt >= nEndPos )
677  {
678  pArrPtr->nWhich = 0; // deleted
679  if( !--m_nStackCount )
680  return m_nFound == m_aComapeSet.Count();
681  }
682  else if( m_bForward ? pArrPtr->nStt < nEndPos : pArrPtr->nEnd > nSttPos )
683  {
684  // move all "open" ones (= stick out over start position) into FndSet
685  OSL_ENSURE( !m_pFindArr[ n ].nWhich, "slot in array is already in use" );
686  m_pFindArr[ n ] = *pArrPtr;
687  pArrPtr->nWhich = 0;
688  m_nFound++;
689  if( !--m_nStackCount )
690  return m_nFound == m_aComapeSet.Count();
691  }
692  }
693  return m_nFound == m_aComapeSet.Count();
694 }
695 
696 static bool lcl_SearchForward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpArr,
697  SwPaM& rPam )
698 {
699  sal_Int32 nEndPos;
700  rCmpArr.SetNewSet( rTextNd, rPam );
701  if( !rTextNd.HasHints() )
702  {
703  if( !rCmpArr.Found() )
704  return false;
705  nEndPos = rCmpArr.GetNdEnd();
706  lcl_SetAttrPam( rPam, rCmpArr.GetNdStt(), &nEndPos, true );
707  return true;
708  }
709 
710  const SwpHints& rHtArr = rTextNd.GetSwpHints();
711  const SwTextAttr* pAttr;
712  size_t nPos = 0;
713 
714  // if everything is already there then check with which it will be ended
715  if( rCmpArr.Found() )
716  {
717  for( ; nPos < rHtArr.Count(); ++nPos )
718  if( !rCmpArr.SetAttrFwd( *( pAttr = rHtArr.Get( nPos )) ) )
719  {
720  if( rCmpArr.GetNdStt() < pAttr->GetStart() )
721  {
722  // found end
723  auto nTmpStart = pAttr->GetStart();
724  lcl_SetAttrPam( rPam, rCmpArr.GetNdStt(),
725  &nTmpStart, true );
726  return true;
727  }
728  // continue search
729  break;
730  }
731 
732  if( nPos == rHtArr.Count() && rCmpArr.Found() )
733  {
734  // found
735  nEndPos = rCmpArr.GetNdEnd();
736  lcl_SetAttrPam( rPam, rCmpArr.GetNdStt(), &nEndPos, true );
737  return true;
738  }
739  }
740 
741  sal_Int32 nSttPos;
742  for( ; nPos < rHtArr.Count(); ++nPos )
743  if( rCmpArr.SetAttrFwd( *( pAttr = rHtArr.Get( nPos )) ) )
744  {
745  // Do multiple start at that position? Do also check those:
746  nSttPos = pAttr->GetStart();
747  while( ++nPos < rHtArr.Count() && nSttPos ==
748  ( pAttr = rHtArr.Get( nPos ))->GetStart() &&
749  rCmpArr.SetAttrFwd( *pAttr ) )
750  ;
751 
752  if( !rCmpArr.Found() )
753  continue;
754 
755  // then we have our search area
756  if( (nSttPos = rCmpArr.Start()) > (nEndPos = rCmpArr.End()) )
757  return false;
758 
759  lcl_SetAttrPam( rPam, nSttPos, &nEndPos, true );
760  return true;
761  }
762 
763  if( !rCmpArr.CheckStack() ||
764  (nSttPos = rCmpArr.Start()) > (nEndPos = rCmpArr.End()) )
765  return false;
766 
767  lcl_SetAttrPam( rPam, nSttPos, &nEndPos, true );
768  return true;
769 }
770 
771 static bool lcl_SearchBackward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpArr,
772  SwPaM& rPam )
773 {
774  sal_Int32 nEndPos;
775  rCmpArr.SetNewSet( rTextNd, rPam );
776  if( !rTextNd.HasHints() )
777  {
778  if( !rCmpArr.Found() )
779  return false;
780  nEndPos = rCmpArr.GetNdEnd();
781  lcl_SetAttrPam( rPam, rCmpArr.GetNdStt(), &nEndPos, false );
782  return true;
783  }
784 
785  const SwpHints& rHtArr = rTextNd.GetSwpHints();
786  const SwTextAttr* pAttr;
787  size_t nPos = rHtArr.Count();
788  sal_Int32 nSttPos;
789 
790  // if everything is already there then check with which it will be ended
791  if( rCmpArr.Found() )
792  {
793  while( nPos )
794  if( !rCmpArr.SetAttrBwd( *( pAttr = rHtArr.GetSortedByEnd( --nPos )) ) )
795  {
796  nSttPos = pAttr->GetAnyEnd();
797  if( nSttPos < rCmpArr.GetNdEnd() )
798  {
799  // found end
800  nEndPos = rCmpArr.GetNdEnd();
801  lcl_SetAttrPam( rPam, nSttPos, &nEndPos, false );
802  return true;
803  }
804 
805  // continue search
806  break;
807  }
808 
809  if( !nPos && rCmpArr.Found() )
810  {
811  // found
812  nEndPos = rCmpArr.GetNdEnd();
813  lcl_SetAttrPam( rPam, rCmpArr.GetNdStt(), &nEndPos, false );
814  return true;
815  }
816  }
817 
818  while( nPos )
819  if( rCmpArr.SetAttrBwd( *( pAttr = rHtArr.GetSortedByEnd( --nPos )) ) )
820  {
821  // Do multiple start at that position? Do also check those:
822  if( nPos )
823  {
824  nEndPos = pAttr->GetAnyEnd();
825  while( --nPos && nEndPos ==
826  ( pAttr = rHtArr.GetSortedByEnd( nPos ))->GetAnyEnd() &&
827  rCmpArr.SetAttrBwd( *pAttr ) )
828  ;
829  }
830  if( !rCmpArr.Found() )
831  continue;
832 
833  // then we have our search area
834  if( (nSttPos = rCmpArr.Start()) > (nEndPos = rCmpArr.End()) )
835  return false;
836 
837  lcl_SetAttrPam( rPam, nSttPos, &nEndPos, false );
838  return true;
839  }
840 
841  if( !rCmpArr.CheckStack() ||
842  (nSttPos = rCmpArr.Start()) > (nEndPos = rCmpArr.End()) )
843  return false;
844 
845  lcl_SetAttrPam( rPam, nSttPos, &nEndPos, false );
846  return true;
847 }
848 
849 static bool lcl_Search( const SwContentNode& rCNd, const SfxItemSet& rCmpSet, bool bNoColls )
850 {
851  // search only hard attribution?
852  if( bNoColls && !rCNd.HasSwAttrSet() )
853  return false;
854 
855  const SfxItemSet& rNdSet = rCNd.GetSwAttrSet();
856  SfxItemIter aIter( rCmpSet );
857  const SfxPoolItem* pItem = aIter.GetCurItem();
858  const SfxPoolItem* pNdItem;
859  sal_uInt16 nWhich;
860 
861  do
862  {
863  if( IsInvalidItem( pItem ))
864  {
865  nWhich = rCmpSet.GetWhichByPos( aIter.GetCurPos() );
866  if( SfxItemState::SET != rNdSet.GetItemState( nWhich, !bNoColls, &pNdItem )
867  || CmpAttr( *pNdItem, rNdSet.GetPool()->GetDefaultItem( nWhich ) ))
868  return false;
869  }
870  else
871  {
872  nWhich = pItem->Which();
873 
874  if( !CmpAttr( rNdSet.Get( nWhich, !bNoColls ), *pItem ))
875  return false;
876  }
877 
878  pItem = aIter.NextItem();
879  } while (pItem);
880  return true; // found
881 }
882 
883 namespace sw {
884 
885 bool FindAttrImpl(SwPaM & rSearchPam,
886  const SfxPoolItem& rAttr, SwMoveFnCollection const & fnMove,
887  const SwPaM & rRegion, bool bInReadOnly,
888  SwRootFrame const*const pLayout)
889 {
890  // determine which attribute is searched:
891  const sal_uInt16 nWhich = rAttr.Which();
892  bool bCharAttr = isCHRATR(nWhich) || isTXTATR(nWhich);
893  assert(isTXTATR(nWhich)); // sw_redlinehide: only works for non-formatting hints such as needed in UpdateFields; use FindAttrsImpl for others
894 
895  std::unique_ptr<SwPaM> pPam(sw::MakeRegion(fnMove, rRegion));
896 
897  bool bFound = false;
898  bool bFirst = true;
899  const bool bSrchForward = &fnMove == &fnMoveForward;
900  SwContentNode * pNode;
901 
902  // if at beginning/end then move it out of the node
903  if( bSrchForward
904  ? pPam->GetPoint()->nContent.GetIndex() == pPam->GetContentNode()->Len()
905  : !pPam->GetPoint()->nContent.GetIndex() )
906  {
907  if( !(*fnMove.fnNds)( &pPam->GetPoint()->nNode, false ))
908  {
909  return false;
910  }
911  SwContentNode *pNd = pPam->GetContentNode();
912  pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() );
913  }
914 
915  while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
916  {
917  if( bCharAttr )
918  {
919  if( !pNode->IsTextNode() ) // CharAttr are only in text nodes
920  continue;
921 
922  SwTextFrame const*const pFrame(pLayout
923  ? static_cast<SwTextFrame const*>(pNode->getLayoutFrame(pLayout))
924  : nullptr);
925  if (pFrame)
926  {
927  SwTextNode const* pAttrNode(nullptr);
928  SwTextAttr const* pAttr(nullptr);
929  if (bSrchForward)
930  {
931  sw::MergedAttrIter iter(*pFrame);
932  do
933  {
934  pAttr = iter.NextAttr(&pAttrNode);
935  }
936  while (pAttr
937  && (pAttrNode->GetIndex() < pPam->GetPoint()->nNode.GetIndex()
938  || (pAttrNode->GetIndex() == pPam->GetPoint()->nNode.GetIndex()
939  && pAttr->GetStart() < pPam->GetPoint()->nContent.GetIndex())
940  || pAttr->Which() != nWhich));
941  }
942  else
943  {
944  sw::MergedAttrIterReverse iter(*pFrame);
945  do
946  {
947  pAttr = iter.PrevAttr(&pAttrNode);
948  }
949  while (pAttr
950  && (pPam->GetPoint()->nNode.GetIndex() < pAttrNode->GetIndex()
951  || (pPam->GetPoint()->nNode.GetIndex() == pAttrNode->GetIndex()
952  && pPam->GetPoint()->nContent.GetIndex() <= pAttr->GetStart())
953  || pAttr->Which() != nWhich));
954  }
955  if (pAttr)
956  {
957  assert(pAttrNode);
958  pPam->GetPoint()->nNode = *pAttrNode;
959  lcl_SetAttrPam(*pPam, pAttr->GetStart(), pAttr->End(), bSrchForward);
960  bFound = true;
961  break;
962  }
963  }
964  else if (!pLayout && pNode->GetTextNode()->HasHints() &&
965  lcl_SearchAttr(*pNode->GetTextNode(), *pPam, rAttr, fnMove))
966  {
967  bFound = true;
968  }
969  if (bFound)
970  {
971  // set to the values of the attribute
972  rSearchPam.SetMark();
973  *rSearchPam.GetPoint() = *pPam->GetPoint();
974  *rSearchPam.GetMark() = *pPam->GetMark();
975  break;
976  }
977  else if (isTXTATR(nWhich))
978  continue;
979  }
980 
981 #if 0
982  // no hard attribution, so check if node was asked for this attr before
983  if( !pNode->HasSwAttrSet() )
984  {
985  SwFormat* pTmpFormat = pNode->GetFormatColl();
986  if( !aFormatArr.insert( pTmpFormat ).second )
987  continue; // collection was requested earlier
988  }
989 
990  if( SfxItemState::SET == pNode->GetSwAttrSet().GetItemState( nWhich,
991  true, &pItem ))
992  {
993  // FORWARD: SPoint at the end, GetMark at the beginning of the node
994  // BACKWARD: SPoint at the beginning, GetMark at the end of the node
995  // always: incl. start and incl. end
996  *rSearchPam.GetPoint() = *pPam->GetPoint();
997  rSearchPam.SetMark();
998  pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent );
999  bFound = true;
1000  break;
1001  }
1002 #endif
1003  }
1004 
1005  // if backward search, switch point and mark
1006  if( bFound && !bSrchForward )
1007  rSearchPam.Exchange();
1008 
1009  return bFound;
1010 }
1011 
1012 } // namespace sw
1013 
1014 typedef bool (*FnSearchAttr)( const SwTextNode&, SwAttrCheckArr&, SwPaM& );
1015 
1016 static bool FindAttrsImpl(SwPaM & rSearchPam,
1017  const SfxItemSet& rSet, bool bNoColls, SwMoveFnCollection const & fnMove,
1018  const SwPaM & rRegion, bool bInReadOnly, bool bMoveFirst,
1019  SwRootFrame const*const pLayout)
1020 {
1021  std::unique_ptr<SwPaM> pPam(sw::MakeRegion(fnMove, rRegion));
1022 
1023  bool bFound = false;
1024  bool bFirst = true;
1025  const bool bSrchForward = &fnMove == &fnMoveForward;
1026  SwContentNode * pNode;
1027  SwpFormats aFormatArr;
1028 
1029  // check which text/char attributes are searched
1030  SwAttrCheckArr aCmpArr( rSet, bSrchForward, bNoColls );
1031  SfxItemSet aOtherSet( rSearchPam.GetDoc()->GetAttrPool(),
1033  aOtherSet.Put( rSet, false ); // got all invalid items
1034 
1035  FnSearchAttr fnSearch = bSrchForward
1036  ? (&::lcl_SearchForward)
1037  : (&::lcl_SearchBackward);
1038 
1039  // if at beginning/end then move it out of the node
1040  if( bMoveFirst &&
1041  ( bSrchForward
1042  ? pPam->GetPoint()->nContent.GetIndex() == pPam->GetContentNode()->Len()
1043  : !pPam->GetPoint()->nContent.GetIndex() ) )
1044  {
1045  if( !(*fnMove.fnNds)( &pPam->GetPoint()->nNode, false ))
1046  {
1047  return false;
1048  }
1049  SwContentNode *pNd = pPam->GetContentNode();
1050  pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() );
1051  }
1052 
1053  while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
1054  {
1055  SwTextFrame const*const pFrame(pLayout && pNode->IsTextNode()
1056  ? static_cast<SwTextFrame const*>(pNode->getLayoutFrame(pLayout))
1057  : nullptr);
1058  assert(!pLayout || !pNode->IsTextNode() || pFrame);
1059  // sw_redlinehide: it's apparently not possible to find break items
1060  // with the UI, so checking one node is enough
1061  SwContentNode const& rPropsNode(*(pFrame
1062  ? pFrame->GetTextNodeForParaProps()
1063  : pNode));
1064 
1065  if( aCmpArr.Count() )
1066  {
1067  if( !pNode->IsTextNode() ) // CharAttr are only in text nodes
1068  continue;
1069 
1070  if (aOtherSet.Count() &&
1071  !lcl_Search(rPropsNode, aOtherSet, bNoColls))
1072  {
1073  continue;
1074  }
1075  sw::MergedPara const*const pMergedPara(pFrame ? pFrame->GetMergedPara() : nullptr);
1076  if (pMergedPara)
1077  {
1078  SwPosition const& rStart(*pPam->Start());
1079  SwPosition const& rEnd(*pPam->End());
1080  // no extents? fall back to searching index 0 of propsnode
1081  // to find its node items
1082  if (pMergedPara->extents.empty())
1083  {
1084  if (rStart.nNode.GetIndex() <= rPropsNode.GetIndex()
1085  && rPropsNode.GetIndex() <= rEnd.nNode.GetIndex())
1086  {
1087  SwPaM tmp(rPropsNode, 0, rPropsNode, 0);
1088  bFound = (*fnSearch)(*pNode->GetTextNode(), aCmpArr, tmp);
1089  if (bFound)
1090  {
1091  *pPam = tmp;
1092  }
1093  }
1094  }
1095  else
1096  {
1097  // iterate the extents, and intersect with input pPam:
1098  // the found ranges should never include delete redlines
1099  // so that subsequent Replace will not affect them
1100  for (size_t i = 0; i < pMergedPara->extents.size(); ++i)
1101  {
1102  auto const rExtent(pMergedPara->extents[bSrchForward
1103  ? i
1104  : pMergedPara->extents.size() - i - 1]);
1105  if (rExtent.pNode->GetIndex() < rStart.nNode.GetIndex()
1106  || rEnd.nNode.GetIndex() < rExtent.pNode->GetIndex())
1107  {
1108  continue;
1109  }
1110  sal_Int32 const nStart(rExtent.pNode == &rStart.nNode.GetNode()
1111  ? rStart.nContent.GetIndex()
1112  : 0);
1113  if (rExtent.nEnd <= nStart)
1114  {
1115  continue;
1116  }
1117  sal_Int32 const nEnd(rExtent.pNode == &rEnd.nNode.GetNode()
1118  ? rEnd.nContent.GetIndex()
1119  : rExtent.pNode->Len());
1120  if (nEnd < rExtent.nStart
1121  || (nStart != nEnd && nEnd == rExtent.nStart))
1122  {
1123  continue;
1124  }
1125  SwPaM tmp(*rExtent.pNode, std::max(nStart, rExtent.nStart),
1126  *rExtent.pNode, std::min(nEnd, rExtent.nEnd));
1127  tmp.Normalize(bSrchForward);
1128  bFound = (*fnSearch)(*rExtent.pNode, aCmpArr, tmp);
1129  if (bFound)
1130  {
1131  *pPam = tmp;
1132  break;
1133  }
1134  }
1135  }
1136  }
1137  else
1138  {
1139  bFound = (*fnSearch)(*pNode->GetTextNode(), aCmpArr, *pPam);
1140  }
1141  if (bFound)
1142  {
1143  // set to the values of the attribute
1144  rSearchPam.SetMark();
1145  *rSearchPam.GetPoint() = *pPam->GetPoint();
1146  *rSearchPam.GetMark() = *pPam->GetMark();
1147  break;
1148  }
1149  continue; // text attribute
1150  }
1151 
1152  if( !aOtherSet.Count() )
1153  continue;
1154 
1155  // no hard attribution, so check if node was asked for this attr before
1156  // (as an optimisation)
1157  if (!rPropsNode.HasSwAttrSet())
1158  {
1159  SwFormat* pTmpFormat = rPropsNode.GetFormatColl();
1160  if( !aFormatArr.insert( pTmpFormat ).second )
1161  continue; // collection was requested earlier
1162  }
1163 
1164  if (lcl_Search(rPropsNode, aOtherSet, bNoColls))
1165  {
1166  // FORWARD: SPoint at the end, GetMark at the beginning of the node
1167  // BACKWARD: SPoint at the beginning, GetMark at the end of the node
1168  if (pFrame)
1169  {
1170  *rSearchPam.GetPoint() = *pPam->GetPoint();
1171  rSearchPam.SetMark();
1172  *rSearchPam.GetMark() = pFrame->MapViewToModelPos(
1173  TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0));
1174  }
1175  else
1176  {
1177  *rSearchPam.GetPoint() = *pPam->GetPoint();
1178  rSearchPam.SetMark();
1179  if (bSrchForward)
1180  {
1181  pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent );
1182  }
1183  else
1184  {
1185  pNode->MakeStartIndex( &rSearchPam.GetPoint()->nContent );
1186  }
1187  }
1188  bFound = true;
1189  break;
1190  }
1191  }
1192 
1193  // in search direction, mark precedes point, because the next iteration
1194  // starts at point
1195  if (bFound)
1196  {
1197  rSearchPam.Normalize(!bSrchForward);
1198  }
1199 
1200  return bFound;
1201 }
1202 
1205 {
1206  bool const m_bNoCollection;
1211  std::unique_ptr<utl::TextSearch> pSText;
1212 
1213  SwFindParaAttr( const SfxItemSet& rSet, bool bNoCollection,
1214  const i18nutil::SearchOptions2* pOpt, const SfxItemSet* pRSet,
1215  SwCursor& rCursor, SwRootFrame const*const pLayout)
1216  : m_bNoCollection(bNoCollection)
1217  , pSet( &rSet )
1218  , pReplSet( pRSet )
1219  , pSearchOpt( pOpt )
1220  , m_rCursor(rCursor)
1221  , m_pLayout(pLayout)
1222  {}
1223 
1224  virtual ~SwFindParaAttr() {}
1225 
1226  virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool bInReadOnly) override;
1227  virtual bool IsReplaceMode() const override;
1228 };
1229 
1230 int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
1231  const SwPaM & rRegion, bool bInReadOnly)
1232 {
1233  // replace string (only if text given and search is not parameterized)?
1234  bool bReplaceText = pSearchOpt && ( !pSearchOpt->replaceString.isEmpty() ||
1235  !pSet->Count() );
1236  bool bReplaceAttr = pReplSet && pReplSet->Count();
1237  bool bMoveFirst = !bReplaceAttr;
1238  if( bInReadOnly && (bReplaceAttr || bReplaceText ))
1239  bInReadOnly = false;
1240 
1241  // We search for attributes, should we search for text as well?
1242  {
1243  SwPaM aRegion( *rRegion.GetMark(), *rRegion.GetPoint() );
1244  SwPaM* pTextRegion = &aRegion;
1245  SwPaM aSrchPam( *rCursor.GetPoint() );
1246 
1247  while( true )
1248  {
1249  if( pSet->Count() ) // any attributes?
1250  {
1251  // first attributes
1252  if (!FindAttrsImpl(aSrchPam, *pSet, m_bNoCollection, fnMove, aRegion, bInReadOnly, bMoveFirst, m_pLayout))
1253  return FIND_NOT_FOUND;
1254  bMoveFirst = true;
1255 
1256  if( !pSearchOpt )
1257  break; // ok, only attributes, so found
1258 
1259  pTextRegion = &aSrchPam;
1260  }
1261  else if( !pSearchOpt )
1262  return FIND_NOT_FOUND;
1263 
1264  // then search in text of it
1265  if( !pSText )
1266  {
1268 
1269  // search in selection
1270  aTmp.searchFlag |= (SearchFlags::REG_NOT_BEGINOFLINE |
1271  SearchFlags::REG_NOT_ENDOFLINE);
1272 
1274 
1275  pSText.reset( new utl::TextSearch( aTmp ) );
1276  }
1277 
1278  // TODO: searching for attributes in Outliner text?!
1279 
1280  // continue search in correct section (pTextRegion)
1281  if (sw::FindTextImpl(aSrchPam, *pSearchOpt, false/*bSearchInNotes*/, *pSText, fnMove, *pTextRegion, bInReadOnly, m_pLayout) &&
1282  *aSrchPam.GetMark() != *aSrchPam.GetPoint() )
1283  break; // found
1284  else if( !pSet->Count() )
1285  return FIND_NOT_FOUND; // only text and nothing found
1286 
1287  *aRegion.GetMark() = *aSrchPam.GetPoint();
1288  }
1289 
1290  *rCursor.GetPoint() = *aSrchPam.GetPoint();
1291  rCursor.SetMark();
1292  *rCursor.GetMark() = *aSrchPam.GetMark();
1293  }
1294 
1295  if( bReplaceText )
1296  {
1297  const bool bRegExp(
1298  SearchAlgorithms2::REGEXP == pSearchOpt->AlgorithmType2);
1299  SwIndex& rSttCntIdx = rCursor.Start()->nContent;
1300  const sal_Int32 nSttCnt = rSttCntIdx.GetIndex();
1301 
1302  // add to shell-cursor-ring so that the regions will be moved eventually
1303  SwPaM* pPrevRing(nullptr);
1304  if( bRegExp )
1305  {
1306  pPrevRing = const_cast<SwPaM &>(rRegion).GetPrev();
1307  const_cast<SwPaM &>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() );
1308  }
1309 
1311  if (bRegExp)
1312  xRepl = sw::ReplaceBackReferences(*pSearchOpt, &rCursor, m_pLayout);
1313  sw::ReplaceImpl(rCursor,
1314  xRepl ? *xRepl : pSearchOpt->replaceString, bRegExp,
1315  *m_rCursor.GetDoc(), m_pLayout);
1316 
1317  m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
1318 
1319  if( bRegExp )
1320  {
1321  // and remove region again
1322  SwPaM* p;
1323  SwPaM* pNext = const_cast<SwPaM*>(&rRegion);
1324  do {
1325  p = pNext;
1326  pNext = p->GetNext();
1327  p->MoveTo(const_cast<SwPaM*>(&rRegion));
1328  } while( p != pPrevRing );
1329  }
1330  rSttCntIdx = nSttCnt;
1331  }
1332 
1333  if( bReplaceAttr )
1334  {
1335  // is the selection still existent?
1336  // all searched attributes are reset to default if
1337  // they are not in ReplaceSet
1338  if( !pSet->Count() )
1339  {
1342  }
1343  else
1344  {
1345  SfxItemPool* pPool = pReplSet->GetPool();
1346  SfxItemSet aSet( *pPool, pReplSet->GetRanges() );
1347 
1348  SfxItemIter aIter( *pSet );
1349  const SfxPoolItem* pItem = aIter.GetCurItem();
1350  do
1351  {
1352  // reset all that are not set with pool defaults
1353  if( !IsInvalidItem( pItem ) && SfxItemState::SET !=
1354  pReplSet->GetItemState( pItem->Which(), false ))
1355  aSet.Put( pPool->GetDefaultItem( pItem->Which() ));
1356 
1357  pItem = aIter.NextItem();
1358  } while (pItem);
1359  aSet.Put( *pReplSet );
1361  rCursor, aSet, SetAttrMode::DEFAULT, m_pLayout);
1362  }
1363 
1364  return FIND_NO_RING;
1365  }
1366  else
1367  return FIND_FOUND;
1368 }
1369 
1371 {
1372  return ( pSearchOpt && !pSearchOpt->replaceString.isEmpty() ) ||
1373  ( pReplSet && pReplSet->Count() );
1374 }
1375 
1377 sal_uLong SwCursor::FindAttrs( const SfxItemSet& rSet, bool bNoCollections,
1378  SwDocPositions nStart, SwDocPositions nEnd,
1379  bool& bCancel, FindRanges eFndRngs,
1380  const i18nutil::SearchOptions2* pSearchOpt,
1381  const SfxItemSet* pReplSet,
1382  SwRootFrame const*const pLayout)
1383 {
1384  // switch off OLE-notifications
1385  SwDoc* pDoc = GetDoc();
1386  Link<bool,void> aLnk( pDoc->GetOle2Link() );
1387  pDoc->SetOle2Link( Link<bool,void>() );
1388 
1389  bool bReplace = ( pSearchOpt && ( !pSearchOpt->replaceString.isEmpty() ||
1390  !rSet.Count() ) ) ||
1391  (pReplSet && pReplSet->Count());
1392  bool const bStartUndo = pDoc->GetIDocumentUndoRedo().DoesUndo() && bReplace;
1393  if (bStartUndo)
1394  {
1395  pDoc->GetIDocumentUndoRedo().StartUndo( SwUndoId::REPLACE, nullptr );
1396  }
1397 
1398  SwFindParaAttr aSwFindParaAttr( rSet, bNoCollections, pSearchOpt,
1399  pReplSet, *this, pLayout );
1400 
1401  sal_uLong nRet = FindAll( aSwFindParaAttr, nStart, nEnd, eFndRngs, bCancel );
1402  pDoc->SetOle2Link( aLnk );
1403  if( nRet && bReplace )
1404  pDoc->getIDocumentState().SetModified();
1405 
1406  if (bStartUndo)
1407  {
1408  pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::REPLACE, nullptr );
1409  }
1410 
1411  return nRet;
1412 }
1413 
1414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFindParaAttr(const SfxItemSet &rSet, bool bNoCollection, const i18nutil::SearchOptions2 *pOpt, const SfxItemSet *pRSet, SwCursor &rCursor, SwRootFrame const *const pLayout)
Definition: findattr.cxx:1213
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
virtual sal_Int32 Len() const
Definition: node.cxx:1180
sal_uLong GetIndex() const
Definition: node.hxx:282
#define RES_GRFATR_END
Definition: hintids.hxx:260
bool CheckStack()
Definition: findattr.cxx:662
Marks a position in the document model.
Definition: pam.hxx:35
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:754
sal_Int32 nEnd
Definition: findattr.cxx:182
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:35
sal_Int32 Start() const
Definition: findattr.cxx:640
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:343
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:501
std::string GetValue
bool isTXTATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:357
const SwTextAttr * GetBkwrdTextHint(const SwpHints &rHtsArr, size_t &rPos, sal_Int32 nContentPos)
Definition: findattr.cxx:106
sal_uInt16 m_nFound
Definition: findattr.cxx:198
SwNodeIndex nNode
Definition: pam.hxx:37
virtual void InsertItemSet(const SwPaM &rRg, const SfxItemSet &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr)=0
boost::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:1088
virtual void SetModified()=0
Must be called manually at changes of format.
sal_uIntPtr sal_uLong
const SwPosition * GetMark() const
Definition: pam.hxx:209
sal_uLong FindAttrs(const SfxItemSet &rSet, bool bNoCollections, SwDocPositions nStart, SwDocPositions nEnde, bool &bCancel, FindRanges, const i18nutil::SearchOptions2 *pSearchOpt, const SfxItemSet *rReplSet=nullptr, SwRootFrame const *const pLayout=nullptr)
search for attributes
Definition: findattr.cxx:1377
sal_Int32 End() const
Definition: findattr.cxx:651
sw::MergedPara * GetMergedPara()
Definition: txtfrm.hxx:438
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1147
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:185
void SetOle2Link(const Link< bool, void > &rLink)
Definition: doc.hxx:1318
SwTextAttr const * PrevAttr(SwTextNode const **ppNode=nullptr)
Definition: txtfrm.cxx:234
static bool lcl_IsAttributeIgnorable(sal_Int32 const nNdStart, sal_Int32 const nNdEnd, SwSrchChrAttr const &rTmp)
Definition: findattr.cxx:320
#define RES_CHRATR_FONT
Definition: hintids.hxx:76
SwTextAttr * GetSortedByEnd(size_t nPos) const
Definition: ndhints.hxx:158
Dialog to specify the properties of date form field.
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:143
#define RES_TXTATR_CHARFMT
Definition: hintids.hxx:143
sal_uInt16 Which() const
Definition: txatbase.hxx:110
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1290
sal_Int32 GetAnyEnd() const
end (if available), else start
Definition: txatbase.hxx:153
static bool CmpAttr(const SfxPoolItem &rItem1, const SfxPoolItem &rItem2)
Definition: findattr.cxx:55
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:314
#define RES_TXTATR_END
Definition: hintids.hxx:159
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
SwRootFrame const * m_pLayout
Definition: findattr.cxx:1210
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
SwTextAttr const * NextAttr(SwTextNode const **ppNode=nullptr)
Definition: txtfrm.cxx:97
void SetNewSet(const SwTextNode &rTextNd, const SwPaM &rPam)
Definition: findattr.cxx:254
sal_Int32 GetNdEnd() const
Definition: findattr.cxx:218
SwDocPositions
Definition: cshtyp.hxx:103
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:229
const SfxPoolItem * NextItem()
SwSrchChrAttr * m_pStackArr
Definition: findattr.cxx:194
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:353
const SfxItemSet * pReplSet
Definition: findattr.cxx:1207
SwIndex nContent
Definition: pam.hxx:38
const i18nutil::SearchOptions2 * pSearchOpt
Definition: findattr.cxx:1208
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1319
GetHint fnGetHint
Definition: pamtyp.hxx:76
FindRanges
Definition: cshtyp.hxx:90
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
sal_Int32 nStt
Definition: findattr.cxx:181
SfxItemSet m_aComapeSet
Definition: findattr.cxx:199
Describes parts of multiple text nodes, which will form a text frame, even when redlines are hidden a...
Definition: txtfrm.hxx:954
#define RES_PARATR_BEGIN
Definition: hintids.hxx:161
virtual bool DoesUndo() const =0
Is Undo enabled?
SwPaM * GetNext()
Definition: pam.hxx:264
SwCursor & m_rCursor
Definition: findattr.cxx:1209
void Normalize(bool bPointFirst=true)
Normalizes PaM, i.e.
Definition: pam.cxx:518
bool FindAttrImpl(SwPaM &rSearchPam, const SfxPoolItem &rAttr, SwMoveFnCollection const &fnMove, const SwPaM &rRegion, bool bInReadOnly, SwRootFrame const *const pLayout)
Definition: findattr.cxx:885
css::lang::Locale Locale
Base class for various Writer styles.
Definition: format.hxx:43
#define RES_CHRATR_COLOR
Definition: hintids.hxx:72
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SwTextNode const * GetTextNodeForParaProps() const
Definition: txtfrm.cxx:1300
size_t Count() const
Definition: ndhints.hxx:142
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
sal_uLong FindAll(SwFindParas &, SwDocPositions, SwDocPositions, FindRanges, bool &bCancel)
Definition: swcrsr.cxx:925
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
virtual ~SwFindParaAttr()
Definition: findattr.cxx:1224
const SwPosition * GetPoint() const
Definition: pam.hxx:207
const SwTextAttr * GetFrwrdTextHint(const SwpHints &rHtsArr, size_t &rPos, sal_Int32 nContentPos)
Definition: findattr.cxx:93
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:198
static bool lcl_Search(const SwContentNode &rCNd, const SfxItemSet &rCmpSet, bool bNoColls)
Definition: findattr.cxx:849
bool const m_bNoColls
Definition: findattr.cxx:200
void Exchange()
Definition: pam.cxx:469
int i
SwContentNode * GetContentNode()
Definition: node.hxx:615
sal_uInt16 Count() const
void MakeStartIndex(SwIndex *pIdx)
Definition: node.hxx:391
bool SetAttrFwd(const SwTextAttr &rAttr)
Definition: findattr.cxx:334
SwDoc * GetDoc() const
Definition: pam.hxx:243
Marks a character position inside a document model node.
Definition: index.hxx:37
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
Returns the item set associated with a character/inet/auto style.
Definition: atrstck.cxx:133
#define RES_CHRATR_BEGIN
Definition: hintids.hxx:69
parameters for search for attributes
Definition: findattr.cxx:1204
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:393
SwAttrCheckArr(const SfxItemSet &rSet, bool bForward, bool bNoCollections)
Definition: findattr.cxx:224
sal_uInt16 m_nArrLen
Definition: findattr.cxx:197
SwpHints & GetSwpHints()
getters for SwpHints
Definition: ndtxt.hxx:808
bool HasSwAttrSet() const
Definition: node.hxx:444
ring_container GetRingContainer()
Definition: ring.hxx:240
sal_uInt16 GetWhichByPos(sal_uInt16 nPos) const
bool ReplaceImpl(SwPaM &rCursor, OUString const &rReplacement, bool const bRegExp, SwDoc &rDoc, SwRootFrame const *const pLayout)
Definition: findtxt.cxx:1020
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
const int FIND_NO_RING
Definition: swcrsr.hxx:36
const SwPosition * Start() const
Definition: pam.hxx:212
SwSrchChrAttr * m_pFindArr
Definition: findattr.cxx:194
sal_uInt16 GetCurPos() const
sal_Int32 GetNdStt() const
Definition: findattr.cxx:217
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
sal_Int32 m_nNodeEnd
Definition: findattr.cxx:196
bool SetAttrBwd(const SwTextAttr &rAttr)
Definition: findattr.cxx:488
#define RES_TXTATR_AUTOFMT
Definition: hintids.hxx:141
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:67
SfxItemState
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 m_nStackCount
Definition: findattr.cxx:198
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
const int FIND_FOUND
Definition: swcrsr.hxx:35
bool Found() const
Definition: findattr.cxx:211
sal_Int32 GetIndex() const
Definition: index.hxx:95
bool const m_bForward
Definition: findattr.cxx:201
const SfxItemSet * pSet
Definition: findattr.cxx:1207
const sal_Int32 * End() const
Definition: txatbase.hxx:148
sal_uInt16 nWhich
Definition: findattr.cxx:180
virtual bool IsReplaceMode() const override
Definition: findattr.cxx:1370
static bool FindAttrsImpl(SwPaM &rSearchPam, const SfxItemSet &rSet, bool bNoColls, SwMoveFnCollection const &fnMove, const SwPaM &rRegion, bool bInReadOnly, bool bMoveFirst, SwRootFrame const *const pLayout)
Definition: findattr.cxx:1016
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:723
sal_uInt16 m_nArrStart
Definition: findattr.cxx:197
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:159
const sal_uInt16 * GetRanges() const
const LanguageTag & GetLanguageTag() const
SwFormatColl * GetFormatColl() const
Definition: node.hxx:447
const int FIND_NOT_FOUND
Definition: swcrsr.hxx:34
std::unique_ptr< utl::TextSearch > pSText
Definition: findattr.cxx:1211
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:455
bool IsInvalidItem(const SfxPoolItem *pItem)
#define RES_PAGEDESC
Definition: hintids.hxx:200
virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool bInReadOnly) override
Definition: findattr.cxx:1230
SwSrchChrAttr(const SfxPoolItem &rItem, sal_Int32 nStart, sal_Int32 nAnyEnd)
Definition: findattr.cxx:186
sal_Int32 nPos
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:1245
bool const m_bNoCollection
Definition: findattr.cxx:1206
virtual void SaveTableBoxContent(const SwPosition *pPos)
Definition: swcrsr.cxx:719
bool(* FnSearchAttr)(const SwTextNode &, SwAttrCheckArr &, SwPaM &)
Definition: findattr.cxx:1014
sal_uInt16 Count() const
how many attributes are there in total?
Definition: findattr.cxx:210
static void lcl_SetAttrPam(SwPaM &rPam, sal_Int32 nStart, const sal_Int32 *pEnd, const bool bSaveMark)
Definition: findattr.cxx:119
void MakeEndIndex(SwIndex *pIdx)
Definition: node.hxx:392
sal_uInt16 Which() const
static bool lcl_SearchForward(const SwTextNode &rTextNd, SwAttrCheckArr &rCmpArr, SwPaM &rPam)
Definition: findattr.cxx:696
std::set< SwFormat * > SwpFormats
Definition: findattr.cxx:52
const SfxPoolItem * GetCurItem() const
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1309
static bool lcl_SearchAttr(const SwTextNode &rTextNd, SwPaM &rPam, const SfxPoolItem &rCmpItem, SwMoveFnCollection const &fnMove)
search for a text attribute
Definition: findattr.cxx:156
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:842
bool HasHints() const
Definition: ndtxt.hxx:220
sal_Int32 m_nNodeStart
Definition: findattr.cxx:195
static bool lcl_SearchBackward(const SwTextNode &rTextNd, SwAttrCheckArr &rCmpArr, SwPaM &rPam)
Definition: findattr.cxx:771
search for multiple text attributes
Definition: findattr.cxx:178