LCOV - code coverage report
Current view: top level - include/canvas/base - canvascustomspritebase.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 73 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 40 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEBASE_HXX
      21             : #define INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEBASE_HXX
      22             : 
      23             : #include <com/sun/star/lang/XServiceInfo.hpp>
      24             : #include <com/sun/star/rendering/XCustomSprite.hpp>
      25             : #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
      26             : #include <basegfx/point/b2dpoint.hxx>
      27             : #include <basegfx/vector/b2dvector.hxx>
      28             : #include <basegfx/range/b2drange.hxx>
      29             : #include <canvas/base/integerbitmapbase.hxx>
      30             : #include <canvas/base/sprite.hxx>
      31             : 
      32             : #include <boost/utility.hpp>
      33             : 
      34             : 
      35             : namespace canvas
      36             : {
      37             :     /** Helper template to handle XCustomSprite method forwarding to
      38             :         CanvasCustomSpriteHelper
      39             : 
      40             :         Use this helper to handle the XCustomSprite part of your
      41             :         implementation.
      42             : 
      43             :         @tpl Base
      44             :         Base class to use, most probably one of the
      45             :         WeakComponentImplHelperN templates with the appropriate
      46             :         interfaces. At least XCustomSprite and Sprite should be among
      47             :         them (why else would you use this template, then?). Base class
      48             :         must have an Base( const Mutex& ) constructor (like the
      49             :         WeakComponentImplHelperN templates have).
      50             : 
      51             :         @tpl SpriteHelper
      52             :         Sprite helper implementation for the backend in question
      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.  Every time 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 CanvasCustomSpriteHelper for further contractual
      71             :         requirements towards the SpriteHelper type, and some examples.
      72             :      */
      73             :     template< class Base,
      74             :               class SpriteHelper,
      75             :               class CanvasHelper,
      76             :               class Mutex=::osl::MutexGuard,
      77           0 :               class UnambiguousBase=::com::sun::star::uno::XInterface > class CanvasCustomSpriteBase :
      78             :         public IntegerBitmapBase< BitmapCanvasBase2<Base, CanvasHelper, Mutex, UnambiguousBase> >
      79             :     {
      80             :     public:
      81             :         typedef IntegerBitmapBase< BitmapCanvasBase2<Base, CanvasHelper, Mutex, UnambiguousBase> > BaseType;
      82             :         typedef SpriteHelper                                                    SpriteHelperType;
      83             : 
      84           0 :         CanvasCustomSpriteBase() :
      85           0 :             maSpriteHelper()
      86             :         {
      87           0 :         }
      88             : 
      89             :         /** Object is being disposed.
      90             : 
      91             :             Called from the cppu helper base, to notify disposal of
      92             :             this object. Already releases all internal references.
      93             : 
      94             :             @derive when overriding this method in derived classes,
      95             :             <em>always</em> call the base class' method!
      96             :          */
      97           0 :         virtual void disposeThis() SAL_OVERRIDE
      98             :         {
      99           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     100             : 
     101           0 :             maSpriteHelper.disposing();
     102             : 
     103             :             // pass on to base class
     104           0 :             BaseType::disposeThis();
     105           0 :         }
     106             : 
     107             :         // XCanvas: selectively override base's methods here, for opacity tracking
     108           0 :         virtual void SAL_CALL clear() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     109             :         {
     110           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     111             : 
     112           0 :             maSpriteHelper.clearingContent( this );
     113             : 
     114             :             // and forward to base class, which handles the actual rendering
     115           0 :             return BaseType::clear();
     116             :         }
     117             : 
     118             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
     119           0 :             drawBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >& xBitmap,
     120             :                         const ::com::sun::star::rendering::ViewState&                                   viewState,
     121             :                         const ::com::sun::star::rendering::RenderState&                                 renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
     122             :                                                                                                                              ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     123             :         {
     124           0 :             tools::verifyArgs(xBitmap, viewState, renderState,
     125             :                               BOOST_CURRENT_FUNCTION,
     126           0 :                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
     127             : 
     128           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     129             : 
     130           0 :             maSpriteHelper.checkDrawBitmap( this, xBitmap, viewState, renderState );
     131             : 
     132             :             // and forward to base class, which handles the actual rendering
     133             :             return BaseType::drawBitmap( xBitmap,
     134             :                                          viewState,
     135           0 :                                          renderState );
     136             :         }
     137             : 
     138             :         // TODO(F3): If somebody uses the XIntegerBitmap methods to
     139             :         // clear pixel (setting alpha != 1.0 there), or a compositing
     140             :         // mode results in similar alpha, maSpriteHelper might
     141             :         // errorneously report fully opaque sprites. Effectively, all
     142             :         // render methods must be overridden here; or better,
     143             :         // functionality provided at the baseclass.
     144             : 
     145             :         // XSprite
     146           0 :         virtual void SAL_CALL setAlpha( double alpha ) throw (::com::sun::star::lang::IllegalArgumentException,
     147             :                                                               ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     148             :         {
     149           0 :             tools::verifyRange( alpha, 0.0, 1.0 );
     150             : 
     151           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     152             : 
     153           0 :             maSpriteHelper.setAlpha( this, alpha );
     154           0 :         }
     155             : 
     156           0 :         virtual void SAL_CALL move( const ::com::sun::star::geometry::RealPoint2D&  aNewPos,
     157             :                                     const ::com::sun::star::rendering::ViewState&   viewState,
     158             :                                     const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
     159             :                                                                                                          ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     160             :         {
     161           0 :             tools::verifyArgs(aNewPos, viewState, renderState,
     162             :                               BOOST_CURRENT_FUNCTION,
     163           0 :                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
     164             : 
     165           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     166             : 
     167           0 :             maSpriteHelper.move( this, aNewPos, viewState, renderState );
     168           0 :         }
     169             : 
     170           0 :         virtual void SAL_CALL transform( const ::com::sun::star::geometry::AffineMatrix2D& aTransformation ) throw (::com::sun::star::lang::IllegalArgumentException,
     171             :                                                                                                                     ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     172             :         {
     173           0 :             tools::verifyArgs(aTransformation,
     174             :                               BOOST_CURRENT_FUNCTION,
     175           0 :                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
     176             : 
     177           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     178             : 
     179           0 :             maSpriteHelper.transform( this, aTransformation );
     180           0 :         }
     181             : 
     182           0 :         virtual void SAL_CALL clip( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& aClip ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     183             :         {
     184             :             // NULL xClip explicitly allowed here (to clear clipping)
     185             : 
     186           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     187             : 
     188           0 :             maSpriteHelper.clip( this, aClip );
     189           0 :         }
     190             : 
     191           0 :         virtual void SAL_CALL setPriority( double nPriority ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     192             :         {
     193           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     194             : 
     195           0 :             maSpriteHelper.setPriority( this, nPriority );
     196           0 :         }
     197             : 
     198           0 :         virtual void SAL_CALL show() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     199             :         {
     200           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     201             : 
     202           0 :             maSpriteHelper.show( this );
     203           0 :         }
     204             : 
     205           0 :         virtual void SAL_CALL hide() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     206             :         {
     207           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     208             : 
     209           0 :             maSpriteHelper.hide( this );
     210           0 :         }
     211             : 
     212             :         // XCustomSprite
     213             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvas > SAL_CALL
     214           0 :             getContentCanvas() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     215             :         {
     216           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     217             : 
     218           0 :             return this;
     219             :         }
     220             : 
     221             :         // Sprite
     222           0 :         virtual bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const SAL_OVERRIDE
     223             :         {
     224           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     225             : 
     226           0 :             return maSpriteHelper.isAreaUpdateOpaque( rUpdateArea );
     227             :         }
     228             : 
     229           0 :         virtual bool isContentChanged() const SAL_OVERRIDE
     230             :         {
     231           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     232             : 
     233           0 :             return BaseType::mbSurfaceDirty;
     234             :         }
     235             : 
     236           0 :         virtual ::basegfx::B2DPoint getPosPixel() const SAL_OVERRIDE
     237             :         {
     238           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     239             : 
     240           0 :             return maSpriteHelper.getPosPixel();
     241             :         }
     242             : 
     243           0 :         virtual ::basegfx::B2DVector getSizePixel() const SAL_OVERRIDE
     244             :         {
     245           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     246             : 
     247           0 :             return maSpriteHelper.getSizePixel();
     248             :         }
     249             : 
     250           0 :         virtual ::basegfx::B2DRange getUpdateArea() const SAL_OVERRIDE
     251             :         {
     252           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     253             : 
     254           0 :             return maSpriteHelper.getUpdateArea();
     255             :         }
     256             : 
     257           0 :         virtual double getPriority() const SAL_OVERRIDE
     258             :         {
     259           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     260             : 
     261           0 :             return maSpriteHelper.getPriority();
     262             :         }
     263             : 
     264             :     protected:
     265             :         SpriteHelperType maSpriteHelper;
     266             :     };
     267             : }
     268             : 
     269             : #endif // INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEBASE_HXX
     270             : 
     271             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11