LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/uno - dlelstnr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 62 25.8 %
Date: 2012-12-27 Functions: 2 8 25.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             : 
      21             : #include <com/sun/star/frame/Desktop.hpp>
      22             : #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
      23             : #include <com/sun/star/linguistic2/XDictionaryList.hpp>
      24             : #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
      25             : #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
      26             : #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
      27             : #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
      28             : 
      29             : #include <unotools/lingucfg.hxx>
      30             : 
      31             : #include <com/sun/star/uno/Reference.h>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <osl/mutex.hxx>
      34             : #include <vcl/svapp.hxx>
      35             : #include <tools/shl.hxx>
      36             : #include "dlelstnr.hxx"
      37             : #include <swmodule.hxx>
      38             : #include <wrtsh.hxx>
      39             : #include <view.hxx>
      40             : 
      41             : using ::rtl::OUString;
      42             : using namespace ::com::sun::star;
      43             : using namespace ::com::sun::star::lang;
      44             : using namespace ::com::sun::star::frame;
      45             : using namespace ::com::sun::star::uno;
      46             : using namespace ::com::sun::star::linguistic2;
      47             : using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
      48             : 
      49           7 : SwLinguServiceEventListener::SwLinguServiceEventListener()
      50             : {
      51           7 :     Reference< XMultiServiceFactory > xMgr( comphelper::getProcessServiceFactory() );
      52           7 :     Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
      53             :     try
      54             :     {
      55           7 :         xDesktop = frame::Desktop::create(xContext);
      56           7 :         xDesktop->addTerminateListener( this );
      57             : 
      58           7 :         xLngSvcMgr = LinguServiceManager::create(xContext);
      59           7 :         xLngSvcMgr->addLinguServiceManagerListener( (XLinguServiceEventListener *) this );
      60             : 
      61           7 :         if (SvtLinguConfig().HasGrammarChecker())
      62             :         {
      63           0 :             OUString aSvcName( "com.sun.star.linguistic2.ProofreadingIterator" );
      64           0 :             xGCIterator = Reference< XProofreadingIterator >( xMgr->createInstance( aSvcName ), UNO_QUERY );
      65           0 :             Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
      66           0 :             if (xBC.is())
      67           0 :                 xBC->addLinguServiceEventListener( (XLinguServiceEventListener *) this );
      68             :         }
      69             :     }
      70           0 :     catch (const uno::Exception&)
      71             :     {
      72             :         OSL_FAIL("exception caught in SwLinguServiceEventListener c-tor" );
      73           7 :     }
      74           7 : }
      75             : 
      76           0 : SwLinguServiceEventListener::~SwLinguServiceEventListener()
      77             : {
      78           0 : }
      79             : 
      80           0 : void SwLinguServiceEventListener::processDictionaryListEvent(
      81             :             const DictionaryListEvent& rDicListEvent)
      82             :         throw( RuntimeException )
      83             : {
      84           0 :     SolarMutexGuard aGuard;
      85             : 
      86           0 :     sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
      87             : 
      88             :     sal_Int16 nSpellWrongFlags =
      89             :             DictionaryListEventFlags::ADD_POS_ENTRY     |
      90             :             DictionaryListEventFlags::DEL_NEG_ENTRY     |
      91             :             DictionaryListEventFlags::ACTIVATE_POS_DIC  |
      92           0 :             DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
      93           0 :     bool bIsSpellWrong  =  0 != (nEvt & nSpellWrongFlags);
      94             :     sal_Int16 nSpellAllFlags =
      95             :             DictionaryListEventFlags::ADD_NEG_ENTRY     |
      96             :             DictionaryListEventFlags::DEL_POS_ENTRY     |
      97             :             DictionaryListEventFlags::ACTIVATE_NEG_DIC  |
      98           0 :             DictionaryListEventFlags::DEACTIVATE_POS_DIC;
      99           0 :     bool bIsSpellAll    =  0 != (nEvt & nSpellAllFlags);
     100             : 
     101           0 :     if (bIsSpellWrong || bIsSpellAll)
     102           0 :         SW_MOD()->CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
     103           0 : }
     104             : 
     105           0 : void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
     106             :             const LinguServiceEvent& rLngSvcEvent )
     107             :         throw(RuntimeException)
     108             : {
     109           0 :     SolarMutexGuard aGuard;
     110             : 
     111           0 :     bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
     112           0 :     bool bIsSpellAll   = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
     113           0 :     if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
     114           0 :         bIsSpellWrong = bIsSpellAll = true;     // have all spelling and grammar checked...
     115           0 :     if (bIsSpellWrong || bIsSpellAll)
     116             :     {
     117           0 :         SW_MOD()->CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
     118             :     }
     119           0 :     if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
     120             :     {
     121           0 :         SwView *pSwView = SW_MOD()->GetFirstView();
     122             : 
     123             :         //!! since this function may be called within the ctor of
     124             :         //!! SwView (during formatting) where the WrtShell is not yet
     125             :         //!! created, we have to check for the WrtShellPtr to see
     126             :         //!! if it is already availbale
     127           0 :         while (pSwView && pSwView->GetWrtShellPtr())
     128             :         {
     129           0 :             pSwView->GetWrtShell().ChgHyphenation();
     130           0 :             pSwView = SW_MOD()->GetNextView( pSwView );
     131             :         }
     132           0 :     }
     133           0 : }
     134             : 
     135          14 : void SAL_CALL SwLinguServiceEventListener::disposing(
     136             :             const EventObject& rEventObj )
     137             :         throw(RuntimeException)
     138             : {
     139          14 :     SolarMutexGuard aGuard;
     140             : 
     141          14 :     if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
     142           7 :         xLngSvcMgr = 0;
     143          14 :     if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
     144           0 :         xGCIterator = 0;
     145          14 : }
     146             : 
     147           0 : void SAL_CALL SwLinguServiceEventListener::queryTermination(
     148             :             const EventObject& /*rEventObj*/ )
     149             :         throw(TerminationVetoException, RuntimeException)
     150             : {
     151           0 : }
     152             : 
     153           0 : void SAL_CALL SwLinguServiceEventListener::notifyTermination(
     154             :             const EventObject& rEventObj )
     155             :         throw(RuntimeException)
     156             : {
     157           0 :     SolarMutexGuard aGuard;
     158             : 
     159           0 :     if (xDesktop.is()  &&  rEventObj.Source == xDesktop)
     160             :     {
     161           0 :         if (xLngSvcMgr.is())
     162           0 :             xLngSvcMgr = 0;
     163           0 :         if (xGCIterator.is())
     164           0 :             xGCIterator = 0;
     165           0 :         xDesktop = NULL;
     166           0 :     }
     167           0 : }
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10