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