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

Generated by: LCOV version 1.10