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