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

Generated by: LCOV version 1.10