Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _LINGUISTIC_GRAMMARCHECKINGITERATOR_HXX_
30 : : #define _LINGUISTIC_GRAMMARCHECKINGITERATOR_HXX_
31 : :
32 : : #include <com/sun/star/i18n/XBreakIterator.hpp>
33 : : #include <com/sun/star/lang/XComponent.hpp>
34 : : #include <com/sun/star/lang/XServiceInfo.hpp>
35 : : #include <com/sun/star/lang/XEventListener.hpp>
36 : : #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
37 : : #include <com/sun/star/linguistic2/XLinguServiceEventListener.hpp>
38 : : #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
39 : : #include <com/sun/star/uno/XComponentContext.hpp>
40 : : #include <com/sun/star/util/XChangesBatch.hpp>
41 : :
42 : : #include <cppuhelper/implbase5.hxx>
43 : : #include <cppuhelper/weakref.hxx>
44 : : #include <osl/mutex.hxx>
45 : : #include <osl/conditn.hxx>
46 : : #include <osl/thread.h>
47 : : #include <rtl/instance.hxx>
48 : :
49 : : #include <map>
50 : : #include <deque>
51 : :
52 : : #include "defs.hxx"
53 : :
54 : :
55 : :
56 [ + - ][ + - ]: 23815 : struct FPEntry
57 : : {
58 : : // flat paragraph iterator
59 : : ::com::sun::star::uno::Reference< ::com::sun::star::text::XFlatParagraphIterator > m_xParaIterator;
60 : :
61 : : // flat paragraph
62 : : ::com::sun::star::uno::WeakReference< ::com::sun::star::text::XFlatParagraph > m_xPara;
63 : :
64 : : // document ID to identify different documents
65 : : ::rtl::OUString m_aDocId;
66 : :
67 : : // the starting position to be checked
68 : : sal_Int32 m_nStartIndex;
69 : :
70 : : // the flag to identify whether the document does automatical grammar checking
71 : : sal_Bool m_bAutomatic;
72 : :
73 : 9526 : FPEntry()
74 : : : m_aDocId()
75 : : , m_nStartIndex( 0 )
76 [ + - ]: 9526 : , m_bAutomatic( 0 )
77 : : {
78 : 9526 : }
79 : : };
80 : :
81 : :
82 : :
83 : :
84 : : class GrammarCheckingIterator:
85 : : public cppu::WeakImplHelper5
86 : : <
87 : : ::com::sun::star::linguistic2::XProofreadingIterator,
88 : : ::com::sun::star::linguistic2::XLinguServiceEventListener,
89 : : ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster,
90 : : ::com::sun::star::lang::XComponent,
91 : : ::com::sun::star::lang::XServiceInfo
92 : : >,
93 : : public LinguDispatcher
94 : : {
95 : : com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMSF;
96 : :
97 : :
98 : : //the queue is keeping track of all senteces to be checked
99 : : //every element of this queue is a FlatParagraphEntry struct-object
100 : : typedef std::deque< FPEntry > FPQueue_t;
101 : :
102 : : // queue for entries to be processed
103 : : FPQueue_t m_aFPEntriesQueue;
104 : :
105 : : // the flag to end the endless loop
106 : : sal_Bool m_bEnd;
107 : :
108 : : // Note that it must be the pointer and not the uno-reference to check if it is the same implementation object
109 : : typedef std::map< XComponent *, ::rtl::OUString > DocMap_t;
110 : : DocMap_t m_aDocIdMap;
111 : :
112 : :
113 : : // language -> implname mapping
114 : : typedef std::map< LanguageType, ::rtl::OUString > GCImplNames_t;
115 : : GCImplNames_t m_aGCImplNamesByLang;
116 : :
117 : : // implname -> UNO reference mapping
118 : : typedef std::map< ::rtl::OUString, ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XProofreader > > GCReferences_t;
119 : : GCReferences_t m_aGCReferencesByService;
120 : :
121 : : ::rtl::OUString m_aCurCheckedDocId;
122 : : sal_Bool m_bGCServicesChecked;
123 : : sal_Int32 m_nDocIdCounter;
124 : : sal_Int32 m_nLastEndOfSentencePos;
125 : : osl::Condition m_aWakeUpThread;
126 : : oslThread m_thread;
127 : :
128 : : //! beware of initilization order !
129 : : struct MyMutex : public rtl::Static< osl::Mutex, MyMutex > {};
130 : : cppu::OInterfaceContainerHelper m_aEventListeners;
131 : : cppu::OInterfaceContainerHelper m_aNotifyListeners;
132 : :
133 : : ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > m_xBreakIterator;
134 : : mutable ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch > m_xUpdateAccess;
135 : :
136 : : void TerminateThread();
137 : :
138 : : sal_Int32 NextDocId();
139 : : ::rtl::OUString GetOrCreateDocId( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > &xComp );
140 : :
141 : : void AddEntry(
142 : : ::com::sun::star::uno::WeakReference< ::com::sun::star::text::XFlatParagraphIterator > xFlatParaIterator,
143 : : ::com::sun::star::uno::WeakReference< ::com::sun::star::text::XFlatParagraph > xFlatPara,
144 : : const ::rtl::OUString &rDocId, sal_Int32 nStartIndex, sal_Bool bAutomatic );
145 : :
146 : : void ProcessResult( const ::com::sun::star::linguistic2::ProofreadingResult &rRes,
147 : : const ::com::sun::star::uno::Reference< ::com::sun::star::text::XFlatParagraphIterator > &rxFlatParagraphIterator,
148 : : bool bIsAutomaticChecking );
149 : :
150 : : sal_Int32 GetSuggestedEndOfSentence( const ::rtl::OUString &rText, sal_Int32 nSentenceStartPos, const ::com::sun::star::lang::Locale &rLocale );
151 : :
152 : : void GetConfiguredGCSvcs_Impl();
153 : : ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XProofreader > GetGrammarChecker( const ::com::sun::star::lang::Locale & rLocale );
154 : :
155 : : ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch > GetUpdateAccess() const;
156 : :
157 : : // disallow use of copy c-tor and assignment operator
158 : : GrammarCheckingIterator( const GrammarCheckingIterator & );
159 : : GrammarCheckingIterator & operator = ( const GrammarCheckingIterator & );
160 : :
161 : : public:
162 : :
163 : : void DequeueAndCheck();
164 : :
165 : : explicit GrammarCheckingIterator( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rxMgr );
166 : : virtual ~GrammarCheckingIterator();
167 : :
168 : : // XProofreadingIterator
169 : : virtual void SAL_CALL startProofreading( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xDocument, const ::com::sun::star::uno::Reference< ::com::sun::star::text::XFlatParagraphIteratorProvider >& xIteratorProvider ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
170 : : virtual ::com::sun::star::linguistic2::ProofreadingResult SAL_CALL checkSentenceAtPosition( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xDocument, const ::com::sun::star::uno::Reference< ::com::sun::star::text::XFlatParagraph >& xFlatParagraph, const ::rtl::OUString& aText, const ::com::sun::star::lang::Locale& aLocale, ::sal_Int32 nStartOfSentencePosition, ::sal_Int32 nSuggestedBehindEndOfSentencePosition, ::sal_Int32 nErrorPositionInParagraph ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
171 : : virtual void SAL_CALL resetIgnoreRules( ) throw (::com::sun::star::uno::RuntimeException);
172 : : virtual ::sal_Bool SAL_CALL isProofreading( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xDocument ) throw (::com::sun::star::uno::RuntimeException);
173 : :
174 : : // XLinguServiceEventListener
175 : : virtual void SAL_CALL processLinguServiceEvent( const ::com::sun::star::linguistic2::LinguServiceEvent& aLngSvcEvent ) throw (::com::sun::star::uno::RuntimeException);
176 : :
177 : : // XLinguServiceEventBroadcaster
178 : : virtual ::sal_Bool SAL_CALL addLinguServiceEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLinguServiceEventListener >& xLstnr ) throw (::com::sun::star::uno::RuntimeException);
179 : : virtual ::sal_Bool SAL_CALL removeLinguServiceEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLinguServiceEventListener >& xLstnr ) throw (::com::sun::star::uno::RuntimeException);
180 : :
181 : : // XComponent
182 : : virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
183 : : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
184 : : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
185 : :
186 : : // XEventListener
187 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
188 : :
189 : : // XServiceInfo
190 : : virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
191 : : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
192 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
193 : :
194 : : // LinguDispatcher
195 : : virtual void SetServiceList( const ::com::sun::star::lang::Locale &rLocale, const ::com::sun::star::uno::Sequence< rtl::OUString > &rSvcImplNames );
196 : : virtual ::com::sun::star::uno::Sequence< rtl::OUString > GetServiceList( const ::com::sun::star::lang::Locale &rLocale ) const;
197 : : virtual DspType GetDspType() const;
198 : : };
199 : :
200 : :
201 : :
202 : : #endif
203 : :
204 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|