1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_LINGUISTIC_SOURCE_GCITERATOR_HXX
21 #define INCLUDED_LINGUISTIC_SOURCE_GCITERATOR_HXX
23 #include <com/sun/star/i18n/XBreakIterator.hpp>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/lang/XEventListener.hpp>
27 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
28 #include <com/sun/star/linguistic2/XLinguServiceEventListener.hpp>
29 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
30 #include <com/sun/star/util/XChangesBatch.hpp>
32 #include <cppuhelper/implbase.hxx>
33 #include <cppuhelper/weakref.hxx>
34 #include <osl/mutex.hxx>
35 #include <osl/conditn.hxx>
36 #include <osl/thread.h>
37 #include <rtl/instance.hxx>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <comphelper/interfacecontainer2.hxx>
41 #include <i18nlangtag/lang.h>
51 // flat paragraph iterator
52 css::uno::Reference
< css::text::XFlatParagraphIterator
> m_xParaIterator
;
55 css::uno::WeakReference
< css::text::XFlatParagraph
> m_xPara
;
57 // document ID to identify different documents
60 // the starting position to be checked
61 sal_Int32 m_nStartIndex
;
63 // the flag to identify whether the document does automatic grammar checking
69 , m_bAutomatic( false )
75 class GrammarCheckingIterator
:
76 public cppu::WeakImplHelper
78 css::linguistic2::XProofreadingIterator
,
79 css::linguistic2::XLinguServiceEventListener
,
80 css::linguistic2::XLinguServiceEventBroadcaster
,
81 css::lang::XComponent
,
82 css::lang::XServiceInfo
84 public LinguDispatcher
86 //the queue is keeping track of all sentences to be checked
87 //every element of this queue is a FlatParagraphEntry struct-object
88 typedef std::deque
< FPEntry
> FPQueue_t
;
90 // queue for entries to be processed
91 FPQueue_t m_aFPEntriesQueue
;
93 // the flag to end the endless loop
96 // Note that it must be the pointer and not the uno-reference to check if it is the same implementation object
97 typedef std::map
< XComponent
*, OUString
> DocMap_t
;
101 // language -> implname mapping
102 typedef std::map
< LanguageType
, OUString
> GCImplNames_t
;
103 GCImplNames_t m_aGCImplNamesByLang
;
105 // implname -> UNO reference mapping
106 typedef std::map
< OUString
, css::uno::Reference
< css::linguistic2::XProofreader
> > GCReferences_t
;
107 GCReferences_t m_aGCReferencesByService
;
109 OUString m_aCurCheckedDocId
;
110 bool m_bGCServicesChecked
;
111 sal_Int32 m_nDocIdCounter
;
112 osl::Condition m_aWakeUpThread
;
115 //! beware of initialization order!
116 struct MyMutex
: public rtl::Static
< osl::Mutex
, MyMutex
> {};
117 comphelper::OInterfaceContainerHelper2 m_aEventListeners
;
118 comphelper::OInterfaceContainerHelper2 m_aNotifyListeners
;
120 css::uno::Reference
< css::i18n::XBreakIterator
> m_xBreakIterator
;
121 mutable css::uno::Reference
< css::util::XChangesBatch
> m_xUpdateAccess
;
123 void TerminateThread();
125 sal_Int32
NextDocId();
126 OUString
GetOrCreateDocId( const css::uno::Reference
< css::lang::XComponent
> &xComp
);
129 const css::uno::WeakReference
< css::text::XFlatParagraphIterator
>& xFlatParaIterator
,
130 const css::uno::WeakReference
< css::text::XFlatParagraph
>& xFlatPara
,
131 const OUString
&rDocId
, sal_Int32 nStartIndex
, bool bAutomatic
);
133 void ProcessResult( const css::linguistic2::ProofreadingResult
&rRes
,
134 const css::uno::Reference
< css::text::XFlatParagraphIterator
> &rxFlatParagraphIterator
,
135 bool bIsAutomaticChecking
);
137 sal_Int32
GetSuggestedEndOfSentence( const OUString
&rText
, sal_Int32 nSentenceStartPos
, const css::lang::Locale
&rLocale
);
139 void GetConfiguredGCSvcs_Impl();
140 css::uno::Reference
< css::linguistic2::XProofreader
> GetGrammarChecker( const css::lang::Locale
& rLocale
);
142 css::uno::Reference
< css::util::XChangesBatch
> const & GetUpdateAccess() const;
144 GrammarCheckingIterator( const GrammarCheckingIterator
& ) = delete;
145 GrammarCheckingIterator
& operator = ( const GrammarCheckingIterator
& ) = delete;
149 void DequeueAndCheck();
151 explicit GrammarCheckingIterator();
152 virtual ~GrammarCheckingIterator() override
;
154 // XProofreadingIterator
155 virtual void SAL_CALL
startProofreading( const css::uno::Reference
< css::uno::XInterface
>& xDocument
, const css::uno::Reference
< css::text::XFlatParagraphIteratorProvider
>& xIteratorProvider
) override
;
156 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
;
157 virtual void SAL_CALL
resetIgnoreRules( ) override
;
158 virtual sal_Bool SAL_CALL
isProofreading( const css::uno::Reference
< css::uno::XInterface
>& xDocument
) override
;
160 // XLinguServiceEventListener
161 virtual void SAL_CALL
processLinguServiceEvent( const css::linguistic2::LinguServiceEvent
& aLngSvcEvent
) override
;
163 // XLinguServiceEventBroadcaster
164 virtual sal_Bool SAL_CALL
addLinguServiceEventListener( const css::uno::Reference
< css::linguistic2::XLinguServiceEventListener
>& xLstnr
) override
;
165 virtual sal_Bool SAL_CALL
removeLinguServiceEventListener( const css::uno::Reference
< css::linguistic2::XLinguServiceEventListener
>& xLstnr
) override
;
168 virtual void SAL_CALL
dispose( ) override
;
169 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
170 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
173 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
176 virtual OUString SAL_CALL
getImplementationName( ) override
;
177 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
178 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
181 virtual void SetServiceList( const css::lang::Locale
&rLocale
, const css::uno::Sequence
< OUString
> &rSvcImplNames
) override
;
182 virtual css::uno::Sequence
< OUString
> GetServiceList( const css::lang::Locale
&rLocale
) const override
;
186 /** Implementation of the css::container::XStringKeyMap interface
188 class LngXStringKeyMap
: public ::cppu::WeakImplHelper
<css::container::XStringKeyMap
>
193 virtual css::uno::Any SAL_CALL
getValue(const OUString
& aKey
) override
;
194 virtual sal_Bool SAL_CALL
hasValue(const OUString
& aKey
) override
;
195 virtual void SAL_CALL
insertValue(const OUString
& aKey
, const css::uno::Any
& aValue
) override
;
196 virtual ::sal_Int32 SAL_CALL
getCount() override
;
197 virtual OUString SAL_CALL
getKeyByIndex(::sal_Int32 nIndex
) override
;
198 virtual css::uno::Any SAL_CALL
getValueByIndex(::sal_Int32 nIndex
) override
;
201 LngXStringKeyMap(LngXStringKeyMap
const &) = delete;
202 void operator=(LngXStringKeyMap
const &) = delete;
204 ~LngXStringKeyMap() override
{};
206 std::map
<OUString
, css::uno::Any
> maMap
;
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */