1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gciterator.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _LINGUISTIC_GRAMMARCHECKINGITERATOR_HXX_
32 #define _LINGUISTIC_GRAMMARCHECKINGITERATOR_HXX_
34 #include <com/sun/star/i18n/XBreakIterator.hpp>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/lang/XEventListener.hpp>
38 #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
39 #include <com/sun/star/linguistic2/XLinguServiceEventListener.hpp>
40 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
41 #include <com/sun/star/uno/XComponentContext.hpp>
42 #include <com/sun/star/util/XChangesBatch.hpp>
44 #include <cppuhelper/implbase5.hxx>
45 #include <cppuhelper/weakref.hxx>
46 #include <osl/mutex.hxx>
47 #include <osl/conditn.hxx>
48 #include <rtl/instance.hxx>
55 //////////////////////////////////////////////////////////////////////
60 // flat paragraph iterator
61 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XFlatParagraphIterator
> m_xParaIterator
;
64 ::com::sun::star::uno::WeakReference
< ::com::sun::star::text::XFlatParagraph
> m_xPara
;
66 // document ID to identify different documents
67 ::rtl::OUString m_aDocId
;
69 // the starting position to be checked
70 sal_Int32 m_nStartIndex
;
72 // the flag to identify whether the document does automatical grammar checking
73 sal_Bool m_bAutomatic
;
84 ///////////////////////////////////////////////////////////////////////////
87 class GrammarCheckingIterator
:
88 public cppu::WeakImplHelper5
90 ::com::sun::star::linguistic2::XProofreadingIterator
,
91 ::com::sun::star::linguistic2::XLinguServiceEventListener
,
92 ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster
,
93 ::com::sun::star::lang::XComponent
,
94 ::com::sun::star::lang::XServiceInfo
96 public LinguDispatcher
98 com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> m_xMSF
;
101 //the queue is keeping track of all senteces to be checked
102 //every element of this queue is a FlatParagraphEntry struct-object
103 typedef std::deque
< FPEntry
> FPQueue_t
;
105 // queue for entries to be processed
106 FPQueue_t m_aFPEntriesQueue
;
108 // the flag to end the endless loop
111 // Note that it must be the pointer and not the uno-reference to check if it is the same implementation object
112 typedef std::map
< XComponent
*, ::rtl::OUString
> DocMap_t
;
113 DocMap_t m_aDocIdMap
;
115 // parameter ::rtl::OUString --> implementation name
116 // parameter ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > --> list of locales supported by service
117 // typedef std::map< ::rtl::OUString, ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > > GCLocales_t;
118 // GCLocales_t m_aGCLocalesByService;
120 // language -> implname mapping
121 typedef std::map
< LanguageType
, ::rtl::OUString
> GCImplNames_t
;
122 GCImplNames_t m_aGCImplNamesByLang
;
124 // implname -> UNO reference mapping
125 typedef std::map
< ::rtl::OUString
, ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XProofreader
> > GCReferences_t
;
126 GCReferences_t m_aGCReferencesByService
;
128 ::rtl::OUString m_aCurCheckedDocId
;
129 sal_Bool m_bGCServicesChecked
;
130 sal_Int32 m_nDocIdCounter
;
131 sal_Int32 m_nLastEndOfSentencePos
;
132 osl::Condition m_aWakeUpThread
;
133 osl::Condition m_aRequestEndThread
;
135 //! beware of initilization order !
136 struct MyMutex
: public rtl::Static
< osl::Mutex
, MyMutex
> {};
138 cppu::OInterfaceContainerHelper m_aEventListeners
;
139 cppu::OInterfaceContainerHelper m_aNotifyListeners
;
141 ::com::sun::star::uno::Reference
< ::com::sun::star::i18n::XBreakIterator
> m_xBreakIterator
;
142 mutable ::com::sun::star::uno::Reference
< ::com::sun::star::util::XChangesBatch
> m_xUpdateAccess
;
144 sal_Int32
NextDocId();
145 ::rtl::OUString
GetOrCreateDocId( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
> &xComp
);
148 ::com::sun::star::uno::WeakReference
< ::com::sun::star::text::XFlatParagraphIterator
> xFlatParaIterator
,
149 ::com::sun::star::uno::WeakReference
< ::com::sun::star::text::XFlatParagraph
> xFlatPara
,
150 const ::rtl::OUString
&rDocId
, sal_Int32 nStartIndex
, sal_Bool bAutomatic
);
152 void ProcessResult( const ::com::sun::star::linguistic2::ProofreadingResult
&rRes
,
153 const ::com::sun::star::uno::Reference
< ::com::sun::star::text::XFlatParagraphIterator
> &rxFlatParagraphIterator
,
154 bool bIsAutomaticChecking
);
156 sal_Int32
GetSuggestedEndOfSentence( const ::rtl::OUString
&rText
, sal_Int32 nSentenceStartPos
, const ::com::sun::star::lang::Locale
&rLocale
);
158 void GetConfiguredGCSvcs_Impl();
159 // void GetMatchingGCSvcs_Impl();
160 // void GetAvailableGCSvcs_Impl();
161 ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XProofreader
> GetGrammarChecker( const ::com::sun::star::lang::Locale
& rLocale
);
163 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XChangesBatch
> GetUpdateAccess() const;
165 // disallow use of copy c-tor and assignment operator
166 GrammarCheckingIterator( const GrammarCheckingIterator
& );
167 GrammarCheckingIterator
& operator = ( const GrammarCheckingIterator
& );
171 void DequeueAndCheck();
173 explicit GrammarCheckingIterator( const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> & rxMgr
);
174 virtual ~GrammarCheckingIterator();
176 // XProofreadingIterator
177 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
);
178 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
);
179 virtual void SAL_CALL
resetIgnoreRules( ) throw (::com::sun::star::uno::RuntimeException
);
180 virtual ::sal_Bool SAL_CALL
isProofreading( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xDocument
) throw (::com::sun::star::uno::RuntimeException
);
182 // XLinguServiceEventListener
183 virtual void SAL_CALL
processLinguServiceEvent( const ::com::sun::star::linguistic2::LinguServiceEvent
& aLngSvcEvent
) throw (::com::sun::star::uno::RuntimeException
);
185 // XLinguServiceEventBroadcaster
186 virtual ::sal_Bool SAL_CALL
addLinguServiceEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XLinguServiceEventListener
>& xLstnr
) throw (::com::sun::star::uno::RuntimeException
);
187 virtual ::sal_Bool SAL_CALL
removeLinguServiceEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XLinguServiceEventListener
>& xLstnr
) throw (::com::sun::star::uno::RuntimeException
);
190 virtual void SAL_CALL
dispose( ) throw (::com::sun::star::uno::RuntimeException
);
191 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
192 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
195 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
);
198 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
);
199 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
);
200 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
203 virtual void SetServiceList( const ::com::sun::star::lang::Locale
&rLocale
, const ::com::sun::star::uno::Sequence
< rtl::OUString
> &rSvcImplNames
);
204 virtual ::com::sun::star::uno::Sequence
< rtl::OUString
> GetServiceList( const ::com::sun::star::lang::Locale
&rLocale
) const;
205 virtual DspType
GetDspType() const;
209 ///////////////////////////////////////////////////////////////////////////