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

Generated by: LCOV version 1.10