tdf#42949 Fix IWYU warnings in sc/source/ui/unoobj/*
[LibreOffice.git] / sc / source / ui / unoobj / appluno.cxx
blob1f14265e5a2bfb7c725228053770549325e416ef
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 #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>
30 #include <scmod.hxx>
31 #include <appoptio.hxx>
32 #include <inputopt.hxx>
33 #include <printopt.hxx>
34 #include <userlist.hxx>
35 #include <scdll.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>
41 #include <memory>
43 using namespace com::sun::star;
45 // Number of last used functions, which are saved
46 //! Combine define with funcpage.hxx and dwfunctr.hxx !!!
47 #define LRU_MAX 10
49 // Special value for zoom
50 //! somewhere central
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 )
95 extern "C" {
97 SAL_DLLPUBLIC_EXPORT void * sc_component_getFactory(
98 const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
100 if (!pServiceManager)
101 return nullptr;
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;
164 if (xFactory.is())
166 xFactory->acquire();
167 pRet = xFactory.get();
169 return pRet;
172 } // extern C
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;
187 ScDLL::Init();
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 };
199 return aRet;
202 bool ScSpreadsheetSettings::getPropertyBool(const OUString& aPropertyName)
204 uno::Any any = getPropertyValue(aPropertyName);
205 bool b = false;
206 any >>= b;
207 return b;
210 sal_Int16 ScSpreadsheetSettings::getPropertyInt16(const OUString& aPropertyName)
212 uno::Any any = getPropertyValue(aPropertyName);
213 sal_Int16 b = 0;
214 any >>= b;
215 return b;
218 // XPropertySet
220 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettings::getPropertySetInfo()
222 SolarMutexGuard aGuard;
223 static uno::Reference<beans::XPropertySetInfo> aRef(
224 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
225 return aRef;
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 ) );
243 bSaveApp = true;
245 else if (aPropertyName == SC_UNONAME_ENTERED)
247 aInpOpt.SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
248 bSaveInp = true;
250 else if (aPropertyName == SC_UNONAME_EXPREF)
252 aInpOpt.SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
253 bSaveInp = true;
255 else if (aPropertyName == SC_UNONAME_EXTFMT)
257 aInpOpt.SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
258 bSaveInp = true;
260 else if (aPropertyName == SC_UNONAME_LINKUPD)
262 // XXX NOTE: this is not css::document::Settings property
263 // LinkUpdateMode but css::sheet::XGlobalSheetSettings attribute
264 // LinkUpdateMode.
265 sal_Int16 n;
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) );
274 bSaveApp = true;
276 else if (aPropertyName == SC_UNONAME_MARKHDR)
278 aInpOpt.SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
279 bSaveInp = true;
281 else if (aPropertyName == SC_UNONAME_MOVESEL)
283 aInpOpt.SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
284 bSaveInp = true;
286 else if (aPropertyName == SC_UNONAME_RANGEFIN)
288 aInpOpt.SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
289 bSaveInp = true;
291 else if (aPropertyName == SC_UNONAME_USETABCOL)
293 aInpOpt.SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
294 bSaveInp = true;
296 else if (aPropertyName == SC_UNONAME_PRMETRICS)
298 aInpOpt.SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
299 bSaveInp = true;
301 else if (aPropertyName == SC_UNONAME_REPLWARN)
303 aInpOpt.SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
304 bSaveInp = true;
306 else if (aPropertyName == SC_UNONAME_METRIC)
308 aAppOpt.SetAppMetric( static_cast<FieldUnit>(ScUnoHelpFunctions::GetInt16FromAny( aValue )) );
309 bSaveApp = true;
311 else if (aPropertyName == SC_UNONAME_MOVEDIR)
313 aInpOpt.SetMoveDir( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
314 bSaveInp = true;
316 else if (aPropertyName == SC_UNONAME_SCALE)
318 short nVal = ScUnoHelpFunctions::GetInt16FromAny( aValue );
319 if ( nVal < 0 )
321 SvxZoomType eType = SvxZoomType::PERCENT;
322 switch (nVal)
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 );
335 bSaveApp = true;
337 else if (aPropertyName == SC_UNONAME_STBFUNC)
339 aAppOpt.SetStatusFunc( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
340 bSaveApp = true;
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
351 pUserList->clear();
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
377 if ( bSaveApp )
378 pScMod->SetAppOptions( aAppOpt );
379 if ( bSaveInp )
380 pScMod->SetInputOptions( aInpOpt );
383 uno::Any SAL_CALL ScSpreadsheetSettings::getPropertyValue( const OUString& aPropertyName )
385 SolarMutexGuard aGuard;
386 uno::Any aRet;
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;
416 default:
418 // added to avoid warnings
421 aRet <<= nZoomVal;
423 else if (aPropertyName == SC_UNONAME_ULISTS )
425 ScUserList* pUserList = ScGlobal::GetUserList();
426 if (pUserList)
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());
434 pAry[i] = aEntry;
436 aRet <<= aSeq;
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
444 return aRet;
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;
461 ScDLL::Init();
462 return cppu::acquire(new ScRecentFunctionsObj());
465 // XRecentFunctions
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();
473 if (pFuncs)
475 uno::Sequence<sal_Int32> aSeq(nCount);
476 sal_Int32* pAry = aSeq.getArray();
477 for (sal_uInt16 i=0; i<nCount; i++)
478 pAry[i] = pFuncs[i];
479 return aSeq;
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()
503 return LRU_MAX;
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;
518 ScDLL::Init();
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;
558 if (nSeqCount)
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();
581 if ( !pFuncList )
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 );
592 return aSeq;
596 throw lang::IllegalArgumentException(); // not found
599 // XNameAccess
601 uno::Any SAL_CALL ScFunctionListObj::getByName( const OUString& aName )
603 SolarMutexGuard aGuard;
604 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
605 if ( !pFuncList )
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
624 // XIndexAccess
626 sal_Int32 SAL_CALL ScFunctionListObj::getCount()
628 SolarMutexGuard aGuard;
629 sal_Int32 nCount = 0;
630 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
631 if ( pFuncList )
632 nCount = static_cast<sal_Int32>(pFuncList->GetCount());
633 return nCount;
636 uno::Any SAL_CALL ScFunctionListObj::getByIndex( sal_Int32 nIndex )
638 SolarMutexGuard aGuard;
639 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
640 if ( !pFuncList )
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);
646 if ( pDesc )
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");
665 // XElementAccess
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();
683 if ( pFuncList )
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;
694 return aSeq;
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();
703 if ( pFuncList )
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 )
711 return true;
714 return false;
717 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */