1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX
21 #define INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX
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>
31 #include <canvas/parametricpolypolygon.hxx>
32 #include <canvas/propertysethelper.hxx>
35 /* Definition of GraphicDeviceBase class */
39 /** Helper template base class for XGraphicDevice implementations.
41 This base class provides partial implementations of the
42 XGraphicDevice-related interface, such as XColorSpace.
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).
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;
66 class ExampleDevice : public ExampleDevice_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.
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.
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
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)
100 template< class Base
,
102 class Mutex
=::osl::MutexGuard
,
103 class UnambiguousBase
=::com::sun::star::uno::XInterface
> class GraphicDeviceBase
:
107 typedef Base BaseType
;
108 typedef DeviceHelper DeviceHelperType
;
109 typedef Mutex MutexType
;
110 typedef UnambiguousBase UnambiguousBaseType
;
111 typedef GraphicDeviceBase ThisType
;
113 typedef ::rtl::Reference
< GraphicDeviceBase
> Reference
;
115 GraphicDeviceBase() :
118 mbDumpScreenContent(false)
120 maPropHelper
.initProperties( PropertySetHelper::MakeMap
121 ("HardwareAcceleration",
122 boost::bind(&DeviceHelper::isAccelerated
,
123 boost::ref(maDeviceHelper
)))
125 boost::bind(&DeviceHelper::getDeviceHandle
,
126 boost::ref(maDeviceHelper
)))
128 boost::bind(&DeviceHelper::getSurfaceHandle
,
129 boost::ref(maDeviceHelper
)))
130 ("DumpScreenContent",
131 boost::bind(&ThisType::getDumpScreenContent
,
133 boost::bind(&ThisType::setDumpScreenContent
,
138 virtual void disposeThis()
140 MutexType
aGuard( BaseType::m_aMutex
);
142 maDeviceHelper
.disposing();
144 // pass on to base class
145 BaseType::disposeThis();
149 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XBufferController
> SAL_CALL
getBufferController( ) throw (::com::sun::star::uno::RuntimeException
)
151 return ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XBufferController
>();
154 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XColorSpace
> SAL_CALL
getDeviceColorSpace( ) throw (::com::sun::star::uno::RuntimeException
)
156 MutexType
aGuard( BaseType::m_aMutex
);
158 return maDeviceHelper
.getColorSpace();
161 virtual ::com::sun::star::geometry::RealSize2D SAL_CALL
getPhysicalResolution( ) throw (::com::sun::star::uno::RuntimeException
)
163 MutexType
aGuard( BaseType::m_aMutex
);
165 return maDeviceHelper
.getPhysicalResolution();
168 virtual ::com::sun::star::geometry::RealSize2D SAL_CALL
getPhysicalSize( ) throw (::com::sun::star::uno::RuntimeException
)
170 MutexType
aGuard( BaseType::m_aMutex
);
172 return maDeviceHelper
.getPhysicalSize();
175 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
)
177 MutexType
aGuard( BaseType::m_aMutex
);
179 return maDeviceHelper
.createCompatibleLinePolyPolygon( this, points
);
182 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
)
184 MutexType
aGuard( BaseType::m_aMutex
);
186 return maDeviceHelper
.createCompatibleBezierPolyPolygon( this, points
);
189 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
)
192 tools::verifyBitmapSize(size
,
193 BOOST_CURRENT_FUNCTION
,
194 static_cast< UnambiguousBaseType
* >(this));
196 MutexType
aGuard( BaseType::m_aMutex
);
198 return maDeviceHelper
.createCompatibleBitmap( this, size
);
201 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
)
204 tools::verifyBitmapSize(size
,
205 BOOST_CURRENT_FUNCTION
,
206 static_cast< UnambiguousBaseType
* >(this));
208 MutexType
aGuard( BaseType::m_aMutex
);
210 return maDeviceHelper
.createVolatileBitmap( this, size
);
213 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
)
216 tools::verifyBitmapSize(size
,
217 BOOST_CURRENT_FUNCTION
,
218 static_cast< UnambiguousBaseType
* >(this));
220 MutexType
aGuard( BaseType::m_aMutex
);
222 return maDeviceHelper
.createCompatibleAlphaBitmap( this, size
);
225 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
)
228 tools::verifyBitmapSize(size
,
229 BOOST_CURRENT_FUNCTION
,
230 static_cast< UnambiguousBaseType
* >(this));
232 MutexType
aGuard( BaseType::m_aMutex
);
234 return maDeviceHelper
.createVolatileAlphaBitmap( this, size
);
237 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> SAL_CALL
getParametricPolyPolygonFactory( ) throw (::com::sun::star::uno::RuntimeException
)
242 virtual ::sal_Bool SAL_CALL
hasFullScreenMode( ) throw (::com::sun::star::uno::RuntimeException
)
244 MutexType
aGuard( BaseType::m_aMutex
);
246 return maDeviceHelper
.hasFullScreenMode();
249 virtual ::sal_Bool SAL_CALL
enterFullScreenMode( ::sal_Bool bEnter
) throw (::com::sun::star::uno::RuntimeException
)
251 MutexType
aGuard( BaseType::m_aMutex
);
253 return maDeviceHelper
.enterFullScreenMode( bEnter
);
256 // XMultiServiceFactory
257 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
)
259 return ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XParametricPolyPolygon2D
>(
260 ParametricPolyPolygon::create(this,
262 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>()));
265 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
)
267 return ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XParametricPolyPolygon2D
>(
268 ParametricPolyPolygon::create(this,
273 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getAvailableServiceNames( ) throw (::com::sun::star::uno::RuntimeException
)
275 return ParametricPolyPolygon::getAvailableServiceNames();
280 virtual void SAL_CALL
update() throw (com::sun::star::uno::RuntimeException
)
282 MutexType
aGuard( BaseType::m_aMutex
);
284 if( mbDumpScreenContent
)
285 maDeviceHelper
.dumpScreenContent();
290 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException
)
292 MutexType
aGuard( BaseType::m_aMutex
);
293 return maPropHelper
.getPropertySetInfo();
296 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
)
303 MutexType
aGuard( BaseType::m_aMutex
);
304 maPropHelper
.setPropertyValue( aPropertyName
, aValue
);
307 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
)
311 MutexType
aGuard( BaseType::m_aMutex
);
312 return maPropHelper
.getPropertyValue( aPropertyName
);
315 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
)
320 MutexType
aGuard( BaseType::m_aMutex
);
321 maPropHelper
.addPropertyChangeListener( aPropertyName
,
325 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
)
330 MutexType
aGuard( BaseType::m_aMutex
);
331 maPropHelper
.removePropertyChangeListener( aPropertyName
,
335 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
)
340 MutexType
aGuard( BaseType::m_aMutex
);
341 maPropHelper
.addVetoableChangeListener( aPropertyName
,
345 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
)
350 MutexType
aGuard( BaseType::m_aMutex
);
351 maPropHelper
.removeVetoableChangeListener( aPropertyName
,
356 ~GraphicDeviceBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
358 ::com::sun::star::uno::Any
getDumpScreenContent() const
360 return ::com::sun::star::uno::makeAny( mbDumpScreenContent
);
363 void setDumpScreenContent( const ::com::sun::star::uno::Any
& rAny
)
365 // TODO(Q1): this was mbDumpScreenContent =
366 // rAny.get<bool>(), only that gcc3.3 wouldn't eat it
367 rAny
>>= mbDumpScreenContent
;
370 DeviceHelperType maDeviceHelper
;
371 PropertySetHelper maPropHelper
;
372 bool mbDumpScreenContent
;
375 GraphicDeviceBase( const GraphicDeviceBase
& );
376 GraphicDeviceBase
& operator=( const GraphicDeviceBase
& );
380 #endif /* INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX */
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */