merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / unoobj / miscuno.cxx
blob0c9122a002f9794a19ee16efb0ad2286fc00e6bf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: miscuno.cxx,v $
10 * $Revision: 1.14.32.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include <tools/debug.hxx>
38 #include "miscuno.hxx"
39 #include "unoguard.hxx"
41 using namespace com::sun::star;
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::uno::Any;
44 using ::rtl::OUString;
46 //------------------------------------------------------------------------
48 //UNUSED2008-05 SC_SIMPLE_SERVICE_INFO( ScEmptyEnumeration, "ScEmptyEnumeration", "stardiv.unknown" )
49 //UNUSED2008-05 SC_SIMPLE_SERVICE_INFO( ScEmptyEnumerationAccess, "ScEmptyEnumerationAccess", "stardiv.unknown" )
50 //UNUSED2008-05 SC_SIMPLE_SERVICE_INFO( ScIndexEnumeration, "ScIndexEnumeration", "stardiv.unknown" )
51 //UNUSED2008-05 SC_SIMPLE_SERVICE_INFO( ScPrintSettingsObj, "ScPrintSettingsObj", "stardiv.unknown" )
53 SC_SIMPLE_SERVICE_INFO( ScNameToIndexAccess, "ScNameToIndexAccess", "stardiv.unknown" )
55 //------------------------------------------------------------------------
57 // static
58 uno::Reference<uno::XInterface> ScUnoHelpFunctions::AnyToInterface( const uno::Any& rAny )
60 if ( rAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
62 return uno::Reference<uno::XInterface>(rAny, uno::UNO_QUERY);
64 return uno::Reference<uno::XInterface>(); //! Exception?
67 // static
68 sal_Bool ScUnoHelpFunctions::GetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp,
69 const rtl::OUString& rName, sal_Bool bDefault )
71 sal_Bool bRet = bDefault;
72 if ( xProp.is() )
74 try
76 uno::Any aAny(xProp->getPropertyValue( rName ));
77 //! type conversion???
78 // operator >>= shouldn't be used for bool (?)
79 if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
81 //! safe way to get bool value from any???
82 bRet = *(sal_Bool*)aAny.getValue();
85 catch(uno::Exception&)
87 // keep default
90 return bRet;
93 // static
94 sal_Int32 ScUnoHelpFunctions::GetLongProperty( const uno::Reference<beans::XPropertySet>& xProp,
95 const rtl::OUString& rName, long nDefault )
97 sal_Int32 nRet = nDefault;
98 if ( xProp.is() )
102 //! type conversion???
103 xProp->getPropertyValue( rName ) >>= nRet;
105 catch(uno::Exception&)
107 // keep default
110 return nRet;
113 // static
114 sal_Int32 ScUnoHelpFunctions::GetEnumProperty( const uno::Reference<beans::XPropertySet>& xProp,
115 const rtl::OUString& rName, long nDefault )
117 sal_Int32 nRet = nDefault;
118 if ( xProp.is() )
122 uno::Any aAny(xProp->getPropertyValue( rName ));
124 if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
126 //! get enum value from any???
127 nRet = *(sal_Int32*)aAny.getValue();
129 else
131 //! type conversion???
132 aAny >>= nRet;
135 catch(uno::Exception&)
137 // keep default
140 return nRet;
143 // static
144 OUString ScUnoHelpFunctions::GetStringProperty(
145 const Reference<beans::XPropertySet>& xProp, const OUString& rName, const OUString& rDefault )
147 OUString aRet = rDefault;
148 if (!xProp.is())
149 return aRet;
153 Any any = xProp->getPropertyValue(rName);
154 any >>= aRet;
156 catch (const uno::Exception&)
160 return aRet;
163 // static
164 sal_Bool ScUnoHelpFunctions::GetBoolFromAny( const uno::Any& aAny )
166 if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
167 return *(sal_Bool*)aAny.getValue();
168 return FALSE;
171 // static
172 sal_Int16 ScUnoHelpFunctions::GetInt16FromAny( const uno::Any& aAny )
174 sal_Int16 nRet = 0;
175 if ( aAny >>= nRet )
176 return nRet;
177 return 0;
180 // static
181 sal_Int32 ScUnoHelpFunctions::GetInt32FromAny( const uno::Any& aAny )
183 sal_Int32 nRet = 0;
184 if ( aAny >>= nRet )
185 return nRet;
186 return 0;
189 // static
190 sal_Int32 ScUnoHelpFunctions::GetEnumFromAny( const uno::Any& aAny )
192 sal_Int32 nRet = 0;
193 if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
194 nRet = *(sal_Int32*)aAny.getValue();
195 else
196 aAny >>= nRet;
197 return nRet;
200 // static
201 void ScUnoHelpFunctions::SetBoolInAny( uno::Any& rAny, sal_Bool bValue )
203 rAny.setValue( &bValue, getBooleanCppuType() );
206 // static
207 void ScUnoHelpFunctions::SetOptionalPropertyValue(
208 Reference<beans::XPropertySet>& rPropSet, const sal_Char* pPropName, const Any& rVal )
212 rPropSet->setPropertyValue(OUString::createFromAscii(pPropName), rVal);
214 catch (const beans::UnknownPropertyException&)
216 // ignored - not supported.
220 //------------------------------------------------------------------------
222 ScIndexEnumeration::ScIndexEnumeration(const uno::Reference<container::XIndexAccess>& rInd,
223 const rtl::OUString& rServiceName) :
224 xIndex( rInd ),
225 sServiceName(rServiceName),
226 nPos( 0 )
230 ScIndexEnumeration::~ScIndexEnumeration()
234 // XEnumeration
236 sal_Bool SAL_CALL ScIndexEnumeration::hasMoreElements() throw(uno::RuntimeException)
238 ScUnoGuard aGuard;
239 return ( nPos < xIndex->getCount() );
242 uno::Any SAL_CALL ScIndexEnumeration::nextElement() throw(container::NoSuchElementException,
243 lang::WrappedTargetException, uno::RuntimeException)
245 ScUnoGuard aGuard;
246 uno::Any aReturn;
249 aReturn = xIndex->getByIndex(nPos++);
251 catch (lang::IndexOutOfBoundsException&)
253 throw container::NoSuchElementException();
255 return aReturn;
258 ::rtl::OUString SAL_CALL ScIndexEnumeration::getImplementationName()
259 throw(::com::sun::star::uno::RuntimeException)
261 return ::rtl::OUString::createFromAscii("ScIndexEnumeration");
264 sal_Bool SAL_CALL ScIndexEnumeration::supportsService( const ::rtl::OUString& ServiceName )
265 throw(::com::sun::star::uno::RuntimeException)
267 return sServiceName == ServiceName;
270 ::com::sun::star::uno::Sequence< ::rtl::OUString >
271 SAL_CALL ScIndexEnumeration::getSupportedServiceNames(void)
272 throw(::com::sun::star::uno::RuntimeException)
274 ::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1);
275 ::rtl::OUString* pArray = aRet.getArray();
276 pArray[0] = sServiceName;
277 return aRet;
280 //------------------------------------------------------------------------
282 //UNUSED2008-05 ScEmptyEnumerationAccess::ScEmptyEnumerationAccess()
283 //UNUSED2008-05 {
284 //UNUSED2008-05 }
285 //UNUSED2008-05
286 //UNUSED2008-05 ScEmptyEnumerationAccess::~ScEmptyEnumerationAccess()
287 //UNUSED2008-05 {
288 //UNUSED2008-05 }
289 //UNUSED2008-05
290 //UNUSED2008-05 // XEnumerationAccess
291 //UNUSED2008-05
292 //UNUSED2008-05 uno::Reference<container::XEnumeration> SAL_CALL ScEmptyEnumerationAccess::createEnumeration()
293 //UNUSED2008-05 throw(uno::RuntimeException)
294 //UNUSED2008-05 {
295 //UNUSED2008-05 ScUnoGuard aGuard;
296 //UNUSED2008-05 return new ScEmptyEnumeration;
297 //UNUSED2008-05 }
298 //UNUSED2008-05
299 //UNUSED2008-05 uno::Type SAL_CALL ScEmptyEnumerationAccess::getElementType() throw(uno::RuntimeException)
300 //UNUSED2008-05 {
301 //UNUSED2008-05 ScUnoGuard aGuard;
302 //UNUSED2008-05 return getCppuType((uno::Reference<uno::XInterface>*)0); // or what?
303 //UNUSED2008-05 }
304 //UNUSED2008-05
305 //UNUSED2008-05 sal_Bool SAL_CALL ScEmptyEnumerationAccess::hasElements() throw(uno::RuntimeException)
306 //UNUSED2008-05 {
307 //UNUSED2008-05 return FALSE;
308 //UNUSED2008-05 }
310 //------------------------------------------------------------------------
312 //UNUSED2008-05 ScEmptyEnumeration::ScEmptyEnumeration()
313 //UNUSED2008-05 {
314 //UNUSED2008-05 }
315 //UNUSED2008-05
316 //UNUSED2008-05 ScEmptyEnumeration::~ScEmptyEnumeration()
317 //UNUSED2008-05 {
318 //UNUSED2008-05 }
319 //UNUSED2008-05
320 //UNUSED2008-05 // XEnumeration
321 //UNUSED2008-05
322 //UNUSED2008-05 sal_Bool SAL_CALL ScEmptyEnumeration::hasMoreElements() throw(uno::RuntimeException)
323 //UNUSED2008-05 {
324 //UNUSED2008-05 ScUnoGuard aGuard;
325 //UNUSED2008-05 return FALSE;
326 //UNUSED2008-05 }
327 //UNUSED2008-05
328 //UNUSED2008-05 uno::Any SAL_CALL ScEmptyEnumeration::nextElement() throw(container::NoSuchElementException,
329 //UNUSED2008-05 lang::WrappedTargetException, uno::RuntimeException)
330 //UNUSED2008-05 {
331 //UNUSED2008-05 ScUnoGuard aGuard;
332 //UNUSED2008-05 return uno::Any();
333 //UNUSED2008-05 }
335 //------------------------------------------------------------------------
337 ScNameToIndexAccess::ScNameToIndexAccess( const com::sun::star::uno::Reference<
338 com::sun::star::container::XNameAccess>& rNameObj ) :
339 xNameAccess( rNameObj )
341 //! test for XIndexAccess interface at rNameObj, use that instead!
343 if ( xNameAccess.is() )
344 aNames = xNameAccess->getElementNames();
347 ScNameToIndexAccess::~ScNameToIndexAccess()
351 // XIndexAccess
353 sal_Int32 SAL_CALL ScNameToIndexAccess::getCount( ) throw(::com::sun::star::uno::RuntimeException)
355 return aNames.getLength();
358 ::com::sun::star::uno::Any SAL_CALL ScNameToIndexAccess::getByIndex( sal_Int32 nIndex )
359 throw(::com::sun::star::lang::IndexOutOfBoundsException,
360 ::com::sun::star::lang::WrappedTargetException,
361 ::com::sun::star::uno::RuntimeException)
363 if ( xNameAccess.is() && nIndex >= 0 && nIndex < aNames.getLength() )
364 return xNameAccess->getByName( aNames.getConstArray()[nIndex] );
366 throw lang::IndexOutOfBoundsException();
367 // return uno::Any();
370 // XElementAccess
372 ::com::sun::star::uno::Type SAL_CALL ScNameToIndexAccess::getElementType( )
373 throw(::com::sun::star::uno::RuntimeException)
375 if ( xNameAccess.is() )
376 return xNameAccess->getElementType();
377 else
378 return uno::Type();
381 sal_Bool SAL_CALL ScNameToIndexAccess::hasElements( ) throw(::com::sun::star::uno::RuntimeException)
383 return getCount() > 0;
386 //------------------------------------------------------------------------
388 //UNUSED2008-05 ScPrintSettingsObj::ScPrintSettingsObj()
389 //UNUSED2008-05 {
390 //UNUSED2008-05 }
391 //UNUSED2008-05
392 //UNUSED2008-05 ScPrintSettingsObj::~ScPrintSettingsObj()
393 //UNUSED2008-05 {
394 //UNUSED2008-05 }
395 //UNUSED2008-05
396 //UNUSED2008-05 // XPropertySet
397 //UNUSED2008-05
398 //UNUSED2008-05 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScPrintSettingsObj::getPropertySetInfo()
399 //UNUSED2008-05 throw(uno::RuntimeException)
400 //UNUSED2008-05 {
401 //UNUSED2008-05 return NULL;
402 //UNUSED2008-05 }
403 //UNUSED2008-05
404 //UNUSED2008-05 void SAL_CALL ScPrintSettingsObj::setPropertyValue(
405 //UNUSED2008-05 const rtl::OUString& /* aPropertyName */, const uno::Any& /* aValue */ )
406 //UNUSED2008-05 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
407 //UNUSED2008-05 lang::IllegalArgumentException, lang::WrappedTargetException,
408 //UNUSED2008-05 uno::RuntimeException)
409 //UNUSED2008-05 {
410 //UNUSED2008-05 //! later...
411 //UNUSED2008-05 }
412 //UNUSED2008-05
413 //UNUSED2008-05 uno::Any SAL_CALL ScPrintSettingsObj::getPropertyValue( const rtl::OUString& /* aPropertyName */ )
414 //UNUSED2008-05 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
415 //UNUSED2008-05 uno::RuntimeException)
416 //UNUSED2008-05 {
417 //UNUSED2008-05 //! later...
418 //UNUSED2008-05 return uno::Any();
419 //UNUSED2008-05 }
420 //UNUSED2008-05
421 //UNUSED2008-05 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScPrintSettingsObj )
424 //------------------------------------------------------------------------