1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/objsh.hxx>
22 #include "adiasync.hxx"
25 #include "document.hxx"
27 #include <osl/thread.h>
29 ScAddInAsyncs theAddInAsyncTbl
;
30 static ScAddInAsync aSeekObj
;
33 void CALLTYPE
ScAddInAsyncCallBack( double& nHandle
, void* pData
)
35 ScAddInAsync::CallBack( sal_uLong( nHandle
), pData
);
39 ScAddInAsync::ScAddInAsync() :
42 { // nur fuer aSeekObj !
45 ScAddInAsync::ScAddInAsync(sal_uLong nHandleP
, FuncData
* pFuncData
, ScDocument
* pDoc
) :
48 mpFuncData(pFuncData
),
50 meType(pFuncData
->GetAsyncType()),
53 pDocs
= new ScAddInDocs();
54 pDocs
->insert( pDoc
);
55 theAddInAsyncTbl
.insert( this );
58 ScAddInAsync::~ScAddInAsync()
60 // aSeekObj does not have that, handle 0 does not exist otherwise
63 // in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
64 mpFuncData
->Unadvice( (double)nHandle
);
65 if ( meType
== PTR_STRING
&& pStr
) // include type comparison because of union
71 ScAddInAsync
* ScAddInAsync::Get( sal_uLong nHandleP
)
73 ScAddInAsync
* pRet
= 0;
74 aSeekObj
.nHandle
= nHandleP
;
75 ScAddInAsyncs::iterator it
= theAddInAsyncTbl
.find( &aSeekObj
);
76 if ( it
!= theAddInAsyncTbl
.end() )
82 void ScAddInAsync::CallBack( sal_uLong nHandleP
, void* pData
)
85 if ( (p
= Get( nHandleP
)) == NULL
)
88 if ( !p
->HasListeners() )
90 // not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
91 theAddInAsyncTbl
.erase( p
);
98 p
->nVal
= *(double*)pData
;
102 sal_Char
* pChar
= (sal_Char
*)pData
;
104 *p
->pStr
= OUString( pChar
, strlen(pChar
),osl_getThreadTextEncoding() );
106 p
->pStr
= new OUString( pChar
, strlen(pChar
), osl_getThreadTextEncoding() );
110 OSL_FAIL( "unknown AsyncType" );
113 p
->bValid
= sal_True
;
114 p
->Broadcast( ScHint(SC_HINT_DATACHANGED
, ScAddress()) );
116 for ( ScAddInDocs::iterator it
= p
->pDocs
->begin(); it
!= p
->pDocs
->end(); ++it
)
118 ScDocument
* pDoc
= *it
;
119 pDoc
->TrackFormulas();
120 pDoc
->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED
) );
124 void ScAddInAsync::RemoveDocument( ScDocument
* pDocumentP
)
126 if ( !theAddInAsyncTbl
.empty() )
128 for( ScAddInAsyncs::reverse_iterator iter1
= theAddInAsyncTbl
.rbegin(); iter1
!= theAddInAsyncTbl
.rend(); ++iter1
)
129 { // backwards because of pointer-movement in array
130 ScAddInAsync
* pAsync
= *iter1
;
131 ScAddInDocs
* p
= pAsync
->pDocs
;
132 ScAddInDocs::iterator iter2
= p
->find( pDocumentP
);
133 if( iter2
!= p
->end() )
137 { // this AddIn is not used anymore
138 theAddInAsyncTbl
.erase( --(iter1
.base()) );
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */