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 _NULLCANVAS_CANVASCUSTOMSPRITE_HXX
25 #define _NULLCANVAS_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 "sprite.hxx"
44 #include "null_canvashelper.hxx"
45 #include "null_spritehelper.hxx"
46 #include "null_spritecanvas.hxx"
47 #include "null_usagecounter.hxx"
48 
49 
50 namespace nullcanvas
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                                               CanvasHelper,
81                                               ::osl::MutexGuard,
82                                               ::cppu::OWeakObject > 					CanvasCustomSpriteBaseT;
83 
84 	/* Definition of CanvasCustomSprite class */
85 
86     class CanvasCustomSprite : public CanvasCustomSpriteBaseT,
87                                private UsageCounter< CanvasCustomSprite >
88     {
89     public:
90         /** Create a custom sprite
91 
92 			@param rSpriteSize
93             Size of the sprite in pixel
94 
95             @param rRefDevice
96             Associated output device
97 
98             @param rSpriteCanvas
99             Target canvas
100 
101             @param rDevice
102             Target DX device
103          */
104         CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
105                             const SpriteCanvasRef&                          rRefDevice );
106 
107         virtual void SAL_CALL disposing();
108 
109 		// Forwarding the XComponent implementation to the
110         // cppu::ImplHelper templated base
111         //                                    Classname           Base doing refcount          Base implementing the XComponent interface
112         //                                          |                    |                         |
113         //                                          V                    V                         V
114         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSpriteBase_Base, ::cppu::WeakComponentImplHelperBase );
115 
116         // XServiceInfo
117         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
118         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
119         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw( ::com::sun::star::uno::RuntimeException );
120 
121         // Sprite
122         virtual void redraw() const;
123 
124     private:
125         /** MUST hold here, too, since CanvasHelper only contains a
126             raw pointer (without refcounting)
127         */
128         SpriteCanvasRef mpSpriteCanvas;
129     };
130 }
131 
132 #endif /* _NULLCANVAS_CANVASCUSTOMSPRITE_HXX */
133