Revert "tdf#110987: type detection, binary Office formats > templates"
[LibreOffice.git] / sc / inc / addincol.hxx
blob46de0b84c7efd6704a489bc626d9f4e1961d0924
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 #ifndef INCLUDED_SC_INC_ADDINCOL_HXX
21 #define INCLUDED_SC_INC_ADDINCOL_HXX
23 #include <memory>
24 #include <com/sun/star/uno/Any.h>
25 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/uno/Sequence.h>
27 #include <formula/errorcodes.hxx>
28 #include <i18nlangtag/lang.h>
29 #include "scdllapi.h"
30 #include <rtl/ustring.hxx>
32 #include "types.hxx"
34 #include <vector>
35 #include <unordered_map>
37 namespace com { namespace sun { namespace star { namespace reflection { class XIdlMethod; } } } }
38 namespace com { namespace sun { namespace star { namespace sheet { class XVolatileResult; } } } }
39 namespace com { namespace sun { namespace star { namespace uno { class XInterface; } } } }
41 class SfxObjectShell;
42 class ScUnoAddInFuncData;
43 class ScFuncDesc;
45 typedef std::unordered_map< OUString, const ScUnoAddInFuncData* > ScAddInHashMap;
47 enum ScAddInArgumentType
49 SC_ADDINARG_NONE, ///< -
50 SC_ADDINARG_INTEGER, ///< long
51 SC_ADDINARG_DOUBLE, ///< double
52 SC_ADDINARG_STRING, ///< string
53 SC_ADDINARG_INTEGER_ARRAY, ///< sequence<sequence<long>>
54 SC_ADDINARG_DOUBLE_ARRAY, ///< sequence<sequence<double>>
55 SC_ADDINARG_STRING_ARRAY, ///< sequence<sequence<string>>
56 SC_ADDINARG_MIXED_ARRAY, ///< sequence<sequence<any>>
57 SC_ADDINARG_VALUE_OR_ARRAY, ///< any
58 SC_ADDINARG_CELLRANGE, ///< XCellRange
59 SC_ADDINARG_CALLER, ///< XPropertySet
60 SC_ADDINARG_VARARGS ///< sequence<any>
63 struct ScAddInArgDesc
65 OUString aInternalName; ///< used to match configuration and reflection information
66 OUString aName;
67 OUString aDescription;
68 ScAddInArgumentType eType;
69 bool bOptional;
72 class ScUnoAddInFuncData
74 public:
75 struct LocalizedName
77 OUString maLocale;
78 OUString maName;
80 LocalizedName( const OUString& rLocale, const OUString& rName )
81 : maLocale( rLocale), maName( rName) { }
83 private:
84 OUString aOriginalName; ///< kept in formula
85 OUString aLocalName; ///< for display
86 OUString aUpperName; ///< for entering formulas
87 OUString aUpperLocal; ///< for entering formulas
88 OUString aDescription;
89 css::uno::Reference< css::reflection::XIdlMethod> xFunction;
90 css::uno::Any aObject;
91 long nArgCount;
92 std::unique_ptr<ScAddInArgDesc[]>
93 pArgDescs;
94 long nCallerPos;
95 sal_uInt16 nCategory;
96 OString sHelpId;
97 mutable ::std::vector< LocalizedName > maCompNames;
98 mutable bool bCompInitialized;
100 public:
101 ScUnoAddInFuncData( const OUString& rNam, const OUString& rLoc,
102 const OUString& rDesc,
103 sal_uInt16 nCat, const OString&,
104 const css::uno::Reference< css::reflection::XIdlMethod>& rFunc,
105 const css::uno::Any& rO,
106 long nAC, const ScAddInArgDesc* pAD,
107 long nCP );
108 ~ScUnoAddInFuncData();
110 const OUString& GetOriginalName() const { return aOriginalName; }
111 const OUString& GetLocalName() const { return aLocalName; }
112 const OUString& GetUpperName() const { return aUpperName; }
113 const OUString& GetUpperLocal() const { return aUpperLocal; }
114 const css::uno::Reference< css::reflection::XIdlMethod>& GetFunction() const
115 { return xFunction; }
116 const css::uno::Any& GetObject() const { return aObject; }
117 long GetArgumentCount() const { return nArgCount; }
118 const ScAddInArgDesc* GetArguments() const { return pArgDescs.get(); }
119 long GetCallerPos() const { return nCallerPos; }
120 const OUString& GetDescription() const { return aDescription; }
121 sal_uInt16 GetCategory() const { return nCategory; }
122 const OString& GetHelpId() const { return sHelpId; }
124 const ::std::vector< LocalizedName >& GetCompNames() const;
125 bool GetExcelName( LanguageType eDestLang, OUString& rRetExcelName ) const;
127 void SetFunction( const css::uno::Reference< css::reflection::XIdlMethod>& rNewFunc,
128 const css::uno::Any& rNewObj );
129 void SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs );
130 void SetCallerPos( long nNewPos );
131 void SetCompNames( const ::std::vector< LocalizedName >& rNew );
134 class SC_DLLPUBLIC ScUnoAddInCollection
136 private:
137 long nFuncCount;
138 std::unique_ptr<std::unique_ptr<ScUnoAddInFuncData>[]> ppFuncData;
139 std::unique_ptr<ScAddInHashMap> pExactHashMap; ///< exact internal name
140 std::unique_ptr<ScAddInHashMap> pNameHashMap; ///< internal name upper
141 std::unique_ptr<ScAddInHashMap> pLocalHashMap; ///< localized name upper
142 bool bInitialized;
144 void Initialize();
145 void ReadConfiguration();
146 void ReadFromAddIn( const css::uno::Reference< css::uno::XInterface>& xInterface );
147 void UpdateFromAddIn( const css::uno::Reference< css::uno::XInterface>& xInterface,
148 const OUString& rServiceName );
149 void LoadComponent( const ScUnoAddInFuncData& rFuncData );
151 public:
152 ScUnoAddInCollection();
153 ~ScUnoAddInCollection();
155 /// User entered name. rUpperName MUST already be upper case!
156 const OUString & FindFunction( const OUString& rUpperName, bool bLocalFirst );
158 /** Only if bComplete is set, the function reference and argument types
159 are initialized (component may have to be loaded).
160 @param rName is the exact Name. */
161 const ScUnoAddInFuncData* GetFuncData( const OUString& rName, bool bComplete = false );
163 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
164 @param nIndex
165 0 <= nIndex < GetFuncCount()
167 const ScUnoAddInFuncData* GetFuncData( long nIndex );
169 void Clear();
171 void LocalizeString( OUString& rName ); ///< modify rName - input: exact name
173 long GetFuncCount();
174 bool FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
176 static bool FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc );
177 /// leave rRetExcelName unchanged, if no matching name is found
178 bool GetExcelName( const OUString& rCalcName, LanguageType eDestLang, OUString& rRetExcelName );
179 /// leave rRetCalcName unchanged, if no matching name is found
180 bool GetCalcName( const OUString& rExcelName, OUString& rRetCalcName );
183 class ScUnoAddInCall
185 private:
186 const ScUnoAddInFuncData* pFuncData;
187 css::uno::Sequence<css::uno::Any> aArgs;
188 css::uno::Sequence<css::uno::Any> aVarArg;
189 css::uno::Reference<css::uno::XInterface> xCaller;
190 bool bValidCount;
191 // result:
192 FormulaError nErrCode;
193 bool bHasString;
194 double fValue;
195 OUString aString;
196 ScMatrixRef xMatrix;
197 css::uno::Reference<css::sheet::XVolatileResult> xVarRes;
199 void ExecuteCallWithArgs(css::uno::Sequence<css::uno::Any>& rCallArgs);
201 public:
202 // exact name
203 ScUnoAddInCall( ScUnoAddInCollection& rColl, const OUString& rName,
204 long nParamCount );
205 ~ScUnoAddInCall();
207 bool NeedsCaller() const;
208 void SetCaller( const css::uno::Reference<css::uno::XInterface>& rInterface );
209 void SetCallerFromObjectShell( const SfxObjectShell* pSh );
211 bool ValidParamCount() { return bValidCount;}
212 ScAddInArgumentType GetArgType( long nPos );
213 void SetParam( long nPos, const css::uno::Any& rValue );
215 void ExecuteCall();
217 void SetResult( const css::uno::Any& rNewRes );
219 FormulaError GetErrCode() const { return nErrCode; }
220 bool HasString() const { return bHasString; }
221 bool HasMatrix() const { return xMatrix.get(); }
222 bool HasVarRes() const { return xVarRes.is(); }
223 double GetValue() const { return fValue; }
224 const OUString& GetString() const { return aString; }
225 const ScMatrixRef& GetMatrix() const { return xMatrix;}
226 const css::uno::Reference<css::sheet::XVolatileResult>&
227 GetVarRes() const { return xVarRes; }
230 #endif
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */