fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / tool / callform.cxx
blob64cc52bb8b43248ee6c640a63174d5988a26775c
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 <boost/noncopyable.hpp>
23 #include <vcl/svapp.hxx>
24 #include <vcl/settings.hxx>
25 #include <osl/module.hxx>
26 #include <osl/file.hxx>
27 #include <unotools/transliterationwrapper.hxx>
29 #include "callform.hxx"
30 #include "global.hxx"
31 #include "adiasync.hxx"
33 extern "C" {
35 typedef void (CALLTYPE* ExFuncPtr1)(void*);
36 typedef void (CALLTYPE* ExFuncPtr2)(void*, void*);
37 typedef void (CALLTYPE* ExFuncPtr3)(void*, void*, void*);
38 typedef void (CALLTYPE* ExFuncPtr4)(void*, void*, void*, void*);
39 typedef void (CALLTYPE* ExFuncPtr5)(void*, void*, void*, void*, void*);
40 typedef void (CALLTYPE* ExFuncPtr6)(void*, void*, void*, void*, void*, void*);
41 typedef void (CALLTYPE* ExFuncPtr7)(void*, void*, void*, void*, void*, void*, void*);
42 typedef void (CALLTYPE* ExFuncPtr8)(void*, void*, void*, void*, void*, void*, void*, void*);
43 typedef void (CALLTYPE* ExFuncPtr9)(void*, void*, void*, void*, void*, void*, void*, void*, void*);
44 typedef void (CALLTYPE* ExFuncPtr10)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
45 typedef void (CALLTYPE* ExFuncPtr11)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
46 typedef void (CALLTYPE* ExFuncPtr12)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
47 typedef void (CALLTYPE* ExFuncPtr13)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
48 typedef void (CALLTYPE* ExFuncPtr14)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
49 typedef void (CALLTYPE* ExFuncPtr15)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
50 typedef void (CALLTYPE* ExFuncPtr16)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
52 typedef void (CALLTYPE* GetFuncCountPtr)(sal_uInt16& nCount);
53 typedef void (CALLTYPE* GetFuncDataPtr)
54 (sal_uInt16& nNo, sal_Char* pFuncName, sal_uInt16& nParamCount, ParamType* peType, sal_Char* pInternalName);
56 typedef void (CALLTYPE* SetLanguagePtr)( sal_uInt16& nLanguage );
57 typedef void (CALLTYPE* GetParamDesc)
58 (sal_uInt16& nNo, sal_uInt16& nParam, sal_Char* pName, sal_Char* pDesc );
60 typedef void (CALLTYPE* IsAsync) ( sal_uInt16& nNo,
61 ParamType* peType );
62 typedef void (CALLTYPE* Advice) ( sal_uInt16& nNo,
63 AdvData& pfCallback );
64 typedef void (CALLTYPE* Unadvice)( double& nHandle );
66 typedef void (CALLTYPE* FARPROC) ( void );
70 #ifndef DISABLE_DYNLOADING
71 #define GETFUNCTIONCOUNT "GetFunctionCount"
72 #define GETFUNCTIONDATA "GetFunctionData"
73 #define SETLANGUAGE "SetLanguage"
74 #define GETPARAMDESC "GetParameterDescription"
75 #define ISASYNC "IsAsync"
76 #define ADVICE "Advice"
77 #define UNADVICE "Unadvice"
78 #endif
80 class ModuleData: private boost::noncopyable
82 friend class ModuleCollection;
83 OUString aName;
84 osl::Module* pInstance;
85 public:
86 ModuleData(const OUString& rStr, osl::Module* pInst) : aName(rStr), pInstance(pInst) {}
87 ~ModuleData() { delete pInstance; }
89 const OUString& GetName() const { return aName; }
90 osl::Module* GetInstance() const { return pInstance; }
93 FuncData::FuncData(const ModuleData*pModule,
94 const OUString& rIName,
95 const OUString& rFName,
96 sal_uInt16 nNo,
97 sal_uInt16 nCount,
98 const ParamType* peType,
99 ParamType eType) :
100 pModuleData (pModule),
101 aInternalName (rIName),
102 aFuncName (rFName),
103 nNumber (nNo),
104 nParamCount (nCount),
105 eAsyncType (eType)
107 for (sal_uInt16 i = 0; i < MAXFUNCPARAM; i++)
108 eParamType[i] = peType[i];
111 FuncData::FuncData(const FuncData& rData) :
112 pModuleData (rData.pModuleData),
113 aInternalName (rData.aInternalName),
114 aFuncName (rData.aFuncName),
115 nNumber (rData.nNumber),
116 nParamCount (rData.nParamCount),
117 eAsyncType (rData.eAsyncType)
119 for (sal_uInt16 i = 0; i < MAXFUNCPARAM; i++)
120 eParamType[i] = rData.eParamType[i];
123 namespace {
125 class ModuleCollection
127 typedef boost::ptr_map<OUString, ModuleData> MapType;
128 MapType maData;
129 public:
130 ModuleCollection() {}
132 const ModuleData* findByName(const OUString& rName) const;
133 void insert(ModuleData* pNew);
134 void clear();
137 const ModuleData* ModuleCollection::findByName(const OUString& rName) const
139 MapType::const_iterator it = maData.find(rName);
140 return it == maData.end() ? NULL : it->second;
143 void ModuleCollection::insert(ModuleData* pNew)
145 if (!pNew)
146 return;
148 OUString aName = pNew->GetName();
149 maData.insert(aName, pNew);
152 void ModuleCollection::clear()
154 maData.clear();
157 ModuleCollection aModuleCollection;
161 bool InitExternalFunc(const OUString& rModuleName)
163 #ifdef DISABLE_DYNLOADING
164 (void) rModuleName;
165 return false;
166 #else
167 // Module already loaded?
168 const ModuleData* pTemp = aModuleCollection.findByName(rModuleName);
169 if (pTemp)
170 return false;
172 OUString aNP;
173 aNP = rModuleName;
175 bool bRet = false;
176 osl::Module* pLib = new osl::Module( aNP );
177 if (pLib->is())
179 FARPROC fpGetCount = (FARPROC)pLib->getFunctionSymbol(GETFUNCTIONCOUNT);
180 FARPROC fpGetData = (FARPROC)pLib->getFunctionSymbol(GETFUNCTIONDATA);
181 if ((fpGetCount != NULL) && (fpGetData != NULL))
183 FARPROC fpIsAsync = (FARPROC)pLib->getFunctionSymbol(ISASYNC);
184 FARPROC fpAdvice = (FARPROC)pLib->getFunctionSymbol(ADVICE);
185 FARPROC fpSetLanguage = (FARPROC)pLib->getFunctionSymbol(SETLANGUAGE);
186 if ( fpSetLanguage )
188 LanguageType eLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType();
189 sal_uInt16 nLanguage = (sal_uInt16) eLanguage;
190 (*reinterpret_cast<SetLanguagePtr>(fpSetLanguage))( nLanguage );
193 // Module in die Collection aufnehmen
194 ModuleData* pModuleData = new ModuleData(rModuleName, pLib);
195 aModuleCollection.insert(pModuleData);
197 // Schnittstelle initialisieren
198 AdvData pfCallBack = &ScAddInAsyncCallBack;
199 FuncCollection* pFuncCol = ScGlobal::GetFuncCollection();
200 sal_uInt16 nCount;
201 (*reinterpret_cast<GetFuncCountPtr>(fpGetCount))(nCount);
202 for (sal_uInt16 i=0; i < nCount; i++)
204 sal_Char cFuncName[256];
205 sal_Char cInternalName[256];
206 sal_uInt16 nParamCount;
207 ParamType eParamType[MAXFUNCPARAM];
208 ParamType eAsyncType = ParamType::NONE;
209 // initialize all, in case the AddIn behaves bad
210 cFuncName[0] = 0;
211 cInternalName[0] = 0;
212 nParamCount = 0;
213 for ( sal_uInt16 j=0; j<MAXFUNCPARAM; j++ )
215 eParamType[j] = ParamType::NONE;
217 (*reinterpret_cast<GetFuncDataPtr>(fpGetData))(i, cFuncName, nParamCount,
218 eParamType, cInternalName);
219 if( fpIsAsync )
221 (*reinterpret_cast<IsAsync>(fpIsAsync))(i, &eAsyncType);
222 if ( fpAdvice && eAsyncType != ParamType::NONE )
223 (*reinterpret_cast<Advice>(fpAdvice))( i, pfCallBack );
225 OUString aInternalName( cInternalName, strlen(cInternalName), osl_getThreadTextEncoding() );
226 OUString aFuncName( cFuncName, strlen(cFuncName), osl_getThreadTextEncoding() );
227 FuncData* pFuncData = new FuncData( pModuleData,
228 aInternalName,
229 aFuncName,
231 nParamCount,
232 eParamType,
233 eAsyncType );
234 pFuncCol->insert(pFuncData);
236 bRet = true;
238 else
239 delete pLib;
241 else
242 delete pLib;
243 return bRet;
244 #endif
247 void ExitExternalFunc()
249 aModuleCollection.clear();
252 bool FuncData::Call(void** ppParam) const
254 #ifdef DISABLE_DYNLOADING
255 (void) ppParam;
256 return false;
257 #else
258 bool bRet = false;
259 osl::Module* pLib = pModuleData->GetInstance();
260 FARPROC fProc = (FARPROC)pLib->getFunctionSymbol(aFuncName);
261 if (fProc != NULL)
263 switch (nParamCount)
265 case 1 :
266 (*reinterpret_cast<ExFuncPtr1>(fProc))(ppParam[0]);
267 bRet = true;
268 break;
269 case 2 :
270 (*reinterpret_cast<ExFuncPtr2>(fProc))(ppParam[0], ppParam[1]);
271 bRet = true;
272 break;
273 case 3 :
274 (*reinterpret_cast<ExFuncPtr3>(fProc))(ppParam[0], ppParam[1], ppParam[2]);
275 bRet = true;
276 break;
277 case 4 :
278 (*reinterpret_cast<ExFuncPtr4>(fProc))(ppParam[0], ppParam[1], ppParam[2], ppParam[3]);
279 bRet = true;
280 break;
281 case 5 :
282 (*reinterpret_cast<ExFuncPtr5>(fProc))(ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4]);
283 bRet = true;
284 break;
285 case 6 :
286 (*reinterpret_cast<ExFuncPtr6>(fProc))(ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5]);
287 bRet = true;
288 break;
289 case 7 :
290 (*reinterpret_cast<ExFuncPtr7>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
291 ppParam[6]);
292 bRet = true;
293 break;
294 case 8 :
295 (*reinterpret_cast<ExFuncPtr8>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
296 ppParam[6], ppParam[7]);
297 bRet = true;
298 break;
299 case 9 :
300 (*reinterpret_cast<ExFuncPtr9>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
301 ppParam[6], ppParam[7], ppParam[8]);
302 bRet = true;
303 break;
304 case 10 :
305 (*reinterpret_cast<ExFuncPtr10>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
306 ppParam[6], ppParam[7], ppParam[8], ppParam[9]);
307 bRet = true;
308 break;
309 case 11 :
310 (*reinterpret_cast<ExFuncPtr11>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
311 ppParam[6], ppParam[7], ppParam[8], ppParam[9], ppParam[10]);
312 bRet = true;
313 break;
314 case 12:
315 (*reinterpret_cast<ExFuncPtr12>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
316 ppParam[6], ppParam[7], ppParam[8], ppParam[9], ppParam[10], ppParam[11]);
317 bRet = true;
318 break;
319 case 13:
320 (*reinterpret_cast<ExFuncPtr13>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
321 ppParam[6], ppParam[7], ppParam[8], ppParam[9], ppParam[10], ppParam[11],
322 ppParam[12]);
323 bRet = true;
324 break;
325 case 14 :
326 (*reinterpret_cast<ExFuncPtr14>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
327 ppParam[6], ppParam[7], ppParam[8], ppParam[9], ppParam[10], ppParam[11],
328 ppParam[12], ppParam[13]);
329 bRet = true;
330 break;
331 case 15 :
332 (*reinterpret_cast<ExFuncPtr15>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
333 ppParam[6], ppParam[7], ppParam[8], ppParam[9], ppParam[10], ppParam[11],
334 ppParam[12], ppParam[13], ppParam[14]);
335 bRet = true;
336 break;
337 case 16 :
338 (*reinterpret_cast<ExFuncPtr16>(fProc))( ppParam[0], ppParam[1], ppParam[2], ppParam[3], ppParam[4], ppParam[5],
339 ppParam[6], ppParam[7], ppParam[8], ppParam[9], ppParam[10], ppParam[11],
340 ppParam[12], ppParam[13], ppParam[14], ppParam[15]);
341 bRet = true;
342 break;
343 default : break;
346 return bRet;
347 #endif
350 bool FuncData::Unadvice( double nHandle )
352 #ifdef DISABLE_DYNLOADING
353 (void) nHandle;
354 return false;
355 #else
356 bool bRet = false;
357 osl::Module* pLib = pModuleData->GetInstance();
358 FARPROC fProc = (FARPROC)pLib->getFunctionSymbol(UNADVICE);
359 if (fProc != NULL)
361 reinterpret_cast< ::Unadvice>(fProc)(nHandle);
362 bRet = true;
364 return bRet;
365 #endif
368 const OUString& FuncData::GetModuleName() const
370 return pModuleData->GetName();
373 bool FuncData::getParamDesc( OUString& aName, OUString& aDesc, sal_uInt16 nParam ) const
375 #ifdef DISABLE_DYNLOADING
376 (void) aName;
377 (void) aDesc;
378 (void) nParam;
379 return false;
380 #else
381 bool bRet = false;
382 if ( nParam <= nParamCount )
384 osl::Module* pLib = pModuleData->GetInstance();
385 FARPROC fProc = (FARPROC) pLib->getFunctionSymbol(GETPARAMDESC);
386 if ( fProc != NULL )
388 sal_Char pcName[256];
389 sal_Char pcDesc[256];
390 *pcName = *pcDesc = 0;
391 sal_uInt16 nFuncNo = nNumber; // nicht per Reference versauen lassen..
392 reinterpret_cast< ::GetParamDesc>(fProc)( nFuncNo, nParam, pcName, pcDesc );
393 aName = OUString( pcName, 256, osl_getThreadTextEncoding() );
394 aDesc = OUString( pcDesc, 256, osl_getThreadTextEncoding() );
395 bRet = true;
398 if ( !bRet )
400 aName.clear();
401 aDesc.clear();
403 return bRet;
404 #endif
407 FuncCollection::FuncCollection() {}
408 FuncCollection::FuncCollection(const FuncCollection& r) : maData(r.maData) {}
410 const FuncData* FuncCollection::findByName(const OUString& rName) const
412 MapType::const_iterator it = maData.find(rName);
413 return it == maData.end() ? NULL : it->second;
416 FuncData* FuncCollection::findByName(const OUString& rName)
418 MapType::iterator it = maData.find(rName);
419 return it == maData.end() ? NULL : it->second;
422 void FuncCollection::insert(FuncData* pNew)
424 OUString aName = pNew->GetInternalName();
425 maData.insert(aName, pNew);
428 FuncCollection::const_iterator FuncCollection::begin() const
430 return maData.begin();
433 FuncCollection::const_iterator FuncCollection::end() const
435 return maData.end();
438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */