LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - miscuno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 85 108 78.7 %
Date: 2012-08-25 Functions: 22 29 75.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 46 112 41.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <vcl/svapp.hxx>
      30                 :            : 
      31                 :            : #include "miscuno.hxx"
      32                 :            : 
      33                 :            : using namespace com::sun::star;
      34                 :            : using ::com::sun::star::uno::Reference;
      35                 :            : using ::com::sun::star::uno::Any;
      36                 :            : using ::rtl::OUString;
      37                 :            : 
      38                 :            : //------------------------------------------------------------------------
      39                 :            : 
      40         [ #  # ]:          0 : SC_SIMPLE_SERVICE_INFO( ScNameToIndexAccess, "ScNameToIndexAccess", "stardiv.unknown" )
      41                 :            : 
      42                 :            : //------------------------------------------------------------------------
      43                 :            : 
      44                 :       8714 : uno::Reference<uno::XInterface> ScUnoHelpFunctions::AnyToInterface( const uno::Any& rAny )
      45                 :            : {
      46         [ +  - ]:       8714 :     if ( rAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
      47                 :            :     {
      48                 :       8714 :         return uno::Reference<uno::XInterface>(rAny, uno::UNO_QUERY);
      49                 :            :     }
      50                 :       8714 :     return uno::Reference<uno::XInterface>();   //! Exception?
      51                 :            : }
      52                 :            : 
      53                 :       5712 : sal_Bool ScUnoHelpFunctions::GetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp,
      54                 :            :                                             const rtl::OUString& rName, sal_Bool bDefault )
      55                 :            : {
      56                 :       5712 :     sal_Bool bRet = bDefault;
      57         [ +  - ]:       5712 :     if ( xProp.is() )
      58                 :            :     {
      59                 :            :         try
      60                 :            :         {
      61 [ +  - ][ +  - ]:       5712 :             uno::Any aAny(xProp->getPropertyValue( rName ));
      62                 :            :             //! type conversion???
      63                 :            :             //  operator >>= shouldn't be used for bool (?)
      64         [ +  - ]:       5712 :             if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
      65                 :            :             {
      66                 :            :                 //! safe way to get bool value from any???
      67                 :       5712 :                 bRet = *(sal_Bool*)aAny.getValue();
      68                 :       5712 :             }
      69                 :            :         }
      70                 :          0 :         catch(uno::Exception&)
      71                 :            :         {
      72                 :            :             // keep default
      73                 :            :         }
      74                 :            :     }
      75         [ #  # ]:       5712 :     return bRet;
      76                 :            : }
      77                 :            : 
      78                 :       2140 : sal_Int32 ScUnoHelpFunctions::GetLongProperty( const uno::Reference<beans::XPropertySet>& xProp,
      79                 :            :                                             const rtl::OUString& rName, long nDefault )
      80                 :            : {
      81                 :       2140 :     sal_Int32 nRet = nDefault;
      82         [ +  - ]:       2140 :     if ( xProp.is() )
      83                 :            :     {
      84                 :            :         try
      85                 :            :         {
      86                 :            :             //! type conversion???
      87 [ +  - ][ +  - ]:       2140 :             xProp->getPropertyValue( rName ) >>= nRet;
      88                 :            :         }
      89         [ #  # ]:          0 :         catch(uno::Exception&)
      90                 :            :         {
      91                 :            :             // keep default
      92                 :            :         }
      93                 :            :     }
      94         [ #  # ]:       2140 :     return nRet;
      95                 :            : }
      96                 :            : 
      97                 :       4350 : sal_Int32 ScUnoHelpFunctions::GetEnumProperty( const uno::Reference<beans::XPropertySet>& xProp,
      98                 :            :                                             const rtl::OUString& rName, long nDefault )
      99                 :            : {
     100                 :       4350 :     sal_Int32 nRet = nDefault;
     101         [ +  - ]:       4350 :     if ( xProp.is() )
     102                 :            :     {
     103                 :            :         try
     104                 :            :         {
     105 [ +  - ][ +  - ]:       4350 :             uno::Any aAny(xProp->getPropertyValue( rName ));
     106                 :            : 
     107         [ +  - ]:       4350 :             if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
     108                 :            :             {
     109                 :            :                 //! get enum value from any???
     110                 :       4350 :                 nRet = *(sal_Int32*)aAny.getValue();
     111                 :            :             }
     112                 :            :             else
     113                 :            :             {
     114                 :            :                 //! type conversion???
     115                 :          0 :                 aAny >>= nRet;
     116                 :       4350 :             }
     117                 :            :         }
     118         [ #  # ]:          0 :         catch(uno::Exception&)
     119                 :            :         {
     120                 :            :             // keep default
     121                 :            :         }
     122                 :            :     }
     123         [ #  # ]:       4350 :     return nRet;
     124                 :            : }
     125                 :            : 
     126                 :        661 : OUString ScUnoHelpFunctions::GetStringProperty(
     127                 :            :     const Reference<beans::XPropertySet>& xProp, const OUString& rName, const OUString& rDefault )
     128                 :            : {
     129                 :        661 :     OUString aRet = rDefault;
     130         [ -  + ]:        661 :     if (!xProp.is())
     131                 :          0 :         return aRet;
     132                 :            : 
     133                 :            :     try
     134                 :            :     {
     135 [ +  - ][ +  - ]:        661 :         Any any = xProp->getPropertyValue(rName);
     136                 :        661 :         any >>= aRet;
     137                 :            :     }
     138         [ #  # ]:          0 :     catch (const uno::Exception&)
     139                 :            :     {
     140                 :            :     }
     141                 :            : 
     142         [ #  # ]:        661 :     return aRet;
     143                 :            : }
     144                 :            : 
     145                 :       8117 : sal_Bool ScUnoHelpFunctions::GetBoolFromAny( const uno::Any& aAny )
     146                 :            : {
     147         [ +  + ]:       8117 :     if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
     148                 :       8115 :         return *(sal_Bool*)aAny.getValue();
     149                 :       8117 :     return false;
     150                 :            : }
     151                 :            : 
     152                 :        216 : sal_Int16 ScUnoHelpFunctions::GetInt16FromAny( const uno::Any& aAny )
     153                 :            : {
     154                 :        216 :     sal_Int16 nRet = 0;
     155         [ +  - ]:        216 :     if ( aAny >>= nRet )
     156                 :        216 :         return nRet;
     157                 :        216 :     return 0;
     158                 :            : }
     159                 :            : 
     160                 :       1300 : sal_Int32 ScUnoHelpFunctions::GetInt32FromAny( const uno::Any& aAny )
     161                 :            : {
     162                 :       1300 :     sal_Int32 nRet = 0;
     163         [ +  - ]:       1300 :     if ( aAny >>= nRet )
     164                 :       1300 :         return nRet;
     165                 :       1300 :     return 0;
     166                 :            : }
     167                 :            : 
     168                 :        170 : sal_Int32 ScUnoHelpFunctions::GetEnumFromAny( const uno::Any& aAny )
     169                 :            : {
     170                 :        170 :     sal_Int32 nRet = 0;
     171         [ +  - ]:        170 :     if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
     172                 :        170 :         nRet = *(sal_Int32*)aAny.getValue();
     173                 :            :     else
     174                 :          0 :         aAny >>= nRet;
     175                 :        170 :     return nRet;
     176                 :            : }
     177                 :            : 
     178                 :       3438 : void ScUnoHelpFunctions::SetBoolInAny( uno::Any& rAny, sal_Bool bValue )
     179                 :            : {
     180                 :       3438 :     rAny.setValue( &bValue, getBooleanCppuType() );
     181                 :       3438 : }
     182                 :            : 
     183                 :       1645 : void ScUnoHelpFunctions::SetOptionalPropertyValue(
     184                 :            :     Reference<beans::XPropertySet>& rPropSet, const sal_Char* pPropName, const Any& rVal )
     185                 :            : {
     186                 :            :     try
     187                 :            :     {
     188 [ +  - ][ +  - ]:       1645 :         rPropSet->setPropertyValue(OUString::createFromAscii(pPropName), rVal);
                 [ #  # ]
     189                 :            :     }
     190                 :          0 :     catch (const beans::UnknownPropertyException&)
     191                 :            :     {
     192                 :            :         // ignored - not supported.
     193                 :            :     }
     194                 :       1645 : }
     195                 :            : 
     196                 :            : //------------------------------------------------------------------------
     197                 :            : 
     198                 :         50 : ScIndexEnumeration::ScIndexEnumeration(const uno::Reference<container::XIndexAccess>& rInd,
     199                 :            :                                        const rtl::OUString& rServiceName) :
     200                 :            :     xIndex( rInd ),
     201                 :            :     sServiceName(rServiceName),
     202                 :         50 :     nPos( 0 )
     203                 :            : {
     204                 :         50 : }
     205                 :            : 
     206                 :         50 : ScIndexEnumeration::~ScIndexEnumeration()
     207                 :            : {
     208         [ -  + ]:        100 : }
     209                 :            : 
     210                 :            : // XEnumeration
     211                 :            : 
     212                 :       1493 : sal_Bool SAL_CALL ScIndexEnumeration::hasMoreElements() throw(uno::RuntimeException)
     213                 :            : {
     214         [ +  - ]:       1493 :     SolarMutexGuard aGuard;
     215 [ +  - ][ +  - ]:       1493 :     return ( nPos < xIndex->getCount() );
                 [ +  - ]
     216                 :            : }
     217                 :            : 
     218                 :       1490 : uno::Any SAL_CALL ScIndexEnumeration::nextElement() throw(container::NoSuchElementException,
     219                 :            :                                         lang::WrappedTargetException, uno::RuntimeException)
     220                 :            : {
     221         [ +  - ]:       1490 :     SolarMutexGuard aGuard;
     222                 :       1490 :     uno::Any aReturn;
     223                 :            :     try
     224                 :            :     {
     225 [ +  + ][ +  - ]:       1490 :         aReturn = xIndex->getByIndex(nPos++);
     226                 :            :     }
     227         [ -  + ]:         42 :     catch (lang::IndexOutOfBoundsException&)
     228                 :            :     {
     229         [ -  + ]:         21 :         throw container::NoSuchElementException();
     230                 :            :     }
     231         [ +  - ]:       1490 :     return aReturn;
     232                 :            : }
     233                 :            : 
     234                 :         19 : ::rtl::OUString SAL_CALL ScIndexEnumeration::getImplementationName()
     235                 :            :     throw(::com::sun::star::uno::RuntimeException)
     236                 :            : {
     237                 :         19 :     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScIndexEnumeration"));
     238                 :            : }
     239                 :            : 
     240                 :          0 : sal_Bool SAL_CALL ScIndexEnumeration::supportsService( const ::rtl::OUString& ServiceName )
     241                 :            :     throw(::com::sun::star::uno::RuntimeException)
     242                 :            : {
     243                 :          0 :     return sServiceName == ServiceName;
     244                 :            : }
     245                 :            : 
     246                 :            : ::com::sun::star::uno::Sequence< ::rtl::OUString >
     247                 :          0 :     SAL_CALL ScIndexEnumeration::getSupportedServiceNames(void)
     248                 :            :     throw(::com::sun::star::uno::RuntimeException)
     249                 :            : {
     250                 :          0 :     ::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1);
     251         [ #  # ]:          0 :     ::rtl::OUString* pArray = aRet.getArray();
     252                 :          0 :     pArray[0] = sServiceName;
     253                 :          0 :     return aRet;
     254                 :            : }
     255                 :            : 
     256                 :            : //------------------------------------------------------------------------
     257                 :            : 
     258                 :            : //------------------------------------------------------------------------
     259                 :            : 
     260                 :       3598 : ScNameToIndexAccess::ScNameToIndexAccess( const com::sun::star::uno::Reference<
     261                 :            :                                             com::sun::star::container::XNameAccess>& rNameObj ) :
     262         [ +  - ]:       3598 :     xNameAccess( rNameObj )
     263                 :            : {
     264                 :            :     //! test for XIndexAccess interface at rNameObj, use that instead!
     265                 :            : 
     266         [ +  - ]:       3598 :     if ( xNameAccess.is() )
     267 [ +  - ][ +  - ]:       3598 :         aNames = xNameAccess->getElementNames();
         [ +  - ][ +  - ]
     268                 :       3598 : }
     269                 :            : 
     270         [ +  - ]:       3598 : ScNameToIndexAccess::~ScNameToIndexAccess()
     271                 :            : {
     272         [ -  + ]:       7196 : }
     273                 :            : 
     274                 :            : // XIndexAccess
     275                 :            : 
     276                 :       3504 : sal_Int32 SAL_CALL ScNameToIndexAccess::getCount(  ) throw(::com::sun::star::uno::RuntimeException)
     277                 :            : {
     278                 :       3504 :     return aNames.getLength();
     279                 :            : }
     280                 :            : 
     281                 :       9703 : ::com::sun::star::uno::Any SAL_CALL ScNameToIndexAccess::getByIndex( sal_Int32 nIndex )
     282                 :            :                                 throw(::com::sun::star::lang::IndexOutOfBoundsException,
     283                 :            :                                         ::com::sun::star::lang::WrappedTargetException,
     284                 :            :                                         ::com::sun::star::uno::RuntimeException)
     285                 :            : {
     286 [ +  - ][ +  - ]:       9703 :     if ( xNameAccess.is() && nIndex >= 0 && nIndex < aNames.getLength() )
         [ +  - ][ +  - ]
     287                 :       9703 :         return xNameAccess->getByName( aNames.getConstArray()[nIndex] );
     288                 :            : 
     289         [ #  # ]:          0 :     throw lang::IndexOutOfBoundsException();
     290                 :            : }
     291                 :            : 
     292                 :            : // XElementAccess
     293                 :            : 
     294                 :          0 : ::com::sun::star::uno::Type SAL_CALL ScNameToIndexAccess::getElementType(  )
     295                 :            :                                 throw(::com::sun::star::uno::RuntimeException)
     296                 :            : {
     297         [ #  # ]:          0 :     if ( xNameAccess.is() )
     298                 :          0 :         return xNameAccess->getElementType();
     299                 :            :     else
     300                 :          0 :         return uno::Type();
     301                 :            : }
     302                 :            : 
     303                 :          0 : sal_Bool SAL_CALL ScNameToIndexAccess::hasElements(  ) throw(::com::sun::star::uno::RuntimeException)
     304                 :            : {
     305                 :          0 :     return getCount() > 0;
     306                 :            : }
     307                 :            : 
     308                 :            : //------------------------------------------------------------------------
     309                 :            : 
     310                 :            : 
     311                 :            : 
     312                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10