1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: layermanager.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_SLIDESHOW_LAYERMANAGER_HXX
32 #define INCLUDED_SLIDESHOW_LAYERMANAGER_HXX
34 #include <boost/shared_ptr.hpp>
35 #include <boost/noncopyable.hpp>
37 #include <cppcanvas/spritecanvas.hxx>
39 #include "unoview.hxx"
40 #include "unoviewcontainer.hxx"
41 #include "attributableshape.hxx"
59 /* Definition of Layermanager class */
61 /** This class manages all of a slide's layers (and shapes)
63 Since layer content changes when animations start or end,
64 the layer manager keeps track of this and also handles
65 starting/stopping of Shape animations. Note that none of
66 the methods actually perform a screen update, this is
67 always delayed until the ActivitiesQueue explicitely
73 class LayerManager
: private boost::noncopyable
76 /** Create a new layer manager for the given page bounds
79 Views currently registered
82 Overall page bounds, in user space coordinates
84 @param bDisableAnimationZOrder
85 When true, all sprite animations run in the
86 foreground. That is, no extra layers are created, and
87 the slideshow runs potentially faster.
89 LayerManager( const UnoViewContainer
& rViews
,
90 const ::basegfx::B2DRange
& rPageBounds
,
91 bool bDisableAnimationZOrder
);
93 /** Activate the LayerManager
95 This method activates the LayerManager. Prior to
96 activation, this instance will be passive, i.e. won't
97 render anything to any view.
99 @param bSlideBackgoundPainted
100 When true, the initial slide content on the background
101 layer is already rendered (e.g. from a previous slide
102 transition). When false, LayerManager also renders
103 initial content of background layer on next update()
106 void activate( bool bSlideBackgoundPainted
);
108 /** Deactivate the LayerManager
110 This method deactivates the LayerManager. After
111 deactivation, this instance will be passive,
112 i.e. don't render anything to any view. Furthermore,
113 if there's currently more than one Layer active, this
114 method also removes all but one.
118 // From ViewEventHandler, forwarded by SlideImpl
119 /// Notify new view added to UnoViewContainer
120 void viewAdded( const UnoViewSharedPtr
& rView
);
121 /// Notify view removed from UnoViewContainer
122 void viewRemoved( const UnoViewSharedPtr
& rView
);
123 void viewChanged( const UnoViewSharedPtr
& rView
);
126 /** Add the shape to this object
128 This method adds a shape to the page.
130 void addShape( const ShapeSharedPtr
& rShape
);
132 /** Remove shape from this object
134 This method removes a shape from the shape.
136 bool removeShape( const ShapeSharedPtr
& rShape
);
138 /** Lookup a Shape from an XShape model object
140 This method looks up the internal shape map for one
141 representing the given XShape.
144 The XShape object, for which the representing Shape
147 ShapeSharedPtr
lookupShape( const ::com::sun::star::uno::Reference
<
148 ::com::sun::star::drawing::XShape
>& xShape
) const;
150 /** Query a subset of the given original shape
152 This method queries a new (but not necessarily unique)
153 shape, which displays only the given subset of the
156 AttributableShapeSharedPtr
getSubsetShape( const AttributableShapeSharedPtr
& rOrigShape
,
157 const DocTreeNode
& rTreeNode
);
159 /** Revoke a previously queried subset shape.
161 With this method, a previously requested subset shape
162 is revoked again. If the last client revokes a given
163 subset, it will cease to be displayed, and the
164 original shape will again show the subset data.
167 The shape the subset was created from
170 The subset created from rOrigShape
172 void revokeSubset( const AttributableShapeSharedPtr
& rOrigShape
,
173 const AttributableShapeSharedPtr
& rSubsetShape
);
175 /** Notify the LayerManager that the given Shape starts an
178 This method enters animation mode for the Shape on all
181 void enterAnimationMode( const AnimatableShapeSharedPtr
& rShape
);
183 /** Notify the LayerManager that the given Shape is no
186 This methods ends animation mode for the given Shape
187 on all registered views.
189 void leaveAnimationMode( const AnimatableShapeSharedPtr
& rShape
);
191 /** Notify that a shape needs an update
193 This method notifies the layer manager that a shape
194 update is necessary. This is useful if, during
195 animation playback, changes occur to shapes which make
196 an update necessary on an update() call. Otherwise,
197 update() will not render anything, which is not
198 triggered by calling one of the other LayerManager
202 Shape which needs an update
204 void notifyShapeUpdate( const ShapeSharedPtr
& rShape
);
206 /** Check whether any update operations are pending.
208 @return true, if this LayerManager has any updates
209 pending, i.e. needs to repaint something for the next
212 bool isUpdatePending() const;
214 /** Update the content
216 This method updates the content on all layers on all
217 registered views. It does not issues a
218 View::updateScreen() call on registered views. Please
219 note that this method only takes into account changes
220 to shapes induced directly by calling methods of the
221 LayerManager. If a shape needs an update, because of
222 some external event unknown to the LayerManager (most
223 notably running animations), you have to notify the
224 LayerManager via notifyShapeUpdate().
226 @see LayerManager::updateScreen()
228 @return whether the update finished successfully.
232 /** Render the content to given canvas
234 This is a one-shot operation, which simply draws all
235 shapes onto the given canvas, without any caching or
236 other fuzz. Don't use that for repeated output onto
237 the same canvas, the View concept is more optimal
241 Target canvas to output onto.
243 bool renderTo( const ::cppcanvas::CanvasSharedPtr
& rTargetCanvas
) const;
246 /** A hash map which maps the XShape to the corresponding Shape object.
248 Provides quicker lookup than ShapeSet for simple mappings
250 typedef ::std::hash_map
<
251 ::com::sun::star::uno::Reference
<
252 ::com::sun::star::drawing::XShape
>,
254 hash
< ::com::sun::star::uno::Reference
<
255 ::com::sun::star::drawing::XShape
> > > XShapeHash
;
257 class ShapeComparator
260 bool operator() (const ShapeSharedPtr
& rpS1
, const ShapeSharedPtr
& rpS2
) const
262 return Shape::lessThanShape::compare(rpS1
.get(), rpS2
.get());
265 /** Set of all shapes
268 typedef ::std::map
< ShapeSharedPtr
, LayerWeakPtr
, ShapeComparator
> LayerShapeMap
;
269 typedef ::std::set
< ShapeSharedPtr
> ShapeUpdateSet
;
272 ////////////////////////////////////////////////////////////////////////
275 /// Adds shape area to containing layer's damage area
276 void addUpdateArea( ShapeSharedPtr
const& rShape
);
278 LayerSharedPtr
createForegroundLayer() const;
280 /** Push changes from updateShapeLayerAssociations() to current layer
282 Factored-out method that resizes layer, if necessary,
283 assigns correct layer priority, and repaints contained shapes.
285 @param nCurrLayerIndex
286 Index of current layer in maLayers
288 @param aFirstLayerShape
289 Valid iterator out of maAllShapes, denoting the first
290 shape from nCurrLayerIndex
292 @param aEndLayerShapes
293 Valid iterator or end iterator out of maAllShapes,
294 denoting one-behind-the-last shape of nCurrLayerIndex
296 void commitLayerChanges( std::size_t nCurrLayerIndex
,
297 LayerShapeMap::const_iterator aFirstLayerShape
,
298 LayerShapeMap::const_iterator aEndLayerShapes
);
300 /** Init Shape layers with background layer.
302 void putShape2BackgroundLayer( LayerShapeMap::value_type
& rShapeEntry
);
304 /** Commits any pending layer reorg, due to shapes either
305 entering or leaving animation mode
307 @param bBackgroundLayerPainted
308 When true, LayerManager does not render anything on
309 the background layer. Use this, if background has been
310 updated by other means (e.g. slide transition)
312 void updateShapeLayers( bool bBackgroundLayerPainted
);
314 /** Common stuff when adding a shape
316 void implAddShape( const ShapeSharedPtr
& rShape
);
318 /** Common stuff when removing a shape
320 void implRemoveShape( const ShapeSharedPtr
& rShape
);
322 /** Add or remove views
324 Sharing duplicate code from viewAdded and viewRemoved
325 method. The only point of variation at those places
326 are removal vs. adding.
328 template<typename LayerFunc
,
329 typename ShapeFunc
> void manageViews( LayerFunc layerFunc
,
330 ShapeFunc shapeFunc
);
332 bool updateSprites();
335 const UnoViewContainer
& mrViews
;
337 /// All layers of this object. Vector owns the layers
338 LayerVector maLayers
;
340 /** Contains all shapes with their XShape reference as the key
342 XShapeHash maXShapeHash
;
344 /** Set of shapes this LayerManager own
346 Contains the same set of shapes as XShapeHash, but is
347 sorted in z order, for painting and layer
348 association. Set entries are enriched with two flags
349 for buffering animation enable/disable changes, and
350 shape update requests.
352 LayerShapeMap maAllShapes
;
354 /** Set of shapes that have requested an update
356 When a shape is member of this set, its maShapes entry
357 has bNeedsUpdate set to true. We maintain this
358 redundant information for faster update processing.
360 ShapeUpdateSet maUpdateShapes
;
362 /** Overall slide bounds (in user coordinate
363 system). shapes that exceed this boundary are clipped,
364 thus, layers only need to be of this size.
366 const basegfx::B2DRange maPageBounds
;
368 /// Number of shape sprites currenly active on this LayerManager
369 sal_Int32 mnActiveSprites
;
371 /// TRUE, if shapes might need to move to different layer
372 bool mbLayerAssociationDirty
;
374 /// FALSE when deactivated
377 /** When true, all sprite animations run in the foreground. That
378 is, no extra layers are created, and the slideshow runs
381 bool mbDisableAnimationZOrder
;
384 typedef ::boost::shared_ptr
< LayerManager
> LayerManagerSharedPtr
;
388 #endif /* INCLUDED_SLIDESHOW_LAYERMANAGER_HXX */