LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/unoobj - miscuno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 83 109 76.1 %
Date: 2013-07-09 Functions: 24 31 77.4 %
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 <vcl/svapp.hxx>
      21             : 
      22             : #include "miscuno.hxx"
      23             : 
      24             : using namespace com::sun::star;
      25             : using ::com::sun::star::uno::Reference;
      26             : using ::com::sun::star::uno::Any;
      27             : 
      28             : //------------------------------------------------------------------------
      29             : 
      30           0 : SC_SIMPLE_SERVICE_INFO( ScNameToIndexAccess, "ScNameToIndexAccess", "stardiv.unknown" )
      31             : 
      32             : //------------------------------------------------------------------------
      33             : 
      34        5316 : uno::Reference<uno::XInterface> ScUnoHelpFunctions::AnyToInterface( const uno::Any& rAny )
      35             : {
      36        5316 :     if ( rAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
      37             :     {
      38        5316 :         return uno::Reference<uno::XInterface>(rAny, uno::UNO_QUERY);
      39             :     }
      40           0 :     return uno::Reference<uno::XInterface>();   //! Exception?
      41             : }
      42             : 
      43        3939 : sal_Bool ScUnoHelpFunctions::GetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp,
      44             :                                             const OUString& rName, sal_Bool bDefault )
      45             : {
      46        3939 :     sal_Bool bRet = bDefault;
      47        3939 :     if ( xProp.is() )
      48             :     {
      49             :         try
      50             :         {
      51        3939 :             uno::Any aAny(xProp->getPropertyValue( rName ));
      52             :             //! type conversion???
      53             :             //  operator >>= shouldn't be used for bool (?)
      54        3939 :             if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
      55             :             {
      56             :                 //! safe way to get bool value from any???
      57        3939 :                 bRet = *(sal_Bool*)aAny.getValue();
      58        3939 :             }
      59             :         }
      60           0 :         catch(uno::Exception&)
      61             :         {
      62             :             // keep default
      63             :         }
      64             :     }
      65        3939 :     return bRet;
      66             : }
      67             : 
      68        1716 : sal_Int32 ScUnoHelpFunctions::GetLongProperty( const uno::Reference<beans::XPropertySet>& xProp,
      69             :                                             const OUString& rName, long nDefault )
      70             : {
      71        1716 :     sal_Int32 nRet = nDefault;
      72        1716 :     if ( xProp.is() )
      73             :     {
      74             :         try
      75             :         {
      76             :             //! type conversion???
      77        1716 :             xProp->getPropertyValue( rName ) >>= nRet;
      78             :         }
      79           0 :         catch(uno::Exception&)
      80             :         {
      81             :             // keep default
      82             :         }
      83             :     }
      84        1716 :     return nRet;
      85             : }
      86             : 
      87        2993 : sal_Int32 ScUnoHelpFunctions::GetEnumProperty( const uno::Reference<beans::XPropertySet>& xProp,
      88             :                                             const OUString& rName, long nDefault )
      89             : {
      90        2993 :     sal_Int32 nRet = nDefault;
      91        2993 :     if ( xProp.is() )
      92             :     {
      93             :         try
      94             :         {
      95        2993 :             uno::Any aAny(xProp->getPropertyValue( rName ));
      96             : 
      97        2993 :             if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
      98             :             {
      99             :                 //! get enum value from any???
     100        2993 :                 nRet = *(sal_Int32*)aAny.getValue();
     101             :             }
     102             :             else
     103             :             {
     104             :                 //! type conversion???
     105           0 :                 aAny >>= nRet;
     106        2993 :             }
     107             :         }
     108           0 :         catch(uno::Exception&)
     109             :         {
     110             :             // keep default
     111             :         }
     112             :     }
     113        2993 :     return nRet;
     114             : }
     115             : 
     116         445 : OUString ScUnoHelpFunctions::GetStringProperty(
     117             :     const Reference<beans::XPropertySet>& xProp, const OUString& rName, const OUString& rDefault )
     118             : {
     119         445 :     OUString aRet = rDefault;
     120         445 :     if (!xProp.is())
     121           0 :         return aRet;
     122             : 
     123             :     try
     124             :     {
     125         445 :         Any any = xProp->getPropertyValue(rName);
     126         445 :         any >>= aRet;
     127             :     }
     128           0 :     catch (const uno::Exception&)
     129             :     {
     130             :     }
     131             : 
     132         445 :     return aRet;
     133             : }
     134             : 
     135        6593 : sal_Bool ScUnoHelpFunctions::GetBoolFromAny( const uno::Any& aAny )
     136             : {
     137        6593 :     if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN )
     138        6591 :         return *(sal_Bool*)aAny.getValue();
     139           2 :     return false;
     140             : }
     141             : 
     142         180 : sal_Int16 ScUnoHelpFunctions::GetInt16FromAny( const uno::Any& aAny )
     143             : {
     144         180 :     sal_Int16 nRet = 0;
     145         180 :     if ( aAny >>= nRet )
     146         180 :         return nRet;
     147           0 :     return 0;
     148             : }
     149             : 
     150        1116 : sal_Int32 ScUnoHelpFunctions::GetInt32FromAny( const uno::Any& aAny )
     151             : {
     152        1116 :     sal_Int32 nRet = 0;
     153        1116 :     if ( aAny >>= nRet )
     154        1116 :         return nRet;
     155           0 :     return 0;
     156             : }
     157             : 
     158         124 : sal_Int32 ScUnoHelpFunctions::GetEnumFromAny( const uno::Any& aAny )
     159             : {
     160         124 :     sal_Int32 nRet = 0;
     161         124 :     if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM )
     162         124 :         nRet = *(sal_Int32*)aAny.getValue();
     163             :     else
     164           0 :         aAny >>= nRet;
     165         124 :     return nRet;
     166             : }
     167             : 
     168        3512 : void ScUnoHelpFunctions::SetBoolInAny( uno::Any& rAny, sal_Bool bValue )
     169             : {
     170        3512 :     rAny.setValue( &bValue, getBooleanCppuType() );
     171        3512 : }
     172             : 
     173         567 : void ScUnoHelpFunctions::SetOptionalPropertyValue(
     174             :     Reference<beans::XPropertySet>& rPropSet, const sal_Char* pPropName, const Any& rVal )
     175             : {
     176             :     try
     177             :     {
     178         567 :         rPropSet->setPropertyValue(OUString::createFromAscii(pPropName), rVal);
     179             :     }
     180           0 :     catch (const beans::UnknownPropertyException&)
     181             :     {
     182             :         // ignored - not supported.
     183             :     }
     184         567 : }
     185             : 
     186             : //------------------------------------------------------------------------
     187             : 
     188         103 : ScIndexEnumeration::ScIndexEnumeration(const uno::Reference<container::XIndexAccess>& rInd,
     189             :                                        const OUString& rServiceName) :
     190             :     xIndex( rInd ),
     191             :     sServiceName(rServiceName),
     192         103 :     nPos( 0 )
     193             : {
     194         103 : }
     195             : 
     196         206 : ScIndexEnumeration::~ScIndexEnumeration()
     197             : {
     198         206 : }
     199             : 
     200             : // XEnumeration
     201             : 
     202        1516 : sal_Bool SAL_CALL ScIndexEnumeration::hasMoreElements() throw(uno::RuntimeException)
     203             : {
     204        1516 :     SolarMutexGuard aGuard;
     205        1516 :     return ( nPos < xIndex->getCount() );
     206             : }
     207             : 
     208        1556 : uno::Any SAL_CALL ScIndexEnumeration::nextElement() throw(container::NoSuchElementException,
     209             :                                         lang::WrappedTargetException, uno::RuntimeException)
     210             : {
     211        1556 :     SolarMutexGuard aGuard;
     212        1556 :     uno::Any aReturn;
     213             :     try
     214             :     {
     215        1556 :         aReturn = xIndex->getByIndex(nPos++);
     216             :     }
     217          21 :     catch (lang::IndexOutOfBoundsException&)
     218             :     {
     219          21 :         throw container::NoSuchElementException();
     220             :     }
     221        1556 :     return aReturn;
     222             : }
     223             : 
     224          19 : OUString SAL_CALL ScIndexEnumeration::getImplementationName()
     225             :     throw(::com::sun::star::uno::RuntimeException)
     226             : {
     227          19 :     return OUString("ScIndexEnumeration");
     228             : }
     229             : 
     230           0 : sal_Bool SAL_CALL ScIndexEnumeration::supportsService( const OUString& ServiceName )
     231             :     throw(::com::sun::star::uno::RuntimeException)
     232             : {
     233           0 :     return sServiceName == ServiceName;
     234             : }
     235             : 
     236             : ::com::sun::star::uno::Sequence< OUString >
     237           0 :     SAL_CALL ScIndexEnumeration::getSupportedServiceNames(void)
     238             :     throw(::com::sun::star::uno::RuntimeException)
     239             : {
     240           0 :     ::com::sun::star::uno::Sequence< OUString > aRet(1);
     241           0 :     OUString* pArray = aRet.getArray();
     242           0 :     pArray[0] = sServiceName;
     243           0 :     return aRet;
     244             : }
     245             : 
     246             : //------------------------------------------------------------------------
     247             : 
     248             : //------------------------------------------------------------------------
     249             : 
     250        2227 : ScNameToIndexAccess::ScNameToIndexAccess( const com::sun::star::uno::Reference<
     251             :                                             com::sun::star::container::XNameAccess>& rNameObj ) :
     252        2227 :     xNameAccess( rNameObj )
     253             : {
     254             :     //! test for XIndexAccess interface at rNameObj, use that instead!
     255             : 
     256        2227 :     if ( xNameAccess.is() )
     257        2227 :         aNames = xNameAccess->getElementNames();
     258        2227 : }
     259             : 
     260        4454 : ScNameToIndexAccess::~ScNameToIndexAccess()
     261             : {
     262        4454 : }
     263             : 
     264             : // XIndexAccess
     265             : 
     266        2110 : sal_Int32 SAL_CALL ScNameToIndexAccess::getCount(  ) throw(::com::sun::star::uno::RuntimeException)
     267             : {
     268        2110 :     return aNames.getLength();
     269             : }
     270             : 
     271        6126 : ::com::sun::star::uno::Any SAL_CALL ScNameToIndexAccess::getByIndex( sal_Int32 nIndex )
     272             :                                 throw(::com::sun::star::lang::IndexOutOfBoundsException,
     273             :                                         ::com::sun::star::lang::WrappedTargetException,
     274             :                                         ::com::sun::star::uno::RuntimeException)
     275             : {
     276        6126 :     if ( xNameAccess.is() && nIndex >= 0 && nIndex < aNames.getLength() )
     277       12252 :         return xNameAccess->getByName( aNames.getConstArray()[nIndex] );
     278             : 
     279           0 :     throw lang::IndexOutOfBoundsException();
     280             : }
     281             : 
     282             : // XElementAccess
     283             : 
     284           0 : ::com::sun::star::uno::Type SAL_CALL ScNameToIndexAccess::getElementType(  )
     285             :                                 throw(::com::sun::star::uno::RuntimeException)
     286             : {
     287           0 :     if ( xNameAccess.is() )
     288           0 :         return xNameAccess->getElementType();
     289             :     else
     290           0 :         return uno::Type();
     291             : }
     292             : 
     293           0 : sal_Bool SAL_CALL ScNameToIndexAccess::hasElements(  ) throw(::com::sun::star::uno::RuntimeException)
     294             : {
     295           0 :     return getCount() > 0;
     296          93 : }
     297             : 
     298             : //------------------------------------------------------------------------
     299             : 
     300             : 
     301             : 
     302             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10