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

Generated by: LCOV version 1.10