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