android: Update app-specific/MIME type icons
[LibreOffice.git] / slideshow / source / engine / slide / layermanager.hxx
blob1969f0cccbb0943c65b38bc06609689c03c41807
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 <unoviewcontainer.hxx>
24 #include <attributableshape.hxx>
25 #include "layer.hxx"
26 #include <tools.hxx>
28 #include <memory>
29 #include <map>
30 #include <unordered_map>
31 #include <vector>
33 namespace basegfx {
34 class B2DRange;
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 >,
45 ShapeSharedPtr,
46 hash< css::uno::Reference< css::drawing::XShape > >
47 > XShapeToShapeMap;
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
58 performs it.
60 @see Layer
61 @see Shape
63 class LayerManager
65 public:
66 /** Create a new layer manager for the given page bounds
68 @param rViews
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.
91 void activate();
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.
101 void deactivate();
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 );
109 void viewsChanged();
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 /** Lookup a Shape from an XShape model object
125 This method looks up the internal shape map for one
126 representing the given XShape.
128 @param xShape
129 The XShape object, for which the representing Shape
130 should be looked up.
132 ShapeSharedPtr lookupShape( const css::uno::Reference< css::drawing::XShape >& xShape ) const;
134 /** Query a subset of the given original shape
136 This method queries a new (but not necessarily unique)
137 shape, which displays only the given subset of the
138 original one.
140 AttributableShapeSharedPtr getSubsetShape( const AttributableShapeSharedPtr& rOrigShape,
141 const DocTreeNode& rTreeNode );
143 /** Get a map that maps all Shapes with their XShape reference as the key
145 * @return an unordered map that contains all shapes in the
146 * current page with their XShape reference as the key
148 const XShapeToShapeMap& getXShapeToShapeMap() const;
150 /** Revoke a previously queried subset shape.
152 With this method, a previously requested subset shape
153 is revoked again. If the last client revokes a given
154 subset, it will cease to be displayed, and the
155 original shape will again show the subset data.
157 @param rOrigShape
158 The shape the subset was created from
160 @param rSubsetShape
161 The subset created from rOrigShape
163 void revokeSubset( const AttributableShapeSharedPtr& rOrigShape,
164 const AttributableShapeSharedPtr& rSubsetShape );
166 /** Notify the LayerManager that the given Shape starts an
167 animation now.
169 This method enters animation mode for the Shape on all
170 registered views.
172 void enterAnimationMode( const AnimatableShapeSharedPtr& rShape );
174 /** Notify the LayerManager that the given Shape is no
175 longer animated.
177 This methods ends animation mode for the given Shape
178 on all registered views.
180 void leaveAnimationMode( const AnimatableShapeSharedPtr& rShape );
182 /** Notify that a shape needs an update
184 This method notifies the layer manager that a shape
185 update is necessary. This is useful if, during
186 animation playback, changes occur to shapes which make
187 an update necessary on an update() call. Otherwise,
188 update() will not render anything, which is not
189 triggered by calling one of the other LayerManager
190 methods.
192 @param rShape
193 Shape which needs an update
195 void notifyShapeUpdate( const ShapeSharedPtr& rShape);
197 /** Check whether any update operations are pending.
199 @return true, if this LayerManager has any updates
200 pending, i.e. needs to repaint something for the next
201 frame.
203 bool isUpdatePending() const;
205 /** Update the content
207 This method updates the content on all layers on all
208 registered views. It does not issues a
209 View::updateScreen() call on registered views. Please
210 note that this method only takes into account changes
211 to shapes induced directly by calling methods of the
212 LayerManager. If a shape needs an update, because of
213 some external event unknown to the LayerManager (most
214 notably running animations), you have to notify the
215 LayerManager via notifyShapeUpdate().
217 @see LayerManager::updateScreen()
219 @return whether the update finished successfully.
221 bool update();
223 /** Render the content to given canvas
225 This is a one-shot operation, which simply draws all
226 shapes onto the given canvas, without any caching or
227 other fuzz. Don't use that for repeated output onto
228 the same canvas, the View concept is more optimal
229 then.
231 @param rTargetCanvas
232 Target canvas to output onto.
234 bool renderTo( const ::cppcanvas::CanvasSharedPtr& rTargetCanvas ) const;
236 private:
238 class ShapeComparator
240 public:
241 bool operator() (const ShapeSharedPtr& rpS1, const ShapeSharedPtr& rpS2 ) const
243 return Shape::lessThanShape::compare(rpS1.get(), rpS2.get());
246 /** Set of all shapes
248 private:
249 typedef ::std::map< ShapeSharedPtr, LayerWeakPtr, ShapeComparator > LayerShapeMap;
252 /// Adds shape area to containing layer's damage area
253 void addUpdateArea( ShapeSharedPtr const& rShape );
255 LayerSharedPtr createForegroundLayer() const;
257 /** Push changes from updateShapeLayerAssociations() to current layer
259 Factored-out method that resizes layer, if necessary,
260 assigns correct layer priority, and repaints contained shapes.
262 @param nCurrLayerIndex
263 Index of current layer in maLayers
265 @param aFirstLayerShape
266 Valid iterator out of maAllShapes, denoting the first
267 shape from nCurrLayerIndex
269 @param aEndLayerShapes
270 Valid iterator or end iterator out of maAllShapes,
271 denoting one-behind-the-last shape of nCurrLayerIndex
273 void commitLayerChanges( std::size_t nCurrLayerIndex,
274 LayerShapeMap::const_iterator aFirstLayerShape,
275 const LayerShapeMap::const_iterator& aEndLayerShapes );
277 /** Init Shape layers with background layer.
279 void putShape2BackgroundLayer( LayerShapeMap::value_type& rShapeEntry );
281 /** Commits any pending layer reorg, due to shapes either
282 entering or leaving animation mode
284 @param bBackgroundLayerPainted
285 When true, LayerManager does not render anything on
286 the background layer. Use this, if background has been
287 updated by other means (e.g. slide transition)
289 void updateShapeLayers( bool bBackgroundLayerPainted );
291 /** Common stuff when adding a shape
293 void implAddShape( const ShapeSharedPtr& rShape );
295 /** Common stuff when removing a shape
297 void implRemoveShape( const ShapeSharedPtr& rShape );
299 /** Add or remove views
301 Sharing duplicate code from viewAdded and viewRemoved
302 method. The only point of variation at those places
303 are removal vs. adding.
305 template<typename LayerFunc,
306 typename ShapeFunc> void manageViews( LayerFunc layerFunc,
307 ShapeFunc shapeFunc );
309 bool updateSprites();
311 /// Registered views
312 const UnoViewContainer& mrViews;
314 /// All layers of this object. Vector owns the layers
315 ::std::vector< LayerSharedPtr >
316 maLayers;
318 /** Contains all shapes with their XShape reference as the key
320 XShapeToShapeMap maXShapeHash;
322 /** Set of shapes this LayerManager own
324 Contains the same set of shapes as XShapeHash, but is
325 sorted in z order, for painting and layer
326 association. Set entries are enriched with two flags
327 for buffering animation enable/disable changes, and
328 shape update requests.
330 LayerShapeMap maAllShapes;
332 /** Set of shapes that have requested an update
334 When a shape is member of this set, its maShapes entry
335 has bNeedsUpdate set to true. We maintain this
336 redundant information for faster update processing.
338 ::std::set< ShapeSharedPtr >
339 maUpdateShapes;
341 /// Number of shape sprites currently active on this LayerManager
342 sal_Int32 mnActiveSprites;
344 /// sal_True, if shapes might need to move to different layer
345 bool mbLayerAssociationDirty;
347 /// sal_False when deactivated
348 bool mbActive;
350 /** When true, all sprite animations run in the foreground. That
351 is, no extra layers are created, and the slideshow runs
352 potentially faster.
354 bool mbDisableAnimationZOrder;
357 typedef ::std::shared_ptr< LayerManager > LayerManagerSharedPtr;
361 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYERMANAGER_HXX
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */