tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / unoobj / appluno.cxx
blob3efb02f574f11751e5032b931a8e6d032ad0539a
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 <o3tl/safeint.hxx>
23 #include <osl/diagnose.h>
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/sheet/FunctionArgument.hpp>
40 #include <memory>
42 using namespace com::sun::star;
44 // Special value for zoom
45 //! somewhere central
46 #define SC_ZOOMVAL_OPTIMAL (-1)
47 #define SC_ZOOMVAL_WHOLEPAGE (-2)
48 #define SC_ZOOMVAL_PAGEWIDTH (-3)
50 // Number of PropertyValues in a function description
51 #define SC_FUNCDESC_PROPCOUNT 5
53 // everything without Which-ID, map only for PropertySetInfo
55 static std::span<const SfxItemPropertyMapEntry> lcl_GetSettingsPropertyMap()
57 static const SfxItemPropertyMapEntry aSettingsPropertyMap_Impl[] =
59 { SC_UNONAME_DOAUTOCP, 0, cppu::UnoType<bool>::get(), 0, 0},
60 { SC_UNONAME_ENTERED, 0, cppu::UnoType<bool>::get(), 0, 0},
61 { SC_UNONAME_EXPREF, 0, cppu::UnoType<bool>::get(), 0, 0},
62 { SC_UNONAME_EXTFMT, 0, cppu::UnoType<bool>::get(), 0, 0},
63 { SC_UNONAME_LINKUPD, 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
64 { SC_UNONAME_MARKHDR, 0, cppu::UnoType<bool>::get(), 0, 0},
65 { SC_UNONAME_METRIC, 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
66 { SC_UNONAME_MOVEDIR, 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
67 { SC_UNONAME_MOVESEL, 0, cppu::UnoType<bool>::get(), 0, 0},
68 { SC_UNONAME_PRALLSH, 0, cppu::UnoType<bool>::get(), 0, 0},
69 { SC_UNONAME_PREMPTY, 0, cppu::UnoType<bool>::get(), 0, 0},
70 { SC_UNONAME_RANGEFIN, 0, cppu::UnoType<bool>::get(), 0, 0},
71 { SC_UNONAME_SCALE, 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
72 { SC_UNONAME_STBFUNC, 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
73 { SC_UNONAME_ULISTS, 0, cppu::UnoType<uno::Sequence<OUString>>::get(), 0, 0},
74 { SC_UNONAME_PRMETRICS,0, cppu::UnoType<bool>::get(), 0, 0},
75 { SC_UNONAME_USETABCOL,0, cppu::UnoType<bool>::get(), 0, 0},
76 { SC_UNONAME_REPLWARN, 0, cppu::UnoType<bool>::get(), 0, 0},
78 return aSettingsPropertyMap_Impl;
81 constexpr OUString SCFUNCTIONLISTOBJ_SERVICE = u"com.sun.star.sheet.FunctionDescriptions"_ustr;
82 constexpr OUString SCRECENTFUNCTIONSOBJ_SERVICE = u"com.sun.star.sheet.RecentFunctions"_ustr;
83 constexpr OUString SCSPREADSHEETSETTINGS_SERVICE = u"com.sun.star.sheet.GlobalSheetSettings"_ustr;
85 SC_SIMPLE_SERVICE_INFO( ScFunctionListObj, u"stardiv.StarCalc.ScFunctionListObj"_ustr, SCFUNCTIONLISTOBJ_SERVICE )
86 SC_SIMPLE_SERVICE_INFO( ScRecentFunctionsObj, u"stardiv.StarCalc.ScRecentFunctionsObj"_ustr, SCRECENTFUNCTIONSOBJ_SERVICE )
87 SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettings, u"stardiv.StarCalc.ScSpreadsheetSettings"_ustr, SCSPREADSHEETSETTINGS_SERVICE )
90 ScSpreadsheetSettings::ScSpreadsheetSettings() :
91 aPropSet( lcl_GetSettingsPropertyMap() )
95 ScSpreadsheetSettings::~ScSpreadsheetSettings()
99 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
100 Calc_ScSpreadsheetSettings_get_implementation(
101 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
103 SolarMutexGuard aGuard;
104 ScDLL::Init();
105 return cppu::acquire(new ScSpreadsheetSettings());
109 bool ScSpreadsheetSettings::getPropertyBool(const OUString& aPropertyName)
111 uno::Any any = getPropertyValue(aPropertyName);
112 bool b = false;
113 any >>= b;
114 return b;
117 sal_Int16 ScSpreadsheetSettings::getPropertyInt16(const OUString& aPropertyName)
119 uno::Any any = getPropertyValue(aPropertyName);
120 sal_Int16 b = 0;
121 any >>= b;
122 return b;
125 // XPropertySet
127 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettings::getPropertySetInfo()
129 SolarMutexGuard aGuard;
130 static uno::Reference<beans::XPropertySetInfo> aRef(
131 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
132 return aRef;
135 void SAL_CALL ScSpreadsheetSettings::setPropertyValue(
136 const OUString& aPropertyName, const uno::Any& aValue )
138 SolarMutexGuard aGuard;
140 ScModule* pScMod = ScModule::get();
141 ScAppOptions aAppOpt(pScMod->GetAppOptions());
142 ScInputOptions aInpOpt(pScMod->GetInputOptions());
143 bool bSaveApp = false;
144 bool bSaveInp = false;
145 // print options aren't loaded until needed
147 if (aPropertyName == SC_UNONAME_DOAUTOCP)
149 aAppOpt.SetAutoComplete( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
150 bSaveApp = true;
152 else if (aPropertyName == SC_UNONAME_ENTERED)
154 aInpOpt.SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
155 bSaveInp = true;
157 else if (aPropertyName == SC_UNONAME_EXPREF)
159 aInpOpt.SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
160 bSaveInp = true;
162 else if (aPropertyName == SC_UNONAME_EXTFMT)
164 aInpOpt.SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
165 bSaveInp = true;
167 else if (aPropertyName == SC_UNONAME_LINKUPD)
169 // XXX NOTE: this is not css::document::Settings property
170 // LinkUpdateMode but css::sheet::XGlobalSheetSettings attribute
171 // LinkUpdateMode.
172 sal_Int16 n;
173 if (!(aValue >>= n) || n < 0 || n >= ScLkUpdMode::LM_UNKNOWN)
175 throw css::lang::IllegalArgumentException(
176 (u"LinkUpdateMode property value must be a SHORT with a value in the range of 0--2"
177 " as documented for css::sheet::XGlobalSheetSettings attribute LinkUpdateMode"_ustr),
178 css::uno::Reference<css::uno::XInterface>(), -1);
180 aAppOpt.SetLinkMode( static_cast<ScLkUpdMode>(n) );
181 bSaveApp = true;
183 else if (aPropertyName == SC_UNONAME_MARKHDR)
185 aInpOpt.SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
186 bSaveInp = true;
188 else if (aPropertyName == SC_UNONAME_MOVESEL)
190 aInpOpt.SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
191 bSaveInp = true;
193 else if (aPropertyName == SC_UNONAME_RANGEFIN)
195 aInpOpt.SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
196 bSaveInp = true;
198 else if (aPropertyName == SC_UNONAME_USETABCOL)
200 aInpOpt.SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
201 bSaveInp = true;
203 else if (aPropertyName == SC_UNONAME_PRMETRICS)
205 aInpOpt.SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
206 bSaveInp = true;
208 else if (aPropertyName == SC_UNONAME_REPLWARN)
210 aInpOpt.SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
211 bSaveInp = true;
213 else if (aPropertyName == SC_UNONAME_METRIC)
215 aAppOpt.SetAppMetric( static_cast<FieldUnit>(ScUnoHelpFunctions::GetInt16FromAny( aValue )) );
216 bSaveApp = true;
218 else if (aPropertyName == SC_UNONAME_MOVEDIR)
220 aInpOpt.SetMoveDir( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
221 bSaveInp = true;
223 else if (aPropertyName == SC_UNONAME_SCALE)
225 short nVal = ScUnoHelpFunctions::GetInt16FromAny( aValue );
226 if ( nVal < 0 )
228 SvxZoomType eType = SvxZoomType::PERCENT;
229 switch (nVal)
231 case SC_ZOOMVAL_OPTIMAL: eType = SvxZoomType::OPTIMAL; break;
232 case SC_ZOOMVAL_WHOLEPAGE: eType = SvxZoomType::WHOLEPAGE; break;
233 case SC_ZOOMVAL_PAGEWIDTH: eType = SvxZoomType::PAGEWIDTH; break;
235 aAppOpt.SetZoomType( eType );
237 else if ( nVal >= MINZOOM && nVal <= MAXZOOM )
239 aAppOpt.SetZoom( nVal );
240 aAppOpt.SetZoomType( SvxZoomType::PERCENT );
242 bSaveApp = true;
244 else if (aPropertyName == SC_UNONAME_STBFUNC)
246 aAppOpt.SetStatusFunc( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
247 bSaveApp = true;
249 else if (aPropertyName == SC_UNONAME_ULISTS)
251 ScUserList& rUserList = ScGlobal::GetUserList();
252 uno::Sequence<OUString> aSeq;
253 if (aValue >>= aSeq)
255 // directly change the active list
256 // ScGlobal::SetUseTabCol does not do much else
258 rUserList.clear();
259 for (const OUString& aEntry : aSeq)
261 rUserList.emplace_back(aEntry);
263 bSaveApp = true; // List with App-Options are saved
266 else if (aPropertyName == SC_UNONAME_PRALLSH)
268 ScPrintOptions aPrintOpt(pScMod->GetPrintOptions());
269 aPrintOpt.SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
270 pScMod->SetPrintOptions( aPrintOpt );
272 else if (aPropertyName == SC_UNONAME_PREMPTY)
274 ScPrintOptions aPrintOpt(pScMod->GetPrintOptions());
275 aPrintOpt.SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); // reversed
276 pScMod->SetPrintOptions( aPrintOpt );
277 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScPrintOptions ) ); // update previews
280 if ( bSaveApp )
281 pScMod->SetAppOptions( aAppOpt );
282 if ( bSaveInp )
283 pScMod->SetInputOptions( aInpOpt );
286 uno::Any SAL_CALL ScSpreadsheetSettings::getPropertyValue( const OUString& aPropertyName )
288 SolarMutexGuard aGuard;
289 uno::Any aRet;
291 ScModule* pScMod = ScModule::get();
292 ScAppOptions aAppOpt = pScMod->GetAppOptions();
293 const ScInputOptions& aInpOpt = pScMod->GetInputOptions();
294 // print options aren't loaded until needed
296 if (aPropertyName == SC_UNONAME_DOAUTOCP) aRet <<= aAppOpt.GetAutoComplete();
297 else if (aPropertyName == SC_UNONAME_ENTERED ) aRet <<= aInpOpt.GetEnterEdit();
298 else if (aPropertyName == SC_UNONAME_EXPREF ) aRet <<= aInpOpt.GetExpandRefs();
299 else if (aPropertyName == SC_UNONAME_EXTFMT ) aRet <<= aInpOpt.GetExtendFormat();
300 else if (aPropertyName == SC_UNONAME_LINKUPD ) aRet <<= static_cast<sal_Int16>(aAppOpt.GetLinkMode());
301 else if (aPropertyName == SC_UNONAME_MARKHDR ) aRet <<= aInpOpt.GetMarkHeader();
302 else if (aPropertyName == SC_UNONAME_MOVESEL ) aRet <<= aInpOpt.GetMoveSelection();
303 else if (aPropertyName == SC_UNONAME_RANGEFIN ) aRet <<= aInpOpt.GetRangeFinder();
304 else if (aPropertyName == SC_UNONAME_USETABCOL ) aRet <<= aInpOpt.GetUseTabCol();
305 else if (aPropertyName == SC_UNONAME_PRMETRICS ) aRet <<= aInpOpt.GetTextWysiwyg();
306 else if (aPropertyName == SC_UNONAME_REPLWARN ) aRet <<= aInpOpt.GetReplaceCellsWarn();
307 else if (aPropertyName == SC_UNONAME_METRIC ) aRet <<= static_cast<sal_Int16>(aAppOpt.GetAppMetric());
308 else if (aPropertyName == SC_UNONAME_MOVEDIR ) aRet <<= static_cast<sal_Int16>(aInpOpt.GetMoveDir());
309 else if (aPropertyName == SC_UNONAME_STBFUNC ) aRet <<= static_cast<sal_Int16>(aAppOpt.GetStatusFunc());
310 else if (aPropertyName == SC_UNONAME_SCALE )
312 sal_Int16 nZoomVal = 0;
313 switch ( aAppOpt.GetZoomType() )
315 case SvxZoomType::PERCENT: nZoomVal = aAppOpt.GetZoom(); break;
316 case SvxZoomType::OPTIMAL: nZoomVal = SC_ZOOMVAL_OPTIMAL; break;
317 case SvxZoomType::WHOLEPAGE: nZoomVal = SC_ZOOMVAL_WHOLEPAGE; break;
318 case SvxZoomType::PAGEWIDTH: nZoomVal = SC_ZOOMVAL_PAGEWIDTH; break;
319 default:
321 // added to avoid warnings
324 aRet <<= nZoomVal;
326 else if (aPropertyName == SC_UNONAME_ULISTS )
328 const ScUserList& rUserList = ScGlobal::GetUserList();
329 size_t nCount = rUserList.size();
330 uno::Sequence<OUString> aSeq(nCount);
331 OUString* pAry = aSeq.getArray();
332 for (size_t i=0; i<nCount; ++i)
333 pAry[i] = rUserList[i].GetString();
334 aRet <<= aSeq;
336 else if (aPropertyName == SC_UNONAME_PRALLSH )
337 aRet <<= pScMod->GetPrintOptions().GetAllSheets();
338 else if (aPropertyName == SC_UNONAME_PREMPTY )
339 aRet <<= !pScMod->GetPrintOptions().GetSkipEmpty(); // reversed
341 return aRet;
344 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettings )
346 ScRecentFunctionsObj::ScRecentFunctionsObj()
350 ScRecentFunctionsObj::~ScRecentFunctionsObj()
354 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
355 ScRecentFunctionsObj_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
357 SolarMutexGuard aGuard;
358 ScDLL::Init();
359 return cppu::acquire(new ScRecentFunctionsObj());
362 // XRecentFunctions
364 uno::Sequence<sal_Int32> SAL_CALL ScRecentFunctionsObj::getRecentFunctionIds()
366 SolarMutexGuard aGuard;
367 const ScAppOptions& rOpt = ScModule::get()->GetAppOptions();
368 sal_uInt16 nCount = rOpt.GetLRUFuncListCount();
369 const sal_uInt16* pFuncs = rOpt.GetLRUFuncList();
370 if (pFuncs)
372 uno::Sequence<sal_Int32> aSeq(nCount);
373 sal_Int32* pAry = aSeq.getArray();
374 for (sal_uInt16 i=0; i<nCount; i++)
375 pAry[i] = pFuncs[i];
376 return aSeq;
378 return {};
381 void SAL_CALL ScRecentFunctionsObj::setRecentFunctionIds(
382 const uno::Sequence<sal_Int32>& aRecentFunctionIds )
384 SolarMutexGuard aGuard;
385 sal_uInt16 nCount = static_cast<sal_uInt16>(std::min( aRecentFunctionIds.getLength(), sal_Int32(LRU_MAX) ));
386 const sal_Int32* pAry = aRecentFunctionIds.getConstArray();
388 std::unique_ptr<sal_uInt16[]> pFuncs(nCount ? new sal_uInt16[nCount] : nullptr);
389 for (sal_uInt16 i=0; i<nCount; i++)
390 pFuncs[i] = static_cast<sal_uInt16>(pAry[i]); //! check for valid values?
392 ScModule* pScMod = ScModule::get();
393 ScAppOptions aNewOpts(pScMod->GetAppOptions());
394 aNewOpts.SetLRUFuncList(pFuncs.get(), nCount);
395 pScMod->SetAppOptions(aNewOpts);
398 sal_Int32 SAL_CALL ScRecentFunctionsObj::getMaxRecentFunctions()
400 return LRU_MAX;
403 ScFunctionListObj::ScFunctionListObj()
407 ScFunctionListObj::~ScFunctionListObj()
411 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
412 ScFunctionListObj_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
414 SolarMutexGuard aGuard;
415 ScDLL::Init();
416 return cppu::acquire(new ScFunctionListObj());
419 static void lcl_FillSequence( uno::Sequence<beans::PropertyValue>& rSequence, const ScFuncDesc& rDesc )
421 rDesc.initArgumentInfo(); // full argument info is needed
423 OSL_ENSURE( rSequence.getLength() == SC_FUNCDESC_PROPCOUNT, "Wrong count" );
425 beans::PropertyValue* pArray = rSequence.getArray();
427 pArray[0].Name = SC_UNONAME_ID;
428 pArray[0].Value <<= static_cast<sal_Int32>(rDesc.nFIndex);
430 pArray[1].Name = SC_UNONAME_CATEGORY;
431 pArray[1].Value <<= static_cast<sal_Int32>(rDesc.nCategory);
433 pArray[2].Name = SC_UNONAME_NAME;
434 if (rDesc.mxFuncName)
435 pArray[2].Value <<= *rDesc.mxFuncName;
437 pArray[3].Name = SC_UNONAME_DESCRIPTION;
438 if (rDesc.mxFuncDesc)
439 pArray[3].Value <<= *rDesc.mxFuncDesc;
441 pArray[4].Name = SC_UNONAME_ARGUMENTS;
442 if (rDesc.maDefArgNames.empty() || rDesc.maDefArgDescs.empty() || !rDesc.pDefArgFlags)
443 return;
445 sal_uInt16 nCount = rDesc.nArgCount;
446 if (nCount >= PAIRED_VAR_ARGS)
447 nCount -= PAIRED_VAR_ARGS - 2;
448 else if (nCount >= VAR_ARGS)
449 nCount -= VAR_ARGS - 1;
450 sal_uInt16 nSeqCount = rDesc.GetSuppressedArgCount();
451 if (nSeqCount >= PAIRED_VAR_ARGS)
452 nSeqCount -= PAIRED_VAR_ARGS - 2;
453 else if (nSeqCount >= VAR_ARGS)
454 nSeqCount -= VAR_ARGS - 1;
456 if (!nSeqCount)
457 return;
459 uno::Sequence<sheet::FunctionArgument> aArgSeq(nSeqCount);
460 sheet::FunctionArgument* pArgAry = aArgSeq.getArray();
461 for (sal_uInt16 i=0, j=0; i<nCount; i++)
463 sheet::FunctionArgument aArgument;
464 aArgument.Name = rDesc.maDefArgNames[i];
465 aArgument.Description = rDesc.maDefArgDescs[i];
466 aArgument.IsOptional = rDesc.pDefArgFlags[i].bOptional;
467 pArgAry[j++] = std::move(aArgument);
469 pArray[4].Value <<= aArgSeq;
472 // XFunctionDescriptions
474 uno::Sequence<beans::PropertyValue> SAL_CALL ScFunctionListObj::getById( sal_Int32 nId )
476 SolarMutexGuard aGuard;
477 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
478 if ( !pFuncList )
479 throw uno::RuntimeException(); // should not happen
481 sal_uInt16 nCount = static_cast<sal_uInt16>(pFuncList->GetCount());
482 for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++)
484 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
485 if ( pDesc && pDesc->nFIndex == nId )
487 uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
488 lcl_FillSequence( aSeq, *pDesc );
489 return aSeq;
493 throw lang::IllegalArgumentException(); // not found
496 // XNameAccess
498 uno::Any SAL_CALL ScFunctionListObj::getByName( const OUString& aName )
500 SolarMutexGuard aGuard;
501 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
502 if ( !pFuncList )
503 throw uno::RuntimeException(); // should not happen
505 sal_uInt16 nCount = static_cast<sal_uInt16>(pFuncList->GetCount());
506 for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++)
508 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
509 //! Case-insensitive???
510 if ( pDesc && pDesc->mxFuncName && aName == *pDesc->mxFuncName )
512 uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
513 lcl_FillSequence( aSeq, *pDesc );
514 return uno::Any(aSeq);
518 throw container::NoSuchElementException(); // not found
521 // XIndexAccess
523 sal_Int32 SAL_CALL ScFunctionListObj::getCount()
525 SolarMutexGuard aGuard;
526 sal_Int32 nCount = 0;
527 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
528 if ( pFuncList )
529 nCount = static_cast<sal_Int32>(pFuncList->GetCount());
530 return nCount;
533 uno::Any SAL_CALL ScFunctionListObj::getByIndex( sal_Int32 nIndex )
535 SolarMutexGuard aGuard;
536 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
537 if ( !pFuncList )
538 throw uno::RuntimeException(); // should not happen
540 if ( nIndex >= 0 && o3tl::make_unsigned(nIndex) < pFuncList->GetCount() )
542 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
543 if ( pDesc )
545 uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
546 lcl_FillSequence( aSeq, *pDesc );
547 return uno::Any(aSeq);
551 throw lang::IndexOutOfBoundsException(); // illegal index
554 // XEnumerationAccess
556 uno::Reference<container::XEnumeration> SAL_CALL ScFunctionListObj::createEnumeration()
558 SolarMutexGuard aGuard;
559 return new ScIndexEnumeration(this, u"com.sun.star.sheet.FunctionDescriptionEnumeration"_ustr);
562 // XElementAccess
564 uno::Type SAL_CALL ScFunctionListObj::getElementType()
566 return cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get();
569 sal_Bool SAL_CALL ScFunctionListObj::hasElements()
571 SolarMutexGuard aGuard;
572 return ( getCount() > 0 );
575 uno::Sequence<OUString> SAL_CALL ScFunctionListObj::getElementNames()
577 SolarMutexGuard aGuard;
578 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
579 if ( pFuncList )
581 sal_uInt32 nCount = pFuncList->GetCount();
582 uno::Sequence<OUString> aSeq(nCount);
583 OUString* pAry = aSeq.getArray();
584 for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
586 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
587 if ( pDesc && pDesc->mxFuncName )
588 pAry[nIndex] = *pDesc->mxFuncName;
590 return aSeq;
592 return {};
595 sal_Bool SAL_CALL ScFunctionListObj::hasByName( const OUString& aName )
597 SolarMutexGuard aGuard;
598 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
599 if ( pFuncList )
601 sal_uInt32 nCount = pFuncList->GetCount();
602 for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
604 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
605 //! Case-insensitive???
606 if ( pDesc && pDesc->mxFuncName && aName == *pDesc->mxFuncName )
607 return true;
610 return false;
613 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */