xref: /aoo42x/main/canvas/source/vcl/spritecanvas.hxx (revision 6d53c851)
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_SPRITECANVAS_HXX_
25 #define _VCLCANVAS_SPRITECANVAS_HXX_
26 
27 #include <rtl/ref.hxx>
28 
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/lang/XServiceName.hpp>
32 #include <com/sun/star/awt/XWindowListener.hpp>
33 #include <com/sun/star/util/XUpdatable.hpp>
34 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
35 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
36 #include <com/sun/star/rendering/XGraphicDevice.hpp>
37 #include <com/sun/star/rendering/XBufferController.hpp>
38 
39 #include <cppuhelper/compbase9.hxx>
40 #include <comphelper/uno3.hxx>
41 
42 #include <canvas/base/spritecanvasbase.hxx>
43 #include <canvas/base/basemutexhelper.hxx>
44 #include <canvas/base/bufferedgraphicdevicebase.hxx>
45 
46 #include "spritecanvashelper.hxx"
47 #include "impltools.hxx"
48 #include "spritedevicehelper.hxx"
49 #include "repainttarget.hxx"
50 
51 
52 #define SPRITECANVAS_SERVICE_NAME        "com.sun.star.rendering.SpriteCanvas.VCL"
53 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas.VCL"
54 
55 namespace vclcanvas
56 {
57     typedef ::cppu::WeakComponentImplHelper9< ::com::sun::star::rendering::XSpriteCanvas,
58                                               ::com::sun::star::rendering::XIntegerBitmap,
59                                               ::com::sun::star::rendering::XGraphicDevice,
60                                               ::com::sun::star::lang::XMultiServiceFactory,
61                                               ::com::sun::star::rendering::XBufferController,
62                                               ::com::sun::star::awt::XWindowListener,
63                                               ::com::sun::star::util::XUpdatable,
64                                               ::com::sun::star::beans::XPropertySet,
65                                               ::com::sun::star::lang::XServiceName >	WindowGraphicDeviceBase_Base;
66     typedef ::canvas::BufferedGraphicDeviceBase< ::canvas::BaseMutexHelper< WindowGraphicDeviceBase_Base >,
67                                                  SpriteDeviceHelper,
68                                                  tools::LocalGuard,
69                                                  ::cppu::OWeakObject > 	SpriteCanvasBase_Base;
70 
71 	/** Mixin SpriteSurface
72 
73     	Have to mixin the SpriteSurface before deriving from
74     	::canvas::SpriteCanvasBase, as this template should already
75     	implement some of those interface methods.
76 
77         The reason why this appears kinda convoluted is the fact that
78         we cannot specify non-IDL types as WeakComponentImplHelperN
79         template args, and furthermore, don't want to derive
80         ::canvas::SpriteCanvasBase directly from
81         ::canvas::SpriteSurface (because derivees of
82         ::canvas::SpriteCanvasBase have to explicitly forward the
83         XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
84         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
85         remain a base class that provides implementation, not to
86         enforce any specific interface on its derivees.
87      */
88 	class SpriteCanvasBaseSpriteSurface_Base : public SpriteCanvasBase_Base,
89     										   public ::canvas::SpriteSurface
90     {
91     };
92 
93 	typedef ::canvas::SpriteCanvasBase< SpriteCanvasBaseSpriteSurface_Base,
94                                         SpriteCanvasHelper,
95                                         tools::LocalGuard,
96                                         ::cppu::OWeakObject >			SpriteCanvasBaseT;
97 
98     /** Product of this component's factory.
99 
100 		The SpriteCanvas object combines the actual Window canvas with
101 		the XGraphicDevice interface. This is because there's a
102 		one-to-one relation between them, anyway, since each window
103 		can have exactly one canvas and one associated
104 		XGraphicDevice. And to avoid messing around with circular
105 		references, this is implemented as one single object.
106      */
107     class SpriteCanvas : public SpriteCanvasBaseT,
108                          public RepaintTarget
109     {
110     public:
111         SpriteCanvas( const ::com::sun::star::uno::Sequence<
112                             ::com::sun::star::uno::Any >&               aArguments,
113                       const ::com::sun::star::uno::Reference<
114                             ::com::sun::star::uno::XComponentContext >& rxContext );
115 
116         void initialize();
117 
118         /// For resource tracking
119         ~SpriteCanvas();
120 
121 #if defined __SUNPRO_CC
122         using SpriteCanvasBaseT::disposing;
123 #endif
124 
125         /// Dispose all internal references
126         virtual void SAL_CALL disposing();
127 
128 		// Forwarding the XComponent implementation to the
129         // cppu::ImplHelper templated base
130         //                                    Classname     Base doing refcounting        Base implementing the XComponent interface
131         //                                       |                 |                            |
132         //                                       V                 V                            V
133         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( SpriteCanvas, WindowGraphicDeviceBase_Base, ::cppu::WeakComponentImplHelperBase );
134 
135         // XBufferController (partial)
136         virtual ::sal_Bool SAL_CALL showBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
137         virtual ::sal_Bool SAL_CALL switchBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
138 
139         // XSpriteCanvas (partial)
140         virtual sal_Bool SAL_CALL updateScreen( sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
141 
142         // XServiceName
143         virtual ::rtl::OUString SAL_CALL getServiceName(  ) throw (::com::sun::star::uno::RuntimeException);
144 
145         // RepaintTarget
146         virtual bool repaint( const GraphicObjectSharedPtr&                   rGrf,
147                               const ::com::sun::star::rendering::ViewState&   viewState,
148                               const ::com::sun::star::rendering::RenderState& renderState,
149                               const ::Point&                                  rPt,
150                               const ::Size&                                   rSz,
151                               const GraphicAttr&                              rAttr ) const;
152 
153         /// Get backbuffer for this canvas
getFrontBuffer() const154         OutDevProviderSharedPtr getFrontBuffer() const { return maDeviceHelper.getOutDev(); }
155         /// Get window for this canvas
getBackBuffer() const156         BackBufferSharedPtr getBackBuffer() const { return maDeviceHelper.getBackBuffer(); }
157 
158     private:
159         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > maArguments;
160         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxComponentContext;
161     };
162 
163     typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
164     typedef ::rtl::Reference< SpriteCanvas > DeviceRef;
165 
166 }
167 
168 #endif
169