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 : #ifndef INCLUDED_OOX_VML_VMLSHAPECONTAINER_HXX
21 : #define INCLUDED_OOX_VML_VMLSHAPECONTAINER_HXX
22 :
23 : #include <com/sun/star/awt/Rectangle.hpp>
24 : #include <oox/helper/refmap.hxx>
25 : #include <oox/helper/refvector.hxx>
26 : #include <stack>
27 :
28 : namespace com { namespace sun { namespace star {
29 : namespace drawing { class XShapes; }
30 : } } }
31 :
32 : namespace oox {
33 : namespace vml {
34 :
35 : class Drawing;
36 : class ShapeType;
37 : class ShapeBase;
38 :
39 :
40 :
41 0 : struct ShapeParentAnchor
42 : {
43 : ::com::sun::star::awt::Rectangle maShapeRect;
44 : ::com::sun::star::awt::Rectangle maCoordSys;
45 : };
46 :
47 :
48 :
49 : /** Container that holds a list of shapes and shape templates. */
50 : class ShapeContainer
51 : {
52 : public:
53 : explicit ShapeContainer( Drawing& rDrawing );
54 : ~ShapeContainer();
55 :
56 : /** Returns the drawing this shape container is part of. */
57 0 : Drawing& getDrawing() { return mrDrawing; }
58 :
59 : /** Creates and returns a new shape template object. */
60 : ShapeType& createShapeType();
61 : /** Creates and returns a new shape object of the specified type. */
62 : template< typename ShapeT >
63 : ShapeT& createShape();
64 :
65 : /** Final processing after import of the drawing fragment. */
66 : void finalizeFragmentImport();
67 :
68 : /** Returns true, if this container does not contain any shapes. */
69 0 : bool empty() const { return maShapes.empty(); }
70 :
71 : /** Returns the shape template with the passed identifier.
72 : @param bDeep True = searches in all group shapes too. */
73 : const ShapeType* getShapeTypeById( const OUString& rShapeId, bool bDeep ) const;
74 : /** Returns the shape with the passed identifier.
75 : @param bDeep True = searches in all group shapes too. */
76 : const ShapeBase* getShapeById( const OUString& rShapeId, bool bDeep ) const;
77 :
78 : /** Searches for a shape type by using the passed functor that takes a
79 : constant reference of a ShapeType object. */
80 : template< typename Functor >
81 : const ShapeType* findShapeType( const Functor& rFunctor ) const;
82 : /** Searches for a shape by using the passed functor that takes a constant
83 : reference of a ShapeBase object. */
84 : template< typename Functor >
85 : const ShapeBase* findShape( const Functor& rFunctor ) const;
86 :
87 : /**
88 : (Word only) Returns the last shape in the collection, if it is after the last
89 : mark from pushMark(), and removes it.
90 : */
91 : boost::shared_ptr< ShapeBase > takeLastShape();
92 : /**
93 : Adds a recursion mark to the stack. It is possible that a shape contains <w:txbxContent>
94 : which contains another shape, and writerfilter needs to know which shape is from the inner
95 : ooxml context and which from the outer ooxml context, while it is necessary to keep
96 : at least shape types across such blocks. Therefore this function marks beginning
97 : of each shape xml block, and takeLastShape() returns only shapes from this block.
98 : */
99 : void pushMark();
100 : /**
101 : Removes a recursion mark.
102 : */
103 : void popMark();
104 :
105 : /** Creates and inserts all UNO shapes into the passed container. */
106 : void convertAndInsert(
107 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
108 : const ShapeParentAnchor* pParentAnchor = 0 ) const;
109 :
110 : private:
111 : typedef RefVector< ShapeType > ShapeTypeVector;
112 : typedef RefVector< ShapeBase > ShapeVector;
113 : typedef RefMap< OUString, ShapeType > ShapeTypeMap;
114 : typedef RefMap< OUString, ShapeBase > ShapeMap;
115 :
116 : Drawing& mrDrawing; ///< The VML drawing page that contains this shape.
117 : ShapeTypeVector maTypes; ///< All shape templates.
118 : ShapeVector maShapes; ///< All shape definitions.
119 : ShapeTypeMap maTypesById; ///< All shape templates mapped by identifier.
120 : ShapeMap maShapesById; ///< All shape definitions mapped by identifier.
121 : std::stack< size_t > markStack; ///< Recursion marks from pushMark()/popMark().
122 : };
123 :
124 :
125 :
126 : template< typename ShapeT >
127 0 : ShapeT& ShapeContainer::createShape()
128 : {
129 0 : ::boost::shared_ptr< ShapeT > xShape( new ShapeT( mrDrawing ) );
130 0 : maShapes.push_back( xShape );
131 0 : return *xShape;
132 : }
133 :
134 : template< typename Functor >
135 : const ShapeType* ShapeContainer::findShapeType( const Functor& rFunctor ) const
136 : {
137 : return maTypes.findIf( rFunctor ).get();
138 : }
139 :
140 : template< typename Functor >
141 0 : const ShapeBase* ShapeContainer::findShape( const Functor& rFunctor ) const
142 : {
143 0 : return maShapes.findIf( rFunctor ).get();
144 : }
145 :
146 :
147 :
148 : } // namespace vml
149 : } // namespace oox
150 :
151 : #endif
152 :
153 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|