1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <appluno.hxx>
21 #include <sal/types.h>
22 #include <osl/diagnose.h>
23 #include <cppuhelper/factory.hxx>
24 #include <formula/funcvarargs.h>
26 #include <vcl/svapp.hxx>
27 #include <sfx2/app.hxx>
28 #include <sfx2/sfxmodelfactory.hxx>
29 #include <miscuno.hxx>
31 #include <appoptio.hxx>
32 #include <inputopt.hxx>
33 #include <printopt.hxx>
34 #include <userlist.hxx>
36 #include <unonames.hxx>
37 #include <funcdesc.hxx>
38 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 #include <com/sun/star/sheet/FunctionArgument.hpp>
43 using namespace com::sun::star
;
45 // Number of last used functions, which are saved
46 //! Combine define with funcpage.hxx and dwfunctr.hxx !!!
49 // Special value for zoom
51 #define SC_ZOOMVAL_OPTIMAL (-1)
52 #define SC_ZOOMVAL_WHOLEPAGE (-2)
53 #define SC_ZOOMVAL_PAGEWIDTH (-3)
55 // Number of PropertyValues in a function description
56 #define SC_FUNCDESC_PROPCOUNT 5
58 // everything without Which-ID, map only for PropertySetInfo
60 static const SfxItemPropertyMapEntry
* lcl_GetSettingsPropertyMap()
62 static const SfxItemPropertyMapEntry aSettingsPropertyMap_Impl
[] =
64 {OUString(SC_UNONAME_DOAUTOCP
), 0, cppu::UnoType
<bool>::get(), 0, 0},
65 {OUString(SC_UNONAME_ENTERED
), 0, cppu::UnoType
<bool>::get(), 0, 0},
66 {OUString(SC_UNONAME_EXPREF
), 0, cppu::UnoType
<bool>::get(), 0, 0},
67 {OUString(SC_UNONAME_EXTFMT
), 0, cppu::UnoType
<bool>::get(), 0, 0},
68 {OUString(SC_UNONAME_LINKUPD
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0},
69 {OUString(SC_UNONAME_MARKHDR
), 0, cppu::UnoType
<bool>::get(), 0, 0},
70 {OUString(SC_UNONAME_METRIC
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0},
71 {OUString(SC_UNONAME_MOVEDIR
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0},
72 {OUString(SC_UNONAME_MOVESEL
), 0, cppu::UnoType
<bool>::get(), 0, 0},
73 {OUString(SC_UNONAME_PRALLSH
), 0, cppu::UnoType
<bool>::get(), 0, 0},
74 {OUString(SC_UNONAME_PREMPTY
), 0, cppu::UnoType
<bool>::get(), 0, 0},
75 {OUString(SC_UNONAME_RANGEFIN
), 0, cppu::UnoType
<bool>::get(), 0, 0},
76 {OUString(SC_UNONAME_SCALE
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0},
77 {OUString(SC_UNONAME_STBFUNC
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0},
78 {OUString(SC_UNONAME_ULISTS
), 0, cppu::UnoType
<uno::Sequence
<OUString
>>::get(), 0, 0},
79 {OUString(SC_UNONAME_PRMETRICS
),0, cppu::UnoType
<bool>::get(), 0, 0},
80 {OUString(SC_UNONAME_USETABCOL
),0, cppu::UnoType
<bool>::get(), 0, 0},
81 {OUString(SC_UNONAME_REPLWARN
), 0, cppu::UnoType
<bool>::get(), 0, 0},
82 { OUString(), 0, css::uno::Type(), 0, 0 }
84 return aSettingsPropertyMap_Impl
;
87 #define SCFUNCTIONLISTOBJ_SERVICE "com.sun.star.sheet.FunctionDescriptions"
88 #define SCRECENTFUNCTIONSOBJ_SERVICE "com.sun.star.sheet.RecentFunctions"
89 #define SCSPREADSHEETSETTINGS_SERVICE "com.sun.star.sheet.GlobalSheetSettings"
91 SC_SIMPLE_SERVICE_INFO( ScFunctionListObj
, "stardiv.StarCalc.ScFunctionListObj", SCFUNCTIONLISTOBJ_SERVICE
)
92 SC_SIMPLE_SERVICE_INFO( ScRecentFunctionsObj
, "stardiv.StarCalc.ScRecentFunctionsObj", SCRECENTFUNCTIONSOBJ_SERVICE
)
93 SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettings
, "stardiv.StarCalc.ScSpreadsheetSettings", SCSPREADSHEETSETTINGS_SERVICE
)
97 SAL_DLLPUBLIC_EXPORT
void * sc_component_getFactory(
98 const sal_Char
* pImplName
, void * pServiceManager
, void * /* pRegistryKey */ )
100 if (!pServiceManager
)
103 uno::Reference
<lang::XSingleServiceFactory
> xFactory
;
104 OUString
aImpl(OUString::createFromAscii(pImplName
));
106 if ( aImpl
== ScSpreadsheetSettings::getImplementationName_Static() )
108 xFactory
.set(cppu::createOneInstanceFactory(
109 static_cast<lang::XMultiServiceFactory
*>(pServiceManager
),
110 ScSpreadsheetSettings::getImplementationName_Static(),
111 ScSpreadsheetSettings_CreateInstance
,
112 ScSpreadsheetSettings::getSupportedServiceNames_Static() ));
114 else if ( aImpl
== ScXMLImport_getImplementationName() )
116 xFactory
.set(cppu::createSingleFactory(
117 static_cast<lang::XMultiServiceFactory
*>(pServiceManager
),
118 ScXMLImport_getImplementationName(),
119 ScXMLImport_createInstance
,
120 ScXMLImport_getSupportedServiceNames() ));
122 else if ( aImpl
== ScXMLImport_Meta_getImplementationName() )
124 xFactory
.set(cppu::createSingleFactory(
125 static_cast<lang::XMultiServiceFactory
*>(pServiceManager
),
126 ScXMLImport_Meta_getImplementationName(),
127 ScXMLImport_Meta_createInstance
,
128 ScXMLImport_Meta_getSupportedServiceNames() ));
130 else if ( aImpl
== ScXMLImport_Styles_getImplementationName() )
132 xFactory
.set(cppu::createSingleFactory(
133 static_cast<lang::XMultiServiceFactory
*>(pServiceManager
),
134 ScXMLImport_Styles_getImplementationName(),
135 ScXMLImport_Styles_createInstance
,
136 ScXMLImport_Styles_getSupportedServiceNames() ));
138 else if ( aImpl
== ScXMLImport_Content_getImplementationName() )
140 xFactory
.set(cppu::createSingleFactory(
141 static_cast<lang::XMultiServiceFactory
*>(pServiceManager
),
142 ScXMLImport_Content_getImplementationName(),
143 ScXMLImport_Content_createInstance
,
144 ScXMLImport_Content_getSupportedServiceNames() ));
146 else if ( aImpl
== ScXMLImport_Settings_getImplementationName() )
148 xFactory
.set(cppu::createSingleFactory(
149 static_cast<lang::XMultiServiceFactory
*>(pServiceManager
),
150 ScXMLImport_Settings_getImplementationName(),
151 ScXMLImport_Settings_createInstance
,
152 ScXMLImport_Settings_getSupportedServiceNames() ));
154 else if ( aImpl
== ScDocument_getImplementationName() )
156 xFactory
.set(sfx2::createSfxModelFactory(
157 static_cast<lang::XMultiServiceFactory
*>(pServiceManager
),
158 ScDocument_getImplementationName(),
159 ScDocument_createInstance
,
160 ScDocument_getSupportedServiceNames() ));
163 void* pRet
= nullptr;
167 pRet
= xFactory
.get();
174 ScSpreadsheetSettings::ScSpreadsheetSettings() :
175 aPropSet( lcl_GetSettingsPropertyMap() )
179 ScSpreadsheetSettings::~ScSpreadsheetSettings()
183 uno::Reference
<uno::XInterface
> ScSpreadsheetSettings_CreateInstance(
184 const uno::Reference
<lang::XMultiServiceFactory
>& /* rSMgr */ )
186 SolarMutexGuard aGuard
;
188 return static_cast<cppu::OWeakObject
*>(new ScSpreadsheetSettings());
191 OUString
ScSpreadsheetSettings::getImplementationName_Static()
193 return OUString( "stardiv.StarCalc.ScSpreadsheetSettings" );
196 uno::Sequence
<OUString
> ScSpreadsheetSettings::getSupportedServiceNames_Static()
198 uno::Sequence
<OUString
> aRet
{ SCSPREADSHEETSETTINGS_SERVICE
};
202 bool ScSpreadsheetSettings::getPropertyBool(const OUString
& aPropertyName
)
204 uno::Any any
= getPropertyValue(aPropertyName
);
210 sal_Int16
ScSpreadsheetSettings::getPropertyInt16(const OUString
& aPropertyName
)
212 uno::Any any
= getPropertyValue(aPropertyName
);
220 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScSpreadsheetSettings::getPropertySetInfo()
222 SolarMutexGuard aGuard
;
223 static uno::Reference
<beans::XPropertySetInfo
> aRef(
224 new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
228 void SAL_CALL
ScSpreadsheetSettings::setPropertyValue(
229 const OUString
& aPropertyName
, const uno::Any
& aValue
)
231 SolarMutexGuard aGuard
;
233 ScModule
* pScMod
= SC_MOD();
234 ScAppOptions
aAppOpt(pScMod
->GetAppOptions());
235 ScInputOptions
aInpOpt(pScMod
->GetInputOptions());
236 bool bSaveApp
= false;
237 bool bSaveInp
= false;
238 // print options aren't loaded until needed
240 if (aPropertyName
== SC_UNONAME_DOAUTOCP
)
242 aAppOpt
.SetAutoComplete( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
245 else if (aPropertyName
== SC_UNONAME_ENTERED
)
247 aInpOpt
.SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
250 else if (aPropertyName
== SC_UNONAME_EXPREF
)
252 aInpOpt
.SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
255 else if (aPropertyName
== SC_UNONAME_EXTFMT
)
257 aInpOpt
.SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
260 else if (aPropertyName
== SC_UNONAME_LINKUPD
)
262 // XXX NOTE: this is not css::document::Settings property
263 // LinkUpdateMode but css::sheet::XGlobalSheetSettings attribute
266 if (!(aValue
>>= n
) || n
< 0 || n
>= ScLkUpdMode::LM_UNKNOWN
)
268 throw css::lang::IllegalArgumentException(
269 ("LinkUpdateMode property value must be a SHORT with a value in the range of 0--2"
270 " as documented for css::sheet::XGlobalSheetSettings attribute LinkUpdateMode"),
271 css::uno::Reference
<css::uno::XInterface
>(), -1);
273 aAppOpt
.SetLinkMode( static_cast<ScLkUpdMode
>(n
) );
276 else if (aPropertyName
== SC_UNONAME_MARKHDR
)
278 aInpOpt
.SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
281 else if (aPropertyName
== SC_UNONAME_MOVESEL
)
283 aInpOpt
.SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
286 else if (aPropertyName
== SC_UNONAME_RANGEFIN
)
288 aInpOpt
.SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
291 else if (aPropertyName
== SC_UNONAME_USETABCOL
)
293 aInpOpt
.SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
296 else if (aPropertyName
== SC_UNONAME_PRMETRICS
)
298 aInpOpt
.SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
301 else if (aPropertyName
== SC_UNONAME_REPLWARN
)
303 aInpOpt
.SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
306 else if (aPropertyName
== SC_UNONAME_METRIC
)
308 aAppOpt
.SetAppMetric( static_cast<FieldUnit
>(ScUnoHelpFunctions::GetInt16FromAny( aValue
)) );
311 else if (aPropertyName
== SC_UNONAME_MOVEDIR
)
313 aInpOpt
.SetMoveDir( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
316 else if (aPropertyName
== SC_UNONAME_SCALE
)
318 short nVal
= ScUnoHelpFunctions::GetInt16FromAny( aValue
);
321 SvxZoomType eType
= SvxZoomType::PERCENT
;
324 case SC_ZOOMVAL_OPTIMAL
: eType
= SvxZoomType::OPTIMAL
; break;
325 case SC_ZOOMVAL_WHOLEPAGE
: eType
= SvxZoomType::WHOLEPAGE
; break;
326 case SC_ZOOMVAL_PAGEWIDTH
: eType
= SvxZoomType::PAGEWIDTH
; break;
328 aAppOpt
.SetZoomType( eType
);
330 else if ( nVal
>= MINZOOM
&& nVal
<= MAXZOOM
)
332 aAppOpt
.SetZoom( nVal
);
333 aAppOpt
.SetZoomType( SvxZoomType::PERCENT
);
337 else if (aPropertyName
== SC_UNONAME_STBFUNC
)
339 aAppOpt
.SetStatusFunc( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
342 else if (aPropertyName
== SC_UNONAME_ULISTS
)
344 ScUserList
* pUserList
= ScGlobal::GetUserList();
345 uno::Sequence
<OUString
> aSeq
;
346 if ( pUserList
&& ( aValue
>>= aSeq
) )
348 // directly change the active list
349 // ScGlobal::SetUseTabCol does not do much else
352 sal_uInt16 nCount
= static_cast<sal_uInt16
>(aSeq
.getLength());
353 const OUString
* pAry
= aSeq
.getConstArray();
354 for (sal_uInt16 i
=0; i
<nCount
; i
++)
356 OUString aEntry
= pAry
[i
];
357 ScUserListData
* pData
= new ScUserListData(aEntry
);
358 pUserList
->push_back(pData
);
360 bSaveApp
= true; // List with App-Options are saved
363 else if (aPropertyName
== SC_UNONAME_PRALLSH
)
365 ScPrintOptions
aPrintOpt(pScMod
->GetPrintOptions());
366 aPrintOpt
.SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
367 pScMod
->SetPrintOptions( aPrintOpt
);
369 else if (aPropertyName
== SC_UNONAME_PREMPTY
)
371 ScPrintOptions
aPrintOpt(pScMod
->GetPrintOptions());
372 aPrintOpt
.SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue
) ); // reversed
373 pScMod
->SetPrintOptions( aPrintOpt
);
374 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScPrintOptions
) ); // update previews
378 pScMod
->SetAppOptions( aAppOpt
);
380 pScMod
->SetInputOptions( aInpOpt
);
383 uno::Any SAL_CALL
ScSpreadsheetSettings::getPropertyValue( const OUString
& aPropertyName
)
385 SolarMutexGuard aGuard
;
388 ScModule
* pScMod
= SC_MOD();
389 ScAppOptions aAppOpt
= pScMod
->GetAppOptions();
390 ScInputOptions aInpOpt
= pScMod
->GetInputOptions();
391 // print options aren't loaded until needed
393 if (aPropertyName
== SC_UNONAME_DOAUTOCP
) aRet
<<= aAppOpt
.GetAutoComplete();
394 else if (aPropertyName
== SC_UNONAME_ENTERED
) aRet
<<= aInpOpt
.GetEnterEdit();
395 else if (aPropertyName
== SC_UNONAME_EXPREF
) aRet
<<= aInpOpt
.GetExpandRefs();
396 else if (aPropertyName
== SC_UNONAME_EXTFMT
) aRet
<<= aInpOpt
.GetExtendFormat();
397 else if (aPropertyName
== SC_UNONAME_LINKUPD
) aRet
<<= static_cast<sal_Int16
>(aAppOpt
.GetLinkMode());
398 else if (aPropertyName
== SC_UNONAME_MARKHDR
) aRet
<<= aInpOpt
.GetMarkHeader();
399 else if (aPropertyName
== SC_UNONAME_MOVESEL
) aRet
<<= aInpOpt
.GetMoveSelection();
400 else if (aPropertyName
== SC_UNONAME_RANGEFIN
) aRet
<<= aInpOpt
.GetRangeFinder();
401 else if (aPropertyName
== SC_UNONAME_USETABCOL
) aRet
<<= aInpOpt
.GetUseTabCol();
402 else if (aPropertyName
== SC_UNONAME_PRMETRICS
) aRet
<<= aInpOpt
.GetTextWysiwyg();
403 else if (aPropertyName
== SC_UNONAME_REPLWARN
) aRet
<<= aInpOpt
.GetReplaceCellsWarn();
404 else if (aPropertyName
== SC_UNONAME_METRIC
) aRet
<<= static_cast<sal_Int16
>(aAppOpt
.GetAppMetric());
405 else if (aPropertyName
== SC_UNONAME_MOVEDIR
) aRet
<<= static_cast<sal_Int16
>(aInpOpt
.GetMoveDir());
406 else if (aPropertyName
== SC_UNONAME_STBFUNC
) aRet
<<= static_cast<sal_Int16
>(aAppOpt
.GetStatusFunc());
407 else if (aPropertyName
== SC_UNONAME_SCALE
)
409 sal_Int16 nZoomVal
= 0;
410 switch ( aAppOpt
.GetZoomType() )
412 case SvxZoomType::PERCENT
: nZoomVal
= aAppOpt
.GetZoom(); break;
413 case SvxZoomType::OPTIMAL
: nZoomVal
= SC_ZOOMVAL_OPTIMAL
; break;
414 case SvxZoomType::WHOLEPAGE
: nZoomVal
= SC_ZOOMVAL_WHOLEPAGE
; break;
415 case SvxZoomType::PAGEWIDTH
: nZoomVal
= SC_ZOOMVAL_PAGEWIDTH
; break;
418 // added to avoid warnings
423 else if (aPropertyName
== SC_UNONAME_ULISTS
)
425 ScUserList
* pUserList
= ScGlobal::GetUserList();
428 size_t nCount
= pUserList
->size();
429 uno::Sequence
<OUString
> aSeq(nCount
);
430 OUString
* pAry
= aSeq
.getArray();
431 for (size_t i
=0; i
<nCount
; ++i
)
433 OUString
aEntry((*pUserList
)[i
].GetString());
439 else if (aPropertyName
== SC_UNONAME_PRALLSH
)
440 aRet
<<= pScMod
->GetPrintOptions().GetAllSheets();
441 else if (aPropertyName
== SC_UNONAME_PREMPTY
)
442 aRet
<<= !pScMod
->GetPrintOptions().GetSkipEmpty(); // reversed
447 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettings
)
449 ScRecentFunctionsObj::ScRecentFunctionsObj()
453 ScRecentFunctionsObj::~ScRecentFunctionsObj()
457 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
458 ScRecentFunctionsObj_get_implementation(css::uno::XComponentContext
*, css::uno::Sequence
<css::uno::Any
> const &)
460 SolarMutexGuard aGuard
;
462 return cppu::acquire(new ScRecentFunctionsObj());
467 uno::Sequence
<sal_Int32
> SAL_CALL
ScRecentFunctionsObj::getRecentFunctionIds()
469 SolarMutexGuard aGuard
;
470 const ScAppOptions
& rOpt
= SC_MOD()->GetAppOptions();
471 sal_uInt16 nCount
= rOpt
.GetLRUFuncListCount();
472 const sal_uInt16
* pFuncs
= rOpt
.GetLRUFuncList();
475 uno::Sequence
<sal_Int32
> aSeq(nCount
);
476 sal_Int32
* pAry
= aSeq
.getArray();
477 for (sal_uInt16 i
=0; i
<nCount
; i
++)
481 return uno::Sequence
<sal_Int32
>(0);
484 void SAL_CALL
ScRecentFunctionsObj::setRecentFunctionIds(
485 const uno::Sequence
<sal_Int32
>& aRecentFunctionIds
)
487 SolarMutexGuard aGuard
;
488 sal_uInt16 nCount
= static_cast<sal_uInt16
>(std::min( aRecentFunctionIds
.getLength(), sal_Int32(LRU_MAX
) ));
489 const sal_Int32
* pAry
= aRecentFunctionIds
.getConstArray();
491 std::unique_ptr
<sal_uInt16
[]> pFuncs(nCount
? new sal_uInt16
[nCount
] : nullptr);
492 for (sal_uInt16 i
=0; i
<nCount
; i
++)
493 pFuncs
[i
] = static_cast<sal_uInt16
>(pAry
[i
]); //! check for valid values?
495 ScModule
* pScMod
= SC_MOD();
496 ScAppOptions
aNewOpts(pScMod
->GetAppOptions());
497 aNewOpts
.SetLRUFuncList(pFuncs
.get(), nCount
);
498 pScMod
->SetAppOptions(aNewOpts
);
501 sal_Int32 SAL_CALL
ScRecentFunctionsObj::getMaxRecentFunctions()
506 ScFunctionListObj::ScFunctionListObj()
510 ScFunctionListObj::~ScFunctionListObj()
514 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
515 ScFunctionListObj_get_implementation(css::uno::XComponentContext
*, css::uno::Sequence
<css::uno::Any
> const &)
517 SolarMutexGuard aGuard
;
519 return cppu::acquire(new ScFunctionListObj());
522 static void lcl_FillSequence( uno::Sequence
<beans::PropertyValue
>& rSequence
, const ScFuncDesc
& rDesc
)
524 rDesc
.initArgumentInfo(); // full argument info is needed
526 OSL_ENSURE( rSequence
.getLength() == SC_FUNCDESC_PROPCOUNT
, "Wrong count" );
528 beans::PropertyValue
* pArray
= rSequence
.getArray();
530 pArray
[0].Name
= SC_UNONAME_ID
;
531 pArray
[0].Value
<<= static_cast<sal_Int32
>(rDesc
.nFIndex
);
533 pArray
[1].Name
= SC_UNONAME_CATEGORY
;
534 pArray
[1].Value
<<= static_cast<sal_Int32
>(rDesc
.nCategory
);
536 pArray
[2].Name
= SC_UNONAME_NAME
;
537 if (rDesc
.mxFuncName
)
538 pArray
[2].Value
<<= *rDesc
.mxFuncName
;
540 pArray
[3].Name
= SC_UNONAME_DESCRIPTION
;
541 if (rDesc
.mxFuncDesc
)
542 pArray
[3].Value
<<= *rDesc
.mxFuncDesc
;
544 pArray
[4].Name
= SC_UNONAME_ARGUMENTS
;
545 if (!rDesc
.maDefArgNames
.empty() && !rDesc
.maDefArgDescs
.empty() && rDesc
.pDefArgFlags
)
547 sal_uInt16 nCount
= rDesc
.nArgCount
;
548 if (nCount
>= PAIRED_VAR_ARGS
)
549 nCount
-= PAIRED_VAR_ARGS
- 2;
550 else if (nCount
>= VAR_ARGS
)
551 nCount
-= VAR_ARGS
- 1;
552 sal_uInt16 nSeqCount
= rDesc
.GetSuppressedArgCount();
553 if (nSeqCount
>= PAIRED_VAR_ARGS
)
554 nSeqCount
-= PAIRED_VAR_ARGS
- 2;
555 else if (nSeqCount
>= VAR_ARGS
)
556 nSeqCount
-= VAR_ARGS
- 1;
560 uno::Sequence
<sheet::FunctionArgument
> aArgSeq(nSeqCount
);
561 sheet::FunctionArgument
* pArgAry
= aArgSeq
.getArray();
562 for (sal_uInt16 i
=0, j
=0; i
<nCount
; i
++)
564 sheet::FunctionArgument aArgument
;
565 aArgument
.Name
= rDesc
.maDefArgNames
[i
];
566 aArgument
.Description
= rDesc
.maDefArgDescs
[i
];
567 aArgument
.IsOptional
= rDesc
.pDefArgFlags
[i
].bOptional
;
568 pArgAry
[j
++] = aArgument
;
570 pArray
[4].Value
<<= aArgSeq
;
575 // XFunctionDescriptions
577 uno::Sequence
<beans::PropertyValue
> SAL_CALL
ScFunctionListObj::getById( sal_Int32 nId
)
579 SolarMutexGuard aGuard
;
580 const ScFunctionList
* pFuncList
= ScGlobal::GetStarCalcFunctionList();
582 throw uno::RuntimeException(); // should not happen
584 sal_uInt16 nCount
= static_cast<sal_uInt16
>(pFuncList
->GetCount());
585 for (sal_uInt16 nIndex
=0; nIndex
<nCount
; nIndex
++)
587 const ScFuncDesc
* pDesc
= pFuncList
->GetFunction(nIndex
);
588 if ( pDesc
&& pDesc
->nFIndex
== nId
)
590 uno::Sequence
<beans::PropertyValue
> aSeq( SC_FUNCDESC_PROPCOUNT
);
591 lcl_FillSequence( aSeq
, *pDesc
);
596 throw lang::IllegalArgumentException(); // not found
601 uno::Any SAL_CALL
ScFunctionListObj::getByName( const OUString
& aName
)
603 SolarMutexGuard aGuard
;
604 const ScFunctionList
* pFuncList
= ScGlobal::GetStarCalcFunctionList();
606 throw uno::RuntimeException(); // should not happen
608 sal_uInt16 nCount
= static_cast<sal_uInt16
>(pFuncList
->GetCount());
609 for (sal_uInt16 nIndex
=0; nIndex
<nCount
; nIndex
++)
611 const ScFuncDesc
* pDesc
= pFuncList
->GetFunction(nIndex
);
612 //! Case-insensitiv ???
613 if ( pDesc
&& pDesc
->mxFuncName
&& aName
== *pDesc
->mxFuncName
)
615 uno::Sequence
<beans::PropertyValue
> aSeq( SC_FUNCDESC_PROPCOUNT
);
616 lcl_FillSequence( aSeq
, *pDesc
);
617 return uno::makeAny(aSeq
);
621 throw container::NoSuchElementException(); // not found
626 sal_Int32 SAL_CALL
ScFunctionListObj::getCount()
628 SolarMutexGuard aGuard
;
629 sal_Int32 nCount
= 0;
630 const ScFunctionList
* pFuncList
= ScGlobal::GetStarCalcFunctionList();
632 nCount
= static_cast<sal_Int32
>(pFuncList
->GetCount());
636 uno::Any SAL_CALL
ScFunctionListObj::getByIndex( sal_Int32 nIndex
)
638 SolarMutexGuard aGuard
;
639 const ScFunctionList
* pFuncList
= ScGlobal::GetStarCalcFunctionList();
641 throw uno::RuntimeException(); // should not happen
643 if ( nIndex
>= 0 && nIndex
< static_cast<sal_Int32
>(pFuncList
->GetCount()) )
645 const ScFuncDesc
* pDesc
= pFuncList
->GetFunction(nIndex
);
648 uno::Sequence
<beans::PropertyValue
> aSeq( SC_FUNCDESC_PROPCOUNT
);
649 lcl_FillSequence( aSeq
, *pDesc
);
650 return uno::makeAny(aSeq
);
654 throw lang::IndexOutOfBoundsException(); // illegal index
657 // XEnumerationAccess
659 uno::Reference
<container::XEnumeration
> SAL_CALL
ScFunctionListObj::createEnumeration()
661 SolarMutexGuard aGuard
;
662 return new ScIndexEnumeration(this, "com.sun.star.sheet.FunctionDescriptionEnumeration");
667 uno::Type SAL_CALL
ScFunctionListObj::getElementType()
669 SolarMutexGuard aGuard
;
670 return cppu::UnoType
<uno::Sequence
<beans::PropertyValue
>>::get();
673 sal_Bool SAL_CALL
ScFunctionListObj::hasElements()
675 SolarMutexGuard aGuard
;
676 return ( getCount() > 0 );
679 uno::Sequence
<OUString
> SAL_CALL
ScFunctionListObj::getElementNames()
681 SolarMutexGuard aGuard
;
682 const ScFunctionList
* pFuncList
= ScGlobal::GetStarCalcFunctionList();
685 sal_uInt32 nCount
= pFuncList
->GetCount();
686 uno::Sequence
<OUString
> aSeq(nCount
);
687 OUString
* pAry
= aSeq
.getArray();
688 for (sal_uInt32 nIndex
=0; nIndex
<nCount
; ++nIndex
)
690 const ScFuncDesc
* pDesc
= pFuncList
->GetFunction(nIndex
);
691 if ( pDesc
&& pDesc
->mxFuncName
)
692 pAry
[nIndex
] = *pDesc
->mxFuncName
;
696 return uno::Sequence
<OUString
>(0);
699 sal_Bool SAL_CALL
ScFunctionListObj::hasByName( const OUString
& aName
)
701 SolarMutexGuard aGuard
;
702 const ScFunctionList
* pFuncList
= ScGlobal::GetStarCalcFunctionList();
705 sal_uInt32 nCount
= pFuncList
->GetCount();
706 for (sal_uInt32 nIndex
=0; nIndex
<nCount
; ++nIndex
)
708 const ScFuncDesc
* pDesc
= pFuncList
->GetFunction(nIndex
);
709 //! Case-insensitiv ???
710 if ( pDesc
&& pDesc
->mxFuncName
&& aName
== *pDesc
->mxFuncName
)
717 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */