fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / slide / layermanager.hxx
blob76a369e26ea98b43a3cacbc6949584a55d9aef41
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_ENGINE_SLIDE_LAYERMANAGER_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYERMANAGER_HXX
23 #include <boost/shared_ptr.hpp>
24 #include <boost/noncopyable.hpp>
26 #include <cppcanvas/spritecanvas.hxx>
28 #include "unoview.hxx"
29 #include "unoviewcontainer.hxx"
30 #include "attributableshape.hxx"
31 #include "layer.hxx"
32 #include "tools.hxx"
34 #include <algorithm>
35 #include <functional>
36 #include <map>
37 #include <unordered_map>
38 #include <vector>
40 namespace basegfx {
41 class B2DRange;
44 namespace slideshow
46 namespace internal
48 /* Definition of Layermanager class */
50 /** This class manages all of a slide's layers (and shapes)
52 Since layer content changes when animations start or end,
53 the layer manager keeps track of this and also handles
54 starting/stopping of Shape animations. Note that none of
55 the methods actually perform a screen update, this is
56 always delayed until the ActivitiesQueue explicitly
57 performs it.
59 @see Layer
60 @see Shape
62 class LayerManager : private boost::noncopyable
64 public:
65 /** Create a new layer manager for the given page bounds
67 @param rViews
68 Views currently registered
70 @param rPageBounds
71 Overall page bounds, in user space coordinates
73 @param bDisableAnimationZOrder
74 When true, all sprite animations run in the
75 foreground. That is, no extra layers are created, and
76 the slideshow runs potentially faster.
78 LayerManager( const UnoViewContainer& rViews,
79 const ::basegfx::B2DRange& rPageBounds,
80 bool bDisableAnimationZOrder );
82 /** Activate the LayerManager
84 This method activates the LayerManager. Prior to
85 activation, this instance will be passive, i.e. won't
86 render anything to any view.
88 @param bSlideBackgoundPainted
89 When true, the initial slide content on the background
90 layer is already rendered (e.g. from a previous slide
91 transition). When false, LayerManager also renders
92 initial content of background layer on next update()
93 call.
95 void activate( bool bSlideBackgoundPainted );
97 /** Deactivate the LayerManager
99 This method deactivates the LayerManager. After
100 deactivation, this instance will be passive,
101 i.e. don't render anything to any view. Furthermore,
102 if there's currently more than one Layer active, this
103 method also removes all but one.
105 void deactivate();
107 // From ViewEventHandler, forwarded by SlideImpl
108 /// Notify new view added to UnoViewContainer
109 void viewAdded( const UnoViewSharedPtr& rView );
110 /// Notify view removed from UnoViewContainer
111 void viewRemoved( const UnoViewSharedPtr& rView );
112 void viewChanged( const UnoViewSharedPtr& rView );
113 void viewsChanged();
115 /** Add the shape to this object
117 This method adds a shape to the page.
119 void addShape( const ShapeSharedPtr& rShape );
121 /** Lookup a Shape from an XShape model object
123 This method looks up the internal shape map for one
124 representing the given XShape.
126 @param xShape
127 The XShape object, for which the representing Shape
128 should be looked up.
130 ShapeSharedPtr lookupShape( const ::com::sun::star::uno::Reference<
131 ::com::sun::star::drawing::XShape >& xShape ) const;
133 /** Query a subset of the given original shape
135 This method queries a new (but not necessarily unique)
136 shape, which displays only the given subset of the
137 original one.
139 AttributableShapeSharedPtr getSubsetShape( const AttributableShapeSharedPtr& rOrigShape,
140 const DocTreeNode& rTreeNode );
142 /** Revoke a previously queried subset shape.
144 With this method, a previously requested subset shape
145 is revoked again. If the last client revokes a given
146 subset, it will cease to be displayed, and the
147 original shape will again show the subset data.
149 @param rOrigShape
150 The shape the subset was created from
152 @param rSubsetShape
153 The subset created from rOrigShape
155 void revokeSubset( const AttributableShapeSharedPtr& rOrigShape,
156 const AttributableShapeSharedPtr& rSubsetShape );
158 /** Notify the LayerManager that the given Shape starts an
159 animation now.
161 This method enters animation mode for the Shape on all
162 registered views.
164 void enterAnimationMode( const AnimatableShapeSharedPtr& rShape );
166 /** Notify the LayerManager that the given Shape is no
167 longer animated.
169 This methods ends animation mode for the given Shape
170 on all registered views.
172 void leaveAnimationMode( const AnimatableShapeSharedPtr& rShape );
174 /** Notify that a shape needs an update
176 This method notifies the layer manager that a shape
177 update is necessary. This is useful if, during
178 animation playback, changes occur to shapes which make
179 an update necessary on an update() call. Otherwise,
180 update() will not render anything, which is not
181 triggered by calling one of the other LayerManager
182 methods.
184 @param rShape
185 Shape which needs an update
187 void notifyShapeUpdate( const ShapeSharedPtr& rShape);
189 /** Check whether any update operations are pending.
191 @return true, if this LayerManager has any updates
192 pending, i.e. needs to repaint something for the next
193 frame.
195 bool isUpdatePending() const;
197 /** Update the content
199 This method updates the content on all layers on all
200 registered views. It does not issues a
201 View::updateScreen() call on registered views. Please
202 note that this method only takes into account changes
203 to shapes induced directly by calling methods of the
204 LayerManager. If a shape needs an update, because of
205 some external event unknown to the LayerManager (most
206 notably running animations), you have to notify the
207 LayerManager via notifyShapeUpdate().
209 @see LayerManager::updateScreen()
211 @return whether the update finished successfully.
213 bool update();
215 /** Render the content to given canvas
217 This is a one-shot operation, which simply draws all
218 shapes onto the given canvas, without any caching or
219 other fuzz. Don't use that for repeated output onto
220 the same canvas, the View concept is more optimal
221 then.
223 @param rTargetCanvas
224 Target canvas to output onto.
226 bool renderTo( const ::cppcanvas::CanvasSharedPtr& rTargetCanvas ) const;
228 private:
229 /** A hash map which maps the XShape to the corresponding Shape object.
231 Provides quicker lookup than ShapeSet for simple mappings
233 typedef std::unordered_map<
234 ::com::sun::star::uno::Reference<
235 ::com::sun::star::drawing::XShape >,
236 ShapeSharedPtr,
237 hash< ::com::sun::star::uno::Reference<
238 ::com::sun::star::drawing::XShape > > > XShapeHash;
240 class ShapeComparator
242 public:
243 bool operator() (const ShapeSharedPtr& rpS1, const ShapeSharedPtr& rpS2 ) const
245 return Shape::lessThanShape::compare(rpS1.get(), rpS2.get());
248 /** Set of all shapes
250 private:
251 typedef ::std::map< ShapeSharedPtr, LayerWeakPtr, ShapeComparator > LayerShapeMap;
252 typedef ::std::set< ShapeSharedPtr > ShapeUpdateSet;
258 /// Adds shape area to containing layer's damage area
259 void addUpdateArea( ShapeSharedPtr const& rShape );
261 LayerSharedPtr createForegroundLayer() const;
263 /** Push changes from updateShapeLayerAssociations() to current layer
265 Factored-out method that resizes layer, if necessary,
266 assigns correct layer priority, and repaints contained shapes.
268 @param nCurrLayerIndex
269 Index of current layer in maLayers
271 @param aFirstLayerShape
272 Valid iterator out of maAllShapes, denoting the first
273 shape from nCurrLayerIndex
275 @param aEndLayerShapes
276 Valid iterator or end iterator out of maAllShapes,
277 denoting one-behind-the-last shape of nCurrLayerIndex
279 void commitLayerChanges( std::size_t nCurrLayerIndex,
280 LayerShapeMap::const_iterator aFirstLayerShape,
281 LayerShapeMap::const_iterator aEndLayerShapes );
283 /** Init Shape layers with background layer.
285 void putShape2BackgroundLayer( LayerShapeMap::value_type& rShapeEntry );
287 /** Commits any pending layer reorg, due to shapes either
288 entering or leaving animation mode
290 @param bBackgroundLayerPainted
291 When true, LayerManager does not render anything on
292 the background layer. Use this, if background has been
293 updated by other means (e.g. slide transition)
295 void updateShapeLayers( bool bBackgroundLayerPainted );
297 /** Common stuff when adding a shape
299 void implAddShape( const ShapeSharedPtr& rShape );
301 /** Common stuff when removing a shape
303 void implRemoveShape( const ShapeSharedPtr& rShape );
305 /** Add or remove views
307 Sharing duplicate code from viewAdded and viewRemoved
308 method. The only point of variation at those places
309 are removal vs. adding.
311 template<typename LayerFunc,
312 typename ShapeFunc> void manageViews( LayerFunc layerFunc,
313 ShapeFunc shapeFunc );
315 bool updateSprites();
317 /// Registered views
318 const UnoViewContainer& mrViews;
320 /// All layers of this object. Vector owns the layers
321 LayerVector maLayers;
323 /** Contains all shapes with their XShape reference as the key
325 XShapeHash maXShapeHash;
327 /** Set of shapes this LayerManager own
329 Contains the same set of shapes as XShapeHash, but is
330 sorted in z order, for painting and layer
331 association. Set entries are enriched with two flags
332 for buffering animation enable/disable changes, and
333 shape update requests.
335 LayerShapeMap maAllShapes;
337 /** Set of shapes that have requested an update
339 When a shape is member of this set, its maShapes entry
340 has bNeedsUpdate set to true. We maintain this
341 redundant information for faster update processing.
343 ShapeUpdateSet maUpdateShapes;
345 /** Overall slide bounds (in user coordinate
346 system). shapes that exceed this boundary are clipped,
347 thus, layers only need to be of this size.
349 const basegfx::B2DRange maPageBounds;
351 /// Number of shape sprites currently active on this LayerManager
352 sal_Int32 mnActiveSprites;
354 /// sal_True, if shapes might need to move to different layer
355 bool mbLayerAssociationDirty;
357 /// sal_False when deactivated
358 bool mbActive;
360 /** When true, all sprite animations run in the foreground. That
361 is, no extra layers are created, and the slideshow runs
362 potentially faster.
364 bool mbDisableAnimationZOrder;
367 typedef ::boost::shared_ptr< LayerManager > LayerManagerSharedPtr;
371 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYERMANAGER_HXX
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */