tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / core / tool / adiasync.cxx
blobba2b49eb3896958e8ec74a530b4000e956ea8c06
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 <sal/config.h>
22 #include <algorithm>
24 #include <sfx2/objsh.hxx>
26 #include <adiasync.hxx>
27 #include <brdcst.hxx>
28 #include <document.hxx>
29 #include <docsh.hxx>
30 #include <osl/diagnose.h>
31 #include <osl/thread.h>
33 ScAddInAsyncs theAddInAsyncTbl;
35 extern "C" {
36 void CALLTYPE ScAddInAsyncCallBack( double& nHandle, void* pData )
38 ScAddInAsync::CallBack( sal_uLong( nHandle ), pData );
42 ScAddInAsync::ScAddInAsync(sal_uLong nHandleP, LegacyFuncData* pFuncData, ScDocument* pDoc) :
43 pStr( nullptr ),
44 mpFuncData(pFuncData),
45 nHandle( nHandleP ),
46 meType(pFuncData->GetAsyncType()),
47 bValid( false )
49 pDocs.reset(new ScAddInDocs);
50 pDocs->insert( pDoc );
51 theAddInAsyncTbl.emplace( this );
54 ScAddInAsync::~ScAddInAsync()
56 // in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
57 mpFuncData->Unadvice( static_cast<double>(nHandle) );
58 if ( meType == ParamType::PTR_STRING && pStr ) // include type comparison because of union
59 delete pStr;
60 pDocs.reset();
63 ScAddInAsync* ScAddInAsync::Get( sal_uLong nHandleP )
65 ScAddInAsync* pRet = nullptr;
66 auto it = std::find_if(
67 theAddInAsyncTbl.begin(), theAddInAsyncTbl.end(),
68 [nHandleP](std::unique_ptr<ScAddInAsync> const & el)
69 { return el->nHandle == nHandleP; });
70 if ( it != theAddInAsyncTbl.end() )
71 pRet = it->get();
72 return pRet;
75 void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
77 auto asyncIt = std::find_if(
78 theAddInAsyncTbl.begin(), theAddInAsyncTbl.end(),
79 [nHandleP](std::unique_ptr<ScAddInAsync> const & el)
80 { return el->nHandle == nHandleP; });
81 if ( asyncIt == theAddInAsyncTbl.end() )
82 return;
83 ScAddInAsync* p = asyncIt->get();
85 if ( !p->HasListeners() )
87 // not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
88 theAddInAsyncTbl.erase( asyncIt );
89 return ;
91 switch ( p->meType )
93 case ParamType::PTR_DOUBLE :
94 p->nVal = *static_cast<double*>(pData);
95 break;
96 case ParamType::PTR_STRING :
98 char* pChar = static_cast<char*>(pData);
99 if ( p->pStr )
100 *p->pStr = OUString( pChar, strlen(pChar),osl_getThreadTextEncoding() );
101 else
102 p->pStr = new OUString( pChar, strlen(pChar), osl_getThreadTextEncoding() );
103 break;
105 default :
106 OSL_FAIL( "unknown AsyncType" );
107 return;
109 p->bValid = true;
110 p->Broadcast( ScHint(SfxHintId::ScDataChanged, ScAddress()) );
112 for ( ScDocument* pDoc : *p->pDocs )
114 pDoc->TrackFormulas();
115 pDoc->GetDocumentShell()->Broadcast( SfxHint( SfxHintId::ScDataChanged ) );
119 void ScAddInAsync::RemoveDocument( ScDocument* pDocumentP )
121 for( ScAddInAsyncs::reverse_iterator iter1 = theAddInAsyncTbl.rbegin(); iter1 != theAddInAsyncTbl.rend(); ++iter1 )
122 { // backwards because of pointer-movement in array
123 ScAddInAsync* pAsync = iter1->get();
124 ScAddInDocs* p = pAsync->pDocs.get();
125 ScAddInDocs::iterator iter2 = p->find( pDocumentP );
126 if( iter2 != p->end() )
128 p->erase( iter2 );
129 if ( p->empty() )
130 { // this AddIn is not used anymore
131 theAddInAsyncTbl.erase( --(iter1.base()) );
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */