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