merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / tool / adiasync.cxx
blobbdca9fee31254cc4ddb170e70e7a9fcddccba23d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: adiasync.cxx,v $
10 * $Revision: 1.6 $
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"
41 #include "brdcst.hxx"
42 #include "global.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 );
58 extern "C" {
59 void CALLTYPE ScAddInAsyncCallBack( double& nHandle, void* pData )
61 ScAddInAsync::CallBack( ULONG( nHandle ), pData );
67 ScAddInAsync::ScAddInAsync() :
68 SvtBroadcaster(),
69 nHandle( 0 )
70 { // nur fuer aSeekObj !
75 ScAddInAsync::ScAddInAsync( ULONG nHandleP, USHORT nIndex, ScDocument* pDoc ) :
76 SvtBroadcaster(),
77 pStr( NULL ),
78 nHandle( nHandleP ),
79 bValid( FALSE )
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
93 if ( nHandle )
95 // im dTor wg. theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
96 pFuncData->Unadvice( (double)nHandle );
97 if ( eType == PTR_STRING && pStr ) // mit Typvergleich wg. Union!
98 delete pStr;
99 delete pDocs;
105 ScAddInAsync* ScAddInAsync::Get( ULONG nHandleP )
107 USHORT nPos;
108 ScAddInAsync* pRet = 0;
109 aSeekObj.nHandle = nHandleP;
110 if ( theAddInAsyncTbl.Seek_Entry( &aSeekObj, &nPos ) )
111 pRet = theAddInAsyncTbl[ nPos ];
112 aSeekObj.nHandle = 0;
113 return pRet;
118 void ScAddInAsync::CallBack( ULONG nHandleP, void* pData )
120 ScAddInAsync* p;
121 if ( (p = Get( nHandleP )) == NULL )
122 return;
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 );
128 delete p;
129 return ;
131 switch ( p->eType )
133 case PTR_DOUBLE :
134 p->nVal = *(double*)pData;
135 break;
136 case PTR_STRING :
137 if ( p->pStr )
138 *p->pStr = String( (sal_Char*)pData, osl_getThreadTextEncoding() );
139 else
140 p->pStr = new String( (sal_Char*)pData, osl_getThreadTextEncoding() );
141 break;
142 default :
143 DBG_ERROR( "unbekannter AsyncType" );
144 return;
146 p->bValid = TRUE;
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();
165 if ( nPos )
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;
172 USHORT nFoundPos;
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 );
180 delete pAsync;
181 ppAsync = (const ScAddInAsync**) theAddInAsyncTbl.GetData()
182 + nPos;