2010-10-12 15:59:00 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-30 12:23:25 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 23:16:46 +00:00
|
|
|
|
|
|
|
#include <sfx2/objsh.hxx>
|
|
|
|
|
|
|
|
#include "adiasync.hxx"
|
|
|
|
#include "brdcst.hxx"
|
|
|
|
#include "global.hxx"
|
|
|
|
#include "document.hxx"
|
|
|
|
#include "sc.hrc" // FID_DATACHANGED
|
|
|
|
#include <osl/thread.h>
|
|
|
|
|
|
|
|
ScAddInAsyncs theAddInAsyncTbl;
|
|
|
|
static ScAddInAsync aSeekObj;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
void CALLTYPE ScAddInAsyncCallBack( double& nHandle, void* pData )
|
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
ScAddInAsync::CallBack( sal_uLong( nHandle ), pData );
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScAddInAsync::ScAddInAsync() :
|
2004-06-04 09:33:01 +00:00
|
|
|
SvtBroadcaster(),
|
2000-09-18 23:16:46 +00:00
|
|
|
nHandle( 0 )
|
|
|
|
{ // nur fuer aSeekObj !
|
|
|
|
}
|
|
|
|
|
2012-02-06 21:22:29 -05:00
|
|
|
ScAddInAsync::ScAddInAsync(sal_uLong nHandleP, FuncData* pFuncData, ScDocument* pDoc) :
|
2004-06-04 09:33:01 +00:00
|
|
|
SvtBroadcaster(),
|
2000-09-18 23:16:46 +00:00
|
|
|
pStr( NULL ),
|
2012-02-06 21:22:29 -05:00
|
|
|
mpFuncData(pFuncData),
|
2000-09-18 23:16:46 +00:00
|
|
|
nHandle( nHandleP ),
|
2012-02-06 21:22:29 -05:00
|
|
|
meType(pFuncData->GetAsyncType()),
|
2011-03-10 16:55:21 -05:00
|
|
|
bValid( false )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2012-07-09 16:02:05 +02:00
|
|
|
pDocs = new ScAddInDocs();
|
|
|
|
pDocs->insert( pDoc );
|
2012-07-09 16:32:39 +02:00
|
|
|
theAddInAsyncTbl.insert( this );
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScAddInAsync::~ScAddInAsync()
|
|
|
|
{
|
2012-08-28 21:28:28 +02:00
|
|
|
// aSeekObj does not have that, handle 0 does not exist otherwise
|
2000-09-18 23:16:46 +00:00
|
|
|
if ( nHandle )
|
|
|
|
{
|
2012-08-28 21:28:28 +02:00
|
|
|
// in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
|
2012-02-06 21:22:29 -05:00
|
|
|
mpFuncData->Unadvice( (double)nHandle );
|
2012-08-28 21:28:28 +02:00
|
|
|
if ( meType == PTR_STRING && pStr ) // include type comparison because of union
|
2000-09-18 23:16:46 +00:00
|
|
|
delete pStr;
|
|
|
|
delete pDocs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
ScAddInAsync* ScAddInAsync::Get( sal_uLong nHandleP )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
ScAddInAsync* pRet = 0;
|
|
|
|
aSeekObj.nHandle = nHandleP;
|
2012-07-09 16:32:39 +02:00
|
|
|
ScAddInAsyncs::iterator it = theAddInAsyncTbl.find( &aSeekObj );
|
|
|
|
if ( it != theAddInAsyncTbl.end() )
|
|
|
|
pRet = *it;
|
2000-09-18 23:16:46 +00:00
|
|
|
aSeekObj.nHandle = 0;
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
ScAddInAsync* p;
|
2007-02-27 11:11:51 +00:00
|
|
|
if ( (p = Get( nHandleP )) == NULL )
|
2000-09-18 23:16:46 +00:00
|
|
|
return;
|
2012-08-28 21:28:28 +02:00
|
|
|
|
2000-09-18 23:16:46 +00:00
|
|
|
if ( !p->HasListeners() )
|
|
|
|
{
|
2012-08-28 21:28:28 +02:00
|
|
|
// not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
|
2012-07-09 16:32:39 +02:00
|
|
|
theAddInAsyncTbl.erase( p );
|
2000-09-18 23:16:46 +00:00
|
|
|
delete p;
|
|
|
|
return ;
|
|
|
|
}
|
2012-02-06 21:22:29 -05:00
|
|
|
switch ( p->meType )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
case PTR_DOUBLE :
|
|
|
|
p->nVal = *(double*)pData;
|
|
|
|
break;
|
|
|
|
case PTR_STRING :
|
|
|
|
if ( p->pStr )
|
|
|
|
*p->pStr = String( (sal_Char*)pData, osl_getThreadTextEncoding() );
|
|
|
|
else
|
|
|
|
p->pStr = new String( (sal_Char*)pData, osl_getThreadTextEncoding() );
|
|
|
|
break;
|
|
|
|
default :
|
2013-03-16 04:58:29 +01:00
|
|
|
OSL_FAIL( "unknown AsyncType" );
|
2000-09-18 23:16:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-01-17 13:20:22 +01:00
|
|
|
p->bValid = sal_True;
|
2013-05-09 10:20:39 -04:00
|
|
|
p->Broadcast( ScHint(SC_HINT_DATACHANGED, ScAddress()) );
|
2000-09-18 23:16:46 +00:00
|
|
|
|
2012-07-09 16:02:05 +02:00
|
|
|
for ( ScAddInDocs::iterator it = p->pDocs->begin(); it != p->pDocs->end(); ++it )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2012-07-09 16:02:05 +02:00
|
|
|
ScDocument* pDoc = *it;
|
2000-09-18 23:16:46 +00:00
|
|
|
pDoc->TrackFormulas();
|
|
|
|
pDoc->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScAddInAsync::RemoveDocument( ScDocument* pDocumentP )
|
|
|
|
{
|
2012-07-09 16:32:39 +02:00
|
|
|
if ( !theAddInAsyncTbl.empty() )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2012-07-09 16:32:39 +02:00
|
|
|
for( ScAddInAsyncs::reverse_iterator iter1 = theAddInAsyncTbl.rbegin(); iter1 != theAddInAsyncTbl.rend(); ++iter1 )
|
2012-08-28 21:28:28 +02:00
|
|
|
{ // backwards because of pointer-movement in array
|
2012-07-09 16:32:39 +02:00
|
|
|
ScAddInAsync* pAsync = *iter1;
|
|
|
|
ScAddInDocs* p = pAsync->pDocs;
|
2012-07-09 16:02:05 +02:00
|
|
|
ScAddInDocs::iterator iter2 = p->find( pDocumentP );
|
|
|
|
if( iter2 != p->end() )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2012-07-09 16:02:05 +02:00
|
|
|
p->erase( iter2 );
|
|
|
|
if ( p->empty() )
|
2012-08-28 21:28:28 +02:00
|
|
|
{ // this AddIn is not used anymore
|
2012-07-09 16:32:39 +02:00
|
|
|
theAddInAsyncTbl.erase( --(iter1.base()) );
|
2000-09-18 23:16:46 +00:00
|
|
|
delete pAsync;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:59:00 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|