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