Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / inc / shape.hxx
blobd3cf3b817331d288d15fa396d0790b5d9cc78f68
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>
25 #include <com/sun/star/drawing/XDrawPage.hpp>
27 #include <basegfx/range/b2drectangle.hxx>
29 #include "viewlayer.hxx"
31 #include <memory>
32 #include <set>
33 #include <vector>
35 namespace basegfx {
36 class B2DRange;
39 namespace slideshow
41 namespace internal
43 // forward declaration necessary, because methods use ShapeSharedPtr
44 class Shape;
46 typedef ::std::shared_ptr< Shape > ShapeSharedPtr;
48 /** Represents a slide's shape object.
50 This interface represents the view-independent aspects of a
51 slide's shape, providing bound rect, underlying XShape and
52 basic paint methods.
54 class Shape
56 public:
57 Shape() = default;
58 virtual ~Shape() {}
59 Shape(const Shape&) = delete;
60 Shape& operator=(const Shape&) = delete;
62 /** Get the associated XShape of this shape.
64 @return the associated XShape. If this method returns
65 an empty reference, this object might be one of the
66 special-purpose shapes of a slide, which have no
67 direct corresponding XShape (the background comes to
68 mind here).
70 virtual css::uno::Reference< css::drawing::XShape > getXShape() const = 0;
73 // View layer methods
76 /** Add a new view layer.
78 This method adds a new view layer, this shape shall
79 show itself on.
81 @param rNewLayer
82 New layer to show on
84 @param bRedrawLayer
85 Redraw shape on given layer
87 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
88 bool bRedrawLayer ) = 0;
90 /** Withdraw the shape from a view layer
92 This method removes the shape from the given view
93 layer.
95 @return true, if the shape was successfully removed
97 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) = 0;
99 /** Withdraw all view layers at once
101 This method will be faster than repeated
102 removeViewLayer() calls.
104 virtual void clearAllViewLayers() = 0;
106 // render methods
109 /** Update the shape
111 This method updates the Shape on all registered view
112 layers, but only if shape content has actually
113 changed.
115 @return whether the update finished successfully.
117 virtual bool update() const = 0;
119 /** Render the shape.
121 This method renders the shape on all registered view
122 layers, regardless of whether shape content has
123 changed or not.
125 @return whether the rendering finished successfully.
127 virtual bool render() const = 0;
129 /** Query whether shape content changed
131 This method returns true, if shape content changed
132 since the last rendering (i.e. the shape needs an
133 update to reflect that changed content on the views).
135 virtual bool isContentChanged() const = 0;
138 // Shape attributes
141 /** Get the current shape position and size.
143 This method yields the currently effective shape
144 bounds (which might change over time, for animated
145 shapes). Please note that possibly shape rotations
146 from its original document state must not be taken
147 into account here: if you need the screen bounding
148 box, use getUpdateArea() instead. Note further that
149 shape rotations, which are already contained in the
150 shape as displayed in the original document
151 <em>are</em> included herein (we currently take the
152 shape as-is from the document, assuming a rotation
153 angle of 0).
155 virtual ::basegfx::B2DRange getBounds() const = 0;
157 /** Get the DOM position and size of the shape.
159 This method yields the underlying DOM shape bounds,
160 i.e. the original shape bounds from the document
161 model. This value is <em>always</em> unaffected by any
162 animation activity. Note that shape rotations, which
163 are already contained in the shape as displayed in the
164 original document are already included herein (we
165 currently take the shape as-is from the document,
166 assuming a rotation angle of 0).
168 virtual ::basegfx::B2DRange getDomBounds() const = 0;
170 /** Get the current shape update area.
172 This method yields the currently effective update area
173 for the shape, i.e. the area that needs to be updated,
174 should the shape be painted. Normally, this will be
175 the (possibly rotated and sheared) area returned by
176 getBounds().
178 virtual ::basegfx::B2DRange getUpdateArea() const = 0;
180 /** Query whether the shape is visible at all.
182 @return true, if this shape is visible, false
183 otherwise.
185 virtual bool isVisible() const = 0;
187 /** Get the shape priority.
189 The shape priority defines the relative order of the
190 shapes on the slide.
192 @return the priority. Will be in the [0,+infty) range.
194 virtual double getPriority() const = 0;
196 /** Query whether the Shape is currently detached from the
197 background.
199 This method checks whether the Shape is currently
200 detached from the slide background, i.e. whether shape
201 updates affect the underlying slide background or
202 not. A shape that returnes true here must not alter
203 slide content in any way when called render() or
204 update() (this is normally achieved by making this
205 shape a sprite).
207 virtual bool isBackgroundDetached() const = 0;
209 // Misc
212 /** Functor struct, for shape ordering
214 This defines a strict weak ordering of shapes, primary
215 sort key is the shape priority, and secondary sort key
216 the object ptr value. Most typical use is for
217 associative containers holding shapes (and which also
218 have to maintain something like a paint order).
220 struct lessThanShape
222 // make functor adaptable (to boost::bind)
223 typedef bool result_type;
225 // since the ZOrder property on the XShape has somewhat
226 // peculiar attributes (it's basically the index of the shapes
227 // in the drawing layer's SdrObjList - which means, it starts
228 // from 0 for children of group objects), we cannot use it to determine
229 // drawing order. Thus, we rely on importer-provided order values here,
230 // which is basically a running counter during shape import (i.e. denotes
231 // the order of shape import). This is the correct order, at least for the
232 // current drawing core.
234 // If, someday, the above proposition is no longer true, one directly use
235 // the shape's ZOrder property
237 static bool compare(const Shape* pLHS, const Shape* pRHS)
239 const double nPrioL( pLHS->getPriority() );
240 const double nPrioR( pRHS->getPriority() );
242 // if prios are equal, tie-break on ptr value
243 return nPrioL == nPrioR ? pLHS < pRHS : nPrioL < nPrioR;
246 bool operator()(const ShapeSharedPtr& rLHS, const ShapeSharedPtr& rRHS) const
248 return compare(rLHS.get(),rRHS.get());
254 typedef ::std::shared_ptr< Shape > ShapeSharedPtr;
256 /** A set which contains all shapes in an ordered fashion.
258 typedef ::std::set< ShapeSharedPtr, Shape::lessThanShape > ShapeSet;
262 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_SHAPE_HXX
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */