LCOV - code coverage report
Current view: top level - sc/source/core/tool - adiasync.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 11 64 17.2 %
Date: 2015-06-13 12:38:46 Functions: 5 10 50.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             : #include <sfx2/objsh.hxx>
      21             : 
      22             : #include "adiasync.hxx"
      23             : #include "brdcst.hxx"
      24             : #include "global.hxx"
      25             : #include "document.hxx"
      26             : #include "sc.hrc"
      27             : #include <osl/diagnose.h>
      28             : #include <osl/thread.h>
      29             : 
      30          52 : ScAddInAsyncs theAddInAsyncTbl;
      31          52 : static ScAddInAsync aSeekObj;
      32             : 
      33             : extern "C" {
      34           0 : void CALLTYPE ScAddInAsyncCallBack( double& nHandle, void* pData )
      35             : {
      36           0 :     ScAddInAsync::CallBack( sal_uLong( nHandle ), pData );
      37           0 : }
      38             : }
      39             : 
      40          52 : ScAddInAsync::ScAddInAsync() :
      41             :     SvtBroadcaster(),
      42             :     pDocs( NULL ),
      43             :     mpFuncData( NULL ),
      44             :     nHandle( 0 ),
      45             :     meType( ParamType::NONE ),
      46          52 :     bValid( false )
      47             : {   // nur fuer aSeekObj !
      48          52 : }
      49             : 
      50           0 : ScAddInAsync::ScAddInAsync(sal_uLong nHandleP, FuncData* pFuncData, ScDocument* pDoc) :
      51             :     SvtBroadcaster(),
      52             :     pStr( NULL ),
      53             :     mpFuncData(pFuncData),
      54             :     nHandle( nHandleP ),
      55           0 :     meType(pFuncData->GetAsyncType()),
      56           0 :     bValid( false )
      57             : {
      58           0 :     pDocs = new ScAddInDocs();
      59           0 :     pDocs->insert( pDoc );
      60           0 :     theAddInAsyncTbl.insert( this );
      61           0 : }
      62             : 
      63         104 : ScAddInAsync::~ScAddInAsync()
      64             : {
      65             :     // aSeekObj does not have that, handle 0 does not exist otherwise
      66          52 :     if ( nHandle )
      67             :     {
      68             :         // in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
      69           0 :         mpFuncData->Unadvice( (double)nHandle );
      70           0 :         if ( meType == ParamType::PTR_STRING && pStr )      // include type comparison because of union
      71           0 :             delete pStr;
      72           0 :         delete pDocs;
      73             :     }
      74          52 : }
      75             : 
      76           0 : ScAddInAsync* ScAddInAsync::Get( sal_uLong nHandleP )
      77             : {
      78           0 :     ScAddInAsync* pRet = 0;
      79           0 :     aSeekObj.nHandle = nHandleP;
      80           0 :     ScAddInAsyncs::iterator it = theAddInAsyncTbl.find( &aSeekObj );
      81           0 :     if ( it != theAddInAsyncTbl.end() )
      82           0 :         pRet = *it;
      83           0 :     aSeekObj.nHandle = 0;
      84           0 :     return pRet;
      85             : }
      86             : 
      87           0 : void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
      88             : {
      89             :     ScAddInAsync* p;
      90           0 :     if ( (p = Get( nHandleP )) == NULL )
      91           0 :         return;
      92             : 
      93           0 :     if ( !p->HasListeners() )
      94             :     {
      95             :         // not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
      96           0 :         theAddInAsyncTbl.erase( p );
      97           0 :         delete p;
      98           0 :         return ;
      99             :     }
     100           0 :     switch ( p->meType )
     101             :     {
     102             :         case ParamType::PTR_DOUBLE :
     103           0 :             p->nVal = *static_cast<double*>(pData);
     104           0 :             break;
     105             :         case ParamType::PTR_STRING :
     106             :         {
     107           0 :             sal_Char* pChar = static_cast<sal_Char*>(pData);
     108           0 :             if ( p->pStr )
     109           0 :                 *p->pStr = OUString( pChar, strlen(pChar),osl_getThreadTextEncoding() );
     110             :             else
     111           0 :                 p->pStr = new OUString( pChar, strlen(pChar), osl_getThreadTextEncoding() );
     112           0 :             break;
     113             :         }
     114             :         default :
     115             :             OSL_FAIL( "unknown AsyncType" );
     116           0 :             return;
     117             :     }
     118           0 :     p->bValid = true;
     119           0 :     p->Broadcast( ScHint(SC_HINT_DATACHANGED, ScAddress()) );
     120             : 
     121           0 :     for ( ScAddInDocs::iterator it = p->pDocs->begin(); it != p->pDocs->end(); ++it )
     122             :     {
     123           0 :         ScDocument* pDoc = *it;
     124           0 :         pDoc->TrackFormulas();
     125           0 :         pDoc->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
     126             :     }
     127             : }
     128             : 
     129        2287 : void ScAddInAsync::RemoveDocument( ScDocument* pDocumentP )
     130             : {
     131        2287 :     if ( !theAddInAsyncTbl.empty() )
     132             :     {
     133           0 :         for( ScAddInAsyncs::reverse_iterator iter1 = theAddInAsyncTbl.rbegin(); iter1 != theAddInAsyncTbl.rend(); ++iter1 )
     134             :         {   // backwards because of pointer-movement in array
     135           0 :             ScAddInAsync* pAsync = *iter1;
     136           0 :             ScAddInDocs* p = pAsync->pDocs;
     137           0 :             ScAddInDocs::iterator iter2 = p->find( pDocumentP );
     138           0 :             if( iter2 != p->end() )
     139             :             {
     140           0 :                 p->erase( iter2 );
     141           0 :                 if ( p->empty() )
     142             :                 {   // this AddIn is not used anymore
     143           0 :                     theAddInAsyncTbl.erase( --(iter1.base()) );
     144           0 :                     delete pAsync;
     145             :                 }
     146             :             }
     147             :         }
     148             :     }
     149        2443 : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11