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_SPRITECANVAS_HXX_
29 #define _CAIROCANVAS_SPRITECANVAS_HXX_
30 
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XServiceName.hpp>
36 #include <com/sun/star/awt/XWindowListener.hpp>
37 #include <com/sun/star/util/XUpdatable.hpp>
38 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
39 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
40 #include <com/sun/star/rendering/XGraphicDevice.hpp>
41 #include <com/sun/star/rendering/XBufferController.hpp>
42 
43 #include <cppuhelper/compbase9.hxx>
44 #include <comphelper/uno3.hxx>
45 
46 #include <canvas/base/spritecanvasbase.hxx>
47 #include <canvas/base/basemutexhelper.hxx>
48 #include <canvas/base/bufferedgraphicdevicebase.hxx>
49 
50 #include <basegfx/vector/b2isize.hxx>
51 
52 #include "cairo_spritedevicehelper.hxx"
53 #include "cairo_repainttarget.hxx"
54 #include "cairo_surfaceprovider.hxx"
55 #include "cairo_spritecanvashelper.hxx"
56 
57 #define SPRITECANVAS_SERVICE_NAME        "com.sun.star.rendering.SpriteCanvas.Cairo"
58 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas.Cairo"
59 
60 namespace cairocanvas
61 {
62     typedef ::cppu::WeakComponentImplHelper9< ::com::sun::star::rendering::XSpriteCanvas,
63                                                 ::com::sun::star::rendering::XIntegerBitmap,
64                                                 ::com::sun::star::rendering::XGraphicDevice,
65                                                 ::com::sun::star::lang::XMultiServiceFactory,
66                                                 ::com::sun::star::rendering::XBufferController,
67                                                 ::com::sun::star::awt::XWindowListener,
68                                                 ::com::sun::star::util::XUpdatable,
69                                                 ::com::sun::star::beans::XPropertySet,
70                                                 ::com::sun::star::lang::XServiceName >	WindowGraphicDeviceBase_Base;
71     typedef ::canvas::BufferedGraphicDeviceBase< ::canvas::BaseMutexHelper< WindowGraphicDeviceBase_Base >,
72                                                  SpriteDeviceHelper,
73                                                  ::osl::MutexGuard,
74                                                  ::cppu::OWeakObject > SpriteCanvasBase_Base;
75 	/** Mixin SpriteSurface
76 
77     	Have to mixin the SpriteSurface before deriving from
78     	::canvas::SpriteCanvasBase, as this template should already
79     	implement some of those interface methods.
80 
81         The reason why this appears kinda convoluted is the fact that
82         we cannot specify non-IDL types as WeakComponentImplHelperN
83         template args, and furthermore, don't want to derive
84         ::canvas::SpriteCanvasBase directly from
85         ::canvas::SpriteSurface (because derivees of
86         ::canvas::SpriteCanvasBase have to explicitely forward the
87         XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
88         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
89         remain a base class that provides implementation, not to
90         enforce any specific interface on its derivees.
91      */
92 	class SpriteCanvasBaseSpriteSurface_Base : public SpriteCanvasBase_Base,
93     										   public ::canvas::SpriteSurface,
94                                                public SurfaceProvider
95     {
96     };
97 
98 	typedef ::canvas::SpriteCanvasBase< SpriteCanvasBaseSpriteSurface_Base,
99                                         SpriteCanvasHelper,
100                                         ::osl::MutexGuard,
101                                         ::cppu::OWeakObject >			SpriteCanvasBaseT;
102 
103     /** Product of this component's factory.
104 
105 		The SpriteCanvas object combines the actual Window canvas with
106 		the XGraphicDevice interface. This is because there's a
107 		one-to-one relation between them, anyway, since each window
108 		can have exactly one canvas and one associated
109 		XGraphicDevice. And to avoid messing around with circular
110 		references, this is implemented as one single object.
111      */
112     class SpriteCanvas : public SpriteCanvasBaseT,
113 						 public RepaintTarget
114     {
115     public:
116         SpriteCanvas( const ::com::sun::star::uno::Sequence<
117                             ::com::sun::star::uno::Any >&               aArguments,
118                       const ::com::sun::star::uno::Reference<
119                             ::com::sun::star::uno::XComponentContext >& rxContext );
120 
121         void initialize();
122 
123 #if defined __SUNPRO_CC
124         using SpriteCanvasBaseT::disposing;
125 #endif
126 
127         /// Dispose all internal references
128         virtual void SAL_CALL disposing();
129 
130 		// Forwarding the XComponent implementation to the
131         // cppu::ImplHelper templated base
132         //                                    Classname     Base doing refcounting        Base implementing the XComponent interface
133         //                                       |                 |                            |
134         //                                       V                 V                            V
135         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( SpriteCanvas, WindowGraphicDeviceBase_Base, ::cppu::WeakComponentImplHelperBase );
136 
137         // XBufferController (partial)
138         virtual ::sal_Bool SAL_CALL showBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
139         virtual ::sal_Bool SAL_CALL switchBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
140 
141         // XSpriteCanvas (partial)
142         virtual sal_Bool SAL_CALL updateScreen( sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
143 
144         // XServiceName
145         virtual ::rtl::OUString SAL_CALL getServiceName(  ) throw (::com::sun::star::uno::RuntimeException);
146 
147         // SurfaceProvider
148 		virtual SurfaceSharedPtr getSurface();
149 		virtual SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, Content aContent = CAIRO_CONTENT_COLOR_ALPHA );
150 		virtual SurfaceSharedPtr createSurface( ::Bitmap& rBitmap );
151 		virtual SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent );
152 		virtual OutputDevice* getOutputDevice();
153 
154         // RepaintTarget
155         virtual bool repaint( const ::cairo::SurfaceSharedPtr&                pSurface,
156                               const ::com::sun::star::rendering::ViewState&	  viewState,
157                               const ::com::sun::star::rendering::RenderState& renderState );
158 
159 		SurfaceSharedPtr getWindowSurface();
160         SurfaceSharedPtr getBufferSurface();
161 
162 		const ::basegfx::B2ISize& getSizePixel();
163 		void setSizePixel( const ::basegfx::B2ISize& rSize );
164 		void flush();
165 
166      private:
167         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > maArguments;
168         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxComponentContext;
169     };
170 
171     typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
172 }
173 
174 #endif
175