1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/svapp.hxx>
21 #include <osl/module.hxx>
22 #include <osl/file.hxx>
23 #include <unotools/transliterationwrapper.hxx>
25 #include "callform.hxx"
27 #include "adiasync.hxx"
31 typedef void (CALLTYPE
* ExFuncPtr1
)(void*);
32 typedef void (CALLTYPE
* ExFuncPtr2
)(void*, void*);
33 typedef void (CALLTYPE
* ExFuncPtr3
)(void*, void*, void*);
34 typedef void (CALLTYPE
* ExFuncPtr4
)(void*, void*, void*, void*);
35 typedef void (CALLTYPE
* ExFuncPtr5
)(void*, void*, void*, void*, void*);
36 typedef void (CALLTYPE
* ExFuncPtr6
)(void*, void*, void*, void*, void*, void*);
37 typedef void (CALLTYPE
* ExFuncPtr7
)(void*, void*, void*, void*, void*, void*, void*);
38 typedef void (CALLTYPE
* ExFuncPtr8
)(void*, void*, void*, void*, void*, void*, void*, void*);
39 typedef void (CALLTYPE
* ExFuncPtr9
)(void*, void*, void*, void*, void*, void*, void*, void*, void*);
40 typedef void (CALLTYPE
* ExFuncPtr10
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
41 typedef void (CALLTYPE
* ExFuncPtr11
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
42 typedef void (CALLTYPE
* ExFuncPtr12
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
43 typedef void (CALLTYPE
* ExFuncPtr13
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
44 typedef void (CALLTYPE
* ExFuncPtr14
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
45 typedef void (CALLTYPE
* ExFuncPtr15
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
46 typedef void (CALLTYPE
* ExFuncPtr16
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
48 typedef void (CALLTYPE
* GetFuncCountPtr
)(sal_uInt16
& nCount
);
49 typedef void (CALLTYPE
* GetFuncDataPtr
)
50 (sal_uInt16
& nNo
, sal_Char
* pFuncName
, sal_uInt16
& nParamCount
, ParamType
* peType
, sal_Char
* pInternalName
);
52 typedef void (CALLTYPE
* SetLanguagePtr
)( sal_uInt16
& nLanguage
);
53 typedef void (CALLTYPE
* GetParamDesc
)
54 (sal_uInt16
& nNo
, sal_uInt16
& nParam
, sal_Char
* pName
, sal_Char
* pDesc
);
56 typedef void (CALLTYPE
* IsAsync
) ( sal_uInt16
& nNo
,
58 typedef void (CALLTYPE
* Advice
) ( sal_uInt16
& nNo
,
59 AdvData
& pfCallback
);
60 typedef void (CALLTYPE
* Unadvice
)( double& nHandle
);
62 typedef void (CALLTYPE
* FARPROC
) ( void );
66 #ifndef DISABLE_DYNLOADING
67 #define GETFUNCTIONCOUNT "GetFunctionCount"
68 #define GETFUNCTIONDATA "GetFunctionData"
69 #define SETLANGUAGE "SetLanguage"
70 #define GETPARAMDESC "GetParameterDescription"
71 #define ISASYNC "IsAsync"
72 #define ADVICE "Advice"
73 #define UNADVICE "Unadvice"
78 friend class ModuleCollection
;
80 osl::Module
* pInstance
;
82 ModuleData(const OUString
& rStr
, osl::Module
* pInst
) : aName(rStr
), pInstance(pInst
) {}
83 ModuleData(const ModuleData
& rData
) : aName(rData
.aName
)
85 #ifndef DISABLE_DYNLOADING
86 pInstance
= new osl::Module(aName
);
91 ~ModuleData() { delete pInstance
; }
93 const OUString
& GetName() const { return aName
; }
94 osl::Module
* GetInstance() const { return pInstance
; }
95 void FreeInstance() { delete pInstance
; pInstance
= 0; }
98 FuncData::FuncData(const ModuleData
*pModule
,
99 const OUString
& rIName
,
100 const OUString
& rFName
,
103 const ParamType
* peType
,
105 pModuleData (pModule
),
106 aInternalName (rIName
),
109 nParamCount (nCount
),
112 for (sal_uInt16 i
= 0; i
< MAXFUNCPARAM
; i
++)
113 eParamType
[i
] = peType
[i
];
116 FuncData::FuncData(const FuncData
& rData
) :
117 pModuleData (rData
.pModuleData
),
118 aInternalName (rData
.aInternalName
),
119 aFuncName (rData
.aFuncName
),
120 nNumber (rData
.nNumber
),
121 nParamCount (rData
.nParamCount
),
122 eAsyncType (rData
.eAsyncType
)
124 for (sal_uInt16 i
= 0; i
< MAXFUNCPARAM
; i
++)
125 eParamType
[i
] = rData
.eParamType
[i
];
130 class ModuleCollection
132 typedef boost::ptr_map
<OUString
, ModuleData
> MapType
;
135 ModuleCollection() {}
136 ModuleCollection(const ModuleCollection
& r
) : maData(r
.maData
) {}
138 const ModuleData
* findByName(const OUString
& rName
) const;
139 void insert(ModuleData
* pNew
);
143 const ModuleData
* ModuleCollection::findByName(const OUString
& rName
) const
145 MapType::const_iterator it
= maData
.find(rName
);
146 return it
== maData
.end() ? NULL
: it
->second
;
149 void ModuleCollection::insert(ModuleData
* pNew
)
154 OUString aName
= pNew
->GetName();
155 maData
.insert(aName
, pNew
);
158 void ModuleCollection::clear()
163 ModuleCollection aModuleCollection
;
167 bool InitExternalFunc(const OUString
& rModuleName
)
169 #ifdef DISABLE_DYNLOADING
173 // Module already loaded?
174 const ModuleData
* pTemp
= aModuleCollection
.findByName(rModuleName
);
182 osl::Module
* pLib
= new osl::Module( aNP
);
185 FARPROC fpGetCount
= (FARPROC
)pLib
->getFunctionSymbol(GETFUNCTIONCOUNT
);
186 FARPROC fpGetData
= (FARPROC
)pLib
->getFunctionSymbol(GETFUNCTIONDATA
);
187 if ((fpGetCount
!= NULL
) && (fpGetData
!= NULL
))
189 FARPROC fpIsAsync
= (FARPROC
)pLib
->getFunctionSymbol(ISASYNC
);
190 FARPROC fpAdvice
= (FARPROC
)pLib
->getFunctionSymbol(ADVICE
);
191 FARPROC fpSetLanguage
= (FARPROC
)pLib
->getFunctionSymbol(SETLANGUAGE
);
194 LanguageType eLanguage
= Application::GetSettings().GetUILanguageTag().getLanguageType();
195 sal_uInt16 nLanguage
= (sal_uInt16
) eLanguage
;
196 (*((SetLanguagePtr
)fpSetLanguage
))( nLanguage
);
199 // Module in die Collection aufnehmen
200 ModuleData
* pModuleData
= new ModuleData(rModuleName
, pLib
);
201 aModuleCollection
.insert(pModuleData
);
203 // Schnittstelle initialisieren
204 AdvData pfCallBack
= &ScAddInAsyncCallBack
;
206 FuncCollection
* pFuncCol
= ScGlobal::GetFuncCollection();
208 (*((GetFuncCountPtr
)fpGetCount
))(nCount
);
209 for (sal_uInt16 i
=0; i
< nCount
; i
++)
211 sal_Char cFuncName
[256];
212 sal_Char cInternalName
[256];
213 sal_uInt16 nParamCount
;
214 ParamType eParamType
[MAXFUNCPARAM
];
215 ParamType eAsyncType
= NONE
;
216 // initialize all, in case the AddIn behaves bad
218 cInternalName
[0] = 0;
220 for ( sal_uInt16 j
=0; j
<MAXFUNCPARAM
; j
++ )
222 eParamType
[j
] = NONE
;
224 (*((GetFuncDataPtr
)fpGetData
))(i
, cFuncName
, nParamCount
,
225 eParamType
, cInternalName
);
228 (*((IsAsync
)fpIsAsync
))(i
, &eAsyncType
);
229 if ( fpAdvice
&& eAsyncType
!= NONE
)
230 (*((Advice
)fpAdvice
))( i
, pfCallBack
);
232 OUString
aInternalName( cInternalName
, strlen(cInternalName
), osl_getThreadTextEncoding() );
233 OUString
aFuncName( cFuncName
, strlen(cFuncName
), osl_getThreadTextEncoding() );
234 pFuncData
= new FuncData( pModuleData
,
241 pFuncCol
->insert(pFuncData
);
254 void ExitExternalFunc()
256 aModuleCollection
.clear();
259 bool FuncData::Call(void** ppParam
) const
261 #ifdef DISABLE_DYNLOADING
266 osl::Module
* pLib
= pModuleData
->GetInstance();
267 FARPROC fProc
= (FARPROC
)pLib
->getFunctionSymbol(aFuncName
);
273 (*((ExFuncPtr1
)fProc
))(ppParam
[0]);
277 (*((ExFuncPtr2
)fProc
))(ppParam
[0], ppParam
[1]);
281 (*((ExFuncPtr3
)fProc
))(ppParam
[0], ppParam
[1], ppParam
[2]);
285 (*((ExFuncPtr4
)fProc
))(ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3]);
289 (*((ExFuncPtr5
)fProc
))(ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4]);
293 (*((ExFuncPtr6
)fProc
))(ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5]);
297 (*((ExFuncPtr7
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
302 (*((ExFuncPtr8
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
303 ppParam
[6], ppParam
[7]);
307 (*((ExFuncPtr9
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
308 ppParam
[6], ppParam
[7], ppParam
[8]);
312 (*((ExFuncPtr10
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
313 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9]);
317 (*((ExFuncPtr11
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
318 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10]);
322 (*((ExFuncPtr12
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
323 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11]);
327 (*((ExFuncPtr13
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
328 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11],
333 (*((ExFuncPtr14
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
334 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11],
335 ppParam
[12], ppParam
[13]);
339 (*((ExFuncPtr15
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
340 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11],
341 ppParam
[12], ppParam
[13], ppParam
[14]);
345 (*((ExFuncPtr16
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
346 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11],
347 ppParam
[12], ppParam
[13], ppParam
[14], ppParam
[15]);
357 bool FuncData::Unadvice( double nHandle
)
359 #ifdef DISABLE_DYNLOADING
364 osl::Module
* pLib
= pModuleData
->GetInstance();
365 FARPROC fProc
= (FARPROC
)pLib
->getFunctionSymbol(UNADVICE
);
368 ((::Unadvice
)fProc
)(nHandle
);
375 const OUString
& FuncData::GetModuleName() const
377 return pModuleData
->GetName();
380 bool FuncData::getParamDesc( OUString
& aName
, OUString
& aDesc
, sal_uInt16 nParam
) const
382 #ifdef DISABLE_DYNLOADING
389 if ( nParam
<= nParamCount
)
391 osl::Module
* pLib
= pModuleData
->GetInstance();
392 FARPROC fProc
= (FARPROC
) pLib
->getFunctionSymbol(GETPARAMDESC
);
395 sal_Char pcName
[256];
396 sal_Char pcDesc
[256];
397 *pcName
= *pcDesc
= 0;
398 sal_uInt16 nFuncNo
= nNumber
; // nicht per Reference versauen lassen..
399 ((::GetParamDesc
)fProc
)( nFuncNo
, nParam
, pcName
, pcDesc
);
400 aName
= OUString( pcName
, 256, osl_getThreadTextEncoding() );
401 aDesc
= OUString( pcDesc
, 256, osl_getThreadTextEncoding() );
414 FuncCollection::FuncCollection() {}
415 FuncCollection::FuncCollection(const FuncCollection
& r
) : maData(r
.maData
) {}
417 const FuncData
* FuncCollection::findByName(const OUString
& rName
) const
419 MapType::const_iterator it
= maData
.find(rName
);
420 return it
== maData
.end() ? NULL
: it
->second
;
423 FuncData
* FuncCollection::findByName(const OUString
& rName
)
425 MapType::iterator it
= maData
.find(rName
);
426 return it
== maData
.end() ? NULL
: it
->second
;
429 void FuncCollection::insert(FuncData
* pNew
)
431 OUString aName
= pNew
->GetInternalName();
432 maData
.insert(aName
, pNew
);
435 FuncCollection::const_iterator
FuncCollection::begin() const
437 return maData
.begin();
440 FuncCollection::const_iterator
FuncCollection::end() const
445 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */