LCOV - code coverage report
Current view: top level - slideshow/source/inc - tools.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 38 0.0 %
Date: 2014-11-03 Functions: 0 22 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_SLIDESHOW_SOURCE_INC_TOOLS_HXX
      21             : #define INCLUDED_SLIDESHOW_SOURCE_INC_TOOLS_HXX
      22             : 
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/uno/Reference.hxx>
      26             : #include <com/sun/star/animations/XAnimationNode.hpp>
      27             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      28             : #include <com/sun/star/container/XEnumeration.hpp>
      29             : #include <comphelper/random.hxx>
      30             : #include <vector>
      31             : 
      32             : #include <cppcanvas/color.hxx>
      33             : 
      34             : #include "shapeattributelayer.hxx"
      35             : #include "shape.hxx"
      36             : #include "rgbcolor.hxx"
      37             : #include "hslcolor.hxx"
      38             : 
      39             : #include <boost/shared_ptr.hpp>
      40             : #include <boost/current_function.hpp>
      41             : 
      42             : #include <functional>
      43             : #include <cstdlib>
      44             : #include <string.h>
      45             : #include <algorithm>
      46             : 
      47             : namespace com { namespace sun { namespace star { namespace beans {
      48             :     struct NamedValue;
      49             : } } } }
      50             : namespace basegfx
      51             : {
      52             :     class B2DRange;
      53             :     class B2DVector;
      54             :     class B2IVector;
      55             :     class B2DHomMatrix;
      56             : }
      57             : namespace cppcanvas{ class Canvas; }
      58             : 
      59             : class GDIMetaFile;
      60             : 
      61             : /* Definition of some animation tools */
      62             : namespace slideshow
      63             : {
      64             :     namespace internal
      65             :     {
      66             :         class UnoView;
      67             :         class Shape;
      68             :         class ShapeAttributeLayer;
      69             : 
      70             :         typedef ::boost::shared_ptr< GDIMetaFile > GDIMetaFileSharedPtr;
      71             : 
      72             :         template <typename T>
      73           0 :         inline ::std::size_t hash_value( T const * p )
      74             :         {
      75             :             ::std::size_t d = static_cast< ::std::size_t >(
      76           0 :                 reinterpret_cast< ::std::ptrdiff_t >(p) );
      77           0 :             return d + (d >> 3);
      78             :         }
      79             : 
      80             :         // xxx todo: remove with boost::hash when 1.33 is available
      81             :         template <typename T>
      82             :         struct hash : ::std::unary_function<T, ::std::size_t>
      83             :         {
      84           0 :             ::std::size_t operator()( T const& val ) const {
      85           0 :                 return hash_value(val);
      86             :             }
      87             :         };
      88             :     }
      89             : }
      90             : 
      91             : namespace com { namespace sun { namespace star { namespace uno {
      92             : 
      93             :         template <typename T>
      94           0 :         inline ::std::size_t hash_value(
      95             :             ::com::sun::star::uno::Reference<T> const& x )
      96             :         {
      97             :             // normalize to object root, because _only_ XInterface is defined
      98             :             // to be stable during object lifetime:
      99             :             ::com::sun::star::uno::Reference<
     100             :                   ::com::sun::star::uno::XInterface> const xRoot(
     101           0 :                       x, ::com::sun::star::uno::UNO_QUERY );
     102           0 :             return slideshow::internal::hash<void *>()(xRoot.get());
     103             :         }
     104             : 
     105             : } } } }
     106             : 
     107             : namespace slideshow
     108             : {
     109             :     namespace internal
     110             :     {
     111             :         /** Cycle mode of intrinsic animations
     112             :          */
     113             :         enum CycleMode
     114             :         {
     115             :             /// loop the animation back to back
     116             :             CYCLE_LOOP,
     117             :             /// loop, but play backwards from end to start
     118             :             CYCLE_PINGPONGLOOP
     119             :         };
     120             : 
     121             : 
     122             :         // Value extraction from Any
     123             :         // =========================
     124             : 
     125             :         /// extract unary double value from Any
     126             :         bool extractValue( double&                              o_rValue,
     127             :                            const ::com::sun::star::uno::Any&    rSourceAny,
     128             :                            const boost::shared_ptr<Shape>&      rShape,
     129             :                            const basegfx::B2DVector&            rSlideBounds );
     130             : 
     131             :         /// extract int from Any
     132             :         bool extractValue( sal_Int32&                           o_rValue,
     133             :                            const ::com::sun::star::uno::Any&    rSourceAny,
     134             :                            const boost::shared_ptr<Shape>&      rShape,
     135             :                            const basegfx::B2DVector&            rSlideBounds );
     136             : 
     137             :         /// extract enum/constant group value from Any
     138             :         bool extractValue( sal_Int16&                           o_rValue,
     139             :                            const ::com::sun::star::uno::Any&    rSourceAny,
     140             :                            const boost::shared_ptr<Shape>&      rShape,
     141             :                            const basegfx::B2DVector&            rSlideBounds );
     142             : 
     143             :         /// extract color value from Any
     144             :         bool extractValue( RGBColor&                            o_rValue,
     145             :                            const ::com::sun::star::uno::Any&    rSourceAny,
     146             :                            const boost::shared_ptr<Shape>&      rShape,
     147             :                            const basegfx::B2DVector&            rSlideBounds );
     148             : 
     149             :         /// extract color value from Any
     150             :         bool extractValue( HSLColor&                            o_rValue,
     151             :                            const ::com::sun::star::uno::Any&    rSourceAny,
     152             :                            const boost::shared_ptr<Shape>&      rShape,
     153             :                            const basegfx::B2DVector&            rSlideBounds );
     154             : 
     155             :         /// extract plain string from Any
     156             :         bool extractValue( OUString&                     o_rValue,
     157             :                            const ::com::sun::star::uno::Any&    rSourceAny,
     158             :                            const boost::shared_ptr<Shape>&      rShape,
     159             :                            const basegfx::B2DVector&            rSlideBounds );
     160             : 
     161             :         /// extract bool value from Any
     162             :         bool extractValue( bool&                                o_rValue,
     163             :                            const ::com::sun::star::uno::Any&    rSourceAny,
     164             :                            const boost::shared_ptr<Shape>&      rShape,
     165             :                            const basegfx::B2DVector&            rSlideBounds );
     166             : 
     167             :         /// extract double 2-tuple from Any
     168             :         bool extractValue( basegfx::B2DTuple&                   o_rPair,
     169             :                            const ::com::sun::star::uno::Any&    rSourceAny,
     170             :                            const boost::shared_ptr<Shape>&      rShape,
     171             :                            const basegfx::B2DVector&            rSlideBounds );
     172             : 
     173             :         /** Search a sequence of NamedValues for a given element.
     174             : 
     175             :             @return true, if the sequence contains the specified
     176             :             element.
     177             :          */
     178             :         bool findNamedValue( ::com::sun::star::uno::Sequence<
     179             :                                  ::com::sun::star::beans::NamedValue > const& rSequence,
     180             :                              const ::com::sun::star::beans::NamedValue& rSearchKey );
     181             : 
     182             :         basegfx::B2DRange calcRelativeShapeBounds( const basegfx::B2DVector& rPageSize,
     183             :                                                    const basegfx::B2DRange&  rShapeBounds );
     184             : 
     185             :         /** Get the shape transformation from the attribute set
     186             : 
     187             :             @param rBounds
     188             :             Original shape bound rect (to substitute default attribute
     189             :             layer values)
     190             : 
     191             :             @param pAttr
     192             :             Attribute set. Might be NULL (then, rBounds is used to set
     193             :             a simple scale and translate of the unit rect to rBounds).
     194             :         */
     195             :         basegfx::B2DHomMatrix getShapeTransformation(
     196             :             const basegfx::B2DRange&                      rBounds,
     197             :             const boost::shared_ptr<ShapeAttributeLayer>& pAttr );
     198             : 
     199             :         /** Get a shape's sprite transformation from the attribute set
     200             : 
     201             :             @param rPixelSize
     202             :             Pixel size of the sprite
     203             : 
     204             :             @param rOrigSize
     205             :             Original shape size (i.e. the size of the actual sprite
     206             :             content, in the user coordinate system)
     207             : 
     208             :             @param pAttr
     209             :             Attribute set. Might be NULL (then, rBounds is used to set
     210             :             a simple scale and translate of the unit rect to rBounds).
     211             : 
     212             :             @return the transformation to be applied to the sprite.
     213             :         */
     214             :         basegfx::B2DHomMatrix getSpriteTransformation(
     215             :             const basegfx::B2DVector&                     rPixelSize,
     216             :             const basegfx::B2DVector&                     rOrigSize,
     217             :             const boost::shared_ptr<ShapeAttributeLayer>& pAttr );
     218             : 
     219             :         /** Calc update area for a shape.
     220             : 
     221             :             This method calculates the 'covered' area for the shape,
     222             :             i.e. the rectangle that is affected when rendering the
     223             :             shape. Apart from applying the given transformation to the
     224             :             shape rectangle, this method also takes attributes into
     225             :             account, which further scale the output (e.g. character
     226             :             sizes).
     227             : 
     228             :             @param rUnitBounds
     229             :             Shape bounds, in the unit rect coordinate space
     230             : 
     231             :             @param rShapeTransform
     232             :             Transformation matrix the shape should undergo.
     233             : 
     234             :             @param pAttr
     235             :             Current shape attributes
     236             :          */
     237             :         basegfx::B2DRange getShapeUpdateArea(
     238             :             const basegfx::B2DRange&                      rUnitBounds,
     239             :             const basegfx::B2DHomMatrix&                  rShapeTransform,
     240             :             const boost::shared_ptr<ShapeAttributeLayer>& pAttr );
     241             : 
     242             :         /** Calc update area for a shape.
     243             : 
     244             :             This method calculates the 'covered' area for the shape,
     245             :             i.e. the rectangle that is affected when rendering the
     246             :             shape. The difference from the other getShapeUpdateArea()
     247             :             method is the fact that this one works without
     248             :             ShapeAttributeLayer, and only scales up the given shape
     249             :             user coordinate bound rect. The method is typically used
     250             :             to retrieve user coordinate system bound rects for shapes
     251             :             which are smaller than the default unit bound rect
     252             :             (because e.g. of subsetting)
     253             : 
     254             :             @param rUnitBounds
     255             :             Shape bounds, in the unit rect coordinate space
     256             : 
     257             :             @param rShapeBounds
     258             :             Current shape bounding box in user coordinate space.
     259             :          */
     260             :         basegfx::B2DRange getShapeUpdateArea( const basegfx::B2DRange& rUnitBounds,
     261             :                                               const basegfx::B2DRange& rShapeBounds );
     262             : 
     263             :         /** Calc output position and size of shape, according to given
     264             :             attribute layer.
     265             : 
     266             :             Rotations, shears etc. and not taken into account,
     267             :             i.e. the returned rectangle is NOT the bounding box. Use
     268             :             it as if aBounds.getMinimum() is the output position and
     269             :             aBounds.getRange() the scaling of the shape.
     270             :          */
     271             :         basegfx::B2DRange getShapePosSize(
     272             :             const basegfx::B2DRange&                      rOrigBounds,
     273             :             const boost::shared_ptr<ShapeAttributeLayer>& pAttr );
     274             : 
     275             :         /** Convert a plain UNO API 32 bit int to RGBColor
     276             :          */
     277             :         RGBColor unoColor2RGBColor( sal_Int32 );
     278             :         /** Convert an IntSRGBA to plain UNO API 32 bit int
     279             :          */
     280             :         sal_Int32 RGBAColor2UnoColor( cppcanvas::Color::IntSRGBA );
     281             : 
     282             :         /** Fill a plain rectangle on the given canvas with the given color
     283             :          */
     284             :         void fillRect( const boost::shared_ptr< cppcanvas::Canvas >& rCanvas,
     285             :                        const basegfx::B2DRange&                      rRect,
     286             :                        cppcanvas::Color::IntSRGBA                    aFillColor );
     287             : 
     288             :         /** Init canvas with default background (white)
     289             :          */
     290             :         void initSlideBackground( const boost::shared_ptr< cppcanvas::Canvas >& rCanvas,
     291             :                                   const basegfx::B2IVector&                     rSize );
     292             : 
     293             :         /// Gets a random ordinal [0,n)
     294           0 :         inline ::std::size_t getRandomOrdinal( const ::std::size_t n )
     295             :         {
     296           0 :             return comphelper::rng::uniform_size_distribution(0, n-1);
     297             :         }
     298             : 
     299             :         /// To work around ternary operator in initializer lists
     300             :         /// (Solaris compiler problems)
     301             :         template <typename T>
     302             :         inline T const & ternary_op(
     303             :             const bool cond, T const & arg1, T const & arg2 )
     304             :         {
     305             :             if (cond)
     306             :                 return arg1;
     307             :             else
     308             :                 return arg2;
     309             :         }
     310             : 
     311             :         template <typename ValueType>
     312           0 :         inline bool getPropertyValue(
     313             :             ValueType & rValue,
     314             :             com::sun::star::uno::Reference<
     315             :             com::sun::star::beans::XPropertySet> const & xPropSet,
     316             :             OUString const & propName )
     317             :         {
     318             :             try {
     319             :                 const com::sun::star::uno::Any& a(
     320           0 :                     xPropSet->getPropertyValue( propName ) );
     321           0 :                 bool const bRet = (a >>= rValue);
     322             : #if OSL_DEBUG_LEVEL > 0
     323             :                 if( !bRet )
     324             :                     OSL_TRACE( "%s: while retrieving property %s, cannot extract Any of type %s\n",
     325             :                                OUStringToOString( propName,
     326             :                                                          RTL_TEXTENCODING_ASCII_US ).getStr(),
     327             :                                BOOST_CURRENT_FUNCTION,
     328             :                                OUStringToOString( a.getValueTypeRef()->pTypeName,
     329             :                                                          RTL_TEXTENCODING_ASCII_US ).getStr() );
     330             : #endif
     331           0 :                 return bRet;
     332             :             }
     333           0 :             catch (com::sun::star::uno::RuntimeException &)
     334             :             {
     335           0 :                 throw;
     336             :             }
     337           0 :             catch (com::sun::star::uno::Exception &)
     338             :             {
     339           0 :                 return false;
     340             :             }
     341             :         }
     342             : 
     343             :         template <typename ValueType>
     344           0 :         inline bool getPropertyValue(
     345             :             com::sun::star::uno::Reference< ValueType >& rIfc,
     346             :             com::sun::star::uno::Reference<
     347             :             com::sun::star::beans::XPropertySet> const & xPropSet,
     348             :             OUString const & propName )
     349             :         {
     350             :             try
     351             :             {
     352             :                 const com::sun::star::uno::Any& a(
     353           0 :                     xPropSet->getPropertyValue( propName ));
     354           0 :                 rIfc.set( a,
     355             :                           com::sun::star::uno::UNO_QUERY );
     356             : 
     357           0 :                 bool const bRet = rIfc.is();
     358             : #if OSL_DEBUG_LEVEL > 0
     359             :                 if( !bRet )
     360             :                     OSL_TRACE( "%s: while retrieving property %s, cannot extract Any of type %s to interface\n",
     361             :                                OUStringToOString( propName,
     362             :                                                          RTL_TEXTENCODING_ASCII_US ).getStr(),
     363             :                                BOOST_CURRENT_FUNCTION,
     364             :                                OUStringToOString( a.getValueTypeRef()->pTypeName,
     365             :                                                          RTL_TEXTENCODING_ASCII_US ).getStr() );
     366             : #endif
     367           0 :                 return bRet;
     368             :             }
     369           0 :             catch (com::sun::star::uno::RuntimeException &)
     370             :             {
     371           0 :                 throw;
     372             :             }
     373           0 :             catch (com::sun::star::uno::Exception &)
     374             :             {
     375           0 :                 return false;
     376             :             }
     377             :         }
     378             : 
     379             :         /// Get the content of the BoundRect shape property
     380             :         basegfx::B2DRange getAPIShapeBounds( const ::com::sun::star::uno::Reference<
     381             :                                                 ::com::sun::star::drawing::XShape >& xShape );
     382             : 
     383             : /*
     384             :         TODO(F1): When ZOrder someday becomes usable enable this
     385             : 
     386             :         /// Get the content of the ZOrder shape property
     387             :         double getAPIShapePrio( const ::com::sun::star::uno::Reference<
     388             :                                       ::com::sun::star::drawing::XShape >& xShape );
     389             : */
     390             : 
     391             :         basegfx::B2IVector getSlideSizePixel( const basegfx::B2DVector&         rSize,
     392             :                                               const boost::shared_ptr<UnoView>& pView );
     393             :     }
     394             : 
     395             :     // TODO(Q1): this could possibly be implemented with a somewhat
     396             :     // more lightweight template, by having the actual worker receive
     397             :     // only a function pointer, and a thin templated wrapper around
     398             :     // that which converts member functions into that.
     399             : 
     400             :     /** Apply given functor to every animation node child.
     401             : 
     402             :         @param xNode
     403             :         Parent node
     404             : 
     405             :         @param rFunctor
     406             :         Functor to apply. The functor must have an appropriate
     407             :         operator()( const ::com::sun::star::uno::Reference<
     408             :         ::com::sun::star::animations::XAnimationNode >& ) member.
     409             : 
     410             :         @return true, if the functor was successfully applied to
     411             :         all children, false otherwise.
     412             :     */
     413           0 :     template< typename Functor > inline bool for_each_childNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >&    xNode,
     414             :                                                                  Functor&                                                                                  rFunctor )
     415             :     {
     416             :         try
     417             :         {
     418             :             // get an XEnumerationAccess to the children
     419             :             ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumerationAccess >
     420             :                    xEnumerationAccess( xNode,
     421           0 :                                        ::com::sun::star::uno::UNO_QUERY_THROW );
     422             :             ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >
     423           0 :                    xEnumeration( xEnumerationAccess->createEnumeration(),
     424           0 :                                  ::com::sun::star::uno::UNO_QUERY_THROW );
     425             : 
     426           0 :             while( xEnumeration->hasMoreElements() )
     427             :             {
     428             :                 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >
     429           0 :                            xChildNode( xEnumeration->nextElement(),
     430           0 :                                       ::com::sun::star::uno::UNO_QUERY_THROW );
     431           0 :                 rFunctor( xChildNode );
     432             :             }
     433           0 :                                                                                                                                                                                                                            return true;
     434             :         }
     435           0 :         catch( ::com::sun::star::uno::Exception& )
     436             :         {
     437           0 :             return false;
     438             :         }
     439             :     }
     440             : }
     441             : 
     442             : #endif // INCLUDED_SLIDESHOW_SOURCE_INC_TOOLS_HXX
     443             : 
     444             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10