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