1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/vml/vmlshapecontainer.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "oox/vml/vmldrawing.hxx"
27cdf0e10cSrcweir #include "oox/vml/vmlshape.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir namespace oox {
30cdf0e10cSrcweir namespace vml {
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // ============================================================================
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::com::sun::star::awt;
35cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using ::rtl::OUString;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // ============================================================================
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir template< typename ShapeType >
lclMapShapesById(RefMap<OUString,ShapeType> & orMap,const RefVector<ShapeType> & rVector)45cdf0e10cSrcweir void lclMapShapesById( RefMap< OUString, ShapeType >& orMap, const RefVector< ShapeType >& rVector )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     for( typename RefVector< ShapeType >::const_iterator aIt = rVector.begin(), aEnd = rVector.end(); aIt != aEnd; ++aIt )
48cdf0e10cSrcweir     {
49cdf0e10cSrcweir         const OUString& rShapeId = (*aIt)->getShapeId();
50cdf0e10cSrcweir         OSL_ENSURE( rShapeId.getLength() > 0, "lclMapShapesById - missing shape identifier" );
51cdf0e10cSrcweir         if( rShapeId.getLength() > 0 )
52cdf0e10cSrcweir         {
53cdf0e10cSrcweir             OSL_ENSURE( orMap.find( rShapeId ) == orMap.end(), "lclMapShapesById - shape identifier already used" );
54cdf0e10cSrcweir             orMap[ rShapeId ] = *aIt;
55cdf0e10cSrcweir         }
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir } // namespace
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // ============================================================================
62cdf0e10cSrcweir 
ShapeContainer(Drawing & rDrawing)63cdf0e10cSrcweir ShapeContainer::ShapeContainer( Drawing& rDrawing ) :
64cdf0e10cSrcweir     mrDrawing( rDrawing )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
~ShapeContainer()68cdf0e10cSrcweir ShapeContainer::~ShapeContainer()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
createShapeType()72cdf0e10cSrcweir ShapeType& ShapeContainer::createShapeType()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     ::boost::shared_ptr< ShapeType > xShape( new ShapeType( mrDrawing ) );
75cdf0e10cSrcweir     maTypes.push_back( xShape );
76cdf0e10cSrcweir     return *xShape;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
finalizeFragmentImport()79cdf0e10cSrcweir void ShapeContainer::finalizeFragmentImport()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     // map all shape templates by shape identifier
82cdf0e10cSrcweir     lclMapShapesById( maTypesById, maTypes );
83cdf0e10cSrcweir     // map all shapes by shape identifier
84cdf0e10cSrcweir     lclMapShapesById( maShapesById, maShapes );
85cdf0e10cSrcweir     /*  process all shapes (map all children templates/shapes in group shapes,
86cdf0e10cSrcweir         resolve template references in all shapes) */
87cdf0e10cSrcweir     maShapes.forEachMem( &ShapeBase::finalizeFragmentImport );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
getShapeTypeById(const OUString & rShapeId,bool bDeep) const90cdf0e10cSrcweir const ShapeType* ShapeContainer::getShapeTypeById( const OUString& rShapeId, bool bDeep ) const
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     // search in own shape template list
93cdf0e10cSrcweir     if( const ShapeType* pType = maTypesById.get( rShapeId ).get() )
94cdf0e10cSrcweir         return pType;
95cdf0e10cSrcweir     // search deep in child shapes
96cdf0e10cSrcweir     if( bDeep )
97cdf0e10cSrcweir         for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
98cdf0e10cSrcweir             if( const ShapeType* pType = (*aVIt)->getChildTypeById( rShapeId ) )
99cdf0e10cSrcweir                 return pType;
100cdf0e10cSrcweir    return 0;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
getShapeById(const OUString & rShapeId,bool bDeep) const103cdf0e10cSrcweir const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bDeep ) const
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     // search in own shape list
106cdf0e10cSrcweir     if( const ShapeBase* pShape = maShapesById.get( rShapeId ).get() )
107cdf0e10cSrcweir         return pShape;
108cdf0e10cSrcweir     // search deep in child shapes
109cdf0e10cSrcweir     if( bDeep )
110cdf0e10cSrcweir         for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
111cdf0e10cSrcweir             if( const ShapeBase* pShape = (*aVIt)->getChildById( rShapeId ) )
112cdf0e10cSrcweir                 return pShape;
113cdf0e10cSrcweir    return 0;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
getFirstShape() const116cdf0e10cSrcweir const ShapeBase* ShapeContainer::getFirstShape() const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::getFirstShape - illegal call, Word filter only" );
119cdf0e10cSrcweir     OSL_ENSURE( maShapes.size() == 1, "ShapeContainer::getFirstShape - single shape expected" );
120cdf0e10cSrcweir     return maShapes.get( 0 ).get();
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
convertAndInsert(const Reference<XShapes> & rxShapes,const ShapeParentAnchor * pParentAnchor) const123cdf0e10cSrcweir void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     for( ShapeVector::const_iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
126cdf0e10cSrcweir         (*aIt)->convertAndInsert( rxShapes, pParentAnchor );
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir // ============================================================================
130cdf0e10cSrcweir 
131cdf0e10cSrcweir } // namespace vml
132cdf0e10cSrcweir } // namespace oox
133