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

Generated by: LCOV version 1.10