LCOV - code coverage report
Current view: top level - linguistic/source - gciterator.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 4 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_LINGUISTIC_SOURCE_GCITERATOR_HXX
      21             : #define INCLUDED_LINGUISTIC_SOURCE_GCITERATOR_HXX
      22             : 
      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>
      32             : 
      33             : #include <cppuhelper/implbase5.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>
      39             : 
      40             : #include <map>
      41             : #include <deque>
      42             : 
      43             : #include "defs.hxx"
      44             : 
      45             : 
      46             : 
      47           0 : struct FPEntry
      48             : {
      49             :     // flat paragraph iterator
      50             :     ::com::sun::star::uno::Reference< ::com::sun::star::text::XFlatParagraphIterator > m_xParaIterator;
      51             : 
      52             :     // flat paragraph
      53             :     ::com::sun::star::uno::WeakReference< ::com::sun::star::text::XFlatParagraph > m_xPara;
      54             : 
      55             :     // document ID to identify different documents
      56             :     OUString m_aDocId;
      57             : 
      58             :     // the starting position to be checked
      59             :     sal_Int32       m_nStartIndex;
      60             : 
      61             :     // the flag to identify whether the document does automatical grammar checking
      62             :     bool        m_bAutomatic;
      63             : 
      64           0 :     FPEntry()
      65             :         : m_aDocId()
      66             :         , m_nStartIndex( 0 )
      67           0 :         , m_bAutomatic( false )
      68             :     {
      69           0 :     }
      70             : };
      71             : 
      72             : 
      73             : 
      74             : 
      75             : class GrammarCheckingIterator:
      76             :     public cppu::WeakImplHelper5
      77             :     <
      78             :         ::com::sun::star::linguistic2::XProofreadingIterator,
      79             :         ::com::sun::star::linguistic2::XLinguServiceEventListener,
      80             :         ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster,
      81             :         ::com::sun::star::lang::XComponent,
      82             :         ::com::sun::star::lang::XServiceInfo
      83             :     >,
      84             :     public LinguDispatcher
      85             : {
      86             :     //the queue is keeping track of all senteces to be checked
      87             :     //every element of this queue is a FlatParagraphEntry struct-object
      88             :     typedef std::deque< FPEntry > FPQueue_t;
      89             : 
      90             :     // queue for entries to be processed
      91             :     FPQueue_t       m_aFPEntriesQueue;
      92             : 
      93             :     // the flag to end the endless loop
      94             :     bool        m_bEnd;
      95             : 
      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;
      99             : 
     100             : 
     101             :     // language -> implname mapping
     102             :     typedef std::map< LanguageType, OUString > GCImplNames_t;
     103             :     GCImplNames_t   m_aGCImplNamesByLang;
     104             : 
     105             :     // implname -> UNO reference mapping
     106             :     typedef std::map< OUString, ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XProofreader > > GCReferences_t;
     107             :     GCReferences_t  m_aGCReferencesByService;
     108             : 
     109             :     OUString m_aCurCheckedDocId;
     110             :     bool        m_bGCServicesChecked;
     111             :     sal_Int32       m_nDocIdCounter;
     112             :     osl::Condition  m_aWakeUpThread;
     113             :     oslThread       m_thread;
     114             : 
     115             :     //! beware of initilization order !
     116             :     struct MyMutex : public rtl::Static< osl::Mutex, MyMutex > {};
     117             :     cppu::OInterfaceContainerHelper     m_aEventListeners;
     118             :     cppu::OInterfaceContainerHelper     m_aNotifyListeners;
     119             : 
     120             :     ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > m_xBreakIterator;
     121             :     mutable ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch >  m_xUpdateAccess;
     122             : 
     123             :     void TerminateThread();
     124             : 
     125             :     sal_Int32 NextDocId();
     126             :     OUString GetOrCreateDocId( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > &xComp );
     127             : 
     128             :     void AddEntry(
     129             :             ::com::sun::star::uno::WeakReference< ::com::sun::star::text::XFlatParagraphIterator > xFlatParaIterator,
     130             :             ::com::sun::star::uno::WeakReference< ::com::sun::star::text::XFlatParagraph > xFlatPara,
     131             :             const OUString &rDocId, sal_Int32 nStartIndex, bool bAutomatic );
     132             : 
     133             :     void ProcessResult( const ::com::sun::star::linguistic2::ProofreadingResult &rRes,
     134             :             const ::com::sun::star::uno::Reference< ::com::sun::star::text::XFlatParagraphIterator > &rxFlatParagraphIterator,
     135             :             bool bIsAutomaticChecking );
     136             : 
     137             :     sal_Int32 GetSuggestedEndOfSentence( const OUString &rText, sal_Int32 nSentenceStartPos, const ::com::sun::star::lang::Locale &rLocale );
     138             : 
     139             :     void GetConfiguredGCSvcs_Impl();
     140             :     ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XProofreader > GetGrammarChecker( const ::com::sun::star::lang::Locale & rLocale );
     141             : 
     142             :     ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch >   GetUpdateAccess() const;
     143             : 
     144             :     GrammarCheckingIterator( const GrammarCheckingIterator & ) SAL_DELETED_FUNCTION;
     145             :     GrammarCheckingIterator & operator = ( const GrammarCheckingIterator & ) SAL_DELETED_FUNCTION;
     146             : 
     147             : public:
     148             : 
     149             :     void DequeueAndCheck();
     150             : 
     151             :     explicit GrammarCheckingIterator();
     152             :     virtual ~GrammarCheckingIterator();
     153             : 
     154             :     // XProofreadingIterator
     155             :     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, std::exception) SAL_OVERRIDE;
     156             :     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 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, std::exception) SAL_OVERRIDE;
     157             :     virtual void SAL_CALL resetIgnoreRules(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     158             :     virtual sal_Bool SAL_CALL isProofreading( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xDocument ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     159             : 
     160             :     // XLinguServiceEventListener
     161             :     virtual void SAL_CALL processLinguServiceEvent( const ::com::sun::star::linguistic2::LinguServiceEvent& aLngSvcEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     162             : 
     163             :     // XLinguServiceEventBroadcaster
     164             :     virtual sal_Bool SAL_CALL addLinguServiceEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLinguServiceEventListener >& xLstnr ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     165             :     virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLinguServiceEventListener >& xLstnr ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     166             : 
     167             :     // XComponent
     168             :     virtual void SAL_CALL dispose(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     169             :     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     170             :     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     171             : 
     172             :     // XEventListener
     173             :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     174             : 
     175             :     // XServiceInfo
     176             :     virtual OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     177             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     178             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     179             : 
     180             :     // LinguDispatcher
     181             :     virtual void SetServiceList( const ::com::sun::star::lang::Locale &rLocale, const ::com::sun::star::uno::Sequence< OUString > &rSvcImplNames ) SAL_OVERRIDE;
     182             :     virtual ::com::sun::star::uno::Sequence< OUString > GetServiceList( const ::com::sun::star::lang::Locale &rLocale ) const SAL_OVERRIDE;
     183             :     virtual DspType GetDspType() const SAL_OVERRIDE;
     184             : };
     185             : 
     186             : 
     187             : 
     188             : #endif
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11