Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "oox/vml/vmlshapecontainer.hxx"
21 : :
22 : : #include "oox/vml/vmldrawing.hxx"
23 : : #include "oox/vml/vmlshape.hxx"
24 : :
25 : : namespace oox {
26 : : namespace vml {
27 : :
28 : : // ============================================================================
29 : :
30 : : using namespace ::com::sun::star::awt;
31 : : using namespace ::com::sun::star::drawing;
32 : : using namespace ::com::sun::star::uno;
33 : :
34 : : using ::rtl::OUString;
35 : :
36 : : // ============================================================================
37 : :
38 : : namespace {
39 : :
40 : : template< typename ShapeType >
41 : 114 : void lclMapShapesById( RefMap< OUString, ShapeType >& orMap, const RefVector< ShapeType >& rVector )
42 : : {
43 [ + - ][ + + ]: 222 : for( typename RefVector< ShapeType >::const_iterator aIt = rVector.begin(), aEnd = rVector.end(); aIt != aEnd; ++aIt )
[ + - ][ + + ]
44 : : {
45 : 108 : const OUString& rShapeId = (*aIt)->getShapeId();
46 : : OSL_ENSURE( !rShapeId.isEmpty(), "lclMapShapesById - missing shape identifier" );
47 [ + - + - ]: 108 : if( !rShapeId.isEmpty() )
48 : : {
49 : : OSL_ENSURE( orMap.find( rShapeId ) == orMap.end(), "lclMapShapesById - shape identifier already used" );
50 [ + - ][ + - ]: 108 : orMap[ rShapeId ] = *aIt;
[ + - ][ + - ]
51 : : }
52 : : }
53 : 114 : }
54 : :
55 : : } // namespace
56 : :
57 : : // ============================================================================
58 : :
59 : 123 : ShapeContainer::ShapeContainer( Drawing& rDrawing ) :
60 [ + - ][ + - ]: 123 : mrDrawing( rDrawing )
[ + - ][ + - ]
[ + - ]
61 : : {
62 : 123 : }
63 : :
64 : 123 : ShapeContainer::~ShapeContainer()
65 : : {
66 : 123 : }
67 : :
68 : 30 : ShapeType& ShapeContainer::createShapeType()
69 : : {
70 [ + - ][ + - ]: 30 : ::boost::shared_ptr< ShapeType > xShape( new ShapeType( mrDrawing ) );
[ + - ]
71 [ + - ]: 30 : maTypes.push_back( xShape );
72 [ + - ]: 30 : return *xShape;
73 : : }
74 : :
75 : 57 : void ShapeContainer::finalizeFragmentImport()
76 : : {
77 : : // map all shape templates by shape identifier
78 : 57 : lclMapShapesById( maTypesById, maTypes );
79 : : // map all shapes by shape identifier
80 : 57 : lclMapShapesById( maShapesById, maShapes );
81 : : /* process all shapes (map all children templates/shapes in group shapes,
82 : : resolve template references in all shapes) */
83 : 57 : maShapes.forEachMem( &ShapeBase::finalizeFragmentImport );
84 : 57 : }
85 : :
86 : 48 : const ShapeType* ShapeContainer::getShapeTypeById( const OUString& rShapeId, bool bDeep ) const
87 : : {
88 : : // search in own shape template list
89 [ + - ][ + - ]: 48 : if( const ShapeType* pType = maTypesById.get( rShapeId ).get() )
[ + + ]
90 : 27 : return pType;
91 : : // search deep in child shapes
92 [ + - ]: 21 : if( bDeep )
93 [ + - ][ + + ]: 48 : for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
94 [ + - ][ - + ]: 27 : if( const ShapeType* pType = (*aVIt)->getChildTypeById( rShapeId ) )
95 : 0 : return pType;
96 : 48 : return 0;
97 : : }
98 : :
99 : 0 : const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bDeep ) const
100 : : {
101 : : // search in own shape list
102 [ # # ][ # # ]: 0 : if( const ShapeBase* pShape = maShapesById.get( rShapeId ).get() )
[ # # ]
103 : 0 : return pShape;
104 : : // search deep in child shapes
105 [ # # ]: 0 : if( bDeep )
106 [ # # ][ # # ]: 0 : for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
107 [ # # ][ # # ]: 0 : if( const ShapeBase* pShape = (*aVIt)->getChildById( rShapeId ) )
108 : 0 : return pShape;
109 : 0 : return 0;
110 : : }
111 : :
112 : 42 : boost::shared_ptr< ShapeBase > ShapeContainer::takeLastShape()
113 : : {
114 : : OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::takeLastShape - illegal call, Word filter only" );
115 : : assert( !markStack.empty());
116 [ + - ][ + + ]: 42 : if( markStack.top() >= maShapes.size())
117 [ + - ]: 3 : return boost::shared_ptr< ShapeBase >();
118 [ + - ][ + - ]: 39 : boost::shared_ptr< ShapeBase > ret = maShapes.back();
119 [ + - ]: 39 : maShapes.pop_back();
120 [ + - ][ + - ]: 42 : return ret;
121 : : }
122 : :
123 : 42 : void ShapeContainer::pushMark()
124 : : {
125 [ + - ]: 42 : markStack.push( maShapes.size());
126 : 42 : }
127 : :
128 : 42 : void ShapeContainer::popMark()
129 : : {
130 : : assert( !markStack.empty());
131 : 42 : markStack.pop();
132 : 42 : }
133 : :
134 : 45 : void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
135 : : {
136 [ + - ][ + + ]: 63 : for( ShapeVector::const_iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
137 [ + - ]: 18 : (*aIt)->convertAndInsert( rxShapes, pParentAnchor );
138 : 45 : }
139 : :
140 : : // ============================================================================
141 : :
142 : : } // namespace vml
143 [ + - ][ + - ]: 285 : } // namespace oox
144 : :
145 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|