fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / tool / adiasync.cxx
blob5daecfaf85d38cd1f2068c9046797724dcaac562
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include "brdcst.hxx"
24 #include "global.hxx"
25 #include "document.hxx"
26 #include "sc.hrc"
27 #include <osl/diagnose.h>
28 #include <osl/thread.h>
30 ScAddInAsyncs theAddInAsyncTbl;
31 static ScAddInAsync aSeekObj;
33 extern "C" {
34 void CALLTYPE ScAddInAsyncCallBack( double& nHandle, void* pData )
36 ScAddInAsync::CallBack( sal_uLong( nHandle ), pData );
40 ScAddInAsync::ScAddInAsync() :
41 SvtBroadcaster(),
42 pDocs( NULL ),
43 mpFuncData( NULL ),
44 nHandle( 0 ),
45 meType( ParamType::NONE ),
46 bValid( false )
47 { // nur fuer aSeekObj !
50 ScAddInAsync::ScAddInAsync(sal_uLong nHandleP, FuncData* pFuncData, ScDocument* pDoc) :
51 SvtBroadcaster(),
52 pStr( NULL ),
53 mpFuncData(pFuncData),
54 nHandle( nHandleP ),
55 meType(pFuncData->GetAsyncType()),
56 bValid( false )
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
66 if ( nHandle )
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
71 delete pStr;
72 delete pDocs;
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() )
82 pRet = *it;
83 aSeekObj.nHandle = 0;
84 return pRet;
87 void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
89 ScAddInAsync* p;
90 if ( (p = Get( nHandleP )) == NULL )
91 return;
93 if ( !p->HasListeners() )
95 // not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
96 theAddInAsyncTbl.erase( p );
97 delete p;
98 return ;
100 switch ( p->meType )
102 case ParamType::PTR_DOUBLE :
103 p->nVal = *static_cast<double*>(pData);
104 break;
105 case ParamType::PTR_STRING :
107 sal_Char* pChar = static_cast<sal_Char*>(pData);
108 if ( p->pStr )
109 *p->pStr = OUString( pChar, strlen(pChar),osl_getThreadTextEncoding() );
110 else
111 p->pStr = new OUString( pChar, strlen(pChar), osl_getThreadTextEncoding() );
112 break;
114 default :
115 OSL_FAIL( "unknown AsyncType" );
116 return;
118 p->bValid = true;
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() )
140 p->erase( iter2 );
141 if ( p->empty() )
142 { // this AddIn is not used anymore
143 theAddInAsyncTbl.erase( --(iter1.base()) );
144 delete pAsync;
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */