LibreOffice Module linguistic (master) 1
gciterator.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 <sal/macros.h>
21#include <com/sun/star/beans/XPropertySet.hpp>
22#include <com/sun/star/container/ElementExistException.hpp>
23#include <com/sun/star/container/XNameAccess.hpp>
24#include <com/sun/star/configuration/theDefaultProvider.hpp>
25#include <com/sun/star/i18n/BreakIterator.hpp>
26#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27#include <com/sun/star/lang/XComponent.hpp>
28#include <com/sun/star/lang/XServiceInfo.hpp>
29#include <com/sun/star/lang/XMultiServiceFactory.hpp>
30#include <com/sun/star/linguistic2/XSupportedLocales.hpp>
31#include <com/sun/star/linguistic2/XProofreader.hpp>
32#include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
33#include <com/sun/star/linguistic2/SingleProofreadingError.hpp>
34#include <com/sun/star/linguistic2/ProofreadingResult.hpp>
35#include <com/sun/star/linguistic2/LinguServiceEvent.hpp>
36#include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
37#include <com/sun/star/text/TextMarkupType.hpp>
38#include <com/sun/star/text/TextMarkupDescriptor.hpp>
39#include <com/sun/star/text/XMultiTextMarkup.hpp>
40#include <com/sun/star/text/XFlatParagraph.hpp>
41#include <com/sun/star/text/XFlatParagraphIterator.hpp>
42#include <com/sun/star/uno/XComponentContext.hpp>
43
44#include <sal/config.h>
45#include <sal/log.hxx>
46#include <o3tl/safeint.hxx>
47#include <osl/conditn.hxx>
49#include <cppuhelper/weak.hxx>
53#include <tools/debug.hxx>
55
56#include <map>
57
58#include <linguistic/misc.hxx>
59
60#include "gciterator.hxx"
61
62using namespace linguistic;
63using namespace ::com::sun::star;
64
65// white space list: obtained from the fonts.config.txt of a Linux system.
67{
68 0x0020, /* SPACE */
69 0x00a0, /* NO-BREAK SPACE */
70 0x00ad, /* SOFT HYPHEN */
71 0x115f, /* HANGUL CHOSEONG FILLER */
72 0x1160, /* HANGUL JUNGSEONG FILLER */
73 0x1680, /* OGHAM SPACE MARK */
74 0x2000, /* EN QUAD */
75 0x2001, /* EM QUAD */
76 0x2002, /* EN SPACE */
77 0x2003, /* EM SPACE */
78 0x2004, /* THREE-PER-EM SPACE */
79 0x2005, /* FOUR-PER-EM SPACE */
80 0x2006, /* SIX-PER-EM SPACE */
81 0x2007, /* FIGURE SPACE */
82 0x2008, /* PUNCTUATION SPACE */
83 0x2009, /* THIN SPACE */
84 0x200a, /* HAIR SPACE */
85 0x200b, /* ZERO WIDTH SPACE */
86 0x200c, /* ZERO WIDTH NON-JOINER */
87 0x200d, /* ZERO WIDTH JOINER */
88 0x200e, /* LEFT-TO-RIGHT MARK */
89 0x200f, /* RIGHT-TO-LEFT MARK */
90 0x2028, /* LINE SEPARATOR */
91 0x2029, /* PARAGRAPH SEPARATOR */
92 0x202a, /* LEFT-TO-RIGHT EMBEDDING */
93 0x202b, /* RIGHT-TO-LEFT EMBEDDING */
94 0x202c, /* POP DIRECTIONAL FORMATTING */
95 0x202d, /* LEFT-TO-RIGHT OVERRIDE */
96 0x202e, /* RIGHT-TO-LEFT OVERRIDE */
97 0x202f, /* NARROW NO-BREAK SPACE */
98 0x205f, /* MEDIUM MATHEMATICAL SPACE */
99 0x2060, /* WORD JOINER */
100 0x2061, /* FUNCTION APPLICATION */
101 0x2062, /* INVISIBLE TIMES */
102 0x2063, /* INVISIBLE SEPARATOR */
103 0x206A, /* INHIBIT SYMMETRIC SWAPPING */
104 0x206B, /* ACTIVATE SYMMETRIC SWAPPING */
105 0x206C, /* INHIBIT ARABIC FORM SHAPING */
106 0x206D, /* ACTIVATE ARABIC FORM SHAPING */
107 0x206E, /* NATIONAL DIGIT SHAPES */
108 0x206F, /* NOMINAL DIGIT SHAPES */
109 0x3000, /* IDEOGRAPHIC SPACE */
110 0x3164, /* HANGUL FILLER */
111 0xfeff, /* ZERO WIDTH NO-BREAK SPACE */
112 0xffa0, /* HALFWIDTH HANGUL FILLER */
113 0xfff9, /* INTERLINEAR ANNOTATION ANCHOR */
114 0xfffa, /* INTERLINEAR ANNOTATION SEPARATOR */
115 0xfffb /* INTERLINEAR ANNOTATION TERMINATOR */
116};
117
118// Information about reason for proofreading (ProofInfo)
119 const sal_Int32 PROOFINFO_GET_PROOFRESULT = 1;
120 const sal_Int32 PROOFINFO_MARK_PARAGRAPH = 2;
121
123
124static bool lcl_IsWhiteSpace( sal_Unicode cChar )
125{
126 bool bFound = false;
127 for (int i = 0; i < nWhiteSpaces && !bFound; ++i)
128 {
129 if (cChar == aWhiteSpaces[i])
130 bFound = true;
131 }
132 return bFound;
133}
134
135static sal_Int32 lcl_SkipWhiteSpaces( const OUString &rText, sal_Int32 nStartPos )
136{
137 // note having nStartPos point right behind the string is OK since that one
138 // is a correct end-of-sentence position to be returned from a grammar checker...
139
140 const sal_Int32 nLen = rText.getLength();
141 bool bIllegalArgument = false;
142 if (nStartPos < 0)
143 {
144 bIllegalArgument = true;
145 nStartPos = 0;
146 }
147 if (nStartPos > nLen)
148 {
149 bIllegalArgument = true;
150 nStartPos = nLen;
151 }
152 if (bIllegalArgument)
153 {
154 SAL_WARN( "linguistic", "lcl_SkipWhiteSpaces: illegal arguments" );
155 }
156
157 sal_Int32 nRes = nStartPos;
158 if (0 <= nStartPos && nStartPos < nLen)
159 {
160 const sal_Unicode* const pEnd = rText.getStr() + nLen;
161 const sal_Unicode *pText = rText.getStr() + nStartPos;
162 while (pText != pEnd && lcl_IsWhiteSpace(*pText))
163 ++pText;
164 nRes = pText - rText.getStr();
165 }
166
167 DBG_ASSERT( 0 <= nRes && nRes <= nLen, "lcl_SkipWhiteSpaces return value out of range" );
168 return nRes;
169}
170
171static sal_Int32 lcl_BacktraceWhiteSpaces( const OUString &rText, sal_Int32 nStartPos )
172{
173 // note: having nStartPos point right behind the string is OK since that one
174 // is a correct end-of-sentence position to be returned from a grammar checker...
175
176 const sal_Int32 nLen = rText.getLength();
177 bool bIllegalArgument = false;
178 if (nStartPos < 0)
179 {
180 bIllegalArgument = true;
181 nStartPos = 0;
182 }
183 if (nStartPos > nLen)
184 {
185 bIllegalArgument = true;
186 nStartPos = nLen;
187 }
188 if (bIllegalArgument)
189 {
190 SAL_WARN( "linguistic", "lcl_BacktraceWhiteSpaces: illegal arguments" );
191 }
192
193 sal_Int32 nRes = nStartPos;
194 sal_Int32 nPosBefore = nStartPos - 1;
195 const sal_Unicode *pStart = rText.getStr();
196 if (0 <= nPosBefore && nPosBefore < nLen && lcl_IsWhiteSpace( pStart[ nPosBefore ] ))
197 {
198 nStartPos = nPosBefore;
199 const sal_Unicode *pText = rText.getStr() + nStartPos;
200 while (pText > pStart && lcl_IsWhiteSpace( *pText ))
201 --pText;
202 // now add 1 since we want to point to the first char after the last char in the sentence...
203 nRes = pText - pStart + 1;
204 }
205
206 DBG_ASSERT( 0 <= nRes && nRes <= nLen, "lcl_BacktraceWhiteSpaces return value out of range" );
207 return nRes;
208}
209
210
211extern "C" {
212
213static void lcl_workerfunc (void * gci)
214{
215 osl_setThreadName("GrammarCheckingIterator");
216
217 static_cast<GrammarCheckingIterator*>(gci)->DequeueAndCheck();
218}
219
220}
221
223 const uno::Reference< text::XFlatParagraph >& xFlatPara,
224 sal_Int32 nStartIndex )
225{
226 //get the language of the first word
227 return xFlatPara->getLanguageOfText( nStartIndex, 1 );
228}
229
230
232
233void SAL_CALL LngXStringKeyMap::insertValue(const OUString& aKey, const css::uno::Any& aValue)
234{
235 std::map<OUString, css::uno::Any>::const_iterator aIter = maMap.find(aKey);
236 if (aIter != maMap.end())
237 throw css::container::ElementExistException();
238
239 maMap[aKey] = aValue;
240}
241
242css::uno::Any SAL_CALL LngXStringKeyMap::getValue(const OUString& aKey)
243{
244 std::map<OUString, css::uno::Any>::const_iterator aIter = maMap.find(aKey);
245 if (aIter == maMap.end())
246 throw css::container::NoSuchElementException();
247
248 return (*aIter).second;
249}
250
251sal_Bool SAL_CALL LngXStringKeyMap::hasValue(const OUString& aKey)
252{
253 return maMap.find(aKey) != maMap.end();
254}
255
256::sal_Int32 SAL_CALL LngXStringKeyMap::getCount() { return maMap.size(); }
257
258OUString SAL_CALL LngXStringKeyMap::getKeyByIndex(::sal_Int32 nIndex)
259{
260 if (nIndex < 0 || o3tl::make_unsigned(nIndex) >= maMap.size())
261 throw css::lang::IndexOutOfBoundsException();
262
263 return OUString();
264}
265
266css::uno::Any SAL_CALL LngXStringKeyMap::getValueByIndex(::sal_Int32 nIndex)
267{
268 if (nIndex < 0 || o3tl::make_unsigned(nIndex) >= maMap.size())
269 throw css::lang::IndexOutOfBoundsException();
270
271 return css::uno::Any();
272}
273
274
276{
277 static osl::Mutex SINGLETON;
278 return SINGLETON;
279}
280
282 m_bEnd( false ),
283 m_bGCServicesChecked( false ),
284 m_nDocIdCounter( 0 ),
285 m_thread(nullptr),
286 m_aEventListeners( MyMutex() ),
287 m_aNotifyListeners( MyMutex() )
288{
289}
290
291
293{
295}
296
298{
299 oslThread t;
300 {
301 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
302 t = m_thread;
303 m_thread = nullptr;
304 m_bEnd = true;
305 m_aWakeUpThread.set();
306 }
307 if (t != nullptr)
308 {
309 osl_joinWithThread(t);
310 osl_destroyThread(t);
311 }
312}
313
315{
316 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
317 m_nDocIdCounter += 1;
318 return m_nDocIdCounter;
319}
320
321
323 const uno::Reference< lang::XComponent > &xComponent )
324{
325 // internal method; will always be called with locked mutex
326
327 OUString aRes;
328 if (xComponent.is())
329 {
330 if (m_aDocIdMap.find( xComponent.get() ) != m_aDocIdMap.end())
331 {
332 // return already existing entry
333 aRes = m_aDocIdMap[ xComponent.get() ];
334 }
335 else // add new entry
336 {
337 sal_Int32 nRes = NextDocId();
338 aRes = OUString::number( nRes );
339 m_aDocIdMap[ xComponent.get() ] = aRes;
340 xComponent->addEventListener( this );
341 }
342 }
343 return aRes;
344}
345
346
348 const uno::Reference< text::XFlatParagraphIterator >& xFlatParaIterator,
349 const uno::Reference< text::XFlatParagraph >& xFlatPara,
350 const OUString & rDocId,
351 sal_Int32 nStartIndex,
352 bool bAutomatic )
353{
354 // we may not need/have a xFlatParaIterator (e.g. if checkGrammarAtPos was called)
355 // but we always need a xFlatPara...
356 if (!xFlatPara.is())
357 return;
358
359 FPEntry aNewFPEntry;
360 aNewFPEntry.m_xParaIterator = xFlatParaIterator;
361 aNewFPEntry.m_xPara = xFlatPara;
362 aNewFPEntry.m_aDocId = rDocId;
363 aNewFPEntry.m_nStartIndex = nStartIndex;
364 aNewFPEntry.m_bAutomatic = bAutomatic;
365
366 // add new entry to the end of this queue
367 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
368 if (!m_thread)
369 m_thread = osl_createThread( lcl_workerfunc, this );
370 m_aFPEntriesQueue.push_back( aNewFPEntry );
371
372 // wake up the thread in order to do grammar checking
373 m_aWakeUpThread.set();
374}
375
376
378 const linguistic2::ProofreadingResult &rRes,
379 const uno::Reference< text::XFlatParagraphIterator > &rxFlatParagraphIterator,
380 bool bIsAutomaticChecking )
381{
382 DBG_ASSERT( rRes.xFlatParagraph.is(), "xFlatParagraph is missing" );
383 //no guard necessary as no members are used
384 bool bContinueWithNextPara = false;
385 if (!rRes.xFlatParagraph.is() || rRes.xFlatParagraph->isModified())
386 {
387 // if paragraph was modified/deleted meanwhile continue with the next one...
388 bContinueWithNextPara = true;
389 }
390 else // paragraph is still unchanged...
391 {
392 // mark found errors...
393
394 sal_Int32 nTextLen = rRes.aText.getLength();
395 bool bBoundariesOk = 0 <= rRes.nStartOfSentencePosition && rRes.nStartOfSentencePosition <= nTextLen &&
396 0 <= rRes.nBehindEndOfSentencePosition && rRes.nBehindEndOfSentencePosition <= nTextLen &&
397 0 <= rRes.nStartOfNextSentencePosition && rRes.nStartOfNextSentencePosition <= nTextLen &&
398 rRes.nStartOfSentencePosition <= rRes.nBehindEndOfSentencePosition &&
399 rRes.nBehindEndOfSentencePosition <= rRes.nStartOfNextSentencePosition;
400 DBG_ASSERT( bBoundariesOk, "inconsistent sentence boundaries" );
401
402 uno::Reference< text::XMultiTextMarkup > xMulti( rRes.xFlatParagraph, uno::UNO_QUERY );
403 if (xMulti.is()) // use new API for markups
404 {
405 try
406 {
407 // length = number of found errors + 1 sentence markup
408 sal_Int32 nErrors = rRes.aErrors.getLength();
409 uno::Sequence< text::TextMarkupDescriptor > aDescriptors( nErrors + 1 );
410 text::TextMarkupDescriptor * pDescriptors = aDescriptors.getArray();
411
412 // at pos 0 .. nErrors-1 -> all grammar errors
413 for (const linguistic2::SingleProofreadingError &rError : rRes.aErrors)
414 {
415 text::TextMarkupDescriptor &rDesc = *pDescriptors++;
416
417 rDesc.nType = rError.nErrorType;
418 rDesc.nOffset = rError.nErrorStart;
419 rDesc.nLength = rError.nErrorLength;
420
421 // the proofreader may return SPELLING but right now our core
422 // does only handle PROOFREADING if the result is from the proofreader...
423 // (later on we may wish to color spelling errors found by the proofreader
424 // differently for example. But no special handling right now.
425 if (rDesc.nType == text::TextMarkupType::SPELLCHECK)
426 rDesc.nType = text::TextMarkupType::PROOFREADING;
427
428 uno::Reference< container::XStringKeyMap > xKeyMap(
429 new LngXStringKeyMap());
430 for( const beans::PropertyValue& rProperty : rError.aProperties )
431 {
432 if ( rProperty.Name == "LineColor" )
433 {
434 xKeyMap->insertValue(rProperty.Name,
435 rProperty.Value);
436 rDesc.xMarkupInfoContainer = xKeyMap;
437 }
438 else if ( rProperty.Name == "LineType" )
439 {
440 xKeyMap->insertValue(rProperty.Name,
441 rProperty.Value);
442 rDesc.xMarkupInfoContainer = xKeyMap;
443 }
444 }
445 }
446
447 // at pos nErrors -> sentence markup
448 // nSentenceLength: includes the white-spaces following the sentence end...
449 const sal_Int32 nSentenceLength = rRes.nStartOfNextSentencePosition - rRes.nStartOfSentencePosition;
450 pDescriptors->nType = text::TextMarkupType::SENTENCE;
451 pDescriptors->nOffset = rRes.nStartOfSentencePosition;
452 pDescriptors->nLength = nSentenceLength;
453
454 xMulti->commitMultiTextMarkup( aDescriptors ) ;
455 }
456 catch (lang::IllegalArgumentException &)
457 {
458 TOOLS_WARN_EXCEPTION( "linguistic", "commitMultiTextMarkup" );
459 }
460 }
461
462 // other sentences left to be checked in this paragraph?
463 if (rRes.nStartOfNextSentencePosition < rRes.aText.getLength())
464 {
465 AddEntry( rxFlatParagraphIterator, rRes.xFlatParagraph, rRes.aDocumentIdentifier, rRes.nStartOfNextSentencePosition, bIsAutomaticChecking );
466 }
467 else // current paragraph finished
468 {
469 // set "already checked" flag for the current flat paragraph
470 if (rRes.xFlatParagraph.is())
471 rRes.xFlatParagraph->setChecked( text::TextMarkupType::PROOFREADING, true );
472
473 bContinueWithNextPara = true;
474 }
475 }
476
477 if (bContinueWithNextPara)
478 {
479 // we need to continue with the next paragraph
480 if (rxFlatParagraphIterator.is())
481 AddEntry(rxFlatParagraphIterator, rxFlatParagraphIterator->getNextPara(),
482 rRes.aDocumentIdentifier, 0, bIsAutomaticChecking);
483 }
484}
485
486
487std::pair<OUString, std::optional<OUString>>
488GrammarCheckingIterator::getServiceForLocale(const lang::Locale& rLocale) const
489{
490 if (!rLocale.Language.isEmpty())
491 {
492 const OUString sBcp47 = LanguageTag::convertToBcp47(rLocale, false);
493 GCImplNames_t::const_iterator aLangIt(m_aGCImplNamesByLang.find(sBcp47));
494 if (aLangIt != m_aGCImplNamesByLang.end())
495 return { aLangIt->second, {} };
496
497 for (const auto& sFallbackBcp47 : LanguageTag(rLocale).getFallbackStrings(false))
498 {
499 aLangIt = m_aGCImplNamesByLang.find(sFallbackBcp47);
500 if (aLangIt != m_aGCImplNamesByLang.end())
501 return { aLangIt->second, sFallbackBcp47 };
502 }
503 }
504
505 return {};
506}
507
508
509uno::Reference< linguistic2::XProofreader > GrammarCheckingIterator::GetGrammarChecker(
510 lang::Locale &rLocale )
511{
512 uno::Reference< linguistic2::XProofreader > xRes;
513
514 // ---- THREAD SAFE START ----
515 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
516
517 // check supported locales for each grammarchecker if not already done
519 {
522 }
523
524 if (const auto& [aSvcImplName, oFallbackBcp47] = getServiceForLocale(rLocale);
525 !aSvcImplName.isEmpty()) // matching configured language found?
526 {
527 if (oFallbackBcp47)
528 rLocale = LanguageTag::convertToLocale(*oFallbackBcp47, false);
529 GCReferences_t::const_iterator aImplNameIt( m_aGCReferencesByService.find( aSvcImplName ) );
530 if (aImplNameIt != m_aGCReferencesByService.end()) // matching impl name found?
531 {
532 xRes = aImplNameIt->second;
533 }
534 else // the service is to be instantiated here for the first time...
535 {
536 try
537 {
538 uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
539 uno::Reference< linguistic2::XProofreader > xGC(
540 xContext->getServiceManager()->createInstanceWithContext(aSvcImplName, xContext),
541 uno::UNO_QUERY_THROW );
542 uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xGC, uno::UNO_QUERY_THROW );
543
544 if (xSuppLoc->hasLocale( rLocale ))
545 {
546 m_aGCReferencesByService[ aSvcImplName ] = xGC;
547 xRes = xGC;
548
549 uno::Reference< linguistic2::XLinguServiceEventBroadcaster > xBC( xGC, uno::UNO_QUERY );
550 if (xBC.is())
551 xBC->addLinguServiceEventListener( this );
552 }
553 else
554 {
555 SAL_WARN( "linguistic", "grammar checker does not support required locale" );
556 }
557 }
558 catch (uno::Exception &)
559 {
560 SAL_WARN( "linguistic", "instantiating grammar checker failed" );
561 }
562 }
563 }
564 else // not found - quite normal
565 {
566 SAL_INFO("linguistic", "No grammar checker found for \""
567 << LanguageTag::convertToBcp47(rLocale, false) << "\"");
568 }
569 // ---- THREAD SAFE END ----
570
571 return xRes;
572}
573
574static uno::Sequence<beans::PropertyValue>
575lcl_makeProperties(uno::Reference<text::XFlatParagraph> const& xFlatPara, sal_Int32 nProofInfo)
576{
577 uno::Reference<beans::XPropertySet> const xProps(
578 xFlatPara, uno::UNO_QUERY_THROW);
579 css::uno::Any a (nProofInfo);
581 { "FieldPositions", xProps->getPropertyValue("FieldPositions") },
582 { "FootnotePositions", xProps->getPropertyValue("FootnotePositions") },
583 { "SortedTextId", xProps->getPropertyValue("SortedTextId") },
584 { "DocumentElementsCount", xProps->getPropertyValue("DocumentElementsCount") },
585 { "ProofInfo", a }
586 });
587}
588
590{
591 for (;;)
592 {
593 // ---- THREAD SAFE START ----
594 bool bQueueEmpty = false;
595 {
596 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
597 if (m_bEnd)
598 {
599 break;
600 }
601 bQueueEmpty = m_aFPEntriesQueue.empty();
602 }
603 // ---- THREAD SAFE END ----
604
605 if (!bQueueEmpty)
606 {
607 uno::Reference< text::XFlatParagraphIterator > xFPIterator;
608 uno::Reference< text::XFlatParagraph > xFlatPara;
609 FPEntry aFPEntryItem;
610 OUString aCurDocId;
611 // ---- THREAD SAFE START ----
612 {
613 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
614 aFPEntryItem = m_aFPEntriesQueue.front();
615 xFPIterator = aFPEntryItem.m_xParaIterator;
616 xFlatPara = aFPEntryItem.m_xPara;
617 m_aCurCheckedDocId = aFPEntryItem.m_aDocId;
618 aCurDocId = m_aCurCheckedDocId;
619
620 m_aFPEntriesQueue.pop_front();
621 }
622 // ---- THREAD SAFE END ----
623
624 if (xFlatPara.is() && xFPIterator.is())
625 {
626 try
627 {
628 OUString aCurTxt( xFlatPara->getText() );
629 lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex );
630
631 const bool bModified = xFlatPara->isModified();
632 if (!bModified)
633 {
634 linguistic2::ProofreadingResult aRes;
635
636 // ---- THREAD SAFE START ----
637 {
638 osl::ClearableMutexGuard aGuard(MyMutex());
639
640 sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex;
641 sal_Int32 nSuggestedEnd
642 = GetSuggestedEndOfSentence(aCurTxt, nStartPos, aCurLocale);
643 DBG_ASSERT((nSuggestedEnd == 0 && aCurTxt.isEmpty())
644 || nSuggestedEnd > nStartPos,
645 "nSuggestedEndOfSentencePos calculation failed?");
646
647 uno::Reference<linguistic2::XProofreader> xGC =
648 GetGrammarChecker(aCurLocale);
649 if (xGC.is())
650 {
651 aGuard.clear();
652 uno::Sequence<beans::PropertyValue> const aProps(
654 aRes = xGC->doProofreading(aCurDocId, aCurTxt, aCurLocale,
655 nStartPos, nSuggestedEnd, aProps);
656
659 if (aRes.nBehindEndOfSentencePosition <= nStartPos
660 && aRes.nBehindEndOfSentencePosition != nSuggestedEnd)
661 {
662 SAL_WARN(
663 "linguistic",
664 "!! Grammarchecker failed to provide end of sentence !!");
665 aRes.nBehindEndOfSentencePosition = nSuggestedEnd;
666 }
667
668 aRes.xFlatParagraph = xFlatPara;
669 aRes.nStartOfSentencePosition = nStartPos;
670 }
671 else
672 {
673 // no grammar checker -> no error
674 // but we need to provide the data below in order to continue with the next sentence
675 aRes.aDocumentIdentifier = aCurDocId;
676 aRes.xFlatParagraph = xFlatPara;
677 aRes.aText = aCurTxt;
678 aRes.aLocale = aCurLocale;
679 aRes.nStartOfSentencePosition = nStartPos;
680 aRes.nBehindEndOfSentencePosition = nSuggestedEnd;
681 }
682 aRes.nStartOfNextSentencePosition
683 = lcl_SkipWhiteSpaces(aCurTxt, aRes.nBehindEndOfSentencePosition);
684 aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces(
685 aCurTxt, aRes.nStartOfNextSentencePosition);
686
687 //guard has to be cleared as ProcessResult calls out of this class
688 }
689 // ---- THREAD SAFE END ----
690 ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic );
691 }
692 else
693 {
694 // the paragraph changed meanwhile... (and maybe is still edited)
695 // thus we simply continue to ask for the next to be checked.
696 uno::Reference< text::XFlatParagraph > xFlatParaNext( xFPIterator->getNextPara() );
697 AddEntry( xFPIterator, xFlatParaNext, aCurDocId, 0, aFPEntryItem.m_bAutomatic );
698 }
699 }
700 catch (css::uno::Exception &)
701 {
702 TOOLS_WARN_EXCEPTION("linguistic", "GrammarCheckingIterator::DequeueAndCheck ignoring");
703 }
704 }
705
706 // ---- THREAD SAFE START ----
707 {
708 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
709 m_aCurCheckedDocId.clear();
710 }
711 // ---- THREAD SAFE END ----
712 }
713 else
714 {
715 // ---- THREAD SAFE START ----
716 {
717 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
718 if (m_bEnd)
719 {
720 break;
721 }
722 // Check queue state again
723 if (m_aFPEntriesQueue.empty())
724 m_aWakeUpThread.reset();
725 }
726 // ---- THREAD SAFE END ----
727
728 //if the queue is empty
729 // IMPORTANT: Don't call condition.wait() with locked
730 // mutex. Otherwise you would keep out other threads
731 // to add entries to the queue! A condition is thread-
732 // safe implemented.
733 m_aWakeUpThread.wait();
734 }
735 }
736}
737
738
740 const uno::Reference< ::uno::XInterface > & xDoc,
741 const uno::Reference< text::XFlatParagraphIteratorProvider > & xIteratorProvider )
742{
743 // get paragraph to start checking with
744 const bool bAutomatic = true;
745 uno::Reference<text::XFlatParagraphIterator> xFPIterator = xIteratorProvider->getFlatParagraphIterator(
746 text::TextMarkupType::PROOFREADING, bAutomatic );
747 uno::Reference< text::XFlatParagraph > xPara( xFPIterator.is()? xFPIterator->getFirstPara() : nullptr );
748 uno::Reference< lang::XComponent > xComponent( xDoc, uno::UNO_QUERY );
749
750 // ---- THREAD SAFE START ----
751 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
752 if (xPara.is() && xComponent.is())
753 {
754 OUString aDocId = GetOrCreateDocId( xComponent );
755
756 // create new entry and add it to queue
757 AddEntry( xFPIterator, xPara, aDocId, 0, bAutomatic );
758 }
759 // ---- THREAD SAFE END ----
760}
761
762
763linguistic2::ProofreadingResult SAL_CALL GrammarCheckingIterator::checkSentenceAtPosition(
764 const uno::Reference< uno::XInterface >& xDoc,
765 const uno::Reference< text::XFlatParagraph >& xFlatPara,
766 const OUString& rText,
767 const lang::Locale&,
768 sal_Int32 nStartOfSentencePos,
769 sal_Int32 nSuggestedEndOfSentencePos,
770 sal_Int32 nErrorPosInPara )
771{
772 // for the context menu...
773
774 linguistic2::ProofreadingResult aRes;
775
776 uno::Reference< lang::XComponent > xComponent( xDoc, uno::UNO_QUERY );
777 if (xFlatPara.is() && xComponent.is() &&
778 ( nErrorPosInPara < 0 || nErrorPosInPara < rText.getLength()))
779 {
780 // iterate through paragraph until we find the sentence we are interested in
781 linguistic2::ProofreadingResult aTmpRes;
782 sal_Int32 nStartPos = nStartOfSentencePos >= 0 ? nStartOfSentencePos : 0;
783
784 bool bFound = false;
785 do
786 {
787 lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, nStartPos );
788 sal_Int32 nOldStartOfSentencePos = nStartPos;
789 uno::Reference< linguistic2::XProofreader > xGC;
790 OUString aDocId;
791
792 // ---- THREAD SAFE START ----
793 {
794 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
795 aDocId = GetOrCreateDocId( xComponent );
796 nSuggestedEndOfSentencePos = GetSuggestedEndOfSentence( rText, nStartPos, aCurLocale );
797 DBG_ASSERT( nSuggestedEndOfSentencePos > nStartPos, "nSuggestedEndOfSentencePos calculation failed?" );
798
799 xGC = GetGrammarChecker( aCurLocale );
800 }
801 // ---- THREAD SAFE START ----
802 sal_Int32 nEndPos = -1;
803 if (xGC.is())
804 {
805 uno::Sequence<beans::PropertyValue> const aProps(
807 aTmpRes = xGC->doProofreading( aDocId, rText,
808 aCurLocale, nStartPos, nSuggestedEndOfSentencePos, aProps );
809
812 if (aTmpRes.nBehindEndOfSentencePosition <= nStartPos)
813 {
814 SAL_WARN( "linguistic", "!! Grammarchecker failed to provide end of sentence !!" );
815 aTmpRes.nBehindEndOfSentencePosition = nSuggestedEndOfSentencePos;
816 }
817
818 aTmpRes.xFlatParagraph = xFlatPara;
819 aTmpRes.nStartOfSentencePosition = nStartPos;
820 nEndPos = aTmpRes.nBehindEndOfSentencePosition;
821
822 if ((nErrorPosInPara< 0 || nStartPos <= nErrorPosInPara) && nErrorPosInPara < nEndPos)
823 bFound = true;
824 }
825 if (nEndPos == -1) // no result from grammar checker
826 nEndPos = nSuggestedEndOfSentencePos;
827 nStartPos = lcl_SkipWhiteSpaces( rText, nEndPos );
828 aTmpRes.nBehindEndOfSentencePosition = nEndPos;
829 aTmpRes.nStartOfNextSentencePosition = nStartPos;
830 aTmpRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( rText, aTmpRes.nStartOfNextSentencePosition );
831
832 // prevent endless loop by forcefully advancing if needs be...
833 if (nStartPos <= nOldStartOfSentencePos)
834 {
835 SAL_WARN( "linguistic", "end-of-sentence detection failed?" );
836 nStartPos = nOldStartOfSentencePos + 1;
837 }
838 }
839 while (!bFound && nStartPos < rText.getLength());
840
841 if (bFound && !xFlatPara->isModified())
842 aRes = aTmpRes;
843 }
844
845 return aRes;
846}
847
848
850 const OUString &rText,
851 sal_Int32 nSentenceStartPos,
852 const lang::Locale &rLocale )
853{
854 // internal method; will always be called with locked mutex
855
856 if (!m_xBreakIterator.is())
857 {
858 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
859 m_xBreakIterator = i18n::BreakIterator::create(xContext);
860 }
861 sal_Int32 nTextLen = rText.getLength();
862 sal_Int32 nEndPosition(0);
863 sal_Int32 nTmpStartPos = nSentenceStartPos;
864 do
865 {
866 sal_Int32 const nPrevEndPosition(nEndPosition);
867 nEndPosition = nTextLen;
868 if (nTmpStartPos < nTextLen)
869 {
870 nEndPosition = m_xBreakIterator->endOfSentence( rText, nTmpStartPos, rLocale );
871 if (nEndPosition <= nPrevEndPosition)
872 {
873 // fdo#68750 if there's no progress at all then presumably
874 // there's no end of sentence in this paragraph so just
875 // set the end position to end of paragraph
876 nEndPosition = nTextLen;
877 }
878 }
879 if (nEndPosition < 0)
880 nEndPosition = nTextLen;
881
882 ++nTmpStartPos;
883 }
884 while (nEndPosition <= nSentenceStartPos && nEndPosition < nTextLen);
885 if (nEndPosition > nTextLen)
886 nEndPosition = nTextLen;
887 return nEndPosition;
888}
889
890
892{
893 for (auto const& elem : m_aGCReferencesByService)
894 {
895 uno::Reference< linguistic2::XProofreader > xGC(elem.second);
896 if (xGC.is())
897 xGC->resetIgnoreRules();
898 }
899}
900
901
903 const uno::Reference< uno::XInterface >& xDoc )
904{
905 // ---- THREAD SAFE START ----
906 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
907
908 bool bRes = false;
909
910 uno::Reference< lang::XComponent > xComponent( xDoc, uno::UNO_QUERY );
911 if (xComponent.is())
912 {
913 // if the component was already used in one of the two calls to check text
914 // i.e. in startGrammarChecking or checkGrammarAtPos it will be found in the
915 // m_aDocIdMap unless the document already disposed.
916 // If it is not found then it is not yet being checked (or requested to being checked)
917 const DocMap_t::const_iterator aIt( m_aDocIdMap.find( xComponent.get() ) );
918 if (aIt != m_aDocIdMap.end())
919 {
920 // check in document is checked automatically in the background...
921 OUString aDocId = aIt->second;
922 if (!m_aCurCheckedDocId.isEmpty() && m_aCurCheckedDocId == aDocId)
923 {
924 // an entry for that document was dequeued and is currently being checked.
925 bRes = true;
926 }
927 else
928 {
929 // we need to check if there is an entry for that document in the queue...
930 // That is the document is going to be checked sooner or later.
931
932 sal_Int32 nSize = m_aFPEntriesQueue.size();
933 for (sal_Int32 i = 0; i < nSize && !bRes; ++i)
934 {
935 if (aDocId == m_aFPEntriesQueue[i].m_aDocId)
936 bRes = true;
937 }
938 }
939 }
940 }
941 // ---- THREAD SAFE END ----
942
943 return bRes;
944}
945
946
948 const linguistic2::LinguServiceEvent& rLngSvcEvent )
949{
950 if (rLngSvcEvent.nEvent != linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN)
951 return;
952
953 try
954 {
955 uno::Reference< uno::XInterface > xThis( getXWeak() );
956 linguistic2::LinguServiceEvent aEvent( xThis, linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN );
958 &linguistic2::XLinguServiceEventListener::processLinguServiceEvent,
959 aEvent);
960 }
961 catch (uno::RuntimeException &)
962 {
963 throw;
964 }
965 catch (const ::uno::Exception &)
966 {
967 // ignore
968 TOOLS_WARN_EXCEPTION("linguistic", "processLinguServiceEvent");
969 }
970}
971
972
974 const uno::Reference< linguistic2::XLinguServiceEventListener >& xListener )
975{
976 if (xListener.is())
977 {
978 m_aNotifyListeners.addInterface( xListener );
979 }
980 return true;
981}
982
983
985 const uno::Reference< linguistic2::XLinguServiceEventListener >& xListener )
986{
987 if (xListener.is())
988 {
990 }
991 return true;
992}
993
994
996{
997 lang::EventObject aEvt( static_cast<linguistic2::XProofreadingIterator *>(this) );
999
1001
1002 // ---- THREAD SAFE START ----
1003 {
1004 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
1005
1006 // release all UNO references
1007
1008 m_xBreakIterator.clear();
1009
1010 // clear containers with UNO references AND have those references released
1011 GCReferences_t aTmpEmpty1;
1012 DocMap_t aTmpEmpty2;
1013 FPQueue_t aTmpEmpty3;
1014 m_aGCReferencesByService.swap( aTmpEmpty1 );
1015 m_aDocIdMap.swap( aTmpEmpty2 );
1016 m_aFPEntriesQueue.swap( aTmpEmpty3 );
1017 }
1018 // ---- THREAD SAFE END ----
1019}
1020
1021
1023 const uno::Reference< lang::XEventListener >& xListener )
1024{
1025 if (xListener.is())
1026 {
1027 m_aEventListeners.addInterface( xListener );
1028 }
1029}
1030
1031
1033 const uno::Reference< lang::XEventListener >& xListener )
1034{
1035 if (xListener.is())
1036 {
1038 }
1039}
1040
1041
1042void SAL_CALL GrammarCheckingIterator::disposing( const lang::EventObject &rSource )
1043{
1044 // if the component (document) is disposing release all references
1052 uno::Reference< lang::XComponent > xDoc( rSource.Source, uno::UNO_QUERY );
1053 if (xDoc.is())
1054 {
1055 // ---- THREAD SAFE START ----
1056 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
1057 m_aDocIdMap.erase( xDoc.get() );
1058 // ---- THREAD SAFE END ----
1059 }
1060}
1061
1062
1063uno::Reference< util::XChangesBatch > const & GrammarCheckingIterator::GetUpdateAccess() const
1064{
1065 if (!m_xUpdateAccess.is())
1066 {
1067 try
1068 {
1069 // get configuration provider
1070 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
1071 uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider =
1072 configuration::theDefaultProvider::get( xContext );
1073
1074 // get configuration update access
1075 beans::PropertyValue aValue;
1076 aValue.Name = "nodepath";
1077 aValue.Value <<= OUString("org.openoffice.Office.Linguistic/ServiceManager");
1078 uno::Sequence< uno::Any > aProps{ uno::Any(aValue) };
1079 m_xUpdateAccess.set(
1080 xConfigurationProvider->createInstanceWithArguments(
1081 "com.sun.star.configuration.ConfigurationUpdateAccess", aProps ),
1082 uno::UNO_QUERY_THROW );
1083 }
1084 catch (uno::Exception &)
1085 {
1086 }
1087 }
1088
1089 return m_xUpdateAccess;
1090}
1091
1092
1094{
1095 GCImplNames_t aTmpGCImplNamesByLang;
1096
1097 try
1098 {
1099 // get node names (locale iso strings) for configured grammar checkers
1100 uno::Reference< container::XNameAccess > xNA( GetUpdateAccess(), uno::UNO_QUERY_THROW );
1101 xNA.set( xNA->getByName( "GrammarCheckerList" ), uno::UNO_QUERY_THROW );
1102 const uno::Sequence< OUString > aElementNames( xNA->getElementNames() );
1103
1104 for (const OUString& rElementName : aElementNames)
1105 {
1106 uno::Sequence< OUString > aImplNames;
1107 uno::Any aTmp( xNA->getByName( rElementName ) );
1108 if (aTmp >>= aImplNames)
1109 {
1110 if (aImplNames.hasElements())
1111 {
1112 // only the first entry is used, there should be only one grammar checker per language
1113 const OUString aImplName( aImplNames[0] );
1114 aTmpGCImplNamesByLang[rElementName] = aImplName;
1115 }
1116 }
1117 else
1118 {
1119 SAL_WARN( "linguistic", "failed to get aImplNames. Wrong type?" );
1120 }
1121 }
1122 }
1123 catch (uno::Exception const &)
1124 {
1125 TOOLS_WARN_EXCEPTION( "linguistic", "exception caught. Failed to get configured services" );
1126 }
1127
1128 {
1129 // ---- THREAD SAFE START ----
1130 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
1131 m_aGCImplNamesByLang.swap(aTmpGCImplNamesByLang);
1132 // ---- THREAD SAFE END ----
1133 }
1134}
1135
1136
1138 const OUString & rServiceName )
1139{
1140 return cppu::supportsService(this, rServiceName);
1141}
1142
1143
1145{
1146 return "com.sun.star.lingu2.ProofreadingIterator";
1147}
1148
1149
1150uno::Sequence< OUString > SAL_CALL GrammarCheckingIterator::getSupportedServiceNames( )
1151{
1152 return { "com.sun.star.linguistic2.ProofreadingIterator" };
1153}
1154
1155
1157 const lang::Locale &rLocale,
1158 const uno::Sequence< OUString > &rSvcImplNames )
1159{
1160 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
1161
1162 OUString sBcp47 = LanguageTag::convertToBcp47(rLocale, false);
1163 OUString aImplName;
1164 if (rSvcImplNames.hasElements())
1165 aImplName = rSvcImplNames[0]; // there is only one grammar checker per language
1166
1167 if (!LinguIsUnspecified(sBcp47) && !sBcp47.isEmpty())
1168 {
1169 if (!aImplName.isEmpty())
1170 m_aGCImplNamesByLang[sBcp47] = aImplName;
1171 else
1172 m_aGCImplNamesByLang.erase(sBcp47);
1173 }
1174}
1175
1176
1178 const lang::Locale &rLocale ) const
1179{
1180 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
1181
1182 const OUString aImplName = getServiceForLocale(rLocale).first; // there is only one grammar checker per language
1183
1184 if (!aImplName.isEmpty())
1185 return { aImplName };
1186 return {};
1187}
1188
1189
1190extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1192 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
1193{
1194 return cppu::acquire(new GrammarCheckingIterator());
1195}
1196
1197
1198
1199/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
AnyEventRef aEvent
virtual sal_Bool SAL_CALL addLinguServiceEventListener(const css::uno::Reference< css::linguistic2::XLinguServiceEventListener > &xLstnr) override
Definition: gciterator.cxx:973
comphelper::OInterfaceContainerHelper3< css::lang::XEventListener > m_aEventListeners
Definition: gciterator.hxx:116
css::uno::Reference< css::linguistic2::XProofreader > GetGrammarChecker(css::lang::Locale &rLocale)
Definition: gciterator.cxx:509
virtual sal_Bool SAL_CALL removeLinguServiceEventListener(const css::uno::Reference< css::linguistic2::XLinguServiceEventListener > &xLstnr) override
Definition: gciterator.cxx:984
virtual OUString SAL_CALL getImplementationName() override
std::map< OUString, css::uno::Reference< css::linguistic2::XProofreader > > GCReferences_t
Definition: gciterator.hxx:105
virtual void SAL_CALL dispose() override
Definition: gciterator.cxx:995
virtual sal_Bool SAL_CALL isProofreading(const css::uno::Reference< css::uno::XInterface > &xDocument) override
Definition: gciterator.cxx:902
std::deque< FPEntry > FPQueue_t
Definition: gciterator.hxx:87
GCReferences_t m_aGCReferencesByService
Definition: gciterator.hxx:106
virtual ~GrammarCheckingIterator() override
Definition: gciterator.cxx:292
virtual css::uno::Sequence< OUString > GetServiceList(const css::lang::Locale &rLocale) const override
std::map< OUString, OUString > GCImplNames_t
Definition: gciterator.hxx:101
void AddEntry(const css::uno::Reference< css::text::XFlatParagraphIterator > &xFlatParaIterator, const css::uno::Reference< css::text::XFlatParagraph > &xFlatPara, const OUString &rDocId, sal_Int32 nStartIndex, bool bAutomatic)
Definition: gciterator.cxx:347
virtual void SAL_CALL processLinguServiceEvent(const css::linguistic2::LinguServiceEvent &aLngSvcEvent) override
Definition: gciterator.cxx:947
comphelper::OInterfaceContainerHelper3< css::linguistic2::XLinguServiceEventListener > m_aNotifyListeners
Definition: gciterator.hxx:117
static osl::Mutex & MyMutex()
beware of initialization order!
Definition: gciterator.cxx:275
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
std::map< XComponent *, OUString > DocMap_t
Definition: gciterator.hxx:96
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL startProofreading(const css::uno::Reference< css::uno::XInterface > &xDocument, const css::uno::Reference< css::text::XFlatParagraphIteratorProvider > &xIteratorProvider) override
Definition: gciterator.cxx:739
void ProcessResult(const css::linguistic2::ProofreadingResult &rRes, const css::uno::Reference< css::text::XFlatParagraphIterator > &rxFlatParagraphIterator, bool bIsAutomaticChecking)
Definition: gciterator.cxx:377
std::pair< OUString, std::optional< OUString > > getServiceForLocale(const css::lang::Locale &rLocale) const
Definition: gciterator.cxx:488
virtual void SetServiceList(const css::lang::Locale &rLocale, const css::uno::Sequence< OUString > &rSvcImplNames) override
OUString GetOrCreateDocId(const css::uno::Reference< css::lang::XComponent > &xComp)
Definition: gciterator.cxx:322
osl::Condition m_aWakeUpThread
Definition: gciterator.hxx:111
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual css::linguistic2::ProofreadingResult SAL_CALL checkSentenceAtPosition(const css::uno::Reference< css::uno::XInterface > &xDocument, const css::uno::Reference< css::text::XFlatParagraph > &xFlatParagraph, const OUString &aText, const css::lang::Locale &aLocale, ::sal_Int32 nStartOfSentencePosition, ::sal_Int32 nSuggestedBehindEndOfSentencePosition, ::sal_Int32 nErrorPositionInParagraph) override
Definition: gciterator.cxx:763
css::uno::Reference< css::util::XChangesBatch > const & GetUpdateAccess() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
css::uno::Reference< css::util::XChangesBatch > m_xUpdateAccess
Definition: gciterator.hxx:120
css::uno::Reference< css::i18n::XBreakIterator > m_xBreakIterator
Definition: gciterator.hxx:119
virtual void SAL_CALL resetIgnoreRules() override
Definition: gciterator.cxx:891
sal_Int32 GetSuggestedEndOfSentence(const OUString &rText, sal_Int32 nSentenceStartPos, const css::lang::Locale &rLocale)
Definition: gciterator.cxx:849
GCImplNames_t m_aGCImplNamesByLang
Definition: gciterator.hxx:102
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
static OUString convertToBcp47(LanguageType nLangID)
Implementation of the css::container::XStringKeyMap interface.
Definition: gciterator.hxx:194
virtual css::uno::Any SAL_CALL getValueByIndex(::sal_Int32 nIndex) override
Definition: gciterator.cxx:266
virtual OUString SAL_CALL getKeyByIndex(::sal_Int32 nIndex) override
Definition: gciterator.cxx:258
virtual sal_Bool SAL_CALL hasValue(const OUString &aKey) override
Definition: gciterator.cxx:251
virtual css::uno::Any SAL_CALL getValue(const OUString &aKey) override
Definition: gciterator.cxx:242
virtual void SAL_CALL insertValue(const OUString &aKey, const css::uno::Any &aValue) override
Definition: gciterator.cxx:233
virtual ::sal_Int32 SAL_CALL getCount() override
Definition: gciterator.cxx:256
std::map< OUString, css::uno::Any > maMap
Definition: gciterator.hxx:209
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
const sal_Unicode aWhiteSpaces[]
Definition: gciterator.cxx:66
static uno::Sequence< beans::PropertyValue > lcl_makeProperties(uno::Reference< text::XFlatParagraph > const &xFlatPara, sal_Int32 nProofInfo)
Definition: gciterator.cxx:575
const int nWhiteSpaces
Definition: gciterator.cxx:122
const sal_Int32 PROOFINFO_MARK_PARAGRAPH
Definition: gciterator.cxx:120
static bool lcl_IsWhiteSpace(sal_Unicode cChar)
Definition: gciterator.cxx:124
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * linguistic_GrammarCheckingIterator_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
static sal_Int32 lcl_BacktraceWhiteSpaces(const OUString &rText, sal_Int32 nStartPos)
Definition: gciterator.cxx:171
static void lcl_workerfunc(void *gci)
Definition: gciterator.cxx:213
static sal_Int32 lcl_SkipWhiteSpaces(const OUString &rText, sal_Int32 nStartPos)
Definition: gciterator.cxx:135
const sal_Int32 PROOFINFO_GET_PROOFRESULT
Definition: gciterator.cxx:119
static lang::Locale lcl_GetPrimaryLanguageOfSentence(const uno::Reference< text::XFlatParagraph > &xFlatPara, sal_Int32 nStartIndex)
Definition: gciterator.cxx:222
sal_Int32 nIndex
uno_Any a
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
#define SAL_N_ELEMENTS(arr)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
bool LinguIsUnspecified(LanguageType nLanguage)
Checks if a LanguageType is one of the values that denote absence of language or undetermined languag...
Definition: misc.cxx:88
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
bool m_bAutomatic
Definition: gciterator.hxx:63
css::uno::Reference< css::text::XFlatParagraphIterator > m_xParaIterator
Definition: gciterator.hxx:51
css::uno::Reference< css::text::XFlatParagraph > m_xPara
Definition: gciterator.hxx:54
sal_Int32 m_nStartIndex
Definition: gciterator.hxx:60
OUString m_aDocId
Definition: gciterator.hxx:57
unsigned char sal_Bool
sal_uInt16 sal_Unicode