LibreOffice Module sc (master) 1
adiasync.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <algorithm>
23
24#include <sfx2/objsh.hxx>
25
26#include <adiasync.hxx>
27#include <brdcst.hxx>
28#include <document.hxx>
29#include <osl/diagnose.h>
30#include <osl/thread.h>
31
33
34extern "C" {
35void CALLTYPE ScAddInAsyncCallBack( double& nHandle, void* pData )
36{
38}
39}
40
42 pStr( nullptr ),
43 mpFuncData(pFuncData),
44 nHandle( nHandleP ),
45 meType(pFuncData->GetAsyncType()),
46 bValid( false )
47{
48 pDocs.reset(new ScAddInDocs);
49 pDocs->insert( pDoc );
50 theAddInAsyncTbl.emplace( this );
51}
52
54{
55 // in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
56 mpFuncData->Unadvice( static_cast<double>(nHandle) );
57 if ( meType == ParamType::PTR_STRING && pStr ) // include type comparison because of union
58 delete pStr;
59 pDocs.reset();
60}
61
63{
64 ScAddInAsync* pRet = nullptr;
65 auto it = std::find_if(
67 [nHandleP](std::unique_ptr<ScAddInAsync> const & el)
68 { return el->nHandle == nHandleP; });
69 if ( it != theAddInAsyncTbl.end() )
70 pRet = it->get();
71 return pRet;
72}
73
74void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
75{
76 auto asyncIt = std::find_if(
78 [nHandleP](std::unique_ptr<ScAddInAsync> const & el)
79 { return el->nHandle == nHandleP; });
80 if ( asyncIt == theAddInAsyncTbl.end() )
81 return;
82 ScAddInAsync* p = asyncIt->get();
83
84 if ( !p->HasListeners() )
85 {
86 // not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
87 theAddInAsyncTbl.erase( asyncIt );
88 return ;
89 }
90 switch ( p->meType )
91 {
93 p->nVal = *static_cast<double*>(pData);
94 break;
96 {
97 char* pChar = static_cast<char*>(pData);
98 if ( p->pStr )
99 *p->pStr = OUString( pChar, strlen(pChar),osl_getThreadTextEncoding() );
100 else
101 p->pStr = new OUString( pChar, strlen(pChar), osl_getThreadTextEncoding() );
102 break;
103 }
104 default :
105 OSL_FAIL( "unknown AsyncType" );
106 return;
107 }
108 p->bValid = true;
109 p->Broadcast( ScHint(SfxHintId::ScDataChanged, ScAddress()) );
110
111 for ( ScDocument* pDoc : *p->pDocs )
112 {
113 pDoc->TrackFormulas();
114 pDoc->GetDocumentShell()->Broadcast( SfxHint( SfxHintId::ScDataChanged ) );
115 }
116}
117
119{
120 for( ScAddInAsyncs::reverse_iterator iter1 = theAddInAsyncTbl.rbegin(); iter1 != theAddInAsyncTbl.rend(); ++iter1 )
121 { // backwards because of pointer-movement in array
122 ScAddInAsync* pAsync = iter1->get();
123 ScAddInDocs* p = pAsync->pDocs.get();
124 ScAddInDocs::iterator iter2 = p->find( pDocumentP );
125 if( iter2 != p->end() )
126 {
127 p->erase( iter2 );
128 if ( p->empty() )
129 { // this AddIn is not used anymore
130 theAddInAsyncTbl.erase( --(iter1.base()) );
131 }
132 }
133 }
134}
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScAddInAsyncs theAddInAsyncTbl
Definition: adiasync.cxx:32
void CALLTYPE ScAddInAsyncCallBack(double &nHandle, void *pData)
Definition: adiasync.cxx:35
std::set< ScDocument * > ScAddInDocs
Definition: adiasync.hxx:33
std::set< std::unique_ptr< ScAddInAsync >, CompareScAddInAsync > ScAddInAsyncs
Definition: adiasync.hxx:73
#define CALLTYPE
Definition: callform.hxx:31
void Unadvice(double nHandle)
Definition: callform.cxx:324
static ScAddInAsync * Get(sal_uLong nHandle)
Definition: adiasync.cxx:62
virtual ~ScAddInAsync() override
Definition: adiasync.cxx:53
static void CallBack(sal_uLong nHandle, void *pData)
Definition: adiasync.cxx:74
sal_uLong nHandle
Definition: adiasync.hxx:45
std::unique_ptr< ScAddInDocs > pDocs
Definition: adiasync.hxx:43
ParamType meType
Definition: adiasync.hxx:46
static void RemoveDocument(ScDocument *pDocument)
Definition: adiasync.cxx:118
LegacyFuncData * mpFuncData
Definition: adiasync.hxx:44
ScAddInAsync(sal_uLong nHandle, LegacyFuncData *pFuncData, ScDocument *pDoc)
Definition: adiasync.cxx:41
OUString * pStr
Definition: adiasync.hxx:41
void TrackFormulas(SfxHintId nHintId=SfxHintId::ScDataChanged)
Definition: documen7.cxx:524
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1083
void * p
std::unique_ptr< sal_Int32[]> pData
sal_Int32 nHandle
sal_uIntPtr sal_uLong
RedlineType meType
const char * pChar