xref: /trunk/main/sc/inc/addincol.hxx (revision cf8e6a53ed981a205d7700be9a04dd40a005f9f6)
138d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
338d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
438d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
538d50f7bSAndrew Rist  * distributed with this work for additional information
638d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
738d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
838d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
938d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1138d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1338d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1438d50f7bSAndrew Rist  * software distributed under the License is distributed on an
1538d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1638d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
1738d50f7bSAndrew Rist  * specific language governing permissions and limitations
1838d50f7bSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2038d50f7bSAndrew Rist  *************************************************************/
2138d50f7bSAndrew Rist 
2238d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_ADDINCOL_HXX
25cdf0e10cSrcweir #define SC_ADDINCOL_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "global.hxx"
28cdf0e10cSrcweir #include <com/sun/star/sheet/XVolatileResult.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sheet/XAddIn.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sheet/XResultListener.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sheet/ResultEvent.hpp>
32cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlMethod.hpp>
34cdf0e10cSrcweir #include <com/sun/star/sheet/LocalizedName.hpp>
35cdf0e10cSrcweir #include <tools/string.hxx>
36cdf0e10cSrcweir #include <i18npool/lang.h>
37cdf0e10cSrcweir #include <rtl/ustring.h>
38cdf0e10cSrcweir #include "scdllapi.h"
39cdf0e10cSrcweir #include <rtl/ustring.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #ifndef SC_SCMATRIX_HXX
42cdf0e10cSrcweir #include "scmatrix.hxx"
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <hash_map>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir class String;
49cdf0e10cSrcweir class SfxObjectShell;
50cdf0e10cSrcweir class ScUnoAddInFuncData;
51cdf0e10cSrcweir class ScMatrix;
52cdf0e10cSrcweir class ScFuncDesc;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir typedef ::std::hash_map< String, const ScUnoAddInFuncData*, ScStringHashCode, ::std::equal_to< String > > ScAddInHashMap;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 
58cdf0e10cSrcweir enum ScAddInArgumentType
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     SC_ADDINARG_NONE,                   // -
61cdf0e10cSrcweir     SC_ADDINARG_INTEGER,                // long
62cdf0e10cSrcweir     SC_ADDINARG_DOUBLE,                 // double
63cdf0e10cSrcweir     SC_ADDINARG_STRING,                 // string
64cdf0e10cSrcweir     SC_ADDINARG_INTEGER_ARRAY,          // sequence<sequence<long>>
65cdf0e10cSrcweir     SC_ADDINARG_DOUBLE_ARRAY,           // sequence<sequence<double>>
66cdf0e10cSrcweir     SC_ADDINARG_STRING_ARRAY,           // sequence<sequence<string>>
67cdf0e10cSrcweir     SC_ADDINARG_MIXED_ARRAY,            // sequence<sequence<any>>
68cdf0e10cSrcweir     SC_ADDINARG_VALUE_OR_ARRAY,         // any
69cdf0e10cSrcweir     SC_ADDINARG_CELLRANGE,              // XCellRange
70cdf0e10cSrcweir     SC_ADDINARG_CALLER,                 // XPropertySet
71cdf0e10cSrcweir     SC_ADDINARG_VARARGS                 // sequence<any>
72cdf0e10cSrcweir };
73cdf0e10cSrcweir 
74cdf0e10cSrcweir //------------------------------------------------------------------------
75cdf0e10cSrcweir 
76cdf0e10cSrcweir struct ScAddInArgDesc
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     String              aInternalName;      // used to match configuration and reflection information
79cdf0e10cSrcweir     String              aName;
80cdf0e10cSrcweir     String              aDescription;
81cdf0e10cSrcweir     ScAddInArgumentType eType;
82cdf0e10cSrcweir     sal_Bool                bOptional;
83cdf0e10cSrcweir };
84cdf0e10cSrcweir 
85cdf0e10cSrcweir class ScUnoAddInFuncData
86cdf0e10cSrcweir {
87cdf0e10cSrcweir private:
88cdf0e10cSrcweir     String              aOriginalName;      // kept in formula
89cdf0e10cSrcweir     String              aLocalName;         // for display
90cdf0e10cSrcweir     String              aUpperName;         // for entering formulas
91cdf0e10cSrcweir     String              aUpperLocal;        // for entering formulas
92cdf0e10cSrcweir     String              aDescription;
93cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod> xFunction;
94cdf0e10cSrcweir     com::sun::star::uno::Any            aObject;
95cdf0e10cSrcweir     long                nArgCount;
96cdf0e10cSrcweir     ScAddInArgDesc*     pArgDescs;
97cdf0e10cSrcweir     long                nCallerPos;
98cdf0e10cSrcweir     sal_uInt16              nCategory;
99cdf0e10cSrcweir     rtl::OString        sHelpId;
100cdf0e10cSrcweir     mutable com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName> aCompNames;
101cdf0e10cSrcweir     mutable sal_Bool        bCompInitialized;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir public:
104cdf0e10cSrcweir                 ScUnoAddInFuncData( const String& rNam, const String& rLoc,
105cdf0e10cSrcweir                                     const String& rDesc,
106cdf0e10cSrcweir                                     sal_uInt16 nCat, const rtl::OString&,
107cdf0e10cSrcweir                                     const com::sun::star::uno::Reference<
108cdf0e10cSrcweir                                         com::sun::star::reflection::XIdlMethod>& rFunc,
109cdf0e10cSrcweir                                     const com::sun::star::uno::Any& rO,
110cdf0e10cSrcweir                                     long nAC, const ScAddInArgDesc* pAD,
111cdf0e10cSrcweir                                     long nCP );
112cdf0e10cSrcweir                 ~ScUnoAddInFuncData();
113cdf0e10cSrcweir 
GetOriginalName() const114cdf0e10cSrcweir     const String&           GetOriginalName() const     { return aOriginalName; }
GetLocalName() const115cdf0e10cSrcweir     const String&           GetLocalName() const        { return aLocalName; }
GetUpperName() const116cdf0e10cSrcweir     const String&           GetUpperName() const        { return aUpperName; }
GetUpperLocal() const117cdf0e10cSrcweir     const String&           GetUpperLocal() const       { return aUpperLocal; }
GetFunction() const118cdf0e10cSrcweir     const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>&   GetFunction() const
119cdf0e10cSrcweir                                                         { return xFunction; }
GetObject() const120cdf0e10cSrcweir     const com::sun::star::uno::Any& GetObject() const   { return aObject; }
GetArgumentCount() const121cdf0e10cSrcweir     long                    GetArgumentCount() const    { return nArgCount; }
GetArguments() const122cdf0e10cSrcweir     const ScAddInArgDesc*   GetArguments() const        { return pArgDescs; }
GetCallerPos() const123cdf0e10cSrcweir     long                    GetCallerPos() const        { return nCallerPos; }
GetDescription() const124cdf0e10cSrcweir     const String&           GetDescription() const      { return aDescription; }
GetCategory() const125cdf0e10cSrcweir     sal_uInt16                  GetCategory() const         { return nCategory; }
GetHelpId() const126cdf0e10cSrcweir     const rtl::OString      GetHelpId() const           { return sHelpId; }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>&  GetCompNames() const;
129cdf0e10cSrcweir     sal_Bool                    GetExcelName( LanguageType eDestLang, String& rRetExcelName ) const;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     void    SetFunction( const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& rNewFunc,
132cdf0e10cSrcweir                          const com::sun::star::uno::Any& rNewObj );
133cdf0e10cSrcweir     void    SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs );
134cdf0e10cSrcweir     void    SetCallerPos( long nNewPos );
135cdf0e10cSrcweir     void    SetCompNames( const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>& rNew );
136cdf0e10cSrcweir };
137cdf0e10cSrcweir 
138cdf0e10cSrcweir //------------------------------------------------------------------------
139cdf0e10cSrcweir 
140cdf0e10cSrcweir class SC_DLLPUBLIC ScUnoAddInCollection
141cdf0e10cSrcweir {
142cdf0e10cSrcweir private:
143cdf0e10cSrcweir     long                    nFuncCount;
144cdf0e10cSrcweir     ScUnoAddInFuncData**    ppFuncData;
145cdf0e10cSrcweir     ScAddInHashMap*         pExactHashMap;      // exact internal name
146cdf0e10cSrcweir     ScAddInHashMap*         pNameHashMap;       // internal name upper
147cdf0e10cSrcweir     ScAddInHashMap*         pLocalHashMap;      // localized name upper
148cdf0e10cSrcweir     sal_Bool                    bInitialized;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     void        Initialize();
151cdf0e10cSrcweir     void        ReadConfiguration();
152cdf0e10cSrcweir     void        ReadFromAddIn( const com::sun::star::uno::Reference<
153cdf0e10cSrcweir                                 com::sun::star::uno::XInterface>& xInterface );
154cdf0e10cSrcweir     void        UpdateFromAddIn( const com::sun::star::uno::Reference<
155cdf0e10cSrcweir                                   com::sun::star::uno::XInterface>& xInterface,
156cdf0e10cSrcweir                                 const String& rServiceName );
157cdf0e10cSrcweir     void        LoadComponent( const ScUnoAddInFuncData& rFuncData );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir public:
160cdf0e10cSrcweir                 ScUnoAddInCollection();
161cdf0e10cSrcweir                 ~ScUnoAddInCollection();
162cdf0e10cSrcweir 
163*cf8e6a53SJohn Bampton                         /// User entered name. rUpperName MUST already be upper case!
164cdf0e10cSrcweir     String              FindFunction( const String& rUpperName, sal_Bool bLocalFirst );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir                         // rName is the exact Name.
167cdf0e10cSrcweir                         // Only if bComplete is set, the function reference and argument types
168cdf0e10cSrcweir                         // are initialized (component may have to be loaded).
169cdf0e10cSrcweir     const ScUnoAddInFuncData*   GetFuncData( const String& rName, bool bComplete = false );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir                         /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
172cdf0e10cSrcweir                             @param nIndex
173cdf0e10cSrcweir                                 0 <= nIndex < GetFuncCount()
174cdf0e10cSrcweir                          */
175cdf0e10cSrcweir     const ScUnoAddInFuncData*   GetFuncData( long nIndex );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     void                Clear();
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     void                LocalizeString( String& rName );    // modify rName - input: exact name
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     long                GetFuncCount();
182cdf0e10cSrcweir     sal_Bool                FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     static sal_Bool         FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     sal_Bool                GetExcelName( const String& rCalcName, LanguageType eDestLang, String& rRetExcelName );
187cdf0e10cSrcweir     sal_Bool                GetCalcName( const String& rExcelName, String& rRetCalcName );
188cdf0e10cSrcweir                                 // both leave rRet... unchanged, if no matching name is found
189cdf0e10cSrcweir };
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 
192cdf0e10cSrcweir class ScUnoAddInCall
193cdf0e10cSrcweir {
194cdf0e10cSrcweir private:
195cdf0e10cSrcweir     const ScUnoAddInFuncData*   pFuncData;
196cdf0e10cSrcweir     com::sun::star::uno::Sequence<com::sun::star::uno::Any>         aArgs;
197cdf0e10cSrcweir     com::sun::star::uno::Sequence<com::sun::star::uno::Any>         aVarArg;
198cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::uno::XInterface> xCaller;
199cdf0e10cSrcweir     sal_Bool                        bValidCount;
200cdf0e10cSrcweir     // result:
201cdf0e10cSrcweir     sal_uInt16                      nErrCode;
202cdf0e10cSrcweir     sal_Bool                        bHasString;
203cdf0e10cSrcweir     double                      fValue;
204cdf0e10cSrcweir     String                      aString;
205cdf0e10cSrcweir     ScMatrixRef                 xMatrix;
206cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult> xVarRes;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     void            ExecuteCallWithArgs(
209cdf0e10cSrcweir                         com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rCallArgs);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir public:
212cdf0e10cSrcweir                     // exact name
213cdf0e10cSrcweir                     ScUnoAddInCall( ScUnoAddInCollection& rColl, const String& rName,
214cdf0e10cSrcweir                                     long nParamCount );
215cdf0e10cSrcweir                     ~ScUnoAddInCall();
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     sal_Bool                NeedsCaller() const;
218cdf0e10cSrcweir     void                SetCaller( const com::sun::star::uno::Reference<
219cdf0e10cSrcweir                                     com::sun::star::uno::XInterface>& rInterface );
220cdf0e10cSrcweir     void                SetCallerFromObjectShell( SfxObjectShell* pSh );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     sal_Bool                ValidParamCount();
223cdf0e10cSrcweir     ScAddInArgumentType GetArgType( long nPos );
224cdf0e10cSrcweir     void                SetParam( long nPos, const com::sun::star::uno::Any& rValue );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     void                ExecuteCall();
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     void                SetResult( const com::sun::star::uno::Any& rNewRes );
229cdf0e10cSrcweir 
GetErrCode() const230cdf0e10cSrcweir     sal_uInt16              GetErrCode() const      { return nErrCode; }
HasString() const231cdf0e10cSrcweir     sal_Bool                HasString() const       { return bHasString; }
HasMatrix() const232cdf0e10cSrcweir     sal_Bool                HasMatrix() const       { return ( xMatrix.Is() ); }
HasVarRes() const233cdf0e10cSrcweir     sal_Bool                HasVarRes() const       { return ( xVarRes.is() ); }
GetValue() const234cdf0e10cSrcweir     double              GetValue() const        { return fValue; }
GetString() const235cdf0e10cSrcweir     const String&       GetString() const       { return aString; }
GetMatrix() const236cdf0e10cSrcweir     ScMatrixRef         GetMatrix() const       { return xMatrix; }
237cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult>
GetVarRes() const238cdf0e10cSrcweir                         GetVarRes() const       { return xVarRes; }
239cdf0e10cSrcweir };
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
242cdf0e10cSrcweir #endif
243