crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / slideshow / source / inc / shape.hxx
blobbbd2988e0254e6954581e23b32dbcb2dc7ec2573
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_SLIDESHOW_SOURCE_INC_SHAPE_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_INC_SHAPE_HXX
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/drawing/XShape.hpp>
26 #include <basegfx/range/b2drectangle.hxx>
28 #include "viewlayer.hxx"
30 #include <memory>
31 #include <set>
33 namespace basegfx {
34 class B2DRange;
37 namespace slideshow::internal
39 // forward declaration necessary, because methods use ShapeSharedPtr
40 class Shape;
42 typedef ::std::shared_ptr< Shape > ShapeSharedPtr;
44 /** Represents a slide's shape object.
46 This interface represents the view-independent aspects of a
47 slide's shape, providing bound rect, underlying XShape and
48 basic paint methods.
50 class Shape
52 public:
53 Shape() : mbIsForeground(true) {}
54 virtual ~Shape() {}
55 Shape(const Shape&) = delete;
56 Shape& operator=(const Shape&) = delete;
58 /** Get the associated XShape of this shape.
60 @return the associated XShape. If this method returns
61 an empty reference, this object might be one of the
62 special-purpose shapes of a slide, which have no
63 direct corresponding XShape (the background comes to
64 mind here).
66 virtual css::uno::Reference< css::drawing::XShape > getXShape() const = 0;
69 // View layer methods
72 /** Add a new view layer.
74 This method adds a new view layer, this shape shall
75 show itself on.
77 @param rNewLayer
78 New layer to show on
80 @param bRedrawLayer
81 Redraw shape on given layer
83 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
84 bool bRedrawLayer ) = 0;
86 /** Withdraw the shape from a view layer
88 This method removes the shape from the given view
89 layer.
91 @return true, if the shape was successfully removed
93 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) = 0;
95 /** Withdraw all view layers at once
97 This method will be faster than repeated
98 removeViewLayer() calls.
100 virtual void clearAllViewLayers() = 0;
102 // render methods
105 /** Update the shape
107 This method updates the Shape on all registered view
108 layers, but only if shape content has actually
109 changed.
111 @return whether the update finished successfully.
113 virtual bool update() const = 0;
115 /** Render the shape.
117 This method renders the shape on all registered view
118 layers, regardless of whether shape content has
119 changed or not.
121 @return whether the rendering finished successfully.
123 virtual bool render() const = 0;
125 /** Query whether shape content changed
127 This method returns true, if shape content changed
128 since the last rendering (i.e. the shape needs an
129 update to reflect that changed content on the views).
131 virtual bool isContentChanged() const = 0;
134 // Shape attributes
137 /** Get the current shape position and size.
139 This method yields the currently effective shape
140 bounds (which might change over time, for animated
141 shapes). Please note that possibly shape rotations
142 from its original document state must not be taken
143 into account here: if you need the screen bounding
144 box, use getUpdateArea() instead. Note further that
145 shape rotations, which are already contained in the
146 shape as displayed in the original document
147 <em>are</em> included herein (we currently take the
148 shape as-is from the document, assuming a rotation
149 angle of 0).
151 virtual ::basegfx::B2DRectangle getBounds() const = 0;
153 /** Get the DOM position and size of the shape.
155 This method yields the underlying DOM shape bounds,
156 i.e. the original shape bounds from the document
157 model. This value is <em>always</em> unaffected by any
158 animation activity. Note that shape rotations, which
159 are already contained in the shape as displayed in the
160 original document are already included herein (we
161 currently take the shape as-is from the document,
162 assuming a rotation angle of 0).
164 virtual ::basegfx::B2DRectangle getDomBounds() const = 0;
166 /** Get the current shape update area.
168 This method yields the currently effective update area
169 for the shape, i.e. the area that needs to be updated,
170 should the shape be painted. Normally, this will be
171 the (possibly rotated and sheared) area returned by
172 getBounds().
174 virtual ::basegfx::B2DRectangle getUpdateArea() const = 0;
176 /** Query whether the shape is visible at all.
178 @return true, if this shape is visible, false
179 otherwise.
181 virtual bool isVisible() const = 0;
183 /** Get the shape priority.
185 The shape priority defines the relative order of the
186 shapes on the slide.
188 @return the priority. Will be in the [0,+infty) range.
190 virtual double getPriority() const = 0;
192 /** Query whether the Shape is currently detached from the
193 background.
195 This method checks whether the Shape is currently
196 detached from the slide background, i.e. whether shape
197 updates affect the underlying slide background or
198 not. A shape that returns true here must not alter
199 slide content in any way when called render() or
200 update() (this is normally achieved by making this
201 shape a sprite).
203 virtual bool isBackgroundDetached() const = 0;
205 /** Check whether the shape belongs to the foreground
207 For instance, if the shape is in the master slide
208 it does not belong to the foreground.
210 @return true if the shape is on the foreground
212 virtual bool isForeground() const { return mbIsForeground; };
215 Set the flag that holds whether the shape is
216 in the foreground or not
218 @param bIsForeground
219 Shape is on the foreground
221 virtual void setIsForeground( const bool bIsForeground ) { mbIsForeground = bIsForeground; };
223 // Misc
226 /** Functor struct, for shape ordering
228 This defines a strict weak ordering of shapes, primary
229 sort key is the shape priority, and secondary sort key
230 the object ptr value. Most typical use is for
231 associative containers holding shapes (and which also
232 have to maintain something like a paint order).
234 struct lessThanShape
236 // make functor adaptable (to boost::bind)
237 typedef bool result_type;
239 // since the ZOrder property on the XShape has somewhat
240 // peculiar attributes (it's basically the index of the shapes
241 // in the drawing layer's SdrObjList - which means, it starts
242 // from 0 for children of group objects), we cannot use it to determine
243 // drawing order. Thus, we rely on importer-provided order values here,
244 // which is basically a running counter during shape import (i.e. denotes
245 // the order of shape import). This is the correct order, at least for the
246 // current drawing core.
248 // If, someday, the above proposition is no longer true, one directly use
249 // the shape's ZOrder property
251 static bool compare(const Shape* pLHS, const Shape* pRHS)
253 const double nPrioL( pLHS->getPriority() );
254 const double nPrioR( pRHS->getPriority() );
256 // if prios are equal, tie-break on ptr value
257 return nPrioL == nPrioR ? pLHS < pRHS : nPrioL < nPrioR;
260 bool operator()(const ShapeSharedPtr& rLHS, const ShapeSharedPtr& rRHS) const
262 return compare(rLHS.get(),rRHS.get());
267 private:
268 /** Flag to check whether the shape belongs to the foreground.
270 For instance, it is false if the shape belongs to the master slide.
272 bool mbIsForeground;
275 /** A set which contains all shapes in an ordered fashion.
277 typedef ::std::set< ShapeSharedPtr, Shape::lessThanShape > ShapeSet;
281 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_SHAPE_HXX
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */