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