Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sc / inc / funcdesc.hxx
bloba507962df6d3ad14c497edb7c2b8b9b89f2a6d1c
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 SC_FUNCDESC_HXX
21 #define SC_FUNCDESC_HXX
23 /* Function descriptions for function wizard / autopilot */
25 #include "scfuncs.hrc"
27 #include <formula/IFunctionDescription.hxx>
28 #include <sal/types.h>
29 #include <rtl/ustring.hxx>
31 #define MAX_FUNCCAT 12 /* maximum number of categories for functions */
32 #define LRU_MAX 10 /* maximal number of last recently used functions */
34 class ScFuncDesc;
35 class ScFunctionList;
36 class ScFunctionCategory;
37 class ScFunctionMgr;
39 /**
40 Stores and generates human readable descriptions for spreadsheet-functions,
41 e.g.\ functions used in formulas in calc
43 class ScFuncDesc : public formula::IFunctionDescription
45 public:
46 ScFuncDesc();
47 virtual ~ScFuncDesc();
49 /**
50 Clears the object
52 Deletes all objets referenced by the pointers in the class,
53 sets pointers to NULL, and all numerical variables to 0
55 void Clear();
57 /**
58 Fills a mapping with indexes for non-suppressed arguments
60 Fills mapping from visible arguments to real arguments, e.g. if of 4
61 parameters the second one is suppressed {0,2,3}. For VAR_ARGS
62 parameters only one element is added to the end of the sequence.
64 @param _rArgumens
65 Vector, which the indices are written to
67 virtual void fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const ;
69 /**
70 Returns the category of the function
72 @return the category of the function
74 virtual const formula::IFunctionCategory* getCategory() const ;
76 /**
77 Returns the description of the function
79 @return the description of the function, or an empty OUString if there is no description
81 virtual OUString getDescription() const ;
83 /**
84 Returns the function signature with parameters from the passed string array.
86 @return function signature with parameters
88 virtual OUString getFormula(const ::std::vector< OUString >& _aArguments) const ;
90 /**
91 Returns the name of the function
93 @return the name of the function, or an empty OUString if there is no name
95 virtual OUString getFunctionName() const ;
97 /**
98 Returns the help id of the function
100 @return help id of the function
102 virtual OString getHelpId() const ;
105 Returns number of arguments
107 @return help id of the function
109 virtual sal_uInt32 getParameterCount() const ;
112 Returns description of parameter at given position
114 @param _nPos
115 Position of the parameter
117 @return OUString description of the parameter
119 virtual OUString getParameterDescription(sal_uInt32 _nPos) const ;
122 Returns name of parameter at given position
124 @param _nPos
125 Position of the parameter
127 @return OUString name of the parameter
129 virtual OUString getParameterName(sal_uInt32 _nPos) const ;
132 Returns list of all parameter names
134 @return OUString containing separated list of all parameter names
136 OUString GetParamList() const;
139 Returns the full function signature
141 @return OUString of the form "FUNCTIONNAME( parameter list )"
143 virtual OUString getSignature() const ;
146 Returns the number of non-suppressed arguments
148 In case there are variable arguments the number of fixed non-suppressed
149 arguments plus VAR_ARGS, same as for nArgCount (variable arguments can't
150 be suppressed). The two functions are equal apart from return type and
151 name.
153 @return number of non-suppressed arguments
155 sal_uInt16 GetSuppressedArgCount() const;
156 virtual xub_StrLen getSuppressedArgumentCount() const ;
159 Requests function data from AddInCollection
161 Logs error message on failure for debugging purposes
163 virtual void initArgumentInfo() const;
166 Returns true if parameter at given position is optional
168 @param _nPos
169 Position of the parameter
171 @return true if optional, false if not optional
173 virtual bool isParameterOptional(sal_uInt32 _nPos) const ;
176 Compares functions by name, respecting special characters
178 @param a
179 pointer to first function descriptor
181 @param b
182 pointer to second function descriptor
184 @return "(a < b)"
186 static bool compareByName(const ScFuncDesc* a, const ScFuncDesc* b);
189 Stores whether a parameter is optional or suppressed
191 struct ParameterFlags
193 bool bOptional :1; /**< Parameter is optional */
194 bool bSuppress :1; /**< Suppress parameter in UI because not implemented yet */
196 ParameterFlags() : bOptional(false), bSuppress(false) {}
201 OUString *pFuncName; /**< Function name */
202 OUString *pFuncDesc; /**< Description of function */
203 OUString **ppDefArgNames; /**< Parameter name(s) */
204 OUString **ppDefArgDescs; /**< Description(s) of parameter(s) */
205 ParameterFlags *pDefArgFlags; /**< Flags for each parameter */
206 sal_uInt16 nFIndex; /**< Unique function index */
207 sal_uInt16 nCategory; /**< Function category */
208 sal_uInt16 nArgCount; /**< All parameter count, suppressed and unsuppressed */
209 OString sHelpId; /**< HelpId of function */
210 bool bIncomplete :1; /**< Incomplete argument info (set for add-in info from configuration) */
211 bool bHasSuppressedArgs :1; /**< Whether there is any suppressed parameter. */
215 List of spreadsheet functions.
216 Generated by retrieving functions from resources, AddIns and StarOne AddIns,
217 and storing these in one linked list. Functions can be retrieved by index and
218 by iterating through the list, starting at the First element, and retrieving
219 the Next elements one by one.
221 The length of the longest function name can be retrieved for easier
222 processing (i.e printing a function list).
224 class ScFunctionList
226 public:
227 ScFunctionList();
228 ~ScFunctionList();
230 sal_uInt32 GetCount() const
231 { return aFunctionList.size(); }
233 const ScFuncDesc* First();
235 const ScFuncDesc* Next();
237 const ScFuncDesc* GetFunction( sal_uInt32 nIndex ) const;
239 xub_StrLen GetMaxFuncNameLen() const
240 { return nMaxFuncNameLen; }
242 private:
243 ::std::vector<const ScFuncDesc*> aFunctionList; /**< List of functions */
244 ::std::vector<const ScFuncDesc*>::iterator aFunctionListIter; /**< position in function list */
245 xub_StrLen nMaxFuncNameLen; /**< Length of longest function name */
249 Category of spreadsheet functions.
251 Contains the name, index and function manager of a category,
252 as well as a list of functions in the category
254 class ScFunctionCategory : public formula::IFunctionCategory
256 public:
257 ScFunctionCategory(ScFunctionMgr* _pMgr,::std::vector<const ScFuncDesc*>* _pCategory,sal_uInt32 _nCategory)
258 : m_pMgr(_pMgr),m_pCategory(_pCategory),m_nCategory(_nCategory){}
259 virtual ~ScFunctionCategory(){}
262 @return count of functions in this category
264 virtual sal_uInt32 getCount() const;
265 virtual const formula::IFunctionManager* getFunctionManager() const;
268 Gives the _nPos'th function in this category.
270 @param _nPos
271 position of function in this category.
273 @return function at the _nPos postion in this category, null if _nPos out of bounds.
275 virtual const formula::IFunctionDescription* getFunction(sal_uInt32 _nPos) const;
278 @return index number of this category.
280 virtual sal_uInt32 getNumber() const;
281 virtual OUString getName() const;
283 private:
284 ScFunctionMgr* m_pMgr; /**< function manager for this category */
285 ::std::vector<const ScFuncDesc*>* m_pCategory; /**< list of functions in this category */
286 mutable OUString m_sName; /**< name of this category */
287 sal_uInt32 m_nCategory; /**< index number of this category */
290 #define SC_FUNCGROUP_COUNT ID_FUNCTION_GRP_ADDINS
292 Stores spreadsheet functions in categories, including a cumulative ('All') category and makes them accessible.
294 class ScFunctionMgr : public formula::IFunctionManager
296 public:
298 Retrieves all calc functions, generates cumulative ('All') category, and the categories.
300 The function lists of the categories are sorted by (case insensitive) function name
302 ScFunctionMgr();
303 virtual ~ScFunctionMgr();
306 Returns name of category.
308 @param _nCategoryNumber
309 index of category
311 @return name of the category specified by _nCategoryNumber, empty string if _nCategoryNumber out of bounds
313 static OUString GetCategoryName(sal_uInt32 _nCategoryNumber );
316 Returns function by name.
318 Searches for a function with the function name rFName, while ignoring case.
320 @param rFName
321 name of the function
323 @return pointer to function with the name rFName, null if no such function was found.
325 const ScFuncDesc* Get( const OUString& rFName ) const;
328 Returns function by index.
330 Searches for a function with the function index nFIndex.
332 @param nFIndex
333 index of the function
335 @return pointer to function with the index nFIndex, null if no such function was found.
337 const ScFuncDesc* Get( sal_uInt16 nFIndex ) const;
340 Returns the first function in category nCategory.
342 Selects nCategory as current category and returns first element of this.
344 @param nCategory
345 index of requested category
347 @return pointer to first element in current category, null if nCategory out of bounds
349 const ScFuncDesc* First( sal_uInt16 nCategory = 0 ) const;
352 Returns the next function of the current category.
354 @return pointer to the next function in current category, null if current category not set.
356 const ScFuncDesc* Next() const;
359 @return number of categories, not counting the cumulative category ('All')
361 virtual sal_uInt32 getCount() const;
364 Returns a category.
366 Creates an IFunctionCategory object from a category specified by nPos.
368 @param nPos
369 the index of the category, note that 0 maps to the first category not the cumulative ('All') category.
371 @return pointer to an IFunctionCategory object, null if nPos out of bounds.
373 virtual const formula::IFunctionCategory* getCategory(sal_uInt32 nPos) const;
376 Appends the last recently used functions.
378 Takes the last recently used functions, but maximal LRU_MAX, and appends them to the given vector _rLastRUFunctions.
380 @param _rLastRUFunctions
381 a vector of pointer to IFunctionDescription, by reference.
383 virtual void fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& _rLastRUFunctions) const;
386 Implemented because of inheritance \see ScFunctionMgr::Get(const OUString&) const
388 virtual const formula::IFunctionDescription* getFunctionByName(const OUString& _sFunctionName) const;
391 Maps Etoken to character
393 Used for retrieving characters for parantheses and separators.
395 @param _eToken
396 token for which, the corresponding character is retrieved
398 @return character
400 virtual sal_Unicode getSingleToken(const formula::IFunctionManager::EToken _eToken) const;
402 private:
403 ScFunctionList* pFuncList; /**< list of all calc functions */
404 ::std::vector<const ScFuncDesc*>* aCatLists[MAX_FUNCCAT]; /**< array of all categories, 0 is the cumulative ('All') category */
405 mutable ::std::vector<const ScFuncDesc*>::iterator pCurCatListIter; /**< position in current category */
406 mutable ::std::vector<const ScFuncDesc*>::iterator pCurCatListEnd; /**< end of current category */
409 #endif // SC_FUNCDESC_HXX
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */