Bump version to 6.4-15
[LibreOffice.git] / include / oox / vml / vmlshapecontainer.hxx
blob72fc9286536e65492d96149f1b1a327789631ba3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_VML_VMLSHAPECONTAINER_HXX
21 #define INCLUDED_OOX_VML_VMLSHAPECONTAINER_HXX
23 #include <cstddef>
24 #include <functional>
25 #include <memory>
26 #include <stack>
28 #include <com/sun/star/awt/Rectangle.hpp>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <oox/helper/refmap.hxx>
31 #include <oox/helper/refvector.hxx>
32 #include <rtl/ustring.hxx>
34 namespace com { namespace sun { namespace star {
35 namespace drawing { class XShapes; }
36 } } }
38 namespace oox {
39 namespace vml {
41 class Drawing;
42 class ShapeType;
43 class ShapeBase;
46 struct ShapeParentAnchor
48 css::awt::Rectangle maShapeRect;
49 css::awt::Rectangle maCoordSys;
53 /** Container that holds a list of shapes and shape templates. */
54 class ShapeContainer
56 public:
57 explicit ShapeContainer( Drawing& rDrawing );
58 ~ShapeContainer();
60 /** Returns the drawing this shape container is part of. */
61 Drawing& getDrawing() { return mrDrawing; }
63 /** Creates and returns a new shape template object. */
64 std::shared_ptr<ShapeType> createShapeType();
65 /** Creates and returns a new shape object of the specified type. */
66 template< typename ShapeT >
67 std::shared_ptr<ShapeT> createShape();
69 /** Final processing after import of the drawing fragment. */
70 void finalizeFragmentImport();
72 /** Returns true, if this container does not contain any shapes. */
73 bool empty() const { return maShapes.empty(); }
75 /** Returns the shape template with the passed identifier.
76 Searches in all group shapes too. */
77 const ShapeType* getShapeTypeById( const OUString& rShapeId ) const;
78 /** Returns the shape with the passed identifier.
79 Searches in all group shapes too. */
80 const ShapeBase* getShapeById( const OUString& rShapeId ) 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;
87 /**
88 (Word only) Returns the last shape in the collection, if it is after the last
89 mark from pushMark(), and removes it.
91 std::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.
99 void pushMark();
101 Removes a recursion mark.
103 void popMark();
105 /** Creates and inserts all UNO shapes into the passed container. */
106 void convertAndInsert(
107 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
108 const ShapeParentAnchor* pParentAnchor = nullptr ) const;
110 private:
111 typedef RefVector< ShapeType > ShapeTypeVector;
112 typedef RefVector< ShapeBase > ShapeVector;
113 typedef RefMap< OUString, ShapeType > ShapeTypeMap;
114 typedef RefMap< OUString, ShapeBase > ShapeMap;
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().
125 template< typename ShapeT >
126 std::shared_ptr<ShapeT> ShapeContainer::createShape()
128 std::shared_ptr< ShapeT > xShape( new ShapeT( mrDrawing ) );
129 xShape->setContainer(this);
130 maShapes.push_back( xShape );
131 return xShape;
134 template< typename Functor >
135 const ShapeBase* ShapeContainer::findShape( const Functor& rFunctor ) const
137 return maShapes.findIf( rFunctor ).get();
141 } // namespace vml
142 } // namespace oox
144 #endif
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */