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 _VCLCANVAS_CANVASCUSTOMSPRITE_HXX
25 #define _VCLCANVAS_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 <vcl/virdev.hxx>
37 
38 #include <canvas/vclwrapper.hxx>
39 #include <canvas/base/basemutexhelper.hxx>
40 #include <canvas/base/spritesurface.hxx>
41 #include <canvas/base/canvascustomspritebase.hxx>
42 
43 #include "sprite.hxx"
44 #include "canvashelper.hxx"
45 #include "spritehelper.hxx"
46 #include "backbuffer.hxx"
47 #include "impltools.hxx"
48 #include "spritecanvas.hxx"
49 #include "repainttarget.hxx"
50 
51 
52 namespace vclcanvas
53 {
54     typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XCustomSprite,
55 									 		  ::com::sun::star::rendering::XBitmapCanvas,
56 											  ::com::sun::star::rendering::XIntegerBitmap,
57                          			 		  ::com::sun::star::lang::XServiceInfo >	CanvasCustomSpriteBase_Base;
58 	/** Mixin Sprite
59 
60     	Have to mixin the Sprite interface before deriving from
61     	::canvas::CanvasCustomSpriteBase, as this template should
62     	already implement some of those interface methods.
63 
64         The reason why this appears kinda convoluted is the fact that
65         we cannot specify non-IDL types as WeakComponentImplHelperN
66         template args, and furthermore, don't want to derive
67         ::canvas::CanvasCustomSpriteBase directly from
68         ::canvas::Sprite (because derivees of
69         ::canvas::CanvasCustomSpriteBase have to explicitly forward
70         the XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
71         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
72         remain a base class that provides implementation, not to
73         enforce any specific interface on its derivees.
74      */
75 	class CanvasCustomSpriteSpriteBase_Base : public ::canvas::BaseMutexHelper< CanvasCustomSpriteBase_Base >,
76     									   	  public Sprite
77     {
78     };
79 
80 	typedef ::canvas::CanvasCustomSpriteBase< CanvasCustomSpriteSpriteBase_Base,
81                                               SpriteHelper,
82                                               CanvasHelper,
83                                               tools::LocalGuard,
84                                               ::cppu::OWeakObject > 					CanvasCustomSpriteBaseT;
85 
86 	/* Definition of CanvasCustomSprite class */
87 
88     class CanvasCustomSprite : public CanvasCustomSpriteBaseT,
89                                public RepaintTarget
90     {
91     public:
92         CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& rSpriteSize,
93                             ::com::sun::star::rendering::XGraphicDevice&  rDevice,
94                             const ::canvas::SpriteSurface::Reference&     rOwningSpriteCanvas,
95                             const OutDevProviderSharedPtr&                rOutDevProvider,
96                             bool                                          bShowSpriteBounds );
97 
98         virtual void SAL_CALL disposing();
99 
100 		// Forwarding the XComponent implementation to the
101         // cppu::ImplHelper templated base
102         //                                    Classname           Base doing refcount          Base implementing the XComponent interface
103         //                                          |                    |                         |
104         //                                          V                    V                         V
105         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSpriteBase_Base, ::cppu::WeakComponentImplHelperBase );
106 
107         // XServiceInfo
108         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
109         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
110         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw( ::com::sun::star::uno::RuntimeException );
111 
112         // Sprite
113         virtual void redraw( OutputDevice& rOutDev,
114                              bool          bBufferedUpdate ) const;
115         virtual void redraw( OutputDevice&              rOutDev,
116                              const ::basegfx::B2DPoint& rPos,
117                              bool                       bBufferedUpdate ) const;
118 
119         // RepaintTarget
120         virtual bool repaint( const GraphicObjectSharedPtr&                   rGrf,
121                               const ::com::sun::star::rendering::ViewState&   viewState,
122                               const ::com::sun::star::rendering::RenderState& renderState,
123                               const ::Point&                                  rPt,
124                               const ::Size&                                   rSz,
125                               const GraphicAttr&                              rAttr ) const;
126     };
127 }
128 
129 #endif /* _VCLCANVAS_CANVASCUSTOMSPRITE_HXX */
130