Branch libreoffice-5-0-4
[LibreOffice.git] / oox / source / vml / vmlshapecontainer.cxx
bloba7fbb785ab201bd19d77a6f6b13042393f8cff5d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/vml/vmlshapecontainer.hxx"
22 #include "oox/vml/vmldrawing.hxx"
23 #include "oox/vml/vmlshape.hxx"
25 #include <osl/diagnose.h>
27 namespace oox {
28 namespace vml {
30 using namespace ::com::sun::star::awt;
31 using namespace ::com::sun::star::drawing;
32 using namespace ::com::sun::star::uno;
34 namespace {
36 template< typename ShapeType >
37 void lclMapShapesById( RefMap< OUString, ShapeType >& orMap, const RefVector< ShapeType >& rVector )
39 for( typename RefVector< ShapeType >::const_iterator aIt = rVector.begin(), aEnd = rVector.end(); aIt != aEnd; ++aIt )
41 const OUString& rShapeId = (*aIt)->getShapeId();
42 OSL_ENSURE( !rShapeId.isEmpty(), "lclMapShapesById - missing shape identifier" );
43 if( !rShapeId.isEmpty() )
45 OSL_ENSURE( orMap.find( rShapeId ) == orMap.end(), "lclMapShapesById - shape identifier already used " );
46 orMap[ rShapeId ] = *aIt;
51 } // namespace
53 ShapeContainer::ShapeContainer( Drawing& rDrawing ) :
54 mrDrawing( rDrawing )
58 ShapeContainer::~ShapeContainer()
62 ShapeType& ShapeContainer::createShapeType()
64 std::shared_ptr< ShapeType > xShape( new ShapeType( mrDrawing ) );
65 maTypes.push_back( xShape );
66 return *xShape;
69 void ShapeContainer::finalizeFragmentImport()
71 // map all shape templates by shape identifier
72 lclMapShapesById( maTypesById, maTypes );
73 // map all shapes by shape identifier
74 lclMapShapesById( maShapesById, maShapes );
75 /* process all shapes (map all children templates/shapes in group shapes,
76 resolve template references in all shapes) */
77 maShapes.forEachMem( &ShapeBase::finalizeFragmentImport );
80 const ShapeType* ShapeContainer::getShapeTypeById( const OUString& rShapeId, bool bDeep ) const
82 // search in own shape template list
83 if( const ShapeType* pType = maTypesById.get( rShapeId ).get() )
84 return pType;
85 // search deep in child shapes
86 if( bDeep )
87 for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
88 if( const ShapeType* pType = (*aVIt)->getChildTypeById( rShapeId ) )
89 return pType;
90 return 0;
93 const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bDeep ) const
95 // search in own shape list
96 if( const ShapeBase* pShape = maShapesById.get( rShapeId ).get() )
97 return pShape;
98 // search deep in child shapes
99 if( bDeep )
100 for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
101 if( const ShapeBase* pShape = (*aVIt)->getChildById( rShapeId ) )
102 return pShape;
103 return 0;
106 std::shared_ptr< ShapeBase > ShapeContainer::takeLastShape()
108 OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::takeLastShape - illegal call, Word filter only" );
109 assert( !markStack.empty());
110 if( markStack.top() >= maShapes.size())
111 return std::shared_ptr< ShapeBase >();
112 std::shared_ptr< ShapeBase > ret = maShapes.back();
113 maShapes.pop_back();
114 return ret;
117 void ShapeContainer::pushMark()
119 markStack.push( maShapes.size());
122 void ShapeContainer::popMark()
124 assert( !markStack.empty());
125 markStack.pop();
128 void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
130 for( ShapeVector::const_iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
131 (*aIt)->convertAndInsert( rxShapes, pParentAnchor );
134 } // namespace vml
135 } // namespace oox
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */