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 _NULLCANVAS_SPRITECANVAS_HXX_
29 #define _NULLCANVAS_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/rendering/XSpriteCanvas.hpp>
38 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
39 #include <com/sun/star/rendering/XGraphicDevice.hpp>
40 #include <com/sun/star/rendering/XBufferController.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 
43 #include <cppuhelper/compbase8.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 "null_spritecanvashelper.hxx"
51 #include "null_devicehelper.hxx"
52 #include "null_usagecounter.hxx"
53 
54 
55 namespace nullcanvas
56 {
57     typedef ::cppu::WeakComponentImplHelper8<  ::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::beans::XPropertySet,
64                                                ::com::sun::star::lang::XServiceName >	WindowGraphicDeviceBase_Base;
65     typedef ::canvas::BufferedGraphicDeviceBase< ::canvas::BaseMutexHelper< WindowGraphicDeviceBase_Base >,
66                                                    DeviceHelper,
67                                                    ::osl::MutexGuard,
68                                                    ::cppu::OWeakObject > 	SpriteCanvasBase_Base;
69 	/** Mixin SpriteSurface
70 
71     	Have to mixin the SpriteSurface before deriving from
72     	::canvas::SpriteCanvasBase, as this template should already
73     	implement some of those interface methods.
74 
75         The reason why this appears kinda convoluted is the fact that
76         we cannot specify non-IDL types as WeakComponentImplHelperN
77         template args, and furthermore, don't want to derive
78         ::canvas::SpriteCanvasBase directly from
79         ::canvas::SpriteSurface (because derivees of
80         ::canvas::SpriteCanvasBase have to explicitely forward the
81         XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
82         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
83         remain a base class that provides implementation, not to
84         enforce any specific interface on its derivees.
85      */
86 	class SpriteCanvasBaseSpriteSurface_Base : public SpriteCanvasBase_Base,
87     										   public ::canvas::SpriteSurface
88     {
89     };
90 
91 	typedef ::canvas::SpriteCanvasBase< SpriteCanvasBaseSpriteSurface_Base,
92                                         SpriteCanvasHelper,
93                                         ::osl::MutexGuard,
94                                         ::cppu::OWeakObject >			SpriteCanvasBaseT;
95 
96     /** Product of this component's factory.
97 
98 		The SpriteCanvas object combines the actual Window canvas with
99 		the XGraphicDevice interface. This is because there's a
100 		one-to-one relation between them, anyway, since each window
101 		can have exactly one canvas and one associated
102 		XGraphicDevice. And to avoid messing around with circular
103 		references, this is implemented as one single object.
104      */
105     class SpriteCanvas : public SpriteCanvasBaseT,
106                          private UsageCounter< SpriteCanvas >
107     {
108     public:
109         SpriteCanvas( const ::com::sun::star::uno::Sequence<
110                             ::com::sun::star::uno::Any >&               aArguments,
111                       const ::com::sun::star::uno::Reference<
112                             ::com::sun::star::uno::XComponentContext >& rxContext );
113 
114         void initialize();
115 
116 #if defined __SUNPRO_CC
117         using SpriteCanvasBaseT::disposing;
118 #endif
119 
120         /// Dispose all internal references
121         virtual void SAL_CALL disposing();
122 
123 		// Forwarding the XComponent implementation to the
124         // cppu::ImplHelper templated base
125         //                                    Classname     Base doing refcounting        Base implementing the XComponent interface
126         //                                       |                 |                            |
127         //                                       V                 V                            V
128         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( SpriteCanvas, WindowGraphicDeviceBase_Base, ::cppu::WeakComponentImplHelperBase );
129 
130         // XBufferController (partial)
131         virtual ::sal_Bool SAL_CALL showBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
132         virtual ::sal_Bool SAL_CALL switchBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
133 
134         // XSpriteCanvas (partial)
135         virtual sal_Bool SAL_CALL updateScreen( sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
136 
137         // XServiceName
138         virtual ::rtl::OUString SAL_CALL getServiceName(  ) throw (::com::sun::star::uno::RuntimeException);
139 
140      private:
141         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > maArguments;
142         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxComponentContext;
143     };
144 
145     typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
146     typedef ::rtl::Reference< SpriteCanvas > DeviceRef;
147 }
148 
149 #endif
150