Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sfx2/objsh.hxx>
21 :
22 : #include "adiasync.hxx"
23 : #include "brdcst.hxx"
24 : #include "global.hxx"
25 : #include "document.hxx"
26 : #include "sc.hrc" // FID_DATACHANGED
27 : #include <osl/thread.h>
28 :
29 :
30 : //------------------------------------------------------------------------
31 :
32 5 : ScAddInAsyncs theAddInAsyncTbl;
33 5 : static ScAddInAsync aSeekObj;
34 :
35 :
36 : extern "C" {
37 0 : void CALLTYPE ScAddInAsyncCallBack( double& nHandle, void* pData )
38 : {
39 0 : ScAddInAsync::CallBack( sal_uLong( nHandle ), pData );
40 0 : }
41 : }
42 :
43 :
44 :
45 5 : ScAddInAsync::ScAddInAsync() :
46 : SvtBroadcaster(),
47 5 : nHandle( 0 )
48 : { // nur fuer aSeekObj !
49 5 : }
50 :
51 :
52 :
53 0 : ScAddInAsync::ScAddInAsync(sal_uLong nHandleP, FuncData* pFuncData, ScDocument* pDoc) :
54 : SvtBroadcaster(),
55 : pStr( NULL ),
56 : mpFuncData(pFuncData),
57 : nHandle( nHandleP ),
58 0 : meType(pFuncData->GetAsyncType()),
59 0 : bValid( false )
60 : {
61 0 : pDocs = new ScAddInDocs();
62 0 : pDocs->insert( pDoc );
63 0 : theAddInAsyncTbl.insert( this );
64 0 : }
65 :
66 :
67 :
68 10 : ScAddInAsync::~ScAddInAsync()
69 : {
70 : // aSeekObj does not have that, handle 0 does not exist otherwise
71 5 : if ( nHandle )
72 : {
73 : // in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
74 0 : mpFuncData->Unadvice( (double)nHandle );
75 0 : if ( meType == PTR_STRING && pStr ) // include type comparison because of union
76 0 : delete pStr;
77 0 : delete pDocs;
78 : }
79 5 : }
80 :
81 :
82 :
83 0 : ScAddInAsync* ScAddInAsync::Get( sal_uLong nHandleP )
84 : {
85 0 : ScAddInAsync* pRet = 0;
86 0 : aSeekObj.nHandle = nHandleP;
87 0 : ScAddInAsyncs::iterator it = theAddInAsyncTbl.find( &aSeekObj );
88 0 : if ( it != theAddInAsyncTbl.end() )
89 0 : pRet = *it;
90 0 : aSeekObj.nHandle = 0;
91 0 : return pRet;
92 : }
93 :
94 :
95 :
96 0 : void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
97 : {
98 : ScAddInAsync* p;
99 0 : if ( (p = Get( nHandleP )) == NULL )
100 : return;
101 :
102 0 : if ( !p->HasListeners() )
103 : {
104 : // not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
105 0 : theAddInAsyncTbl.erase( p );
106 0 : delete p;
107 : return ;
108 : }
109 0 : switch ( p->meType )
110 : {
111 : case PTR_DOUBLE :
112 0 : p->nVal = *(double*)pData;
113 0 : break;
114 : case PTR_STRING :
115 0 : if ( p->pStr )
116 0 : *p->pStr = String( (sal_Char*)pData, osl_getThreadTextEncoding() );
117 : else
118 0 : p->pStr = new String( (sal_Char*)pData, osl_getThreadTextEncoding() );
119 0 : break;
120 : default :
121 : OSL_FAIL( "unbekannter AsyncType" );
122 : return;
123 : }
124 0 : p->bValid = sal_True;
125 0 : p->Broadcast( ScHint( SC_HINT_DATACHANGED, ScAddress(), NULL ) );
126 :
127 0 : for ( ScAddInDocs::iterator it = p->pDocs->begin(); it != p->pDocs->end(); ++it )
128 : {
129 0 : ScDocument* pDoc = *it;
130 0 : pDoc->TrackFormulas();
131 0 : pDoc->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
132 : }
133 : }
134 :
135 :
136 :
137 111 : void ScAddInAsync::RemoveDocument( ScDocument* pDocumentP )
138 : {
139 111 : if ( !theAddInAsyncTbl.empty() )
140 : {
141 0 : for( ScAddInAsyncs::reverse_iterator iter1 = theAddInAsyncTbl.rbegin(); iter1 != theAddInAsyncTbl.rend(); ++iter1 )
142 : { // backwards because of pointer-movement in array
143 0 : ScAddInAsync* pAsync = *iter1;
144 0 : ScAddInDocs* p = pAsync->pDocs;
145 0 : ScAddInDocs::iterator iter2 = p->find( pDocumentP );
146 0 : if( iter2 != p->end() )
147 : {
148 0 : p->erase( iter2 );
149 0 : if ( p->empty() )
150 : { // this AddIn is not used anymore
151 0 : theAddInAsyncTbl.erase( --(iter1.base()) );
152 0 : delete pAsync;
153 : }
154 : }
155 : }
156 : }
157 126 : }
158 :
159 :
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|