xref: /AOO41X/main/oox/source/vml/vmlshapecontainer.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/vml/vmlshapecontainer.hxx"
29 
30 #include "oox/vml/vmldrawing.hxx"
31 #include "oox/vml/vmlshape.hxx"
32 
33 namespace oox {
34 namespace vml {
35 
36 // ============================================================================
37 
38 using namespace ::com::sun::star::awt;
39 using namespace ::com::sun::star::drawing;
40 using namespace ::com::sun::star::uno;
41 
42 using ::rtl::OUString;
43 
44 // ============================================================================
45 
46 namespace {
47 
48 template< typename ShapeType >
49 void lclMapShapesById( RefMap< OUString, ShapeType >& orMap, const RefVector< ShapeType >& rVector )
50 {
51     for( typename RefVector< ShapeType >::const_iterator aIt = rVector.begin(), aEnd = rVector.end(); aIt != aEnd; ++aIt )
52     {
53         const OUString& rShapeId = (*aIt)->getShapeId();
54         OSL_ENSURE( rShapeId.getLength() > 0, "lclMapShapesById - missing shape identifier" );
55         if( rShapeId.getLength() > 0 )
56         {
57             OSL_ENSURE( orMap.find( rShapeId ) == orMap.end(), "lclMapShapesById - shape identifier already used" );
58             orMap[ rShapeId ] = *aIt;
59         }
60     }
61 }
62 
63 } // namespace
64 
65 // ============================================================================
66 
67 ShapeContainer::ShapeContainer( Drawing& rDrawing ) :
68     mrDrawing( rDrawing )
69 {
70 }
71 
72 ShapeContainer::~ShapeContainer()
73 {
74 }
75 
76 ShapeType& ShapeContainer::createShapeType()
77 {
78     ::boost::shared_ptr< ShapeType > xShape( new ShapeType( mrDrawing ) );
79     maTypes.push_back( xShape );
80     return *xShape;
81 }
82 
83 void ShapeContainer::finalizeFragmentImport()
84 {
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 );
92 }
93 
94 const ShapeType* ShapeContainer::getShapeTypeById( const OUString& rShapeId, bool bDeep ) const
95 {
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;
105 }
106 
107 const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bDeep ) const
108 {
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;
118 }
119 
120 const ShapeBase* ShapeContainer::getFirstShape() const
121 {
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();
125 }
126 
127 void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
128 {
129     for( ShapeVector::const_iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
130         (*aIt)->convertAndInsert( rxShapes, pParentAnchor );
131 }
132 
133 // ============================================================================
134 
135 } // namespace vml
136 } // namespace oox
137