1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef INCLUDED_CANVAS_CANVASCUSTOMSPRITEBASE_HXX 29*cdf0e10cSrcweir #define INCLUDED_CANVAS_CANVASCUSTOMSPRITEBASE_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/rendering/XCustomSprite.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/rendering/XPolyPolygon2D.hpp> 34*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 35*cdf0e10cSrcweir #include <basegfx/vector/b2dvector.hxx> 36*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx> 37*cdf0e10cSrcweir #include <canvas/base/integerbitmapbase.hxx> 38*cdf0e10cSrcweir #include <canvas/base/sprite.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <boost/utility.hpp> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir namespace canvas 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir /** Helper template to handle XCustomSprite method forwarding to 46*cdf0e10cSrcweir CanvasCustomSpriteHelper 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir Use this helper to handle the XCustomSprite part of your 49*cdf0e10cSrcweir implementation. 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir @tpl Base 52*cdf0e10cSrcweir Base class to use, most probably one of the 53*cdf0e10cSrcweir WeakComponentImplHelperN templates with the appropriate 54*cdf0e10cSrcweir interfaces. At least XCustomSprite and Sprite should be among 55*cdf0e10cSrcweir them (why else would you use this template, then?). Base class 56*cdf0e10cSrcweir must have an Base( const Mutex& ) constructor (like the 57*cdf0e10cSrcweir WeakComponentImplHelperN templates have). 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir @tpl SpriteHelper 60*cdf0e10cSrcweir Sprite helper implementation for the backend in question 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir @tpl CanvasHelper 63*cdf0e10cSrcweir Canvas helper implementation for the backend in question 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir @tpl Mutex 66*cdf0e10cSrcweir Lock strategy to use. Defaults to using the 67*cdf0e10cSrcweir OBaseMutex-provided lock. Everytime one of the methods is 68*cdf0e10cSrcweir entered, an object of type Mutex is created with m_aMutex as 69*cdf0e10cSrcweir the sole parameter, and destroyed again when the method scope 70*cdf0e10cSrcweir is left. 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir @tpl UnambiguousBase 73*cdf0e10cSrcweir Optional unambiguous base class for XInterface of Base. It's 74*cdf0e10cSrcweir sometimes necessary to specify this parameter, e.g. if Base 75*cdf0e10cSrcweir derives from multiple UNO interface (were each provides its 76*cdf0e10cSrcweir own version of XInterface, making the conversion ambiguous) 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir @see CanvasCustomSpriteHelper for further contractual 79*cdf0e10cSrcweir requirements towards the SpriteHelper type, and some examples. 80*cdf0e10cSrcweir */ 81*cdf0e10cSrcweir template< class Base, 82*cdf0e10cSrcweir class SpriteHelper, 83*cdf0e10cSrcweir class CanvasHelper, 84*cdf0e10cSrcweir class Mutex=::osl::MutexGuard, 85*cdf0e10cSrcweir class UnambiguousBase=::com::sun::star::uno::XInterface > class CanvasCustomSpriteBase : 86*cdf0e10cSrcweir public IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase > 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir public: 89*cdf0e10cSrcweir typedef IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase > BaseType; 90*cdf0e10cSrcweir typedef SpriteHelper SpriteHelperType; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir CanvasCustomSpriteBase() : 93*cdf0e10cSrcweir maSpriteHelper() 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir /** Object is being disposed. 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir Called from the cppu helper base, to notify disposal of 100*cdf0e10cSrcweir this object. Already releases all internal references. 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir @derive when overriding this method in derived classes, 103*cdf0e10cSrcweir <em>always</em> call the base class' method! 104*cdf0e10cSrcweir */ 105*cdf0e10cSrcweir virtual void SAL_CALL disposing() 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir maSpriteHelper.disposing(); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // pass on to base class 112*cdf0e10cSrcweir BaseType::disposing(); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // XCanvas: selectively override base's methods here, for opacity tracking 116*cdf0e10cSrcweir virtual void SAL_CALL clear() throw (::com::sun::star::uno::RuntimeException) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir maSpriteHelper.clearingContent( this ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // and forward to base class, which handles the actual rendering 123*cdf0e10cSrcweir return BaseType::clear(); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL 127*cdf0e10cSrcweir drawBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >& xBitmap, 128*cdf0e10cSrcweir const ::com::sun::star::rendering::ViewState& viewState, 129*cdf0e10cSrcweir const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, 130*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir tools::verifyArgs(xBitmap, viewState, renderState, 133*cdf0e10cSrcweir BOOST_CURRENT_FUNCTION, 134*cdf0e10cSrcweir static_cast< typename BaseType::UnambiguousBaseType* >(this)); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir maSpriteHelper.checkDrawBitmap( this, xBitmap, viewState, renderState ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // and forward to base class, which handles the actual rendering 141*cdf0e10cSrcweir return BaseType::drawBitmap( xBitmap, 142*cdf0e10cSrcweir viewState, 143*cdf0e10cSrcweir renderState ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // TODO(F3): If somebody uses the XIntegerBitmap methods to 147*cdf0e10cSrcweir // clear pixel (setting alpha != 1.0 there), or a compositing 148*cdf0e10cSrcweir // mode results in similar alpha, maSpriteHelper might 149*cdf0e10cSrcweir // errorneously report fully opaque sprites. Effectively, all 150*cdf0e10cSrcweir // render methods must be overridden here; or better, 151*cdf0e10cSrcweir // functionality provided at the baseclass. 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // XSprite 154*cdf0e10cSrcweir virtual void SAL_CALL setAlpha( double alpha ) throw (::com::sun::star::lang::IllegalArgumentException, 155*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir tools::verifyRange( alpha, 0.0, 1.0 ); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir maSpriteHelper.setAlpha( this, alpha ); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir virtual void SAL_CALL move( const ::com::sun::star::geometry::RealPoint2D& aNewPos, 165*cdf0e10cSrcweir const ::com::sun::star::rendering::ViewState& viewState, 166*cdf0e10cSrcweir const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, 167*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir tools::verifyArgs(aNewPos, viewState, renderState, 170*cdf0e10cSrcweir BOOST_CURRENT_FUNCTION, 171*cdf0e10cSrcweir static_cast< typename BaseType::UnambiguousBaseType* >(this)); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir maSpriteHelper.move( this, aNewPos, viewState, renderState ); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir virtual void SAL_CALL transform( const ::com::sun::star::geometry::AffineMatrix2D& aTransformation ) throw (::com::sun::star::lang::IllegalArgumentException, 179*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir tools::verifyArgs(aTransformation, 182*cdf0e10cSrcweir BOOST_CURRENT_FUNCTION, 183*cdf0e10cSrcweir static_cast< typename BaseType::UnambiguousBaseType* >(this)); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir maSpriteHelper.transform( this, aTransformation ); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir virtual void SAL_CALL clip( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& aClip ) throw (::com::sun::star::uno::RuntimeException) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir // NULL xClip explicitely allowed here (to clear clipping) 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir maSpriteHelper.clip( this, aClip ); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir virtual void SAL_CALL setPriority( double nPriority ) throw (::com::sun::star::uno::RuntimeException) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir maSpriteHelper.setPriority( this, nPriority ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir virtual void SAL_CALL show() throw (::com::sun::star::uno::RuntimeException) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir maSpriteHelper.show( this ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir virtual void SAL_CALL hide() throw (::com::sun::star::uno::RuntimeException) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir maSpriteHelper.hide( this ); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir // XCustomSprite 221*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvas > SAL_CALL 222*cdf0e10cSrcweir getContentCanvas() throw (::com::sun::star::uno::RuntimeException) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir return this; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // Sprite 230*cdf0e10cSrcweir virtual bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir return maSpriteHelper.isAreaUpdateOpaque( rUpdateArea ); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir virtual bool isContentChanged() const 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir return BaseType::mbSurfaceDirty; 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir virtual ::basegfx::B2DPoint getPosPixel() const 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir return maSpriteHelper.getPosPixel(); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir virtual ::basegfx::B2DVector getSizePixel() const 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir return maSpriteHelper.getSizePixel(); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir virtual ::basegfx::B2DRange getUpdateArea() const 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir return maSpriteHelper.getUpdateArea(); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir virtual double getPriority() const 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir return maSpriteHelper.getPriority(); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir protected: 273*cdf0e10cSrcweir SpriteHelperType maSpriteHelper; 274*cdf0e10cSrcweir }; 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir #endif /* INCLUDED_CANVAS_CANVASCUSTOMSPRITEBASE_HXX */ 278