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

Generated by: LCOV version 1.10