1*91c99ff4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*91c99ff4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*91c99ff4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*91c99ff4SAndrew Rist  * distributed with this work for additional information
6*91c99ff4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*91c99ff4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*91c99ff4SAndrew Rist  * "License"); you may not use this file except in compliance
9*91c99ff4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*91c99ff4SAndrew Rist  *
11*91c99ff4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*91c99ff4SAndrew Rist  *
13*91c99ff4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*91c99ff4SAndrew Rist  * software distributed under the License is distributed on an
15*91c99ff4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*91c99ff4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*91c99ff4SAndrew Rist  * specific language governing permissions and limitations
18*91c99ff4SAndrew Rist  * under the License.
19*91c99ff4SAndrew Rist  *
20*91c99ff4SAndrew Rist  *************************************************************/
21*91c99ff4SAndrew Rist 
22*91c99ff4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX
25cdf0e10cSrcweir #define _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <cppuhelper/compbase4.hxx>
28cdf0e10cSrcweir #include <comphelper/uno3.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
32cdf0e10cSrcweir #include <com/sun/star/rendering/XCustomSprite.hpp>
33cdf0e10cSrcweir #include <com/sun/star/rendering/XIntegerBitmap.hpp>
34cdf0e10cSrcweir #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
37cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx>
38cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <canvas/base/basemutexhelper.hxx>
41cdf0e10cSrcweir #include <canvas/base/canvascustomspritebase.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include "cairo_sprite.hxx"
44cdf0e10cSrcweir #include "cairo_cairo.hxx"
45cdf0e10cSrcweir #include "cairo_canvashelper.hxx"
46cdf0e10cSrcweir #include "cairo_repainttarget.hxx"
47cdf0e10cSrcweir #include "cairo_spritehelper.hxx"
48cdf0e10cSrcweir #include "cairo_spritecanvas.hxx"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace cairocanvas
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XCustomSprite,
54cdf0e10cSrcweir 									 		  ::com::sun::star::rendering::XBitmapCanvas,
55cdf0e10cSrcweir 											  ::com::sun::star::rendering::XIntegerBitmap,
56cdf0e10cSrcweir                          			 		  ::com::sun::star::lang::XServiceInfo >	CanvasCustomSpriteBase_Base;
57cdf0e10cSrcweir 	/** Mixin Sprite
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     	Have to mixin the Sprite interface before deriving from
60cdf0e10cSrcweir     	::canvas::CanvasCustomSpriteBase, as this template should
61cdf0e10cSrcweir     	already implement some of those interface methods.
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         The reason why this appears kinda convoluted is the fact that
64cdf0e10cSrcweir         we cannot specify non-IDL types as WeakComponentImplHelperN
65cdf0e10cSrcweir         template args, and furthermore, don't want to derive
66cdf0e10cSrcweir         ::canvas::CanvasCustomSpriteBase directly from
67cdf0e10cSrcweir         ::canvas::Sprite (because derivees of
68cdf0e10cSrcweir         ::canvas::CanvasCustomSpriteBase have to explicitely forward
69cdf0e10cSrcweir         the XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
70cdf0e10cSrcweir         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
71cdf0e10cSrcweir         remain a base class that provides implementation, not to
72cdf0e10cSrcweir         enforce any specific interface on its derivees.
73cdf0e10cSrcweir      */
74cdf0e10cSrcweir 	class CanvasCustomSpriteSpriteBase_Base : public ::canvas::BaseMutexHelper< CanvasCustomSpriteBase_Base >,
75cdf0e10cSrcweir     									   	  public Sprite,
76cdf0e10cSrcweir                                               public SurfaceProvider
77cdf0e10cSrcweir     {
78cdf0e10cSrcweir     };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	typedef ::canvas::CanvasCustomSpriteBase< CanvasCustomSpriteSpriteBase_Base,
81cdf0e10cSrcweir                                               SpriteHelper,
82cdf0e10cSrcweir                                               CanvasHelper,
83cdf0e10cSrcweir                                               ::osl::MutexGuard,
84cdf0e10cSrcweir                                               ::cppu::OWeakObject > 					CanvasCustomSpriteBaseT;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	/* Definition of CanvasCustomSprite class */
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     class CanvasCustomSprite : public CanvasCustomSpriteBaseT,
89cdf0e10cSrcweir 							   public RepaintTarget
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir     public:
92cdf0e10cSrcweir         /** Create a custom sprite
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 			@param rSpriteSize
95cdf0e10cSrcweir             Size of the sprite in pixel
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             @param rRefDevice
98cdf0e10cSrcweir             Associated output device
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             @param rSpriteCanvas
101cdf0e10cSrcweir             Target canvas
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             @param rDevice
104cdf0e10cSrcweir             Target DX device
105cdf0e10cSrcweir          */
106cdf0e10cSrcweir         CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
107cdf0e10cSrcweir                             const SpriteCanvasRef&                          rRefDevice );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         virtual void SAL_CALL disposing();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		// Forwarding the XComponent implementation to the
112cdf0e10cSrcweir         // cppu::ImplHelper templated base
113cdf0e10cSrcweir         //                                    Classname           Base doing refcount          Base implementing the XComponent interface
114cdf0e10cSrcweir         //                                          |                    |                         |
115cdf0e10cSrcweir         //                                          V                    V                         V
116cdf0e10cSrcweir         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSpriteBase_Base, ::cppu::WeakComponentImplHelperBase );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         // XServiceInfo
119cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
120cdf0e10cSrcweir         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
121cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw( ::com::sun::star::uno::RuntimeException );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         // Sprite
124cdf0e10cSrcweir         virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
125cdf0e10cSrcweir                              bool                           bBufferedUpdate ) const;
126cdf0e10cSrcweir         virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
127cdf0e10cSrcweir                              const ::basegfx::B2DPoint&     rOrigOutputPos,
128cdf0e10cSrcweir                              bool                           bBufferedUpdate ) const;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         // RepaintTarget
131cdf0e10cSrcweir         virtual bool repaint( const ::cairo::SurfaceSharedPtr&                pSurface,
132cdf0e10cSrcweir                               const ::com::sun::star::rendering::ViewState&	  viewState,
133cdf0e10cSrcweir                               const ::com::sun::star::rendering::RenderState& renderState );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		// SurfaceProvider
136cdf0e10cSrcweir 		virtual SurfaceSharedPtr getSurface();
137cdf0e10cSrcweir 		virtual SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, Content aContent = CAIRO_CONTENT_COLOR_ALPHA );
138cdf0e10cSrcweir 		virtual SurfaceSharedPtr createSurface( ::Bitmap& rBitmap );
139cdf0e10cSrcweir 		virtual SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent );
140cdf0e10cSrcweir 		virtual OutputDevice* getOutputDevice();
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     private:
143cdf0e10cSrcweir         /** MUST hold here, too, since CanvasHelper only contains a
144cdf0e10cSrcweir             raw pointer (without refcounting)
145cdf0e10cSrcweir         */
146cdf0e10cSrcweir         SpriteCanvasRef           mpSpriteCanvas;
147cdf0e10cSrcweir 		::cairo::SurfaceSharedPtr mpBufferSurface;
148cdf0e10cSrcweir 		::basegfx::B2ISize        maSize;
149cdf0e10cSrcweir     };
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir #endif /* _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX */
153