LCOV - code coverage report
Current view: top level - sw/source/ui/uno - dlelstnr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 67 59.7 %
Date: 2012-08-25 Functions: 6 8 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 51 158 32.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
      31                 :            : #include <com/sun/star/linguistic2/XDictionaryList.hpp>
      32                 :            : #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
      33                 :            : #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
      34                 :            : #include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
      35                 :            : #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
      36                 :            : 
      37                 :            : #include <unotools/lingucfg.hxx>
      38                 :            : 
      39                 :            : #include <com/sun/star/uno/Reference.h>
      40                 :            : #include <comphelper/processfactory.hxx>
      41                 :            : #include <osl/mutex.hxx>
      42                 :            : #include <vcl/svapp.hxx>
      43                 :            : #include <tools/shl.hxx>
      44                 :            : #include "dlelstnr.hxx"
      45                 :            : #include <swmodule.hxx>
      46                 :            : #include <wrtsh.hxx>
      47                 :            : #include <view.hxx>
      48                 :            : 
      49                 :            : using ::rtl::OUString;
      50                 :            : using namespace ::com::sun::star;
      51                 :            : using namespace ::com::sun::star::lang;
      52                 :            : using namespace ::com::sun::star::frame;
      53                 :            : using namespace ::com::sun::star::uno;
      54                 :            : using namespace ::com::sun::star::linguistic2;
      55                 :            : using namespace ::com::sun::star::linguistic2::LinguServiceEventFlags;
      56                 :            : 
      57                 :         47 : SwLinguServiceEventListener::SwLinguServiceEventListener()
      58                 :            : {
      59         [ +  - ]:         47 :     Reference< XMultiServiceFactory > xMgr( comphelper::getProcessServiceFactory() );
      60         [ +  - ]:         47 :     if (xMgr.is())
      61                 :            :     {
      62                 :            :         try
      63                 :            :         {
      64                 :         47 :             OUString aSvcName( OUString( "com.sun.star.frame.Desktop" ) );
      65                 :            :             xDesktop = Reference< frame::XDesktop >(
      66 [ +  - ][ +  - ]:         47 :                     xMgr->createInstance( aSvcName ), UNO_QUERY );
         [ +  - ][ +  - ]
      67         [ +  - ]:         47 :             if (xDesktop.is())
      68 [ +  - ][ +  - ]:         47 :                 xDesktop->addTerminateListener( this );
                 [ +  - ]
      69                 :            : 
      70                 :         47 :             aSvcName = OUString( "com.sun.star.linguistic2.LinguServiceManager" );
      71 [ +  - ][ +  - ]:         47 :             xLngSvcMgr = Reference< XLinguServiceManager >( xMgr->createInstance( aSvcName ), UNO_QUERY );
         [ +  - ][ +  - ]
      72         [ +  + ]:         47 :             if (xLngSvcMgr.is())
      73 [ +  - ][ +  - ]:         26 :                 xLngSvcMgr->addLinguServiceManagerListener( (XLinguServiceEventListener *) this );
                 [ +  - ]
      74                 :            : 
      75 [ +  - ][ +  - ]:         47 :             if (SvtLinguConfig().HasGrammarChecker())
         [ +  - ][ +  + ]
      76                 :            :             {
      77                 :         26 :                 aSvcName = OUString( "com.sun.star.linguistic2.ProofreadingIterator" );
      78 [ +  - ][ +  - ]:         26 :                 xGCIterator = Reference< XProofreadingIterator >( xMgr->createInstance( aSvcName ), UNO_QUERY );
         [ +  - ][ +  - ]
      79         [ +  - ]:         26 :                 Reference< XLinguServiceEventBroadcaster > xBC( xGCIterator, UNO_QUERY );
      80         [ +  - ]:         26 :                 if (xBC.is())
      81 [ +  - ][ +  - ]:         26 :                     xBC->addLinguServiceEventListener( (XLinguServiceEventListener *) this );
                 [ +  - ]
      82         [ #  # ]:         47 :             }
      83                 :            :         }
      84         [ #  # ]:          0 :         catch (const uno::Exception&)
      85                 :            :         {
      86                 :            :             OSL_FAIL("exception caught in SwLinguServiceEventListener c-tor" );
      87                 :            :         }
      88                 :         47 :     }
      89                 :         47 : }
      90                 :            : 
      91                 :         26 : SwLinguServiceEventListener::~SwLinguServiceEventListener()
      92                 :            : {
      93         [ -  + ]:         52 : }
      94                 :            : 
      95                 :          0 : void SwLinguServiceEventListener::processDictionaryListEvent(
      96                 :            :             const DictionaryListEvent& rDicListEvent)
      97                 :            :         throw( RuntimeException )
      98                 :            : {
      99         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     100                 :            : 
     101                 :          0 :     sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
     102                 :            : 
     103                 :            :     sal_Int16 nSpellWrongFlags =
     104                 :            :             DictionaryListEventFlags::ADD_POS_ENTRY     |
     105                 :            :             DictionaryListEventFlags::DEL_NEG_ENTRY     |
     106                 :            :             DictionaryListEventFlags::ACTIVATE_POS_DIC  |
     107                 :          0 :             DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
     108                 :          0 :     sal_Bool bIsSpellWrong  =  0 != (nEvt & nSpellWrongFlags);
     109                 :            :     sal_Int16 nSpellAllFlags =
     110                 :            :             DictionaryListEventFlags::ADD_NEG_ENTRY     |
     111                 :            :             DictionaryListEventFlags::DEL_POS_ENTRY     |
     112                 :            :             DictionaryListEventFlags::ACTIVATE_NEG_DIC  |
     113                 :          0 :             DictionaryListEventFlags::DEACTIVATE_POS_DIC;
     114                 :          0 :     sal_Bool bIsSpellAll    =  0 != (nEvt & nSpellAllFlags);
     115                 :            : 
     116 [ #  # ][ #  # ]:          0 :     if (bIsSpellWrong || bIsSpellAll)
     117 [ #  # ][ #  # ]:          0 :         SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False );
                 [ #  # ]
     118                 :          0 : }
     119                 :            : 
     120                 :          0 : void SAL_CALL SwLinguServiceEventListener::processLinguServiceEvent(
     121                 :            :             const LinguServiceEvent& rLngSvcEvent )
     122                 :            :         throw(RuntimeException)
     123                 :            : {
     124         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     125                 :            : 
     126                 :          0 :     sal_Bool bIsSpellWrong = 0 != (rLngSvcEvent.nEvent & SPELL_WRONG_WORDS_AGAIN);
     127                 :          0 :     sal_Bool bIsSpellAll   = 0 != (rLngSvcEvent.nEvent & SPELL_CORRECT_WORDS_AGAIN);
     128         [ #  # ]:          0 :     if (0 != (rLngSvcEvent.nEvent & PROOFREAD_AGAIN))
     129                 :          0 :         bIsSpellWrong = bIsSpellAll = sal_True;     // have all spelling and grammar checked...
     130 [ #  # ][ #  # ]:          0 :     if (bIsSpellWrong || bIsSpellAll)
     131                 :            :     {
     132 [ #  # ][ #  # ]:          0 :         SW_MOD()->CheckSpellChanges( sal_False, bIsSpellWrong, bIsSpellAll, sal_False );
     133                 :            :     }
     134         [ #  # ]:          0 :     if (rLngSvcEvent.nEvent & HYPHENATE_AGAIN)
     135                 :            :     {
     136 [ #  # ][ #  # ]:          0 :         SwView *pSwView = SW_MOD()->GetFirstView();
     137                 :            : 
     138                 :            :         //!! since this function may be called within the ctor of
     139                 :            :         //!! SwView (during formatting) where the WrtShell is not yet
     140                 :            :         //!! created, we have to check for the WrtShellPtr to see
     141                 :            :         //!! if it is already availbale
     142 [ #  # ][ #  # ]:          0 :         while (pSwView && pSwView->GetWrtShellPtr())
                 [ #  # ]
     143                 :            :         {
     144         [ #  # ]:          0 :             pSwView->GetWrtShell().ChgHyphenation();
     145 [ #  # ][ #  # ]:          0 :             pSwView = SW_MOD()->GetNextView( pSwView );
     146                 :            :         }
     147         [ #  # ]:          0 :     }
     148                 :          0 : }
     149                 :            : 
     150                 :         73 : void SAL_CALL SwLinguServiceEventListener::disposing(
     151                 :            :             const EventObject& rEventObj )
     152                 :            :         throw(RuntimeException)
     153                 :            : {
     154         [ +  - ]:         73 :     SolarMutexGuard aGuard;
     155                 :            : 
     156 [ -  + ][ #  # ]:         73 :     if (xLngSvcMgr.is() && rEventObj.Source == xLngSvcMgr)
         [ #  # ][ -  + ]
     157         [ #  # ]:          0 :         xLngSvcMgr = 0;
     158 [ -  + ][ #  # ]:         73 :     if (xLngSvcMgr.is() && rEventObj.Source == xGCIterator)
         [ #  # ][ -  + ]
     159 [ #  # ][ +  - ]:         73 :         xGCIterator = 0;
     160                 :         73 : }
     161                 :            : 
     162                 :         26 : void SAL_CALL SwLinguServiceEventListener::queryTermination(
     163                 :            :             const EventObject& /*rEventObj*/ )
     164                 :            :         throw(TerminationVetoException, RuntimeException)
     165                 :            : {
     166                 :         26 : }
     167                 :            : 
     168                 :         26 : void SAL_CALL SwLinguServiceEventListener::notifyTermination(
     169                 :            :             const EventObject& rEventObj )
     170                 :            :         throw(RuntimeException)
     171                 :            : {
     172         [ +  - ]:         26 :     SolarMutexGuard aGuard;
     173                 :            : 
     174 [ +  - ][ +  - ]:         26 :     if (xDesktop.is()  &&  rEventObj.Source == xDesktop)
         [ +  - ][ +  - ]
     175                 :            :     {
     176         [ +  - ]:         26 :         if (xLngSvcMgr.is())
     177         [ +  - ]:         26 :             xLngSvcMgr = 0;
     178         [ +  - ]:         26 :         if (xGCIterator.is())
     179         [ +  - ]:         26 :             xGCIterator = 0;
     180         [ +  - ]:         26 :         xDesktop = NULL;
     181         [ +  - ]:         26 :     }
     182                 :         26 : }
     183                 :            : 
     184                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10