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