LibreOffice Module oox (master)  1
vmlshapecontainer.cxx
Go to the documentation of this file.
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 
21 
22 #include <oox/vml/vmldrawing.hxx>
23 #include <oox/vml/vmlshape.hxx>
24 
25 #include <osl/diagnose.h>
26 
27 namespace oox::vml {
28 
29 using namespace ::com::sun::star::awt;
30 using namespace ::com::sun::star::drawing;
31 using namespace ::com::sun::star::uno;
32 
33 namespace {
34 
35 template< typename ShapeType >
36 void lclMapShapesById( RefMap< OUString, ShapeType >& orMap, const RefVector< ShapeType >& rVector )
37 {
38  for (auto const& elem : rVector)
39  {
40  const OUString& rShapeId = elem->getShapeId();
41  OSL_ENSURE( !rShapeId.isEmpty(), "lclMapShapesById - missing shape identifier" );
42  if( !rShapeId.isEmpty() )
43  {
44  OSL_ENSURE( orMap.find( rShapeId ) == orMap.end(), "lclMapShapesById - shape identifier already used " );
45  orMap[ rShapeId ] = elem;
46  }
47  }
48 }
49 
50 } // namespace
51 
53  mrDrawing( rDrawing )
54 {
55 }
56 
58 {
59 }
60 
61 std::shared_ptr<ShapeType> ShapeContainer::createShapeType()
62 {
63  auto xShape = std::make_shared<ShapeType>( mrDrawing );
64  maTypes.push_back( xShape );
65  return xShape;
66 }
67 
69 {
70  // map all shape templates by shape identifier
71  lclMapShapesById( maTypesById, maTypes );
72  // map all shapes by shape identifier
73  lclMapShapesById( maShapesById, maShapes );
74  /* process all shapes (map all children templates/shapes in group shapes,
75  resolve template references in all shapes) */
77 }
78 
79 const ShapeType* ShapeContainer::getShapeTypeById( const OUString& rShapeId ) const
80 {
81  if (maTypesById.empty() && !maTypes.empty())
82  {
83  lclMapShapesById(const_cast<ShapeTypeMap&>(maTypesById), maTypes);
84  }
85 
86  // search in own shape template list
87  if( const ShapeType* pType = maTypesById.get( rShapeId ).get() )
88  return pType;
89  // search deep in child shapes
90  for (auto const& shape : maShapes)
91  if( const ShapeType* pType = shape->getChildTypeById( rShapeId ) )
92  return pType;
93  return nullptr;
94 }
95 
96 const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId ) const
97 {
98  // search in own shape list
99  if( const ShapeBase* pShape = maShapesById.get( rShapeId ).get() )
100  return pShape;
101  // search deep in child shapes
102  for (auto const& shape : maShapes)
103  if( const ShapeBase* pShape = shape->getChildById( rShapeId ) )
104  return pShape;
105  return nullptr;
106 }
107 
108 std::shared_ptr< ShapeBase > ShapeContainer::takeLastShape()
109 {
110  OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::takeLastShape - illegal call, Word filter only" );
111  assert( !markStack.empty());
112  if( markStack.top() >= maShapes.size())
113  return std::shared_ptr< ShapeBase >();
114  std::shared_ptr< ShapeBase > ret = maShapes.back();
115  maShapes.pop_back();
116  return ret;
117 }
118 
120 {
121  markStack.push( maShapes.size());
122 }
123 
125 {
126  assert( !markStack.empty());
127  markStack.pop();
128 }
129 
130 void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
131 {
132  for (auto const& shape : maShapes)
133  shape->convertAndInsert( rxShapes, pParentAnchor );
134 }
135 
136 } // namespace oox::vml
137 
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Drawing & mrDrawing
The VML drawing page that contains this shape.
std::shared_ptr< ShapeType > createShapeType()
Creates and returns a new shape template object.
A shape object that is part of a drawing.
Definition: vmlshape.hxx:234
const ShapeBase * getShapeById(const OUString &rShapeId) const
Returns the shape with the passed identifier.
void pushMark()
Adds a recursion mark to the stack.
void convertAndInsert(const css::uno::Reference< css::drawing::XShapes > &rxShapes, const ShapeParentAnchor *pParentAnchor=nullptr) const
Creates and inserts all UNO shapes into the passed container.
A shape template contains all formatting properties of shapes and can serve as templates for several ...
Definition: vmlshape.hxx:125
void popMark()
Removes a recursion mark.
ShapeMap maShapesById
All shape definitions mapped by identifier.
void forEachMem(FuncType pFunc) const
Calls the passed member function of ObjType on every contained object, automatically skips all elemen...
Definition: refvector.hxx:68
virtual void finalizeFragmentImport()
Final processing after import of the drawing fragment.
Definition: vmlshape.cxx:288
DrawingType getType() const
Returns the application type containing the drawing.
Definition: vmldrawing.hxx:106
const ShapeType * getShapeTypeById(const OUString &rShapeId) const
Returns the shape template with the passed identifier.
ShapeContainer(Drawing &rDrawing)
std::stack< size_t > markStack
Recursion marks from pushMark()/popMark().
Word: One shape per drawing.
Definition: vmldrawing.hxx:55
void finalizeFragmentImport()
Final processing after import of the drawing fragment.
ShapeTypeVector maTypes
All shape templates.
std::shared_ptr< ShapeBase > takeLastShape()
(Word only) Returns the last shape in the collection, if it is after the last mark from pushMark()...
mapped_type get(key_type nKey) const
Returns a reference to the object associated to the passed key, or an empty reference on error...
Definition: refmap.hxx:59
ShapeVector maShapes
All shape definitions.
Represents the collection of VML shapes for a complete draw page.
Definition: vmldrawing.hxx:93
ShapeTypeMap maTypesById
All shape templates mapped by identifier.
virtual const ShapeBase * getChildById(const OUString &rShapeId) const
Returns the shape with the passed identifier from the child shapes.
Definition: vmlshape.cxx:346