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_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYERMANAGER_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYERMANAGER_HXX
23 #include <unoviewcontainer.hxx>
24 #include <attributableshape.hxx>
30 #include <unordered_map>
37 namespace slideshow::internal
39 /** A hash map which maps the XShape to the corresponding Shape object.
41 Provides quicker lookup than ShapeSet for simple mappings
43 typedef std::unordered_map
<
44 css::uno::Reference
< css::drawing::XShape
>,
46 hash
< css::uno::Reference
< css::drawing::XShape
> >
49 /* Definition of Layermanager class */
51 /** This class manages all of a slide's layers (and shapes)
53 Since layer content changes when animations start or end,
54 the layer manager keeps track of this and also handles
55 starting/stopping of Shape animations. Note that none of
56 the methods actually perform a screen update, this is
57 always delayed until the ActivitiesQueue explicitly
66 /** Create a new layer manager for the given page bounds
69 Views currently registered
71 @param bDisableAnimationZOrder
72 When true, all sprite animations run in the
73 foreground. That is, no extra layers are created, and
74 the slideshow runs potentially faster.
76 LayerManager( const UnoViewContainer
& rViews
,
77 bool bDisableAnimationZOrder
);
79 /// Forbid copy construction
80 LayerManager(const LayerManager
&) = delete;
82 /// Forbid copy assignment
83 LayerManager
& operator=(const LayerManager
&) = delete;
85 /** Activate the LayerManager
87 This method activates the LayerManager. Prior to
88 activation, this instance will be passive, i.e. won't
89 render anything to any view.
93 /** Deactivate the LayerManager
95 This method deactivates the LayerManager. After
96 deactivation, this instance will be passive,
97 i.e. don't render anything to any view. Furthermore,
98 if there's currently more than one Layer active, this
99 method also removes all but one.
103 // From ViewEventHandler, forwarded by SlideImpl
104 /// Notify new view added to UnoViewContainer
105 void viewAdded( const UnoViewSharedPtr
& rView
);
106 /// Notify view removed from UnoViewContainer
107 void viewRemoved( const UnoViewSharedPtr
& rView
);
108 void viewChanged( const UnoViewSharedPtr
& rView
);
111 /** Add the shape to this object
113 This method adds a shape to the page.
115 void addShape( const ShapeSharedPtr
& rShape
);
117 /** Remove shape from this object
119 This method removes a shape from the shape.
121 bool removeShape( const ShapeSharedPtr
& rShape
);
123 /** Remove all shapes from this object
125 This method removes all shapes from the page.
127 void removeAllShapes();
129 /** Lookup a Shape from an XShape model object
131 This method looks up the internal shape map for one
132 representing the given XShape.
135 The XShape object, for which the representing Shape
138 ShapeSharedPtr
lookupShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
) const;
140 /** Query a subset of the given original shape
142 This method queries a new (but not necessarily unique)
143 shape, which displays only the given subset of the
146 AttributableShapeSharedPtr
getSubsetShape( const AttributableShapeSharedPtr
& rOrigShape
,
147 const DocTreeNode
& rTreeNode
);
149 /** Get a map that maps all Shapes with their XShape reference as the key
151 * @return an unordered map that contains all shapes in the
152 * current page with their XShape reference as the key
154 const XShapeToShapeMap
& getXShapeToShapeMap() const;
156 /** Revoke a previously queried subset shape.
158 With this method, a previously requested subset shape
159 is revoked again. If the last client revokes a given
160 subset, it will cease to be displayed, and the
161 original shape will again show the subset data.
164 The shape the subset was created from
167 The subset created from rOrigShape
169 void revokeSubset( const AttributableShapeSharedPtr
& rOrigShape
,
170 const AttributableShapeSharedPtr
& rSubsetShape
);
172 /** Notify the LayerManager that the given Shape starts an
175 This method enters animation mode for the Shape on all
178 void enterAnimationMode( const AnimatableShapeSharedPtr
& rShape
);
180 /** Notify the LayerManager that the given Shape is no
183 This methods ends animation mode for the given Shape
184 on all registered views.
186 void leaveAnimationMode( const AnimatableShapeSharedPtr
& rShape
);
188 /** Notify that a shape needs an update
190 This method notifies the layer manager that a shape
191 update is necessary. This is useful if, during
192 animation playback, changes occur to shapes which make
193 an update necessary on an update() call. Otherwise,
194 update() will not render anything, which is not
195 triggered by calling one of the other LayerManager
199 Shape which needs an update
201 void notifyShapeUpdate( const ShapeSharedPtr
& rShape
);
203 /** Check whether any update operations are pending.
205 @return true, if this LayerManager has any updates
206 pending, i.e. needs to repaint something for the next
209 bool isUpdatePending() const;
211 /** Update the content
213 This method updates the content on all layers on all
214 registered views. It does not issues a
215 View::updateScreen() call on registered views. Please
216 note that this method only takes into account changes
217 to shapes induced directly by calling methods of the
218 LayerManager. If a shape needs an update, because of
219 some external event unknown to the LayerManager (most
220 notably running animations), you have to notify the
221 LayerManager via notifyShapeUpdate().
223 @see LayerManager::updateScreen()
225 @return whether the update finished successfully.
229 /** Render the content to given canvas
231 This is a one-shot operation, which simply draws all
232 shapes onto the given canvas, without any caching or
233 other fuzz. Don't use that for repeated output onto
234 the same canvas, the View concept is more optimal
238 Target canvas to output onto.
240 bool renderTo( const ::cppcanvas::CanvasSharedPtr
& rTargetCanvas
) const;
244 class ShapeComparator
247 bool operator() (const ShapeSharedPtr
& rpS1
, const ShapeSharedPtr
& rpS2
) const
249 return Shape::lessThanShape::compare(rpS1
.get(), rpS2
.get());
252 /** Set of all shapes
255 typedef ::std::map
< ShapeSharedPtr
, LayerWeakPtr
, ShapeComparator
> LayerShapeMap
;
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 const 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();
318 const UnoViewContainer
& mrViews
;
320 /// All layers of this object. Vector owns the layers
321 ::std::vector
< LayerSharedPtr
>
324 /** Contains all shapes with their XShape reference as the key
326 XShapeToShapeMap maXShapeHash
;
328 /** Set of shapes this LayerManager own
330 Contains the same set of shapes as XShapeHash, but is
331 sorted in z order, for painting and layer
332 association. Set entries are enriched with two flags
333 for buffering animation enable/disable changes, and
334 shape update requests.
336 LayerShapeMap maAllShapes
;
338 /** Set of shapes that have requested an update
340 When a shape is member of this set, its maShapes entry
341 has bNeedsUpdate set to true. We maintain this
342 redundant information for faster update processing.
344 ::std::set
< ShapeSharedPtr
>
347 /// Number of shape sprites currently active on this LayerManager
348 sal_Int32 mnActiveSprites
;
350 /// sal_True, if shapes might need to move to different layer
351 bool mbLayerAssociationDirty
;
353 /// sal_False when deactivated
356 /** When true, all sprite animations run in the foreground. That
357 is, no extra layers are created, and the slideshow runs
360 bool mbDisableAnimationZOrder
;
363 typedef ::std::shared_ptr
< LayerManager
> LayerManagerSharedPtr
;
367 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYERMANAGER_HXX
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */