LCOV - code coverage report
Current view: top level - svx/source/items - customshapeitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 99 150 66.0 %
Date: 2012-08-25 Functions: 23 30 76.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 69 214 32.2 %

           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 <svx/sdasitm.hxx>
      30                 :            : #include <svx/svdattr.hxx>
      31                 :            : 
      32                 :            : using namespace ::std;
      33                 :            : using namespace com::sun::star;
      34                 :            : 
      35                 :       3512 : SdrCustomShapeEngineItem::SdrCustomShapeEngineItem()
      36         [ +  - ]:       3512 : :   SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE, String() )
      37                 :       3512 : {}
      38                 :            : 
      39                 :       3512 : SdrCustomShapeDataItem::SdrCustomShapeDataItem()
      40         [ +  - ]:       3512 : :   SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA, String() )
      41                 :       3512 : {}
      42                 :            : 
      43                 :       9573 : bool SdrCustomShapeGeometryItem::PropertyEq::operator()( const rtl::OUString& r1, const rtl::OUString& r2 ) const
      44                 :            : {
      45                 :       9573 :     return r1.equals( r2 );
      46                 :            : }
      47                 :       1263 : bool SdrCustomShapeGeometryItem::PropertyPairEq::operator()( const SdrCustomShapeGeometryItem::PropertyPair& r1, const SdrCustomShapeGeometryItem::PropertyPair& r2 ) const
      48                 :            : {
      49 [ +  - ][ +  - ]:       1263 :     return ( r1.first.equals( r2.first ) ) && ( r1.second.equals( r2.second ) );
      50                 :            : }
      51                 :       8427 : size_t SdrCustomShapeGeometryItem::PropertyPairHash::operator()( const SdrCustomShapeGeometryItem::PropertyPair &r1 ) const
      52                 :            : {
      53                 :       8427 :     return (size_t)r1.first.hashCode() + r1.second.hashCode();
      54                 :            : };
      55                 :            : 
      56 [ -  + ][ -  + ]:      49781 : TYPEINIT1_FACTORY( SdrCustomShapeGeometryItem, SfxPoolItem , new  SdrCustomShapeGeometryItem);
                 [ #  # ]
      57                 :       3512 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem()
      58 [ +  - ][ +  - ]:       3512 : :   SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
                 [ +  - ]
      59                 :       3512 : {}
      60                 :       3256 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( const uno::Sequence< beans::PropertyValue >& rVal )
      61 [ +  - ][ +  - ]:       3256 : :   SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
                 [ +  - ]
      62                 :            : {
      63                 :            :     sal_Int32 i, j;
      64         [ +  - ]:       3256 :     aPropSeq = rVal;
      65                 :            : 
      66         [ +  + ]:       8474 :     for ( i = 0; i < aPropSeq.getLength(); i++ )
      67                 :            :     {
      68         [ +  - ]:       5218 :         beans::PropertyValue& rPropVal = aPropSeq[ i ];
      69         [ +  - ]:       5218 :         aPropHashMap[ rPropVal.Name ] = i;
      70 [ +  - ][ +  + ]:       5218 :         if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
      71                 :            :         {
      72                 :        654 :             uno::Sequence< beans::PropertyValue >& rPropSeq = *( uno::Sequence< beans::PropertyValue >*)rPropVal.Value.getValue();
      73         [ +  + ]:       2061 :             for ( j = 0; j < rPropSeq.getLength(); j++ )
      74                 :            :             {
      75         [ +  - ]:       1407 :                 beans::PropertyValue& rPropVal2 = rPropSeq[ j ];
      76         [ +  - ]:       1407 :                 aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = j;
      77                 :            :             }
      78                 :            :         }
      79                 :            :     }
      80                 :       3256 : }
      81                 :            : 
      82                 :      18237 : com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const rtl::OUString& rPropName )
      83                 :            : {
      84                 :      18237 :     com::sun::star::uno::Any* pRet = NULL;
      85         [ +  - ]:      18237 :     PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
      86 [ +  - ][ +  + ]:      18237 :     if ( aHashIter != aPropHashMap.end() )
      87 [ +  - ][ +  - ]:       9573 :         pRet = &aPropSeq[ (*aHashIter).second ].Value;
      88                 :      18237 :     return pRet;
      89                 :            : }
      90                 :            : 
      91                 :       7572 : com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const rtl::OUString& rSequenceName, const rtl::OUString& rPropName )
      92                 :            : {
      93                 :       7572 :     com::sun::star::uno::Any* pRet = NULL;
      94                 :       7572 :     com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
      95         [ +  + ]:       7572 :     if ( pSeqAny )
      96                 :            :     {
      97         [ +  - ]:       6363 :         if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
      98                 :            :         {
      99         [ +  - ]:       6363 :             PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropName ) ) );
     100 [ +  + ][ +  - ]:       6363 :             if ( aHashIter != aPropPairHashMap.end() )
     101                 :            :             {
     102                 :            :                 ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
     103                 :       1263 :                     *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
     104 [ +  - ][ +  - ]:       6363 :                 pRet = &rSecSequence[ (*aHashIter).second ].Value;
     105                 :            :             }
     106                 :            :         }
     107                 :            :     }
     108                 :       7572 :     return pRet;
     109                 :            : }
     110                 :            : 
     111                 :       1203 : void SdrCustomShapeGeometryItem::SetPropertyValue( const com::sun::star::beans::PropertyValue& rPropVal )
     112                 :            : {
     113                 :       1203 :     com::sun::star::uno::Any* pAny = GetPropertyValueByName( rPropVal.Name );
     114         [ +  + ]:       1203 :     if ( pAny )
     115                 :            :     {   // property is already available
     116                 :            :         sal_Int32 i;
     117         [ -  + ]:        180 :         if ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
     118                 :            :         {   // old property is a sequence->each entry has to be removed from the HashPairMap
     119                 :            :             ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
     120                 :          0 :                 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
     121         [ #  # ]:          0 :             for ( i = 0; i < rSecSequence.getLength(); i++ )
     122                 :            :             {
     123 [ #  # ][ #  # ]:          0 :                 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rPropVal.Name, rSecSequence[ i ].Name ) ) );
     124 [ #  # ][ #  # ]:          0 :                 if ( aHashIter != aPropPairHashMap.end() )
     125         [ #  # ]:          0 :                     aPropPairHashMap.erase( aHashIter );
     126                 :            :             }
     127                 :            :         }
     128                 :        180 :         *pAny = rPropVal.Value;
     129         [ -  + ]:        180 :         if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
     130                 :            :         {   // the new property is a sequence->each entry has to be inserted into the HashPairMap
     131                 :            :             ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
     132                 :          0 :                 *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
     133         [ #  # ]:          0 :             for ( i = 0; i < rSecSequence.getLength(); i++ )
     134                 :            :             {
     135                 :          0 :                 beans::PropertyValue& rPropVal2 = rSecSequence[ i ];
     136         [ #  # ]:          0 :                 aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = i;
     137                 :            :             }
     138                 :            :         }
     139                 :            :     }
     140                 :            :     else
     141                 :            :     {   // its a new property
     142                 :       1023 :         sal_uInt32 nIndex = aPropSeq.getLength();
     143                 :       1023 :         aPropSeq.realloc( nIndex + 1 );
     144                 :       1023 :         aPropSeq[ nIndex ] = rPropVal ;
     145                 :            : 
     146                 :       1023 :         aPropHashMap[ rPropVal.Name ] = nIndex;
     147                 :            :     }
     148                 :       1203 : }
     149                 :            : 
     150                 :        549 : void SdrCustomShapeGeometryItem::SetPropertyValue( const rtl::OUString& rSequenceName, const com::sun::star::beans::PropertyValue& rPropVal )
     151                 :            : {
     152                 :        549 :     com::sun::star::uno::Any* pAny = GetPropertyValueByName( rSequenceName, rPropVal.Name );
     153         [ -  + ]:        549 :     if ( pAny ) // just replacing
     154                 :          0 :         *pAny = rPropVal.Value;
     155                 :            :     else
     156                 :            :     {
     157                 :        549 :         com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
     158         [ +  + ]:        549 :         if( pSeqAny == NULL )
     159                 :            :         {
     160         [ +  - ]:        441 :             ::com::sun::star::uno::Sequence < beans::PropertyValue > aSeq;
     161                 :        441 :             beans::PropertyValue aValue;
     162                 :        441 :             aValue.Name = rSequenceName;
     163         [ +  - ]:        441 :             aValue.Value = ::com::sun::star::uno::makeAny( aSeq );
     164                 :            : 
     165                 :        441 :             sal_uInt32 nIndex = aPropSeq.getLength();
     166         [ +  - ]:        441 :             aPropSeq.realloc( nIndex + 1 );
     167         [ +  - ]:        441 :             aPropSeq[ nIndex ] = aValue;
     168         [ +  - ]:        441 :             aPropHashMap[ rSequenceName ] = nIndex;
     169                 :            : 
     170 [ +  - ][ +  - ]:        441 :             pSeqAny = &aPropSeq[ nIndex ].Value;
     171                 :            :         }
     172                 :            : 
     173                 :            :         DBG_ASSERT( pSeqAny, "SdrCustomShapeGeometryItem::SetPropertyValue() - No Value??" );
     174                 :            : 
     175         [ +  - ]:        549 :         if( pSeqAny )
     176                 :            :         {
     177         [ +  - ]:        549 :             if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
     178                 :            :             {
     179         [ +  - ]:        549 :                 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropVal.Name ) ) );
     180 [ -  + ][ +  - ]:        549 :                 if ( aHashIter != aPropPairHashMap.end() )
     181                 :            :                 {
     182                 :            :                     ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
     183                 :          0 :                         *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
     184 [ #  # ][ #  # ]:          0 :                     rSecSequence[ (*aHashIter).second ].Value = rPropVal.Value;
     185                 :            :                 }
     186                 :            :                 else
     187                 :            :                 {
     188                 :            :                     ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
     189                 :        549 :                         *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
     190                 :            : 
     191                 :        549 :                     sal_Int32 nCount = rSecSequence.getLength();
     192         [ +  - ]:        549 :                     rSecSequence.realloc( nCount + 1 );
     193         [ +  - ]:        549 :                     rSecSequence[ nCount ] = rPropVal;
     194                 :            : 
     195         [ +  - ]:        549 :                     aPropPairHashMap[ PropertyPair( rSequenceName, rPropVal.Name ) ] = nCount;
     196                 :            :                 }
     197                 :            :             }
     198                 :            :         }
     199                 :            :     }
     200                 :        549 : }
     201                 :            : 
     202                 :          0 : void SdrCustomShapeGeometryItem::ClearPropertyValue( const rtl::OUString& rPropName )
     203                 :            : {
     204         [ #  # ]:          0 :     if ( aPropSeq.getLength() )
     205                 :            :     {
     206         [ #  # ]:          0 :         PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
     207 [ #  # ][ #  # ]:          0 :         if ( aHashIter != aPropHashMap.end() )
     208                 :            :         {
     209 [ #  # ][ #  # ]:          0 :              com::sun::star::uno::Any* pSeqAny = &aPropSeq[ (*aHashIter).second ].Value;
     210         [ #  # ]:          0 :             if ( pSeqAny )
     211                 :            :             {
     212 [ #  # ][ #  # ]:          0 :                 if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
     213                 :            :                 {
     214                 :            :                     ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
     215                 :          0 :                         *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
     216                 :            : 
     217                 :            :                     sal_Int32 i;
     218         [ #  # ]:          0 :                     for ( i = 0; i < rSecSequence.getLength(); i++ )
     219                 :            :                     {
     220 [ #  # ][ #  # ]:          0 :                         PropertyPairHashMap::iterator _aHashIter( aPropPairHashMap.find( PropertyPair( rPropName, rSecSequence[ i ].Name ) ) );
     221 [ #  # ][ #  # ]:          0 :                         if ( _aHashIter != aPropPairHashMap.end() )
     222         [ #  # ]:          0 :                             aPropPairHashMap.erase( _aHashIter );       // removing property from pair hashmap
     223                 :            :                     }
     224                 :            :                 }
     225                 :            :             }
     226                 :          0 :             sal_Int32 nLength = aPropSeq.getLength();
     227         [ #  # ]:          0 :             if ( nLength )
     228                 :            :             {
     229         [ #  # ]:          0 :                 sal_Int32 nIndex  = (*aHashIter).second;
     230         [ #  # ]:          0 :                 if ( nIndex != ( nLength - 1 ) )                        // resizing sequence
     231                 :            :                 {
     232 [ #  # ][ #  # ]:          0 :                     PropertyHashMap::iterator aHashIter2( aPropHashMap.find( aPropSeq[ nLength - 1 ].Name ) );
     233         [ #  # ]:          0 :                     (*aHashIter2).second = nIndex;
     234 [ #  # ][ #  # ]:          0 :                     aPropSeq[ (*aHashIter).second ] = aPropSeq[ aPropSeq.getLength() - 1 ];
                 [ #  # ]
     235                 :            :                 }
     236         [ #  # ]:          0 :                 aPropSeq.realloc( aPropSeq.getLength() - 1 );
     237                 :            :             }
     238         [ #  # ]:          0 :             aPropHashMap.erase( aHashIter );                            // removing property from hashmap
     239                 :            :         }
     240                 :            :     }
     241                 :          0 : }
     242                 :            : 
     243 [ +  - ][ +  - ]:       9858 : SdrCustomShapeGeometryItem::~SdrCustomShapeGeometryItem()
                 [ +  - ]
     244                 :            : {
     245         [ -  + ]:      15400 : }
     246                 :          0 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( SvStream& /*rIn*/, sal_uInt16 nVersion ):
     247 [ #  # ][ #  # ]:          0 :     SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
                 [ #  # ]
     248                 :            : {
     249                 :            :     if ( nVersion )
     250                 :            :     {
     251                 :            : 
     252                 :            :     }
     253                 :          0 : }
     254                 :      18762 : int SdrCustomShapeGeometryItem::operator==( const SfxPoolItem& rCmp ) const
     255                 :            : {
     256                 :      18762 :     int bRet = SfxPoolItem::operator==( rCmp );
     257         [ +  - ]:      18762 :     if ( bRet )
     258                 :      18762 :         bRet = ((SdrCustomShapeGeometryItem&)rCmp).aPropSeq == aPropSeq;
     259                 :      18762 :     return bRet;
     260                 :            : }
     261                 :            : 
     262                 :          0 : SfxItemPresentation SdrCustomShapeGeometryItem::GetPresentation(
     263                 :            :     SfxItemPresentation ePresentation, SfxMapUnit /*eCoreMetric*/,
     264                 :            :     SfxMapUnit /*ePresentationMetric*/, XubString &rText, const IntlWrapper *) const
     265                 :            : {
     266                 :          0 :     rText += sal_Unicode( ' ' );
     267         [ #  # ]:          0 :     if ( ePresentation == SFX_ITEM_PRESENTATION_COMPLETE )
     268                 :            :     {
     269         [ #  # ]:          0 :         XubString aStr;
     270         [ #  # ]:          0 :         aStr += sal_Unicode( ' ' );
     271 [ #  # ][ #  # ]:          0 :         rText.Insert( aStr, 0 );
     272                 :            :     }
     273                 :          0 :     return ePresentation;
     274                 :            : }
     275                 :            : 
     276                 :          0 : SfxPoolItem* SdrCustomShapeGeometryItem::Create( SvStream& rIn, sal_uInt16 nItemVersion ) const
     277                 :            : {
     278         [ #  # ]:          0 :     return new SdrCustomShapeGeometryItem( rIn, nItemVersion );
     279                 :            : }
     280                 :            : 
     281                 :          0 : SvStream& SdrCustomShapeGeometryItem::Store( SvStream& rOut, sal_uInt16 nItemVersion ) const
     282                 :            : {
     283                 :            :     if ( nItemVersion )
     284                 :            :     {
     285                 :            : 
     286                 :            :     }
     287                 :          0 :     return rOut;
     288                 :            : }
     289                 :            : 
     290                 :       2234 : SfxPoolItem* SdrCustomShapeGeometryItem::Clone( SfxItemPool * /*pPool*/ ) const
     291                 :            : {
     292         [ +  - ]:       2234 :     return new SdrCustomShapeGeometryItem( GetGeometry() );
     293                 :            : }
     294                 :            : 
     295                 :          0 : sal_uInt16 SdrCustomShapeGeometryItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
     296                 :            : {
     297                 :          0 :     return 1;
     298                 :            : }
     299                 :        204 : bool SdrCustomShapeGeometryItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
     300                 :            : {
     301                 :        204 :     rVal <<= aPropSeq;
     302                 :        204 :     return true;
     303                 :            : }
     304                 :        219 : bool SdrCustomShapeGeometryItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
     305                 :            : {
     306         [ -  + ]:        219 :     if ( ! ( rVal >>= aPropSeq ) )
     307                 :          0 :         return false;
     308                 :            :     else
     309                 :        219 :         return true;
     310                 :            : }
     311                 :       2234 : const uno::Sequence< beans::PropertyValue >& SdrCustomShapeGeometryItem::GetGeometry() const
     312                 :            : {
     313                 :       2234 :     return aPropSeq;
     314                 :            : }
     315                 :            : 
     316                 :       3512 : SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem()
     317         [ +  - ]:       3512 : :   SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL, String() )
     318                 :       3512 : {}
     319                 :            : 
     320                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10