LCOV - code coverage report
Current view: top level - svx/source/items - customshapeitem.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 111 167 66.5 %
Date: 2015-06-13 12:38:46 Functions: 21 28 75.0 %
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        4814 : SdrCustomShapeEngineItem::SdrCustomShapeEngineItem()
      27        4814 : :   SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE, "" )
      28        4814 : {}
      29             : 
      30        4814 : SdrCustomShapeDataItem::SdrCustomShapeDataItem()
      31        4814 : :   SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA, "" )
      32        4814 : {}
      33             : 
      34      253314 : TYPEINIT1_FACTORY( SdrCustomShapeGeometryItem, SfxPoolItem , new  SdrCustomShapeGeometryItem);
      35             : 
      36        4814 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem()
      37        4814 : :   SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
      38        4814 : {}
      39             : 
      40       16162 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( const uno::Sequence< beans::PropertyValue >& rVal )
      41       16162 : :   SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
      42             : {
      43             :     sal_Int32 i, j;
      44       16162 :     aPropSeq = rVal;
      45             : 
      46       88785 :     for ( i = 0; i < aPropSeq.getLength(); i++ )
      47             :     {
      48       72623 :         beans::PropertyValue& rPropVal = aPropSeq[ i ];
      49             :         std::pair<PropertyHashMap::iterator, bool> const ret(
      50       72623 :                 aPropHashMap.insert(std::make_pair(rPropVal.Name, i)));
      51             :         assert(ret.second); // serious bug: duplicate xml attribute exported
      52       72623 :         if (!ret.second)
      53             :         {
      54             :             throw uno::RuntimeException(
      55           0 :                 "CustomShapeGeometry has duplicate property " + rPropVal.Name);
      56             :         }
      57       72623 :         if ( rPropVal.Value.getValueType() == cppu::UnoType<css::uno::Sequence < beans::PropertyValue >>::get() )
      58             :         {
      59        7910 :             uno::Sequence< beans::PropertyValue > const & rPropSeq = *static_cast<uno::Sequence< beans::PropertyValue > const *>(rPropVal.Value.getValue());
      60       31779 :             for ( j = 0; j < rPropSeq.getLength(); j++ )
      61             :             {
      62       23869 :                 beans::PropertyValue const & rPropVal2 = rPropSeq[ j ];
      63       23869 :                 aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = j;
      64             :             }
      65             :         }
      66             :     }
      67       16162 : }
      68             : 
      69      325594 : com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const OUString& rPropName )
      70             : {
      71      325594 :     com::sun::star::uno::Any* pRet = NULL;
      72      325594 :     PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
      73      325594 :     if ( aHashIter != aPropHashMap.end() )
      74      212866 :         pRet = &aPropSeq[ (*aHashIter).second ].Value;
      75      325594 :     return pRet;
      76             : }
      77             : 
      78       96671 : const com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const OUString& rPropName ) const
      79             : {
      80       96671 :     const com::sun::star::uno::Any* pRet = NULL;
      81       96671 :     PropertyHashMap::const_iterator aHashIter( aPropHashMap.find( rPropName ) );
      82       96671 :     if ( aHashIter != aPropHashMap.end() )
      83       48969 :         pRet = &aPropSeq[ (*aHashIter).second ].Value;
      84       96671 :     return pRet;
      85             : }
      86             : 
      87      185508 : com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const OUString& rSequenceName, const OUString& rPropName )
      88             : {
      89      185508 :     com::sun::star::uno::Any* pRet = NULL;
      90      185508 :     com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
      91      185508 :     if ( pSeqAny )
      92             :     {
      93      130589 :         if ( pSeqAny->getValueType() == cppu::UnoType<css::uno::Sequence < beans::PropertyValue >>::get() )
      94             :         {
      95      130589 :             PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropName ) ) );
      96      130589 :             if ( aHashIter != aPropPairHashMap.end() )
      97             :             {
      98             :                 ::com::sun::star::uno::Sequence < beans::PropertyValue > const & rSecSequence =
      99       50663 :                     *static_cast<css::uno::Sequence < beans::PropertyValue > const *>(pSeqAny->getValue());
     100       50663 :                 pRet = const_cast<css::uno::Any *>(&rSecSequence[ (*aHashIter).second ].Value);
     101             :             }
     102             :         }
     103             :     }
     104      185508 :     return pRet;
     105             : }
     106             : 
     107       15807 : const com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const OUString& rSequenceName, const OUString& rPropName ) const
     108             : {
     109       15807 :     const com::sun::star::uno::Any* pRet = NULL;
     110       15807 :     const com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
     111       15807 :     if ( pSeqAny )
     112             :     {
     113         429 :         if ( pSeqAny->getValueType() == cppu::UnoType<css::uno::Sequence < beans::PropertyValue >>::get() )
     114             :         {
     115         429 :             PropertyPairHashMap::const_iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropName ) ) );
     116         429 :             if ( aHashIter != aPropPairHashMap.end() )
     117             :             {
     118             :                 ::com::sun::star::uno::Sequence < beans::PropertyValue > const & rSecSequence =
     119         429 :                     *static_cast<css::uno::Sequence < beans::PropertyValue > const *>(pSeqAny->getValue());
     120         429 :                 pRet = &rSecSequence[ (*aHashIter).second ].Value;
     121             :             }
     122             :         }
     123             :     }
     124       15807 :     return pRet;
     125             : }
     126             : 
     127        5790 : void SdrCustomShapeGeometryItem::SetPropertyValue( const com::sun::star::beans::PropertyValue& rPropVal )
     128             : {
     129        5790 :     com::sun::star::uno::Any* pAny = GetPropertyValueByName( rPropVal.Name );
     130        5790 :     if ( pAny )
     131             :     {   // property is already available
     132             :         sal_Int32 i;
     133        2575 :         if ( pAny->getValueType() == cppu::UnoType<css::uno::Sequence < beans::PropertyValue >>::get() )
     134             :         {   // old property is a sequence->each entry has to be removed from the HashPairMap
     135             :             ::com::sun::star::uno::Sequence < beans::PropertyValue > const & rSecSequence =
     136           0 :                 *static_cast<css::uno::Sequence < beans::PropertyValue > const *>(pAny->getValue());
     137           0 :             for ( i = 0; i < rSecSequence.getLength(); i++ )
     138             :             {
     139           0 :                 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rPropVal.Name, rSecSequence[ i ].Name ) ) );
     140           0 :                 if ( aHashIter != aPropPairHashMap.end() )
     141           0 :                     aPropPairHashMap.erase( aHashIter );
     142             :             }
     143             :         }
     144        2575 :         *pAny = rPropVal.Value;
     145        2575 :         if ( rPropVal.Value.getValueType() == cppu::UnoType<css::uno::Sequence < beans::PropertyValue >>::get() )
     146             :         {   // the new property is a sequence->each entry has to be inserted into the HashPairMap
     147             :             ::com::sun::star::uno::Sequence < beans::PropertyValue > const & rSecSequence =
     148           0 :                 *static_cast<css::uno::Sequence < beans::PropertyValue > const *>(pAny->getValue());
     149           0 :             for ( i = 0; i < rSecSequence.getLength(); i++ )
     150             :             {
     151           0 :                 beans::PropertyValue const & rPropVal2 = rSecSequence[ i ];
     152           0 :                 aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = i;
     153             :             }
     154             :         }
     155             :     }
     156             :     else
     157             :     {   // it's a new property
     158             :         assert(aPropSeq.end() == std::find_if(aPropSeq.begin(), aPropSeq.end(),
     159             :             [&rPropVal](beans::PropertyValue const& rVal)
     160             :                 { return rVal.Name == rPropVal.Name; } ));
     161        3215 :         sal_uInt32 nIndex = aPropSeq.getLength();
     162        3215 :         aPropSeq.realloc( nIndex + 1 );
     163        3215 :         aPropSeq[ nIndex ] = rPropVal ;
     164             : 
     165        3215 :         aPropHashMap[ rPropVal.Name ] = nIndex;
     166             :     }
     167        5790 : }
     168             : 
     169        1849 : void SdrCustomShapeGeometryItem::SetPropertyValue( const OUString& rSequenceName, const com::sun::star::beans::PropertyValue& rPropVal )
     170             : {
     171        1849 :     com::sun::star::uno::Any* pAny = GetPropertyValueByName( rSequenceName, rPropVal.Name );
     172        1849 :     if ( pAny ) // just replacing
     173           0 :         *pAny = rPropVal.Value;
     174             :     else
     175             :     {
     176        1849 :         com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
     177        1849 :         if( pSeqAny == NULL )
     178             :         {
     179        1292 :             ::com::sun::star::uno::Sequence < beans::PropertyValue > aSeq;
     180        2584 :             beans::PropertyValue aValue;
     181        1292 :             aValue.Name = rSequenceName;
     182        1292 :             aValue.Value = ::com::sun::star::uno::makeAny( aSeq );
     183             : 
     184             :             assert(aPropSeq.end() == std::find_if(aPropSeq.begin(), aPropSeq.end(),
     185             :                 [&rSequenceName](beans::PropertyValue const& rV)
     186             :                     { return rV.Name == rSequenceName; } ));
     187        1292 :             sal_uInt32 nIndex = aPropSeq.getLength();
     188        1292 :             aPropSeq.realloc( nIndex + 1 );
     189        1292 :             aPropSeq[ nIndex ] = aValue;
     190        1292 :             aPropHashMap[ rSequenceName ] = nIndex;
     191             : 
     192        2584 :             pSeqAny = &aPropSeq[ nIndex ].Value;
     193             :         }
     194             : 
     195             :         DBG_ASSERT( pSeqAny, "SdrCustomShapeGeometryItem::SetPropertyValue() - No Value??" );
     196             : 
     197        1849 :         if( pSeqAny )
     198             :         {
     199        1849 :             if ( pSeqAny->getValueType() == cppu::UnoType<css::uno::Sequence < beans::PropertyValue >>::get() )
     200             :             {
     201        1849 :                 PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropVal.Name ) ) );
     202        1849 :                 if ( aHashIter != aPropPairHashMap.end() )
     203             :                 {
     204             :                     ::com::sun::star::uno::Sequence < beans::PropertyValue > const & rSecSequence =
     205           0 :                         *static_cast<css::uno::Sequence < beans::PropertyValue > const *>(pSeqAny->getValue());
     206           0 :                     const_cast<css::uno::Sequence<css::beans::PropertyValue> &>(rSecSequence)[ (*aHashIter).second ].Value = rPropVal.Value;
     207             :                 }
     208             :                 else
     209             :                 {
     210             :                     ::com::sun::star::uno::Sequence < beans::PropertyValue > const & rSecSequence =
     211        1849 :                         *static_cast<css::uno::Sequence < beans::PropertyValue > const *>(pSeqAny->getValue());
     212             : 
     213        1849 :                     sal_Int32 nCount = rSecSequence.getLength();
     214        1849 :                     const_cast<css::uno::Sequence<css::beans::PropertyValue> &>(rSecSequence).realloc( nCount + 1 );
     215        1849 :                     const_cast<css::uno::Sequence<css::beans::PropertyValue> &>(rSecSequence)[ nCount ] = rPropVal;
     216             : 
     217        1849 :                     aPropPairHashMap[ PropertyPair( rSequenceName, rPropVal.Name ) ] = nCount;
     218             :                 }
     219             :             }
     220             :         }
     221             :     }
     222        1849 : }
     223             : 
     224           0 : void SdrCustomShapeGeometryItem::ClearPropertyValue( const OUString& rPropName )
     225             : {
     226           0 :     if ( aPropSeq.getLength() )
     227             :     {
     228           0 :         PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
     229           0 :         if ( aHashIter != aPropHashMap.end() )
     230             :         {
     231           0 :              com::sun::star::uno::Any* pSeqAny = &aPropSeq[ (*aHashIter).second ].Value;
     232           0 :             if ( pSeqAny )
     233             :             {
     234           0 :                 if ( pSeqAny->getValueType() == cppu::UnoType<css::uno::Sequence < beans::PropertyValue >>::get() )
     235             :                 {
     236             :                     ::com::sun::star::uno::Sequence < beans::PropertyValue > const & rSecSequence =
     237           0 :                         *static_cast<css::uno::Sequence < beans::PropertyValue > const *>(pSeqAny->getValue());
     238             : 
     239             :                     sal_Int32 i;
     240           0 :                     for ( i = 0; i < rSecSequence.getLength(); i++ )
     241             :                     {
     242           0 :                         PropertyPairHashMap::iterator _aHashIter( aPropPairHashMap.find( PropertyPair( rPropName, rSecSequence[ i ].Name ) ) );
     243           0 :                         if ( _aHashIter != aPropPairHashMap.end() )
     244           0 :                             aPropPairHashMap.erase( _aHashIter );       // removing property from pair hashmap
     245             :                     }
     246             :                 }
     247             :             }
     248           0 :             sal_Int32 nLength = aPropSeq.getLength();
     249           0 :             if ( nLength )
     250             :             {
     251           0 :                 sal_Int32 nIndex  = (*aHashIter).second;
     252           0 :                 if ( nIndex != ( nLength - 1 ) )                        // resizing sequence
     253             :                 {
     254           0 :                     PropertyHashMap::iterator aHashIter2( aPropHashMap.find( aPropSeq[ nLength - 1 ].Name ) );
     255           0 :                     (*aHashIter2).second = nIndex;
     256           0 :                     aPropSeq[ (*aHashIter).second ] = aPropSeq[ aPropSeq.getLength() - 1 ];
     257             :                 }
     258           0 :                 aPropSeq.realloc( aPropSeq.getLength() - 1 );
     259             :             }
     260           0 :             aPropHashMap.erase( aHashIter );                            // removing property from hashmap
     261             :         }
     262             :     }
     263           0 : }
     264             : 
     265       67117 : SdrCustomShapeGeometryItem::~SdrCustomShapeGeometryItem()
     266             : {
     267       67117 : }
     268           0 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( SvStream& /*rIn*/, sal_uInt16 nVersion ):
     269           0 :     SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
     270             : {
     271             :     if ( nVersion )
     272             :     {
     273             : 
     274             :     }
     275           0 : }
     276      107946 : bool SdrCustomShapeGeometryItem::operator==( const SfxPoolItem& rCmp ) const
     277             : {
     278      107946 :     bool bRet = SfxPoolItem::operator==( rCmp );
     279      107946 :     if ( bRet )
     280      107946 :         bRet = static_cast<const SdrCustomShapeGeometryItem&>(rCmp).aPropSeq == aPropSeq;
     281      107946 :     return bRet;
     282             : }
     283             : 
     284           0 : bool SdrCustomShapeGeometryItem::GetPresentation(
     285             :     SfxItemPresentation ePresentation, SfxMapUnit /*eCoreMetric*/,
     286             :     SfxMapUnit /*ePresentationMetric*/, OUString &rText, const IntlWrapper *) const
     287             : {
     288           0 :     rText += " ";
     289           0 :     if ( ePresentation == SFX_ITEM_PRESENTATION_COMPLETE )
     290             :     {
     291           0 :         rText = " " + rText;
     292           0 :         return true;
     293             :     }
     294           0 :     else if ( ePresentation == SFX_ITEM_PRESENTATION_NAMELESS )
     295           0 :         return true;
     296           0 :     return false;
     297             : }
     298             : 
     299           0 : SfxPoolItem* SdrCustomShapeGeometryItem::Create( SvStream& rIn, sal_uInt16 nItemVersion ) const
     300             : {
     301           0 :     return new SdrCustomShapeGeometryItem( rIn, nItemVersion );
     302             : }
     303             : 
     304           0 : SvStream& SdrCustomShapeGeometryItem::Store( SvStream& rOut, sal_uInt16 nItemVersion ) const
     305             : {
     306             :     if ( nItemVersion )
     307             :     {
     308             : 
     309             :     }
     310           0 :     return rOut;
     311             : }
     312             : 
     313       14133 : SfxPoolItem* SdrCustomShapeGeometryItem::Clone( SfxItemPool * /*pPool*/ ) const
     314             : {
     315       14133 :     return new SdrCustomShapeGeometryItem( GetGeometry() );
     316             : }
     317             : 
     318           0 : sal_uInt16 SdrCustomShapeGeometryItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
     319             : {
     320           0 :     return 1;
     321             : }
     322        4308 : bool SdrCustomShapeGeometryItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
     323             : {
     324        4308 :     rVal <<= aPropSeq;
     325        4308 :     return true;
     326             : }
     327        2532 : bool SdrCustomShapeGeometryItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
     328             : {
     329        2532 :     if ( ! ( rVal >>= aPropSeq ) )
     330           0 :         return false;
     331             :     else
     332             :     {
     333       25197 :         for (sal_Int32 i = 0; i < aPropSeq.getLength(); ++i)
     334             :         {
     335      118091 :             for (sal_Int32 j = i+1; j < aPropSeq.getLength(); ++j)
     336             :             {
     337       95426 :                 if (aPropSeq[i].Name == aPropSeq[j].Name)
     338             :                 {
     339             :                     assert(false); // serious bug: duplicate xml attribute exported
     340           0 :                     OUString const name(aPropSeq[i].Name);
     341           0 :                     aPropSeq.realloc(0);
     342             :                     throw uno::RuntimeException(
     343           0 :                         "CustomShapeGeometry has duplicate property " + name);
     344             :                 }
     345             :             }
     346             :         }
     347        2532 :         return true;
     348             :     }
     349             : }
     350             : 
     351        4814 : SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem()
     352        4814 : :   SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL, "" )
     353        4814 : {}
     354             : 
     355             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11