LCOV - code coverage report
Current view: top level - oox/source/vml - vmlshapecontainer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 48 53 90.6 %
Date: 2014-11-03 Functions: 14 14 100.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 "oox/vml/vmlshapecontainer.hxx"
      21             : 
      22             : #include "oox/vml/vmldrawing.hxx"
      23             : #include "oox/vml/vmlshape.hxx"
      24             : 
      25             : namespace oox {
      26             : namespace vml {
      27             : 
      28             : using namespace ::com::sun::star::awt;
      29             : using namespace ::com::sun::star::drawing;
      30             : using namespace ::com::sun::star::uno;
      31             : 
      32             : namespace {
      33             : 
      34             : template< typename ShapeType >
      35        1600 : void lclMapShapesById( RefMap< OUString, ShapeType >& orMap, const RefVector< ShapeType >& rVector )
      36             : {
      37        4156 :     for( typename RefVector< ShapeType >::const_iterator aIt = rVector.begin(), aEnd = rVector.end(); aIt != aEnd; ++aIt )
      38             :     {
      39        2556 :         const OUString& rShapeId = (*aIt)->getShapeId();
      40             :         OSL_ENSURE( !rShapeId.isEmpty(), "lclMapShapesById - missing shape identifier" );
      41        2556 :         if( !rShapeId.isEmpty() )
      42             :         {
      43             :             OSL_ENSURE( orMap.find( rShapeId ) == orMap.end(), "lclMapShapesById - shape identifier already used " );
      44        2544 :             orMap[ rShapeId ] = *aIt;
      45             :         }
      46             :     }
      47        1600 : }
      48             : 
      49             : } // namespace
      50             : 
      51        2088 : ShapeContainer::ShapeContainer( Drawing& rDrawing ) :
      52        2088 :     mrDrawing( rDrawing )
      53             : {
      54        2088 : }
      55             : 
      56        2088 : ShapeContainer::~ShapeContainer()
      57             : {
      58        2088 : }
      59             : 
      60         402 : ShapeType& ShapeContainer::createShapeType()
      61             : {
      62         402 :     ::boost::shared_ptr< ShapeType > xShape( new ShapeType( mrDrawing ) );
      63         402 :     maTypes.push_back( xShape );
      64         402 :     return *xShape;
      65             : }
      66             : 
      67         800 : void ShapeContainer::finalizeFragmentImport()
      68             : {
      69             :     // map all shape templates by shape identifier
      70         800 :     lclMapShapesById( maTypesById, maTypes );
      71             :     // map all shapes by shape identifier
      72         800 :     lclMapShapesById( maShapesById, maShapes );
      73             :     /*  process all shapes (map all children templates/shapes in group shapes,
      74             :         resolve template references in all shapes) */
      75         800 :     maShapes.forEachMem( &ShapeBase::finalizeFragmentImport );
      76         800 : }
      77             : 
      78         778 : const ShapeType* ShapeContainer::getShapeTypeById( const OUString& rShapeId, bool bDeep ) const
      79             : {
      80             :     // search in own shape template list
      81         778 :     if( const ShapeType* pType = maTypesById.get( rShapeId ).get() )
      82         614 :         return pType;
      83             :     // search deep in child shapes
      84         164 :     if( bDeep )
      85         234 :         for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
      86         178 :             if( const ShapeType* pType = (*aVIt)->getChildTypeById( rShapeId ) )
      87         108 :                 return pType;
      88          56 :    return 0;
      89             : }
      90             : 
      91           4 : const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bDeep ) const
      92             : {
      93             :     // search in own shape list
      94           4 :     if( const ShapeBase* pShape = maShapesById.get( rShapeId ).get() )
      95           4 :         return pShape;
      96             :     // search deep in child shapes
      97           0 :     if( bDeep )
      98           0 :         for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
      99           0 :             if( const ShapeBase* pShape = (*aVIt)->getChildById( rShapeId ) )
     100           0 :                 return pShape;
     101           0 :    return 0;
     102             : }
     103             : 
     104         724 : boost::shared_ptr< ShapeBase > ShapeContainer::takeLastShape()
     105             : {
     106             :     OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::takeLastShape - illegal call, Word filter only" );
     107             :     assert( !markStack.empty());
     108         724 :     if( markStack.top() >= maShapes.size())
     109           6 :         return boost::shared_ptr< ShapeBase >();
     110         718 :     boost::shared_ptr< ShapeBase > ret = maShapes.back();
     111         718 :     maShapes.pop_back();
     112         718 :     return ret;
     113             : }
     114             : 
     115         724 : void ShapeContainer::pushMark()
     116             : {
     117         724 :     markStack.push( maShapes.size());
     118         724 : }
     119             : 
     120         724 : void ShapeContainer::popMark()
     121             : {
     122             :     assert( !markStack.empty());
     123         724 :     markStack.pop();
     124         724 : }
     125             : 
     126         430 : void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
     127             : {
     128        1640 :     for( ShapeVector::const_iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
     129        1210 :         (*aIt)->convertAndInsert( rxShapes, pParentAnchor );
     130         430 : }
     131             : 
     132             : } // namespace vml
     133         408 : } // namespace oox
     134             : 
     135             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10