1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 //------------------------------------------------------------------------
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?
68 sal_Bool
ScUnoHelpFunctions::GetBoolProperty( const uno::Reference
<beans::XPropertySet
>& xProp
,
69 const rtl::OUString
& rName
, sal_Bool bDefault
)
71 sal_Bool bRet
= bDefault
;
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
&)
94 sal_Int32
ScUnoHelpFunctions::GetLongProperty( const uno::Reference
<beans::XPropertySet
>& xProp
,
95 const rtl::OUString
& rName
, long nDefault
)
97 sal_Int32 nRet
= nDefault
;
102 //! type conversion???
103 xProp
->getPropertyValue( rName
) >>= nRet
;
105 catch(uno::Exception
&)
114 sal_Int32
ScUnoHelpFunctions::GetEnumProperty( const uno::Reference
<beans::XPropertySet
>& xProp
,
115 const rtl::OUString
& rName
, long nDefault
)
117 sal_Int32 nRet
= nDefault
;
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();
131 //! type conversion???
135 catch(uno::Exception
&)
144 OUString
ScUnoHelpFunctions::GetStringProperty(
145 const Reference
<beans::XPropertySet
>& xProp
, const OUString
& rName
, const OUString
& rDefault
)
147 OUString aRet
= rDefault
;
153 Any any
= xProp
->getPropertyValue(rName
);
156 catch (const uno::Exception
&)
164 sal_Bool
ScUnoHelpFunctions::GetBoolFromAny( const uno::Any
& aAny
)
166 if ( aAny
.getValueTypeClass() == uno::TypeClass_BOOLEAN
)
167 return *(sal_Bool
*)aAny
.getValue();
172 sal_Int16
ScUnoHelpFunctions::GetInt16FromAny( const uno::Any
& aAny
)
181 sal_Int32
ScUnoHelpFunctions::GetInt32FromAny( const uno::Any
& aAny
)
190 sal_Int32
ScUnoHelpFunctions::GetEnumFromAny( const uno::Any
& aAny
)
193 if ( aAny
.getValueTypeClass() == uno::TypeClass_ENUM
)
194 nRet
= *(sal_Int32
*)aAny
.getValue();
201 void ScUnoHelpFunctions::SetBoolInAny( uno::Any
& rAny
, sal_Bool bValue
)
203 rAny
.setValue( &bValue
, getBooleanCppuType() );
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
) :
225 sServiceName(rServiceName
),
230 ScIndexEnumeration::~ScIndexEnumeration()
236 sal_Bool SAL_CALL
ScIndexEnumeration::hasMoreElements() throw(uno::RuntimeException
)
239 return ( nPos
< xIndex
->getCount() );
242 uno::Any SAL_CALL
ScIndexEnumeration::nextElement() throw(container::NoSuchElementException
,
243 lang::WrappedTargetException
, uno::RuntimeException
)
249 aReturn
= xIndex
->getByIndex(nPos
++);
251 catch (lang::IndexOutOfBoundsException
&)
253 throw container::NoSuchElementException();
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
;
280 //------------------------------------------------------------------------
282 //UNUSED2008-05 ScEmptyEnumerationAccess::ScEmptyEnumerationAccess()
286 //UNUSED2008-05 ScEmptyEnumerationAccess::~ScEmptyEnumerationAccess()
290 //UNUSED2008-05 // XEnumerationAccess
292 //UNUSED2008-05 uno::Reference<container::XEnumeration> SAL_CALL ScEmptyEnumerationAccess::createEnumeration()
293 //UNUSED2008-05 throw(uno::RuntimeException)
295 //UNUSED2008-05 ScUnoGuard aGuard;
296 //UNUSED2008-05 return new ScEmptyEnumeration;
299 //UNUSED2008-05 uno::Type SAL_CALL ScEmptyEnumerationAccess::getElementType() throw(uno::RuntimeException)
301 //UNUSED2008-05 ScUnoGuard aGuard;
302 //UNUSED2008-05 return getCppuType((uno::Reference<uno::XInterface>*)0); // or what?
305 //UNUSED2008-05 sal_Bool SAL_CALL ScEmptyEnumerationAccess::hasElements() throw(uno::RuntimeException)
307 //UNUSED2008-05 return FALSE;
310 //------------------------------------------------------------------------
312 //UNUSED2008-05 ScEmptyEnumeration::ScEmptyEnumeration()
316 //UNUSED2008-05 ScEmptyEnumeration::~ScEmptyEnumeration()
320 //UNUSED2008-05 // XEnumeration
322 //UNUSED2008-05 sal_Bool SAL_CALL ScEmptyEnumeration::hasMoreElements() throw(uno::RuntimeException)
324 //UNUSED2008-05 ScUnoGuard aGuard;
325 //UNUSED2008-05 return FALSE;
328 //UNUSED2008-05 uno::Any SAL_CALL ScEmptyEnumeration::nextElement() throw(container::NoSuchElementException,
329 //UNUSED2008-05 lang::WrappedTargetException, uno::RuntimeException)
331 //UNUSED2008-05 ScUnoGuard aGuard;
332 //UNUSED2008-05 return uno::Any();
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()
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();
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();
381 sal_Bool SAL_CALL
ScNameToIndexAccess::hasElements( ) throw(::com::sun::star::uno::RuntimeException
)
383 return getCount() > 0;
386 //------------------------------------------------------------------------
388 //UNUSED2008-05 ScPrintSettingsObj::ScPrintSettingsObj()
392 //UNUSED2008-05 ScPrintSettingsObj::~ScPrintSettingsObj()
396 //UNUSED2008-05 // XPropertySet
398 //UNUSED2008-05 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScPrintSettingsObj::getPropertySetInfo()
399 //UNUSED2008-05 throw(uno::RuntimeException)
401 //UNUSED2008-05 return NULL;
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)
410 //UNUSED2008-05 //! later...
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)
417 //UNUSED2008-05 //! later...
418 //UNUSED2008-05 return uno::Any();
421 //UNUSED2008-05 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScPrintSettingsObj )
424 //------------------------------------------------------------------------