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