merge the formfield patch from ooo-build
[ooovba.git] / slideshow / source / engine / shapes / viewshape.hxx
blobc97b54376c4c244977147670bbb46845f3dcbce9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewshape.hxx,v $
10 * $Revision: 1.3 $
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_VIEWSHAPE_HXX
32 #define INCLUDED_SLIDESHOW_VIEWSHAPE_HXX
34 #include <cppcanvas/renderer.hxx>
35 #include <cppcanvas/bitmap.hxx>
37 #include <basegfx/range/b2drectangle.hxx>
38 #include <basegfx/polygon/b2dpolygon.hxx>
40 #include <boost/shared_ptr.hpp>
41 #include <boost/utility.hpp>
43 #include "tools.hxx"
44 #include "shapeattributelayer.hxx"
45 #include "animatedsprite.hxx"
46 #include "viewlayer.hxx"
47 #include "doctreenode.hxx"
49 #include <vector>
52 namespace slideshow
54 namespace internal
56 /** This class is the viewable representation of a draw
57 document's XShape, associated to a specific View
59 The class is able to render the associated XShape on
60 View implementations.
62 class ViewShape : private boost::noncopyable
64 public:
65 /** Create a ViewShape for the given View
67 @param rView
68 The associated View object.
70 explicit ViewShape( const ViewLayerSharedPtr& rViewLayer );
72 /** Query the associated view layer of this shape
74 ViewLayerSharedPtr getViewLayer() const;
76 /** Query dimension of a safety border around the shape for AA
78 If the view performs antialiasing, this method
79 calculates a safety border around the shape, in the
80 shape coordinate system, which is guaranteed to
81 include every pixel touched when rendering the shape.
83 ::basegfx::B2DSize getAntialiasingBorder() const;
86 // animation methods
87 //------------------------------------------------------------------
89 /** Notify the ViewShape that an animation starts now
91 This method enters animation mode on the associate
92 target view. The shape can be animated in parallel on
93 different views.
95 @return whether the mode change finished successfully.
97 bool enterAnimationMode();
99 /** Notify the ViewShape that it is no longer animated
101 This methods ends animation mode on the associate
102 target view
104 void leaveAnimationMode();
106 /** Query whether the ViewShape is currently animated
108 This method checks whether the ViewShape is currently in
109 animation mode.
111 bool isBackgroundDetached() const { return mbAnimationMode; }
114 // render methods
115 //------------------------------------------------------------------
117 enum UpdateFlags
119 NONE= 0,
120 TRANSFORMATION= 1,
121 CLIP= 2,
122 ALPHA= 4,
123 POSITION= 8,
124 CONTENT= 16,
125 FORCE= 32
128 struct RenderArgs
130 /** Create render argument struct
132 @param rOrigBounds
133 The initial shape bounds
135 @param rUpdateBounds
136 The area covered by the shape
138 @param rBounds
139 The current shape bounds
141 @param rAttr
142 The current shape attribute set. Can be NULL, for
143 default attributes. Attention: stored as a reference,
144 thus, parameter object must stay valid!
146 @param rSubsets
147 Vector of subset rendering ranges. Attention:
148 stored as a reference, thus, parameter object must
149 stay valid!
151 @param nPrio
152 Shape priority
154 RenderArgs( const ::basegfx::B2DRectangle& rOrigBounds,
155 const ::basegfx::B2DRectangle& rUpdateBounds,
156 const ::basegfx::B2DRectangle& rBounds,
157 const ::basegfx::B2DRectangle& rUnitBounds,
158 const ShapeAttributeLayerSharedPtr& rAttr,
159 const VectorOfDocTreeNodes& rSubsets,
160 double nPrio ) :
161 maOrigBounds( rOrigBounds ),
162 maUpdateBounds( rUpdateBounds ),
163 maBounds( rBounds ),
164 maUnitBounds( rUnitBounds ),
165 mrAttr( rAttr ),
166 mrSubsets( rSubsets ),
167 mnShapePriority( nPrio )
171 const ::basegfx::B2DRectangle maOrigBounds;
172 const ::basegfx::B2DRectangle maUpdateBounds;
173 const ::basegfx::B2DRectangle maBounds;
174 const ::basegfx::B2DRectangle maUnitBounds;
175 const ShapeAttributeLayerSharedPtr& mrAttr;
176 const VectorOfDocTreeNodes& mrSubsets;
177 const double mnShapePriority;
180 /** Update the ViewShape
182 This method updates the ViewShape on the associated
183 view. If the shape is currently animated, the render
184 target is the sprite, otherwise the view's
185 canvas. This method does not render anything, if the
186 update flags are 0.
188 @param rMtf
189 The metafile representation of the shape
191 @param rArgs
192 Parameter structure, containing all necessary arguments
194 @param nUpdateFlags
195 Bitmask of things to update. Use FORCE to force a repaint.
197 @param bIsVisible
198 When false, the shape is fully invisible (and possibly
199 don't need to be painted)
201 @return whether the rendering finished successfully.
203 bool update( const GDIMetaFileSharedPtr& rMtf,
204 const RenderArgs& rArgs,
205 int nUpdateFlags,
206 bool bIsVisible ) const;
208 /** Retrieve renderer for given canvas and metafile.
210 If necessary, the renderer is created or updated for
211 the metafile and attribute layer.
213 @return a renderer that renders to the given
214 destination canvas
216 ::cppcanvas::RendererSharedPtr getRenderer( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
217 const GDIMetaFileSharedPtr& rMtf,
218 const ShapeAttributeLayerSharedPtr& rAttr ) const;
221 private:
222 struct RendererCacheEntry
224 RendererCacheEntry() :
225 mpDestinationCanvas(),
226 mpRenderer(),
227 mpMtf(),
228 mpLastBitmap(),
229 mpLastBitmapCanvas()
233 ::cppcanvas::CanvasSharedPtr getDestinationCanvas()
235 return mpDestinationCanvas;
238 ::cppcanvas::CanvasSharedPtr mpDestinationCanvas;
239 ::cppcanvas::RendererSharedPtr mpRenderer;
240 GDIMetaFileSharedPtr mpMtf;
241 ::cppcanvas::BitmapSharedPtr mpLastBitmap;
242 ::cppcanvas::BitmapCanvasSharedPtr mpLastBitmapCanvas;
245 typedef ::std::vector< RendererCacheEntry > RendererCacheVector;
248 /** Prefetch Renderer for given canvas
250 bool prefetch( RendererCacheEntry& io_rCacheEntry,
251 const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
252 const GDIMetaFileSharedPtr& rMtf,
253 const ShapeAttributeLayerSharedPtr& rAttr ) const;
255 /** Draw with prefetched Renderer to stored canvas
257 This method draws prefetched Renderer to its
258 associated canvas (which happens to be mpLastCanvas).
260 bool draw( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
261 const GDIMetaFileSharedPtr& rMtf,
262 const ShapeAttributeLayerSharedPtr& rAttr,
263 const ::basegfx::B2DHomMatrix& rTransform,
264 const ::basegfx::B2DPolyPolygon* pClip,
265 const VectorOfDocTreeNodes& rSubsets ) const;
267 /** Render shape to an active sprite
269 bool renderSprite( const ViewLayerSharedPtr& rViewLayer,
270 const GDIMetaFileSharedPtr& rMtf,
271 const ::basegfx::B2DRectangle& rOrigBounds,
272 const ::basegfx::B2DRectangle& rBounds,
273 const ::basegfx::B2DRectangle& rUnitBounds,
274 int nUpdateFlags,
275 const ShapeAttributeLayerSharedPtr& pAttr,
276 const VectorOfDocTreeNodes& rSubsets,
277 double nPrio,
278 bool bIsVisible ) const;
280 /** Render shape to given canvas
282 bool render( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
283 const GDIMetaFileSharedPtr& rMtf,
284 const ::basegfx::B2DRectangle& rBounds,
285 const ::basegfx::B2DRectangle& rUpdateBounds,
286 int nUpdateFlags,
287 const ShapeAttributeLayerSharedPtr& pAttr,
288 const VectorOfDocTreeNodes& rSubsets,
289 bool bIsVisible ) const;
291 /** Calc sprite size in pixel
293 Converts user coordinate system to device pixel, and
294 adds antialiasing border.
296 @param rUserSize
297 Size of the sprite in user coordinate system (doc coordinates)
299 ::basegfx::B2DSize calcSpriteSizePixel( const ::basegfx::B2DSize& rUserSize ) const;
301 enum{ MAX_RENDER_CACHE_ENTRIES=2 };
303 /** Retrieve a valid iterator to renderer cache entry
305 This method ensures that an internal limit of
306 MAX_RENDER_CACHE_ENTRIES is not exceeded.
308 @param rDestinationCanvas
309 Destination canvas to retrieve cache entry for
311 @return a valid iterator to a renderer cache entry for
312 the given canvas. The entry might be
313 default-constructed (if newly added)
315 RendererCacheVector::iterator getCacheEntry( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas ) const;
317 void invalidateRenderer() const;
319 /** The view layer this object is part of.
321 Needed for sprite creation
323 ViewLayerSharedPtr mpViewLayer;
325 /// A set of cached mtf/canvas combinations
326 mutable RendererCacheVector maRenderers;
328 /// The sprite object
329 mutable AnimatedSpriteSharedPtr mpSprite;
331 /// If true, render() calls go to the sprite
332 mutable bool mbAnimationMode;
334 /// If true, shape needs full repaint (and the sprite a setup, if any)
335 mutable bool mbForceUpdate;
338 typedef ::boost::shared_ptr< ViewShape > ViewShapeSharedPtr;
343 #endif /* INCLUDED_SLIDESHOW_VIEWSHAPE_HXX */