Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / unoobj / appluno.cxx
blobefddd0ad354fe02fc6d406baaac2013a51e81c46
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 .
21 #include "appluno.hxx"
22 #include <sal/types.h>
23 #include <osl/diagnose.h>
24 #include <cppuhelper/factory.hxx>
26 #include <sfx2/app.hxx>
27 #include <sfx2/sfxmodelfactory.hxx>
28 #include "afmtuno.hxx"
29 #include "funcuno.hxx"
30 #include "filtuno.hxx"
31 #include "miscuno.hxx"
32 #include "scmod.hxx"
33 #include "appoptio.hxx"
34 #include "inputopt.hxx"
35 #include "printopt.hxx"
36 #include "userlist.hxx"
37 #include "sc.hrc"
38 #include "unonames.hxx"
39 #include "funcdesc.hxx"
40 #include <com/sun/star/sheet/FunctionArgument.hpp>
41 #include "ScPanelFactory.hxx"
42 #include <boost/scoped_array.hpp>
44 using namespace com::sun::star;
46 // Anzahl der Funktionen, die als zuletzt benutzt gespeichert werden
47 //! Define mit funcpage.hxx und dwfunctr.hxx zusammenfassen !!!
48 #define LRU_MAX 10
50 // Spezial-Werte fuer Zoom
51 //! irgendwo zentral
52 #define SC_ZOOMVAL_OPTIMAL (-1)
53 #define SC_ZOOMVAL_WHOLEPAGE (-2)
54 #define SC_ZOOMVAL_PAGEWIDTH (-3)
56 // Anzahl der PropertyValues in einer Function-Description
57 #define SC_FUNCDESC_PROPCOUNT 5
59 // alles ohne Which-ID, Map nur fuer PropertySetInfo
61 static const SfxItemPropertyMapEntry* lcl_GetSettingsPropertyMap()
63 static const SfxItemPropertyMapEntry aSettingsPropertyMap_Impl[] =
65 {OUString(SC_UNONAME_DOAUTOCP), 0, getBooleanCppuType(), 0, 0},
66 {OUString(SC_UNONAME_ENTERED), 0, getBooleanCppuType(), 0, 0},
67 {OUString(SC_UNONAME_EXPREF), 0, getBooleanCppuType(), 0, 0},
68 {OUString(SC_UNONAME_EXTFMT), 0, getBooleanCppuType(), 0, 0},
69 {OUString(SC_UNONAME_LINKUPD), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
70 {OUString(SC_UNONAME_MARKHDR), 0, getBooleanCppuType(), 0, 0},
71 {OUString(SC_UNONAME_METRIC), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
72 {OUString(SC_UNONAME_MOVEDIR), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
73 {OUString(SC_UNONAME_MOVESEL), 0, getBooleanCppuType(), 0, 0},
74 {OUString(SC_UNONAME_PRALLSH), 0, getBooleanCppuType(), 0, 0},
75 {OUString(SC_UNONAME_PREMPTY), 0, getBooleanCppuType(), 0, 0},
76 {OUString(SC_UNONAME_RANGEFIN), 0, getBooleanCppuType(), 0, 0},
77 {OUString(SC_UNONAME_SCALE), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
78 {OUString(SC_UNONAME_STBFUNC), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
79 {OUString(SC_UNONAME_ULISTS), 0, getCppuType((uno::Sequence<OUString>*)0), 0, 0},
80 {OUString(SC_UNONAME_PRMETRICS),0, getBooleanCppuType(), 0, 0},
81 {OUString(SC_UNONAME_USETABCOL),0, getBooleanCppuType(), 0, 0},
82 {OUString(SC_UNONAME_REPLWARN), 0, getBooleanCppuType(), 0, 0},
83 { OUString(), 0, css::uno::Type(), 0, 0 }
85 return aSettingsPropertyMap_Impl;
88 #define SCFUNCTIONLISTOBJ_SERVICE "com.sun.star.sheet.FunctionDescriptions"
89 #define SCRECENTFUNCTIONSOBJ_SERVICE "com.sun.star.sheet.RecentFunctions"
90 #define SCSPREADSHEETSETTINGS_SERVICE "com.sun.star.sheet.GlobalSheetSettings"
92 SC_SIMPLE_SERVICE_INFO( ScFunctionListObj, "ScFunctionListObj", SCFUNCTIONLISTOBJ_SERVICE )
93 SC_SIMPLE_SERVICE_INFO( ScRecentFunctionsObj, "ScRecentFunctionsObj", SCRECENTFUNCTIONSOBJ_SERVICE )
94 SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettings, "ScSpreadsheetSettings", SCSPREADSHEETSETTINGS_SERVICE )
96 extern "C" {
98 SAL_DLLPUBLIC_EXPORT void * SAL_CALL sc_component_getFactory(
99 const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
101 if (!pServiceManager)
102 return NULL;
104 uno::Reference<lang::XSingleServiceFactory> xFactory;
105 OUString aImpl(OUString::createFromAscii(pImplName));
107 if ( aImpl == ScSpreadsheetSettings::getImplementationName_Static() )
109 xFactory.set(cppu::createOneInstanceFactory(
110 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
111 ScSpreadsheetSettings::getImplementationName_Static(),
112 ScSpreadsheetSettings_CreateInstance,
113 ScSpreadsheetSettings::getSupportedServiceNames_Static() ));
115 else if ( aImpl == ScRecentFunctionsObj::getImplementationName_Static() )
117 xFactory.set(cppu::createOneInstanceFactory(
118 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
119 ScRecentFunctionsObj::getImplementationName_Static(),
120 ScRecentFunctionsObj_CreateInstance,
121 ScRecentFunctionsObj::getSupportedServiceNames_Static() ));
123 else if ( aImpl == ScFunctionListObj::getImplementationName_Static() )
125 xFactory.set(cppu::createOneInstanceFactory(
126 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
127 ScFunctionListObj::getImplementationName_Static(),
128 ScFunctionListObj_CreateInstance,
129 ScFunctionListObj::getSupportedServiceNames_Static() ));
131 else if ( aImpl == ScAutoFormatsObj::getImplementationName_Static() )
133 xFactory.set(cppu::createOneInstanceFactory(
134 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
135 ScAutoFormatsObj::getImplementationName_Static(),
136 ScAutoFormatsObj_CreateInstance,
137 ScAutoFormatsObj::getSupportedServiceNames_Static() ));
139 else if ( aImpl == ScFunctionAccess::getImplementationName_Static() )
141 xFactory.set(cppu::createOneInstanceFactory(
142 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
143 ScFunctionAccess::getImplementationName_Static(),
144 ScFunctionAccess_CreateInstance,
145 ScFunctionAccess::getSupportedServiceNames_Static() ));
147 else if ( aImpl == ScFilterOptionsObj::getImplementationName_Static() )
149 xFactory.set(cppu::createSingleFactory(
150 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
151 ScFilterOptionsObj::getImplementationName_Static(),
152 ScFilterOptionsObj_CreateInstance,
153 ScFilterOptionsObj::getSupportedServiceNames_Static() ));
155 else if ( aImpl == ScXMLImport_getImplementationName() )
157 xFactory.set(cppu::createSingleFactory(
158 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
159 ScXMLImport_getImplementationName(),
160 ScXMLImport_createInstance,
161 ScXMLImport_getSupportedServiceNames() ));
163 else if ( aImpl == ScXMLImport_Meta_getImplementationName() )
165 xFactory.set(cppu::createSingleFactory(
166 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
167 ScXMLImport_Meta_getImplementationName(),
168 ScXMLImport_Meta_createInstance,
169 ScXMLImport_Meta_getSupportedServiceNames() ));
171 else if ( aImpl == ScXMLImport_Styles_getImplementationName() )
173 xFactory.set(cppu::createSingleFactory(
174 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
175 ScXMLImport_Styles_getImplementationName(),
176 ScXMLImport_Styles_createInstance,
177 ScXMLImport_Styles_getSupportedServiceNames() ));
179 else if ( aImpl == ScXMLImport_Content_getImplementationName() )
181 xFactory.set(cppu::createSingleFactory(
182 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
183 ScXMLImport_Content_getImplementationName(),
184 ScXMLImport_Content_createInstance,
185 ScXMLImport_Content_getSupportedServiceNames() ));
187 else if ( aImpl == ScXMLImport_Settings_getImplementationName() )
189 xFactory.set(cppu::createSingleFactory(
190 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
191 ScXMLImport_Settings_getImplementationName(),
192 ScXMLImport_Settings_createInstance,
193 ScXMLImport_Settings_getSupportedServiceNames() ));
195 else if ( aImpl == ScXMLOOoExport_getImplementationName() )
197 xFactory = cppu::createSingleFactory(
198 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
199 ScXMLOOoExport_getImplementationName(),
200 ScXMLOOoExport_createInstance,
201 ScXMLOOoExport_getSupportedServiceNames() );
203 else if ( aImpl == ScXMLOOoExport_Meta_getImplementationName() )
205 xFactory = cppu::createSingleFactory(
206 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
207 ScXMLOOoExport_Meta_getImplementationName(),
208 ScXMLOOoExport_Meta_createInstance,
209 ScXMLOOoExport_Meta_getSupportedServiceNames() );
211 else if ( aImpl == ScXMLOOoExport_Styles_getImplementationName() )
213 xFactory = cppu::createSingleFactory(
214 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
215 ScXMLOOoExport_Styles_getImplementationName(),
216 ScXMLOOoExport_Styles_createInstance,
217 ScXMLOOoExport_Styles_getSupportedServiceNames() );
219 else if ( aImpl == ScXMLOOoExport_Content_getImplementationName() )
221 xFactory = cppu::createSingleFactory(
222 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
223 ScXMLOOoExport_Content_getImplementationName(),
224 ScXMLOOoExport_Content_createInstance,
225 ScXMLOOoExport_Content_getSupportedServiceNames() );
227 else if ( aImpl == ScXMLOOoExport_Settings_getImplementationName() )
229 xFactory = cppu::createSingleFactory(
230 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
231 ScXMLOOoExport_Settings_getImplementationName(),
232 ScXMLOOoExport_Settings_createInstance,
233 ScXMLOOoExport_Settings_getSupportedServiceNames() );
235 else if ( aImpl == ScXMLOasisExport_getImplementationName() )
237 xFactory = cppu::createSingleFactory(
238 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
239 ScXMLOasisExport_getImplementationName(),
240 ScXMLOasisExport_createInstance,
241 ScXMLOasisExport_getSupportedServiceNames() );
243 else if ( aImpl == ScXMLOasisExport_Meta_getImplementationName() )
245 xFactory = cppu::createSingleFactory(
246 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
247 ScXMLOasisExport_Meta_getImplementationName(),
248 ScXMLOasisExport_Meta_createInstance,
249 ScXMLOasisExport_Meta_getSupportedServiceNames() );
251 else if ( aImpl == ScXMLOasisExport_Styles_getImplementationName() )
253 xFactory = cppu::createSingleFactory(
254 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
255 ScXMLOasisExport_Styles_getImplementationName(),
256 ScXMLOasisExport_Styles_createInstance,
257 ScXMLOasisExport_Styles_getSupportedServiceNames() );
259 else if ( aImpl == ScXMLOasisExport_Content_getImplementationName() )
261 xFactory = cppu::createSingleFactory(
262 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
263 ScXMLOasisExport_Content_getImplementationName(),
264 ScXMLOasisExport_Content_createInstance,
265 ScXMLOasisExport_Content_getSupportedServiceNames() );
267 else if ( aImpl == ScXMLOasisExport_Settings_getImplementationName() )
269 xFactory = cppu::createSingleFactory(
270 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
271 ScXMLOasisExport_Settings_getImplementationName(),
272 ScXMLOasisExport_Settings_createInstance,
273 ScXMLOasisExport_Settings_getSupportedServiceNames() );
275 else if ( aImpl == ScDocument_getImplementationName() )
277 xFactory.set(sfx2::createSfxModelFactory(
278 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
279 ScDocument_getImplementationName(),
280 ScDocument_createInstance,
281 ScDocument_getSupportedServiceNames() ));
283 else if ( aImpl == ::sc::sidebar::ScPanelFactory::getImplementationName() )
285 xFactory = ::cppu::createSingleFactory(
286 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
287 ::sc::sidebar::ScPanelFactory::getImplementationName(),
288 ::sc::sidebar::ScPanelFactory::createInstance,
289 ::sc::sidebar::ScPanelFactory::getSupportedServiceNames() );
292 void* pRet = NULL;
293 if (xFactory.is())
295 xFactory->acquire();
296 pRet = xFactory.get();
298 return pRet;
301 } // extern C
303 ScSpreadsheetSettings::ScSpreadsheetSettings() :
304 aPropSet( lcl_GetSettingsPropertyMap() )
308 ScSpreadsheetSettings::~ScSpreadsheetSettings()
312 uno::Reference<uno::XInterface> SAL_CALL ScSpreadsheetSettings_CreateInstance(
313 const uno::Reference<lang::XMultiServiceFactory>& /* rSMgr */ )
315 SolarMutexGuard aGuard;
316 ScDLL::Init();
317 static uno::Reference<uno::XInterface> xInst((cppu::OWeakObject*)new ScSpreadsheetSettings());
318 return xInst;
321 OUString ScSpreadsheetSettings::getImplementationName_Static()
323 return OUString( "stardiv.StarCalc.ScSpreadsheetSettings" );
326 uno::Sequence<OUString> ScSpreadsheetSettings::getSupportedServiceNames_Static()
328 uno::Sequence<OUString> aRet(1);
329 OUString* pArray = aRet.getArray();
330 pArray[0] = OUString( SCSPREADSHEETSETTINGS_SERVICE );
331 return aRet;
334 bool ScSpreadsheetSettings::getPropertyBool(const OUString& aPropertyName) throw (css::uno::RuntimeException)
336 uno::Any any = getPropertyValue(aPropertyName);
337 bool b = false;
338 any >>= b;
339 return b;
342 sal_Int16 ScSpreadsheetSettings::getPropertyInt16(const OUString& aPropertyName) throw (css::uno::RuntimeException)
344 uno::Any any = getPropertyValue(aPropertyName);
345 sal_Int16 b = 0;
346 any >>= b;
347 return b;
350 // XPropertySet
352 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettings::getPropertySetInfo()
353 throw(uno::RuntimeException, std::exception)
355 SolarMutexGuard aGuard;
356 static uno::Reference<beans::XPropertySetInfo> aRef(
357 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
358 return aRef;
361 void SAL_CALL ScSpreadsheetSettings::setPropertyValue(
362 const OUString& aPropertyName, const uno::Any& aValue )
363 throw (beans::UnknownPropertyException, beans::PropertyVetoException,
364 lang::IllegalArgumentException, lang::WrappedTargetException,
365 uno::RuntimeException, std::exception)
367 SolarMutexGuard aGuard;
368 OUString aString(aPropertyName);
370 ScModule* pScMod = SC_MOD();
371 ScAppOptions aAppOpt(pScMod->GetAppOptions());
372 ScInputOptions aInpOpt(pScMod->GetInputOptions());
373 bool bSaveApp = false;
374 bool bSaveInp = false;
375 // print options aren't loaded until needed
377 if (aString.equalsAscii( SC_UNONAME_DOAUTOCP ))
379 aAppOpt.SetAutoComplete( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
380 bSaveApp = true;
382 else if (aString.equalsAscii( SC_UNONAME_ENTERED ))
384 aInpOpt.SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
385 bSaveInp = true;
387 else if (aString.equalsAscii( SC_UNONAME_EXPREF ))
389 aInpOpt.SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
390 bSaveInp = true;
392 else if (aString.equalsAscii( SC_UNONAME_EXTFMT ))
394 aInpOpt.SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
395 bSaveInp = true;
397 else if (aString.equalsAscii( SC_UNONAME_LINKUPD ))
399 aAppOpt.SetLinkMode( (ScLkUpdMode) ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
400 bSaveApp = true;
402 else if (aString.equalsAscii( SC_UNONAME_MARKHDR ))
404 aInpOpt.SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
405 bSaveInp = true;
407 else if (aString.equalsAscii( SC_UNONAME_MOVESEL ))
409 aInpOpt.SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
410 bSaveInp = true;
412 else if (aString.equalsAscii( SC_UNONAME_RANGEFIN ))
414 aInpOpt.SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
415 bSaveInp = true;
417 else if (aString.equalsAscii( SC_UNONAME_USETABCOL ))
419 aInpOpt.SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
420 bSaveInp = true;
422 else if (aString.equalsAscii( SC_UNONAME_PRMETRICS ))
424 aInpOpt.SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
425 bSaveInp = true;
427 else if (aString.equalsAscii( SC_UNONAME_REPLWARN ))
429 aInpOpt.SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
430 bSaveInp = true;
432 else if (aString.equalsAscii( SC_UNONAME_METRIC ))
434 aAppOpt.SetAppMetric( (FieldUnit) ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
435 bSaveApp = true;
437 else if (aString.equalsAscii( SC_UNONAME_MOVEDIR ))
439 aInpOpt.SetMoveDir( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
440 bSaveInp = true;
442 else if (aString.equalsAscii( SC_UNONAME_SCALE ))
444 short nVal = ScUnoHelpFunctions::GetInt16FromAny( aValue );
445 if ( nVal < 0 )
447 SvxZoomType eType = SVX_ZOOM_PERCENT;
448 switch (nVal)
450 case SC_ZOOMVAL_OPTIMAL: eType = SVX_ZOOM_OPTIMAL; break;
451 case SC_ZOOMVAL_WHOLEPAGE: eType = SVX_ZOOM_WHOLEPAGE; break;
452 case SC_ZOOMVAL_PAGEWIDTH: eType = SVX_ZOOM_PAGEWIDTH; break;
454 aAppOpt.SetZoomType( eType );
456 else if ( nVal >= MINZOOM && nVal <= MAXZOOM )
458 aAppOpt.SetZoom( nVal );
459 aAppOpt.SetZoomType( SVX_ZOOM_PERCENT );
461 bSaveApp = true;
463 else if (aString.equalsAscii( SC_UNONAME_STBFUNC ))
465 aAppOpt.SetStatusFunc( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
466 bSaveApp = true;
468 else if (aString.equalsAscii( SC_UNONAME_ULISTS ))
470 ScUserList* pUserList = ScGlobal::GetUserList();
471 uno::Sequence<OUString> aSeq;
472 if ( pUserList && ( aValue >>= aSeq ) )
474 // es wird direkt die "lebende" Liste veraendert,
475 // mehr tut ScGlobal::SetUserList auch nicht
477 pUserList->clear(); // alle Eintraege raus
478 sal_uInt16 nCount = (sal_uInt16)aSeq.getLength();
479 const OUString* pAry = aSeq.getConstArray();
480 for (sal_uInt16 i=0; i<nCount; i++)
482 OUString aEntry = pAry[i];
483 ScUserListData* pData = new ScUserListData(aEntry);
484 pUserList->push_back(pData);
486 bSaveApp = true; // Liste wird mit den App-Optionen gespeichert
489 else if (aString.equalsAscii( SC_UNONAME_PRALLSH ))
491 ScPrintOptions aPrintOpt(pScMod->GetPrintOptions());
492 aPrintOpt.SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
493 pScMod->SetPrintOptions( aPrintOpt );
495 else if (aString.equalsAscii( SC_UNONAME_PREMPTY ))
497 ScPrintOptions aPrintOpt(pScMod->GetPrintOptions());
498 aPrintOpt.SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); // reversed
499 pScMod->SetPrintOptions( aPrintOpt );
500 SFX_APP()->Broadcast( SfxSimpleHint( SID_SCPRINTOPTIONS ) ); // update previews
503 if ( bSaveApp )
504 pScMod->SetAppOptions( aAppOpt );
505 if ( bSaveInp )
506 pScMod->SetInputOptions( aInpOpt );
509 uno::Any SAL_CALL ScSpreadsheetSettings::getPropertyValue( const OUString& aPropertyName )
510 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
511 uno::RuntimeException, std::exception)
513 SolarMutexGuard aGuard;
514 OUString aString = aPropertyName;
515 uno::Any aRet;
517 ScModule* pScMod = SC_MOD();
518 ScAppOptions aAppOpt = pScMod->GetAppOptions();
519 ScInputOptions aInpOpt = pScMod->GetInputOptions();
520 // print options aren't loaded until needed
522 if (aString.equalsAscii( SC_UNONAME_DOAUTOCP )) ScUnoHelpFunctions::SetBoolInAny( aRet, aAppOpt.GetAutoComplete() );
523 else if (aString.equalsAscii( SC_UNONAME_ENTERED )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetEnterEdit() );
524 else if (aString.equalsAscii( SC_UNONAME_EXPREF )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetExpandRefs() );
525 else if (aString.equalsAscii( SC_UNONAME_EXTFMT )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetExtendFormat() );
526 else if (aString.equalsAscii( SC_UNONAME_LINKUPD )) aRet <<= (sal_Int16) aAppOpt.GetLinkMode();
527 else if (aString.equalsAscii( SC_UNONAME_MARKHDR )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetMarkHeader() );
528 else if (aString.equalsAscii( SC_UNONAME_MOVESEL )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetMoveSelection() );
529 else if (aString.equalsAscii( SC_UNONAME_RANGEFIN )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetRangeFinder() );
530 else if (aString.equalsAscii( SC_UNONAME_USETABCOL )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetUseTabCol() );
531 else if (aString.equalsAscii( SC_UNONAME_PRMETRICS )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetTextWysiwyg() );
532 else if (aString.equalsAscii( SC_UNONAME_REPLWARN )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetReplaceCellsWarn() );
533 else if (aString.equalsAscii( SC_UNONAME_METRIC )) aRet <<= (sal_Int16) aAppOpt.GetAppMetric();
534 else if (aString.equalsAscii( SC_UNONAME_MOVEDIR )) aRet <<= (sal_Int16) aInpOpt.GetMoveDir();
535 else if (aString.equalsAscii( SC_UNONAME_STBFUNC )) aRet <<= (sal_Int16) aAppOpt.GetStatusFunc();
536 else if (aString.equalsAscii( SC_UNONAME_SCALE ))
538 sal_Int16 nZoomVal = 0;
539 switch ( aAppOpt.GetZoomType() )
541 case SVX_ZOOM_PERCENT: nZoomVal = aAppOpt.GetZoom(); break;
542 case SVX_ZOOM_OPTIMAL: nZoomVal = SC_ZOOMVAL_OPTIMAL; break;
543 case SVX_ZOOM_WHOLEPAGE: nZoomVal = SC_ZOOMVAL_WHOLEPAGE; break;
544 case SVX_ZOOM_PAGEWIDTH: nZoomVal = SC_ZOOMVAL_PAGEWIDTH; break;
545 default:
547 // added to avoid warnings
550 aRet <<= (sal_Int16) nZoomVal;
552 else if (aString.equalsAscii( SC_UNONAME_ULISTS ))
554 ScUserList* pUserList = ScGlobal::GetUserList();
555 if (pUserList)
557 size_t nCount = pUserList->size();
558 uno::Sequence<OUString> aSeq(nCount);
559 OUString* pAry = aSeq.getArray();
560 for (size_t i=0; i<nCount; ++i)
562 OUString aEntry((*pUserList)[i]->GetString());
563 pAry[i] = aEntry;
565 aRet <<= aSeq;
568 else if (aString.equalsAscii( SC_UNONAME_PRALLSH ))
569 ScUnoHelpFunctions::SetBoolInAny( aRet, pScMod->GetPrintOptions().GetAllSheets() );
570 else if (aString.equalsAscii( SC_UNONAME_PREMPTY ))
571 ScUnoHelpFunctions::SetBoolInAny( aRet, !pScMod->GetPrintOptions().GetSkipEmpty() ); // reversed
573 return aRet;
576 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettings )
578 ScRecentFunctionsObj::ScRecentFunctionsObj()
582 ScRecentFunctionsObj::~ScRecentFunctionsObj()
586 // stuff for exService_...
588 uno::Reference<uno::XInterface> SAL_CALL ScRecentFunctionsObj_CreateInstance(
589 const uno::Reference<lang::XMultiServiceFactory>& /* rSMgr */ )
591 SolarMutexGuard aGuard;
592 ScDLL::Init();
593 static uno::Reference<uno::XInterface> xInst((cppu::OWeakObject*)new ScRecentFunctionsObj());
594 return xInst;
597 OUString ScRecentFunctionsObj::getImplementationName_Static()
599 return OUString( "stardiv.StarCalc.ScRecentFunctionsObj" );
602 uno::Sequence<OUString> ScRecentFunctionsObj::getSupportedServiceNames_Static()
604 uno::Sequence<OUString> aRet(1);
605 OUString* pArray = aRet.getArray();
606 pArray[0] = OUString( SCRECENTFUNCTIONSOBJ_SERVICE );
607 return aRet;
610 // XRecentFunctions
612 uno::Sequence<sal_Int32> SAL_CALL ScRecentFunctionsObj::getRecentFunctionIds()
613 throw(uno::RuntimeException, std::exception)
615 SolarMutexGuard aGuard;
616 const ScAppOptions& rOpt = SC_MOD()->GetAppOptions();
617 sal_uInt16 nCount = rOpt.GetLRUFuncListCount();
618 const sal_uInt16* pFuncs = rOpt.GetLRUFuncList();
619 if (pFuncs)
621 uno::Sequence<sal_Int32> aSeq(nCount);
622 sal_Int32* pAry = aSeq.getArray();
623 for (sal_uInt16 i=0; i<nCount; i++)
624 pAry[i] = pFuncs[i];
625 return aSeq;
627 return uno::Sequence<sal_Int32>(0);
630 void SAL_CALL ScRecentFunctionsObj::setRecentFunctionIds(
631 const uno::Sequence<sal_Int32>& aRecentFunctionIds )
632 throw(uno::RuntimeException, std::exception)
634 SolarMutexGuard aGuard;
635 sal_uInt16 nCount = (sal_uInt16) std::min( aRecentFunctionIds.getLength(), (sal_Int32) LRU_MAX );
636 const sal_Int32* pAry = aRecentFunctionIds.getConstArray();
638 boost::scoped_array<sal_uInt16> pFuncs(nCount ? new sal_uInt16[nCount] : NULL);
639 for (sal_uInt16 i=0; i<nCount; i++)
640 pFuncs[i] = (sal_uInt16)pAry[i]; //! auf gueltige Werte testen?
642 ScModule* pScMod = SC_MOD();
643 ScAppOptions aNewOpts(pScMod->GetAppOptions());
644 aNewOpts.SetLRUFuncList(pFuncs.get(), nCount);
645 pScMod->SetAppOptions(aNewOpts);
647 pScMod->RecentFunctionsChanged(); // update function list child window
650 sal_Int32 SAL_CALL ScRecentFunctionsObj::getMaxRecentFunctions() throw(uno::RuntimeException, std::exception)
652 return LRU_MAX;
655 ScFunctionListObj::ScFunctionListObj()
659 ScFunctionListObj::~ScFunctionListObj()
663 // stuff for exService_...
665 uno::Reference<uno::XInterface> SAL_CALL ScFunctionListObj_CreateInstance(
666 const uno::Reference<lang::XMultiServiceFactory>& /* rSMgr */ )
668 SolarMutexGuard aGuard;
669 ScDLL::Init();
670 static uno::Reference<uno::XInterface> xInst((cppu::OWeakObject*)new ScFunctionListObj());
671 return xInst;
674 OUString ScFunctionListObj::getImplementationName_Static()
676 return OUString( "stardiv.StarCalc.ScFunctionListObj" );
679 uno::Sequence<OUString> ScFunctionListObj::getSupportedServiceNames_Static()
681 uno::Sequence<OUString> aRet(1);
682 OUString* pArray = aRet.getArray();
683 pArray[0] = OUString( SCFUNCTIONLISTOBJ_SERVICE );
684 return aRet;
688 static void lcl_FillSequence( uno::Sequence<beans::PropertyValue>& rSequence, const ScFuncDesc& rDesc )
690 rDesc.initArgumentInfo(); // full argument info is needed
692 OSL_ENSURE( rSequence.getLength() == SC_FUNCDESC_PROPCOUNT, "Falscher Count" );
694 beans::PropertyValue* pArray = rSequence.getArray();
696 pArray[0].Name = OUString( SC_UNONAME_ID );
697 pArray[0].Value <<= (sal_Int32) rDesc.nFIndex;
699 pArray[1].Name = OUString( SC_UNONAME_CATEGORY );
700 pArray[1].Value <<= (sal_Int32) rDesc.nCategory;
702 pArray[2].Name = OUString( SC_UNONAME_NAME );
703 if (rDesc.pFuncName)
704 pArray[2].Value <<= OUString( *rDesc.pFuncName );
706 pArray[3].Name = OUString( SC_UNONAME_DESCRIPTION );
707 if (rDesc.pFuncDesc)
708 pArray[3].Value <<= OUString( *rDesc.pFuncDesc );
710 pArray[4].Name = OUString( SC_UNONAME_ARGUMENTS );
711 if (!rDesc.maDefArgNames.empty() && !rDesc.maDefArgDescs.empty() && rDesc.pDefArgFlags )
713 sal_uInt16 nCount = rDesc.nArgCount;
714 if (nCount >= PAIRED_VAR_ARGS)
715 nCount -= PAIRED_VAR_ARGS - 2;
716 else if (nCount >= VAR_ARGS)
717 nCount -= VAR_ARGS - 1;
718 sal_uInt16 nSeqCount = rDesc.GetSuppressedArgCount();
719 if (nSeqCount >= PAIRED_VAR_ARGS)
720 nSeqCount -= PAIRED_VAR_ARGS - 2;
721 else if (nSeqCount >= VAR_ARGS)
722 nSeqCount -= VAR_ARGS - 1;
724 if (nSeqCount)
726 uno::Sequence<sheet::FunctionArgument> aArgSeq(nSeqCount);
727 sheet::FunctionArgument* pArgAry = aArgSeq.getArray();
728 for (sal_uInt16 i=0, j=0; i<nCount; i++)
730 if (!rDesc.pDefArgFlags[i].bSuppress)
732 sheet::FunctionArgument aArgument;
733 aArgument.Name = rDesc.maDefArgNames[i];
734 aArgument.Description = rDesc.maDefArgDescs[i];
735 aArgument.IsOptional = rDesc.pDefArgFlags[i].bOptional;
736 pArgAry[j++] = aArgument;
739 pArray[4].Value <<= aArgSeq;
744 // XFunctionDescriptions
746 uno::Sequence<beans::PropertyValue> SAL_CALL ScFunctionListObj::getById( sal_Int32 nId )
747 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
749 SolarMutexGuard aGuard;
750 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
751 if ( pFuncList )
753 sal_uInt16 nCount = (sal_uInt16)pFuncList->GetCount();
754 for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++)
756 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
757 if ( pDesc && pDesc->nFIndex == nId )
759 uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
760 lcl_FillSequence( aSeq, *pDesc );
761 return aSeq;
765 throw lang::IllegalArgumentException(); // not found
767 else
768 throw uno::RuntimeException(); // should not happen
771 // XNameAccess
773 uno::Any SAL_CALL ScFunctionListObj::getByName( const OUString& aName )
774 throw(container::NoSuchElementException,
775 lang::WrappedTargetException, uno::RuntimeException, std::exception)
777 SolarMutexGuard aGuard;
778 OUString aNameStr(aName);
779 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
780 if ( pFuncList )
782 sal_uInt16 nCount = (sal_uInt16)pFuncList->GetCount();
783 for (sal_uInt16 nIndex=0; nIndex<nCount; nIndex++)
785 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
786 //! Case-insensitiv ???
787 if ( pDesc && pDesc->pFuncName && aNameStr == *pDesc->pFuncName )
789 uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
790 lcl_FillSequence( aSeq, *pDesc );
791 return uno::makeAny(aSeq);
795 throw container::NoSuchElementException(); // not found
797 else
798 throw uno::RuntimeException(); // should not happen
801 // XIndexAccess
803 sal_Int32 SAL_CALL ScFunctionListObj::getCount() throw(uno::RuntimeException, std::exception)
805 SolarMutexGuard aGuard;
806 sal_Int32 nCount = 0;
807 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
808 if ( pFuncList )
809 nCount = static_cast<sal_Int32>(pFuncList->GetCount());
810 return nCount;
813 uno::Any SAL_CALL ScFunctionListObj::getByIndex( sal_Int32 nIndex )
814 throw(lang::IndexOutOfBoundsException,
815 lang::WrappedTargetException, uno::RuntimeException, std::exception)
817 SolarMutexGuard aGuard;
818 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
819 if ( pFuncList )
821 if ( nIndex >= 0 && nIndex < (sal_Int32)pFuncList->GetCount() )
823 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
824 if ( pDesc )
826 uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT );
827 lcl_FillSequence( aSeq, *pDesc );
828 return uno::makeAny(aSeq);
832 throw lang::IndexOutOfBoundsException(); // illegal index
834 else
835 throw uno::RuntimeException(); // should not happen
838 // XEnumerationAccess
840 uno::Reference<container::XEnumeration> SAL_CALL ScFunctionListObj::createEnumeration()
841 throw(uno::RuntimeException, std::exception)
843 SolarMutexGuard aGuard;
844 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.FunctionDescriptionEnumeration"));
847 // XElementAccess
849 uno::Type SAL_CALL ScFunctionListObj::getElementType() throw(uno::RuntimeException, std::exception)
851 SolarMutexGuard aGuard;
852 return getCppuType((uno::Sequence<beans::PropertyValue>*)0);
855 sal_Bool SAL_CALL ScFunctionListObj::hasElements() throw(uno::RuntimeException, std::exception)
857 SolarMutexGuard aGuard;
858 return ( getCount() > 0 );
861 uno::Sequence<OUString> SAL_CALL ScFunctionListObj::getElementNames() throw(uno::RuntimeException, std::exception)
863 SolarMutexGuard aGuard;
864 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
865 if ( pFuncList )
867 sal_uInt32 nCount = pFuncList->GetCount();
868 uno::Sequence<OUString> aSeq(nCount);
869 OUString* pAry = aSeq.getArray();
870 for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
872 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
873 if ( pDesc && pDesc->pFuncName )
874 pAry[nIndex] = *pDesc->pFuncName;
876 return aSeq;
878 return uno::Sequence<OUString>(0);
881 sal_Bool SAL_CALL ScFunctionListObj::hasByName( const OUString& aName )
882 throw(uno::RuntimeException, std::exception)
884 SolarMutexGuard aGuard;
885 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
886 if ( pFuncList )
888 sal_uInt32 nCount = pFuncList->GetCount();
889 for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
891 const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex);
892 //! Case-insensitiv ???
893 if ( pDesc && pDesc->pFuncName && aName == *pDesc->pFuncName )
894 return sal_True;
897 return false;
903 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */