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 _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX
29*cdf0e10cSrcweir #define _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <cppuhelper/compbase4.hxx>
32*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/rendering/XCustomSprite.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/rendering/XIntegerBitmap.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
41*cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx>
42*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <canvas/base/basemutexhelper.hxx>
45*cdf0e10cSrcweir #include <canvas/base/canvascustomspritebase.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include "cairo_sprite.hxx"
48*cdf0e10cSrcweir #include "cairo_cairo.hxx"
49*cdf0e10cSrcweir #include "cairo_canvashelper.hxx"
50*cdf0e10cSrcweir #include "cairo_repainttarget.hxx"
51*cdf0e10cSrcweir #include "cairo_spritehelper.hxx"
52*cdf0e10cSrcweir #include "cairo_spritecanvas.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace cairocanvas
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir     typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XCustomSprite,
58*cdf0e10cSrcweir 									 		  ::com::sun::star::rendering::XBitmapCanvas,
59*cdf0e10cSrcweir 											  ::com::sun::star::rendering::XIntegerBitmap,
60*cdf0e10cSrcweir                          			 		  ::com::sun::star::lang::XServiceInfo >	CanvasCustomSpriteBase_Base;
61*cdf0e10cSrcweir 	/** Mixin Sprite
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     	Have to mixin the Sprite interface before deriving from
64*cdf0e10cSrcweir     	::canvas::CanvasCustomSpriteBase, as this template should
65*cdf0e10cSrcweir     	already implement some of those interface methods.
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir         The reason why this appears kinda convoluted is the fact that
68*cdf0e10cSrcweir         we cannot specify non-IDL types as WeakComponentImplHelperN
69*cdf0e10cSrcweir         template args, and furthermore, don't want to derive
70*cdf0e10cSrcweir         ::canvas::CanvasCustomSpriteBase directly from
71*cdf0e10cSrcweir         ::canvas::Sprite (because derivees of
72*cdf0e10cSrcweir         ::canvas::CanvasCustomSpriteBase have to explicitely forward
73*cdf0e10cSrcweir         the XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
74*cdf0e10cSrcweir         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
75*cdf0e10cSrcweir         remain a base class that provides implementation, not to
76*cdf0e10cSrcweir         enforce any specific interface on its derivees.
77*cdf0e10cSrcweir      */
78*cdf0e10cSrcweir 	class CanvasCustomSpriteSpriteBase_Base : public ::canvas::BaseMutexHelper< CanvasCustomSpriteBase_Base >,
79*cdf0e10cSrcweir     									   	  public Sprite,
80*cdf0e10cSrcweir                                               public SurfaceProvider
81*cdf0e10cSrcweir     {
82*cdf0e10cSrcweir     };
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	typedef ::canvas::CanvasCustomSpriteBase< CanvasCustomSpriteSpriteBase_Base,
85*cdf0e10cSrcweir                                               SpriteHelper,
86*cdf0e10cSrcweir                                               CanvasHelper,
87*cdf0e10cSrcweir                                               ::osl::MutexGuard,
88*cdf0e10cSrcweir                                               ::cppu::OWeakObject > 					CanvasCustomSpriteBaseT;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	/* Definition of CanvasCustomSprite class */
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     class CanvasCustomSprite : public CanvasCustomSpriteBaseT,
93*cdf0e10cSrcweir 							   public RepaintTarget
94*cdf0e10cSrcweir     {
95*cdf0e10cSrcweir     public:
96*cdf0e10cSrcweir         /** Create a custom sprite
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 			@param rSpriteSize
99*cdf0e10cSrcweir             Size of the sprite in pixel
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir             @param rRefDevice
102*cdf0e10cSrcweir             Associated output device
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir             @param rSpriteCanvas
105*cdf0e10cSrcweir             Target canvas
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir             @param rDevice
108*cdf0e10cSrcweir             Target DX device
109*cdf0e10cSrcweir          */
110*cdf0e10cSrcweir         CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
111*cdf0e10cSrcweir                             const SpriteCanvasRef&                          rRefDevice );
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir         virtual void SAL_CALL disposing();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 		// Forwarding the XComponent implementation to the
116*cdf0e10cSrcweir         // cppu::ImplHelper templated base
117*cdf0e10cSrcweir         //                                    Classname           Base doing refcount          Base implementing the XComponent interface
118*cdf0e10cSrcweir         //                                          |                    |                         |
119*cdf0e10cSrcweir         //                                          V                    V                         V
120*cdf0e10cSrcweir         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSpriteBase_Base, ::cppu::WeakComponentImplHelperBase );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir         // XServiceInfo
123*cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
124*cdf0e10cSrcweir         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
125*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw( ::com::sun::star::uno::RuntimeException );
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir         // Sprite
128*cdf0e10cSrcweir         virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
129*cdf0e10cSrcweir                              bool                           bBufferedUpdate ) const;
130*cdf0e10cSrcweir         virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
131*cdf0e10cSrcweir                              const ::basegfx::B2DPoint&     rOrigOutputPos,
132*cdf0e10cSrcweir                              bool                           bBufferedUpdate ) const;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         // RepaintTarget
135*cdf0e10cSrcweir         virtual bool repaint( const ::cairo::SurfaceSharedPtr&                pSurface,
136*cdf0e10cSrcweir                               const ::com::sun::star::rendering::ViewState&	  viewState,
137*cdf0e10cSrcweir                               const ::com::sun::star::rendering::RenderState& renderState );
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 		// SurfaceProvider
140*cdf0e10cSrcweir 		virtual SurfaceSharedPtr getSurface();
141*cdf0e10cSrcweir 		virtual SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, Content aContent = CAIRO_CONTENT_COLOR_ALPHA );
142*cdf0e10cSrcweir 		virtual SurfaceSharedPtr createSurface( ::Bitmap& rBitmap );
143*cdf0e10cSrcweir 		virtual SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent );
144*cdf0e10cSrcweir 		virtual OutputDevice* getOutputDevice();
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     private:
147*cdf0e10cSrcweir         /** MUST hold here, too, since CanvasHelper only contains a
148*cdf0e10cSrcweir             raw pointer (without refcounting)
149*cdf0e10cSrcweir         */
150*cdf0e10cSrcweir         SpriteCanvasRef           mpSpriteCanvas;
151*cdf0e10cSrcweir 		::cairo::SurfaceSharedPtr mpBufferSurface;
152*cdf0e10cSrcweir 		::basegfx::B2ISize        maSize;
153*cdf0e10cSrcweir     };
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir #endif /* _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX */
157