LibreOffice Module sw (master)  1
txtedt.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 <hintids.hxx>
21 #include <vcl/svapp.hxx>
22 #include <svl/itemiter.hxx>
23 #include <editeng/splwrap.hxx>
24 #include <editeng/langitem.hxx>
25 #include <editeng/fontitem.hxx>
27 #include <editeng/hangulhanja.hxx>
29 #include <SwSmartTagMgr.hxx>
30 #include <linguistic/lngprops.hxx>
31 #include <officecfg/Office/Writer.hxx>
33 #include <unotools/charclass.hxx>
34 #include <sal/log.hxx>
35 #include <dlelstnr.hxx>
36 #include <swmodule.hxx>
37 #include <splargs.hxx>
38 #include <viewopt.hxx>
39 #include <acmplwrd.hxx>
40 #include <doc.hxx>
43 #include <docsh.hxx>
44 #include <txtfld.hxx>
45 #include <fmtfld.hxx>
46 #include <txatbase.hxx>
47 #include <charatr.hxx>
48 #include <fldbas.hxx>
49 #include <pam.hxx>
50 #include <hints.hxx>
51 #include <ndtxt.hxx>
52 #include <txtfrm.hxx>
53 #include <SwGrammarMarkUp.hxx>
54 #include <rootfrm.hxx>
55 #include <swscanner.hxx>
56 
57 #include <breakit.hxx>
58 #include <crstate.hxx>
59 #include <UndoOverwrite.hxx>
60 #include <txatritr.hxx>
61 #include <redline.hxx>
62 #include <docary.hxx>
63 #include <scriptinfo.hxx>
64 #include <docstat.hxx>
65 #include <editsh.hxx>
66 #include <unotextmarkup.hxx>
67 #include <txtatr.hxx>
68 #include <fmtautofmt.hxx>
69 #include <istyleaccess.hxx>
70 #include <unicode/uchar.h>
72 
73 #include <unomid.h>
74 
75 #include <com/sun/star/i18n/WordType.hpp>
76 #include <com/sun/star/i18n/ScriptType.hpp>
77 #include <com/sun/star/i18n/XBreakIterator.hpp>
78 
79 #include <vector>
80 #include <utility>
81 
82 #include <unotextrange.hxx>
83 
84 using namespace ::com::sun::star;
85 using namespace ::com::sun::star::frame;
86 using namespace ::com::sun::star::i18n;
87 using namespace ::com::sun::star::beans;
88 using namespace ::com::sun::star::uno;
89 using namespace ::com::sun::star::linguistic2;
90 using namespace ::com::sun::star::smarttags;
91 
92 namespace
93 {
94  void DetectAndMarkMissingDictionaries( SwDoc* pDoc,
95  const uno::Reference< XSpellChecker1 >& xSpell,
96  const LanguageType eActLang )
97  {
98  if( !pDoc )
99  return;
100 
101  if( xSpell.is() && !xSpell->hasLanguage( eActLang.get() ) )
102  pDoc->SetMissingDictionaries( true );
103  else
104  pDoc->SetMissingDictionaries( false );
105  }
106 }
107 
109 {
110  SwWrongList* pWrong; // for spell checking
111  SwGrammarMarkUp* pGrammarCheck; // for grammar checking / proof reading
122 
124  pWrong ( nullptr ),
125  pGrammarCheck ( nullptr ),
126  pSmartTags ( nullptr ),
127  nNumberOfWords ( 0 ),
128  nNumberOfAsianWords ( 0 ),
129  nNumberOfChars ( 0 ),
130  nNumberOfCharsExcludingSpaces ( 0 ),
131  bWordCountDirty ( true ),
132  eWrongDirty ( SwTextNode::WrongState::TODO ),
133  bGrammarCheckDirty ( true ),
134  bSmartTagDirty ( true ),
135  bAutoComplDirty ( true ) {};
136 };
137 
138 /*
139  * This has basically the same function as SwScriptInfo::MaskHiddenRanges,
140  * only for deleted redlines
141  */
142 
143 static sal_Int32
144 lcl_MaskRedlines( const SwTextNode& rNode, OUStringBuffer& rText,
145  sal_Int32 nStt, sal_Int32 nEnd,
146  const sal_Unicode cChar )
147 {
148  sal_Int32 nNumOfMaskedRedlines = 0;
149 
150  const SwDoc& rDoc = *rNode.GetDoc();
151 
153  {
154  const SwRangeRedline* pRed = rDoc.getIDocumentRedlineAccess().GetRedlineTable()[ nAct ];
155 
156  if ( pRed->Start()->nNode > rNode.GetIndex() )
157  break;
158 
160  {
161  sal_Int32 nRedlineEnd;
162  sal_Int32 nRedlineStart;
163 
164  pRed->CalcStartEnd( rNode.GetIndex(), nRedlineStart, nRedlineEnd );
165 
166  if ( nRedlineEnd < nStt || nRedlineStart > nEnd )
167  continue;
168 
169  while ( nRedlineStart < nRedlineEnd && nRedlineStart < nEnd )
170  {
171  if (nRedlineStart >= nStt)
172  {
173  rText[nRedlineStart] = cChar;
174  ++nNumOfMaskedRedlines;
175  }
176  ++nRedlineStart;
177  }
178  }
179  }
180 
181  return nNumOfMaskedRedlines;
182 }
183 
187 static bool
188 lcl_MaskRedlinesAndHiddenText( const SwTextNode& rNode, OUStringBuffer& rText,
189  sal_Int32 nStt, sal_Int32 nEnd,
190  const sal_Unicode cChar = CH_TXTATR_INWORD )
191 {
192  sal_Int32 nRedlinesMasked = 0;
193  sal_Int32 nHiddenCharsMasked = 0;
194 
195  const SwDoc& rDoc = *rNode.GetDoc();
197 
198  // If called from word count or from spell checking, deleted redlines
199  // should be masked:
200  if ( bShowChg )
201  {
202  nRedlinesMasked = lcl_MaskRedlines( rNode, rText, nStt, nEnd, cChar );
203  }
204 
205  const bool bHideHidden = !SW_MOD()->GetViewOption(rDoc.GetDocumentSettingManager().get(DocumentSettingId::HTML_MODE))->IsShowHiddenChar();
206 
207  // If called from word count, we want to mask the hidden ranges even
208  // if they are visible:
209  if ( bHideHidden )
210  {
211  nHiddenCharsMasked =
212  SwScriptInfo::MaskHiddenRanges( rNode, rText, nStt, nEnd, cChar );
213  }
214 
215  return (nRedlinesMasked > 0) || (nHiddenCharsMasked > 0);
216 }
217 
222  SwTextFrame & rTextFrame, SwTextNode & rNode,
223  sal_Int32 const nChgStart, sal_Int32 const nChgEnd)
224 {
225  TextFrameIndex const iChgStart(rTextFrame.MapModelToView(&rNode, nChgStart));
226  TextFrameIndex const iChgEnd(rTextFrame.MapModelToView(&rNode, nChgEnd));
227 
228  SwRect aRect = rTextFrame.GetPaintArea();
229  SwRect aTmp = rTextFrame.GetPaintArea();
230 
231  const SwTextFrame* pStartFrame = &rTextFrame;
232  while( pStartFrame->HasFollow() &&
233  iChgStart >= pStartFrame->GetFollow()->GetOfst())
234  pStartFrame = pStartFrame->GetFollow();
235  const SwTextFrame* pEndFrame = pStartFrame;
236  while( pEndFrame->HasFollow() &&
237  iChgEnd >= pEndFrame->GetFollow()->GetOfst())
238  pEndFrame = pEndFrame->GetFollow();
239 
240  bool bSameFrame = true;
241 
242  if( rTextFrame.HasFollow() )
243  {
244  if( pEndFrame != pStartFrame )
245  {
246  bSameFrame = false;
247  SwRect aStFrame( pStartFrame->GetPaintArea() );
248  {
249  SwRectFnSet aRectFnSet(pStartFrame);
250  aRectFnSet.SetLeft( aTmp, aRectFnSet.GetLeft(aStFrame) );
251  aRectFnSet.SetRight( aTmp, aRectFnSet.GetRight(aStFrame) );
252  aRectFnSet.SetBottom( aTmp, aRectFnSet.GetBottom(aStFrame) );
253  }
254  aStFrame = pEndFrame->GetPaintArea();
255  {
256  SwRectFnSet aRectFnSet(pEndFrame);
257  aRectFnSet.SetTop( aRect, aRectFnSet.GetTop(aStFrame) );
258  aRectFnSet.SetLeft( aRect, aRectFnSet.GetLeft(aStFrame) );
259  aRectFnSet.SetRight( aRect, aRectFnSet.GetRight(aStFrame) );
260  }
261  aRect.Union( aTmp );
262  while( true )
263  {
264  pStartFrame = pStartFrame->GetFollow();
265  if( pStartFrame == pEndFrame )
266  break;
267  aRect.Union( pStartFrame->GetPaintArea() );
268  }
269  }
270  }
271  if( bSameFrame )
272  {
273  SwRectFnSet aRectFnSet(pStartFrame);
274  if( aRectFnSet.GetTop(aTmp) == aRectFnSet.GetTop(aRect) )
275  aRectFnSet.SetLeft( aRect, aRectFnSet.GetLeft(aTmp) );
276  else
277  {
278  SwRect aStFrame( pStartFrame->GetPaintArea() );
279  aRectFnSet.SetLeft( aRect, aRectFnSet.GetLeft(aStFrame) );
280  aRectFnSet.SetRight( aRect, aRectFnSet.GetRight(aStFrame) );
281  aRectFnSet.SetTop( aRect, aRectFnSet.GetTop(aTmp) );
282  }
283 
284  if( aTmp.Height() > aRect.Height() )
285  aRect.Height( aTmp.Height() );
286  }
287 
288  return aRect;
289 }
290 
294 static bool lcl_HaveCommonAttributes( IStyleAccess& rStyleAccess,
295  const SfxItemSet* pSet1,
296  sal_uInt16 nWhichId,
297  const SfxItemSet& rSet2,
298  std::shared_ptr<SfxItemSet>& pStyleHandle )
299 {
300  bool bRet = false;
301 
302  std::unique_ptr<SfxItemSet> pNewSet;
303 
304  if ( !pSet1 )
305  {
306  OSL_ENSURE( nWhichId, "lcl_HaveCommonAttributes not used correctly" );
307  if ( SfxItemState::SET == rSet2.GetItemState( nWhichId, false ) )
308  {
309  pNewSet = rSet2.Clone();
310  pNewSet->ClearItem( nWhichId );
311  }
312  }
313  else if ( pSet1->Count() )
314  {
315  SfxItemIter aIter( *pSet1 );
316  const SfxPoolItem* pItem = aIter.GetCurItem();
317  while( true )
318  {
319  if ( SfxItemState::SET == rSet2.GetItemState( pItem->Which(), false ) )
320  {
321  if ( !pNewSet )
322  pNewSet = rSet2.Clone();
323  pNewSet->ClearItem( pItem->Which() );
324  }
325 
326  if( aIter.IsAtEnd() )
327  break;
328 
329  pItem = aIter.NextItem();
330  }
331  }
332 
333  if ( pNewSet )
334  {
335  if ( pNewSet->Count() )
336  pStyleHandle = rStyleAccess.getAutomaticStyle( *pNewSet, IStyleAccess::AUTO_STYLE_CHAR );
337  bRet = true;
338  }
339 
340  return bRet;
341 }
342 
367  const SwIndex &rIdx,
368  const sal_Int32 nLen,
369  const sal_uInt16 nWhich,
370  const SfxItemSet* pSet,
371  const bool bInclRefToxMark,
372  const bool bExactRange )
373 {
374  if ( !GetpSwpHints() )
375  return;
376 
377  sal_Int32 nStt = rIdx.GetIndex();
378  sal_Int32 nEnd = nStt + nLen;
379  {
380  // enlarge range for the reset of text attributes in case of an overlapping input field
381  const SwTextInputField* pTextInputField = dynamic_cast<const SwTextInputField*>(GetTextAttrAt( nStt, RES_TXTATR_INPUTFIELD, PARENT ));
382  if ( pTextInputField == nullptr )
383  {
384  pTextInputField = dynamic_cast<const SwTextInputField*>(GetTextAttrAt(nEnd, RES_TXTATR_INPUTFIELD, PARENT ));
385  }
386  if ( pTextInputField != nullptr )
387  {
388  if ( nStt > pTextInputField->GetStart() )
389  {
390  nStt = pTextInputField->GetStart();
391  }
392  if ( nEnd < *(pTextInputField->End()) )
393  {
394  nEnd = *(pTextInputField->End());
395  }
396  }
397  }
398 
399  bool bChanged = false;
400 
401  // nMin and nMax initialized to maximum / minimum (inverse)
402  sal_Int32 nMin = m_Text.getLength();
403  sal_Int32 nMax = nStt;
404  const bool bNoLen = nMin == 0;
405 
406  // We have to remember the "new" attributes that have
407  // been introduced by splitting surrounding attributes (case 2,3,4).
408  std::vector<SwTextAttr *> newAttributes;
409  std::vector<SwTextAttr *> delAttributes;
410 
411  // iterate over attribute array until start of attribute is behind deletion range
412  size_t i = 0;
413  sal_Int32 nAttrStart = sal_Int32();
414  SwTextAttr *pHt = nullptr;
415  while ( (i < m_pSwpHints->Count())
416  && ( ( ( nAttrStart = m_pSwpHints->Get(i)->GetStart()) < nEnd )
417  || nLen==0 ) && !bExactRange)
418  {
419  pHt = m_pSwpHints->Get(i);
420 
421  // attributes without end stay in!
422  // but consider <bInclRefToxMark> used by Undo
423  sal_Int32* const pAttrEnd = pHt->GetEnd();
424  const bool bKeepAttrWithoutEnd =
425  pAttrEnd == nullptr
426  && ( !bInclRefToxMark
427  || ( RES_TXTATR_REFMARK != pHt->Which()
428  && RES_TXTATR_TOXMARK != pHt->Which()
429  && RES_TXTATR_META != pHt->Which()
430  && RES_TXTATR_METAFIELD != pHt->Which() ) );
431  if ( bKeepAttrWithoutEnd )
432  {
433 
434  i++;
435  continue;
436  }
437  // attributes with content stay in
438  if ( pHt->HasContent() )
439  {
440  ++i;
441  continue;
442  }
443 
444  // Default behavior is to process all attributes:
445  bool bSkipAttr = false;
446  std::shared_ptr<SfxItemSet> pStyleHandle;
447 
448  // 1. case: We want to reset only the attributes listed in pSet:
449  if ( pSet )
450  {
451  bSkipAttr = SfxItemState::SET != pSet->GetItemState( pHt->Which(), false );
452  if ( bSkipAttr && RES_TXTATR_AUTOFMT == pHt->Which() )
453  {
454  // if the current attribute is an autostyle, we have to check if the autostyle
455  // and pSet have any attributes in common. If so, pStyleHandle will contain
456  // a handle to AutoStyle / pSet:
457  bSkipAttr = !lcl_HaveCommonAttributes( getIDocumentStyleAccess(), pSet, 0, *static_cast<const SwFormatAutoFormat&>(pHt->GetAttr()).GetStyleHandle(), pStyleHandle );
458  }
459  }
460  else if ( nWhich )
461  {
462  // 2. case: We want to reset only the attributes with WhichId nWhich:
463  bSkipAttr = nWhich != pHt->Which();
464  if ( bSkipAttr && RES_TXTATR_AUTOFMT == pHt->Which() )
465  {
466  bSkipAttr = !lcl_HaveCommonAttributes( getIDocumentStyleAccess(), nullptr, nWhich, *static_cast<const SwFormatAutoFormat&>(pHt->GetAttr()).GetStyleHandle(), pStyleHandle );
467  }
468  }
469  else if ( !bInclRefToxMark )
470  {
471  // 3. case: Reset all attributes except from ref/toxmarks:
472  // skip hints with CH_TXTATR here
473  // (deleting those is ONLY allowed for UNDO!)
474  bSkipAttr = RES_TXTATR_REFMARK == pHt->Which()
475  || RES_TXTATR_TOXMARK == pHt->Which()
476  || RES_TXTATR_META == pHt->Which()
477  || RES_TXTATR_METAFIELD == pHt->Which();
478  }
479 
480  if ( bSkipAttr )
481  {
482  i++;
483  continue;
484  }
485 
486  if (nStt <= nAttrStart) // Case: 1,3,5
487  {
488  const sal_Int32 nAttrEnd = pAttrEnd != nullptr
489  ? *pAttrEnd
490  : nAttrStart;
491  if (nEnd > nAttrStart
492  || (nEnd == nAttrEnd && nEnd == nAttrStart)) // Case: 1,3
493  {
494  if ( nMin > nAttrStart )
495  nMin = nAttrStart;
496  if ( nMax < nAttrEnd )
497  nMax = nAttrEnd;
498  // If only a no-extent hint is deleted, no resorting is needed
499  bChanged = bChanged || nEnd > nAttrStart || bNoLen;
500  if (nAttrEnd <= nEnd) // Case: 1
501  {
502  delAttributes.push_back(pHt);
503 
504  if ( pStyleHandle.get() )
505  {
506  SwTextAttr* pNew = MakeTextAttr( *GetDoc(),
507  *pStyleHandle, nAttrStart, nAttrEnd );
508  newAttributes.push_back(pNew);
509  }
510  }
511  else // Case: 3
512  {
513  bChanged = true;
514  m_pSwpHints->NoteInHistory( pHt );
515  // UGLY: this may temporarily destroy the sorting!
516  pHt->GetStart() = nEnd;
517  m_pSwpHints->NoteInHistory( pHt, true );
518 
519  if ( pStyleHandle.get() && nAttrStart < nEnd )
520  {
521  SwTextAttr* pNew = MakeTextAttr( *GetDoc(),
522  *pStyleHandle, nAttrStart, nEnd );
523  newAttributes.push_back(pNew);
524  }
525  }
526  }
527  }
528  else if (pAttrEnd != nullptr) // Case: 2,4,5
529  {
530  if (*pAttrEnd > nStt) // Case: 2,4
531  {
532  if (*pAttrEnd < nEnd) // Case: 2
533  {
534  if ( nMin > nAttrStart )
535  nMin = nAttrStart;
536  if ( nMax < *pAttrEnd )
537  nMax = *pAttrEnd;
538  bChanged = true;
539 
540  const sal_Int32 nAttrEnd = *pAttrEnd;
541 
542  m_pSwpHints->NoteInHistory( pHt );
543  // UGLY: this may temporarily destroy the sorting!
544  *pAttrEnd = nStt;
545  m_pSwpHints->NoteInHistory( pHt, true );
546 
547  if ( pStyleHandle.get() )
548  {
549  SwTextAttr* pNew = MakeTextAttr( *GetDoc(),
550  *pStyleHandle, nStt, nAttrEnd );
551  newAttributes.push_back(pNew);
552  }
553  }
554  else if (nLen) // Case: 4
555  {
556  // for Length 0 both hints would be merged again by
557  // InsertHint, so leave them alone!
558  if ( nMin > nAttrStart )
559  nMin = nAttrStart;
560  if ( nMax < *pAttrEnd )
561  nMax = *pAttrEnd;
562  bChanged = true;
563  const sal_Int32 nTmpEnd = *pAttrEnd;
564  m_pSwpHints->NoteInHistory( pHt );
565  // UGLY: this may temporarily destroy the sorting!
566  *pAttrEnd = nStt;
567  m_pSwpHints->NoteInHistory( pHt, true );
568 
569  if ( pStyleHandle.get() && nStt < nEnd )
570  {
571  SwTextAttr* pNew = MakeTextAttr( *GetDoc(),
572  *pStyleHandle, nStt, nEnd );
573  newAttributes.push_back(pNew);
574  }
575 
576  if( nEnd < nTmpEnd )
577  {
578  SwTextAttr* pNew = MakeTextAttr( *GetDoc(),
579  pHt->GetAttr(), nEnd, nTmpEnd );
580  if ( pNew )
581  {
582  SwTextCharFormat* pCharFormat = dynamic_cast<SwTextCharFormat*>(pHt);
583  if ( pCharFormat )
584  static_txtattr_cast<SwTextCharFormat*>(pNew)->SetSortNumber(pCharFormat->GetSortNumber());
585 
586  newAttributes.push_back(pNew);
587  }
588  }
589  }
590  }
591  }
592  ++i;
593  }
594 
595  if (bExactRange)
596  {
597  // Only delete the hints which start at nStt and end at nEnd.
598  for (i = 0; i < m_pSwpHints->Count(); ++i)
599  {
600  SwTextAttr* pHint = m_pSwpHints->Get(i);
601  if ( (isTXTATR_WITHEND(pHint->Which()) && RES_TXTATR_AUTOFMT != pHint->Which())
602  || pHint->GetStart() != nStt)
603  continue;
604 
605  const sal_Int32* pHintEnd = pHint->GetEnd();
606  if (!pHintEnd || *pHintEnd != nEnd)
607  continue;
608 
609  delAttributes.push_back(pHint);
610  }
611  }
612 
613  if (bChanged && !delAttributes.empty())
614  { // Delete() calls GetStartOf() - requires sorted hints!
615  m_pSwpHints->Resort();
616  }
617 
618  // delay deleting the hints because it re-sorts the hints array
619  for (SwTextAttr *const pDel : delAttributes)
620  {
621  m_pSwpHints->Delete(pDel);
622  DestroyAttr(pDel);
623  }
624 
625  // delay inserting the hints because it re-sorts the hints array
626  for (SwTextAttr *const pNew : newAttributes)
627  {
629  }
630 
632 
633  if (bChanged)
634  {
635  if ( HasHints() )
636  { // possibly sometimes Resort would be sufficient, but...
637  m_pSwpHints->MergePortions(*this);
638  }
639 
640  // TextFrame's respond to aHint, others to aNew
641  SwUpdateAttr aHint(
642  nMin,
643  nMax,
644  0);
645 
646  NotifyClients( nullptr, &aHint );
647  SwFormatChg aNew( GetFormatColl() );
648  NotifyClients( nullptr, &aNew );
649  }
650 }
651 
652 static sal_Int32 clipIndexBounds(const OUString &rStr, sal_Int32 nPos)
653 {
654  if (nPos < 0)
655  return 0;
656  if (nPos > rStr.getLength())
657  return rStr.getLength();
658  return nPos;
659 }
660 
661 // Return current word:
662 // Search from left to right, so find the word before nPos.
663 // Except if at the start of the paragraph, then return the first word.
664 // If the first word consists only of whitespace, return an empty string.
665 OUString SwTextFrame::GetCurWord(SwPosition const& rPos) const
666 {
668  SwTextNode *const pTextNode(rPos.nNode.GetNode().GetTextNode());
669  assert(pTextNode);
670  OUString const& rText(GetText());
671  assert(sal_Int32(nPos) <= rText.getLength()); // invalid index
672 
673  if (rText.isEmpty() || IsHiddenNow())
674  return OUString();
675 
676  assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
677  const uno::Reference< XBreakIterator > &rxBreak = g_pBreakIt->GetBreakIter();
678  sal_Int16 nWordType = WordType::DICTIONARY_WORD;
679  lang::Locale aLocale( g_pBreakIt->GetLocale(pTextNode->GetLang(rPos.nContent.GetIndex())) );
680  Boundary aBndry =
681  rxBreak->getWordBoundary(rText, sal_Int32(nPos), aLocale, nWordType, true);
682 
683  // if no word was found use previous word (if any)
684  if (aBndry.startPos == aBndry.endPos)
685  {
686  aBndry = rxBreak->previousWord(rText, sal_Int32(nPos), aLocale, nWordType);
687  }
688 
689  // check if word was found and if it uses a symbol font, if so
690  // enforce returning an empty string
691  if (aBndry.endPos != aBndry.startPos
692  && IsSymbolAt(TextFrameIndex(aBndry.startPos)))
693  {
694  aBndry.endPos = aBndry.startPos;
695  }
696 
697  // can have -1 as start/end of bounds not found
698  aBndry.startPos = clipIndexBounds(rText, aBndry.startPos);
699  aBndry.endPos = clipIndexBounds(rText, aBndry.endPos);
700 
701  return rText.copy(aBndry.startPos,
702  aBndry.endPos - aBndry.startPos);
703 }
704 
705 SwScanner::SwScanner( const SwTextNode& rNd, const OUString& rText,
706  const LanguageType* pLang, const ModelToViewHelper& rConvMap,
707  sal_uInt16 nType, sal_Int32 nStart, sal_Int32 nEnde, bool bClp )
708  : SwScanner(
709  [&rNd](sal_Int32 const nBegin, sal_uInt16 const nScript, bool const bNoChar)
710  { return rNd.GetLang(nBegin, bNoChar ? 0 : 1, nScript); }
711  , rText, pLang, rConvMap, nType, nStart, nEnde, bClp)
712 {
713 }
714 
715 SwScanner::SwScanner(std::function<LanguageType(sal_Int32, sal_Int32, bool)> const& pGetLangOfChar,
716  const OUString& rText, const LanguageType* pLang,
717  const ModelToViewHelper& rConvMap, sal_uInt16 nType, sal_Int32 nStart,
718  sal_Int32 nEnde, bool bClp)
719  : m_pGetLangOfChar(pGetLangOfChar)
720  , m_aPreDashReplacementText(rText)
721  , m_pLanguage(pLang)
722  , m_ModelToView(rConvMap)
723  , m_nLength(0)
724  , m_nOverriddenDashCount(0)
725  , m_nWordType(nType)
726  , m_bClip(bClp)
727 {
728  m_nStartPos = m_nBegin = nStart;
729  m_nEndPos = nEnde;
730 
731  //MSWord f.e has special emdash and endash behaviour in that they break
732  //words for the purposes of word counting, while a hyphen etc. doesn't.
733 
734  //The default configuration treats emdash/endash as a word break, but
735  //additional ones can be added in under tools->options
736  if (m_nWordType == i18n::WordType::WORD_COUNT)
737  {
739  OUStringBuffer aBuf(m_aPreDashReplacementText);
740  for (sal_Int32 i = m_nStartPos; i < m_nEndPos; ++i)
741  {
742  if (i < 0)
743  continue;
744  sal_Unicode cChar = aBuf[i];
745  if (sDashes.indexOf(cChar) != -1)
746  {
747  aBuf[i] = ' ';
749  }
750  }
751  m_aText = aBuf.makeStringAndClear();
752  }
753  else
755 
756  assert(m_aPreDashReplacementText.getLength() == m_aText.getLength());
757 
758  if ( m_pLanguage )
759  {
761  }
762  else
763  {
764  ModelToViewHelper::ModelPosition aModelBeginPos =
766  m_aCurrentLang = m_pGetLangOfChar(aModelBeginPos.mnPos, 0, true);
767  }
768 }
769 
770 namespace
771 {
772  //fdo#45271 for Asian words count characters instead of words
773  sal_Int32 forceEachAsianCodePointToWord(const OUString &rText, sal_Int32 nBegin, sal_Int32 nLen)
774  {
775  if (nLen > 1)
776  {
777  const uno::Reference< XBreakIterator > &rxBreak = g_pBreakIt->GetBreakIter();
778 
779  sal_uInt16 nCurrScript = rxBreak->getScriptType( rText, nBegin );
780 
781  sal_Int32 indexUtf16 = nBegin;
782  rText.iterateCodePoints(&indexUtf16);
783 
784  //First character is Asian, consider it a word :-(
785  if (nCurrScript == i18n::ScriptType::ASIAN)
786  {
787  nLen = indexUtf16 - nBegin;
788  return nLen;
789  }
790 
791  //First character was not Asian, consider appearance of any Asian character
792  //to be the end of the word
793  while (indexUtf16 < nBegin + nLen)
794  {
795  nCurrScript = rxBreak->getScriptType( rText, indexUtf16 );
796  if (nCurrScript == i18n::ScriptType::ASIAN)
797  {
798  nLen = indexUtf16 - nBegin;
799  return nLen;
800  }
801  rText.iterateCodePoints(&indexUtf16);
802  }
803  }
804  return nLen;
805  }
806 }
807 
809 {
811  Boundary aBound;
812 
813  CharClass& rCC = GetAppCharClass();
814  LanguageTag aOldLanguageTag = rCC.getLanguageTag();
815 
816  while ( true )
817  {
818  // skip non-letter characters:
819  while (m_nBegin < m_aText.getLength())
820  {
821  if (m_nBegin >= 0 && !u_isspace(m_aText[m_nBegin]))
822  {
823  if ( !m_pLanguage )
824  {
825  const sal_uInt16 nNextScriptType = g_pBreakIt->GetBreakIter()->getScriptType( m_aText, m_nBegin );
826  ModelToViewHelper::ModelPosition aModelBeginPos =
828  m_aCurrentLang = m_pGetLangOfChar(aModelBeginPos.mnPos, nNextScriptType, false);
829  }
830 
831  if ( m_nWordType != i18n::WordType::WORD_COUNT )
832  {
834  if ( rCC.isLetterNumeric(OUString(m_aText[m_nBegin])) )
835  break;
836  }
837  else
838  break;
839  }
840  ++m_nBegin;
841  }
842 
843  if ( m_nBegin >= m_aText.getLength() || m_nBegin >= m_nEndPos )
844  return false;
845 
846  // get the word boundaries
847  aBound = g_pBreakIt->GetBreakIter()->getWordBoundary( m_aText, m_nBegin,
849  OSL_ENSURE( aBound.endPos >= aBound.startPos, "broken aBound result" );
850 
851  // we don't want to include preceding text
852  // to count words in text with mixed script punctuation correctly,
853  // but we want to include preceding symbols (eg. percent sign, section sign,
854  // degree sign defined by dict_word_hu to spell check their affixed forms).
855  if (m_nWordType == i18n::WordType::WORD_COUNT && aBound.startPos < m_nBegin)
856  aBound.startPos = m_nBegin;
857 
858  //no word boundaries could be found
859  if(aBound.endPos == aBound.startPos)
860  return false;
861 
862  //if a word before is found it has to be searched for the next
863  if(aBound.endPos == m_nBegin)
864  ++m_nBegin;
865  else
866  break;
867  } // end while( true )
868 
869  rCC.setLanguageTag( aOldLanguageTag );
870 
871  // #i89042, as discussed with HDU: don't evaluate script changes for word count. Use whole word.
872  if ( m_nWordType == i18n::WordType::WORD_COUNT )
873  {
874  m_nBegin = std::max(aBound.startPos, m_nBegin);
875  m_nLength = 0;
876  if (aBound.endPos > m_nBegin)
877  m_nLength = aBound.endPos - m_nBegin;
878  }
879  else
880  {
881  // we have to differentiate between these cases:
882  if ( aBound.startPos <= m_nBegin )
883  {
884  OSL_ENSURE( aBound.endPos >= m_nBegin, "Unexpected aBound result" );
885 
886  // restrict boundaries to script boundaries and nEndPos
887  const sal_uInt16 nCurrScript = g_pBreakIt->GetBreakIter()->getScriptType( m_aText, m_nBegin );
888  OUString aTmpWord = m_aText.copy( m_nBegin, aBound.endPos - m_nBegin );
889  const sal_Int32 nScriptEnd = m_nBegin +
890  g_pBreakIt->GetBreakIter()->endOfScript( aTmpWord, 0, nCurrScript );
891  const sal_Int32 nEnd = std::min( aBound.endPos, nScriptEnd );
892 
893  // restrict word start to last script change position
894  sal_Int32 nScriptBegin = 0;
895  if ( aBound.startPos < m_nBegin )
896  {
897  // search from nBegin backwards until the next script change
898  aTmpWord = m_aText.copy( aBound.startPos,
899  m_nBegin - aBound.startPos + 1 );
900  nScriptBegin = aBound.startPos +
901  g_pBreakIt->GetBreakIter()->beginOfScript( aTmpWord, m_nBegin - aBound.startPos,
902  nCurrScript );
903  }
904 
905  m_nBegin = std::max( aBound.startPos, nScriptBegin );
906  m_nLength = nEnd - m_nBegin;
907  }
908  else
909  {
910  const sal_uInt16 nCurrScript = g_pBreakIt->GetBreakIter()->getScriptType( m_aText, aBound.startPos );
911  OUString aTmpWord = m_aText.copy( aBound.startPos,
912  aBound.endPos - aBound.startPos );
913  const sal_Int32 nScriptEnd = aBound.startPos +
914  g_pBreakIt->GetBreakIter()->endOfScript( aTmpWord, 0, nCurrScript );
915  const sal_Int32 nEnd = std::min( aBound.endPos, nScriptEnd );
916  m_nBegin = aBound.startPos;
917  m_nLength = nEnd - m_nBegin;
918  }
919  }
920 
921  // optionally clip the result of getWordBoundaries:
922  if ( m_bClip )
923  {
924  aBound.startPos = std::max( aBound.startPos, m_nStartPos );
925  aBound.endPos = std::min( aBound.endPos, m_nEndPos );
926  if (aBound.endPos < aBound.startPos)
927  {
929  m_nLength = 0; // found word is outside of search interval
930  }
931  else
932  {
933  m_nBegin = aBound.startPos;
934  m_nLength = aBound.endPos - m_nBegin;
935  }
936  }
937 
938  if( ! m_nLength )
939  return false;
940 
941  if ( m_nWordType == i18n::WordType::WORD_COUNT )
942  m_nLength = forceEachAsianCodePointToWord(m_aText, m_nBegin, m_nLength);
943 
944  m_aWord = m_aPreDashReplacementText.copy( m_nBegin, m_nLength );
945 
946  return true;
947 }
948 
949 // Note: this is a clone of SwTextFrame::AutoSpell_, so keep them in sync when fixing things!
951 {
952  // modify string according to redline information and hidden text
953  const OUString aOldText( m_Text );
954  OUStringBuffer buf(m_Text);
955  const bool bRestoreString =
956  lcl_MaskRedlinesAndHiddenText(*this, buf, 0, m_Text.getLength());
957  if (bRestoreString)
958  { // ??? UGLY: is it really necessary to modify m_Text here?
959  m_Text = buf.makeStringAndClear();
960  }
961 
962  sal_Int32 nBegin = ( pArgs->pStartNode != this )
963  ? 0
964  : pArgs->pStartIdx->GetIndex();
965 
966  sal_Int32 nEnd = ( pArgs->pEndNode != this )
967  ? m_Text.getLength()
968  : pArgs->pEndIdx->GetIndex();
969 
970  pArgs->xSpellAlt = nullptr;
971 
972  // 4 cases:
973 
974  // 1. IsWrongDirty = 0 and GetWrong = 0
975  // Everything is checked and correct
976  // 2. IsWrongDirty = 0 and GetWrong = 1
977  // Everything is checked and errors are identified in the wrong list
978  // 3. IsWrongDirty = 1 and GetWrong = 0
979  // Nothing has been checked
980  // 4. IsWrongDirty = 1 and GetWrong = 1
981  // Text has been checked but there is an invalid range in the wrong list
982 
983  // Nothing has to be done for case 1.
984  if ( ( IsWrongDirty() || GetWrong() ) && m_Text.getLength() )
985  {
986  if (nBegin > m_Text.getLength())
987  {
988  nBegin = m_Text.getLength();
989  }
990  if (nEnd > m_Text.getLength())
991  {
992  nEnd = m_Text.getLength();
993  }
994 
995  if(!IsWrongDirty())
996  {
997  const sal_Int32 nTemp = GetWrong()->NextWrong( nBegin );
998  if(nTemp > nEnd)
999  {
1000  // reset original text
1001  if ( bRestoreString )
1002  {
1003  m_Text = aOldText;
1004  }
1005  return false;
1006  }
1007  if(nTemp > nBegin)
1008  nBegin = nTemp;
1009 
1010  }
1011 
1012  // In case 2. we pass the wrong list to the scanned, because only
1013  // the words in the wrong list have to be checked
1014  SwScanner aScanner( *this, m_Text, nullptr, ModelToViewHelper(),
1015  WordType::DICTIONARY_WORD,
1016  nBegin, nEnd );
1017  while( !pArgs->xSpellAlt.is() && aScanner.NextWord() )
1018  {
1019  const OUString& rWord = aScanner.GetWord();
1020 
1021  // get next language for next word, consider language attributes
1022  // within the word
1023  LanguageType eActLang = aScanner.GetCurrentLanguage();
1024  DetectAndMarkMissingDictionaries( GetTextNode()->GetDoc(), pArgs->xSpeller, eActLang );
1025 
1026  if( rWord.getLength() > 0 && LANGUAGE_NONE != eActLang )
1027  {
1028  if (pArgs->xSpeller.is())
1029  {
1030  SvxSpellWrapper::CheckSpellLang( pArgs->xSpeller, eActLang );
1031  pArgs->xSpellAlt = pArgs->xSpeller->spell( rWord, static_cast<sal_uInt16>(eActLang),
1033  }
1034  if( pArgs->xSpellAlt.is() )
1035  {
1036  if (IsSymbolAt(aScanner.GetBegin()))
1037  {
1038  pArgs->xSpellAlt = nullptr;
1039  }
1040  else
1041  {
1042  // make sure the selection build later from the data
1043  // below does not include "in word" character to the
1044  // left and right in order to preserve those. Therefore
1045  // count those "in words" in order to modify the
1046  // selection accordingly.
1047  const sal_Unicode* pChar = rWord.getStr();
1048  sal_Int32 nLeft = 0;
1049  while (*pChar++ == CH_TXTATR_INWORD)
1050  ++nLeft;
1051  pChar = rWord.getLength() ? rWord.getStr() + rWord.getLength() - 1 : nullptr;
1052  sal_Int32 nRight = 0;
1053  while (pChar && *pChar-- == CH_TXTATR_INWORD)
1054  ++nRight;
1055 
1056  pArgs->pStartNode = this;
1057  pArgs->pEndNode = this;
1058  pArgs->pStartIdx->Assign(this, aScanner.GetEnd() - nRight );
1059  pArgs->pEndIdx->Assign(this, aScanner.GetBegin() + nLeft );
1060  }
1061  }
1062  }
1063  }
1064  }
1065 
1066  // reset original text
1067  if ( bRestoreString )
1068  {
1069  m_Text = aOldText;
1070  }
1071 
1072  return pArgs->xSpellAlt.is();
1073 }
1074 
1076  LanguageType nLang, sal_uInt16 nLangWhichId,
1077  const vcl::Font *pFont, sal_uInt16 nFontWhichId )
1078 {
1079  sal_uInt16 aRanges[] = {
1080  nLangWhichId, nLangWhichId,
1081  nFontWhichId, nFontWhichId,
1082  0, 0, 0 };
1083  if (!pFont)
1084  aRanges[2] = aRanges[3] = 0; // clear entries with font WhichId
1085 
1086  SwEditShell *pEditShell = GetDoc()->GetEditShell();
1087  SfxItemSet aSet( pEditShell->GetAttrPool(), aRanges );
1088  aSet.Put( SvxLanguageItem( nLang, nLangWhichId ) );
1089 
1090  OSL_ENSURE( pFont, "target font missing?" );
1091  if (pFont)
1092  {
1093  SvxFontItem aFontItem = static_cast<const SvxFontItem&>( aSet.Get( nFontWhichId ) );
1094  aFontItem.SetFamilyName( pFont->GetFamilyName());
1095  aFontItem.SetFamily( pFont->GetFamilyType());
1096  aFontItem.SetStyleName( pFont->GetStyleName());
1097  aFontItem.SetPitch( pFont->GetPitch());
1098  aFontItem.SetCharSet( pFont->GetCharSet() );
1099  aSet.Put( aFontItem );
1100  }
1101 
1103  // SetAttr( aSet ); <- Does not set language attribute of empty paragraphs correctly,
1104  // <- because since there is no selection the flag to garbage
1105  // <- collect all attributes is set, and therefore attributes spanned
1106  // <- over empty selection are removed.
1107 
1108 }
1109 
1111 {
1112  // get range of text within node to be converted
1113  // (either all the text or the text within the selection
1114  // when the conversion was started)
1115  const sal_Int32 nTextBegin = ( rArgs.pStartNode == this )
1116  ? std::min(rArgs.pStartIdx->GetIndex(), m_Text.getLength())
1117  : 0;
1118 
1119  const sal_Int32 nTextEnd = ( rArgs.pEndNode == this )
1120  ? std::min(rArgs.pEndIdx->GetIndex(), m_Text.getLength())
1121  : m_Text.getLength();
1122 
1123  rArgs.aConvText.clear();
1124 
1125  // modify string according to redline information and hidden text
1126  const OUString aOldText( m_Text );
1127  OUStringBuffer buf(m_Text);
1128  const bool bRestoreString =
1129  lcl_MaskRedlinesAndHiddenText(*this, buf, 0, m_Text.getLength());
1130  if (bRestoreString)
1131  { // ??? UGLY: is it really necessary to modify m_Text here?
1132  m_Text = buf.makeStringAndClear();
1133  }
1134 
1135  bool bFound = false;
1136  sal_Int32 nBegin = nTextBegin;
1137  sal_Int32 nLen = 0;
1138  LanguageType nLangFound = LANGUAGE_NONE;
1139  if (m_Text.isEmpty())
1140  {
1142  {
1143  // create SwPaM with mark & point spanning empty paragraph
1144  //SwPaM aCurPaM( *this, *this, nBegin, nBegin + nLen ); <-- wrong c-tor, does sth different
1145  SwPaM aCurPaM( *this, 0 );
1146 
1147  SetLanguageAndFont( aCurPaM,
1150  }
1151  }
1152  else
1153  {
1154  SwLanguageIterator aIter( *this, nBegin );
1155 
1156  // Implicit changes require setting new attributes, which in turn destroys
1157  // the attribute sequence on that aIter iterates. We store the necessary
1158  // coordinates and apply those changes after iterating through the text.
1159  typedef std::pair<sal_Int32, sal_Int32> ImplicitChangesRange;
1160  std::vector<ImplicitChangesRange> aImplicitChanges;
1161 
1162  // find non zero length text portion of appropriate language
1163  do {
1164  nLangFound = aIter.GetLanguage();
1165  bool bLangOk = (nLangFound == rArgs.nConvSrcLang) ||
1168 
1169  sal_Int32 nChPos = aIter.GetChgPos();
1170  // the position at the end of the paragraph is COMPLETE_STRING and
1171  // thus must be cut to the end of the actual string.
1172  assert(nChPos != -1);
1173  if (nChPos == -1 || nChPos == COMPLETE_STRING)
1174  {
1175  nChPos = m_Text.getLength();
1176  }
1177 
1178  nLen = nChPos - nBegin;
1179  bFound = bLangOk && nLen > 0;
1180  if (!bFound)
1181  {
1182  // create SwPaM with mark & point spanning the attributed text
1183  //SwPaM aCurPaM( *this, *this, nBegin, nBegin + nLen ); <-- wrong c-tor, does sth different
1184  SwPaM aCurPaM( *this, nBegin );
1185  aCurPaM.SetMark();
1186  aCurPaM.GetPoint()->nContent = nBegin + nLen;
1187 
1188  // check script type of selected text
1189  SwEditShell *pEditShell = GetDoc()->GetEditShell();
1190  pEditShell->Push(); // save current cursor on stack
1191  pEditShell->SetSelection( aCurPaM );
1192  bool bIsAsianScript = (SvtScriptType::ASIAN == pEditShell->GetScriptType());
1193  pEditShell->Pop(SwCursorShell::PopMode::DeleteCurrent); // restore cursor from stack
1194 
1195  if (!bIsAsianScript && rArgs.bAllowImplicitChangesForNotConvertibleText)
1196  {
1197  // Store for later use
1198  aImplicitChanges.emplace_back(nBegin, nBegin+nLen);
1199  }
1200  nBegin = nChPos; // start of next language portion
1201  }
1202  } while (!bFound && aIter.Next()); /* loop while nothing was found and still sth is left to be searched */
1203 
1204  // Apply implicit changes, if any, now that aIter is no longer used
1205  for (const std::pair<int,int> & rImplicitChange : aImplicitChanges)
1206  {
1207  SwPaM aPaM( *this, rImplicitChange.first );
1208  aPaM.SetMark();
1209  aPaM.GetPoint()->nContent = rImplicitChange.second;
1211  }
1212 
1213  }
1214 
1215  // keep resulting text within selection / range of text to be converted
1216  if (nBegin < nTextBegin)
1217  nBegin = nTextBegin;
1218  if (nBegin + nLen > nTextEnd)
1219  nLen = nTextEnd - nBegin;
1220  bool bInSelection = nBegin < nTextEnd;
1221 
1222  if (bFound && bInSelection) // convertible text found within selection/range?
1223  {
1224  OSL_ENSURE( !m_Text.isEmpty(), "convertible text portion missing!" );
1225  rArgs.aConvText = m_Text.copy(nBegin, nLen);
1226  rArgs.nConvTextLang = nLangFound;
1227 
1228  // position where to start looking in next iteration (after current ends)
1229  rArgs.pStartNode = this;
1230  rArgs.pStartIdx->Assign(this, nBegin + nLen );
1231  // end position (when we have travelled over the whole document)
1232  rArgs.pEndNode = this;
1233  rArgs.pEndIdx->Assign(this, nBegin );
1234  }
1235 
1236  // restore original text
1237  if ( bRestoreString )
1238  {
1239  m_Text = aOldText;
1240  }
1241 
1242  return !rArgs.aConvText.isEmpty();
1243 }
1244 
1245 // Note: this is a clone of SwTextNode::Spell, so keep them in sync when fixing things!
1246 SwRect SwTextFrame::AutoSpell_(SwTextNode & rNode, sal_Int32 nActPos)
1247 {
1248  SwRect aRect;
1249  assert(sw::FrameContainsNode(*this, rNode.GetIndex()));
1250  SwTextNode *const pNode(&rNode);
1251  if (!nActPos)
1252  nActPos = COMPLETE_STRING;
1253 
1255 
1256  // modify string according to redline information and hidden text
1257  const OUString aOldText( pNode->GetText() );
1258  OUStringBuffer buf(pNode->m_Text);
1259  const bool bRestoreString =
1260  lcl_MaskRedlinesAndHiddenText(*pNode, buf, 0, pNode->GetText().getLength());
1261  if (bRestoreString)
1262  { // ??? UGLY: is it really necessary to modify m_Text here? just for GetLang()?
1263  pNode->m_Text = buf.makeStringAndClear();
1264  }
1265 
1266  // a change of data indicates that at least one word has been modified
1267 
1268  sal_Int32 nBegin = 0;
1269  sal_Int32 nEnd = pNode->GetText().getLength();
1270  sal_Int32 nInsertPos = 0;
1271  sal_Int32 nChgStart = COMPLETE_STRING;
1272  sal_Int32 nChgEnd = 0;
1273  sal_Int32 nInvStart = COMPLETE_STRING;
1274  sal_Int32 nInvEnd = 0;
1275 
1276  const bool bAddAutoCmpl = pNode->IsAutoCompleteWordDirty() &&
1278 
1279  if( pNode->GetWrong() )
1280  {
1281  nBegin = pNode->GetWrong()->GetBeginInv();
1282  if( COMPLETE_STRING != nBegin )
1283  {
1284  nEnd = std::max(pNode->GetWrong()->GetEndInv(), pNode->GetText().getLength());
1285  }
1286 
1287  // get word around nBegin, we start at nBegin - 1
1288  if ( COMPLETE_STRING != nBegin )
1289  {
1290  if ( nBegin )
1291  --nBegin;
1292 
1293  LanguageType eActLang = pNode->GetLang( nBegin );
1294  Boundary aBound =
1295  g_pBreakIt->GetBreakIter()->getWordBoundary( pNode->GetText(), nBegin,
1296  g_pBreakIt->GetLocale( eActLang ),
1297  WordType::DICTIONARY_WORD, true );
1298  nBegin = aBound.startPos;
1299  }
1300 
1301  // get the position in the wrong list
1302  nInsertPos = pNode->GetWrong()->GetWrongPos( nBegin );
1303 
1304  // sometimes we have to skip one entry
1305  if( nInsertPos < pNode->GetWrong()->Count() &&
1306  nBegin == pNode->GetWrong()->Pos( nInsertPos ) +
1307  pNode->GetWrong()->Len( nInsertPos ) )
1308  nInsertPos++;
1309  }
1310 
1311  bool bFresh = nBegin < nEnd;
1312  bool bPending(false);
1313 
1314  if( bFresh )
1315  {
1316  uno::Reference< XSpellChecker1 > xSpell( ::GetSpellChecker() );
1317  SwDoc* pDoc = pNode->GetDoc();
1318 
1319  SwScanner aScanner( *pNode, pNode->GetText(), nullptr, ModelToViewHelper(),
1320  WordType::DICTIONARY_WORD, nBegin, nEnd);
1321 
1322  while( aScanner.NextWord() )
1323  {
1324  const OUString& rWord = aScanner.GetWord();
1325  nBegin = aScanner.GetBegin();
1326  sal_Int32 nLen = aScanner.GetLen();
1327 
1328  // get next language for next word, consider language attributes
1329  // within the word
1330  LanguageType eActLang = aScanner.GetCurrentLanguage();
1331  DetectAndMarkMissingDictionaries( pDoc, xSpell, eActLang );
1332 
1333  bool bSpell = xSpell.is() && xSpell->hasLanguage( static_cast<sal_uInt16>(eActLang) );
1334  if( bSpell && !rWord.isEmpty() )
1335  {
1336  // check for: bAlter => xHyphWord.is()
1337  OSL_ENSURE(!bSpell || xSpell.is(), "NULL pointer");
1338 
1339  if( !xSpell->isValid( rWord, static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) )
1340  {
1341  sal_Int32 nSmartTagStt = nBegin;
1342  sal_Int32 nDummy = 1;
1343  if ( !pNode->GetSmartTags() || !pNode->GetSmartTags()->InWrongWord( nSmartTagStt, nDummy ) )
1344  {
1345  if( !pNode->GetWrong() )
1346  {
1347  pNode->SetWrong( new SwWrongList( WRONGLIST_SPELL ) );
1348  pNode->GetWrong()->SetInvalid( 0, nEnd );
1349  }
1350  SwWrongList::FreshState const eState(pNode->GetWrong()->Fresh(
1351  nChgStart, nChgEnd, nBegin, nLen, nInsertPos, nActPos));
1352  switch (eState)
1353  {
1355  pNode->GetWrong()->Insert(OUString(), nullptr, nBegin, nLen, nInsertPos++);
1356  break;
1358  bPending = true;
1359  [[fallthrough]]; // to mark as invalid
1361  nInvStart = nBegin;
1362  nInvEnd = nBegin + nLen;
1363  break;
1364  }
1365  }
1366  }
1367  else if( bAddAutoCmpl && rACW.GetMinWordLen() <= rWord.getLength() )
1368  {
1369  rACW.InsertWord( rWord, *pDoc );
1370  }
1371  }
1372  }
1373  }
1374 
1375  // reset original text
1376  // i63141 before calling GetCharRect(..) with formatting!
1377  if ( bRestoreString )
1378  {
1379  pNode->m_Text = aOldText;
1380  }
1381  if( pNode->GetWrong() )
1382  {
1383  if( bFresh )
1384  pNode->GetWrong()->Fresh( nChgStart, nChgEnd,
1385  nEnd, 0, nInsertPos, nActPos );
1386 
1387  // Calculate repaint area:
1388 
1389  if( nChgStart < nChgEnd )
1390  {
1391  aRect = lcl_CalculateRepaintRect(*this, rNode, nChgStart, nChgEnd);
1392 
1393  // fdo#71558 notify misspelled word to accessibility
1394  SwViewShell* pViewSh = getRootFrame() ? getRootFrame()->GetCurrShell() : nullptr;
1395  if( pViewSh )
1396  pViewSh->InvalidateAccessibleParaAttrs( *this );
1397  }
1398 
1399  pNode->GetWrong()->SetInvalid( nInvStart, nInvEnd );
1400  pNode->SetWrongDirty(
1401  (COMPLETE_STRING != pNode->GetWrong()->GetBeginInv())
1402  ? (bPending
1406  if( !pNode->GetWrong()->Count() && ! pNode->IsWrongDirty() )
1407  pNode->SetWrong( nullptr );
1408  }
1409  else
1411 
1412  if( bAddAutoCmpl )
1413  pNode->SetAutoCompleteWordDirty( false );
1414 
1415  return aRect;
1416 }
1417 
1428 {
1429  SwRect aRet;
1430 
1431  assert(sw::FrameContainsNode(*this, rNode.GetIndex()));
1432  SwTextNode *const pNode = &rNode;
1433  const OUString& rText = pNode->GetText();
1434 
1435  // Iterate over language portions
1436  SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get();
1437 
1438  SwWrongList* pSmartTagList = pNode->GetSmartTags();
1439 
1440  sal_Int32 nBegin = 0;
1441  sal_Int32 nEnd = rText.getLength();
1442 
1443  if ( pSmartTagList )
1444  {
1445  if ( pSmartTagList->GetBeginInv() != COMPLETE_STRING )
1446  {
1447  nBegin = pSmartTagList->GetBeginInv();
1448  nEnd = std::min( pSmartTagList->GetEndInv(), rText.getLength() );
1449 
1450  if ( nBegin < nEnd )
1451  {
1452  const LanguageType aCurrLang = pNode->GetLang( nBegin );
1453  const css::lang::Locale aCurrLocale = g_pBreakIt->GetLocale( aCurrLang );
1454  nBegin = g_pBreakIt->GetBreakIter()->beginOfSentence( rText, nBegin, aCurrLocale );
1455  nEnd = g_pBreakIt->GetBreakIter()->endOfSentence(rText, nEnd, aCurrLocale);
1456  if (nEnd > rText.getLength() || nEnd < 0)
1457  nEnd = rText.getLength();
1458  }
1459  }
1460  }
1461 
1462  const sal_uInt16 nNumberOfEntries = pSmartTagList ? pSmartTagList->Count() : 0;
1463  sal_uInt16 nNumberOfRemovedEntries = 0;
1464  sal_uInt16 nNumberOfInsertedEntries = 0;
1465 
1466  // clear smart tag list between nBegin and nEnd:
1467  if ( 0 != nNumberOfEntries )
1468  {
1469  sal_Int32 nChgStart = COMPLETE_STRING;
1470  sal_Int32 nChgEnd = 0;
1471  const sal_uInt16 nCurrentIndex = pSmartTagList->GetWrongPos( nBegin );
1472  pSmartTagList->Fresh( nChgStart, nChgEnd, nBegin, nEnd - nBegin, nCurrentIndex, COMPLETE_STRING );
1473  nNumberOfRemovedEntries = nNumberOfEntries - pSmartTagList->Count();
1474  }
1475 
1476  if ( nBegin < nEnd )
1477  {
1478  // Expand the string:
1479  const ModelToViewHelper aConversionMap(*pNode, getRootFrame() /*TODO - replace or expand fields for smart tags?*/);
1480  const OUString& aExpandText = aConversionMap.getViewText();
1481 
1482  // Ownership ov ConversionMap is passed to SwXTextMarkup object!
1483  uno::Reference<text::XTextMarkup> const xTextMarkup =
1484  new SwXTextMarkup(pNode, aConversionMap);
1485 
1486  css::uno::Reference< css::frame::XController > xController = pNode->GetDoc()->GetDocShell()->GetController();
1487 
1488  SwPosition start(*pNode, nBegin);
1489  SwPosition end (*pNode, nEnd);
1490  Reference< css::text::XTextRange > xRange = SwXTextRange::CreateXTextRange(*pNode->GetDoc(), start, &end);
1491 
1492  rSmartTagMgr.RecognizeTextRange(xRange, xTextMarkup, xController);
1493 
1494  sal_Int32 nLangBegin = nBegin;
1495  sal_Int32 nLangEnd;
1496 
1497  // smart tag recognition has to be done for each language portion:
1498  SwLanguageIterator aIter( *pNode, nLangBegin );
1499 
1500  do
1501  {
1502  const LanguageType nLang = aIter.GetLanguage();
1503  const css::lang::Locale aLocale = g_pBreakIt->GetLocale( nLang );
1504  nLangEnd = std::min<sal_Int32>( nEnd, aIter.GetChgPos() );
1505 
1506  const sal_Int32 nExpandBegin = aConversionMap.ConvertToViewPosition( nLangBegin );
1507  const sal_Int32 nExpandEnd = aConversionMap.ConvertToViewPosition( nLangEnd );
1508 
1509  rSmartTagMgr.RecognizeString(aExpandText, xTextMarkup, xController, aLocale, nExpandBegin, nExpandEnd - nExpandBegin );
1510 
1511  nLangBegin = nLangEnd;
1512  }
1513  while ( aIter.Next() && nLangEnd < nEnd );
1514 
1515  pSmartTagList = pNode->GetSmartTags();
1516 
1517  const sal_uInt16 nNumberOfEntriesAfterRecognize = pSmartTagList ? pSmartTagList->Count() : 0;
1518  nNumberOfInsertedEntries = nNumberOfEntriesAfterRecognize - ( nNumberOfEntries - nNumberOfRemovedEntries );
1519  }
1520 
1521  if( pSmartTagList )
1522  {
1523  // Update WrongList stuff
1524  pSmartTagList->SetInvalid( COMPLETE_STRING, 0 );
1525  pNode->SetSmartTagDirty( COMPLETE_STRING != pSmartTagList->GetBeginInv() );
1526 
1527  if( !pSmartTagList->Count() && !pNode->IsSmartTagDirty() )
1528  pNode->SetSmartTags( nullptr );
1529 
1530  // Calculate repaint area:
1531  if ( nBegin < nEnd && ( 0 != nNumberOfRemovedEntries ||
1532  0 != nNumberOfInsertedEntries ) )
1533  {
1534  aRet = lcl_CalculateRepaintRect(*this, rNode, nBegin, nEnd);
1535  }
1536  }
1537  else
1538  pNode->SetSmartTagDirty( false );
1539 
1540  return aRet;
1541 }
1542 
1543 void SwTextFrame::CollectAutoCmplWrds(SwTextNode & rNode, sal_Int32 nActPos)
1544 {
1545  assert(sw::FrameContainsNode(*this, rNode.GetIndex())); (void) this;
1546  SwTextNode *const pNode(&rNode);
1547  if (!nActPos)
1548  nActPos = COMPLETE_STRING;
1549 
1550  SwDoc* pDoc = pNode->GetDoc();
1552 
1553  sal_Int32 nBegin = 0;
1554  sal_Int32 nEnd = pNode->GetText().getLength();
1555  sal_Int32 nLen;
1556  bool bACWDirty = false;
1557 
1558  if( nBegin < nEnd )
1559  {
1560  int nCnt = 200;
1561  SwScanner aScanner( *pNode, pNode->GetText(), nullptr, ModelToViewHelper(),
1562  WordType::DICTIONARY_WORD, nBegin, nEnd );
1563  while( aScanner.NextWord() )
1564  {
1565  nBegin = aScanner.GetBegin();
1566  nLen = aScanner.GetLen();
1567  if( rACW.GetMinWordLen() <= nLen )
1568  {
1569  const OUString& rWord = aScanner.GetWord();
1570 
1571  if( nActPos < nBegin || ( nBegin + nLen ) < nActPos )
1572  {
1573  if( rACW.GetMinWordLen() <= rWord.getLength() )
1574  rACW.InsertWord( rWord, *pDoc );
1575  }
1576  else
1577  bACWDirty = true;
1578  }
1579  if( !--nCnt )
1580  {
1581  // don't wait for TIMER here, so we can finish big paragraphs
1582  if (Application::AnyInput(VCL_INPUT_ANY & VclInputFlags(~VclInputFlags::TIMER)))
1583  return;
1584  nCnt = 100;
1585  }
1586  }
1587  }
1588 
1589  if (!bACWDirty)
1590  pNode->SetAutoCompleteWordDirty( false );
1591 }
1592 
1594  SwTextFrame const& rFrame, SwTextNode const& rNode,
1595  SwInterHyphInfo const& rHyphInfo)
1596  : m_nStart(rFrame.MapModelToView(&rNode, rHyphInfo.nStart))
1597  , m_nEnd(rFrame.MapModelToView(&rNode, rHyphInfo.nEnd))
1598  , m_nWordStart(0)
1599  , m_nWordLen(0)
1600 {
1601 }
1602 
1604  SwTextNode const& rNode, SwInterHyphInfo & o_rHyphInfo)
1605 {
1606  std::pair<SwTextNode const*, sal_Int32> const wordStart(rFrame.MapViewToModel(m_nWordStart));
1607  std::pair<SwTextNode const*, sal_Int32> const wordEnd(rFrame.MapViewToModel(m_nWordStart+m_nWordLen));
1608  if (wordStart.first != &rNode || wordEnd.first != &rNode)
1609  { // not sure if this can happen since nStart/nEnd are in rNode
1610  SAL_WARN("sw.core", "UpdateTextNodeHyphInfo: outside of node");
1611  return;
1612  }
1613  o_rHyphInfo.nWordStart = wordStart.second;
1614  o_rHyphInfo.nWordLen = wordEnd.second - wordStart.second;
1615  o_rHyphInfo.SetHyphWord(m_xHyphWord);
1616 }
1617 
1620 {
1621  // shortcut: paragraph doesn't have a language set:
1623  && LanguageType(USHRT_MAX) == GetLang(0, m_Text.getLength()))
1624  {
1625  return false;
1626  }
1627 
1629  [&rHyphInf, this]() {
1630  std::pair<Point, bool> tmp;
1631  Point const*const pPoint = rHyphInf.GetCursorPos();
1632  if (pPoint)
1633  {
1634  tmp.first = *pPoint;
1635  tmp.second = true;
1636  }
1637  return static_cast<SwTextFrame*>(this->getLayoutFrame(
1638  this->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
1639  nullptr, pPoint ? &tmp : nullptr));
1640  });
1641  if (!pFrame)
1642  {
1643  // There was a comment here that claimed that the following assertion
1644  // shouldn't exist as it's triggered by "Trennung ueber Sonderbereiche",
1645  // (hyphenation across special sections?), whatever that means.
1646  OSL_ENSURE( pFrame, "!SwTextNode::Hyphenate: can't find any frame" );
1647  return false;
1648  }
1649  SwInterHyphInfoTextFrame aHyphInfo(*pFrame, *this, rHyphInf);
1650 
1651  pFrame = &(pFrame->GetFrameAtOfst( aHyphInfo.m_nStart ));
1652 
1653  while( pFrame )
1654  {
1655  if (pFrame->Hyphenate(aHyphInfo))
1656  {
1657  // The layout is not robust wrt. "direct formatting"
1658  // cf. layact.cxx, SwLayAction::TurboAction_(), if( !pCnt->IsValid() ...
1659  pFrame->SetCompletePaint();
1660  aHyphInfo.UpdateTextNodeHyphInfo(*pFrame, *this, rHyphInf);
1661  return true;
1662  }
1663  pFrame = pFrame->GetFollow();
1664  if( pFrame )
1665  {
1666  aHyphInfo.m_nEnd = aHyphInfo.m_nEnd - (pFrame->GetOfst() - aHyphInfo.m_nStart);
1667  aHyphInfo.m_nStart = pFrame->GetOfst();
1668  }
1669  }
1670  return false;
1671 }
1672 
1673 namespace
1674 {
1675  struct swTransliterationChgData
1676  {
1677  sal_Int32 nStart;
1678  sal_Int32 nLen;
1679  OUString sChanged;
1680  Sequence< sal_Int32 > aOffsets;
1681  };
1682 }
1683 
1684 // change text to Upper/Lower/Hiragana/Katakana/...
1687  sal_Int32 nStt, sal_Int32 nEnd,
1688  SwUndoTransliterate* pUndo )
1689 {
1690  if (nStt < nEnd)
1691  {
1692  // since we don't use Hiragana/Katakana or half-width/full-width transliterations here
1693  // it is fine to use ANYWORD_IGNOREWHITESPACES. (ANY_WORD btw is broken and will
1694  // occasionally miss words in consecutive sentences). Also with ANYWORD_IGNOREWHITESPACES
1695  // text like 'just-in-time' will be converted to 'Just-In-Time' which seems to be the
1696  // proper thing to do.
1697  const sal_Int16 nWordType = WordType::ANYWORD_IGNOREWHITESPACES;
1698 
1699  // In order to have less trouble with changing text size, e.g. because
1700  // of ligatures or German small sz being resolved, we need to process
1701  // the text replacements from end to start.
1702  // This way the offsets for the yet to be changed words will be
1703  // left unchanged by the already replaced text.
1704  // For this we temporarily save the changes to be done in this vector
1705  std::vector< swTransliterationChgData > aChanges;
1706  swTransliterationChgData aChgData;
1707 
1708  if (rTrans.getType() == TransliterationFlags::TITLE_CASE)
1709  {
1710  // for 'capitalize every word' we need to iterate over each word
1711 
1712  Boundary aSttBndry;
1713  Boundary aEndBndry;
1714  aSttBndry = g_pBreakIt->GetBreakIter()->getWordBoundary(
1715  GetText(), nStt,
1716  g_pBreakIt->GetLocale( GetLang( nStt ) ),
1717  nWordType,
1718  true /*prefer forward direction*/);
1719  aEndBndry = g_pBreakIt->GetBreakIter()->getWordBoundary(
1720  GetText(), nEnd,
1721  g_pBreakIt->GetLocale( GetLang( nEnd ) ),
1722  nWordType,
1723  false /*prefer backward direction*/);
1724 
1725  // prevent backtracking to the previous word if selection is at word boundary
1726  if (aSttBndry.endPos <= nStt)
1727  {
1728  aSttBndry = g_pBreakIt->GetBreakIter()->nextWord(
1729  GetText(), aSttBndry.endPos,
1730  g_pBreakIt->GetLocale( GetLang( aSttBndry.endPos ) ),
1731  nWordType);
1732  }
1733  // prevent advancing to the next word if selection is at word boundary
1734  if (aEndBndry.startPos >= nEnd)
1735  {
1736  aEndBndry = g_pBreakIt->GetBreakIter()->previousWord(
1737  GetText(), aEndBndry.startPos,
1738  g_pBreakIt->GetLocale( GetLang( aEndBndry.startPos ) ),
1739  nWordType);
1740  }
1741 
1742  Boundary aCurWordBndry( aSttBndry );
1743  while (aCurWordBndry.startPos <= aEndBndry.startPos)
1744  {
1745  nStt = aCurWordBndry.startPos;
1746  nEnd = aCurWordBndry.endPos;
1747  const sal_Int32 nLen = nEnd - nStt;
1748  OSL_ENSURE( nLen > 0, "invalid word length of 0" );
1749 
1750  Sequence <sal_Int32> aOffsets;
1751  OUString const sChgd( rTrans.transliterate(
1752  GetText(), GetLang(nStt), nStt, nLen, &aOffsets) );
1753 
1754  assert(nStt < m_Text.getLength());
1755  if (0 != rtl_ustr_shortenedCompare_WithLength(
1756  m_Text.getStr() + nStt, m_Text.getLength() - nStt,
1757  sChgd.getStr(), sChgd.getLength(), nLen))
1758  {
1759  aChgData.nStart = nStt;
1760  aChgData.nLen = nLen;
1761  aChgData.sChanged = sChgd;
1762  aChgData.aOffsets = aOffsets;
1763  aChanges.push_back( aChgData );
1764  }
1765 
1766  aCurWordBndry = g_pBreakIt->GetBreakIter()->nextWord(
1767  GetText(), nStt,
1768  g_pBreakIt->GetLocale(GetLang(nStt, 1)),
1769  nWordType);
1770  }
1771  }
1772  else if (rTrans.getType() == TransliterationFlags::SENTENCE_CASE)
1773  {
1774  // for 'sentence case' we need to iterate sentence by sentence
1775 
1776  sal_Int32 nLastStart = g_pBreakIt->GetBreakIter()->beginOfSentence(
1777  GetText(), nEnd,
1778  g_pBreakIt->GetLocale( GetLang( nEnd ) ) );
1779  sal_Int32 nLastEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1780  GetText(), nLastStart,
1781  g_pBreakIt->GetLocale( GetLang( nLastStart ) ) );
1782 
1783  // extend nStt, nEnd to the current sentence boundaries
1784  sal_Int32 nCurrentStart = g_pBreakIt->GetBreakIter()->beginOfSentence(
1785  GetText(), nStt,
1786  g_pBreakIt->GetLocale( GetLang( nStt ) ) );
1787  sal_Int32 nCurrentEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1788  GetText(), nCurrentStart,
1789  g_pBreakIt->GetLocale( GetLang( nCurrentStart ) ) );
1790 
1791  // prevent backtracking to the previous sentence if selection starts at end of a sentence
1792  if (nCurrentEnd <= nStt)
1793  {
1794  // now nCurrentStart is probably located on a non-letter word. (unless we
1795  // are in Asian text with no spaces...)
1796  // Thus to get the real sentence start we should locate the next real word,
1797  // that is one found by DICTIONARY_WORD
1798  i18n::Boundary aBndry = g_pBreakIt->GetBreakIter()->nextWord(
1799  GetText(), nCurrentEnd,
1800  g_pBreakIt->GetLocale( GetLang( nCurrentEnd ) ),
1801  i18n::WordType::DICTIONARY_WORD);
1802 
1803  // now get new current sentence boundaries
1804  nCurrentStart = g_pBreakIt->GetBreakIter()->beginOfSentence(
1805  GetText(), aBndry.startPos,
1806  g_pBreakIt->GetLocale( GetLang( aBndry.startPos) ) );
1807  nCurrentEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1808  GetText(), nCurrentStart,
1809  g_pBreakIt->GetLocale( GetLang( nCurrentStart) ) );
1810  }
1811  // prevent advancing to the next sentence if selection ends at start of a sentence
1812  if (nLastStart >= nEnd)
1813  {
1814  // now nCurrentStart is probably located on a non-letter word. (unless we
1815  // are in Asian text with no spaces...)
1816  // Thus to get the real sentence start we should locate the previous real word,
1817  // that is one found by DICTIONARY_WORD
1818  i18n::Boundary aBndry = g_pBreakIt->GetBreakIter()->previousWord(
1819  GetText(), nLastStart,
1820  g_pBreakIt->GetLocale( GetLang( nLastStart) ),
1821  i18n::WordType::DICTIONARY_WORD);
1822  nLastEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1823  GetText(), aBndry.startPos,
1824  g_pBreakIt->GetLocale( GetLang( aBndry.startPos) ) );
1825  if (nCurrentEnd > nLastEnd)
1826  nCurrentEnd = nLastEnd;
1827  }
1828 
1829  while (nCurrentStart < nLastEnd)
1830  {
1831  sal_Int32 nLen = nCurrentEnd - nCurrentStart;
1832  OSL_ENSURE( nLen > 0, "invalid word length of 0" );
1833 
1834  Sequence <sal_Int32> aOffsets;
1835  OUString const sChgd( rTrans.transliterate(GetText(),
1836  GetLang(nCurrentStart), nCurrentStart, nLen, &aOffsets) );
1837 
1838  assert(nStt < m_Text.getLength());
1839  if (0 != rtl_ustr_shortenedCompare_WithLength(
1840  m_Text.getStr() + nStt, m_Text.getLength() - nStt,
1841  sChgd.getStr(), sChgd.getLength(), nLen))
1842  {
1843  aChgData.nStart = nCurrentStart;
1844  aChgData.nLen = nLen;
1845  aChgData.sChanged = sChgd;
1846  aChgData.aOffsets = aOffsets;
1847  aChanges.push_back( aChgData );
1848  }
1849 
1850  Boundary aFirstWordBndry = g_pBreakIt->GetBreakIter()->nextWord(
1851  GetText(), nCurrentEnd,
1852  g_pBreakIt->GetLocale( GetLang( nCurrentEnd ) ),
1853  nWordType);
1854  nCurrentStart = aFirstWordBndry.startPos;
1855  nCurrentEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1856  GetText(), nCurrentStart,
1857  g_pBreakIt->GetLocale( GetLang( nCurrentStart ) ) );
1858  }
1859  }
1860  else
1861  {
1862  // here we may transliterate over complete language portions...
1863 
1864  std::unique_ptr<SwLanguageIterator> pIter;
1865  if( rTrans.needLanguageForTheMode() )
1866  pIter.reset(new SwLanguageIterator( *this, nStt ));
1867 
1868  sal_Int32 nEndPos = 0;
1870  do {
1871  if( pIter )
1872  {
1873  nLang = pIter->GetLanguage();
1874  nEndPos = pIter->GetChgPos();
1875  if( nEndPos > nEnd )
1876  nEndPos = nEnd;
1877  }
1878  else
1879  {
1880  nLang = LANGUAGE_SYSTEM;
1881  nEndPos = nEnd;
1882  }
1883  const sal_Int32 nLen = nEndPos - nStt;
1884 
1885  Sequence <sal_Int32> aOffsets;
1886  OUString const sChgd( rTrans.transliterate(
1887  m_Text, nLang, nStt, nLen, &aOffsets) );
1888 
1889  assert(nStt < m_Text.getLength());
1890  if (0 != rtl_ustr_shortenedCompare_WithLength(
1891  m_Text.getStr() + nStt, m_Text.getLength() - nStt,
1892  sChgd.getStr(), sChgd.getLength(), nLen))
1893  {
1894  aChgData.nStart = nStt;
1895  aChgData.nLen = nLen;
1896  aChgData.sChanged = sChgd;
1897  aChgData.aOffsets = aOffsets;
1898  aChanges.push_back( aChgData );
1899  }
1900 
1901  nStt = nEndPos;
1902  } while( nEndPos < nEnd && pIter && pIter->Next() );
1903  }
1904 
1905  if (!aChanges.empty())
1906  {
1907  // now apply the changes from end to start to leave the offsets of the
1908  // yet unchanged text parts remain the same.
1909  size_t nSum(0);
1910  for (size_t i = 0; i < aChanges.size(); ++i)
1911  { // check this here since AddChanges cannot be moved below
1912  // call to ReplaceTextOnly
1913  swTransliterationChgData & rData =
1914  aChanges[ aChanges.size() - 1 - i ];
1915  nSum += rData.sChanged.getLength() - rData.nLen;
1916  if (nSum > static_cast<size_t>(GetSpaceLeft()))
1917  {
1918  SAL_WARN("sw.core", "SwTextNode::ReplaceTextOnly: "
1919  "node text with insertion > node capacity.");
1920  return;
1921  }
1922  if (pUndo)
1923  pUndo->AddChanges( *this, rData.nStart, rData.nLen, rData.aOffsets );
1924  ReplaceTextOnly( rData.nStart, rData.nLen, rData.sChanged, rData.aOffsets );
1925  }
1926  }
1927  }
1928 }
1929 
1930 void SwTextNode::ReplaceTextOnly( sal_Int32 nPos, sal_Int32 nLen,
1931  const OUString & rText,
1932  const Sequence<sal_Int32>& rOffsets )
1933 {
1934  assert(rText.getLength() - nLen <= GetSpaceLeft());
1935 
1936  m_Text = m_Text.replaceAt(nPos, nLen, rText);
1937 
1938  sal_Int32 nTLen = rText.getLength();
1939  const sal_Int32* pOffsets = rOffsets.getConstArray();
1940  // now look for no 1-1 mapping -> move the indices!
1941  sal_Int32 nMyOff = nPos;
1942  for( sal_Int32 nI = 0; nI < nTLen; ++nI )
1943  {
1944  const sal_Int32 nOff = pOffsets[ nI ];
1945  if( nOff < nMyOff )
1946  {
1947  // something is inserted
1948  sal_Int32 nCnt = 1;
1949  while( nI + nCnt < nTLen && nOff == pOffsets[ nI + nCnt ] )
1950  ++nCnt;
1951 
1952  Update( SwIndex( this, nMyOff ), nCnt );
1953  nMyOff = nOff;
1954  //nMyOff -= nCnt;
1955  nI += nCnt - 1;
1956  }
1957  else if( nOff > nMyOff )
1958  {
1959  // something is deleted
1960  Update( SwIndex( this, nMyOff+1 ), nOff - nMyOff, true );
1961  nMyOff = nOff;
1962  }
1963  ++nMyOff;
1964  }
1965  if( nMyOff < nLen )
1966  // something is deleted at the end
1967  Update( SwIndex( this, nMyOff ), nLen - nMyOff, true );
1968 
1969  // notify the layout!
1970  SwDelText aDelHint( nPos, nTLen );
1971  NotifyClients( nullptr, &aDelHint );
1972 
1973  SwInsText aHint( nPos, nTLen );
1974  NotifyClients( nullptr, &aHint );
1975 }
1976 
1977 // the return values allows us to see if we did the heavy-
1978 // lifting required to actually break and count the words.
1980  sal_Int32 nStt, sal_Int32 nEnd ) const
1981 {
1982  if( nStt > nEnd )
1983  { // bad call
1984  return false;
1985  }
1986  if (IsInRedlines())
1987  { //not counting txtnodes used to hold deleted redline content
1988  return false;
1989  }
1990  bool bCountAll = ( (0 == nStt) && (GetText().getLength() == nEnd) );
1991  ++rStat.nAllPara; // #i93174#: count _all_ paragraphs
1992  if ( IsHidden() )
1993  { // not counting hidden paras
1994  return false;
1995  }
1996  // count words in numbering string if started at beginning of para:
1997  bool bCountNumbering = nStt == 0;
1998  bool bHasBullet = false, bHasNumbering = false;
1999  OUString sNumString;
2000  if (bCountNumbering)
2001  {
2002  sNumString = GetNumString();
2003  bHasNumbering = !sNumString.isEmpty();
2004  if (!bHasNumbering)
2005  bHasBullet = HasBullet();
2006  bCountNumbering = bHasNumbering || bHasBullet;
2007  }
2008 
2009  if( nStt == nEnd && !bCountNumbering)
2010  { // unnumbered empty node or empty selection
2011  return false;
2012  }
2013 
2014  // count of non-empty paras
2015  ++rStat.nPara;
2016 
2017  // Shortcut when counting whole paragraph and current count is clean
2018  if ( bCountAll && !IsWordCountDirty() )
2019  {
2020  // accumulate into DocStat record to return the values
2022  {
2027  }
2028  return false;
2029  }
2030 
2031  // ConversionMap to expand fields, remove invisible and redline deleted text for scanner
2032  const ModelToViewHelper aConversionMap(*this,
2033  getIDocumentLayoutAccess().GetCurrentLayout(),
2035  const OUString& aExpandText = aConversionMap.getViewText();
2036 
2037  if (aExpandText.isEmpty() && !bCountNumbering)
2038  {
2039  return false;
2040  }
2041 
2042  // map start and end points onto the ConversionMap
2043  const sal_Int32 nExpandBegin = aConversionMap.ConvertToViewPosition( nStt );
2044  const sal_Int32 nExpandEnd = aConversionMap.ConvertToViewPosition( nEnd );
2045 
2046  //do the count
2047  // all counts exclude hidden paras and hidden+redlined within para
2048  // definition of space/white chars in SwScanner (and BreakIter!)
2049  // uses both u_isspace and BreakIter getWordBoundary in SwScanner
2050  sal_uInt32 nTmpWords = 0; // count of all words
2051  sal_uInt32 nTmpAsianWords = 0; //count of all Asian codepoints
2052  sal_uInt32 nTmpChars = 0; // count of all chars
2053  sal_uInt32 nTmpCharsExcludingSpaces = 0; // all non-white chars
2054 
2055  // count words in masked and expanded text:
2056  if (!aExpandText.isEmpty())
2057  {
2058  assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
2059 
2060  // zero is NULL for pLanguage -----------v last param = true for clipping
2061  SwScanner aScanner( *this, aExpandText, nullptr, aConversionMap, i18n::WordType::WORD_COUNT,
2062  nExpandBegin, nExpandEnd, true );
2063 
2064  // used to filter out scanner returning almost empty strings (len=1; unichar=0x0001)
2065  const OUString aBreakWord( CH_TXTATR_BREAKWORD );
2066 
2067  while ( aScanner.NextWord() )
2068  {
2069  if( !aExpandText.match(aBreakWord, aScanner.GetBegin() ))
2070  {
2071  ++nTmpWords;
2072  const OUString &rWord = aScanner.GetWord();
2073  if (g_pBreakIt->GetBreakIter()->getScriptType(rWord, 0) == i18n::ScriptType::ASIAN)
2074  ++nTmpAsianWords;
2075  nTmpCharsExcludingSpaces += g_pBreakIt->getGraphemeCount(rWord);
2076  }
2077  }
2078 
2079  nTmpCharsExcludingSpaces += aScanner.getOverriddenDashCount();
2080 
2081  nTmpChars = g_pBreakIt->getGraphemeCount(aExpandText, nExpandBegin, nExpandEnd);
2082  }
2083 
2084  // no nTmpCharsExcludingSpaces adjust needed neither for blanked out MaskedChars
2085  // nor for mid-word selection - set scanner bClip = true at creation
2086 
2087  // count outline number label - ? no expansion into map
2088  // always counts all of number-ish label
2089  if (bHasNumbering) // count words in numbering string
2090  {
2091  LanguageType aLanguage = GetLang( 0 );
2092 
2093  SwScanner aScanner( *this, sNumString, &aLanguage, ModelToViewHelper(),
2094  i18n::WordType::WORD_COUNT, 0, sNumString.getLength(), true );
2095 
2096  while ( aScanner.NextWord() )
2097  {
2098  ++nTmpWords;
2099  const OUString &rWord = aScanner.GetWord();
2100  if (g_pBreakIt->GetBreakIter()->getScriptType(rWord, 0) == i18n::ScriptType::ASIAN)
2101  ++nTmpAsianWords;
2102  nTmpCharsExcludingSpaces += g_pBreakIt->getGraphemeCount(rWord);
2103  }
2104 
2105  nTmpCharsExcludingSpaces += aScanner.getOverriddenDashCount();
2106  nTmpChars += g_pBreakIt->getGraphemeCount(sNumString);
2107  }
2108  else if ( bHasBullet )
2109  {
2110  ++nTmpWords;
2111  ++nTmpChars;
2112  ++nTmpCharsExcludingSpaces;
2113  }
2114 
2115  // If counting the whole para then update cached values and mark clean
2116  if ( bCountAll )
2117  {
2118  if ( m_pParaIdleData_Impl )
2119  {
2120  m_pParaIdleData_Impl->nNumberOfWords = nTmpWords;
2121  m_pParaIdleData_Impl->nNumberOfAsianWords = nTmpAsianWords;
2122  m_pParaIdleData_Impl->nNumberOfChars = nTmpChars;
2123  m_pParaIdleData_Impl->nNumberOfCharsExcludingSpaces = nTmpCharsExcludingSpaces;
2124  }
2125  SetWordCountDirty( false );
2126  }
2127  // accumulate into DocStat record to return the values
2128  rStat.nWord += nTmpWords;
2129  rStat.nAsianWord += nTmpAsianWords;
2130  rStat.nChar += nTmpChars;
2131  rStat.nCharExcludingSpaces += nTmpCharsExcludingSpaces;
2132 
2133  return true;
2134 }
2135 
2136 // Paragraph statistics start -->
2137 
2139 {
2140  if ( bNew )
2141  {
2143  }
2144  else if ( m_pParaIdleData_Impl )
2145  {
2146  delete m_pParaIdleData_Impl->pWrong;
2149  delete m_pParaIdleData_Impl;
2150  m_pParaIdleData_Impl = nullptr;
2151  }
2152 }
2153 
2154 void SwTextNode::SetWrong( SwWrongList* pNew, bool bDelete )
2155 {
2156  if ( m_pParaIdleData_Impl )
2157  {
2158  if ( bDelete )
2159  {
2160  delete m_pParaIdleData_Impl->pWrong;
2161  }
2162  m_pParaIdleData_Impl->pWrong = pNew;
2163  }
2164 }
2165 
2167 {
2168  return m_pParaIdleData_Impl ? m_pParaIdleData_Impl->pWrong : nullptr;
2169 }
2170 
2171 // #i71360#
2173 {
2174  return m_pParaIdleData_Impl ? m_pParaIdleData_Impl->pWrong : nullptr;
2175 }
2176 
2178 {
2179  if ( m_pParaIdleData_Impl )
2180  {
2181  if ( bDelete )
2182  {
2184  }
2186  }
2187 }
2188 
2190 {
2192 }
2193 
2195 {
2196  return static_cast<SwWrongList const*>(const_cast<SwTextNode*>(this)->GetGrammarCheck());
2197 }
2198 
2199 void SwTextNode::SetSmartTags( SwWrongList* pNew, bool bDelete )
2200 {
2201  OSL_ENSURE( !pNew || SwSmartTagMgr::Get().IsSmartTagsEnabled(),
2202  "Weird - we have a smart tag list without any recognizers?" );
2203 
2204  if ( m_pParaIdleData_Impl )
2205  {
2206  if ( bDelete )
2207  {
2209  }
2211  }
2212 }
2213 
2215 {
2217 }
2218 
2220 {
2221  return const_cast<SwWrongList const*>(const_cast<SwTextNode*>(this)->GetSmartTags());
2222 }
2223 
2224 void SwTextNode::SetWordCountDirty( bool bNew ) const
2225 {
2226  if ( m_pParaIdleData_Impl )
2227  {
2229  }
2230 }
2231 
2233 {
2235 }
2236 
2238 {
2239  if ( m_pParaIdleData_Impl )
2240  {
2242  }
2243 }
2244 
2246 {
2248 }
2249 
2251 {
2253 }
2254 
2255 void SwTextNode::SetGrammarCheckDirty( bool bNew ) const
2256 {
2257  if ( m_pParaIdleData_Impl )
2258  {
2260  }
2261 }
2262 
2264 {
2266 }
2267 
2268 void SwTextNode::SetSmartTagDirty( bool bNew ) const
2269 {
2270  if ( m_pParaIdleData_Impl )
2271  {
2273  }
2274 }
2275 
2277 {
2279 }
2280 
2282 {
2283  if ( m_pParaIdleData_Impl )
2284  {
2286  }
2287 }
2288 
2290 {
2292 }
2293 
2294 // <-- Paragraph statistics end
2295 
2296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
LanguageType const nConvSrcLang
Definition: splargs.hxx:65
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
void SetWordCountDirty(bool bNew) const
Definition: txtedt.cxx:2224
sal_Int32 Pos(sal_uInt16 nIdx) const
Definition: wrong.hxx:304
void SetCharSet(rtl_TextEncoding _eEncoding)
sal_Int32 & GetStart()
start position
Definition: txatbase.hxx:77
const sal_Char * pChar
OUString m_aWord
Definition: swscanner.hxx:35
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
virtual std::shared_ptr< SfxItemSet > getAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily, const OUString *pParentName=nullptr)=0
#define LANGUAGE_NONE
bool bAllowImplicitChangesForNotConvertibleText
Definition: splargs.hxx:72
sal_uLong GetIndex() const
Definition: node.hxx:282
bool InsertWord(const OUString &rWord, SwDoc &rDoc)
Definition: acmplwrd.cxx:226
SwInterHyphInfoTextFrame(SwTextFrame const &rFrame, SwTextNode const &rNode, SwInterHyphInfo const &rHyphInfo)
Definition: txtedt.cxx:1593
bool HasBullet() const
Returns if this text node has a bullet.
Definition: ndtxt.cxx:3113
void SetStyleName(const OUString &rStyleName)
SwGrammarMarkUp * pGrammarCheck
Definition: txtedt.cxx:111
Marks a position in the document model.
Definition: pam.hxx:35
#define RES_CHRATR_CJK_LANGUAGE
Definition: hintids.hxx:92
const OUString & GetFamilyName() const
sal_uLong nPara
paragraphs for document statistic: non-empty and non-hidden ones
Definition: docstat.hxx:32
const OUString & GetText() const
Definition: ndtxt.hxx:211
virtual bool get(DocumentSettingId id) const override
Return the specified document setting.
static SwAutoCompleteWord & GetAutoCompleteWords()
Definition: doc.hxx:1521
#define RES_TXTATR_METAFIELD
Definition: hintids.hxx:139
bool IsWrongDirty() const
Definition: txtedt.cxx:2250
SwDocShell * GetDocShell()
Definition: doc.hxx:1340
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:219
const OUString & GetStyleName() const
bool isTXTATR_WITHEND(const sal_uInt16 nWhich)
Definition: hintids.hxx:346
FreshState Fresh(sal_Int32 &rStart, sal_Int32 &rEnd, sal_Int32 nPos, sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos)
Remove given range of entries.
Definition: wrong.cxx:355
void InvalidateAccessibleParaAttrs(const SwTextFrame &rTextFrame)
invalidate attributes for paragraphs and paragraph's characters
Definition: viewsh.cxx:2450
SwNodeIndex nNode
Definition: pam.hxx:37
void SetPitch(FontPitch _ePitch)
void SetCompletePaint() const
Definition: frame.hxx:970
virtual void InsertItemSet(const SwPaM &rRg, const SfxItemSet &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr)=0
sal_Int32 GetSpaceLeft() const
Definition: ndtxt.hxx:859
sal_uIntPtr sal_uLong
void UpdateTextNodeHyphInfo(SwTextFrame const &rFrame, SwTextNode const &rNode, SwInterHyphInfo &o_rHyphInfo)
Definition: txtedt.cxx:1603
bool Spell(SwSpellArgs *)
Definition: txtedt.cxx:950
css::uno::Reference< css::linguistic2::XSpellChecker1 > xSpeller
Definition: splargs.hxx:88
Implementation of the css::text::XTextMarkup interface.
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:402
static bool lcl_MaskRedlinesAndHiddenText(const SwTextNode &rNode, OUStringBuffer &rText, sal_Int32 nStt, sal_Int32 nEnd, const sal_Unicode cChar=CH_TXTATR_INWORD)
Used for spell checking.
Definition: txtedt.cxx:188
static bool IsAutoCompleteWords()
Definition: viewopt.cxx:318
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1150
Definition: doc.hxx:185
const LanguageTag & getLanguageTag() const
TransliterationFlags getType() const
bool HasFollow() const
Definition: flowfrm.hxx:165
SAL_DLLPRIVATE void SetLanguageAndFont(const SwPaM &rPaM, LanguageType nLang, sal_uInt16 nLangWhichId, const vcl::Font *pFont, sal_uInt16 nFontWhichId)
Definition: txtedt.cxx:1075
aBuf
void SetFamily(FontFamily _eFamily)
sal_uLong nChar
Definition: docstat.hxx:37
void Height(long nNew)
Definition: swrect.hxx:189
LanguageType GetCurrentLanguage() const
Definition: swscanner.hxx:70
long GetBottom(const SwRect &rRect) const
Definition: frame.hxx:1339
TextFrameIndex GetOfst() const
Definition: txtfrm.hxx:426
SwNode & GetNode() const
Definition: ndindex.hxx:118
bool IsAtEnd() const
void TryDeleteSwpHints()
Definition: ndtxt.hxx:828
bool IsSmartTagDirty() const
Definition: txtedt.cxx:2276
sal_uLong nNumberOfWords
Definition: txtedt.cxx:113
This struct defines a position in the model string.
#define RES_CHRATR_CJK_FONT
Definition: hintids.hxx:90
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
sal_uInt16 Which() const
Definition: txatbase.hxx:105
sal_Int32 m_nStartPos
Definition: swscanner.hxx:40
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1278
SwTextAttr * GetTextAttrAt(sal_Int32 const nIndex, sal_uInt16 const nWhich, enum GetTextAttrMode const eMode=DEFAULT) const
get the innermost text attribute covering position nIndex.
Definition: ndtxt.cxx:1729
const vcl::Font * pTargetFont
Definition: splargs.hxx:70
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:347
void SetSmartTags(SwWrongList *pNew, bool bDelete=true)
Definition: txtedt.cxx:2199
void SetGrammarCheckDirty(bool bNew) const
Definition: txtedt.cxx:2255
void CalcStartEnd(sal_uLong nNdIdx, sal_Int32 &rStart, sal_Int32 &rEnd) const
Calculates the intersection with text node number nNdIdx.
Definition: docredln.cxx:1316
sal_uLong nCharExcludingSpaces
Definition: docstat.hxx:38
const Point * GetCursorPos() const
Definition: splargs.hxx:131
FontFamily GetFamilyType()
VclInputFlags
static bool IsShowChanges(const RedlineFlags eM)
bool IsSymbolAt(sal_Int32 nBegin) const
in ndcopy.cxx
Definition: itratr.cxx:840
static LanguageType nLang
Definition: srtdlg.cxx:58
void SetFamilyName(const OUString &rFamilyName)
bool Hyphenate(SwInterHyphInfoTextFrame &rInf)
We format a Line for interactive hyphenation.
Definition: txthyph.cxx:59
size_type size() const
Definition: docary.hxx:370
bool IsHiddenNow() const
Hidden.
Definition: txtfrm.cxx:1345
OUString GetCurWord(SwPosition const &) const
Definition: txtedt.cxx:665
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:43
#define RES_TXTATR_META
Definition: hintids.hxx:138
sal_Int32 getGraphemeCount(const OUString &rStr, sal_Int32 nStart, sal_Int32 nEnd) const
Definition: breakit.cxx:158
bool isLetterNumeric(const OUString &rStr, sal_Int32 nPos) const
sal_uInt16 sal_Unicode
static sal_Int32 MaskHiddenRanges(const SwTextNode &rNode, OUStringBuffer &rText, const sal_Int32 nStt, const sal_Int32 nEnd, const sal_Unicode cChar)
Hidden text attribute handling.
Definition: porlay.cxx:1491
bool IsInRedlines() const
Checks if this node is in redlines.
Definition: node.cxx:2056
#define CH_TXTATR_INWORD
Definition: hintids.hxx:44
Reference< XController > xController
FUNC_TYPE const nType
SwIndex nContent
Definition: pam.hxx:38
TextFrameIndex m_nWordStart
output: found word
Definition: txtfrm.hxx:65
sal_Int32 ConvertToViewPosition(sal_Int32 nModelPos) const
Converts a model position into a view position.
void DestroyAttr(SwTextAttr *pAttr)
Definition: thints.cxx:1111
bool bAutoComplDirty
auto complete list dirty
Definition: txtedt.cxx:121
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:34
sal_Int32 m_nEndPos
Definition: swscanner.hxx:41
sal_Int32 m_nOverriddenDashCount
Definition: swscanner.hxx:44
bool const m_bClip
Definition: swscanner.hxx:47
bool IsWordCountDirty() const
Definition: txtedt.cxx:2232
sal_Int32 m_nBegin
Definition: swscanner.hxx:42
long GetLeft(const SwRect &rRect) const
Definition: frame.hxx:1340
long GetRight(const SwRect &rRect) const
Definition: frame.hxx:1341
sal_uLong nNumberOfChars
Definition: txtedt.cxx:115
bool needLanguageForTheMode() const
const RedlineType_t REDLINE_DELETE
void SetWrongDirty(WrongState eNew) const
Definition: txtedt.cxx:2237
static sal_Int16 CheckSpellLang(css::uno::Reference< css::linguistic2::XSpellChecker1 > const &xSpell, LanguageType nLang)
TextFrameIndex m_nEnd
Definition: txtfrm.hxx:63
const SwRect GetPaintArea() const
|* The paintarea is the area, in which the content of a frame is allowed |* to be displayed...
Definition: ssfrm.cxx:619
void SetBottom(SwRect &rRect, long nNew) const
Definition: frame.hxx:1348
SwTextFrame * GetFollow()
Definition: txtfrm.hxx:842
void TransliterateText(utl::TransliterationWrapper &rTrans, sal_Int32 nStart, sal_Int32 nEnd, SwUndoTransliterate *pUndo)
change text to Upper/Lower/Hiragana/Katakana/...
Definition: txtedt.cxx:1685
SAL_DLLPRIVATE void InitSwParaStatistics(bool bNew)
Start: Data collected during idle time.
Definition: txtedt.cxx:2138
std::function< LanguageType(sal_Int32, sal_Int32, bool)> const m_pGetLangOfChar
Definition: swscanner.hxx:34
virtual SwRedlineTable::size_type GetRedlinePos(const SwNode &rNode, sal_uInt16 nType) const =0
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
sal_Int32 NextWrong(sal_Int32 nChk) const
Find next incorrectly selected position.
Definition: wrong.cxx:163
bool FrameContainsNode(SwContentFrame const &rFrame, sal_uLong nNodeIndex)
Definition: txtfrm.cxx:289
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:614
SwIndex * pStartIdx
Definition: splargs.hxx:39
LanguageType nConvTextLang
Definition: splargs.hxx:66
RedlineType_t GetType(sal_uInt16 nPos=0) const
Definition: redline.hxx:225
UNDERLYING_TYPE get() const
void RstTextAttr(const SwIndex &rIdx, const sal_Int32 nLen, const sal_uInt16 nWhich=0, const SfxItemSet *pSet=nullptr, const bool bInclRefToxMark=false, const bool bExactRange=false)
delete all attributes.
Definition: txtedt.cxx:366
const OUString & getViewText() const
sal_uInt16 Count() const
Definition: wrong.hxx:309
SvtScriptType GetScriptType() const
returns the script type of the selection
Definition: edattr.cxx:671
TextFrameIndex MapModelToViewPos(SwPosition const &rPos) const
Definition: txtfrm.cxx:1254
sal_uLong nAsianWord
Definition: docstat.hxx:36
#define SW_MOD()
Definition: swmodule.hxx:255
void SetTop(SwRect &rRect, long nNew) const
Definition: frame.hxx:1347
FontPitch GetPitch()
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SwWrongList * pSmartTags
Definition: txtedt.cxx:112
SwScanner(const std::function< LanguageType(sal_Int32, sal_Int32, bool)> &pGetLangOfChar, const OUString &rText, const LanguageType *pLang, const ModelToViewHelper &rConvMap, sal_uInt16 nWordType, sal_Int32 nStart, sal_Int32 nEnde, bool bClip=false)
void SetSmartTagDirty(bool bNew) const
Definition: txtedt.cxx:2268
const ModelToViewHelper m_ModelToView
Definition: swscanner.hxx:39
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void RecognizeTextRange(const css::uno::Reference< css::text::XTextRange > &rRange, const css::uno::Reference< css::text::XTextMarkup > &rMarkup, const css::uno::Reference< css::frame::XController > &rController) const
static bool AnyInput(VclInputFlags nType=VCL_INPUT_ANY)
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:198
static SwSmartTagMgr & Get()
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:323
SwTextAttr * MakeTextAttr(SwDoc &rDoc, SfxPoolItem &rAttr, sal_Int32 const nStt, sal_Int32 const nEnd, CopyOrNewType const bIsCopy, SwTextNode *const pTextNode)
if COPY then pTextNode must be given!
Definition: thints.cxx:979
#define LANGUAGE_SYSTEM
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2143
Count
bool HasContent() const
Definition: txatbase.hxx:101
TextFrameIndex MapModelToView(MergedPara const &, SwTextNode const *pNode, sal_Int32 nIndex)
Definition: txtfrm.cxx:1170
int i
static bool IsChinese(LanguageType nLang)
vector_type::size_type size_type
Definition: docary.hxx:331
sal_uInt16 Count() const
const SfxPoolItem * NextItem()
static bool lcl_HaveCommonAttributes(IStyleAccess &rStyleAccess, const SfxItemSet *pSet1, sal_uInt16 nWhichId, const SfxItemSet &rSet2, std::shared_ptr< SfxItemSet > &pStyleHandle)
Used for automatic styles.
Definition: txtedt.cxx:294
SwDoc * GetDoc()
Definition: node.hxx:702
void SetAutoCompleteWordDirty(bool bNew) const
Definition: txtedt.cxx:2281
SwTextFrame & GetFrameAtOfst(TextFrameIndex nOfst)
Definition: frmcrsr.cxx:144
sal_Int32 Len(sal_uInt16 nIdx) const
Definition: wrong.hxx:299
Marks a character position inside a document model node.
Definition: index.hxx:37
void SetSelection(const SwPaM &rCursor)
Definition: crsrsh.cxx:3393
SwGrammarMarkUp * GetGrammarCheck()
Definition: txtedt.cxx:2189
const OUString m_aPreDashReplacementText
Definition: swscanner.hxx:36
bool Hyphenate(SwInterHyphInfo &rHyphInf)
Interactive hyphenation: we find TextFrame and call its CalcHyph.
Definition: txtedt.cxx:1619
void SetMissingDictionaries(bool bIsMissing)
Use to notify if the dictionary can be found for a single content portion (has to be called for all p...
Definition: doc.cxx:1828
css::uno::Reference< css::linguistic2::XHyphenatedWord > m_xHyphWord
output: hyphenated word
Definition: txtfrm.hxx:59
#define RES_TXTATR_TOXMARK
Definition: hintids.hxx:137
sal_uInt16 GetSortNumber() const
Definition: txtatr.hxx:50
SwWrongList * GetSmartTags()
Definition: txtedt.cxx:2214
LanguageType nConvTargetLang
Definition: splargs.hxx:69
T static_txtattr_cast(S *s)
Definition: txatbase.hxx:231
virtual sal_Int32 * GetEnd()
end position
Definition: txatbase.cxx:49
attention: NOHINTADJUST prevents MergePortions! when using this need to pay attention to ignore start...
sal_Int32 GetChgPos() const
Definition: txatritr.hxx:67
SwWrongList * pWrong
Definition: txtedt.cxx:110
std::pair< SwTextNode *, sal_Int32 > MapViewToModel(TextFrameIndex nIndex) const
map position in potentially merged text frame to SwPosition
Definition: txtfrm.cxx:1218
sal_uLong nNumberOfCharsExcludingSpaces
Definition: txtedt.cxx:116
sal_Int32 GetEndInv() const
Definition: wrong.hxx:275
enumrange< T >::Iterator end(enumrange< T >)
const SwPosition * Start() const
Definition: pam.hxx:212
EXPAND : (Start < nIndex <= End)
Definition: ndtxt.hxx:363
void NotifyClients(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:167
void SetLeft(SwRect &rRect, long nNew) const
Definition: frame.hxx:1349
#define VCL_INPUT_ANY
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: node.cxx:2044
void SetGrammarCheck(SwGrammarMarkUp *pNew, bool bDelete=true)
Definition: txtedt.cxx:2177
void ReplaceTextOnly(sal_Int32 nPos, sal_Int32 nLen, const OUString &rText, const css::uno::Sequence< sal_Int32 > &rOffsets)
Definition: txtedt.cxx:1930
const OUString & GetWord() const
Definition: swscanner.hxx:64
OUString aConvText
Definition: splargs.hxx:64
const css::lang::Locale & GetLocale(const LanguageType aLang)
Definition: breakit.hxx:67
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
SwTextNode::WrongState eWrongDirty
online spell checking needed/done?
Definition: txtedt.cxx:118
static sal_Int32 lcl_MaskRedlines(const SwTextNode &rNode, OUStringBuffer &rText, sal_Int32 nStt, sal_Int32 nEnd, const sal_Unicode cChar)
Definition: txtedt.cxx:144
sal_uInt16 const m_nWordType
Definition: swscanner.hxx:46
css::uno::Reference< css::linguistic2::XSpellAlternatives > xSpellAlt
Definition: splargs.hxx:90
friend class SwIndex
Definition: index.hxx:112
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:367
sal_Int32 GetBeginInv() const
Definition: wrong.hxx:274
void SetHyphWord(const css::uno::Reference< css::linguistic2::XHyphenatedWord > &rxHW)
Definition: splargs.hxx:135
#define RES_TXTATR_AUTOFMT
Definition: hintids.hxx:140
SwRect AutoSpell_(SwTextNode &, sal_Int32)
Is called by DoIdleJob_() and ExecSpellPopup()
Definition: txtedt.cxx:1246
sal_Int32 m_nLength
Definition: swscanner.hxx:43
sal_uInt16 GetMinWordLen() const
Definition: acmplwrd.hxx:64
WrongState GetWrongDirty() const
Definition: txtedt.cxx:2245
css::uno::Reference< css::frame::XController > GetController()
Definition: docsh.cxx:1305
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:259
sal_uInt16 GetWrongPos(sal_Int32 nValue) const
Find the first position that is greater or equal to the given value.
Definition: wrong.cxx:190
SwParaIdleData_Impl * m_pParaIdleData_Impl
Definition: ndtxt.hxx:100
TextFrameIndex MapModelToView(SwTextNode const *pNode, sal_Int32 nIndex) const
Definition: txtfrm.cxx:1239
OUString transliterate(const OUString &rStr, sal_Int32 nStart, sal_Int32 nLen) const
sal_Int32 GetIndex() const
Definition: index.hxx:95
bool InWrongWord(sal_Int32 &rChk, sal_Int32 &rLn) const
If a word is incorrectly selected, this method returns begin and length of it.
Definition: wrong.cxx:102
void CollectAutoCmplWrds(SwTextNode &, sal_Int32)
Is called by DoIdleJob_()
Definition: txtedt.cxx:1543
uno::Reference< linguistic2::XSpellChecker1 > GetSpellChecker()
Definition: swtypes.cxx:66
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:218
LanguageType GetLang(const sal_Int32 nBegin, const sal_Int32 nLen=0, sal_uInt16 nScript=0) const
Definition: thints.cxx:3361
TextFrameIndex m_nStart
input: requested range to hyphenate
Definition: txtfrm.hxx:62
void SetWrong(SwWrongList *pNew, bool bDelete=true)
Definition: txtedt.cxx:2154
const sal_Int32 * End() const
Definition: txatbase.hxx:142
ModelPosition ConvertToModelPosition(sal_Int32 nViewPos) const
Converts a view position into a model position.
SwRect SmartTagScan(SwTextNode &)
Is called by DoIdleJob_()
Definition: txtedt.cxx:1427
void SetRight(SwRect &rRect, long nNew) const
Definition: frame.hxx:1350
bool IsHidden() const
Definition: ndtxt.cxx:4559
SwWrongList * GetWrong()
Definition: txtedt.cxx:2166
sal_Int32 GetBegin() const
Definition: swscanner.hxx:66
bool IsAutoCompleteWordDirty() const
Definition: txtedt.cxx:2289
bool CountWords(SwDocStat &rStat, sal_Int32 nStart, sal_Int32 nEnd) const
count words in given range - returns true if we refreshed out count
Definition: txtedt.cxx:1979
const LanguageType * m_pLanguage
Definition: swscanner.hxx:38
#define RES_TXTATR_REFMARK
Definition: hintids.hxx:136
a clone of SwInterHyphInfo, but with TextFrameIndex instead of node index
Definition: txtfrm.hxx:55
sal_Int32 nWordLen
Definition: splargs.hxx:122
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:723
void RecognizeString(const OUString &rText, const css::uno::Reference< css::text::XTextMarkup > &rMarkup, const css::uno::Reference< css::frame::XController > &rController, const css::lang::Locale &rLocale, sal_uInt32 nStart, sal_uInt32 nLen) const
bool InsertHint(SwTextAttr *const pAttr, const SetAttrMode nMode=SetAttrMode::DEFAULT)
Insert pAttr into hints array.
Definition: thints.cxx:1254
sal_uLong nNumberOfAsianWords
Definition: txtedt.cxx:114
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter()
Definition: breakit.hxx:62
OUString GetNumString(const bool _bInclPrefixAndSuffixStrings=true, const unsigned int _nRestrictToThisLevel=MAXLEVEL, SwRootFrame const *pLayout=nullptr) const
Returns outline of numbering string.
Definition: ndtxt.cxx:3131
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:153
SwTextNode * pStartNode
Definition: splargs.hxx:38
LanguageType m_aCurrentLang
Definition: swscanner.hxx:45
void setLanguageTag(const LanguageTag &rLanguageTag)
long GetTop(const SwRect &rRect) const
Definition: frame.hxx:1338
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
#define SAL_WARN(area, stream)
SwIndex * pEndIdx
Definition: splargs.hxx:41
SwFormatColl * GetFormatColl() const
Definition: node.hxx:447
std::unique_ptr< SwpHints > m_pSwpHints
May be 0.
Definition: ndtxt.hxx:93
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:457
static sal_Int32 clipIndexBounds(const OUString &rStr, sal_Int32 nPos)
Definition: txtedt.cxx:652
SwTextFrame * SwHyphIterCacheLastTextFrame(SwTextNode const *pNode, const sw::Creator &create)
Definition: edlingu.cxx:569
bool Pop(PopMode)
delete cursor
Definition: crsrsh.cxx:2165
sal_uLong nWord
Definition: docstat.hxx:35
static css::uno::Reference< css::text::XTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1135
sal_Int32 nWordStart
output: found word
Definition: splargs.hxx:121
virtual const SwRedlineTable & GetRedlineTable() const =0
bool NextWord()
Definition: txtedt.cxx:808
sal_uLong nAllPara
all paragraphs, including empty/hidden ones
Definition: docstat.hxx:34
void Insert(sal_uInt16 nWhere, std::vector< SwWrongArea >::iterator startPos, std::vector< SwWrongArea >::iterator const &endPos)
Definition: wrong.cxx:537
static SwRect lcl_CalculateRepaintRect(SwTextFrame &rTextFrame, SwTextNode &rNode, sal_Int32 const nChgStart, sal_Int32 const nChgEnd)
Used for spell checking.
Definition: txtedt.cxx:221
SwViewShell * GetCurrShell() const
Definition: rootfrm.hxx:204
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 Convert(SwConversionArgs &)
Definition: txtedt.cxx:1110
TextFrameIndex m_nWordLen
Definition: txtfrm.hxx:66
CharClass & GetAppCharClass()
Definition: init.cxx:740
#define RES_TXTATR_INPUTFIELD
Definition: hintids.hxx:145
LanguageType GetLanguage() const
Definition: txatritr.hxx:68
SwTextNode * pEndNode
Definition: splargs.hxx:40
OUString m_Text
Definition: ndtxt.hxx:98
IStyleAccess & getIDocumentStyleAccess()
Provides access to the document automatic styles interface.
Definition: node.cxx:2054
const sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:61
sal_uInt16 Which() const
SwRootFrame * getRootFrame()
Definition: frame.hxx:657
virtual void Update(SwIndex const &rPos, const sal_Int32 nChangeLen, const bool bNegative=false, const bool bDelete=false) override
override SwIndexReg
Definition: ndtxt.cxx:1171
OUString m_aText
Definition: swscanner.hxx:37
void SetInvalid(sal_Int32 nBegin, sal_Int32 nEnd)
Definition: wrong.cxx:253
rtl_TextEncoding GetCharSet() const
const SfxPoolItem * GetCurItem() const
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:842
bool IsGrammarCheckDirty() const
Definition: txtedt.cxx:2263
bool HasHints() const
Definition: ndtxt.hxx:221
bool IsSymbolAt(TextFrameIndex) const
Definition: itratr.cxx:190
sal_Int32 GetEnd() const
Definition: swscanner.hxx:67
void AddChanges(SwTextNode &rTNd, sal_Int32 nStart, sal_Int32 nLen, css::uno::Sequence< sal_Int32 > const &rOffsets)
Definition: unovwr.cxx:385
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo