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

Generated by: LCOV version 1.10