LibreOffice Module sc (master)  1
funcdesc.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 /* Function descriptions for function wizard / autopilot */
23 
24 #include "scfuncs.hxx"
25 
27 #include <sal/types.h>
28 #include <rtl/ustring.hxx>
29 #include <optional>
30 #include <map>
31 #include <memory>
32 
33 #define MAX_FUNCCAT 12 /* maximum number of categories for functions */
34 #define LRU_MAX 10 /* maximal number of last recently used functions */
35 
41 {
42 public:
43  ScFuncDesc();
44  virtual ~ScFuncDesc();
45 
52  void Clear();
53 
64  virtual void fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const override ;
65 
71  virtual const formula::IFunctionCategory* getCategory() const override ;
72 
78  virtual OUString getDescription() const override ;
79 
85  virtual OUString getFormula(const ::std::vector< OUString >& _aArguments) const override ;
86 
92  virtual OUString getFunctionName() const override ;
93 
99  virtual OString getHelpId() const override ;
100 
106  virtual bool isHidden() const override;
107 
113  virtual sal_uInt32 getParameterCount() const override ;
114 
120  virtual sal_uInt32 getVarArgsStart() const override ;
121 
127  virtual sal_uInt32 getVarArgsLimit() const override ;
128 
137  virtual OUString getParameterDescription(sal_uInt32 _nPos) const override ;
138 
147  virtual OUString getParameterName(sal_uInt32 _nPos) const override ;
148 
154  OUString GetParamList() const;
155 
161  virtual OUString getSignature() const override ;
162 
173  sal_uInt16 GetSuppressedArgCount() const;
174  virtual sal_Int32 getSuppressedArgumentCount() const override ;
175 
181  virtual void initArgumentInfo() const override;
182 
191  virtual bool isParameterOptional(sal_uInt32 _nPos) const override ;
192 
204  static bool compareByName(const ScFuncDesc* a, const ScFuncDesc* b);
205 
210  {
211  bool bOptional :1;
213  ParameterFlags() : bOptional(false) {}
214  };
215 
216  std::optional<OUString> mxFuncName;
217  std::optional<OUString> mxFuncDesc;
218  std::vector<OUString> maDefArgNames;
219  std::vector<OUString> maDefArgDescs;
221  sal_uInt16 nFIndex;
222  sal_uInt16 nCategory;
223  sal_uInt16 nArgCount;
224  sal_uInt16 nVarArgsStart;
225  sal_uInt16 nVarArgsLimit;
226  OString sHelpId;
227  bool bIncomplete :1;
228  bool mbHidden :1;
229 };
230 
242 {
243 public:
244  ScFunctionList();
245  ~ScFunctionList();
246 
247  sal_uInt32 GetCount() const
248  { return aFunctionList.size(); }
249 
250  const ScFuncDesc* First();
251 
252  const ScFuncDesc* Next();
253 
254  const ScFuncDesc* GetFunction( sal_uInt32 nIndex ) const;
255 
256 private:
257  ::std::vector<const ScFuncDesc*> aFunctionList;
258  ::std::vector<const ScFuncDesc*>::iterator aFunctionListIter;
259 };
260 
268 {
269 public:
270  ScFunctionCategory(::std::vector<const ScFuncDesc*>* _pCategory,sal_uInt32 _nCategory)
271  : m_pCategory(_pCategory),m_nCategory(_nCategory){}
273 
277  virtual sal_uInt32 getCount() const override;
278 
287  virtual const formula::IFunctionDescription* getFunction(sal_uInt32 _nPos) const override;
288 
292  virtual sal_uInt32 getNumber() const override;
293  virtual OUString getName() const override;
294 
295 private:
296  ::std::vector<const ScFuncDesc*>* m_pCategory;
297  mutable OUString m_sName;
298  sal_uInt32 m_nCategory;
299 };
300 
301 #define SC_FUNCGROUP_COUNT ID_FUNCTION_GRP_ADDINS
302 
306 {
307 public:
313  ScFunctionMgr();
314  virtual ~ScFunctionMgr();
315 
324  static OUString GetCategoryName(sal_uInt32 _nCategoryNumber );
325 
336  const ScFuncDesc* Get( sal_uInt16 nFIndex ) const;
337 
348  const ScFuncDesc* First( sal_uInt16 nCategory = 0 ) const;
349 
355  const ScFuncDesc* Next() const;
356 
360  virtual sal_uInt32 getCount() const override;
361 
372  virtual const formula::IFunctionCategory* getCategory(sal_uInt32 nPos) const override;
373 
382  virtual void fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& _rLastRUFunctions) const override;
383 
394  virtual sal_Unicode getSingleToken(const formula::IFunctionManager::EToken _eToken) const override;
395 
396 private:
397  std::unique_ptr<std::vector<const ScFuncDesc*>> aCatLists[MAX_FUNCCAT];
398  mutable std::map< sal_uInt32, std::shared_ptr<ScFunctionCategory> > m_aCategories;
399  mutable std::vector<const ScFuncDesc*>::iterator pCurCatListIter;
400  mutable std::vector<const ScFuncDesc*>::iterator pCurCatListEnd;
401 };
402 
403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_uInt32 getCount() const override
Definition: funcdesc.cxx:1133
sal_uInt32 m_nCategory
index number of this category
Definition: funcdesc.hxx:298
virtual bool isHidden() const override
Returns whether function is hidden and not offered in the Function Wizard unless used in an expressio...
Definition: funcdesc.cxx:358
List of spreadsheet functions.
Definition: funcdesc.hxx:241
OUString m_sName
name of this category
Definition: funcdesc.hxx:297
virtual sal_uInt32 getVarArgsStart() const override
Returns start of variable arguments.
Definition: funcdesc.cxx:368
std::map< sal_uInt32, std::shared_ptr< ScFunctionCategory > > m_aCategories
map of category pos to IFunctionCategory
Definition: funcdesc.hxx:398
sal_uInt16 GetSuppressedArgCount() const
Returns the number of non-suppressed arguments.
Definition: funcdesc.cxx:278
bool bOptional
Parameter is optional.
Definition: funcdesc.hxx:211
virtual sal_Int32 getSuppressedArgumentCount() const override
Definition: funcdesc.cxx:304
const ScFuncDesc * Get(sal_uInt16 nFIndex) const
Returns function by index.
Definition: funcdesc.cxx:1093
const ScFuncDesc * Next() const
Returns the next function of the current category.
Definition: funcdesc.cxx:1120
Stores whether a parameter is optional or suppressed.
Definition: funcdesc.hxx:209
virtual sal_uInt32 getVarArgsLimit() const override
Returns maximum number of (variable) arguments.
Definition: funcdesc.cxx:373
virtual OUString getName() const override
Definition: funcdesc.cxx:1024
virtual bool isParameterOptional(sal_uInt32 _nPos) const override
Returns true if parameter at given position is optional.
Definition: funcdesc.cxx:388
virtual const formula::IFunctionCategory * getCategory(sal_uInt32 nPos) const override
Returns a category.
Definition: funcdesc.cxx:1138
virtual sal_Unicode getSingleToken(const formula::IFunctionManager::EToken _eToken) const override
Maps Etoken to character.
Definition: funcdesc.cxx:1176
virtual sal_uInt32 getNumber() const override
Definition: funcdesc.cxx:1039
virtual OUString getParameterDescription(sal_uInt32 _nPos) const override
Returns description of parameter at given position.
Definition: funcdesc.cxx:383
Stores spreadsheet functions in categories, including a cumulative ('All') category and makes them ac...
Definition: funcdesc.hxx:305
virtual ~ScFunctionMgr()
Definition: funcdesc.cxx:1088
bool mbHidden
Whether function is hidden.
Definition: funcdesc.hxx:228
virtual const formula::IFunctionDescription * getFunction(sal_uInt32 _nPos) const override
Gives the _nPos'th function in this category.
Definition: funcdesc.cxx:1031
virtual ~ScFunctionCategory()
Definition: funcdesc.hxx:272
sal_uInt16 sal_Unicode
::std::vector< const ScFuncDesc * > * m_pCategory
list of functions in this category
Definition: funcdesc.hxx:296
Category of spreadsheet functions.
Definition: funcdesc.hxx:267
const ScFuncDesc * First()
Definition: funcdesc.cxx:988
ParameterFlags * pDefArgFlags
Flags for each parameter.
Definition: funcdesc.hxx:220
virtual OUString getFormula(const ::std::vector< OUString > &_aArguments) const override
Returns the function signature with parameters from the passed string array.
Definition: funcdesc.cxx:247
OUString GetParamList() const
Returns list of all parameter names.
Definition: funcdesc.cxx:146
sal_uInt16 nCategory
Function category.
Definition: funcdesc.hxx:222
virtual OUString getSignature() const override
Returns the full function signature.
Definition: funcdesc.cxx:224
uno_Any a
virtual sal_uInt32 getParameterCount() const override
Returns number of arguments.
Definition: funcdesc.cxx:363
std::vector< OUString > maDefArgDescs
Description(s) of parameter(s)
Definition: funcdesc.hxx:219
static bool compareByName(const ScFuncDesc *a, const ScFuncDesc *b)
Compares functions by name, respecting special characters.
Definition: funcdesc.cxx:393
virtual void fillVisibleArgumentMapping(::std::vector< sal_uInt16 > &_rArguments) const override
Fills a mapping with indexes for non-suppressed arguments.
Definition: funcdesc.cxx:309
std::optional< OUString > mxFuncDesc
Description of function.
Definition: funcdesc.hxx:217
std::vector< const ScFuncDesc * >::iterator pCurCatListIter
position in current category
Definition: funcdesc.hxx:399
static OUString GetCategoryName(sal_uInt32 _nCategoryNumber)
Returns name of category.
Definition: funcdesc.cxx:1165
virtual OString getHelpId() const override
Returns the help id of the function.
Definition: funcdesc.cxx:353
const ScFuncDesc * GetFunction(sal_uInt32 nIndex) const
Definition: funcdesc.cxx:1009
virtual const formula::IFunctionCategory * getCategory() const override
Returns the category of the function.
Definition: funcdesc.cxx:291
virtual sal_uInt32 getCount() const override
Definition: funcdesc.cxx:1019
std::unique_ptr< std::vector< const ScFuncDesc * > > aCatLists[MAX_FUNCCAT]
array of all categories, 0 is the cumulative ('All') category
Definition: funcdesc.hxx:397
ScFunctionCategory(::std::vector< const ScFuncDesc * > *_pCategory, sal_uInt32 _nCategory)
Definition: funcdesc.hxx:270
virtual void fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription * > &_rLastRUFunctions) const override
Appends the last recently used functions.
Definition: funcdesc.cxx:1149
sal_uInt16 nVarArgsStart
Start of variable arguments, for numbering.
Definition: funcdesc.hxx:224
sal_uInt16 nVarArgsLimit
Limit maximum of (variable) arguments, for numbering.
Definition: funcdesc.hxx:225
std::optional< OUString > mxFuncName
Function name.
Definition: funcdesc.hxx:216
void Clear()
Clears the object.
Definition: funcdesc.cxx:118
ScFunctionMgr()
Retrieves all calc functions, generates cumulative ('All') category, and the categories.
Definition: funcdesc.cxx:1045
#define MAX_FUNCCAT
Definition: funcdesc.hxx:33
virtual void initArgumentInfo() const override
Requests function data from AddInCollection.
Definition: funcdesc.cxx:327
const ScFuncDesc * Next()
Definition: funcdesc.cxx:998
sal_Int32 _nPos
sal_uInt16 nFIndex
Unique function index.
Definition: funcdesc.hxx:221
sal_uInt32 GetCount() const
Definition: funcdesc.hxx:247
virtual OUString getDescription() const override
Returns the description of the function.
Definition: funcdesc.cxx:296
OString sHelpId
HelpId of function.
Definition: funcdesc.hxx:226
virtual OUString getFunctionName() const override
Returns the name of the function.
Definition: funcdesc.cxx:283
std::vector< OUString > maDefArgNames
Parameter name(s)
Definition: funcdesc.hxx:218
::std::vector< const ScFuncDesc * >::iterator aFunctionListIter
position in function list
Definition: funcdesc.hxx:258
virtual OUString getParameterName(sal_uInt32 _nPos) const override
Returns name of parameter at given position.
Definition: funcdesc.cxx:378
bool bIncomplete
Incomplete argument info (set for add-in info from configuration)
Definition: funcdesc.hxx:227
Stores and generates human readable descriptions for spreadsheet-functions, e.g. functions used in fo...
Definition: funcdesc.hxx:40
sal_uInt16 nArgCount
All parameter count, suppressed and unsuppressed.
Definition: funcdesc.hxx:223
std::vector< const ScFuncDesc * >::iterator pCurCatListEnd
end of current category
Definition: funcdesc.hxx:400
virtual ~ScFuncDesc()
Definition: funcdesc.cxx:113
::std::vector< const ScFuncDesc * > aFunctionList
List of functions.
Definition: funcdesc.hxx:257
sal_uInt16 nPos
const ScFuncDesc * First(sal_uInt16 nCategory=0) const
Returns the first function in category nCategory.
Definition: funcdesc.cxx:1102