1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX
29 #define _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX
30 
31 #include <cppuhelper/compbase4.hxx>
32 #include <comphelper/uno3.hxx>
33 
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/rendering/XCustomSprite.hpp>
37 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
38 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
39 
40 #include <basegfx/point/b2dpoint.hxx>
41 #include <basegfx/vector/b2isize.hxx>
42 #include <basegfx/matrix/b2dhommatrix.hxx>
43 
44 #include <canvas/base/basemutexhelper.hxx>
45 #include <canvas/base/canvascustomspritebase.hxx>
46 
47 #include "cairo_sprite.hxx"
48 #include "cairo_cairo.hxx"
49 #include "cairo_canvashelper.hxx"
50 #include "cairo_repainttarget.hxx"
51 #include "cairo_spritehelper.hxx"
52 #include "cairo_spritecanvas.hxx"
53 
54 
55 namespace cairocanvas
56 {
57     typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XCustomSprite,
58 									 		  ::com::sun::star::rendering::XBitmapCanvas,
59 											  ::com::sun::star::rendering::XIntegerBitmap,
60                          			 		  ::com::sun::star::lang::XServiceInfo >	CanvasCustomSpriteBase_Base;
61 	/** Mixin Sprite
62 
63     	Have to mixin the Sprite interface before deriving from
64     	::canvas::CanvasCustomSpriteBase, as this template should
65     	already implement some of those interface methods.
66 
67         The reason why this appears kinda convoluted is the fact that
68         we cannot specify non-IDL types as WeakComponentImplHelperN
69         template args, and furthermore, don't want to derive
70         ::canvas::CanvasCustomSpriteBase directly from
71         ::canvas::Sprite (because derivees of
72         ::canvas::CanvasCustomSpriteBase have to explicitely forward
73         the XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
74         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
75         remain a base class that provides implementation, not to
76         enforce any specific interface on its derivees.
77      */
78 	class CanvasCustomSpriteSpriteBase_Base : public ::canvas::BaseMutexHelper< CanvasCustomSpriteBase_Base >,
79     									   	  public Sprite,
80                                               public SurfaceProvider
81     {
82     };
83 
84 	typedef ::canvas::CanvasCustomSpriteBase< CanvasCustomSpriteSpriteBase_Base,
85                                               SpriteHelper,
86                                               CanvasHelper,
87                                               ::osl::MutexGuard,
88                                               ::cppu::OWeakObject > 					CanvasCustomSpriteBaseT;
89 
90 	/* Definition of CanvasCustomSprite class */
91 
92     class CanvasCustomSprite : public CanvasCustomSpriteBaseT,
93 							   public RepaintTarget
94     {
95     public:
96         /** Create a custom sprite
97 
98 			@param rSpriteSize
99             Size of the sprite in pixel
100 
101             @param rRefDevice
102             Associated output device
103 
104             @param rSpriteCanvas
105             Target canvas
106 
107             @param rDevice
108             Target DX device
109          */
110         CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
111                             const SpriteCanvasRef&                          rRefDevice );
112 
113         virtual void SAL_CALL disposing();
114 
115 		// Forwarding the XComponent implementation to the
116         // cppu::ImplHelper templated base
117         //                                    Classname           Base doing refcount          Base implementing the XComponent interface
118         //                                          |                    |                         |
119         //                                          V                    V                         V
120         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSpriteBase_Base, ::cppu::WeakComponentImplHelperBase );
121 
122         // XServiceInfo
123         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
124         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
125         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw( ::com::sun::star::uno::RuntimeException );
126 
127         // Sprite
128         virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
129                              bool                           bBufferedUpdate ) const;
130         virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
131                              const ::basegfx::B2DPoint&     rOrigOutputPos,
132                              bool                           bBufferedUpdate ) const;
133 
134         // RepaintTarget
135         virtual bool repaint( const ::cairo::SurfaceSharedPtr&                pSurface,
136                               const ::com::sun::star::rendering::ViewState&	  viewState,
137                               const ::com::sun::star::rendering::RenderState& renderState );
138 
139 		// SurfaceProvider
140 		virtual SurfaceSharedPtr getSurface();
141 		virtual SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, Content aContent = CAIRO_CONTENT_COLOR_ALPHA );
142 		virtual SurfaceSharedPtr createSurface( ::Bitmap& rBitmap );
143 		virtual SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent );
144 		virtual OutputDevice* getOutputDevice();
145 
146     private:
147         /** MUST hold here, too, since CanvasHelper only contains a
148             raw pointer (without refcounting)
149         */
150         SpriteCanvasRef           mpSpriteCanvas;
151 		::cairo::SurfaceSharedPtr mpBufferSurface;
152 		::basegfx::B2ISize        maSize;
153     };
154 }
155 
156 #endif /* _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX */
157