LCOV - code coverage report
Current view: top level - sw/source/uibase/uno - dlelstnr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 42 50 84.0 %
Date: 2015-06-13 12:38:46 Functions: 9 9 100.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/LinguServiceEventFlags.hpp>
      26             : 
      27             : #include <unotools/lingucfg.hxx>
      28             : 
      29             : #include <com/sun/star/uno/Reference.h>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <osl/mutex.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : #include "dlelstnr.hxx"
      34             : #include <proofreadingiterator.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          42 : SwLinguServiceEventListener::SwLinguServiceEventListener()
      47             : {
      48          42 :     Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
      49             :     try
      50             :     {
      51          42 :         xDesktop = frame::Desktop::create(xContext);
      52          42 :         xDesktop->addTerminateListener( this );
      53             : 
      54          42 :         xLngSvcMgr = LinguServiceManager::create(xContext);
      55          42 :         xLngSvcMgr->addLinguServiceManagerListener( static_cast<XLinguServiceEventListener *>(this) );
      56             : 
      57          42 :         if (SvtLinguConfig().HasGrammarChecker())
      58             :         {
      59           0 :             xGCIterator = sw::proofreadingiterator::get(xContext);
      60           0 :             Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
      61           0 :             if (xBC.is())
      62           0 :                 xBC->addLinguServiceEventListener( static_cast<XLinguServiceEventListener *>(this) );
      63             :         }
      64             :     }
      65           0 :     catch (const uno::Exception&)
      66             :     {
      67             :         OSL_FAIL("exception caught in SwLinguServiceEventListener c-tor" );
      68          42 :     }
      69          42 : }
      70             : 
      71          40 : SwLinguServiceEventListener::~SwLinguServiceEventListener()
      72             : {
      73          40 : }
      74             : 
      75           1 : void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
      76             :             const LinguServiceEvent& rLngSvcEvent )
      77             :         throw(RuntimeException, std::exception)
      78             : {
      79           1 :     SolarMutexGuard aGuard;
      80             : 
      81           1 :     bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
      82           1 :     bool bIsSpellAll   = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
      83           1 :     if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
      84           0 :         bIsSpellWrong = bIsSpellAll = true;     // have all spelling and grammar checked...
      85           1 :     if (bIsSpellWrong || bIsSpellAll)
      86             :     {
      87           1 :         SwModule::CheckSpellChanges( false, bIsSpellWrong, bIsSpellAll, false );
      88             :     }
      89           1 :     if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
      90             :     {
      91           1 :         SwView *pSwView = SwModule::GetFirstView();
      92             : 
      93             :         //!! since this function may be called within the ctor of
      94             :         //!! SwView (during formatting) where the WrtShell is not yet
      95             :         //!! created, we have to check for the WrtShellPtr to see
      96             :         //!! if it is already availbale
      97           3 :         while (pSwView && pSwView->GetWrtShellPtr())
      98             :         {
      99           1 :             pSwView->GetWrtShell().ChgHyphenation();
     100           1 :             pSwView = SwModule::GetNextView( pSwView );
     101             :         }
     102           1 :     }
     103           1 : }
     104             : 
     105          84 : void SAL_CALL SwLinguServiceEventListener::disposing(
     106             :             const EventObject& rEventObj )
     107             :         throw(RuntimeException, std::exception)
     108             : {
     109          84 :     SolarMutexGuard aGuard;
     110             : 
     111          84 :     if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
     112          22 :         xLngSvcMgr = 0;
     113          84 :     if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
     114           0 :         xGCIterator = 0;
     115          84 : }
     116             : 
     117          20 : void SAL_CALL SwLinguServiceEventListener::queryTermination(
     118             :             const EventObject& /*rEventObj*/ )
     119             :         throw(TerminationVetoException, RuntimeException, std::exception)
     120             : {
     121          20 : }
     122             : 
     123          20 : void SAL_CALL SwLinguServiceEventListener::notifyTermination(
     124             :             const EventObject& rEventObj )
     125             :         throw(RuntimeException, std::exception)
     126             : {
     127          20 :     SolarMutexGuard aGuard;
     128             : 
     129          20 :     if (xDesktop.is()  &&  rEventObj.Source == xDesktop)
     130             :     {
     131          20 :         if (xLngSvcMgr.is())
     132          20 :             xLngSvcMgr = 0;
     133          20 :         if (xGCIterator.is())
     134           0 :             xGCIterator = 0;
     135          20 :         xDesktop = NULL;
     136          20 :     }
     137         197 : }
     138             : 
     139             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11