calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / linguistic / source / gciterator.hxx
blobf4123d58cf53f571a768110eda88de6862394b0e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <osl/mutex.hxx>
34 #include <osl/conditn.hxx>
35 #include <osl/thread.h>
37 #include <com/sun/star/uno/Any.hxx>
38 #include <comphelper/interfacecontainer3.hxx>
39 #include <i18nlangtag/lang.h>
41 #include <map>
42 #include <optional>
43 #include <utility>
44 #include <deque>
46 #include "defs.hxx"
49 struct FPEntry
51 // flat paragraph iterator
52 css::uno::Reference< css::text::XFlatParagraphIterator > m_xParaIterator;
54 // flat paragraph
55 css::uno::Reference< css::text::XFlatParagraph > m_xPara;
57 // document ID to identify different documents
58 OUString m_aDocId;
60 // the starting position to be checked
61 sal_Int32 m_nStartIndex;
63 // the flag to identify whether the document does automatic grammar checking
64 bool m_bAutomatic;
66 FPEntry()
67 : m_aDocId()
68 , m_nStartIndex( 0 )
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
94 bool m_bEnd;
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;
98 DocMap_t m_aDocIdMap;
101 // BCP-47 language tag -> implname mapping
102 typedef std::map< OUString, 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;
113 oslThread m_thread;
115 //! beware of initialization order!
116 static osl::Mutex& MyMutex();
117 comphelper::OInterfaceContainerHelper3<css::lang::XEventListener> m_aEventListeners;
118 comphelper::OInterfaceContainerHelper3<css::linguistic2::XLinguServiceEventListener> 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 );
128 void AddEntry(
129 const css::uno::Reference< css::text::XFlatParagraphIterator >& xFlatParaIterator,
130 const css::uno::Reference< 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( 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;
147 // Gets the grammar checker service, using fallback locales if necessary,
148 // and the BCP-47 tag for the updated locale, if the fallback was used.
149 // Precondition: MyMutex() is locked.
150 std::pair<OUString, std::optional<OUString>>
151 getServiceForLocale(const css::lang::Locale& rLocale) const;
153 public:
155 void DequeueAndCheck();
157 explicit GrammarCheckingIterator();
158 virtual ~GrammarCheckingIterator() override;
160 // XProofreadingIterator
161 virtual void SAL_CALL startProofreading( const css::uno::Reference< css::uno::XInterface >& xDocument, const css::uno::Reference< css::text::XFlatParagraphIteratorProvider >& xIteratorProvider ) override;
162 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;
163 virtual void SAL_CALL resetIgnoreRules( ) override;
164 virtual sal_Bool SAL_CALL isProofreading( const css::uno::Reference< css::uno::XInterface >& xDocument ) override;
166 // XLinguServiceEventListener
167 virtual void SAL_CALL processLinguServiceEvent( const css::linguistic2::LinguServiceEvent& aLngSvcEvent ) override;
169 // XLinguServiceEventBroadcaster
170 virtual sal_Bool SAL_CALL addLinguServiceEventListener( const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >& xLstnr ) override;
171 virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const css::uno::Reference< css::linguistic2::XLinguServiceEventListener >& xLstnr ) override;
173 // XComponent
174 virtual void SAL_CALL dispose( ) override;
175 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
176 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
178 // XEventListener
179 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
181 // XServiceInfo
182 virtual OUString SAL_CALL getImplementationName( ) override;
183 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
184 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
186 // LinguDispatcher
187 virtual void SetServiceList( const css::lang::Locale &rLocale, const css::uno::Sequence< OUString > &rSvcImplNames ) override;
188 virtual css::uno::Sequence< OUString > GetServiceList( const css::lang::Locale &rLocale ) const override;
192 /** Implementation of the css::container::XStringKeyMap interface
194 class LngXStringKeyMap : public ::cppu::WeakImplHelper<css::container::XStringKeyMap>
196 public:
197 LngXStringKeyMap();
199 virtual css::uno::Any SAL_CALL getValue(const OUString& aKey) override;
200 virtual sal_Bool SAL_CALL hasValue(const OUString& aKey) override;
201 virtual void SAL_CALL insertValue(const OUString& aKey, const css::uno::Any& aValue) override;
202 virtual ::sal_Int32 SAL_CALL getCount() override;
203 virtual OUString SAL_CALL getKeyByIndex(::sal_Int32 nIndex) override;
204 virtual css::uno::Any SAL_CALL getValueByIndex(::sal_Int32 nIndex) override;
206 private:
207 LngXStringKeyMap(LngXStringKeyMap const &) = delete;
208 void operator=(LngXStringKeyMap const &) = delete;
210 ~LngXStringKeyMap() override{};
212 std::map<OUString, css::uno::Any> maMap;
216 #endif
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */