/src/libreoffice/sc/source/ui/unoobj/appluno.cxx
Line | Count | Source |
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 | | #include <appluno.hxx> |
21 | | #include <sal/types.h> |
22 | | #include <o3tl/safeint.hxx> |
23 | | #include <osl/diagnose.h> |
24 | | #include <formula/funcvarargs.h> |
25 | | |
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> |
41 | | |
42 | | using namespace com::sun::star; |
43 | | |
44 | | // Special value for zoom |
45 | | //! somewhere central |
46 | 0 | #define SC_ZOOMVAL_OPTIMAL (-1) |
47 | 0 | #define SC_ZOOMVAL_WHOLEPAGE (-2) |
48 | 0 | #define SC_ZOOMVAL_PAGEWIDTH (-3) |
49 | | |
50 | | // Number of PropertyValues in a function description |
51 | 0 | #define SC_FUNCDESC_PROPCOUNT 5 |
52 | | |
53 | | // everything without Which-ID, map only for PropertySetInfo |
54 | | |
55 | | static std::span<const SfxItemPropertyMapEntry> lcl_GetSettingsPropertyMap() |
56 | 0 | { |
57 | 0 | static const SfxItemPropertyMapEntry aSettingsPropertyMap_Impl[] = |
58 | 0 | { |
59 | 0 | { SC_UNONAME_DOAUTOCP, 0, cppu::UnoType<bool>::get(), 0, 0}, |
60 | 0 | { SC_UNONAME_ENTERED, 0, cppu::UnoType<bool>::get(), 0, 0}, |
61 | 0 | { SC_UNONAME_EXPREF, 0, cppu::UnoType<bool>::get(), 0, 0}, |
62 | 0 | { SC_UNONAME_EXTFMT, 0, cppu::UnoType<bool>::get(), 0, 0}, |
63 | 0 | { SC_UNONAME_LINKUPD, 0, cppu::UnoType<sal_Int16>::get(), 0, 0}, |
64 | 0 | { SC_UNONAME_MARKHDR, 0, cppu::UnoType<bool>::get(), 0, 0}, |
65 | 0 | { SC_UNONAME_METRIC, 0, cppu::UnoType<sal_Int16>::get(), 0, 0}, |
66 | 0 | { SC_UNONAME_MOVEDIR, 0, cppu::UnoType<sal_Int16>::get(), 0, 0}, |
67 | 0 | { SC_UNONAME_MOVESEL, 0, cppu::UnoType<bool>::get(), 0, 0}, |
68 | 0 | { SC_UNONAME_PRALLSH, 0, cppu::UnoType<bool>::get(), 0, 0}, |
69 | 0 | { SC_UNONAME_PREMPTY, 0, cppu::UnoType<bool>::get(), 0, 0}, |
70 | 0 | { SC_UNONAME_RANGEFIN, 0, cppu::UnoType<bool>::get(), 0, 0}, |
71 | 0 | { SC_UNONAME_SCALE, 0, cppu::UnoType<sal_Int16>::get(), 0, 0}, |
72 | 0 | { SC_UNONAME_STBFUNC, 0, cppu::UnoType<sal_Int16>::get(), 0, 0}, |
73 | 0 | { SC_UNONAME_ULISTS, 0, cppu::UnoType<uno::Sequence<OUString>>::get(), 0, 0}, |
74 | 0 | { SC_UNONAME_PRMETRICS,0, cppu::UnoType<bool>::get(), 0, 0}, |
75 | 0 | { SC_UNONAME_USETABCOL,0, cppu::UnoType<bool>::get(), 0, 0}, |
76 | 0 | { SC_UNONAME_REPLWARN, 0, cppu::UnoType<bool>::get(), 0, 0}, |
77 | 0 | }; |
78 | 0 | return aSettingsPropertyMap_Impl; |
79 | 0 | } |
80 | | |
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; |
84 | | |
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 ) |
88 | | |
89 | | |
90 | | ScSpreadsheetSettings::ScSpreadsheetSettings() : |
91 | 0 | aPropSet( lcl_GetSettingsPropertyMap() ) |
92 | 0 | { |
93 | 0 | } |
94 | | |
95 | | ScSpreadsheetSettings::~ScSpreadsheetSettings() |
96 | 0 | { |
97 | 0 | } |
98 | | |
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&) |
102 | 0 | { |
103 | 0 | SolarMutexGuard aGuard; |
104 | 0 | ScDLL::Init(); |
105 | 0 | return cppu::acquire(new ScSpreadsheetSettings()); |
106 | 0 | } |
107 | | |
108 | | |
109 | | bool ScSpreadsheetSettings::getPropertyBool(const OUString& aPropertyName) |
110 | 0 | { |
111 | 0 | uno::Any any = getPropertyValue(aPropertyName); |
112 | 0 | bool b = false; |
113 | 0 | any >>= b; |
114 | 0 | return b; |
115 | 0 | } |
116 | | |
117 | | sal_Int16 ScSpreadsheetSettings::getPropertyInt16(const OUString& aPropertyName) |
118 | 0 | { |
119 | 0 | uno::Any any = getPropertyValue(aPropertyName); |
120 | 0 | sal_Int16 b = 0; |
121 | 0 | any >>= b; |
122 | 0 | return b; |
123 | 0 | } |
124 | | |
125 | | // XPropertySet |
126 | | |
127 | | uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettings::getPropertySetInfo() |
128 | 0 | { |
129 | 0 | SolarMutexGuard aGuard; |
130 | 0 | static uno::Reference<beans::XPropertySetInfo> aRef( |
131 | 0 | new SfxItemPropertySetInfo( aPropSet.getPropertyMap() )); |
132 | 0 | return aRef; |
133 | 0 | } |
134 | | |
135 | | void SAL_CALL ScSpreadsheetSettings::setPropertyValue( |
136 | | const OUString& aPropertyName, const uno::Any& aValue ) |
137 | 0 | { |
138 | 0 | SolarMutexGuard aGuard; |
139 | |
|
140 | 0 | ScModule* pScMod = ScModule::get(); |
141 | 0 | ScAppOptions aAppOpt(pScMod->GetAppOptions()); |
142 | 0 | ScInputOptions aInpOpt(pScMod->GetInputOptions()); |
143 | 0 | bool bSaveApp = false; |
144 | 0 | bool bSaveInp = false; |
145 | | // print options aren't loaded until needed |
146 | |
|
147 | 0 | if (aPropertyName == SC_UNONAME_DOAUTOCP) |
148 | 0 | { |
149 | 0 | aAppOpt.SetAutoComplete( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
150 | 0 | bSaveApp = true; |
151 | 0 | } |
152 | 0 | else if (aPropertyName == SC_UNONAME_ENTERED) |
153 | 0 | { |
154 | 0 | aInpOpt.SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
155 | 0 | bSaveInp = true; |
156 | 0 | } |
157 | 0 | else if (aPropertyName == SC_UNONAME_EXPREF) |
158 | 0 | { |
159 | 0 | aInpOpt.SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
160 | 0 | bSaveInp = true; |
161 | 0 | } |
162 | 0 | else if (aPropertyName == SC_UNONAME_EXTFMT) |
163 | 0 | { |
164 | 0 | aInpOpt.SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
165 | 0 | bSaveInp = true; |
166 | 0 | } |
167 | 0 | else if (aPropertyName == SC_UNONAME_LINKUPD) |
168 | 0 | { |
169 | | // XXX NOTE: this is not css::document::Settings property |
170 | | // LinkUpdateMode but css::sheet::XGlobalSheetSettings attribute |
171 | | // LinkUpdateMode. |
172 | 0 | sal_Int16 n; |
173 | 0 | if (!(aValue >>= n) || n < 0 || n >= ScLkUpdMode::LM_UNKNOWN) |
174 | 0 | { |
175 | 0 | throw css::lang::IllegalArgumentException( |
176 | 0 | (u"LinkUpdateMode property value must be a SHORT with a value in the range of 0--2" |
177 | 0 | " as documented for css::sheet::XGlobalSheetSettings attribute LinkUpdateMode"_ustr), |
178 | 0 | css::uno::Reference<css::uno::XInterface>(), -1); |
179 | 0 | } |
180 | 0 | aAppOpt.SetLinkMode( static_cast<ScLkUpdMode>(n) ); |
181 | 0 | bSaveApp = true; |
182 | 0 | } |
183 | 0 | else if (aPropertyName == SC_UNONAME_MARKHDR) |
184 | 0 | { |
185 | 0 | aInpOpt.SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
186 | 0 | bSaveInp = true; |
187 | 0 | } |
188 | 0 | else if (aPropertyName == SC_UNONAME_MOVESEL) |
189 | 0 | { |
190 | 0 | aInpOpt.SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
191 | 0 | bSaveInp = true; |
192 | 0 | } |
193 | 0 | else if (aPropertyName == SC_UNONAME_RANGEFIN) |
194 | 0 | { |
195 | 0 | aInpOpt.SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
196 | 0 | bSaveInp = true; |
197 | 0 | } |
198 | 0 | else if (aPropertyName == SC_UNONAME_USETABCOL) |
199 | 0 | { |
200 | 0 | aInpOpt.SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
201 | 0 | bSaveInp = true; |
202 | 0 | } |
203 | 0 | else if (aPropertyName == SC_UNONAME_PRMETRICS) |
204 | 0 | { |
205 | 0 | aInpOpt.SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
206 | 0 | bSaveInp = true; |
207 | 0 | } |
208 | 0 | else if (aPropertyName == SC_UNONAME_REPLWARN) |
209 | 0 | { |
210 | 0 | aInpOpt.SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
211 | 0 | bSaveInp = true; |
212 | 0 | } |
213 | 0 | else if (aPropertyName == SC_UNONAME_METRIC) |
214 | 0 | { |
215 | 0 | aAppOpt.SetAppMetric( static_cast<FieldUnit>(ScUnoHelpFunctions::GetInt16FromAny( aValue )) ); |
216 | 0 | bSaveApp = true; |
217 | 0 | } |
218 | 0 | else if (aPropertyName == SC_UNONAME_MOVEDIR) |
219 | 0 | { |
220 | 0 | aInpOpt.SetMoveDir( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); |
221 | 0 | bSaveInp = true; |
222 | 0 | } |
223 | 0 | else if (aPropertyName == SC_UNONAME_SCALE) |
224 | 0 | { |
225 | 0 | short nVal = ScUnoHelpFunctions::GetInt16FromAny( aValue ); |
226 | 0 | if ( nVal < 0 ) |
227 | 0 | { |
228 | 0 | SvxZoomType eType = SvxZoomType::PERCENT; |
229 | 0 | switch (nVal) |
230 | 0 | { |
231 | 0 | case SC_ZOOMVAL_OPTIMAL: eType = SvxZoomType::OPTIMAL; break; |
232 | 0 | case SC_ZOOMVAL_WHOLEPAGE: eType = SvxZoomType::WHOLEPAGE; break; |
233 | 0 | case SC_ZOOMVAL_PAGEWIDTH: eType = SvxZoomType::PAGEWIDTH; break; |
234 | 0 | } |
235 | 0 | aAppOpt.SetZoomType( eType ); |
236 | 0 | } |
237 | 0 | else if ( nVal >= MINZOOM && nVal <= MAXZOOM ) |
238 | 0 | { |
239 | 0 | aAppOpt.SetZoom( nVal ); |
240 | 0 | aAppOpt.SetZoomType( SvxZoomType::PERCENT ); |
241 | 0 | } |
242 | 0 | bSaveApp = true; |
243 | 0 | } |
244 | 0 | else if (aPropertyName == SC_UNONAME_STBFUNC) |
245 | 0 | { |
246 | 0 | aAppOpt.SetStatusFunc( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); |
247 | 0 | bSaveApp = true; |
248 | 0 | } |
249 | 0 | else if (aPropertyName == SC_UNONAME_ULISTS) |
250 | 0 | { |
251 | 0 | ScUserList& rUserList = ScGlobal::GetUserList(); |
252 | 0 | uno::Sequence<OUString> aSeq; |
253 | 0 | if (aValue >>= aSeq) |
254 | 0 | { |
255 | | // directly change the active list |
256 | | // ScGlobal::SetUseTabCol does not do much else |
257 | |
|
258 | 0 | rUserList.clear(); |
259 | 0 | for (const OUString& aEntry : aSeq) |
260 | 0 | { |
261 | 0 | rUserList.emplace_back(aEntry); |
262 | 0 | } |
263 | 0 | bSaveApp = true; // List with App-Options are saved |
264 | 0 | } |
265 | 0 | } |
266 | 0 | else if (aPropertyName == SC_UNONAME_PRALLSH) |
267 | 0 | { |
268 | 0 | ScPrintOptions aPrintOpt(pScMod->GetPrintOptions()); |
269 | 0 | aPrintOpt.SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); |
270 | 0 | pScMod->SetPrintOptions( aPrintOpt ); |
271 | 0 | } |
272 | 0 | else if (aPropertyName == SC_UNONAME_PREMPTY) |
273 | 0 | { |
274 | 0 | ScPrintOptions aPrintOpt(pScMod->GetPrintOptions()); |
275 | 0 | aPrintOpt.SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); // reversed |
276 | 0 | pScMod->SetPrintOptions( aPrintOpt ); |
277 | 0 | SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScPrintOptions ) ); // update previews |
278 | 0 | } |
279 | | |
280 | 0 | if ( bSaveApp ) |
281 | 0 | pScMod->SetAppOptions( aAppOpt ); |
282 | 0 | if ( bSaveInp ) |
283 | 0 | pScMod->SetInputOptions( aInpOpt ); |
284 | 0 | } |
285 | | |
286 | | uno::Any SAL_CALL ScSpreadsheetSettings::getPropertyValue( const OUString& aPropertyName ) |
287 | 0 | { |
288 | 0 | SolarMutexGuard aGuard; |
289 | 0 | uno::Any aRet; |
290 | |
|
291 | 0 | ScModule* pScMod = ScModule::get(); |
292 | 0 | ScAppOptions aAppOpt = pScMod->GetAppOptions(); |
293 | 0 | const ScInputOptions& aInpOpt = pScMod->GetInputOptions(); |
294 | | // print options aren't loaded until needed |
295 | |
|
296 | 0 | if (aPropertyName == SC_UNONAME_DOAUTOCP) aRet <<= aAppOpt.GetAutoComplete(); |
297 | 0 | else if (aPropertyName == SC_UNONAME_ENTERED ) aRet <<= aInpOpt.GetEnterEdit(); |
298 | 0 | else if (aPropertyName == SC_UNONAME_EXPREF ) aRet <<= aInpOpt.GetExpandRefs(); |
299 | 0 | else if (aPropertyName == SC_UNONAME_EXTFMT ) aRet <<= aInpOpt.GetExtendFormat(); |
300 | 0 | else if (aPropertyName == SC_UNONAME_LINKUPD ) aRet <<= static_cast<sal_Int16>(aAppOpt.GetLinkMode()); |
301 | 0 | else if (aPropertyName == SC_UNONAME_MARKHDR ) aRet <<= aInpOpt.GetMarkHeader(); |
302 | 0 | else if (aPropertyName == SC_UNONAME_MOVESEL ) aRet <<= aInpOpt.GetMoveSelection(); |
303 | 0 | else if (aPropertyName == SC_UNONAME_RANGEFIN ) aRet <<= aInpOpt.GetRangeFinder(); |
304 | 0 | else if (aPropertyName == SC_UNONAME_USETABCOL ) aRet <<= aInpOpt.GetUseTabCol(); |
305 | 0 | else if (aPropertyName == SC_UNONAME_PRMETRICS ) aRet <<= aInpOpt.GetTextWysiwyg(); |
306 | 0 | else if (aPropertyName == SC_UNONAME_REPLWARN ) aRet <<= aInpOpt.GetReplaceCellsWarn(); |
307 | 0 | else if (aPropertyName == SC_UNONAME_METRIC ) aRet <<= static_cast<sal_Int16>(aAppOpt.GetAppMetric()); |
308 | 0 | else if (aPropertyName == SC_UNONAME_MOVEDIR ) aRet <<= static_cast<sal_Int16>(aInpOpt.GetMoveDir()); |
309 | 0 | else if (aPropertyName == SC_UNONAME_STBFUNC ) aRet <<= static_cast<sal_Int16>(aAppOpt.GetStatusFunc()); |
310 | 0 | else if (aPropertyName == SC_UNONAME_SCALE ) |
311 | 0 | { |
312 | 0 | sal_Int16 nZoomVal = 0; |
313 | 0 | switch ( aAppOpt.GetZoomType() ) |
314 | 0 | { |
315 | 0 | case SvxZoomType::PERCENT: nZoomVal = aAppOpt.GetZoom(); break; |
316 | 0 | case SvxZoomType::OPTIMAL: nZoomVal = SC_ZOOMVAL_OPTIMAL; break; |
317 | 0 | case SvxZoomType::WHOLEPAGE: nZoomVal = SC_ZOOMVAL_WHOLEPAGE; break; |
318 | 0 | case SvxZoomType::PAGEWIDTH: nZoomVal = SC_ZOOMVAL_PAGEWIDTH; break; |
319 | 0 | default: |
320 | 0 | { |
321 | | // added to avoid warnings |
322 | 0 | } |
323 | 0 | } |
324 | 0 | aRet <<= nZoomVal; |
325 | 0 | } |
326 | 0 | else if (aPropertyName == SC_UNONAME_ULISTS ) |
327 | 0 | { |
328 | 0 | const ScUserList& rUserList = ScGlobal::GetUserList(); |
329 | 0 | size_t nCount = rUserList.size(); |
330 | 0 | uno::Sequence<OUString> aSeq(nCount); |
331 | 0 | OUString* pAry = aSeq.getArray(); |
332 | 0 | for (size_t i=0; i<nCount; ++i) |
333 | 0 | pAry[i] = rUserList[i].GetString(); |
334 | 0 | aRet <<= aSeq; |
335 | 0 | } |
336 | 0 | else if (aPropertyName == SC_UNONAME_PRALLSH ) |
337 | 0 | aRet <<= pScMod->GetPrintOptions().GetAllSheets(); |
338 | 0 | else if (aPropertyName == SC_UNONAME_PREMPTY ) |
339 | 0 | aRet <<= !pScMod->GetPrintOptions().GetSkipEmpty(); // reversed |
340 | | |
341 | 0 | return aRet; |
342 | 0 | } |
343 | | |
344 | | SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettings ) |
345 | | |
346 | | ScRecentFunctionsObj::ScRecentFunctionsObj() |
347 | 0 | { |
348 | 0 | } |
349 | | |
350 | | ScRecentFunctionsObj::~ScRecentFunctionsObj() |
351 | 0 | { |
352 | 0 | } |
353 | | |
354 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
355 | | ScRecentFunctionsObj_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &) |
356 | 0 | { |
357 | 0 | SolarMutexGuard aGuard; |
358 | 0 | ScDLL::Init(); |
359 | 0 | return cppu::acquire(new ScRecentFunctionsObj()); |
360 | 0 | } |
361 | | |
362 | | // XRecentFunctions |
363 | | |
364 | | uno::Sequence<sal_Int32> SAL_CALL ScRecentFunctionsObj::getRecentFunctionIds() |
365 | 0 | { |
366 | 0 | SolarMutexGuard aGuard; |
367 | 0 | const ScAppOptions& rOpt = ScModule::get()->GetAppOptions(); |
368 | 0 | sal_uInt16 nCount = rOpt.GetLRUFuncListCount(); |
369 | 0 | const sal_uInt16* pFuncs = rOpt.GetLRUFuncList(); |
370 | 0 | if (pFuncs) |
371 | 0 | { |
372 | 0 | uno::Sequence<sal_Int32> aSeq(nCount); |
373 | 0 | sal_Int32* pAry = aSeq.getArray(); |
374 | 0 | for (sal_uInt16 i=0; i<nCount; i++) |
375 | 0 | pAry[i] = pFuncs[i]; |
376 | 0 | return aSeq; |
377 | 0 | } |
378 | 0 | return {}; |
379 | 0 | } |
380 | | |
381 | | void SAL_CALL ScRecentFunctionsObj::setRecentFunctionIds( |
382 | | const uno::Sequence<sal_Int32>& aRecentFunctionIds ) |
383 | 0 | { |
384 | 0 | SolarMutexGuard aGuard; |
385 | 0 | sal_uInt16 nCount = static_cast<sal_uInt16>(std::min( aRecentFunctionIds.getLength(), sal_Int32(LRU_MAX) )); |
386 | 0 | const sal_Int32* pAry = aRecentFunctionIds.getConstArray(); |
387 | |
|
388 | 0 | std::unique_ptr<sal_uInt16[]> pFuncs(nCount ? new sal_uInt16[nCount] : nullptr); |
389 | 0 | for (sal_uInt16 i=0; i<nCount; i++) |
390 | 0 | pFuncs[i] = static_cast<sal_uInt16>(pAry[i]); //! check for valid values? |
391 | |
|
392 | 0 | ScModule* pScMod = ScModule::get(); |
393 | 0 | ScAppOptions aNewOpts(pScMod->GetAppOptions()); |
394 | 0 | aNewOpts.SetLRUFuncList(pFuncs.get(), nCount); |
395 | 0 | pScMod->SetAppOptions(aNewOpts); |
396 | 0 | } |
397 | | |
398 | | sal_Int32 SAL_CALL ScRecentFunctionsObj::getMaxRecentFunctions() |
399 | 0 | { |
400 | 0 | return LRU_MAX; |
401 | 0 | } |
402 | | |
403 | | ScFunctionListObj::ScFunctionListObj() |
404 | 0 | { |
405 | 0 | } |
406 | | |
407 | | ScFunctionListObj::~ScFunctionListObj() |
408 | 0 | { |
409 | 0 | } |
410 | | |
411 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
412 | | ScFunctionListObj_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &) |
413 | 0 | { |
414 | 0 | SolarMutexGuard aGuard; |
415 | 0 | ScDLL::Init(); |
416 | 0 | return cppu::acquire(new ScFunctionListObj()); |
417 | 0 | } |
418 | | |
419 | | static void lcl_FillSequence( uno::Sequence<beans::PropertyValue>& rSequence, const ScFuncDesc& rDesc ) |
420 | 0 | { |
421 | 0 | rDesc.initArgumentInfo(); // full argument info is needed |
422 | |
|
423 | 0 | OSL_ENSURE( rSequence.getLength() == SC_FUNCDESC_PROPCOUNT, "Wrong count" ); |
424 | |
|
425 | 0 | beans::PropertyValue* pArray = rSequence.getArray(); |
426 | |
|
427 | 0 | pArray[0].Name = SC_UNONAME_ID; |
428 | 0 | pArray[0].Value <<= static_cast<sal_Int32>(rDesc.nFIndex); |
429 | |
|
430 | 0 | pArray[1].Name = SC_UNONAME_CATEGORY; |
431 | 0 | pArray[1].Value <<= static_cast<sal_Int32>(rDesc.nCategory); |
432 | |
|
433 | 0 | pArray[2].Name = SC_UNONAME_NAME; |
434 | 0 | if (rDesc.mxFuncName) |
435 | 0 | pArray[2].Value <<= *rDesc.mxFuncName; |
436 | |
|
437 | 0 | pArray[3].Name = SC_UNONAME_DESCRIPTION; |
438 | 0 | if (rDesc.mxFuncDesc) |
439 | 0 | pArray[3].Value <<= *rDesc.mxFuncDesc; |
440 | |
|
441 | 0 | pArray[4].Name = SC_UNONAME_ARGUMENTS; |
442 | 0 | if (rDesc.maDefArgNames.empty() || rDesc.maDefArgDescs.empty() || !rDesc.pDefArgFlags) |
443 | 0 | return; |
444 | | |
445 | 0 | sal_uInt16 nCount = rDesc.nArgCount; |
446 | 0 | if (nCount >= PAIRED_VAR_ARGS) |
447 | 0 | nCount -= PAIRED_VAR_ARGS - 2; |
448 | 0 | else if (nCount >= VAR_ARGS) |
449 | 0 | nCount -= VAR_ARGS - 1; |
450 | 0 | sal_uInt16 nSeqCount = rDesc.GetSuppressedArgCount(); |
451 | 0 | if (nSeqCount >= PAIRED_VAR_ARGS) |
452 | 0 | nSeqCount -= PAIRED_VAR_ARGS - 2; |
453 | 0 | else if (nSeqCount >= VAR_ARGS) |
454 | 0 | nSeqCount -= VAR_ARGS - 1; |
455 | |
|
456 | 0 | if (!nSeqCount) |
457 | 0 | return; |
458 | | |
459 | 0 | uno::Sequence<sheet::FunctionArgument> aArgSeq(nSeqCount); |
460 | 0 | sheet::FunctionArgument* pArgAry = aArgSeq.getArray(); |
461 | 0 | for (sal_uInt16 i=0, j=0; i<nCount; i++) |
462 | 0 | { |
463 | 0 | sheet::FunctionArgument aArgument; |
464 | 0 | aArgument.Name = rDesc.maDefArgNames[i]; |
465 | 0 | aArgument.Description = rDesc.maDefArgDescs[i]; |
466 | 0 | aArgument.IsOptional = rDesc.pDefArgFlags[i].bOptional; |
467 | 0 | pArgAry[j++] = std::move(aArgument); |
468 | 0 | } |
469 | 0 | pArray[4].Value <<= aArgSeq; |
470 | 0 | } |
471 | | |
472 | | // XFunctionDescriptions |
473 | | |
474 | | uno::Sequence<beans::PropertyValue> SAL_CALL ScFunctionListObj::getById( sal_Int32 nId ) |
475 | 0 | { |
476 | 0 | SolarMutexGuard aGuard; |
477 | 0 | const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); |
478 | 0 | if ( !pFuncList ) |
479 | 0 | throw uno::RuntimeException(); // should not happen |
480 | | |
481 | 0 | sal_uInt16 nCount = static_cast<sal_uInt16>(pFuncList->GetCount()); |
482 | 0 | for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++) |
483 | 0 | { |
484 | 0 | const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); |
485 | 0 | if ( pDesc && pDesc->nFIndex == nId ) |
486 | 0 | { |
487 | 0 | uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT ); |
488 | 0 | lcl_FillSequence( aSeq, *pDesc ); |
489 | 0 | return aSeq; |
490 | 0 | } |
491 | 0 | } |
492 | | |
493 | 0 | throw lang::IllegalArgumentException(); // not found |
494 | 0 | } |
495 | | |
496 | | // XNameAccess |
497 | | |
498 | | uno::Any SAL_CALL ScFunctionListObj::getByName( const OUString& aName ) |
499 | 0 | { |
500 | 0 | SolarMutexGuard aGuard; |
501 | 0 | const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); |
502 | 0 | if ( !pFuncList ) |
503 | 0 | throw uno::RuntimeException(); // should not happen |
504 | | |
505 | 0 | sal_uInt16 nCount = static_cast<sal_uInt16>(pFuncList->GetCount()); |
506 | 0 | for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++) |
507 | 0 | { |
508 | 0 | const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); |
509 | | //! Case-insensitive??? |
510 | 0 | if ( pDesc && pDesc->mxFuncName && aName == *pDesc->mxFuncName ) |
511 | 0 | { |
512 | 0 | uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT ); |
513 | 0 | lcl_FillSequence( aSeq, *pDesc ); |
514 | 0 | return uno::Any(aSeq); |
515 | 0 | } |
516 | 0 | } |
517 | | |
518 | 0 | throw container::NoSuchElementException(); // not found |
519 | 0 | } |
520 | | |
521 | | // XIndexAccess |
522 | | |
523 | | sal_Int32 SAL_CALL ScFunctionListObj::getCount() |
524 | 0 | { |
525 | 0 | SolarMutexGuard aGuard; |
526 | 0 | sal_Int32 nCount = 0; |
527 | 0 | const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); |
528 | 0 | if ( pFuncList ) |
529 | 0 | nCount = static_cast<sal_Int32>(pFuncList->GetCount()); |
530 | 0 | return nCount; |
531 | 0 | } |
532 | | |
533 | | uno::Any SAL_CALL ScFunctionListObj::getByIndex( sal_Int32 nIndex ) |
534 | 0 | { |
535 | 0 | SolarMutexGuard aGuard; |
536 | 0 | const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); |
537 | 0 | if ( !pFuncList ) |
538 | 0 | throw uno::RuntimeException(); // should not happen |
539 | | |
540 | 0 | if ( nIndex >= 0 && o3tl::make_unsigned(nIndex) < pFuncList->GetCount() ) |
541 | 0 | { |
542 | 0 | const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); |
543 | 0 | if ( pDesc ) |
544 | 0 | { |
545 | 0 | uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT ); |
546 | 0 | lcl_FillSequence( aSeq, *pDesc ); |
547 | 0 | return uno::Any(aSeq); |
548 | 0 | } |
549 | 0 | } |
550 | | |
551 | 0 | throw lang::IndexOutOfBoundsException(); // illegal index |
552 | 0 | } |
553 | | |
554 | | // XEnumerationAccess |
555 | | |
556 | | uno::Reference<container::XEnumeration> SAL_CALL ScFunctionListObj::createEnumeration() |
557 | 0 | { |
558 | 0 | SolarMutexGuard aGuard; |
559 | 0 | return new ScIndexEnumeration(this, u"com.sun.star.sheet.FunctionDescriptionEnumeration"_ustr); |
560 | 0 | } |
561 | | |
562 | | // XElementAccess |
563 | | |
564 | | uno::Type SAL_CALL ScFunctionListObj::getElementType() |
565 | 0 | { |
566 | 0 | return cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get(); |
567 | 0 | } |
568 | | |
569 | | sal_Bool SAL_CALL ScFunctionListObj::hasElements() |
570 | 0 | { |
571 | 0 | SolarMutexGuard aGuard; |
572 | 0 | return ( getCount() > 0 ); |
573 | 0 | } |
574 | | |
575 | | uno::Sequence<OUString> SAL_CALL ScFunctionListObj::getElementNames() |
576 | 0 | { |
577 | 0 | SolarMutexGuard aGuard; |
578 | 0 | const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); |
579 | 0 | if ( pFuncList ) |
580 | 0 | { |
581 | 0 | sal_uInt32 nCount = pFuncList->GetCount(); |
582 | 0 | uno::Sequence<OUString> aSeq(nCount); |
583 | 0 | OUString* pAry = aSeq.getArray(); |
584 | 0 | for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex) |
585 | 0 | { |
586 | 0 | const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); |
587 | 0 | if ( pDesc && pDesc->mxFuncName ) |
588 | 0 | pAry[nIndex] = *pDesc->mxFuncName; |
589 | 0 | } |
590 | 0 | return aSeq; |
591 | 0 | } |
592 | 0 | return {}; |
593 | 0 | } |
594 | | |
595 | | sal_Bool SAL_CALL ScFunctionListObj::hasByName( const OUString& aName ) |
596 | 0 | { |
597 | 0 | SolarMutexGuard aGuard; |
598 | 0 | const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); |
599 | 0 | if ( pFuncList ) |
600 | 0 | { |
601 | 0 | sal_uInt32 nCount = pFuncList->GetCount(); |
602 | 0 | for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex) |
603 | 0 | { |
604 | 0 | const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); |
605 | | //! Case-insensitive??? |
606 | 0 | if ( pDesc && pDesc->mxFuncName && aName == *pDesc->mxFuncName ) |
607 | 0 | return true; |
608 | 0 | } |
609 | 0 | } |
610 | 0 | return false; |
611 | 0 | } |
612 | | |
613 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |