LCOV - code coverage report
Current view: top level - sc/source/core/tool - addinlis.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 6 57 10.5 %
Date: 2014-11-03 Functions: 3 13 23.1 %
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 <sfx2/objsh.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : 
      23             : #include "addinlis.hxx"
      24             : #include "miscuno.hxx"
      25             : #include "document.hxx"
      26             : #include "brdcst.hxx"
      27             : #include "sc.hrc"
      28             : 
      29             : using namespace com::sun::star;
      30             : 
      31           0 : SC_SIMPLE_SERVICE_INFO( ScAddInListener, "ScAddInListener", "stardiv.one.sheet.AddInListener" )
      32             : 
      33          76 : ::std::list<ScAddInListener*> ScAddInListener::aAllListeners;
      34             : 
      35           0 : ScAddInListener* ScAddInListener::CreateListener(
      36             :                         uno::Reference<sheet::XVolatileResult> xVR, ScDocument* pDoc )
      37             : {
      38           0 :     ScAddInListener* pNew = new ScAddInListener( xVR, pDoc );
      39             : 
      40           0 :     pNew->acquire(); // for aAllListeners
      41           0 :     aAllListeners.push_back( pNew );
      42             : 
      43           0 :     if ( xVR.is() )
      44           0 :         xVR->addResultListener( pNew ); // after at least 1 ref exists!
      45             : 
      46           0 :     return pNew;
      47             : }
      48             : 
      49           0 : ScAddInListener::ScAddInListener( uno::Reference<sheet::XVolatileResult> xVR, ScDocument* pDoc ) :
      50           0 :     xVolRes( xVR )
      51             : {
      52           0 :     pDocs = new ScAddInDocs();
      53           0 :     pDocs->insert( pDoc );
      54           0 : }
      55             : 
      56           0 : ScAddInListener::~ScAddInListener()
      57             : {
      58           0 :     delete pDocs;
      59           0 : }
      60             : 
      61           0 : ScAddInListener* ScAddInListener::Get( uno::Reference<sheet::XVolatileResult> xVR )
      62             : {
      63           0 :     ScAddInListener* pLst = NULL;
      64           0 :     sheet::XVolatileResult* pComp = xVR.get();
      65             : 
      66           0 :     for(::std::list<ScAddInListener*>::iterator iter = aAllListeners.begin(); iter != aAllListeners.end(); ++iter)
      67             :     {
      68           0 :         if ( pComp == (sheet::XVolatileResult*)(*iter)->xVolRes.get() )
      69             :         {
      70           0 :             pLst = *iter;
      71           0 :             break;
      72             :         }
      73             :     }
      74           0 :     return pLst;
      75             : }
      76             : 
      77             : //! move to some container object?
      78        4192 : void ScAddInListener::RemoveDocument( ScDocument* pDocumentP )
      79             : {
      80        4192 :     ::std::list<ScAddInListener*>::iterator iter = aAllListeners.begin();
      81        8384 :     while(iter != aAllListeners.end())
      82             :     {
      83           0 :         ScAddInDocs* p = (*iter)->pDocs;
      84           0 :         ScAddInDocs::iterator iter2 = p->find( pDocumentP );
      85           0 :         if( iter2 != p->end() )
      86             :         {
      87           0 :             p->erase( iter2 );
      88           0 :             if ( p->empty() )
      89             :             {
      90           0 :                 if ( (*iter)->xVolRes.is() )
      91           0 :                     (*iter)->xVolRes->removeResultListener( *iter );
      92             : 
      93           0 :                 (*iter)->release(); // Ref for aAllListeners - pLst may be deleted here
      94             : 
      95             :                 // this AddIn is no longer used
      96             :                 // dont delete, just remove the ref for the list
      97             : 
      98           0 :                 iter = aAllListeners.erase( iter );
      99           0 :                 continue;
     100             :             }
     101             :         }
     102           0 :         ++iter;
     103             :     }
     104        4192 : }
     105             : 
     106             : // XResultListener
     107             : 
     108           0 : void SAL_CALL ScAddInListener::modified( const ::com::sun::star::sheet::ResultEvent& aEvent )
     109             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception)
     110             : {
     111           0 :     SolarMutexGuard aGuard; //! or generate a UserEvent
     112             : 
     113           0 :     aResult = aEvent.Value; // store result
     114             : 
     115             :     // notify document of changes
     116             : 
     117           0 :     Broadcast( ScHint(SC_HINT_DATACHANGED, ScAddress()) );
     118             : 
     119           0 :     for ( ScAddInDocs::iterator it = pDocs->begin(); it != pDocs->end(); ++it )
     120             :     {
     121           0 :         ScDocument* pDoc = *it;
     122           0 :         pDoc->TrackFormulas();
     123           0 :         pDoc->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
     124           0 :     }
     125           0 : }
     126             : 
     127             : // XEventListener
     128             : 
     129           0 : void SAL_CALL ScAddInListener::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
     130             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception)
     131             : {
     132             :     // hold a ref so this is not deleted at removeResultListener
     133           0 :     uno::Reference<sheet::XResultListener> xRef( this );
     134             : 
     135           0 :     if ( xVolRes.is() )
     136             :     {
     137           0 :         xVolRes->removeResultListener( this );
     138           0 :         xVolRes = NULL;
     139           0 :     }
     140         228 : }
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10