LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - miscuno.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 83 109 76.1 %
Date: 2014-04-11 Functions: 22 29 75.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <cppuhelper/supportsservice.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : 
      23             : #include "miscuno.hxx"
      24             : 
      25             : using namespace com::sun::star;
      26             : using ::com::sun::star::uno::Reference;
      27             : using ::com::sun::star::uno::Any;
      28             : 
      29           0 : SC_SIMPLE_SERVICE_INFO( ScNameToIndexAccess, "ScNameToIndexAccess", "stardiv.unknown" )
      30             : 
      31        5616 : uno::Reference<uno::XInterface> ScUnoHelpFunctions::AnyToInterface( const uno::Any& rAny )
      32             : {
      33        5616 :     if ( rAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
      34             :     {
      35        5616 :         return uno::Reference<uno::XInterface>(rAny, uno::UNO_QUERY);
      36             :     }
      37           0 :     return uno::Reference<uno::XInterface>();   //! Exception?
      38             : }
      39             : 
      40        4052 : bool ScUnoHelpFunctions::GetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp,
      41             :                                             const OUString& rName, bool bDefault )
      42             : {
      43        4052 :     bool bRet = bDefault;
      44        4052 :     if ( xProp.is() )
      45             :     {
      46             :         try
      47             :         {
      48        4052 :             uno::Any aAny(xProp->getPropertyValue( rName ));
      49             :             //! type conversion???
      50             :             //  operator >>= shouldn't be used for bool (?)
      51        4052 :             if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
      52             :             {
      53             :                 //! safe way to get bool value from any???
      54        4052 :                 bRet = *(sal_Bool*)aAny.getValue();
      55        4052 :             }
      56             :         }
      57           0 :         catch(uno::Exception&)
      58             :         {
      59             :             // keep default
      60             :         }
      61             :     }
      62        4052 :     return bRet;
      63             : }
      64             : 
      65        1796 : sal_Int32 ScUnoHelpFunctions::GetLongProperty( const uno::Reference<beans::XPropertySet>& xProp,
      66             :                                             const OUString& rName, long nDefault )
      67             : {
      68        1796 :     sal_Int32 nRet = nDefault;
      69        1796 :     if ( xProp.is() )
      70             :     {
      71             :         try
      72             :         {
      73             :             //! type conversion???
      74        1796 :             xProp->getPropertyValue( rName ) >>= nRet;
      75             :         }
      76           0 :         catch(uno::Exception&)
      77             :         {
      78             :             // keep default
      79             :         }
      80             :     }
      81        1796 :     return nRet;
      82             : }
      83             : 
      84        3087 : sal_Int32 ScUnoHelpFunctions::GetEnumProperty( const uno::Reference<beans::XPropertySet>& xProp,
      85             :                                             const OUString& rName, long nDefault )
      86             : {
      87        3087 :     sal_Int32 nRet = nDefault;
      88        3087 :     if ( xProp.is() )
      89             :     {
      90             :         try
      91             :         {
      92        3087 :             uno::Any aAny(xProp->getPropertyValue( rName ));
      93             : 
      94        3087 :             if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
      95             :             {
      96             :                 //! get enum value from any???
      97        3087 :                 nRet = *(sal_Int32*)aAny.getValue();
      98             :             }
      99             :             else
     100             :             {
     101             :                 //! type conversion???
     102           0 :                 aAny >>= nRet;
     103        3087 :             }
     104             :         }
     105           0 :         catch(uno::Exception&)
     106             :         {
     107             :             // keep default
     108             :         }
     109             :     }
     110        3087 :     return nRet;
     111             : }
     112             : 
     113         473 : OUString ScUnoHelpFunctions::GetStringProperty(
     114             :     const Reference<beans::XPropertySet>& xProp, const OUString& rName, const OUString& rDefault )
     115             : {
     116         473 :     OUString aRet = rDefault;
     117         473 :     if (!xProp.is())
     118           0 :         return aRet;
     119             : 
     120             :     try
     121             :     {
     122         473 :         Any any = xProp->getPropertyValue(rName);
     123         473 :         any >>= aRet;
     124             :     }
     125           0 :     catch (const uno::Exception&)
     126             :     {
     127             :     }
     128             : 
     129         473 :     return aRet;
     130             : }
     131             : 
     132        7954 : bool ScUnoHelpFunctions::GetBoolFromAny( const uno::Any& aAny )
     133             : {
     134        7954 :     if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
     135        7952 :         return *(sal_Bool*)aAny.getValue();
     136           2 :     return false;
     137             : }
     138             : 
     139         244 : sal_Int16 ScUnoHelpFunctions::GetInt16FromAny( const uno::Any& aAny )
     140             : {
     141         244 :     sal_Int16 nRet = 0;
     142         244 :     if ( aAny >>= nRet )
     143         244 :         return nRet;
     144           0 :     return 0;
     145             : }
     146             : 
     147        1296 : sal_Int32 ScUnoHelpFunctions::GetInt32FromAny( const uno::Any& aAny )
     148             : {
     149        1296 :     sal_Int32 nRet = 0;
     150        1296 :     if ( aAny >>= nRet )
     151        1296 :         return nRet;
     152           0 :     return 0;
     153             : }
     154             : 
     155         123 : sal_Int32 ScUnoHelpFunctions::GetEnumFromAny( const uno::Any& aAny )
     156             : {
     157         123 :     sal_Int32 nRet = 0;
     158         123 :     if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
     159         123 :         nRet = *(sal_Int32*)aAny.getValue();
     160             :     else
     161           0 :         aAny >>= nRet;
     162         123 :     return nRet;
     163             : }
     164             : 
     165        3916 : void ScUnoHelpFunctions::SetBoolInAny( uno::Any& rAny, bool bValue )
     166             : {
     167        3916 :     sal_Bool bTemp = bValue ? 1 : 0;
     168        3916 :     rAny.setValue( &bTemp, getBooleanCppuType() );
     169        3916 : }
     170             : 
     171         627 : void ScUnoHelpFunctions::SetOptionalPropertyValue(
     172             :     Reference<beans::XPropertySet>& rPropSet, const sal_Char* pPropName, const Any& rVal )
     173             : {
     174             :     try
     175             :     {
     176         627 :         rPropSet->setPropertyValue(OUString::createFromAscii(pPropName), rVal);
     177             :     }
     178           0 :     catch (const beans::UnknownPropertyException&)
     179             :     {
     180             :         // ignored - not supported.
     181             :     }
     182         627 : }
     183             : 
     184          94 : ScIndexEnumeration::ScIndexEnumeration(const uno::Reference<container::XIndexAccess>& rInd,
     185             :                                        const OUString& rServiceName) :
     186             :     xIndex( rInd ),
     187             :     sServiceName(rServiceName),
     188          94 :     nPos( 0 )
     189             : {
     190          94 : }
     191             : 
     192         188 : ScIndexEnumeration::~ScIndexEnumeration()
     193             : {
     194         188 : }
     195             : 
     196             : // XEnumeration
     197             : 
     198        1565 : sal_Bool SAL_CALL ScIndexEnumeration::hasMoreElements() throw(uno::RuntimeException, std::exception)
     199             : {
     200        1565 :     SolarMutexGuard aGuard;
     201        1565 :     return ( nPos < xIndex->getCount() );
     202             : }
     203             : 
     204        1614 : uno::Any SAL_CALL ScIndexEnumeration::nextElement() throw(container::NoSuchElementException,
     205             :                                         lang::WrappedTargetException, uno::RuntimeException, std::exception)
     206             : {
     207        1614 :     SolarMutexGuard aGuard;
     208        1614 :     uno::Any aReturn;
     209             :     try
     210             :     {
     211        1614 :         aReturn = xIndex->getByIndex(nPos++);
     212             :     }
     213          21 :     catch (lang::IndexOutOfBoundsException&)
     214             :     {
     215          21 :         throw container::NoSuchElementException();
     216             :     }
     217        1614 :     return aReturn;
     218             : }
     219             : 
     220          19 : OUString SAL_CALL ScIndexEnumeration::getImplementationName()
     221             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     222             : {
     223          19 :     return OUString("ScIndexEnumeration");
     224             : }
     225             : 
     226           0 : sal_Bool SAL_CALL ScIndexEnumeration::supportsService( const OUString& ServiceName )
     227             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     228             : {
     229           0 :     return cppu::supportsService(this, ServiceName);
     230             : }
     231             : 
     232             : ::com::sun::star::uno::Sequence< OUString >
     233           0 :     SAL_CALL ScIndexEnumeration::getSupportedServiceNames(void)
     234             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     235             : {
     236           0 :     ::com::sun::star::uno::Sequence< OUString > aRet(1);
     237           0 :     OUString* pArray = aRet.getArray();
     238           0 :     pArray[0] = sServiceName;
     239           0 :     return aRet;
     240             : }
     241             : 
     242             : 
     243             : 
     244        2380 : ScNameToIndexAccess::ScNameToIndexAccess( const com::sun::star::uno::Reference<
     245             :                                             com::sun::star::container::XNameAccess>& rNameObj ) :
     246        2380 :     xNameAccess( rNameObj )
     247             : {
     248             :     //! test for XIndexAccess interface at rNameObj, use that instead!
     249             : 
     250        2380 :     if ( xNameAccess.is() )
     251        2380 :         aNames = xNameAccess->getElementNames();
     252        2380 : }
     253             : 
     254        4760 : ScNameToIndexAccess::~ScNameToIndexAccess()
     255             : {
     256        4760 : }
     257             : 
     258             : // XIndexAccess
     259             : 
     260        2268 : sal_Int32 SAL_CALL ScNameToIndexAccess::getCount(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     261             : {
     262        2268 :     return aNames.getLength();
     263             : }
     264             : 
     265        6398 : ::com::sun::star::uno::Any SAL_CALL ScNameToIndexAccess::getByIndex( sal_Int32 nIndex )
     266             :                                 throw(::com::sun::star::lang::IndexOutOfBoundsException,
     267             :                                         ::com::sun::star::lang::WrappedTargetException,
     268             :                                         ::com::sun::star::uno::RuntimeException, std::exception)
     269             : {
     270        6398 :     if ( xNameAccess.is() && nIndex >= 0 && nIndex < aNames.getLength() )
     271       12796 :         return xNameAccess->getByName( aNames.getConstArray()[nIndex] );
     272             : 
     273           0 :     throw lang::IndexOutOfBoundsException();
     274             : }
     275             : 
     276             : // XElementAccess
     277             : 
     278           0 : ::com::sun::star::uno::Type SAL_CALL ScNameToIndexAccess::getElementType(  )
     279             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception)
     280             : {
     281           0 :     if ( xNameAccess.is() )
     282           0 :         return xNameAccess->getElementType();
     283             :     else
     284           0 :         return uno::Type();
     285             : }
     286             : 
     287           0 : sal_Bool SAL_CALL ScNameToIndexAccess::hasElements(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     288             : {
     289           0 :     return getCount() > 0;
     290             : }
     291             : 
     292             : 
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10