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/diagnose.h>
28 #include <osl/thread.h>
30 ScAddInAsyncs theAddInAsyncTbl
;
31 static ScAddInAsync aSeekObj
;
34 void CALLTYPE
ScAddInAsyncCallBack( double& nHandle
, void* pData
)
36 ScAddInAsync::CallBack( sal_uLong( nHandle
), pData
);
40 ScAddInAsync::ScAddInAsync() :
45 meType( ParamType::NONE
),
47 { // nur fuer aSeekObj !
50 ScAddInAsync::ScAddInAsync(sal_uLong nHandleP
, FuncData
* pFuncData
, ScDocument
* pDoc
) :
53 mpFuncData(pFuncData
),
55 meType(pFuncData
->GetAsyncType()),
58 pDocs
= new ScAddInDocs();
59 pDocs
->insert( pDoc
);
60 theAddInAsyncTbl
.insert( this );
63 ScAddInAsync::~ScAddInAsync()
65 // aSeekObj does not have that, handle 0 does not exist otherwise
68 // in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
69 mpFuncData
->Unadvice( (double)nHandle
);
70 if ( meType
== ParamType::PTR_STRING
&& pStr
) // include type comparison because of union
76 ScAddInAsync
* ScAddInAsync::Get( sal_uLong nHandleP
)
78 ScAddInAsync
* pRet
= 0;
79 aSeekObj
.nHandle
= nHandleP
;
80 ScAddInAsyncs::iterator it
= theAddInAsyncTbl
.find( &aSeekObj
);
81 if ( it
!= theAddInAsyncTbl
.end() )
87 void ScAddInAsync::CallBack( sal_uLong nHandleP
, void* pData
)
90 if ( (p
= Get( nHandleP
)) == NULL
)
93 if ( !p
->HasListeners() )
95 // not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
96 theAddInAsyncTbl
.erase( p
);
102 case ParamType::PTR_DOUBLE
:
103 p
->nVal
= *static_cast<double*>(pData
);
105 case ParamType::PTR_STRING
:
107 sal_Char
* pChar
= static_cast<sal_Char
*>(pData
);
109 *p
->pStr
= OUString( pChar
, strlen(pChar
),osl_getThreadTextEncoding() );
111 p
->pStr
= new OUString( pChar
, strlen(pChar
), osl_getThreadTextEncoding() );
115 OSL_FAIL( "unknown AsyncType" );
119 p
->Broadcast( ScHint(SC_HINT_DATACHANGED
, ScAddress()) );
121 for ( ScAddInDocs::iterator it
= p
->pDocs
->begin(); it
!= p
->pDocs
->end(); ++it
)
123 ScDocument
* pDoc
= *it
;
124 pDoc
->TrackFormulas();
125 pDoc
->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED
) );
129 void ScAddInAsync::RemoveDocument( ScDocument
* pDocumentP
)
131 if ( !theAddInAsyncTbl
.empty() )
133 for( ScAddInAsyncs::reverse_iterator iter1
= theAddInAsyncTbl
.rbegin(); iter1
!= theAddInAsyncTbl
.rend(); ++iter1
)
134 { // backwards because of pointer-movement in array
135 ScAddInAsync
* pAsync
= *iter1
;
136 ScAddInDocs
* p
= pAsync
->pDocs
;
137 ScAddInDocs::iterator iter2
= p
->find( pDocumentP
);
138 if( iter2
!= p
->end() )
142 { // this AddIn is not used anymore
143 theAddInAsyncTbl
.erase( --(iter1
.base()) );
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */