1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 #include <tools/debug.hxx>
30
31 #include "miscuno.hxx"
32 #include "unoguard.hxx"
33
34 using namespace com::sun::star;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::Any;
37 using ::rtl::OUString;
38
39 //------------------------------------------------------------------------
40
41 //UNUSED2008-05 SC_SIMPLE_SERVICE_INFO( ScEmptyEnumeration, "ScEmptyEnumeration", "stardiv.unknown" )
42 //UNUSED2008-05 SC_SIMPLE_SERVICE_INFO( ScEmptyEnumerationAccess, "ScEmptyEnumerationAccess", "stardiv.unknown" )
43 //UNUSED2008-05 SC_SIMPLE_SERVICE_INFO( ScIndexEnumeration, "ScIndexEnumeration", "stardiv.unknown" )
44 //UNUSED2008-05 SC_SIMPLE_SERVICE_INFO( ScPrintSettingsObj, "ScPrintSettingsObj", "stardiv.unknown" )
45
46 SC_SIMPLE_SERVICE_INFO( ScNameToIndexAccess, "ScNameToIndexAccess", "stardiv.unknown" )
47
48 //------------------------------------------------------------------------
49
50 // static
AnyToInterface(const uno::Any & rAny)51 uno::Reference<uno::XInterface> ScUnoHelpFunctions::AnyToInterface( const uno::Any& rAny )
52 {
53 if ( rAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
54 {
55 return uno::Reference<uno::XInterface>(rAny, uno::UNO_QUERY);
56 }
57 return uno::Reference<uno::XInterface>(); //! Exception?
58 }
59
60 // static
GetBoolProperty(const uno::Reference<beans::XPropertySet> & xProp,const rtl::OUString & rName,sal_Bool bDefault)61 sal_Bool ScUnoHelpFunctions::GetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp,
62 const rtl::OUString& rName, sal_Bool bDefault )
63 {
64 sal_Bool bRet = bDefault;
65 if ( xProp.is() )
66 {
67 try
68 {
69 uno::Any aAny(xProp->getPropertyValue( rName ));
70 //! type conversion???
71 // operator >>= shouldn't be used for bool (?)
72 if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
73 {
74 //! safe way to get bool value from any???
75 bRet = *(sal_Bool*)aAny.getValue();
76 }
77 }
78 catch(uno::Exception&)
79 {
80 // keep default
81 }
82 }
83 return bRet;
84 }
85
86 // static
GetLongProperty(const uno::Reference<beans::XPropertySet> & xProp,const rtl::OUString & rName,long nDefault)87 sal_Int32 ScUnoHelpFunctions::GetLongProperty( const uno::Reference<beans::XPropertySet>& xProp,
88 const rtl::OUString& rName, long nDefault )
89 {
90 sal_Int32 nRet = nDefault;
91 if ( xProp.is() )
92 {
93 try
94 {
95 //! type conversion???
96 xProp->getPropertyValue( rName ) >>= nRet;
97 }
98 catch(uno::Exception&)
99 {
100 // keep default
101 }
102 }
103 return nRet;
104 }
105
106 // static
GetEnumProperty(const uno::Reference<beans::XPropertySet> & xProp,const rtl::OUString & rName,long nDefault)107 sal_Int32 ScUnoHelpFunctions::GetEnumProperty( const uno::Reference<beans::XPropertySet>& xProp,
108 const rtl::OUString& rName, long nDefault )
109 {
110 sal_Int32 nRet = nDefault;
111 if ( xProp.is() )
112 {
113 try
114 {
115 uno::Any aAny(xProp->getPropertyValue( rName ));
116
117 if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
118 {
119 //! get enum value from any???
120 nRet = *(sal_Int32*)aAny.getValue();
121 }
122 else
123 {
124 //! type conversion???
125 aAny >>= nRet;
126 }
127 }
128 catch(uno::Exception&)
129 {
130 // keep default
131 }
132 }
133 return nRet;
134 }
135
136 // static
GetStringProperty(const Reference<beans::XPropertySet> & xProp,const OUString & rName,const OUString & rDefault)137 OUString ScUnoHelpFunctions::GetStringProperty(
138 const Reference<beans::XPropertySet>& xProp, const OUString& rName, const OUString& rDefault )
139 {
140 OUString aRet = rDefault;
141 if (!xProp.is())
142 return aRet;
143
144 try
145 {
146 Any any = xProp->getPropertyValue(rName);
147 any >>= aRet;
148 }
149 catch (const uno::Exception&)
150 {
151 }
152
153 return aRet;
154 }
155
156 // static
GetBoolFromAny(const uno::Any & aAny)157 sal_Bool ScUnoHelpFunctions::GetBoolFromAny( const uno::Any& aAny )
158 {
159 if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
160 return *(sal_Bool*)aAny.getValue();
161 return sal_False;
162 }
163
164 // static
GetInt16FromAny(const uno::Any & aAny)165 sal_Int16 ScUnoHelpFunctions::GetInt16FromAny( const uno::Any& aAny )
166 {
167 sal_Int16 nRet = 0;
168 if ( aAny >>= nRet )
169 return nRet;
170 return 0;
171 }
172
173 // static
GetInt32FromAny(const uno::Any & aAny)174 sal_Int32 ScUnoHelpFunctions::GetInt32FromAny( const uno::Any& aAny )
175 {
176 sal_Int32 nRet = 0;
177 if ( aAny >>= nRet )
178 return nRet;
179 return 0;
180 }
181
182 // static
GetEnumFromAny(const uno::Any & aAny)183 sal_Int32 ScUnoHelpFunctions::GetEnumFromAny( const uno::Any& aAny )
184 {
185 sal_Int32 nRet = 0;
186 if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
187 nRet = *(sal_Int32*)aAny.getValue();
188 else
189 aAny >>= nRet;
190 return nRet;
191 }
192
193 // static
SetBoolInAny(uno::Any & rAny,sal_Bool bValue)194 void ScUnoHelpFunctions::SetBoolInAny( uno::Any& rAny, sal_Bool bValue )
195 {
196 rAny.setValue( &bValue, getBooleanCppuType() );
197 }
198
199 // static
SetOptionalPropertyValue(Reference<beans::XPropertySet> & rPropSet,const sal_Char * pPropName,const Any & rVal)200 void ScUnoHelpFunctions::SetOptionalPropertyValue(
201 Reference<beans::XPropertySet>& rPropSet, const sal_Char* pPropName, const Any& rVal )
202 {
203 try
204 {
205 rPropSet->setPropertyValue(OUString::createFromAscii(pPropName), rVal);
206 }
207 catch (const beans::UnknownPropertyException&)
208 {
209 // ignored - not supported.
210 }
211 }
212
213 //------------------------------------------------------------------------
214
ScIndexEnumeration(const uno::Reference<container::XIndexAccess> & rInd,const rtl::OUString & rServiceName)215 ScIndexEnumeration::ScIndexEnumeration(const uno::Reference<container::XIndexAccess>& rInd,
216 const rtl::OUString& rServiceName) :
217 xIndex( rInd ),
218 sServiceName(rServiceName),
219 nPos( 0 )
220 {
221 }
222
~ScIndexEnumeration()223 ScIndexEnumeration::~ScIndexEnumeration()
224 {
225 }
226
227 // XEnumeration
228
hasMoreElements()229 sal_Bool SAL_CALL ScIndexEnumeration::hasMoreElements()
230 {
231 ScUnoGuard aGuard;
232 return ( nPos < xIndex->getCount() );
233 }
234
nextElement()235 uno::Any SAL_CALL ScIndexEnumeration::nextElement()
236 {
237 ScUnoGuard aGuard;
238 uno::Any aReturn;
239 try
240 {
241 aReturn = xIndex->getByIndex(nPos++);
242 }
243 catch (lang::IndexOutOfBoundsException&)
244 {
245 throw container::NoSuchElementException();
246 }
247 return aReturn;
248 }
249
getImplementationName()250 ::rtl::OUString SAL_CALL ScIndexEnumeration::getImplementationName()
251 {
252 return ::rtl::OUString::createFromAscii("ScIndexEnumeration");
253 }
254
supportsService(const::rtl::OUString & ServiceName)255 sal_Bool SAL_CALL ScIndexEnumeration::supportsService( const ::rtl::OUString& ServiceName )
256 {
257 return sServiceName == ServiceName;
258 }
259
260 ::com::sun::star::uno::Sequence< ::rtl::OUString >
getSupportedServiceNames(void)261 SAL_CALL ScIndexEnumeration::getSupportedServiceNames(void)
262 {
263 ::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1);
264 ::rtl::OUString* pArray = aRet.getArray();
265 pArray[0] = sServiceName;
266 return aRet;
267 }
268
269 //------------------------------------------------------------------------
270
271 //UNUSED2008-05 ScEmptyEnumerationAccess::ScEmptyEnumerationAccess()
272 //UNUSED2008-05 {
273 //UNUSED2008-05 }
274 //UNUSED2008-05
275 //UNUSED2008-05 ScEmptyEnumerationAccess::~ScEmptyEnumerationAccess()
276 //UNUSED2008-05 {
277 //UNUSED2008-05 }
278 //UNUSED2008-05
279 //UNUSED2008-05 // XEnumerationAccess
280 //UNUSED2008-05
281 //UNUSED2008-05 uno::Reference<container::XEnumeration> SAL_CALL ScEmptyEnumerationAccess::createEnumeration()
282 //UNUSED2008-05 throw(uno::RuntimeException)
283 //UNUSED2008-05 {
284 //UNUSED2008-05 ScUnoGuard aGuard;
285 //UNUSED2008-05 return new ScEmptyEnumeration;
286 //UNUSED2008-05 }
287 //UNUSED2008-05
288 //UNUSED2008-05 uno::Type SAL_CALL ScEmptyEnumerationAccess::getElementType() throw(uno::RuntimeException)
289 //UNUSED2008-05 {
290 //UNUSED2008-05 ScUnoGuard aGuard;
291 //UNUSED2008-05 return getCppuType((uno::Reference<uno::XInterface>*)0); // or what?
292 //UNUSED2008-05 }
293 //UNUSED2008-05
294 //UNUSED2008-05 sal_Bool SAL_CALL ScEmptyEnumerationAccess::hasElements() throw(uno::RuntimeException)
295 //UNUSED2008-05 {
296 //UNUSED2008-05 return sal_False;
297 //UNUSED2008-05 }
298
299 //------------------------------------------------------------------------
300
301 //UNUSED2008-05 ScEmptyEnumeration::ScEmptyEnumeration()
302 //UNUSED2008-05 {
303 //UNUSED2008-05 }
304 //UNUSED2008-05
305 //UNUSED2008-05 ScEmptyEnumeration::~ScEmptyEnumeration()
306 //UNUSED2008-05 {
307 //UNUSED2008-05 }
308 //UNUSED2008-05
309 //UNUSED2008-05 // XEnumeration
310 //UNUSED2008-05
311 //UNUSED2008-05 sal_Bool SAL_CALL ScEmptyEnumeration::hasMoreElements() throw(uno::RuntimeException)
312 //UNUSED2008-05 {
313 //UNUSED2008-05 ScUnoGuard aGuard;
314 //UNUSED2008-05 return sal_False;
315 //UNUSED2008-05 }
316 //UNUSED2008-05
317 //UNUSED2008-05 uno::Any SAL_CALL ScEmptyEnumeration::nextElement() throw(container::NoSuchElementException,
318 //UNUSED2008-05 lang::WrappedTargetException, uno::RuntimeException)
319 //UNUSED2008-05 {
320 //UNUSED2008-05 ScUnoGuard aGuard;
321 //UNUSED2008-05 return uno::Any();
322 //UNUSED2008-05 }
323
324 //------------------------------------------------------------------------
325
ScNameToIndexAccess(const com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> & rNameObj)326 ScNameToIndexAccess::ScNameToIndexAccess( const com::sun::star::uno::Reference<
327 com::sun::star::container::XNameAccess>& rNameObj ) :
328 xNameAccess( rNameObj )
329 {
330 //! test for XIndexAccess interface at rNameObj, use that instead!
331
332 if ( xNameAccess.is() )
333 aNames = xNameAccess->getElementNames();
334 }
335
~ScNameToIndexAccess()336 ScNameToIndexAccess::~ScNameToIndexAccess()
337 {
338 }
339
340 // XIndexAccess
341
getCount()342 sal_Int32 SAL_CALL ScNameToIndexAccess::getCount( )
343 {
344 return aNames.getLength();
345 }
346
getByIndex(sal_Int32 nIndex)347 ::com::sun::star::uno::Any SAL_CALL ScNameToIndexAccess::getByIndex( sal_Int32 nIndex )
348 {
349 if ( xNameAccess.is() && nIndex >= 0 && nIndex < aNames.getLength() )
350 return xNameAccess->getByName( aNames.getConstArray()[nIndex] );
351
352 throw lang::IndexOutOfBoundsException();
353 // return uno::Any();
354 }
355
356 // XElementAccess
357
getElementType()358 ::com::sun::star::uno::Type SAL_CALL ScNameToIndexAccess::getElementType( )
359 {
360 if ( xNameAccess.is() )
361 return xNameAccess->getElementType();
362 else
363 return uno::Type();
364 }
365
hasElements()366 sal_Bool SAL_CALL ScNameToIndexAccess::hasElements( )
367 {
368 return getCount() > 0;
369 }
370
371 //------------------------------------------------------------------------
372
373 //UNUSED2008-05 ScPrintSettingsObj::ScPrintSettingsObj()
374 //UNUSED2008-05 {
375 //UNUSED2008-05 }
376 //UNUSED2008-05
377 //UNUSED2008-05 ScPrintSettingsObj::~ScPrintSettingsObj()
378 //UNUSED2008-05 {
379 //UNUSED2008-05 }
380 //UNUSED2008-05
381 //UNUSED2008-05 // XPropertySet
382 //UNUSED2008-05
383 //UNUSED2008-05 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScPrintSettingsObj::getPropertySetInfo()
384 //UNUSED2008-05 throw(uno::RuntimeException)
385 //UNUSED2008-05 {
386 //UNUSED2008-05 return NULL;
387 //UNUSED2008-05 }
388 //UNUSED2008-05
389 //UNUSED2008-05 void SAL_CALL ScPrintSettingsObj::setPropertyValue(
390 //UNUSED2008-05 const rtl::OUString& /* aPropertyName */, const uno::Any& /* aValue */ )
391 //UNUSED2008-05 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
392 //UNUSED2008-05 lang::IllegalArgumentException, lang::WrappedTargetException,
393 //UNUSED2008-05 uno::RuntimeException)
394 //UNUSED2008-05 {
395 //UNUSED2008-05 //! later...
396 //UNUSED2008-05 }
397 //UNUSED2008-05
398 //UNUSED2008-05 uno::Any SAL_CALL ScPrintSettingsObj::getPropertyValue( const rtl::OUString& /* aPropertyName */ )
399 //UNUSED2008-05 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
400 //UNUSED2008-05 uno::RuntimeException)
401 //UNUSED2008-05 {
402 //UNUSED2008-05 //! later...
403 //UNUSED2008-05 return uno::Any();
404 //UNUSED2008-05 }
405 //UNUSED2008-05
406 //UNUSED2008-05 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScPrintSettingsObj )
407
408
409 //------------------------------------------------------------------------
410