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/uno/XComponentContext.hpp>
31 #include <com/sun/star/util/XChangesBatch.hpp>
33 #include <cppuhelper/implbase.hxx>
34 #include <cppuhelper/weakref.hxx>
35 #include <osl/mutex.hxx>
36 #include <osl/conditn.hxx>
37 #include <osl/thread.h>
38 #include <rtl/instance.hxx>
48 // flat paragraph iterator
49 css::uno::Reference
< css::text::XFlatParagraphIterator
> m_xParaIterator
;
52 css::uno::WeakReference
< css::text::XFlatParagraph
> m_xPara
;
54 // document ID to identify different documents
57 // the starting position to be checked
58 sal_Int32 m_nStartIndex
;
60 // the flag to identify whether the document does automatic grammar checking
66 , m_bAutomatic( false )
72 class GrammarCheckingIterator
:
73 public cppu::WeakImplHelper
75 css::linguistic2::XProofreadingIterator
,
76 css::linguistic2::XLinguServiceEventListener
,
77 css::linguistic2::XLinguServiceEventBroadcaster
,
78 css::lang::XComponent
,
79 css::lang::XServiceInfo
81 public LinguDispatcher
83 //the queue is keeping track of all sentences to be checked
84 //every element of this queue is a FlatParagraphEntry struct-object
85 typedef std::deque
< FPEntry
> FPQueue_t
;
87 // queue for entries to be processed
88 FPQueue_t m_aFPEntriesQueue
;
90 // the flag to end the endless loop
93 // Note that it must be the pointer and not the uno-reference to check if it is the same implementation object
94 typedef std::map
< XComponent
*, OUString
> DocMap_t
;
98 // language -> implname mapping
99 typedef std::map
< LanguageType
, OUString
> GCImplNames_t
;
100 GCImplNames_t m_aGCImplNamesByLang
;
102 // implname -> UNO reference mapping
103 typedef std::map
< OUString
, css::uno::Reference
< css::linguistic2::XProofreader
> > GCReferences_t
;
104 GCReferences_t m_aGCReferencesByService
;
106 OUString m_aCurCheckedDocId
;
107 bool m_bGCServicesChecked
;
108 sal_Int32 m_nDocIdCounter
;
109 osl::Condition m_aWakeUpThread
;
112 //! beware of initialization order!
113 struct MyMutex
: public rtl::Static
< osl::Mutex
, MyMutex
> {};
114 comphelper::OInterfaceContainerHelper2 m_aEventListeners
;
115 comphelper::OInterfaceContainerHelper2 m_aNotifyListeners
;
117 css::uno::Reference
< css::i18n::XBreakIterator
> m_xBreakIterator
;
118 mutable css::uno::Reference
< css::util::XChangesBatch
> m_xUpdateAccess
;
120 void TerminateThread();
122 sal_Int32
NextDocId();
123 OUString
GetOrCreateDocId( const css::uno::Reference
< css::lang::XComponent
> &xComp
);
126 const css::uno::WeakReference
< css::text::XFlatParagraphIterator
>& xFlatParaIterator
,
127 const css::uno::WeakReference
< css::text::XFlatParagraph
>& xFlatPara
,
128 const OUString
&rDocId
, sal_Int32 nStartIndex
, bool bAutomatic
);
130 void ProcessResult( const css::linguistic2::ProofreadingResult
&rRes
,
131 const css::uno::Reference
< css::text::XFlatParagraphIterator
> &rxFlatParagraphIterator
,
132 bool bIsAutomaticChecking
);
134 sal_Int32
GetSuggestedEndOfSentence( const OUString
&rText
, sal_Int32 nSentenceStartPos
, const css::lang::Locale
&rLocale
);
136 void GetConfiguredGCSvcs_Impl();
137 css::uno::Reference
< css::linguistic2::XProofreader
> GetGrammarChecker( const css::lang::Locale
& rLocale
);
139 css::uno::Reference
< css::util::XChangesBatch
> const & GetUpdateAccess() const;
141 GrammarCheckingIterator( const GrammarCheckingIterator
& ) = delete;
142 GrammarCheckingIterator
& operator = ( const GrammarCheckingIterator
& ) = delete;
146 void DequeueAndCheck();
148 explicit GrammarCheckingIterator();
149 virtual ~GrammarCheckingIterator() override
;
151 // XProofreadingIterator
152 virtual void SAL_CALL
startProofreading( const css::uno::Reference
< css::uno::XInterface
>& xDocument
, const css::uno::Reference
< css::text::XFlatParagraphIteratorProvider
>& xIteratorProvider
) override
;
153 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
;
154 virtual void SAL_CALL
resetIgnoreRules( ) override
;
155 virtual sal_Bool SAL_CALL
isProofreading( const css::uno::Reference
< css::uno::XInterface
>& xDocument
) override
;
157 // XLinguServiceEventListener
158 virtual void SAL_CALL
processLinguServiceEvent( const css::linguistic2::LinguServiceEvent
& aLngSvcEvent
) override
;
160 // XLinguServiceEventBroadcaster
161 virtual sal_Bool SAL_CALL
addLinguServiceEventListener( const css::uno::Reference
< css::linguistic2::XLinguServiceEventListener
>& xLstnr
) override
;
162 virtual sal_Bool SAL_CALL
removeLinguServiceEventListener( const css::uno::Reference
< css::linguistic2::XLinguServiceEventListener
>& xLstnr
) override
;
165 virtual void SAL_CALL
dispose( ) override
;
166 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
167 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
170 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
173 virtual OUString SAL_CALL
getImplementationName( ) override
;
174 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
175 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
178 virtual void SetServiceList( const css::lang::Locale
&rLocale
, const css::uno::Sequence
< OUString
> &rSvcImplNames
) override
;
179 virtual css::uno::Sequence
< OUString
> GetServiceList( const css::lang::Locale
&rLocale
) const override
;
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */