Update ooo320-m1
[ooovba.git] / oox / source / vml / vmlshapecontainer.cxx
blob3b9346f3096a680df9417914215535fe3cd1d126
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vmlshapecontainer.cxx,v $
10 * $Revision: 1.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/vml/vmlshapecontainer.hxx"
32 #include "oox/vml/vmldrawing.hxx"
33 #include "oox/vml/vmlshape.hxx"
35 using ::rtl::OUString;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::awt::Rectangle;
38 using ::com::sun::star::drawing::XShapes;
39 using ::oox::core::XmlFilterBase;
41 namespace oox {
42 namespace vml {
44 // ============================================================================
46 namespace {
48 template< typename ShapeType >
49 void lclMapShapesById( RefMap< OUString, ShapeType >& orMap, const RefVector< ShapeType >& rVector )
51 for( typename RefVector< ShapeType >::const_iterator aIt = rVector.begin(), aEnd = rVector.end(); aIt != aEnd; ++aIt )
53 const OUString& rShapeId = (*aIt)->getShapeId();
54 OSL_ENSURE( rShapeId.getLength() > 0, "lclMapShapesById - missing shape identifier" );
55 if( rShapeId.getLength() > 0 )
57 OSL_ENSURE( orMap.find( rShapeId ) == orMap.end(), "lclMapShapesById - shape identifier already used" );
58 orMap[ rShapeId ] = *aIt;
63 } // namespace
65 // ============================================================================
67 ShapeContainer::ShapeContainer( const Drawing& rDrawing ) :
68 mrDrawing( rDrawing )
72 ShapeContainer::~ShapeContainer()
76 ShapeType& ShapeContainer::createShapeType()
78 ::boost::shared_ptr< ShapeType > xShape( new ShapeType( mrDrawing ) );
79 maTypes.push_back( xShape );
80 return *xShape;
83 void ShapeContainer::finalizeFragmentImport()
85 // map all shape templates by shape identifier
86 lclMapShapesById( maTypesById, maTypes );
87 // map all shapes by shape identifier
88 lclMapShapesById( maShapesById, maShapes );
89 /* process all shapes (map all children templates/shapes in group shapes,
90 resolve template references in all shapes) */
91 maShapes.forEachMem( &ShapeBase::finalizeFragmentImport );
94 const ShapeType* ShapeContainer::getShapeTypeById( const OUString& rShapeId, bool bDeep ) const
96 // search in own shape template list
97 if( const ShapeType* pType = maTypesById.get( rShapeId ).get() )
98 return pType;
99 // search deep in child shapes
100 if( bDeep )
101 for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
102 if( const ShapeType* pType = (*aVIt)->getChildTypeById( rShapeId ) )
103 return pType;
104 return 0;
107 const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bDeep ) const
109 // search in own shape list
110 if( const ShapeBase* pShape = maShapesById.get( rShapeId ).get() )
111 return pShape;
112 // search deep in child shapes
113 if( bDeep )
114 for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
115 if( const ShapeBase* pShape = (*aVIt)->getChildById( rShapeId ) )
116 return pShape;
117 return 0;
120 const ShapeBase* ShapeContainer::getFirstShape() const
122 OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::getFirstShape - illegal call, Word filter only" );
123 OSL_ENSURE( maShapes.size() == 1, "ShapeContainer::getFirstShape - single shape expected" );
124 return maShapes.get( 0 ).get();
127 void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
129 for( ShapeVector::const_iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
130 (*aIt)->convertAndInsert( rxShapes, pParentAnchor );
133 // ============================================================================
135 } // namespace vml
136 } // namespace oox