1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/awt/Rectangle.hpp>
24 #include <oox/helper/refmap.hxx>
25 #include <oox/helper/refvector.hxx>
28 namespace com
{ namespace sun
{ namespace star
{
29 namespace drawing
{ class XShapes
; }
40 struct ShapeParentAnchor
42 css::awt::Rectangle maShapeRect
;
43 css::awt::Rectangle maCoordSys
;
47 /** Container that holds a list of shapes and shape templates. */
51 explicit ShapeContainer( Drawing
& rDrawing
);
54 /** Returns the drawing this shape container is part of. */
55 Drawing
& getDrawing() { return mrDrawing
; }
57 /** Creates and returns a new shape template object. */
58 ShapeType
& createShapeType();
59 /** Creates and returns a new shape object of the specified type. */
60 template< typename ShapeT
>
61 ShapeT
& createShape();
63 /** Final processing after import of the drawing fragment. */
64 void finalizeFragmentImport();
66 /** Returns true, if this container does not contain any shapes. */
67 bool empty() const { return maShapes
.empty(); }
69 /** Returns the shape template with the passed identifier.
70 @param bDeep True = searches in all group shapes too. */
71 const ShapeType
* getShapeTypeById( const OUString
& rShapeId
, bool bDeep
) const;
72 /** Returns the shape with the passed identifier.
73 @param bDeep True = searches in all group shapes too. */
74 const ShapeBase
* getShapeById( const OUString
& rShapeId
, bool bDeep
) const;
76 /** Searches for a shape by using the passed functor that takes a constant
77 reference of a ShapeBase object. */
78 template< typename Functor
>
79 const ShapeBase
* findShape( const Functor
& rFunctor
) const;
82 (Word only) Returns the last shape in the collection, if it is after the last
83 mark from pushMark(), and removes it.
85 std::shared_ptr
< ShapeBase
> takeLastShape();
87 Adds a recursion mark to the stack. It is possible that a shape contains <w:txbxContent>
88 which contains another shape, and writerfilter needs to know which shape is from the inner
89 ooxml context and which from the outer ooxml context, while it is necessary to keep
90 at least shape types across such blocks. Therefore this function marks beginning
91 of each shape xml block, and takeLastShape() returns only shapes from this block.
95 Removes a recursion mark.
99 /** Creates and inserts all UNO shapes into the passed container. */
100 void convertAndInsert(
101 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
102 const ShapeParentAnchor
* pParentAnchor
= nullptr ) const;
105 typedef RefVector
< ShapeType
> ShapeTypeVector
;
106 typedef RefVector
< ShapeBase
> ShapeVector
;
107 typedef RefMap
< OUString
, ShapeType
> ShapeTypeMap
;
108 typedef RefMap
< OUString
, ShapeBase
> ShapeMap
;
110 Drawing
& mrDrawing
; ///< The VML drawing page that contains this shape.
111 ShapeTypeVector maTypes
; ///< All shape templates.
112 ShapeVector maShapes
; ///< All shape definitions.
113 ShapeTypeMap maTypesById
; ///< All shape templates mapped by identifier.
114 ShapeMap maShapesById
; ///< All shape definitions mapped by identifier.
115 std::stack
< size_t > markStack
; ///< Recursion marks from pushMark()/popMark().
119 template< typename ShapeT
>
120 ShapeT
& ShapeContainer::createShape()
122 std::shared_ptr
< ShapeT
> xShape( new ShapeT( mrDrawing
) );
123 maShapes
.push_back( xShape
);
127 template< typename Functor
>
128 const ShapeBase
* ShapeContainer::findShape( const Functor
& rFunctor
) const
130 return maShapes
.findIf( rFunctor
).get();
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */