LibreOffice Module sw (master)  1
acorrect.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 
22 #include <fmtinfmt.hxx>
23 #include <editsh.hxx>
24 #include <doc.hxx>
25 #include <pam.hxx>
26 #include <unocrsr.hxx>
27 #include <txatbase.hxx>
28 #include <txtfrm.hxx>
29 #include <ndtxt.hxx>
30 #include <acorrect.hxx>
31 #include <shellio.hxx>
32 #include <swundo.hxx>
33 #include <viscrs.hxx>
34 #include <com/sun/star/linguistic2/XHyphenator.hpp>
35 #include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
36 #include <osl/diagnose.h>
37 #include <svl/numformat.hxx>
38 #include <svl/zforlist.hxx>
39 
40 #include <editeng/acorrcfg.hxx>
42 #include <rootfrm.hxx>
43 
44 using namespace ::com::sun::star;
45 
46 namespace {
47 
48 class PaMIntoCursorShellRing
49 {
50  SwPaM &m_rDelPam, &m_rCursor;
51  SwPaM* m_pPrevDelPam;
52  SwPaM* m_pPrevCursor;
53 
54  static void RemoveFromRing( SwPaM& rPam, SwPaM const * pPrev );
55 public:
56  PaMIntoCursorShellRing( SwCursorShell& rSh, SwPaM& rCursor, SwPaM& rPam );
57  ~PaMIntoCursorShellRing();
58 };
59 
60 }
61 
62 PaMIntoCursorShellRing::PaMIntoCursorShellRing(SwCursorShell& rCSh, SwPaM& rShCursor, SwPaM& rPam)
63  : m_rDelPam(rPam)
64  , m_rCursor(rShCursor)
65 {
66  SwPaM* pShCursor = rCSh.GetCursor_();
67 
68  m_pPrevDelPam = m_rDelPam.GetPrev();
69  m_pPrevCursor = m_rCursor.GetPrev();
70 
71  m_rDelPam.GetRingContainer().merge(pShCursor->GetRingContainer());
72  m_rCursor.GetRingContainer().merge(pShCursor->GetRingContainer());
73 }
74 
75 PaMIntoCursorShellRing::~PaMIntoCursorShellRing()
76 {
77  // and take out the Pam again:
78  RemoveFromRing(m_rDelPam, m_pPrevDelPam);
79  RemoveFromRing(m_rCursor, m_pPrevCursor);
80 }
81 
82 void PaMIntoCursorShellRing::RemoveFromRing( SwPaM& rPam, SwPaM const * pPrev )
83 {
84  SwPaM* p;
85  SwPaM* pNext = &rPam;
86  do {
87  p = pNext;
88  pNext = p->GetNext();
89  p->MoveTo( &rPam );
90  } while( p != pPrev );
91 }
92 
94  sal_Unicode cIns )
95  : m_rEditSh( rEditShell ), m_rCursor( rPam )
96  , m_nEndUndoCounter(0)
97  , m_bUndoIdInitialized( cIns == 0 )
98 {
99 }
100 
102 {
103  for (int i = 0; i < m_nEndUndoCounter; ++i)
104  {
105  m_rEditSh.EndUndo();
106  }
107 }
108 
110 {
111  // this should work with plain SwPaM as well because start and end
112  // are always in same node, but since there is GetRanges already...
113  std::vector<std::shared_ptr<SwUnoCursor>> ranges;
114  if (sw::GetRanges(ranges, *m_rEditSh.GetDoc(), rDelPam))
115  {
116  DeleteSelImpl(rDelPam);
117  }
118  else
119  {
120  for (auto const& pCursor : ranges)
121  {
122  DeleteSelImpl(*pCursor);
123  }
124  }
125 }
126 
128 {
129  SwDoc* pDoc = m_rEditSh.GetDoc();
130  if( pDoc->IsAutoFormatRedline() )
131  {
132  // so that also the DelPam be moved, include it in the
133  // Shell-Cursr-Ring !!
134  // ??? is that really necessary - this should never join nodes, so Update should be enough?
135 // PaMIntoCursorShellRing aTmp( rEditSh, rCursor, rDelPam );
136  assert(rDelPam.GetPoint()->nNode == rDelPam.GetMark()->nNode);
137  pDoc->getIDocumentContentOperations().DeleteAndJoin( rDelPam );
138  }
139  else
140  {
141  pDoc->getIDocumentContentOperations().DeleteRange( rDelPam );
142  }
143 }
144 
145 bool SwAutoCorrDoc::Delete( sal_Int32 nStt, sal_Int32 nEnd )
146 {
147  SwTextNode const*const pTextNd = m_rCursor.GetNode().GetTextNode();
148  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
149  pTextNd->getLayoutFrame(m_rEditSh.GetLayout())));
150  assert(pFrame);
151  SwPaM aSel(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
152  pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
153  DeleteSel( aSel );
154 
156  m_bUndoIdInitialized = true;
157  return true;
158 }
159 
160 bool SwAutoCorrDoc::Insert( sal_Int32 nPos, const OUString& rText )
161 {
162  SwTextNode const*const pTextNd = m_rCursor.GetNode().GetTextNode();
163  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
164  pTextNd->getLayoutFrame(m_rEditSh.GetLayout())));
165  assert(pFrame);
166  SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nPos)));
168  if( !m_bUndoIdInitialized )
169  {
170  m_bUndoIdInitialized = true;
171  if( 1 == rText.getLength() )
172  {
175  }
176  }
177  return true;
178 }
179 
180 bool SwAutoCorrDoc::Replace( sal_Int32 nPos, const OUString& rText )
181 {
182  return ReplaceRange( nPos, rText.getLength(), rText );
183 }
184 
185 bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const OUString& rText )
186 {
187  assert(nSourceLength == 1); // sw_redlinehide: this is currently the case,
188  // and ensures that the replace range cannot *contain* delete redlines,
189  // so we don't need something along the lines of:
190  // if (sw::GetRanges(ranges, *rEditSh.GetDoc(), aPam))
191  // ReplaceImpl(...)
192  // else
193  // ReplaceImpl(ranges.begin())
194  // for (ranges.begin() + 1; ranges.end(); )
195  // DeleteImpl(*it)
196 
197  SwTextNode * const pNd = m_rCursor.GetNode().GetTextNode();
198  if ( !pNd )
199  {
200  return false;
201  }
202 
203  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
205  assert(pFrame);
206  std::pair<SwTextNode *, sal_Int32> const pos(pFrame->MapViewToModel(TextFrameIndex(nPos)));
207 
208  SwPaM* pPam = &m_rCursor;
209  if (pPam->GetPoint()->nNode != *pos.first
210  || pPam->GetPoint()->nContent != pos.second)
211  {
212  pPam = new SwPaM(*pos.first, pos.second);
213  }
214 
215  // text attributes with dummy characters must not be replaced!
216  bool bDoReplace = true;
217  sal_Int32 const nLen = rText.getLength();
218  for (sal_Int32 n = 0; n < nLen && n + nPos < pFrame->GetText().getLength(); ++n)
219  {
220  sal_Unicode const Char = pFrame->GetText()[n + nPos];
221  if (CH_TXTATR_BREAKWORD == Char || CH_TXTATR_INWORD == Char)
222  {
223  assert(pFrame->MapViewToModel(TextFrameIndex(n+nPos)).first->GetTextAttrForCharAt(pFrame->MapViewToModel(TextFrameIndex(n+nPos)).second));
224  bDoReplace = false;
225  break;
226  }
227  }
228 
229  // tdf#83419 avoid bad autocorrect with visible redlines
230  // e.g. replacing the first letter of the tracked deletion
231  // with its capitalized (and not deleted) version.
232  if ( bDoReplace && !pFrame->getRootFrame()->IsHideRedlines() &&
233  m_rEditSh.GetDoc()->getIDocumentRedlineAccess().HasRedline( *pPam, RedlineType::Delete, /*bStartOrEndInRange=*/false ) )
234  {
235  bDoReplace = false;
236  }
237 
238  if ( bDoReplace )
239  {
240  SwDoc* pDoc = m_rEditSh.GetDoc();
241 
242  if( pDoc->IsAutoFormatRedline() )
243  {
244  if (nPos == pFrame->GetText().getLength()) // at the End do an Insert
245  {
246  pDoc->getIDocumentContentOperations().InsertString( *pPam, rText );
247  }
248  else
249  {
250  assert(pos.second != pos.first->Len()); // must be _before_ char
251  PaMIntoCursorShellRing aTmp( m_rEditSh, m_rCursor, *pPam );
252 
253  pPam->SetMark();
254  pPam->GetPoint()->nContent = std::min<sal_Int32>(
255  pos.first->GetText().getLength(), pos.second + nSourceLength);
256  pDoc->getIDocumentContentOperations().ReplaceRange( *pPam, rText, false );
257  pPam->Exchange();
258  pPam->DeleteMark();
259  }
260  }
261  else
262  {
263  pPam->SetMark();
264  pPam->GetPoint()->nContent = std::min<sal_Int32>(
265  pos.first->GetText().getLength(), pos.second + nSourceLength);
266  pDoc->getIDocumentContentOperations().ReplaceRange( *pPam, rText, false );
267  pPam->Exchange();
268  pPam->DeleteMark();
269  }
270 
272  {
273  m_bUndoIdInitialized = true;
274  if( 1 == rText.getLength() )
275  {
278  }
279  }
280  }
281 
282  if( pPam != &m_rCursor )
283  delete pPam;
284 
285  return true;
286 }
287 
288 void SwAutoCorrDoc::SetAttr( sal_Int32 nStt, sal_Int32 nEnd, sal_uInt16 nSlotId,
289  SfxPoolItem& rItem )
290 {
291  SwTextNode const*const pTextNd = m_rCursor.GetNode().GetTextNode();
292  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
293  pTextNd->getLayoutFrame(m_rEditSh.GetLayout())));
294  assert(pFrame);
295  SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
296  pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
297 
298  SfxItemPool& rPool = m_rEditSh.GetDoc()->GetAttrPool();
299  sal_uInt16 nWhich = rPool.GetWhich( nSlotId, false );
300  if( nWhich )
301  {
302  rItem.SetWhich( nWhich );
303 
304  SfxItemSet aSet( rPool, aCharFormatSetRange );
305  SetAllScriptItem( aSet, rItem );
306 
307  m_rEditSh.GetDoc()->SetFormatItemByAutoFormat( aPam, aSet );
308 
310  m_bUndoIdInitialized = true;
311  }
312 }
313 
314 bool SwAutoCorrDoc::SetINetAttr( sal_Int32 nStt, sal_Int32 nEnd, const OUString& rURL )
315 {
316  SwTextNode const*const pTextNd = m_rCursor.GetNode().GetTextNode();
317  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
318  pTextNd->getLayoutFrame(m_rEditSh.GetLayout())));
319  assert(pFrame);
320  SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
321  pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
322 
324  svl::Items<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> );
325  aSet.Put( SwFormatINetFormat( rURL, OUString() ));
326  m_rEditSh.GetDoc()->SetFormatItemByAutoFormat( aPam, aSet );
328  m_bUndoIdInitialized = true;
329  return true;
330 }
331 
338 OUString const* SwAutoCorrDoc::GetPrevPara(bool const bAtNormalPos)
339 {
340  OUString const* pStr(nullptr);
341 
342  if( bAtNormalPos || !m_pIndex )
343  {
345  }
347 
348  SwTextFrame const* pFrame(nullptr);
349  for (SwTextNode * pTextNd = m_pIndex->GetNode().GetTextNode();
350  pTextNd; pTextNd = m_pIndex->GetNode().GetTextNode())
351  {
352  pFrame = static_cast<SwTextFrame const*>(
353  pTextNd->getLayoutFrame(m_rEditSh.GetLayout()));
354  if (pFrame && !pFrame->GetText().isEmpty())
355  {
356  break;
357  }
359  }
360  if (pFrame && 0 == pFrame->GetTextNodeForParaProps()->GetAttrOutlineLevel())
361  pStr = & pFrame->GetText();
362 
364  m_bUndoIdInitialized = true;
365 
366  return pStr;
367 }
368 
369 bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
370  SvxAutoCorrect& rACorrect,
371  OUString* pPara )
372 {
374  m_bUndoIdInitialized = true;
375 
376  // Found a beginning of a paragraph or a Blank,
377  // search for the word Kuerzel (Shortcut) in the Auto
378  SwTextNode* pTextNd = m_rCursor.GetNode().GetTextNode();
379  OSL_ENSURE( pTextNd, "where is the TextNode?" );
380 
381  bool bRet = false;
382  if( nEndPos == rSttPos )
383  return bRet;
384 
385  LanguageType eLang = GetLanguage(nEndPos);
386  if(LANGUAGE_SYSTEM == eLang)
387  eLang = GetAppLanguage();
388  LanguageTag aLanguageTag( eLang);
389 
390  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
391  pTextNd->getLayoutFrame(m_rEditSh.GetLayout())));
392  assert(pFrame);
393 
394  const OUString sFrameText = pFrame->GetText();
395  const SvxAutocorrWord* pFnd = rACorrect.SearchWordsInList(
396  sFrameText, rSttPos, nEndPos, *this, aLanguageTag);
397  SwDoc* pDoc = m_rEditSh.GetDoc();
398  if( pFnd )
399  {
400  // replace also last colon of keywords surrounded by colons (for example, ":name:")
401  const bool replaceLastChar = sFrameText.getLength() > nEndPos && pFnd->GetShort()[0] == ':'
402  && pFnd->GetShort().endsWith(":");
403 
404  SwPosition aStartPos( pFrame->MapViewToModelPos(TextFrameIndex(rSttPos) ));
405  SwPosition aEndPos( pFrame->MapViewToModelPos(TextFrameIndex(nEndPos + (replaceLastChar ? 1 : 0))) );
406  SwPaM aPam(aStartPos, aEndPos);
407 
408  // don't replace, if a redline starts or ends within the original text
409  if ( pDoc->getIDocumentRedlineAccess().HasRedline( aPam, RedlineType::Any, /*bStartOrEndInRange=*/true ) )
410  {
411  return bRet;
412  }
413 
414  if( pFnd->IsTextOnly() )
415  {
416  //JP 22.04.99: Bug 63883 - Special treatment for dots.
417  const bool bLastCharIsPoint
418  = nEndPos < sFrameText.getLength() && ('.' == sFrameText[nEndPos]);
419  if( !bLastCharIsPoint || pFnd->GetLong().isEmpty() ||
420  '.' != pFnd->GetLong()[ pFnd->GetLong().getLength() - 1 ] )
421  {
422  // replace the selection
423  std::vector<std::shared_ptr<SwUnoCursor>> ranges;
424  if (sw::GetRanges(ranges, *m_rEditSh.GetDoc(), aPam))
425  {
426  pDoc->getIDocumentContentOperations().ReplaceRange(aPam, pFnd->GetLong(), false);
427  bRet = true;
428  }
429  else if (!ranges.empty())
430  {
431  assert(ranges.front()->GetPoint()->nNode == ranges.front()->GetMark()->nNode);
433  *ranges.front(), pFnd->GetLong(), false);
434  for (auto it = ranges.begin() + 1; it != ranges.end(); ++it)
435  {
436  DeleteSelImpl(**it);
437  }
438  bRet = true;
439  }
440 
441  // tdf#83260 After calling sw::DocumentContentOperationsManager::ReplaceRange
442  // pTextNd may become invalid when change tracking is on and Edit -> Track Changes -> Show == OFF.
443  // ReplaceRange shows changes, this moves deleted nodes from special section to document.
444  // Then Show mode is disabled again. As a result pTextNd may be invalidated.
445  pTextNd = m_rCursor.GetNode().GetTextNode();
446  }
447  }
448  else
449  {
450  SwTextBlocks aTBlks( rACorrect.GetAutoCorrFileName( aLanguageTag, false, true ));
451  sal_uInt16 nPos = aTBlks.GetIndex( pFnd->GetShort() );
452  if( USHRT_MAX != nPos && aTBlks.BeginGetDoc( nPos ) )
453  {
454  DeleteSel( aPam );
455  pDoc->DontExpandFormat( *aPam.GetPoint() );
456 
457  if( pPara )
458  {
459  OSL_ENSURE( !m_pIndex, "who has not deleted his Index?" );
460  m_pIndex.reset(new SwNodeIndex( m_rCursor.GetPoint()->nNode ));
462  }
463 
464  SwDoc* pAutoDoc = aTBlks.GetDoc();
465  SwNodeIndex aSttIdx( pAutoDoc->GetNodes().GetEndOfExtras(), 1 );
466  SwContentNode* pContentNd = pAutoDoc->GetNodes().GoNext( &aSttIdx );
467  SwPaM aCpyPam( aSttIdx );
468 
469  const SwTableNode* pTableNd = pContentNd->FindTableNode();
470  if( pTableNd )
471  {
472  aCpyPam.GetPoint()->nContent.Assign( nullptr, 0 );
473  aCpyPam.GetPoint()->nNode = *pTableNd;
474  }
475  aCpyPam.SetMark();
476 
477  // then until the end of the Nodes Array
478  aCpyPam.GetPoint()->nNode.Assign( pAutoDoc->GetNodes().GetEndOfContent(), -1 );
479  pContentNd = aCpyPam.GetContentNode();
480  aCpyPam.GetPoint()->nContent.Assign(
481  pContentNd, pContentNd ? pContentNd->Len() : 0);
482 
483  SwDontExpandItem aExpItem;
484  aExpItem.SaveDontExpandItems( *aPam.GetPoint() );
485 
487 
488  aExpItem.RestoreDontExpandItems( *aPam.GetPoint() );
489 
490  if( pPara )
491  {
493  pTextNd = m_pIndex->GetNode().GetTextNode();
494  }
495  bRet = true;
496  }
497  aTBlks.EndGetDoc();
498  }
499  }
500 
501  if( bRet && pPara && pTextNd )
502  {
503  SwTextFrame const*const pNewFrame(static_cast<SwTextFrame const*>(
504  pTextNd->getLayoutFrame(m_rEditSh.GetLayout())));
505  *pPara = pNewFrame->GetText();
506  }
507 
508  return bRet;
509 }
510 
511 bool SwAutoCorrDoc::TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos, bool bApply )
512 {
514  m_bUndoIdInitialized = true;
515 
516  SwTextNode* pTextNd = m_rCursor.GetNode().GetTextNode();
517  OSL_ENSURE( pTextNd, "where is the TextNode?" );
518 
519  bool bRet = false;
520  if( nEndPos == rSttPos )
521  return bRet;
522 
523  LanguageType eLang = GetLanguage(nEndPos);
524  if(LANGUAGE_SYSTEM == eLang)
525  eLang = GetAppLanguage();
526  LanguageTag aLanguageTag(eLang);
527 
528  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
529  pTextNd->getLayoutFrame(m_rEditSh.GetLayout())));
530  assert(pFrame);
531 
532  const OUString sFrameText = pFrame->GetText();
533  SwDoc* pDoc = m_rEditSh.GetDoc();
534  if ( pFrame->IsRightToLeft() || bApply )
535  {
536  // transliterate to Old Hungarian using Numbertext via NatNum12 number format modifier
537  OUString sWord(sFrameText.copy(rSttPos, nEndPos - rSttPos));
538  // Consonant disambiguation using hyphenation
539  uno::Reference< linguistic2::XHyphenator > xHyph;
540  xHyph = ::GetHyphenator();
541  OUStringBuffer sDisambiguatedWord;
542 
543  const ::css::uno::Sequence< ::css::beans::PropertyValue > aProperties;
544  css::uno::Reference< css::linguistic2::XHyphenatedWord > xHyphWord;
545  for (int i = 0; i+1 < sWord.getLength(); i++ )
546  {
547  xHyphWord = xHyph->hyphenate( sWord,
548  aLanguageTag.getLocale(),
549  i,
550  aProperties );
551  // insert ZWSP at a hyphenation point, if it's not an alternative one (i.e. ssz->sz-sz)
552  if (xHyphWord.is() && xHyphWord->getHyphenationPos()+1 == i && !xHyphWord->isAlternativeSpelling())
553  {
554  sDisambiguatedWord.append(CHAR_ZWSP);
555  }
556  sDisambiguatedWord.append(sWord[i]);
557  }
558  sDisambiguatedWord.append(sWord[sWord.getLength()-1]);
559 
560  SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
561  OUString sConverted;
562  if (pFormatter && !sWord.isEmpty())
563  {
564  const Color* pColor = nullptr;
565  // Send text as NatNum12 prefix
566  OUString sPrefix("[NatNum12 " + sDisambiguatedWord.makeStringAndClear() + "]0");
567  if (pFormatter->GetPreviewString(sPrefix, 0, sConverted, &pColor, LANGUAGE_USER_HUNGARIAN_ROVAS))
568  bRet = true;
569  }
570 
571  SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(rSttPos)),
572  pFrame->MapViewToModelPos(TextFrameIndex(nEndPos)));
573  if (bRet && nEndPos <= sFrameText.getLength())
574  pDoc->getIDocumentContentOperations().ReplaceRange(aPam, sConverted, false);
575  }
576 
577  return bRet;
578 }
579 
580 // Called by the functions:
581 // - FnCapitalStartWord
582 // - FnCapitalStartSentence
583 // after the exchange of characters. Then the words, if necessary, can be inserted
584 // into the exception list.
585 void SwAutoCorrDoc::SaveCpltSttWord( ACFlags nFlag, sal_Int32 nPos,
586  const OUString& rExceptWord,
587  sal_Unicode cChar )
588 {
589  sal_uLong nNode = m_pIndex ? m_pIndex->GetIndex() : m_rCursor.GetPoint()->nNode.GetIndex();
590  LanguageType eLang = GetLanguage(nPos);
591  m_rEditSh.GetDoc()->SetAutoCorrExceptWord( std::make_unique<SwAutoCorrExceptWord>( nFlag,
592  nNode, nPos, rExceptWord, cChar, eLang ));
593 }
594 
596 {
598 
600 
601  if( pNd )
602  {
603  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
605  assert(pFrame);
606  eRet = pFrame->GetLangOfChar(TextFrameIndex(nPos), 0, true);
607  }
608  if(LANGUAGE_SYSTEM == eRet)
609  eRet = GetAppLanguage();
610  return eRet;
611 }
612 
614 {
615  // test only if this is an improvement.
616  // If yes, then add the word to the list.
617  if (m_cChar == cChr && rPos.nNode.GetIndex() == m_nNode && rPos.nContent.GetIndex() == m_nContent)
618  {
619  // get the current autocorrection:
621 
622  // then add to the list:
623  if (ACFlags::CapitalStartWord & m_nFlags)
625  else if (ACFlags::CapitalStartSentence & m_nFlags)
627  }
628 }
629 
631 {
632  bool bRet = false;
633  if (!m_bDeleted && rPos.nNode.GetIndex() == m_nNode && rPos.nContent.GetIndex() == m_nContent)
634  m_bDeleted = bRet = true;
635  return bRet;
636 }
637 
639 {
640 }
641 
643 {
644  const SwTextNode* pTextNd = rPos.nNode.GetNode().GetTextNode();
645  if( pTextNd )
646  {
647  m_pDontExpandItems.reset( new SfxItemSet( const_cast<SwDoc&>(pTextNd->GetDoc()).GetAttrPool(),
649  const sal_Int32 n = rPos.nContent.GetIndex();
650  if (!pTextNd->GetParaAttr( *m_pDontExpandItems, n, n,
651  n != pTextNd->GetText().getLength() ))
652  {
653  m_pDontExpandItems.reset();
654  }
655  }
656 }
657 
659 {
660  SwTextNode* pTextNd = rPos.nNode.GetNode().GetTextNode();
661  if( !pTextNd )
662  return;
663 
664  const sal_Int32 nStart = rPos.nContent.GetIndex();
665  if( nStart == pTextNd->GetText().getLength() )
666  pTextNd->FormatToTextAttr( pTextNd );
667 
668  if( !(pTextNd->GetpSwpHints() && pTextNd->GetpSwpHints()->Count()) )
669  return;
670 
671  const size_t nSize = pTextNd->GetpSwpHints()->Count();
672  sal_Int32 nAttrStart;
673 
674  for( size_t n = 0; n < nSize; ++n )
675  {
676  SwTextAttr* pHt = pTextNd->GetpSwpHints()->Get( n );
677  nAttrStart = pHt->GetStart();
678  if( nAttrStart > nStart ) // beyond the area
679  break;
680 
681  const sal_Int32* pAttrEnd;
682  if( nullptr != ( pAttrEnd = pHt->End() ) &&
683  ( ( nAttrStart < nStart &&
684  ( pHt->DontExpand() ? nStart < *pAttrEnd
685  : nStart <= *pAttrEnd )) ||
686  ( nStart == nAttrStart &&
687  ( nAttrStart == *pAttrEnd || !nStart ))) )
688  {
689  const SfxPoolItem* pItem;
690  if( !m_pDontExpandItems || SfxItemState::SET != m_pDontExpandItems->
691  GetItemState( pHt->Which(), false, &pItem ) ||
692  *pItem != pHt->GetAttr() )
693  {
694  // The attribute was not previously set in this form in the
695  // paragraph, so it can only be created through insert/copy
696  // Because of that it is a candidate for DontExpand
697  pHt->SetDontExpand( true );
698  }
699  }
700  }
701 }
702 
703 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool ReplaceRange(sal_Int32 nPos, sal_Int32 nLen, const OUString &rText) override
Definition: acorrect.cxx:185
void merge(RingContainer< value_type > aDestRing)
Merges two ring containers.
Definition: ring.hxx:182
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:158
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
void SetDontExpand(bool bDontExpand)
Definition: txatbase.hxx:175
static SvxAutoCorrCfg & Get()
bool GetRanges(std::vector< std::shared_ptr< SwUnoCursor >> &rRanges, SwDoc &rDoc, SwPaM const &rDelPam)
Definition: autofmt.cxx:1117
Marks a position in the document model.
Definition: pam.hxx:35
virtual bool HasRedline(const SwPaM &rPam, RedlineType nType, bool bStartOrEndInRange) const =0
const OUString & GetText() const
Definition: ndtxt.hxx:215
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:223
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1411
SwNodeIndex nNode
Definition: pam.hxx:37
sal_uIntPtr sal_uLong
virtual bool SetINetAttr(sal_Int32 nStt, sal_Int32 nEnd, const OUString &rURL) override
Definition: acorrect.cxx:314
const SwPosition * GetMark() const
Definition: pam.hxx:209
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1213
sal_Int64 n
Definition: doc.hxx:188
const SvxAutocorrWord * SearchWordsInList(const OUString &rTxt, sal_Int32 &rStt, sal_Int32 nEndPos, SvxAutoCorrDoc &rDoc, LanguageTag &rLang)
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
virtual void DeleteRange(SwPaM &)=0
Delete a range SwFlyFrameFormat.
SwNode & GetNode() const
Definition: ndindex.hxx:119
bool m_bUndoIdInitialized
Definition: acorrect.hxx:54
sal_uInt16 Which() const
Definition: txatbase.hxx:114
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1295
virtual bool DeleteAndJoin(SwPaM &, const bool bForceJoinNext=false)=0
complete delete of a given PaM
SwShellCursor * GetPrev()
Definition: viscrs.hxx:166
bool AddCplSttException(const OUString &rNew, LanguageType eLang)
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
const OUString & GetShort() const
virtual ~SwAutoCorrDoc() override
Definition: acorrect.cxx:101
void MoveTo(value_type *pDestRing)
Removes this item from its current ring container and adds it to another ring container.
Definition: ring.hxx:135
virtual void SaveCpltSttWord(ACFlags nFlag, sal_Int32 nPos, const OUString &rExceptWord, sal_Unicode cChar) override
Definition: acorrect.cxx:585
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
bool IsTextOnly() const
OUString GetAutoCorrFileName(const LanguageTag &rLanguageTag, bool bNewFile=false, bool bTstUserExist=false, bool bUnlocalized=false) const
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:229
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:170
void DeleteSel(SwPaM &rDelPam)
Definition: acorrect.cxx:109
sal_uInt16 sal_Unicode
#define CH_TXTATR_INWORD
Definition: hintids.hxx:171
LanguageType m_eLanguage
Definition: acorrect.hxx:102
ACFlags
PropertiesInfo aProperties
int m_nEndUndoCounter
Definition: acorrect.hxx:53
SwIndex nContent
Definition: pam.hxx:38
size_t pos
void RestoreDontExpandItems(const SwPosition &rPos)
Definition: acorrect.cxx:658
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
check if target position is in fly anchored at source range
void SetAllScriptItem(SfxItemSet &rSet, const SfxPoolItem &rItem)
Definition: poolfmt.cxx:41
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
void SetFormatItemByAutoFormat(const SwPaM &rPam, const SfxItemSet &)
Definition: docfmt.cxx:1824
void SaveDontExpandItems(const SwPosition &rPos)
Definition: acorrect.cxx:642
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
void GotoNextLayoutTextFrame(SwNodeIndex &rIndex, SwRootFrame const *const pLayout)
Definition: docnum.cxx:1472
std::unique_ptr< SwNodeIndex > m_pIndex
Definition: acorrect.hxx:52
SwPaM * GetNext()
Definition: pam.hxx:264
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:163
SwEditShell & m_rEditSh
Definition: acorrect.hxx:50
SwShellCursor * GetCursor_()
Definition: crsrsh.hxx:328
virtual bool Insert(sal_Int32 nPos, const OUString &rText) override
Definition: acorrect.cxx:160
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual bool InsertString(const SwPaM &rRg, const OUString &, const SwInsertFlags nInsertMode=SwInsertFlags::EMPTYEXPAND)=0
Insert string into existing text node at position rRg.Point().
size_t Count() const
Definition: ndhints.hxx:142
#define LANGUAGE_USER_HUNGARIAN_ROVAS
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
int i
SwDoc & GetDoc()
Definition: node.hxx:212
const SwPosition * GetPoint() const
Definition: pam.hxx:207
virtual bool CopyRange(SwPaM &rPam, SwPosition &rPos, SwCopyFlags flags) const =0
Copy a selected content range to a position.
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
#define LANGUAGE_SYSTEM
bool GetParaAttr(SfxItemSet &rSet, sal_Int32 nStt, sal_Int32 nEnd, const bool bOnlyTextAttr=false, const bool bGetFromChrFormat=true, const bool bMergeIndentValuesOfNumRule=false, SwRootFrame const *pLayout=nullptr) const
Query the attributes of textnode over the range.
Definition: thints.cxx:2055
WhichRangesContainer const aCharFormatSetRange(svl::Items< RES_CHRATR_BEGIN, RES_CHRATR_END-1, RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1 >)
SvxAutoCorrect * GetAutoCorrect()
void DeleteSelImpl(SwPaM &rDelPam)
Definition: acorrect.cxx:127
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
sal_Unicode m_cChar
Definition: acorrect.hxx:101
#define CHAR_ZWSP
Definition: swtypes.hxx:167
Marks a node in the document model.
Definition: ndindex.hxx:31
virtual bool ReplaceRange(SwPaM &rPam, const OUString &rNewStr, const bool bRegExReplace)=0
Replace selected range in a TextNode with string.
ring_container GetRingContainer()
Definition: ring.hxx:240
void CheckChar(const SwPosition &rPos, sal_Unicode cChar)
Definition: acorrect.cxx:613
OUString sPrefix
bool AddWrtSttException(const OUString &rNew, LanguageType eLang)
void SetAutoCorrExceptWord(std::unique_ptr< SwAutoCorrExceptWord > pNew)
Definition: docedt.cxx:830
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:335
virtual OUString const * GetPrevPara(bool bAtNormalPos) override
Return the text of a previous paragraph.
Definition: acorrect.cxx:338
virtual bool TransliterateRTLWord(sal_Int32 &rSttPos, sal_Int32 nEndPos, bool bApply=false) override
Definition: acorrect.cxx:511
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual LanguageType GetLanguage(sal_Int32 nPos) const override
Definition: acorrect.cxx:595
sal_Int32 m_nContent
Definition: acorrect.hxx:100
bool CheckDelChar(const SwPosition &rPos)
Definition: acorrect.cxx:630
bool DontExpandFormat(const SwPosition &rPos, bool bFlag=true)
Definition: docfmt.cxx:1707
void SetWhich(sal_uInt16 nId)
sal_Int32 GetIndex() const
Definition: index.hxx:91
LanguageType GetAppLanguage()
Definition: init.cxx:723
SwNodes & GetNodes()
Definition: doc.hxx:409
const sal_Int32 * End() const
Definition: txatbase.hxx:152
virtual bool ChgAutoCorrWord(sal_Int32 &rSttPos, sal_Int32 nEndPos, SvxAutoCorrect &rACorrect, OUString *pPara) override
Definition: acorrect.cxx:369
void * p
SwPaM & m_rCursor
Definition: acorrect.hxx:51
bool IsAutoFormatRedline() const
Definition: doc.hxx:1447
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:357
void GotoPrevLayoutTextFrame(SwNodeIndex &rIndex, SwRootFrame const *const pLayout)
Definition: docnum.cxx:1444
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:163
uno::Reference< linguistic2::XHyphenator > GetHyphenator()
Definition: swtypes.cxx:57
bool DontExpand() const
Definition: txatbase.hxx:96
virtual void SetAttr(sal_Int32 nStt, sal_Int32 nEnd, sal_uInt16 nSlotId, SfxPoolItem &) override
Definition: acorrect.cxx:288
virtual bool Delete(sal_Int32 nStt, sal_Int32 nEnd) override
Definition: acorrect.cxx:145
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:478
const OUString & GetLong() const
std::unique_ptr< SfxItemSet > m_pDontExpandItems
Definition: acorrect.hxx:37
void FormatToTextAttr(SwTextNode *pNd)
Convey attributes of an AttrSet (AutoFormat) to SwpHintsArray.
Definition: thints.cxx:2454
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:161
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2074
bool GetPreviewString(const OUString &sFormatString, double fPreviewNumber, OUString &sOutString, const Color **ppColor, LanguageType eLnge, bool bUseStarFormat=false)
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...
SwAutoCorrDoc(SwEditShell &rEditShell, SwPaM &rPam, sal_Unicode cIns=0)
Definition: acorrect.cxx:93
virtual bool Replace(sal_Int32 nPos, const OUString &rText) override
Definition: acorrect.cxx:180
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1293
sal_uInt16 nPos
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1319
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:850
SwNodeIndex & Assign(SwNodes const &rNds, sal_uLong)
Definition: ndindex.hxx:272