xref: /aoo42x/main/canvas/source/vcl/spritecanvas.hxx (revision cdf0e10c)
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 _VCLCANVAS_SPRITECANVAS_HXX_
29 #define _VCLCANVAS_SPRITECANVAS_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/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 "spritecanvashelper.hxx"
51 #include "impltools.hxx"
52 #include "spritedevicehelper.hxx"
53 #include "repainttarget.hxx"
54 
55 
56 #define SPRITECANVAS_SERVICE_NAME        "com.sun.star.rendering.SpriteCanvas.VCL"
57 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas.VCL"
58 
59 namespace vclcanvas
60 {
61     typedef ::cppu::WeakComponentImplHelper9< ::com::sun::star::rendering::XSpriteCanvas,
62                                               ::com::sun::star::rendering::XIntegerBitmap,
63                                               ::com::sun::star::rendering::XGraphicDevice,
64                                               ::com::sun::star::lang::XMultiServiceFactory,
65                                               ::com::sun::star::rendering::XBufferController,
66                                               ::com::sun::star::awt::XWindowListener,
67                                               ::com::sun::star::util::XUpdatable,
68                                               ::com::sun::star::beans::XPropertySet,
69                                               ::com::sun::star::lang::XServiceName >	WindowGraphicDeviceBase_Base;
70     typedef ::canvas::BufferedGraphicDeviceBase< ::canvas::BaseMutexHelper< WindowGraphicDeviceBase_Base >,
71                                                  SpriteDeviceHelper,
72                                                  tools::LocalGuard,
73                                                  ::cppu::OWeakObject > 	SpriteCanvasBase_Base;
74 
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     {
95     };
96 
97 	typedef ::canvas::SpriteCanvasBase< SpriteCanvasBaseSpriteSurface_Base,
98                                         SpriteCanvasHelper,
99                                         tools::LocalGuard,
100                                         ::cppu::OWeakObject >			SpriteCanvasBaseT;
101 
102     /** Product of this component's factory.
103 
104 		The SpriteCanvas object combines the actual Window canvas with
105 		the XGraphicDevice interface. This is because there's a
106 		one-to-one relation between them, anyway, since each window
107 		can have exactly one canvas and one associated
108 		XGraphicDevice. And to avoid messing around with circular
109 		references, this is implemented as one single object.
110      */
111     class SpriteCanvas : public SpriteCanvasBaseT,
112                          public RepaintTarget
113     {
114     public:
115         SpriteCanvas( const ::com::sun::star::uno::Sequence<
116                             ::com::sun::star::uno::Any >&               aArguments,
117                       const ::com::sun::star::uno::Reference<
118                             ::com::sun::star::uno::XComponentContext >& rxContext );
119 
120         void initialize();
121 
122         /// For resource tracking
123         ~SpriteCanvas();
124 
125 #if defined __SUNPRO_CC
126         using SpriteCanvasBaseT::disposing;
127 #endif
128 
129         /// Dispose all internal references
130         virtual void SAL_CALL disposing();
131 
132 		// Forwarding the XComponent implementation to the
133         // cppu::ImplHelper templated base
134         //                                    Classname     Base doing refcounting        Base implementing the XComponent interface
135         //                                       |                 |                            |
136         //                                       V                 V                            V
137         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( SpriteCanvas, WindowGraphicDeviceBase_Base, ::cppu::WeakComponentImplHelperBase );
138 
139         // XBufferController (partial)
140         virtual ::sal_Bool SAL_CALL showBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
141         virtual ::sal_Bool SAL_CALL switchBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
142 
143         // XSpriteCanvas (partial)
144         virtual sal_Bool SAL_CALL updateScreen( sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
145 
146         // XServiceName
147         virtual ::rtl::OUString SAL_CALL getServiceName(  ) throw (::com::sun::star::uno::RuntimeException);
148 
149         // RepaintTarget
150         virtual bool repaint( const GraphicObjectSharedPtr&                   rGrf,
151                               const ::com::sun::star::rendering::ViewState&   viewState,
152                               const ::com::sun::star::rendering::RenderState& renderState,
153                               const ::Point&                                  rPt,
154                               const ::Size&                                   rSz,
155                               const GraphicAttr&                              rAttr ) const;
156 
157         /// Get backbuffer for this canvas
158         OutDevProviderSharedPtr getFrontBuffer() const { return maDeviceHelper.getOutDev(); }
159         /// Get window for this canvas
160         BackBufferSharedPtr getBackBuffer() const { return maDeviceHelper.getBackBuffer(); }
161 
162     private:
163         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > maArguments;
164         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxComponentContext;
165     };
166 
167     typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
168     typedef ::rtl::Reference< SpriteCanvas > DeviceRef;
169 
170 }
171 
172 #endif
173