LCOV - code coverage report
Current view: top level - libreoffice/toolkit/source/helper - unopropertyarrayhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 68 75.0 %
Date: 2012-12-27 Functions: 6 9 66.7 %
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             : 
      21             : #include <toolkit/helper/unopropertyarrayhelper.hxx>
      22             : #include <toolkit/helper/property.hxx>
      23             : #include <map>
      24             : 
      25             : //  ----------------------------------------------------
      26             : //  class UnoPropertyArrayHelper
      27             : //  ----------------------------------------------------
      28             : 
      29           7 : UnoPropertyArrayHelper::UnoPropertyArrayHelper( const ::com::sun::star::uno::Sequence<sal_Int32>& rIDs )
      30             : {
      31           7 :     sal_Int32 nIDs = rIDs.getLength();
      32           7 :     const sal_Int32* pIDs = rIDs.getConstArray();
      33         131 :     for ( sal_Int32 n = 0; n < nIDs; n++ )
      34         124 :         maIDs.insert( pIDs[n] );
      35           7 : }
      36             : 
      37           0 : UnoPropertyArrayHelper::UnoPropertyArrayHelper( const std::list< sal_uInt16 > &rIDs )
      38             : {
      39           0 :     std::list< sal_uInt16 >::const_iterator iter;
      40           0 :     for( iter = rIDs.begin(); iter != rIDs.end(); ++iter)
      41           0 :       maIDs.insert( *iter );
      42           0 : }
      43             : 
      44         398 : sal_Bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId ) const
      45             : {
      46         398 :     if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
      47          64 :         nPropId = BASEPROPERTY_FONTDESCRIPTOR;
      48             : 
      49         398 :     return maIDs.find( nPropId ) != maIDs.end() ? sal_True : sal_False;
      50             : }
      51             : 
      52             : // ::cppu::IPropertyArrayHelper
      53         293 : sal_Bool UnoPropertyArrayHelper::fillPropertyMembersByHandle( ::rtl::OUString * pPropName, sal_Int16 * pAttributes, sal_Int32 nPropId )
      54             : {
      55         293 :     sal_uInt16 id = sal::static_int_cast< sal_uInt16 >(nPropId);
      56         293 :     sal_Bool bValid = ImplHasProperty( id );
      57         293 :     if ( bValid )
      58             :     {
      59         293 :         if ( pPropName )
      60         128 :             *pPropName = GetPropertyName( id );
      61         293 :         if ( pAttributes )
      62         250 :             *pAttributes = GetPropertyAttribs( id );
      63             :     }
      64         293 :     return bValid;
      65             : }
      66             : 
      67           7 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > UnoPropertyArrayHelper::getProperties()
      68             : {
      69             :     // Sortiert nach Namen...
      70             : 
      71           7 :     std::map<sal_Int32, sal_uInt16> aSortedPropsIds;
      72         131 :     for( std::set<sal_Int32>::const_iterator it =  maIDs.begin(); it != maIDs.end(); ++it)
      73             :     {
      74         124 :         sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >(*it);
      75         124 :         aSortedPropsIds[ 1+GetPropertyOrderNr( nId ) ] = nId;
      76             : 
      77         124 :         if ( nId == BASEPROPERTY_FONTDESCRIPTOR )
      78             :         {
      79             :             // Einzelproperties...
      80          68 :             for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= BASEPROPERTY_FONTDESCRIPTORPART_END; i++ )
      81          64 :                 aSortedPropsIds[ 1+GetPropertyOrderNr( i ) ]  = i;
      82             :         }
      83             :     }
      84             : 
      85           7 :     sal_uInt32 nProps = aSortedPropsIds.size();   // koennen jetzt mehr sein
      86           7 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps( nProps );
      87           7 :     ::com::sun::star::beans::Property* pProps = aProps.getArray();
      88             : 
      89           7 :     std::map<sal_Int32, sal_uInt16>::const_iterator it = aSortedPropsIds.begin();
      90         195 :     for ( sal_uInt32 n = 0; n < nProps; n++, ++it )
      91             :     {
      92         188 :         sal_uInt16 nId = it->second;
      93         188 :         pProps[n].Name = GetPropertyName( nId );
      94         188 :         pProps[n].Handle = nId;
      95         188 :         pProps[n].Type = *GetPropertyType( nId );
      96         188 :         pProps[n].Attributes = GetPropertyAttribs( nId );
      97             :     }
      98             : 
      99           7 :     return aProps;
     100             : }
     101             : 
     102           0 : ::com::sun::star::beans::Property UnoPropertyArrayHelper::getPropertyByName(const ::rtl::OUString& rPropertyName) throw (::com::sun::star::beans::UnknownPropertyException)
     103             : {
     104           0 :     ::com::sun::star::beans::Property aProp;
     105           0 :     sal_uInt16 nId = GetPropertyId( rPropertyName );
     106           0 :     if ( ImplHasProperty( nId ) )
     107             :     {
     108           0 :         aProp.Name = rPropertyName;
     109           0 :         aProp.Handle = -1;
     110           0 :         aProp.Type = *GetPropertyType( nId );
     111           0 :         aProp.Attributes = GetPropertyAttribs( nId );
     112             :     }
     113             : 
     114           0 :     return aProp;
     115             : }
     116             : 
     117           0 : sal_Bool UnoPropertyArrayHelper::hasPropertyByName(const ::rtl::OUString& rPropertyName)
     118             : {
     119           0 :     return ImplHasProperty( GetPropertyId( rPropertyName ) );
     120             : }
     121             : 
     122          12 : sal_Int32 UnoPropertyArrayHelper::getHandleByName( const ::rtl::OUString & rPropertyName )
     123             : {
     124          12 :     sal_Int32 nId = (sal_Int32 ) GetPropertyId( rPropertyName );
     125          12 :     return nId ? nId : (-1);
     126             : }
     127             : 
     128           9 : sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rPropNames )
     129             : {
     130           9 :     const ::rtl::OUString* pNames = rPropNames.getConstArray();
     131           9 :     sal_Int32 nValues = rPropNames.getLength();
     132           9 :     sal_Int32 nValidHandles = 0;
     133             : 
     134         114 :     for ( sal_Int32 n = 0; n < nValues; n++ )
     135             :     {
     136         105 :         sal_uInt16 nPropId = GetPropertyId( pNames[n] );
     137         105 :         if ( nPropId && ImplHasProperty( nPropId ) )
     138             :         {
     139         105 :             pHandles[n] = nPropId;
     140         105 :             nValidHandles++;
     141             :         }
     142             :         else
     143             :         {
     144           0 :             pHandles[n] = -1;
     145             :         }
     146             :     }
     147           9 :     return nValidHandles;
     148             : }
     149             : 
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10