fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / unoobj / miscuno.cxx
blob9f187786be2a96644b31008a38f375d373ae6a90
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 <cppuhelper/supportsservice.hxx>
21 #include <vcl/svapp.hxx>
23 #include "miscuno.hxx"
25 using namespace com::sun::star;
26 using ::com::sun::star::uno::Reference;
27 using ::com::sun::star::uno::Any;
29 SC_SIMPLE_SERVICE_INFO( ScNameToIndexAccess, "ScNameToIndexAccess", "stardiv.unknown" )
31 uno::Reference<uno::XInterface> ScUnoHelpFunctions::AnyToInterface( const uno::Any& rAny )
33 if ( rAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
35 return uno::Reference<uno::XInterface>(rAny, uno::UNO_QUERY);
37 return uno::Reference<uno::XInterface>(); //! Exception?
40 bool ScUnoHelpFunctions::GetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp,
41 const OUString& rName, bool bDefault )
43 bool bRet = bDefault;
44 if ( xProp.is() )
46 try
48 uno::Any aAny(xProp->getPropertyValue( rName ));
49 //! type conversion???
50 // operator >>= shouldn't be used for bool (?)
51 if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
53 //! safe way to get bool value from any???
54 bRet = *static_cast<sal_Bool const *>(aAny.getValue());
57 catch(uno::Exception&)
59 // keep default
62 return bRet;
65 sal_Int32 ScUnoHelpFunctions::GetLongProperty( const uno::Reference<beans::XPropertySet>& xProp,
66 const OUString& rName, long nDefault )
68 sal_Int32 nRet = nDefault;
69 if ( xProp.is() )
71 try
73 //! type conversion???
74 xProp->getPropertyValue( rName ) >>= nRet;
76 catch(uno::Exception&)
78 // keep default
81 return nRet;
84 sal_Int32 ScUnoHelpFunctions::GetEnumProperty( const uno::Reference<beans::XPropertySet>& xProp,
85 const OUString& rName, long nDefault )
87 sal_Int32 nRet = nDefault;
88 if ( xProp.is() )
90 try
92 uno::Any aAny(xProp->getPropertyValue( rName ));
94 if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
96 //! get enum value from any???
97 nRet = *static_cast<sal_Int32 const *>(aAny.getValue());
99 else
101 //! type conversion???
102 aAny >>= nRet;
105 catch(uno::Exception&)
107 // keep default
110 return nRet;
113 OUString ScUnoHelpFunctions::GetStringProperty(
114 const Reference<beans::XPropertySet>& xProp, const OUString& rName, const OUString& rDefault )
116 OUString aRet = rDefault;
117 if (!xProp.is())
118 return aRet;
122 Any any = xProp->getPropertyValue(rName);
123 any >>= aRet;
125 catch (const uno::Exception&)
129 return aRet;
132 bool ScUnoHelpFunctions::GetBoolFromAny( const uno::Any& aAny )
134 if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
135 return *static_cast<sal_Bool const *>(aAny.getValue());
136 return false;
139 sal_Int16 ScUnoHelpFunctions::GetInt16FromAny( const uno::Any& aAny )
141 sal_Int16 nRet = 0;
142 if ( aAny >>= nRet )
143 return nRet;
144 return 0;
147 sal_Int32 ScUnoHelpFunctions::GetInt32FromAny( const uno::Any& aAny )
149 sal_Int32 nRet = 0;
150 if ( aAny >>= nRet )
151 return nRet;
152 return 0;
155 sal_Int32 ScUnoHelpFunctions::GetEnumFromAny( const uno::Any& aAny )
157 sal_Int32 nRet = 0;
158 if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
159 nRet = *static_cast<sal_Int32 const *>(aAny.getValue());
160 else
161 aAny >>= nRet;
162 return nRet;
165 void ScUnoHelpFunctions::SetBoolInAny( uno::Any& rAny, bool bValue )
167 sal_Bool bTemp = bValue ? 1 : 0;
168 rAny.setValue( &bTemp, cppu::UnoType<bool>::get() );
171 void ScUnoHelpFunctions::SetOptionalPropertyValue(
172 Reference<beans::XPropertySet>& rPropSet, const sal_Char* pPropName, const Any& rVal )
176 rPropSet->setPropertyValue(OUString::createFromAscii(pPropName), rVal);
178 catch (const beans::UnknownPropertyException&)
180 // ignored - not supported.
184 ScIndexEnumeration::ScIndexEnumeration(const uno::Reference<container::XIndexAccess>& rInd,
185 const OUString& rServiceName) :
186 xIndex( rInd ),
187 sServiceName(rServiceName),
188 nPos( 0 )
192 ScIndexEnumeration::~ScIndexEnumeration()
196 // XEnumeration
198 sal_Bool SAL_CALL ScIndexEnumeration::hasMoreElements() throw(uno::RuntimeException, std::exception)
200 SolarMutexGuard aGuard;
201 return ( nPos < xIndex->getCount() );
204 uno::Any SAL_CALL ScIndexEnumeration::nextElement() throw(container::NoSuchElementException,
205 lang::WrappedTargetException, uno::RuntimeException, std::exception)
207 SolarMutexGuard aGuard;
208 uno::Any aReturn;
211 aReturn = xIndex->getByIndex(nPos++);
213 catch (lang::IndexOutOfBoundsException&)
215 throw container::NoSuchElementException();
217 return aReturn;
220 OUString SAL_CALL ScIndexEnumeration::getImplementationName()
221 throw(::com::sun::star::uno::RuntimeException, std::exception)
223 return OUString("ScIndexEnumeration");
226 sal_Bool SAL_CALL ScIndexEnumeration::supportsService( const OUString& ServiceName )
227 throw(::com::sun::star::uno::RuntimeException, std::exception)
229 return cppu::supportsService(this, ServiceName);
232 ::com::sun::star::uno::Sequence< OUString >
233 SAL_CALL ScIndexEnumeration::getSupportedServiceNames()
234 throw(::com::sun::star::uno::RuntimeException, std::exception)
236 ::com::sun::star::uno::Sequence< OUString > aRet(1);
237 OUString* pArray = aRet.getArray();
238 pArray[0] = sServiceName;
239 return aRet;
242 ScNameToIndexAccess::ScNameToIndexAccess( const com::sun::star::uno::Reference<
243 com::sun::star::container::XNameAccess>& rNameObj ) :
244 xNameAccess( rNameObj )
246 //! test for XIndexAccess interface at rNameObj, use that instead!
248 if ( xNameAccess.is() )
249 aNames = xNameAccess->getElementNames();
252 ScNameToIndexAccess::~ScNameToIndexAccess()
256 // XIndexAccess
258 sal_Int32 SAL_CALL ScNameToIndexAccess::getCount( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
260 return aNames.getLength();
263 ::com::sun::star::uno::Any SAL_CALL ScNameToIndexAccess::getByIndex( sal_Int32 nIndex )
264 throw(::com::sun::star::lang::IndexOutOfBoundsException,
265 ::com::sun::star::lang::WrappedTargetException,
266 ::com::sun::star::uno::RuntimeException, std::exception)
268 if ( xNameAccess.is() && nIndex >= 0 && nIndex < aNames.getLength() )
269 return xNameAccess->getByName( aNames.getConstArray()[nIndex] );
271 throw lang::IndexOutOfBoundsException();
274 // XElementAccess
276 ::com::sun::star::uno::Type SAL_CALL ScNameToIndexAccess::getElementType( )
277 throw(::com::sun::star::uno::RuntimeException, std::exception)
279 if ( xNameAccess.is() )
280 return xNameAccess->getElementType();
281 else
282 return uno::Type();
285 sal_Bool SAL_CALL ScNameToIndexAccess::hasElements( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
287 return getCount() > 0;
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */