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