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_SPRITECANVASBASE_HXX 29 #define INCLUDED_CANVAS_SPRITECANVASBASE_HXX 30 31 #include <rtl/ref.hxx> 32 #include <com/sun/star/rendering/XSpriteCanvas.hpp> 33 #include <com/sun/star/rendering/InterpolationMode.hpp> 34 #include <canvas/base/integerbitmapbase.hxx> 35 #include <canvas/spriteredrawmanager.hxx> 36 37 38 namespace canvas 39 { 40 /** Helper template to handle XIntegerBitmap method forwarding to 41 BitmapCanvasHelper 42 43 Use this helper to handle the XIntegerBitmap part of your 44 implementation. 45 46 @tpl Base 47 Base class to use, most probably one of the 48 WeakComponentImplHelperN templates with the appropriate 49 interfaces. At least XSpriteCanvas and SpriteSurface should be 50 among them (why else would you use this template, then?). Base 51 class must have an Base( const Mutex& ) constructor (like the 52 WeakComponentImplHelperN templates have). 53 54 @tpl CanvasHelper 55 Canvas helper implementation for the backend in question 56 57 @tpl Mutex 58 Lock strategy to use. Defaults to using the 59 OBaseMutex-provided lock. Everytime one of the methods is 60 entered, an object of type Mutex is created with m_aMutex as 61 the sole parameter, and destroyed again when the method scope 62 is left. 63 64 @tpl UnambiguousBase 65 Optional unambiguous base class for XInterface of Base. It's 66 sometimes necessary to specify this parameter, e.g. if Base 67 derives from multiple UNO interface (were each provides its 68 own version of XInterface, making the conversion ambiguous) 69 70 @see CanvasBase for further contractual requirements towards 71 the CanvasHelper type, and some examples. 72 */ 73 template< class Base, 74 class CanvasHelper, 75 class Mutex=::osl::MutexGuard, 76 class UnambiguousBase=::com::sun::star::uno::XInterface > class SpriteCanvasBase : 77 public IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase > 78 { 79 public: 80 typedef IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase > BaseType; 81 typedef ::rtl::Reference< SpriteCanvasBase > Reference; 82 83 SpriteCanvasBase() : 84 maRedrawManager() 85 { 86 } 87 88 #if defined __SUNPRO_CC 89 using Base::disposing; 90 #endif 91 virtual void SAL_CALL disposing() 92 { 93 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 94 95 maRedrawManager.disposing(); 96 97 // pass on to base class 98 BaseType::disposing(); 99 } 100 101 // XSpriteCanvas 102 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimation >& animation ) throw (::com::sun::star::lang::IllegalArgumentException, 103 ::com::sun::star::uno::RuntimeException) 104 { 105 tools::verifyArgs(animation, 106 BOOST_CURRENT_FUNCTION, 107 static_cast< typename BaseType::UnambiguousBaseType* >(this)); 108 109 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 110 111 return BaseType::maCanvasHelper.createSpriteFromAnimation(animation); 112 } 113 114 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > >& animationBitmaps, 115 sal_Int8 interpolationMode ) throw (::com::sun::star::lang::IllegalArgumentException, 116 ::com::sun::star::rendering::VolatileContentDestroyedException, 117 ::com::sun::star::uno::RuntimeException) 118 { 119 tools::verifyArgs(animationBitmaps, 120 BOOST_CURRENT_FUNCTION, 121 static_cast< typename BaseType::UnambiguousBaseType* >(this)); 122 tools::verifyRange( interpolationMode, 123 ::com::sun::star::rendering::InterpolationMode::NEAREST_NEIGHBOR, 124 ::com::sun::star::rendering::InterpolationMode::BEZIERSPLINE4 ); 125 126 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 127 128 return BaseType::maCanvasHelper.createSpriteFromBitmaps(animationBitmaps, interpolationMode); 129 } 130 131 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCustomSprite > SAL_CALL createCustomSprite( const ::com::sun::star::geometry::RealSize2D& spriteSize ) throw (::com::sun::star::lang::IllegalArgumentException, 132 ::com::sun::star::uno::RuntimeException) 133 { 134 tools::verifySpriteSize(spriteSize, 135 BOOST_CURRENT_FUNCTION, 136 static_cast< typename BaseType::UnambiguousBaseType* >(this)); 137 138 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 139 140 return BaseType::maCanvasHelper.createCustomSprite(spriteSize); 141 } 142 143 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite > SAL_CALL createClonedSprite( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite >& original ) throw (::com::sun::star::lang::IllegalArgumentException, 144 ::com::sun::star::uno::RuntimeException) 145 { 146 tools::verifyArgs(original, 147 BOOST_CURRENT_FUNCTION, 148 static_cast< typename BaseType::UnambiguousBaseType* >(this)); 149 150 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 151 152 return BaseType::maCanvasHelper.createClonedSprite(original); 153 } 154 155 // SpriteSurface 156 virtual void showSprite( const Sprite::Reference& rSprite ) 157 { 158 OSL_ASSERT( rSprite.is() ); 159 160 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 161 162 maRedrawManager.showSprite( rSprite ); 163 } 164 165 virtual void hideSprite( const Sprite::Reference& rSprite ) 166 { 167 OSL_ASSERT( rSprite.is() ); 168 169 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 170 171 maRedrawManager.hideSprite( rSprite ); 172 } 173 174 virtual void moveSprite( const Sprite::Reference& rSprite, 175 const ::basegfx::B2DPoint& rOldPos, 176 const ::basegfx::B2DPoint& rNewPos, 177 const ::basegfx::B2DVector& rSpriteSize ) 178 { 179 OSL_ASSERT( rSprite.is() ); 180 181 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 182 183 maRedrawManager.moveSprite( rSprite, rOldPos, rNewPos, rSpriteSize ); 184 } 185 186 virtual void updateSprite( const Sprite::Reference& rSprite, 187 const ::basegfx::B2DPoint& rPos, 188 const ::basegfx::B2DRange& rUpdateArea ) 189 { 190 OSL_ASSERT( rSprite.is() ); 191 192 typename BaseType::MutexType aGuard( BaseType::m_aMutex ); 193 194 maRedrawManager.updateSprite( rSprite, rPos, rUpdateArea ); 195 } 196 197 protected: 198 SpriteRedrawManager maRedrawManager; 199 }; 200 } 201 202 #endif /* INCLUDED_CANVAS_SPRITECANVASBASE_HXX */ 203