1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir //------------------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <sfx2/objsh.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "adiasync.hxx"
34cdf0e10cSrcweir #include "brdcst.hxx"
35cdf0e10cSrcweir #include "global.hxx"
36cdf0e10cSrcweir #include "document.hxx"
37cdf0e10cSrcweir #include "sc.hrc" // FID_DATACHANGED
38cdf0e10cSrcweir #include <osl/thread.h>
39cdf0e10cSrcweir
40cdf0e10cSrcweir
41cdf0e10cSrcweir //------------------------------------------------------------------------
42cdf0e10cSrcweir
43cdf0e10cSrcweir ScAddInAsyncs theAddInAsyncTbl;
44cdf0e10cSrcweir static ScAddInAsync aSeekObj;
45cdf0e10cSrcweir
46cdf0e10cSrcweir
47cdf0e10cSrcweir SV_IMPL_OP_PTRARR_SORT( ScAddInAsyncs, ScAddInAsyncPtr );
48cdf0e10cSrcweir
49cdf0e10cSrcweir SV_IMPL_PTRARR_SORT( ScAddInDocs, ScAddInDocPtr );
50cdf0e10cSrcweir
51cdf0e10cSrcweir extern "C" {
ScAddInAsyncCallBack(double & nHandle,void * pData)52cdf0e10cSrcweir void CALLTYPE ScAddInAsyncCallBack( double& nHandle, void* pData )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir ScAddInAsync::CallBack( sal_uLong( nHandle ), pData );
55cdf0e10cSrcweir }
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
58cdf0e10cSrcweir
59cdf0e10cSrcweir
ScAddInAsync()60cdf0e10cSrcweir ScAddInAsync::ScAddInAsync() :
61cdf0e10cSrcweir SvtBroadcaster(),
62cdf0e10cSrcweir nHandle( 0 )
63cdf0e10cSrcweir { // nur fuer aSeekObj !
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
66cdf0e10cSrcweir
67cdf0e10cSrcweir
ScAddInAsync(sal_uLong nHandleP,sal_uInt16 nIndex,ScDocument * pDoc)68cdf0e10cSrcweir ScAddInAsync::ScAddInAsync( sal_uLong nHandleP, sal_uInt16 nIndex, ScDocument* pDoc ) :
69cdf0e10cSrcweir SvtBroadcaster(),
70cdf0e10cSrcweir pStr( NULL ),
71cdf0e10cSrcweir nHandle( nHandleP ),
72cdf0e10cSrcweir bValid( sal_False )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir pDocs = new ScAddInDocs( 1, 1 );
75cdf0e10cSrcweir pDocs->Insert( pDoc );
76cdf0e10cSrcweir pFuncData = (FuncData*)ScGlobal::GetFuncCollection()->At(nIndex);
77cdf0e10cSrcweir eType = pFuncData->GetAsyncType();
78cdf0e10cSrcweir theAddInAsyncTbl.Insert( this );
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
81cdf0e10cSrcweir
82cdf0e10cSrcweir
~ScAddInAsync()83cdf0e10cSrcweir ScAddInAsync::~ScAddInAsync()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir // aSeekObj hat das alles nicht, Handle 0 gibt es sonst nicht
86cdf0e10cSrcweir if ( nHandle )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir // im dTor wg. theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
89cdf0e10cSrcweir pFuncData->Unadvice( (double)nHandle );
90cdf0e10cSrcweir if ( eType == PTR_STRING && pStr ) // mit Typvergleich wg. Union!
91cdf0e10cSrcweir delete pStr;
92cdf0e10cSrcweir delete pDocs;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir
97cdf0e10cSrcweir
Get(sal_uLong nHandleP)98cdf0e10cSrcweir ScAddInAsync* ScAddInAsync::Get( sal_uLong nHandleP )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir sal_uInt16 nPos;
101cdf0e10cSrcweir ScAddInAsync* pRet = 0;
102cdf0e10cSrcweir aSeekObj.nHandle = nHandleP;
103cdf0e10cSrcweir if ( theAddInAsyncTbl.Seek_Entry( &aSeekObj, &nPos ) )
104cdf0e10cSrcweir pRet = theAddInAsyncTbl[ nPos ];
105cdf0e10cSrcweir aSeekObj.nHandle = 0;
106cdf0e10cSrcweir return pRet;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir
110cdf0e10cSrcweir
CallBack(sal_uLong nHandleP,void * pData)111cdf0e10cSrcweir void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir ScAddInAsync* p;
114cdf0e10cSrcweir if ( (p = Get( nHandleP )) == NULL )
115cdf0e10cSrcweir return;
116cdf0e10cSrcweir // keiner mehr dran? Unadvice und weg damit
117cdf0e10cSrcweir if ( !p->HasListeners() )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir // nicht im dTor wg. theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
120cdf0e10cSrcweir theAddInAsyncTbl.Remove( p );
121cdf0e10cSrcweir delete p;
122cdf0e10cSrcweir return ;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir switch ( p->eType )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir case PTR_DOUBLE :
127cdf0e10cSrcweir p->nVal = *(double*)pData;
128cdf0e10cSrcweir break;
129cdf0e10cSrcweir case PTR_STRING :
130cdf0e10cSrcweir if ( p->pStr )
131cdf0e10cSrcweir *p->pStr = String( (sal_Char*)pData, osl_getThreadTextEncoding() );
132cdf0e10cSrcweir else
133cdf0e10cSrcweir p->pStr = new String( (sal_Char*)pData, osl_getThreadTextEncoding() );
134cdf0e10cSrcweir break;
135cdf0e10cSrcweir default :
136cdf0e10cSrcweir DBG_ERROR( "unbekannter AsyncType" );
137cdf0e10cSrcweir return;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir p->bValid = sal_True;
140cdf0e10cSrcweir p->Broadcast( ScHint( SC_HINT_DATACHANGED, ScAddress(), NULL ) );
141cdf0e10cSrcweir
142cdf0e10cSrcweir const ScDocument** ppDoc = (const ScDocument**) p->pDocs->GetData();
143cdf0e10cSrcweir sal_uInt16 nCount = p->pDocs->Count();
144cdf0e10cSrcweir for ( sal_uInt16 j=0; j<nCount; j++, ppDoc++ )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir ScDocument* pDoc = (ScDocument*)*ppDoc;
147cdf0e10cSrcweir pDoc->TrackFormulas();
148cdf0e10cSrcweir pDoc->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
149cdf0e10cSrcweir pDoc->ResetChanged( ScRange(0,0,0,MAXCOL,MAXROW,MAXTAB) );
150cdf0e10cSrcweir }
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir
154cdf0e10cSrcweir
RemoveDocument(ScDocument * pDocumentP)155cdf0e10cSrcweir void ScAddInAsync::RemoveDocument( ScDocument* pDocumentP )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir sal_uInt16 nPos = theAddInAsyncTbl.Count();
158cdf0e10cSrcweir if ( nPos )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir const ScAddInAsync** ppAsync =
161cdf0e10cSrcweir (const ScAddInAsync**) theAddInAsyncTbl.GetData() + nPos - 1;
162cdf0e10cSrcweir for ( ; nPos-- >0; ppAsync-- )
163cdf0e10cSrcweir { // rueckwaerts wg. Pointer-Aufrueckerei im Array
164cdf0e10cSrcweir ScAddInDocs* p = ((ScAddInAsync*)*ppAsync)->pDocs;
165cdf0e10cSrcweir sal_uInt16 nFoundPos;
166cdf0e10cSrcweir if ( p->Seek_Entry( pDocumentP, &nFoundPos ) )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir p->Remove( nFoundPos );
169cdf0e10cSrcweir if ( p->Count() == 0 )
170cdf0e10cSrcweir { // dieses AddIn wird nicht mehr benutzt
171cdf0e10cSrcweir ScAddInAsync* pAsync = (ScAddInAsync*)*ppAsync;
172cdf0e10cSrcweir theAddInAsyncTbl.Remove( nPos );
173cdf0e10cSrcweir delete pAsync;
174cdf0e10cSrcweir ppAsync = (const ScAddInAsync**) theAddInAsyncTbl.GetData()
175cdf0e10cSrcweir + nPos;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir
183cdf0e10cSrcweir
184