1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: callform.cxx,v $
10 * $Revision: 1.12.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
37 #include <vcl/svapp.hxx>
38 #include <osl/module.hxx>
39 #include <osl/file.hxx>
40 #include <unotools/transliterationwrapper.hxx>
42 #include "callform.hxx"
44 #include "adiasync.hxx"
46 //------------------------------------------------------------------------
50 typedef void (CALLTYPE
* ExFuncPtr1
)(void*);
51 typedef void (CALLTYPE
* ExFuncPtr2
)(void*, void*);
52 typedef void (CALLTYPE
* ExFuncPtr3
)(void*, void*, void*);
53 typedef void (CALLTYPE
* ExFuncPtr4
)(void*, void*, void*, void*);
54 typedef void (CALLTYPE
* ExFuncPtr5
)(void*, void*, void*, void*, void*);
55 typedef void (CALLTYPE
* ExFuncPtr6
)(void*, void*, void*, void*, void*, void*);
56 typedef void (CALLTYPE
* ExFuncPtr7
)(void*, void*, void*, void*, void*, void*, void*);
57 typedef void (CALLTYPE
* ExFuncPtr8
)(void*, void*, void*, void*, void*, void*, void*, void*);
58 typedef void (CALLTYPE
* ExFuncPtr9
)(void*, void*, void*, void*, void*, void*, void*, void*, void*);
59 typedef void (CALLTYPE
* ExFuncPtr10
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
60 typedef void (CALLTYPE
* ExFuncPtr11
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
61 typedef void (CALLTYPE
* ExFuncPtr12
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
62 typedef void (CALLTYPE
* ExFuncPtr13
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
63 typedef void (CALLTYPE
* ExFuncPtr14
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
64 typedef void (CALLTYPE
* ExFuncPtr15
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
65 typedef void (CALLTYPE
* ExFuncPtr16
)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*);
67 typedef void (CALLTYPE
* GetFuncCountPtr
)(USHORT
& nCount
);
68 typedef void (CALLTYPE
* GetFuncDataPtr
)
69 (USHORT
& nNo
, sal_Char
* pFuncName
, USHORT
& nParamCount
, ParamType
* peType
, sal_Char
* pInternalName
);
71 typedef void (CALLTYPE
* SetLanguagePtr
)( USHORT
& nLanguage
);
72 typedef void (CALLTYPE
* GetParamDesc
)
73 (USHORT
& nNo
, USHORT
& nParam
, sal_Char
* pName
, sal_Char
* pDesc
);
75 typedef void (CALLTYPE
* IsAsync
) ( USHORT
& nNo
,
77 typedef void (CALLTYPE
* Advice
) ( USHORT
& nNo
,
78 AdvData
& pfCallback
);
79 typedef void (CALLTYPE
* Unadvice
)( double& nHandle
);
81 typedef void (CALLTYPE
* FARPROC
) ( void );
85 #if defined(OS2) && defined(BLC)
86 #define GETFUNCTIONCOUNT "_GetFunctionCount"
87 #define GETFUNCTIONDATA "_GetFunctionData"
88 #define SETLANGUAGE "_SetLanguage"
89 #define GETPARAMDESC "_GetParameterDescription"
90 #define ISASYNC "_IsAsync"
91 #define ADVICE "_Advice"
92 #define UNADVICE "_Unadvice"
93 #else // Pascal oder extern "C"
94 #define GETFUNCTIONCOUNT "GetFunctionCount"
95 #define GETFUNCTIONDATA "GetFunctionData"
96 #define SETLANGUAGE "SetLanguage"
97 #define GETPARAMDESC "GetParameterDescription"
98 #define ISASYNC "IsAsync"
99 #define ADVICE "Advice"
100 #define UNADVICE "Unadvice"
103 #define LIBFUNCNAME( name ) \
104 (String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( name ) ))
106 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
108 FuncData::FuncData(const String
& rIName
) :
110 aInternalName (rIName
),
116 for (USHORT i
= 0; i
< MAXFUNCPARAM
; i
++)
117 eParamType
[i
] = PTR_DOUBLE
;
120 //------------------------------------------------------------------------
122 FuncData::FuncData(const ModuleData
*pModule
,
123 const String
& rIName
,
124 const String
& rFName
,
127 const ParamType
* peType
,
129 pModuleData (pModule
),
130 aInternalName (rIName
),
133 nParamCount (nCount
),
136 for (USHORT i
= 0; i
< MAXFUNCPARAM
; i
++)
137 eParamType
[i
] = peType
[i
];
140 //------------------------------------------------------------------------
142 FuncData::FuncData(const FuncData
& rData
) :
144 pModuleData (rData
.pModuleData
),
145 aInternalName (rData
.aInternalName
),
146 aFuncName (rData
.aFuncName
),
147 nNumber (rData
.nNumber
),
148 nParamCount (rData
.nParamCount
),
149 eAsyncType (rData
.eAsyncType
)
151 for (USHORT i
= 0; i
< MAXFUNCPARAM
; i
++)
152 eParamType
[i
] = rData
.eParamType
[i
];
155 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
157 short FuncCollection::Compare(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const
159 return (short) ScGlobal::GetpTransliteration()->compareString(
160 ((FuncData
*)pKey1
)->aInternalName
, ((FuncData
*)pKey2
)->aInternalName
);
163 //------------------------------------------------------------------------
165 BOOL
FuncCollection::SearchFunc( const String
& rName
, USHORT
& rIndex
) const
167 FuncData
aDataObj(rName
);
168 return Search( &aDataObj
, rIndex
);
171 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
172 class ModuleData
: public ScDataObject
174 friend class ModuleCollection
;
176 osl::Module
* pInstance
;
178 ModuleData(const String
& rStr
, osl::Module
* pInst
) : aName (rStr
), pInstance (pInst
) {}
179 ModuleData(const ModuleData
& rData
) : ScDataObject(), aName (rData
.aName
) {pInstance
= new osl::Module(aName
);}
180 ~ModuleData() { delete pInstance
; }
181 virtual ScDataObject
* Clone() const { return new ModuleData(*this); }
183 const String
& GetName() const { return aName
; }
184 osl::Module
* GetInstance() const { return pInstance
; }
185 void FreeInstance() { delete pInstance
; pInstance
= 0; }
188 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
189 class ModuleCollection
: public ScSortedCollection
192 ModuleCollection(USHORT nLim
= 4, USHORT nDel
= 4, BOOL bDup
= FALSE
) : ScSortedCollection ( nLim
, nDel
, bDup
) {}
193 ModuleCollection(const ModuleCollection
& rModuleCollection
) : ScSortedCollection ( rModuleCollection
) {}
195 virtual ScDataObject
* Clone() const { return new ModuleCollection(*this); }
196 ModuleData
* operator[]( const USHORT nIndex
) const {return (ModuleData
*)At(nIndex
);}
197 virtual short Compare(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const;
198 BOOL
SearchModule( const String
& rName
,
199 const ModuleData
*& rpModule
) const;
202 static ModuleCollection aModuleCollection
;
204 //------------------------------------------------------------------------
206 short ModuleCollection::Compare(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const
208 return (short) ScGlobal::GetpTransliteration()->compareString(
209 ((ModuleData
*)pKey1
)->aName
, ((ModuleData
*)pKey2
)->aName
);
212 //------------------------------------------------------------------------
214 BOOL
ModuleCollection::SearchModule( const String
& rName
,
215 const ModuleData
*& rpModule
) const
218 ModuleData
aSearchModule(rName
, 0);
219 BOOL bFound
= Search( &aSearchModule
, nIndex
);
221 rpModule
= (ModuleData
*)At(nIndex
);
227 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
229 BOOL
InitExternalFunc(const rtl::OUString
& rModuleName
)
231 String
aModuleName( rModuleName
);
233 // Module schon geladen?
234 const ModuleData
* pTemp
;
235 if (aModuleCollection
.SearchModule(aModuleName
, pTemp
))
242 osl::Module
* pLib
= new osl::Module( aNP
);
245 FARPROC fpGetCount
= (FARPROC
)pLib
->getFunctionSymbol(LIBFUNCNAME(GETFUNCTIONCOUNT
));
246 FARPROC fpGetData
= (FARPROC
)pLib
->getFunctionSymbol(LIBFUNCNAME(GETFUNCTIONDATA
));
247 if ((fpGetCount
!= NULL
) && (fpGetData
!= NULL
))
249 FARPROC fpIsAsync
= (FARPROC
)pLib
->getFunctionSymbol(LIBFUNCNAME(ISASYNC
));
250 FARPROC fpAdvice
= (FARPROC
)pLib
->getFunctionSymbol(LIBFUNCNAME(ADVICE
));
251 FARPROC fpSetLanguage
= (FARPROC
)pLib
->getFunctionSymbol(LIBFUNCNAME(SETLANGUAGE
));
254 LanguageType eLanguage
= Application::GetSettings().GetUILanguage();
255 USHORT nLanguage
= (USHORT
) eLanguage
;
256 (*((SetLanguagePtr
)fpSetLanguage
))( nLanguage
);
259 // Module in die Collection aufnehmen
260 ModuleData
* pModuleData
= new ModuleData(aModuleName
, pLib
);
261 aModuleCollection
.Insert(pModuleData
);
263 // Schnittstelle initialisieren
264 AdvData pfCallBack
= &ScAddInAsyncCallBack
;
266 FuncCollection
* pFuncCol
= ScGlobal::GetFuncCollection();
268 (*((GetFuncCountPtr
)fpGetCount
))(nCount
);
269 for (USHORT i
=0; i
< nCount
; i
++)
271 sal_Char cFuncName
[256];
272 sal_Char cInternalName
[256];
274 ParamType eParamType
[MAXFUNCPARAM
];
275 ParamType eAsyncType
= NONE
;
276 // #62113# alles initialisieren, falls das AddIn sich schlecht verhaelt
278 cInternalName
[0] = 0;
280 for ( USHORT j
=0; j
<MAXFUNCPARAM
; j
++ )
282 eParamType
[j
] = NONE
;
284 (*((GetFuncDataPtr
)fpGetData
))(i
, cFuncName
, nParamCount
,
285 eParamType
, cInternalName
);
288 (*((IsAsync
)fpIsAsync
))(i
, &eAsyncType
);
289 if ( fpAdvice
&& eAsyncType
!= NONE
)
290 (*((Advice
)fpAdvice
))( i
, pfCallBack
);
292 String
aInternalName( cInternalName
, osl_getThreadTextEncoding() );
293 String
aFuncName( cFuncName
, osl_getThreadTextEncoding() );
294 pFuncData
= new FuncData( pModuleData
,
301 pFuncCol
->Insert(pFuncData
);
313 //------------------------------------------------------------------------
315 void ExitExternalFunc()
317 USHORT nCount
= aModuleCollection
.GetCount();
318 for (USHORT i
=0; i
<nCount
; i
++)
320 ModuleData
* pData
= aModuleCollection
[i
];
321 pData
->FreeInstance();
325 //------------------------------------------------------------------------
327 BOOL
FuncData::Call(void** ppParam
)
330 osl::Module
* pLib
= pModuleData
->GetInstance();
331 FARPROC fProc
= (FARPROC
)pLib
->getFunctionSymbol(aFuncName
);
337 (*((ExFuncPtr1
)fProc
))(ppParam
[0]);
341 (*((ExFuncPtr2
)fProc
))(ppParam
[0], ppParam
[1]);
345 (*((ExFuncPtr3
)fProc
))(ppParam
[0], ppParam
[1], ppParam
[2]);
349 (*((ExFuncPtr4
)fProc
))(ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3]);
353 (*((ExFuncPtr5
)fProc
))(ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4]);
357 (*((ExFuncPtr6
)fProc
))(ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5]);
361 (*((ExFuncPtr7
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
366 (*((ExFuncPtr8
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
367 ppParam
[6], ppParam
[7]);
371 (*((ExFuncPtr9
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
372 ppParam
[6], ppParam
[7], ppParam
[8]);
376 (*((ExFuncPtr10
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
377 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9]);
381 (*((ExFuncPtr11
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
382 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10]);
386 (*((ExFuncPtr12
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
387 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11]);
391 (*((ExFuncPtr13
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
392 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11],
397 (*((ExFuncPtr14
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
398 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11],
399 ppParam
[12], ppParam
[13]);
403 (*((ExFuncPtr15
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
404 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11],
405 ppParam
[12], ppParam
[13], ppParam
[14]);
409 (*((ExFuncPtr16
)fProc
))( ppParam
[0], ppParam
[1], ppParam
[2], ppParam
[3], ppParam
[4], ppParam
[5],
410 ppParam
[6], ppParam
[7], ppParam
[8], ppParam
[9], ppParam
[10], ppParam
[11],
411 ppParam
[12], ppParam
[13], ppParam
[14], ppParam
[15]);
420 //------------------------------------------------------------------------
422 BOOL
FuncData::Unadvice( double nHandle
)
425 osl::Module
* pLib
= pModuleData
->GetInstance();
426 FARPROC fProc
= (FARPROC
)pLib
->getFunctionSymbol(LIBFUNCNAME(UNADVICE
));
429 ((::Unadvice
)fProc
)(nHandle
);
435 //------------------------------------------------------------------------
437 const String
& FuncData::GetModuleName() const
439 // DBG_ASSERT( pModuleData, "Keine Arme, keine Kekse" ):
440 return pModuleData
->GetName();
443 //------------------------------------------------------------------------
445 BOOL
FuncData::GetParamDesc( String
& aName
, String
& aDesc
, USHORT nParam
)
448 if ( nParam
<= nParamCount
)
450 osl::Module
* pLib
= pModuleData
->GetInstance();
451 FARPROC fProc
= (FARPROC
) pLib
->getFunctionSymbol( LIBFUNCNAME(GETPARAMDESC
) );
454 sal_Char pcName
[256];
455 sal_Char pcDesc
[256];
456 *pcName
= *pcDesc
= 0;
457 USHORT nFuncNo
= nNumber
; // nicht per Reference versauen lassen..
458 ((::GetParamDesc
)fProc
)( nFuncNo
, nParam
, pcName
, pcDesc
);
459 aName
= String( pcName
, osl_getThreadTextEncoding() );
460 aDesc
= String( pcDesc
, osl_getThreadTextEncoding() );