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