1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: adiasync.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------------
38 #include <sfx2/objsh.hxx>
40 #include "adiasync.hxx"
43 #include "document.hxx"
44 #include "sc.hrc" // FID_DATACHANGED
45 #include <osl/thread.h>
48 //------------------------------------------------------------------------
50 ScAddInAsyncs theAddInAsyncTbl
;
51 static ScAddInAsync aSeekObj
;
54 SV_IMPL_OP_PTRARR_SORT( ScAddInAsyncs
, ScAddInAsyncPtr
);
56 SV_IMPL_PTRARR_SORT( ScAddInDocs
, ScAddInDocPtr
);
59 void CALLTYPE
ScAddInAsyncCallBack( double& nHandle
, void* pData
)
61 ScAddInAsync::CallBack( ULONG( nHandle
), pData
);
67 ScAddInAsync::ScAddInAsync() :
70 { // nur fuer aSeekObj !
75 ScAddInAsync::ScAddInAsync( ULONG nHandleP
, USHORT nIndex
, ScDocument
* pDoc
) :
81 pDocs
= new ScAddInDocs( 1, 1 );
82 pDocs
->Insert( pDoc
);
83 pFuncData
= (FuncData
*)ScGlobal::GetFuncCollection()->At(nIndex
);
84 eType
= pFuncData
->GetAsyncType();
85 theAddInAsyncTbl
.Insert( this );
90 ScAddInAsync::~ScAddInAsync()
92 // aSeekObj hat das alles nicht, Handle 0 gibt es sonst nicht
95 // im dTor wg. theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
96 pFuncData
->Unadvice( (double)nHandle
);
97 if ( eType
== PTR_STRING
&& pStr
) // mit Typvergleich wg. Union!
105 ScAddInAsync
* ScAddInAsync::Get( ULONG nHandleP
)
108 ScAddInAsync
* pRet
= 0;
109 aSeekObj
.nHandle
= nHandleP
;
110 if ( theAddInAsyncTbl
.Seek_Entry( &aSeekObj
, &nPos
) )
111 pRet
= theAddInAsyncTbl
[ nPos
];
112 aSeekObj
.nHandle
= 0;
118 void ScAddInAsync::CallBack( ULONG nHandleP
, void* pData
)
121 if ( (p
= Get( nHandleP
)) == NULL
)
123 // keiner mehr dran? Unadvice und weg damit
124 if ( !p
->HasListeners() )
126 // nicht im dTor wg. theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
127 theAddInAsyncTbl
.Remove( p
);
134 p
->nVal
= *(double*)pData
;
138 *p
->pStr
= String( (sal_Char
*)pData
, osl_getThreadTextEncoding() );
140 p
->pStr
= new String( (sal_Char
*)pData
, osl_getThreadTextEncoding() );
143 DBG_ERROR( "unbekannter AsyncType" );
147 p
->Broadcast( ScHint( SC_HINT_DATACHANGED
, ScAddress(), NULL
) );
149 const ScDocument
** ppDoc
= (const ScDocument
**) p
->pDocs
->GetData();
150 USHORT nCount
= p
->pDocs
->Count();
151 for ( USHORT j
=0; j
<nCount
; j
++, ppDoc
++ )
153 ScDocument
* pDoc
= (ScDocument
*)*ppDoc
;
154 pDoc
->TrackFormulas();
155 pDoc
->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED
) );
156 pDoc
->ResetChanged( ScRange(0,0,0,MAXCOL
,MAXROW
,MAXTAB
) );
162 void ScAddInAsync::RemoveDocument( ScDocument
* pDocumentP
)
164 USHORT nPos
= theAddInAsyncTbl
.Count();
167 const ScAddInAsync
** ppAsync
=
168 (const ScAddInAsync
**) theAddInAsyncTbl
.GetData() + nPos
- 1;
169 for ( ; nPos
-- >0; ppAsync
-- )
170 { // rueckwaerts wg. Pointer-Aufrueckerei im Array
171 ScAddInDocs
* p
= ((ScAddInAsync
*)*ppAsync
)->pDocs
;
173 if ( p
->Seek_Entry( pDocumentP
, &nFoundPos
) )
175 p
->Remove( nFoundPos
);
176 if ( p
->Count() == 0 )
177 { // dieses AddIn wird nicht mehr benutzt
178 ScAddInAsync
* pAsync
= (ScAddInAsync
*)*ppAsync
;
179 theAddInAsyncTbl
.Remove( nPos
);
181 ppAsync
= (const ScAddInAsync
**) theAddInAsyncTbl
.GetData()