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 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 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 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 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 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 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 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 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 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 194 void ScUnoHelpFunctions::SetBoolInAny( uno::Any& rAny, sal_Bool bValue ) 195 { 196 rAny.setValue( &bValue, getBooleanCppuType() ); 197 } 198 199 // static 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 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 223 ScIndexEnumeration::~ScIndexEnumeration() 224 { 225 } 226 227 // XEnumeration 228 229 sal_Bool SAL_CALL ScIndexEnumeration::hasMoreElements() throw(uno::RuntimeException) 230 { 231 ScUnoGuard aGuard; 232 return ( nPos < xIndex->getCount() ); 233 } 234 235 uno::Any SAL_CALL ScIndexEnumeration::nextElement() throw(container::NoSuchElementException, 236 lang::WrappedTargetException, uno::RuntimeException) 237 { 238 ScUnoGuard aGuard; 239 uno::Any aReturn; 240 try 241 { 242 aReturn = xIndex->getByIndex(nPos++); 243 } 244 catch (lang::IndexOutOfBoundsException&) 245 { 246 throw container::NoSuchElementException(); 247 } 248 return aReturn; 249 } 250 251 ::rtl::OUString SAL_CALL ScIndexEnumeration::getImplementationName() 252 throw(::com::sun::star::uno::RuntimeException) 253 { 254 return ::rtl::OUString::createFromAscii("ScIndexEnumeration"); 255 } 256 257 sal_Bool SAL_CALL ScIndexEnumeration::supportsService( const ::rtl::OUString& ServiceName ) 258 throw(::com::sun::star::uno::RuntimeException) 259 { 260 return sServiceName == ServiceName; 261 } 262 263 ::com::sun::star::uno::Sequence< ::rtl::OUString > 264 SAL_CALL ScIndexEnumeration::getSupportedServiceNames(void) 265 throw(::com::sun::star::uno::RuntimeException) 266 { 267 ::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1); 268 ::rtl::OUString* pArray = aRet.getArray(); 269 pArray[0] = sServiceName; 270 return aRet; 271 } 272 273 //------------------------------------------------------------------------ 274 275 //UNUSED2008-05 ScEmptyEnumerationAccess::ScEmptyEnumerationAccess() 276 //UNUSED2008-05 { 277 //UNUSED2008-05 } 278 //UNUSED2008-05 279 //UNUSED2008-05 ScEmptyEnumerationAccess::~ScEmptyEnumerationAccess() 280 //UNUSED2008-05 { 281 //UNUSED2008-05 } 282 //UNUSED2008-05 283 //UNUSED2008-05 // XEnumerationAccess 284 //UNUSED2008-05 285 //UNUSED2008-05 uno::Reference<container::XEnumeration> SAL_CALL ScEmptyEnumerationAccess::createEnumeration() 286 //UNUSED2008-05 throw(uno::RuntimeException) 287 //UNUSED2008-05 { 288 //UNUSED2008-05 ScUnoGuard aGuard; 289 //UNUSED2008-05 return new ScEmptyEnumeration; 290 //UNUSED2008-05 } 291 //UNUSED2008-05 292 //UNUSED2008-05 uno::Type SAL_CALL ScEmptyEnumerationAccess::getElementType() throw(uno::RuntimeException) 293 //UNUSED2008-05 { 294 //UNUSED2008-05 ScUnoGuard aGuard; 295 //UNUSED2008-05 return getCppuType((uno::Reference<uno::XInterface>*)0); // or what? 296 //UNUSED2008-05 } 297 //UNUSED2008-05 298 //UNUSED2008-05 sal_Bool SAL_CALL ScEmptyEnumerationAccess::hasElements() throw(uno::RuntimeException) 299 //UNUSED2008-05 { 300 //UNUSED2008-05 return sal_False; 301 //UNUSED2008-05 } 302 303 //------------------------------------------------------------------------ 304 305 //UNUSED2008-05 ScEmptyEnumeration::ScEmptyEnumeration() 306 //UNUSED2008-05 { 307 //UNUSED2008-05 } 308 //UNUSED2008-05 309 //UNUSED2008-05 ScEmptyEnumeration::~ScEmptyEnumeration() 310 //UNUSED2008-05 { 311 //UNUSED2008-05 } 312 //UNUSED2008-05 313 //UNUSED2008-05 // XEnumeration 314 //UNUSED2008-05 315 //UNUSED2008-05 sal_Bool SAL_CALL ScEmptyEnumeration::hasMoreElements() throw(uno::RuntimeException) 316 //UNUSED2008-05 { 317 //UNUSED2008-05 ScUnoGuard aGuard; 318 //UNUSED2008-05 return sal_False; 319 //UNUSED2008-05 } 320 //UNUSED2008-05 321 //UNUSED2008-05 uno::Any SAL_CALL ScEmptyEnumeration::nextElement() throw(container::NoSuchElementException, 322 //UNUSED2008-05 lang::WrappedTargetException, uno::RuntimeException) 323 //UNUSED2008-05 { 324 //UNUSED2008-05 ScUnoGuard aGuard; 325 //UNUSED2008-05 return uno::Any(); 326 //UNUSED2008-05 } 327 328 //------------------------------------------------------------------------ 329 330 ScNameToIndexAccess::ScNameToIndexAccess( const com::sun::star::uno::Reference< 331 com::sun::star::container::XNameAccess>& rNameObj ) : 332 xNameAccess( rNameObj ) 333 { 334 //! test for XIndexAccess interface at rNameObj, use that instead! 335 336 if ( xNameAccess.is() ) 337 aNames = xNameAccess->getElementNames(); 338 } 339 340 ScNameToIndexAccess::~ScNameToIndexAccess() 341 { 342 } 343 344 // XIndexAccess 345 346 sal_Int32 SAL_CALL ScNameToIndexAccess::getCount( ) throw(::com::sun::star::uno::RuntimeException) 347 { 348 return aNames.getLength(); 349 } 350 351 ::com::sun::star::uno::Any SAL_CALL ScNameToIndexAccess::getByIndex( sal_Int32 nIndex ) 352 throw(::com::sun::star::lang::IndexOutOfBoundsException, 353 ::com::sun::star::lang::WrappedTargetException, 354 ::com::sun::star::uno::RuntimeException) 355 { 356 if ( xNameAccess.is() && nIndex >= 0 && nIndex < aNames.getLength() ) 357 return xNameAccess->getByName( aNames.getConstArray()[nIndex] ); 358 359 throw lang::IndexOutOfBoundsException(); 360 // return uno::Any(); 361 } 362 363 // XElementAccess 364 365 ::com::sun::star::uno::Type SAL_CALL ScNameToIndexAccess::getElementType( ) 366 throw(::com::sun::star::uno::RuntimeException) 367 { 368 if ( xNameAccess.is() ) 369 return xNameAccess->getElementType(); 370 else 371 return uno::Type(); 372 } 373 374 sal_Bool SAL_CALL ScNameToIndexAccess::hasElements( ) throw(::com::sun::star::uno::RuntimeException) 375 { 376 return getCount() > 0; 377 } 378 379 //------------------------------------------------------------------------ 380 381 //UNUSED2008-05 ScPrintSettingsObj::ScPrintSettingsObj() 382 //UNUSED2008-05 { 383 //UNUSED2008-05 } 384 //UNUSED2008-05 385 //UNUSED2008-05 ScPrintSettingsObj::~ScPrintSettingsObj() 386 //UNUSED2008-05 { 387 //UNUSED2008-05 } 388 //UNUSED2008-05 389 //UNUSED2008-05 // XPropertySet 390 //UNUSED2008-05 391 //UNUSED2008-05 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScPrintSettingsObj::getPropertySetInfo() 392 //UNUSED2008-05 throw(uno::RuntimeException) 393 //UNUSED2008-05 { 394 //UNUSED2008-05 return NULL; 395 //UNUSED2008-05 } 396 //UNUSED2008-05 397 //UNUSED2008-05 void SAL_CALL ScPrintSettingsObj::setPropertyValue( 398 //UNUSED2008-05 const rtl::OUString& /* aPropertyName */, const uno::Any& /* aValue */ ) 399 //UNUSED2008-05 throw(beans::UnknownPropertyException, beans::PropertyVetoException, 400 //UNUSED2008-05 lang::IllegalArgumentException, lang::WrappedTargetException, 401 //UNUSED2008-05 uno::RuntimeException) 402 //UNUSED2008-05 { 403 //UNUSED2008-05 //! later... 404 //UNUSED2008-05 } 405 //UNUSED2008-05 406 //UNUSED2008-05 uno::Any SAL_CALL ScPrintSettingsObj::getPropertyValue( const rtl::OUString& /* aPropertyName */ ) 407 //UNUSED2008-05 throw(beans::UnknownPropertyException, lang::WrappedTargetException, 408 //UNUSED2008-05 uno::RuntimeException) 409 //UNUSED2008-05 { 410 //UNUSED2008-05 //! later... 411 //UNUSED2008-05 return uno::Any(); 412 //UNUSED2008-05 } 413 //UNUSED2008-05 414 //UNUSED2008-05 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScPrintSettingsObj ) 415 416 417 //------------------------------------------------------------------------ 418 419 420 421