1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef OOX_VML_VMLSHAPECONTAINER_HXX
25 #define OOX_VML_VMLSHAPECONTAINER_HXX
26
27 #include <com/sun/star/awt/Rectangle.hpp>
28 #include "oox/helper/refmap.hxx"
29 #include "oox/helper/refvector.hxx"
30
31 namespace com { namespace sun { namespace star {
32 namespace drawing { class XShapes; }
33 } } }
34
35 namespace oox {
36 namespace vml {
37
38 class Drawing;
39 class ShapeType;
40 class ShapeBase;
41
42 // ============================================================================
43
44 struct ShapeParentAnchor
45 {
46 ::com::sun::star::awt::Rectangle maShapeRect;
47 ::com::sun::star::awt::Rectangle maCoordSys;
48 };
49
50 // ============================================================================
51
52 /** Container that holds a list of shapes and shape templates. */
53 class ShapeContainer
54 {
55 public:
56 explicit ShapeContainer( Drawing& rDrawing );
57 ~ShapeContainer();
58
59 /** Returns the drawing this shape container is part of. */
getDrawing()60 inline Drawing& getDrawing() { return mrDrawing; }
61
62 /** Creates and returns a new shape template object. */
63 ShapeType& createShapeType();
64 /** Creates and returns a new shape object of the specified type. */
65 template< typename ShapeT >
66 ShapeT& createShape();
67
68 /** Final processing after import of the drawing fragment. */
69 void finalizeFragmentImport();
70
71 /** Returns true, if this contaikner does not contain any shapes. */
empty() const72 inline bool empty() const { return maShapes.empty(); }
73
74 /** Returns the shape template with the passed identifier.
75 @param bDeep True = searches in all group shapes too. */
76 const ShapeType* getShapeTypeById( const ::rtl::OUString& rShapeId, bool bDeep ) const;
77 /** Returns the shape with the passed identifier.
78 @param bDeep True = searches in all group shapes too. */
79 const ShapeBase* getShapeById( const ::rtl::OUString& rShapeId, bool bDeep ) const;
80
81 /** Searches for a shape type by using the passed functor that takes a
82 constant reference of a ShapeType object. */
83 template< typename Functor >
84 const ShapeType* findShapeType( const Functor& rFunctor ) const;
85 /** Searches for a shape by using the passed functor that takes a constant
86 reference of a ShapeBase object. */
87 template< typename Functor >
88 const ShapeBase* findShape( const Functor& rFunctor ) const;
89
90 /** Returns the first shape in the collection (Word only). */
91 const ShapeBase* getFirstShape() const;
92
93 /** Creates and inserts all UNO shapes into the passed container. */
94 void convertAndInsert(
95 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
96 const ShapeParentAnchor* pParentAnchor = 0 ) const;
97
98 private:
99 typedef RefVector< ShapeType > ShapeTypeVector;
100 typedef RefVector< ShapeBase > ShapeVector;
101 typedef RefMap< ::rtl::OUString, ShapeType > ShapeTypeMap;
102 typedef RefMap< ::rtl::OUString, ShapeBase > ShapeMap;
103
104 Drawing& mrDrawing; /// The VML drawing page that contains this shape.
105 ShapeTypeVector maTypes; /// All shape templates.
106 ShapeVector maShapes; /// All shape definitions.
107 ShapeTypeMap maTypesById; /// All shape templates mapped by identifier.
108 ShapeMap maShapesById; /// All shape definitions mapped by identifier.
109 };
110
111 // ----------------------------------------------------------------------------
112
113 template< typename ShapeT >
createShape()114 ShapeT& ShapeContainer::createShape()
115 {
116 ::boost::shared_ptr< ShapeT > xShape( new ShapeT( mrDrawing ) );
117 maShapes.push_back( xShape );
118 return *xShape;
119 }
120
121 template< typename Functor >
findShapeType(const Functor & rFunctor) const122 const ShapeType* ShapeContainer::findShapeType( const Functor& rFunctor ) const
123 {
124 return maTypes.findIf( rFunctor ).get();
125 }
126
127 template< typename Functor >
findShape(const Functor & rFunctor) const128 const ShapeBase* ShapeContainer::findShape( const Functor& rFunctor ) const
129 {
130 return maShapes.findIf( rFunctor ).get();
131 }
132
133 // ============================================================================
134
135 } // namespace vml
136 } // namespace oox
137
138 #endif
139