xref: /AOO41X/main/slideshow/source/engine/shapes/viewshape.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_VIEWSHAPE_HXX
29*cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_VIEWSHAPE_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <cppcanvas/renderer.hxx>
32*cdf0e10cSrcweir #include <cppcanvas/bitmap.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
35*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
38*cdf0e10cSrcweir #include <boost/utility.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "tools.hxx"
41*cdf0e10cSrcweir #include "shapeattributelayer.hxx"
42*cdf0e10cSrcweir #include "animatedsprite.hxx"
43*cdf0e10cSrcweir #include "viewlayer.hxx"
44*cdf0e10cSrcweir #include "doctreenode.hxx"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <vector>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir namespace slideshow
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir     namespace internal
52*cdf0e10cSrcweir     {
53*cdf0e10cSrcweir         /** This class is the viewable representation of a draw
54*cdf0e10cSrcweir             document's XShape, associated to a specific View
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir             The class is able to render the associated XShape on
57*cdf0e10cSrcweir             View implementations.
58*cdf0e10cSrcweir          */
59*cdf0e10cSrcweir         class ViewShape : private boost::noncopyable
60*cdf0e10cSrcweir         {
61*cdf0e10cSrcweir         public:
62*cdf0e10cSrcweir             /** Create a ViewShape for the given View
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir             	@param rView
65*cdf0e10cSrcweir                 The associated View object.
66*cdf0e10cSrcweir              */
67*cdf0e10cSrcweir             explicit ViewShape( const ViewLayerSharedPtr& rViewLayer );
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 			/** Query the associated view layer of this shape
70*cdf0e10cSrcweir              */
71*cdf0e10cSrcweir             ViewLayerSharedPtr getViewLayer() const;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir             /** Query dimension of a safety border around the shape for AA
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir             	If the view performs antialiasing, this method
76*cdf0e10cSrcweir             	calculates a safety border around the shape, in the
77*cdf0e10cSrcweir             	shape coordinate system, which is guaranteed to
78*cdf0e10cSrcweir             	include every pixel touched when rendering the shape.
79*cdf0e10cSrcweir              */
80*cdf0e10cSrcweir             ::basegfx::B2DSize getAntialiasingBorder() const;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir             // animation methods
84*cdf0e10cSrcweir             //------------------------------------------------------------------
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir             /** Notify the ViewShape that an animation starts now
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 				This method enters animation mode on the associate
89*cdf0e10cSrcweir 				target view. The shape can be animated in parallel on
90*cdf0e10cSrcweir 				different views.
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	            @return whether the mode change finished successfully.
93*cdf0e10cSrcweir              */
94*cdf0e10cSrcweir             bool enterAnimationMode();
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir             /** Notify the ViewShape that it is no longer animated
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 				This methods ends animation mode on the associate
99*cdf0e10cSrcweir 				target view
100*cdf0e10cSrcweir              */
101*cdf0e10cSrcweir             void leaveAnimationMode();
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir             /** Query whether the ViewShape is currently animated
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 				This method checks whether the ViewShape is currently in
106*cdf0e10cSrcweir 				animation mode.
107*cdf0e10cSrcweir              */
108*cdf0e10cSrcweir             bool isBackgroundDetached() const { return mbAnimationMode; }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir             // render methods
112*cdf0e10cSrcweir             //------------------------------------------------------------------
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir             enum UpdateFlags
115*cdf0e10cSrcweir             {
116*cdf0e10cSrcweir                 NONE=			0,
117*cdf0e10cSrcweir                 TRANSFORMATION=	1,
118*cdf0e10cSrcweir                 CLIP=			2,
119*cdf0e10cSrcweir                 ALPHA=			4,
120*cdf0e10cSrcweir                 POSITION=		8,
121*cdf0e10cSrcweir                 CONTENT=	    16,
122*cdf0e10cSrcweir                 FORCE=			32
123*cdf0e10cSrcweir             };
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir             struct RenderArgs
126*cdf0e10cSrcweir             {
127*cdf0e10cSrcweir                 /** Create render argument struct
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir                     @param rOrigBounds
130*cdf0e10cSrcweir                     The initial shape bounds
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir                     @param rUpdateBounds
133*cdf0e10cSrcweir                     The area covered by the shape
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir                     @param rBounds
136*cdf0e10cSrcweir                     The current shape bounds
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir                     @param rAttr
139*cdf0e10cSrcweir                     The current shape attribute set. Can be NULL, for
140*cdf0e10cSrcweir                     default attributes. Attention: stored as a reference,
141*cdf0e10cSrcweir                     thus, parameter object must stay valid!
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir                     @param rSubsets
144*cdf0e10cSrcweir                     Vector of subset rendering ranges. Attention:
145*cdf0e10cSrcweir                     stored as a reference, thus, parameter object must
146*cdf0e10cSrcweir                     stay valid!
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir                     @param nPrio
149*cdf0e10cSrcweir                     Shape priority
150*cdf0e10cSrcweir                 */
151*cdf0e10cSrcweir                 RenderArgs( const ::basegfx::B2DRectangle&		rOrigBounds,
152*cdf0e10cSrcweir                             const ::basegfx::B2DRectangle&		rUpdateBounds,
153*cdf0e10cSrcweir                             const ::basegfx::B2DRectangle&		rBounds,
154*cdf0e10cSrcweir                             const ::basegfx::B2DRectangle&		rUnitBounds,
155*cdf0e10cSrcweir                             const ShapeAttributeLayerSharedPtr&	rAttr,
156*cdf0e10cSrcweir                             const VectorOfDocTreeNodes&			rSubsets,
157*cdf0e10cSrcweir                             double                              nPrio ) :
158*cdf0e10cSrcweir                     maOrigBounds( rOrigBounds ),
159*cdf0e10cSrcweir                     maUpdateBounds( rUpdateBounds ),
160*cdf0e10cSrcweir                     maBounds( rBounds ),
161*cdf0e10cSrcweir                     maUnitBounds( rUnitBounds ),
162*cdf0e10cSrcweir                     mrAttr( rAttr ),
163*cdf0e10cSrcweir                     mrSubsets( rSubsets ),
164*cdf0e10cSrcweir                     mnShapePriority( nPrio )
165*cdf0e10cSrcweir                 {
166*cdf0e10cSrcweir                 }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir                 const ::basegfx::B2DRectangle		maOrigBounds;
169*cdf0e10cSrcweir                 const ::basegfx::B2DRectangle		maUpdateBounds;
170*cdf0e10cSrcweir                 const ::basegfx::B2DRectangle		maBounds;
171*cdf0e10cSrcweir                 const ::basegfx::B2DRectangle		maUnitBounds;
172*cdf0e10cSrcweir                 const ShapeAttributeLayerSharedPtr&	mrAttr;
173*cdf0e10cSrcweir                 const VectorOfDocTreeNodes&			mrSubsets;
174*cdf0e10cSrcweir                 const double                        mnShapePriority;
175*cdf0e10cSrcweir             };
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir             /** Update the ViewShape
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 				This method updates the ViewShape on the associated
180*cdf0e10cSrcweir 				view. If the shape is currently animated, the render
181*cdf0e10cSrcweir 				target is the sprite, otherwise the view's
182*cdf0e10cSrcweir 				canvas. This method does not render anything, if the
183*cdf0e10cSrcweir 				update flags are 0.
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir                 @param rMtf
186*cdf0e10cSrcweir                 The metafile representation of the shape
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir                 @param rArgs
189*cdf0e10cSrcweir                 Parameter structure, containing all necessary arguments
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir                 @param nUpdateFlags
192*cdf0e10cSrcweir                 Bitmask of things to update. Use FORCE to force a repaint.
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir                 @param bIsVisible
195*cdf0e10cSrcweir                 When false, the shape is fully invisible (and possibly
196*cdf0e10cSrcweir                 don't need to be painted)
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	            @return whether the rendering finished successfully.
199*cdf0e10cSrcweir             */
200*cdf0e10cSrcweir             bool update( const GDIMetaFileSharedPtr&	rMtf,
201*cdf0e10cSrcweir                          const RenderArgs&				rArgs,
202*cdf0e10cSrcweir                          int							nUpdateFlags,
203*cdf0e10cSrcweir                          bool							bIsVisible ) const;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir             /** Retrieve renderer for given canvas and metafile.
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir             	If necessary, the renderer is created or updated for
208*cdf0e10cSrcweir             	the metafile and attribute layer.
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir                 @return a renderer that renders to the given
211*cdf0e10cSrcweir                 destination canvas
212*cdf0e10cSrcweir              */
213*cdf0e10cSrcweir             ::cppcanvas::RendererSharedPtr getRenderer( const ::cppcanvas::CanvasSharedPtr&	rDestinationCanvas,
214*cdf0e10cSrcweir                                                         const GDIMetaFileSharedPtr&			rMtf,
215*cdf0e10cSrcweir                                                         const ShapeAttributeLayerSharedPtr&	rAttr ) const;
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         private:
219*cdf0e10cSrcweir             struct RendererCacheEntry
220*cdf0e10cSrcweir             {
221*cdf0e10cSrcweir                 RendererCacheEntry() :
222*cdf0e10cSrcweir                     mpDestinationCanvas(),
223*cdf0e10cSrcweir                     mpRenderer(),
224*cdf0e10cSrcweir                     mpMtf(),
225*cdf0e10cSrcweir                     mpLastBitmap(),
226*cdf0e10cSrcweir                     mpLastBitmapCanvas()
227*cdf0e10cSrcweir                 {
228*cdf0e10cSrcweir                 }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir                 ::cppcanvas::CanvasSharedPtr getDestinationCanvas()
231*cdf0e10cSrcweir                 {
232*cdf0e10cSrcweir                     return mpDestinationCanvas;
233*cdf0e10cSrcweir                 }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir                 ::cppcanvas::CanvasSharedPtr		mpDestinationCanvas;
236*cdf0e10cSrcweir                 ::cppcanvas::RendererSharedPtr		mpRenderer;
237*cdf0e10cSrcweir                 GDIMetaFileSharedPtr				mpMtf;
238*cdf0e10cSrcweir                 ::cppcanvas::BitmapSharedPtr		mpLastBitmap;
239*cdf0e10cSrcweir                 ::cppcanvas::BitmapCanvasSharedPtr	mpLastBitmapCanvas;
240*cdf0e10cSrcweir             };
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir             typedef ::std::vector< RendererCacheEntry >	RendererCacheVector;
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir             /** Prefetch Renderer for given canvas
246*cdf0e10cSrcweir              */
247*cdf0e10cSrcweir             bool prefetch( RendererCacheEntry&					io_rCacheEntry,
248*cdf0e10cSrcweir                            const ::cppcanvas::CanvasSharedPtr&	rDestinationCanvas,
249*cdf0e10cSrcweir                            const GDIMetaFileSharedPtr&			rMtf,
250*cdf0e10cSrcweir                            const ShapeAttributeLayerSharedPtr&	rAttr ) const;
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir             /** Draw with prefetched Renderer to stored canvas
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir             	This method draws prefetched Renderer to its
255*cdf0e10cSrcweir             	associated canvas (which happens to be mpLastCanvas).
256*cdf0e10cSrcweir              */
257*cdf0e10cSrcweir             bool draw( const ::cppcanvas::CanvasSharedPtr&	rDestinationCanvas,
258*cdf0e10cSrcweir                        const GDIMetaFileSharedPtr&			rMtf,
259*cdf0e10cSrcweir                        const ShapeAttributeLayerSharedPtr&	rAttr,
260*cdf0e10cSrcweir                        const ::basegfx::B2DHomMatrix&		rTransform,
261*cdf0e10cSrcweir                        const ::basegfx::B2DPolyPolygon*		pClip,
262*cdf0e10cSrcweir                        const VectorOfDocTreeNodes&			rSubsets ) const;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir             /** Render shape to an active sprite
265*cdf0e10cSrcweir              */
266*cdf0e10cSrcweir             bool renderSprite( const ViewLayerSharedPtr&            rViewLayer,
267*cdf0e10cSrcweir                                const GDIMetaFileSharedPtr&			rMtf,
268*cdf0e10cSrcweir                                const ::basegfx::B2DRectangle&		rOrigBounds,
269*cdf0e10cSrcweir                                const ::basegfx::B2DRectangle&		rBounds,
270*cdf0e10cSrcweir                                const ::basegfx::B2DRectangle&		rUnitBounds,
271*cdf0e10cSrcweir                                int									nUpdateFlags,
272*cdf0e10cSrcweir                                const ShapeAttributeLayerSharedPtr&	pAttr,
273*cdf0e10cSrcweir                                const VectorOfDocTreeNodes&			rSubsets,
274*cdf0e10cSrcweir                                double                               nPrio,
275*cdf0e10cSrcweir                                bool 								bIsVisible ) const;
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir             /** Render shape to given canvas
278*cdf0e10cSrcweir              */
279*cdf0e10cSrcweir             bool render( const ::cppcanvas::CanvasSharedPtr&	rDestinationCanvas,
280*cdf0e10cSrcweir                          const GDIMetaFileSharedPtr&			rMtf,
281*cdf0e10cSrcweir                          const ::basegfx::B2DRectangle&			rBounds,
282*cdf0e10cSrcweir                          const ::basegfx::B2DRectangle&			rUpdateBounds,
283*cdf0e10cSrcweir                          int									nUpdateFlags,
284*cdf0e10cSrcweir                          const ShapeAttributeLayerSharedPtr&	pAttr,
285*cdf0e10cSrcweir                          const VectorOfDocTreeNodes&			rSubsets,
286*cdf0e10cSrcweir                          bool 									bIsVisible ) const;
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir             /** Calc sprite size in pixel
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir             	Converts user coordinate system to device pixel, and
291*cdf0e10cSrcweir             	adds antialiasing border.
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir             	@param rUserSize
294*cdf0e10cSrcweir                 Size of the sprite in user coordinate system (doc coordinates)
295*cdf0e10cSrcweir              */
296*cdf0e10cSrcweir             ::basegfx::B2DSize calcSpriteSizePixel( const ::basegfx::B2DSize& rUserSize ) const;
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir             enum{ MAX_RENDER_CACHE_ENTRIES=2 };
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir             /** Retrieve a valid iterator to renderer cache entry
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir             	This method ensures that an internal limit of
303*cdf0e10cSrcweir             	MAX_RENDER_CACHE_ENTRIES is not exceeded.
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir             	@param rDestinationCanvas
306*cdf0e10cSrcweir                 Destination canvas to retrieve cache entry for
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir             	@return a valid iterator to a renderer cache entry for
309*cdf0e10cSrcweir             	the given canvas. The entry might be
310*cdf0e10cSrcweir             	default-constructed (if newly added)
311*cdf0e10cSrcweir              */
312*cdf0e10cSrcweir             RendererCacheVector::iterator getCacheEntry( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas ) const;
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir             void invalidateRenderer() const;
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir             /** The view layer this object is part of.
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir                 Needed for sprite creation
319*cdf0e10cSrcweir             */
320*cdf0e10cSrcweir             ViewLayerSharedPtr							mpViewLayer;
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir             /// A set of cached mtf/canvas combinations
323*cdf0e10cSrcweir             mutable RendererCacheVector					maRenderers;
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir             /// The sprite object
326*cdf0e10cSrcweir             mutable AnimatedSpriteSharedPtr				mpSprite;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir             /// If true, render() calls go to the sprite
329*cdf0e10cSrcweir             mutable bool								mbAnimationMode;
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir             /// If true, shape needs full repaint (and the sprite a setup, if any)
332*cdf0e10cSrcweir             mutable bool								mbForceUpdate;
333*cdf0e10cSrcweir         };
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir         typedef ::boost::shared_ptr< ViewShape > ViewShapeSharedPtr;
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_VIEWSHAPE_HXX */
341