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

Generated by: LCOV version 1.10