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 : #include <osl/diagnose.h>
26 :
27 : namespace oox {
28 : namespace vml {
29 :
30 : using namespace ::com::sun::star::awt;
31 : using namespace ::com::sun::star::drawing;
32 : using namespace ::com::sun::star::uno;
33 :
34 : namespace {
35 :
36 : template< typename ShapeType >
37 806 : void lclMapShapesById( RefMap< OUString, ShapeType >& orMap, const RefVector< ShapeType >& rVector )
38 : {
39 2088 : for( typename RefVector< ShapeType >::const_iterator aIt = rVector.begin(), aEnd = rVector.end(); aIt != aEnd; ++aIt )
40 : {
41 1282 : const OUString& rShapeId = (*aIt)->getShapeId();
42 : OSL_ENSURE( !rShapeId.isEmpty(), "lclMapShapesById - missing shape identifier" );
43 1282 : if( !rShapeId.isEmpty() )
44 : {
45 : OSL_ENSURE( orMap.find( rShapeId ) == orMap.end(), "lclMapShapesById - shape identifier already used " );
46 1275 : orMap[ rShapeId ] = *aIt;
47 : }
48 : }
49 806 : }
50 :
51 : } // namespace
52 :
53 1306 : ShapeContainer::ShapeContainer( Drawing& rDrawing ) :
54 1306 : mrDrawing( rDrawing )
55 : {
56 1306 : }
57 :
58 1306 : ShapeContainer::~ShapeContainer()
59 : {
60 1306 : }
61 :
62 201 : ShapeType& ShapeContainer::createShapeType()
63 : {
64 201 : std::shared_ptr< ShapeType > xShape( new ShapeType( mrDrawing ) );
65 201 : maTypes.push_back( xShape );
66 201 : return *xShape;
67 : }
68 :
69 403 : void ShapeContainer::finalizeFragmentImport()
70 : {
71 : // map all shape templates by shape identifier
72 403 : lclMapShapesById( maTypesById, maTypes );
73 : // map all shapes by shape identifier
74 403 : lclMapShapesById( maShapesById, maShapes );
75 : /* process all shapes (map all children templates/shapes in group shapes,
76 : resolve template references in all shapes) */
77 403 : maShapes.forEachMem( &ShapeBase::finalizeFragmentImport );
78 403 : }
79 :
80 390 : const ShapeType* ShapeContainer::getShapeTypeById( const OUString& rShapeId, bool bDeep ) const
81 : {
82 : // search in own shape template list
83 390 : if( const ShapeType* pType = maTypesById.get( rShapeId ).get() )
84 307 : return pType;
85 : // search deep in child shapes
86 83 : if( bDeep )
87 119 : for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
88 90 : if( const ShapeType* pType = (*aVIt)->getChildTypeById( rShapeId ) )
89 54 : return pType;
90 29 : return 0;
91 : }
92 :
93 2 : const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bDeep ) const
94 : {
95 : // search in own shape list
96 2 : if( const ShapeBase* pShape = maShapesById.get( rShapeId ).get() )
97 2 : return pShape;
98 : // search deep in child shapes
99 0 : if( bDeep )
100 0 : for( ShapeVector::const_iterator aVIt = maShapes.begin(), aVEnd = maShapes.end(); aVIt != aVEnd; ++aVIt )
101 0 : if( const ShapeBase* pShape = (*aVIt)->getChildById( rShapeId ) )
102 0 : return pShape;
103 0 : return 0;
104 : }
105 :
106 364 : std::shared_ptr< ShapeBase > ShapeContainer::takeLastShape()
107 : {
108 : OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::takeLastShape - illegal call, Word filter only" );
109 : assert( !markStack.empty());
110 364 : if( markStack.top() >= maShapes.size())
111 3 : return std::shared_ptr< ShapeBase >();
112 361 : std::shared_ptr< ShapeBase > ret = maShapes.back();
113 361 : maShapes.pop_back();
114 361 : return ret;
115 : }
116 :
117 364 : void ShapeContainer::pushMark()
118 : {
119 364 : markStack.push( maShapes.size());
120 364 : }
121 :
122 364 : void ShapeContainer::popMark()
123 : {
124 : assert( !markStack.empty());
125 364 : markStack.pop();
126 364 : }
127 :
128 330 : void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
129 : {
130 936 : for( ShapeVector::const_iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt )
131 606 : (*aIt)->convertAndInsert( rxShapes, pParentAnchor );
132 330 : }
133 :
134 : } // namespace vml
135 246 : } // namespace oox
136 :
137 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|