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

Generated by: LCOV version 1.10