Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX
30 : : #define INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX
31 : :
32 : : #include <rtl/ref.hxx>
33 : : #include <com/sun/star/lang/XServiceInfo.hpp>
34 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 : : #include <com/sun/star/beans/XPropertySet.hpp>
36 : : #include <com/sun/star/util/XUpdatable.hpp>
37 : : #include <com/sun/star/rendering/XGraphicDevice.hpp>
38 : : #include <com/sun/star/rendering/XColorSpace.hpp>
39 : :
40 : : #include <canvas/parametricpolypolygon.hxx>
41 : : #include <canvas/propertysethelper.hxx>
42 : :
43 : :
44 : : /* Definition of GraphicDeviceBase class */
45 : :
46 : : namespace canvas
47 : : {
48 : : /** Helper template base class for XGraphicDevice implementations.
49 : :
50 : : This base class provides partial implementations of the
51 : : XGraphicDevice-related interface, such as XColorSpace.
52 : :
53 : : This template basically interposes itself between the full
54 : : interface you implement (i.e. not restricted to XGraphicDevice
55 : : etc.). The problem with UNO partial interface implementation
56 : : actually is, that you cannot do it the plain way, since
57 : : deriving from a common base subclass always introduces the
58 : : whole set of pure virtuals, that your baseclass helper just
59 : : overrided) and your implementation class. You then only have
60 : : to implement the functionality <em>besides</em>
61 : : XGraphicDevice. If you want to support the optional debug
62 : : XUpdatable interface, also add that to the base classes
63 : : (client code will call the corresponding update() method,
64 : : whenever a burst of animations is over).
65 : :
66 : : <pre>
67 : : Example:
68 : : typedef ::cppu::WeakComponentImplHelper5< ::com::sun::star::rendering::XGraphicDevice,
69 : : ::com::sun::star::rendering::XColorSpace,
70 : : ::com::sun::star::rendering::XPropertySet,
71 : : ::com::sun::star::lang::XServiceInfo,
72 : : ::com::sun::star::lang::XServiceName > GraphicDeviceBase_Base;
73 : : typedef ::canvas::internal::GraphicDeviceBase< GraphicDeviceBase, DeviceHelper > ExampleDevice_Base;
74 : :
75 : : class ExampleDevice : public ExampleDevice_Base
76 : : {
77 : : };
78 : : </pre>
79 : :
80 : : @tpl Base
81 : : Base class to use, most probably one of the
82 : : WeakComponentImplHelperN templates with the appropriate
83 : : interfaces. At least XGraphicDevice should be among them (why else
84 : : would you use this template, then?). Base class must have an
85 : : Base( const Mutex& ) constructor (like the
86 : : WeakComponentImplHelperN templates have). As the very least,
87 : : the base class must be derived from uno::XInterface, as some
88 : : error reporting mechanisms rely on that.
89 : :
90 : : @tpl DeviceHelper
91 : : Device helper implementation for the backend in question. This
92 : : object will be held as a member of this template class, and
93 : : basically gets forwarded all XGraphicDevice API calls that
94 : : could not be handled generically.
95 : :
96 : : @tpl Mutex
97 : : Lock strategy to use. Defaults to using the
98 : : DisambiguationHelper-provided lock. Everytime one of the methods is
99 : : entered, an object of type Mutex is created with m_aMutex as
100 : : the sole parameter, and destroyed again when the method scope
101 : : is left.
102 : :
103 : : @tpl UnambiguousBase
104 : : Optional unambiguous base class for XInterface of Base. It's
105 : : sometimes necessary to specify this parameter, e.g. if Base
106 : : derives from multiple UNO interface (were each provides its
107 : : own version of XInterface, making the conversion ambiguous)
108 : : */
109 : : template< class Base,
110 : : class DeviceHelper,
111 : : class Mutex=::osl::MutexGuard,
112 : : class UnambiguousBase=::com::sun::star::uno::XInterface > class GraphicDeviceBase :
113 : : public Base
114 : : {
115 : : public:
116 : : typedef Base BaseType;
117 : : typedef DeviceHelper DeviceHelperType;
118 : : typedef Mutex MutexType;
119 : : typedef UnambiguousBase UnambiguousBaseType;
120 : : typedef GraphicDeviceBase ThisType;
121 : :
122 : : typedef ::rtl::Reference< GraphicDeviceBase > Reference;
123 : :
124 : 0 : GraphicDeviceBase() :
125 : : maDeviceHelper(),
126 : : maPropHelper(),
127 : 0 : mbDumpScreenContent(false)
128 : : {
129 : 0 : maPropHelper.initProperties( PropertySetHelper::MakeMap
130 : : ("HardwareAcceleration",
131 : : boost::bind(&DeviceHelper::isAccelerated,
132 : : boost::ref(maDeviceHelper)))
133 : : ("DeviceHandle",
134 : : boost::bind(&DeviceHelper::getDeviceHandle,
135 : : boost::ref(maDeviceHelper)))
136 : : ("SurfaceHandle",
137 : : boost::bind(&DeviceHelper::getSurfaceHandle,
138 : : boost::ref(maDeviceHelper)))
139 : : ("DumpScreenContent",
140 : : boost::bind(&ThisType::getDumpScreenContent,
141 : : this),
142 : : boost::bind(&ThisType::setDumpScreenContent,
143 : : this,
144 : : _1)));
145 : 0 : }
146 : :
147 : 0 : virtual void disposeThis()
148 : : {
149 : 0 : MutexType aGuard( BaseType::m_aMutex );
150 : :
151 : 0 : maDeviceHelper.disposing();
152 : :
153 : : // pass on to base class
154 : 0 : BaseType::disposeThis();
155 : 0 : }
156 : :
157 : : // XGraphicDevice
158 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBufferController > SAL_CALL getBufferController( ) throw (::com::sun::star::uno::RuntimeException)
159 : : {
160 : 0 : return ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBufferController >();
161 : : }
162 : :
163 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XColorSpace > SAL_CALL getDeviceColorSpace( ) throw (::com::sun::star::uno::RuntimeException)
164 : : {
165 : 0 : MutexType aGuard( BaseType::m_aMutex );
166 : :
167 : 0 : return maDeviceHelper.getColorSpace();
168 : : }
169 : :
170 : 0 : virtual ::com::sun::star::geometry::RealSize2D SAL_CALL getPhysicalResolution( ) throw (::com::sun::star::uno::RuntimeException)
171 : : {
172 : 0 : MutexType aGuard( BaseType::m_aMutex );
173 : :
174 : 0 : return maDeviceHelper.getPhysicalResolution();
175 : : }
176 : :
177 : 0 : virtual ::com::sun::star::geometry::RealSize2D SAL_CALL getPhysicalSize( ) throw (::com::sun::star::uno::RuntimeException)
178 : : {
179 : 0 : MutexType aGuard( BaseType::m_aMutex );
180 : :
181 : 0 : return maDeviceHelper.getPhysicalSize();
182 : : }
183 : :
184 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XLinePolyPolygon2D > SAL_CALL createCompatibleLinePolyPolygon( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > >& points ) throw (::com::sun::star::uno::RuntimeException)
185 : : {
186 : 0 : MutexType aGuard( BaseType::m_aMutex );
187 : :
188 : 0 : return maDeviceHelper.createCompatibleLinePolyPolygon( this, points );
189 : : }
190 : :
191 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBezierPolyPolygon2D > SAL_CALL createCompatibleBezierPolyPolygon( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealBezierSegment2D > >& points ) throw (::com::sun::star::uno::RuntimeException)
192 : : {
193 : 0 : MutexType aGuard( BaseType::m_aMutex );
194 : :
195 : 0 : return maDeviceHelper.createCompatibleBezierPolyPolygon( this, points );
196 : : }
197 : :
198 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > SAL_CALL createCompatibleBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) throw (::com::sun::star::lang::IllegalArgumentException,
199 : : ::com::sun::star::uno::RuntimeException)
200 : : {
201 : 0 : tools::verifyBitmapSize(size,
202 : : BOOST_CURRENT_FUNCTION,
203 : : static_cast< UnambiguousBaseType* >(this));
204 : :
205 : 0 : MutexType aGuard( BaseType::m_aMutex );
206 : :
207 : 0 : return maDeviceHelper.createCompatibleBitmap( this, size );
208 : : }
209 : :
210 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XVolatileBitmap > SAL_CALL createVolatileBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) throw (::com::sun::star::lang::IllegalArgumentException,
211 : : ::com::sun::star::uno::RuntimeException)
212 : : {
213 : 0 : tools::verifyBitmapSize(size,
214 : : BOOST_CURRENT_FUNCTION,
215 : : static_cast< UnambiguousBaseType* >(this));
216 : :
217 : 0 : MutexType aGuard( BaseType::m_aMutex );
218 : :
219 : 0 : return maDeviceHelper.createVolatileBitmap( this, size );
220 : : }
221 : :
222 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > SAL_CALL createCompatibleAlphaBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) throw (::com::sun::star::lang::IllegalArgumentException,
223 : : ::com::sun::star::uno::RuntimeException)
224 : : {
225 : 0 : tools::verifyBitmapSize(size,
226 : : BOOST_CURRENT_FUNCTION,
227 : : static_cast< UnambiguousBaseType* >(this));
228 : :
229 : 0 : MutexType aGuard( BaseType::m_aMutex );
230 : :
231 : 0 : return maDeviceHelper.createCompatibleAlphaBitmap( this, size );
232 : : }
233 : :
234 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XVolatileBitmap > SAL_CALL createVolatileAlphaBitmap( const ::com::sun::star::geometry::IntegerSize2D& size ) throw (::com::sun::star::lang::IllegalArgumentException,
235 : : ::com::sun::star::uno::RuntimeException)
236 : : {
237 : 0 : tools::verifyBitmapSize(size,
238 : : BOOST_CURRENT_FUNCTION,
239 : : static_cast< UnambiguousBaseType* >(this));
240 : :
241 : 0 : MutexType aGuard( BaseType::m_aMutex );
242 : :
243 : 0 : return maDeviceHelper.createVolatileAlphaBitmap( this, size );
244 : : }
245 : :
246 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > SAL_CALL getParametricPolyPolygonFactory( ) throw (::com::sun::star::uno::RuntimeException)
247 : : {
248 : 0 : return this;
249 : : }
250 : :
251 : 0 : virtual ::sal_Bool SAL_CALL hasFullScreenMode( ) throw (::com::sun::star::uno::RuntimeException)
252 : : {
253 : 0 : MutexType aGuard( BaseType::m_aMutex );
254 : :
255 : 0 : return maDeviceHelper.hasFullScreenMode();
256 : : }
257 : :
258 : 0 : virtual ::sal_Bool SAL_CALL enterFullScreenMode( ::sal_Bool bEnter ) throw (::com::sun::star::uno::RuntimeException)
259 : : {
260 : 0 : MutexType aGuard( BaseType::m_aMutex );
261 : :
262 : 0 : return maDeviceHelper.enterFullScreenMode( bEnter );
263 : : }
264 : :
265 : : // XMultiServiceFactory
266 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
267 : : {
268 : : return ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XParametricPolyPolygon2D >(
269 : : ParametricPolyPolygon::create(this,
270 : : aServiceSpecifier,
271 : 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >()));
272 : : }
273 : :
274 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& aServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
275 : : {
276 : : return ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XParametricPolyPolygon2D >(
277 : : ParametricPolyPolygon::create(this,
278 : : aServiceSpecifier,
279 : 0 : Arguments));
280 : : }
281 : :
282 : 0 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw (::com::sun::star::uno::RuntimeException)
283 : : {
284 : 0 : return ParametricPolyPolygon::getAvailableServiceNames();
285 : : }
286 : :
287 : :
288 : : // XUpdatable
289 : 0 : virtual void SAL_CALL update() throw (com::sun::star::uno::RuntimeException)
290 : : {
291 : 0 : MutexType aGuard( BaseType::m_aMutex );
292 : :
293 : 0 : if( mbDumpScreenContent )
294 : 0 : maDeviceHelper.dumpScreenContent();
295 : 0 : }
296 : :
297 : :
298 : : // XPropertySet
299 : 0 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException)
300 : : {
301 : 0 : MutexType aGuard( BaseType::m_aMutex );
302 : 0 : return maPropHelper.getPropertySetInfo();
303 : : }
304 : :
305 : 0 : virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName,
306 : : const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException,
307 : : ::com::sun::star::beans::PropertyVetoException,
308 : : ::com::sun::star::lang::IllegalArgumentException,
309 : : ::com::sun::star::lang::WrappedTargetException,
310 : : ::com::sun::star::uno::RuntimeException)
311 : : {
312 : 0 : MutexType aGuard( BaseType::m_aMutex );
313 : 0 : maPropHelper.setPropertyValue( aPropertyName, aValue );
314 : 0 : }
315 : :
316 : 0 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& aPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException,
317 : : ::com::sun::star::lang::WrappedTargetException,
318 : : ::com::sun::star::uno::RuntimeException)
319 : : {
320 : 0 : MutexType aGuard( BaseType::m_aMutex );
321 : 0 : return maPropHelper.getPropertyValue( aPropertyName );
322 : : }
323 : :
324 : 0 : virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
325 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException,
326 : : ::com::sun::star::lang::WrappedTargetException,
327 : : ::com::sun::star::uno::RuntimeException)
328 : : {
329 : 0 : MutexType aGuard( BaseType::m_aMutex );
330 : 0 : maPropHelper.addPropertyChangeListener( aPropertyName,
331 : : xListener );
332 : 0 : }
333 : :
334 : 0 : virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
335 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException,
336 : : ::com::sun::star::lang::WrappedTargetException,
337 : : ::com::sun::star::uno::RuntimeException)
338 : : {
339 : 0 : MutexType aGuard( BaseType::m_aMutex );
340 : 0 : maPropHelper.removePropertyChangeListener( aPropertyName,
341 : : xListener );
342 : 0 : }
343 : :
344 : 0 : virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& aPropertyName,
345 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException,
346 : : ::com::sun::star::lang::WrappedTargetException,
347 : : ::com::sun::star::uno::RuntimeException)
348 : : {
349 : 0 : MutexType aGuard( BaseType::m_aMutex );
350 : 0 : maPropHelper.addVetoableChangeListener( aPropertyName,
351 : : xListener );
352 : 0 : }
353 : :
354 : 0 : virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& aPropertyName,
355 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException,
356 : : ::com::sun::star::lang::WrappedTargetException,
357 : : ::com::sun::star::uno::RuntimeException)
358 : : {
359 : 0 : MutexType aGuard( BaseType::m_aMutex );
360 : 0 : maPropHelper.removeVetoableChangeListener( aPropertyName,
361 : : xListener );
362 : 0 : }
363 : :
364 : : protected:
365 : 0 : ~GraphicDeviceBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
366 : :
367 : 0 : ::com::sun::star::uno::Any getDumpScreenContent() const
368 : : {
369 : 0 : return ::com::sun::star::uno::makeAny( mbDumpScreenContent );
370 : : }
371 : :
372 : 0 : void setDumpScreenContent( const ::com::sun::star::uno::Any& rAny )
373 : : {
374 : : // TODO(Q1): this was mbDumpScreenContent =
375 : : // rAny.get<bool>(), only that gcc3.3 wouldn't eat it
376 : 0 : rAny >>= mbDumpScreenContent;
377 : 0 : }
378 : :
379 : : DeviceHelperType maDeviceHelper;
380 : : PropertySetHelper maPropHelper;
381 : : bool mbDumpScreenContent;
382 : :
383 : : private:
384 : : GraphicDeviceBase( const GraphicDeviceBase& );
385 : : GraphicDeviceBase& operator=( const GraphicDeviceBase& );
386 : : };
387 : : }
388 : :
389 : : #endif /* INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX */
390 : :
391 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|