LCOV - code coverage report
Current view: top level - slideshow/source/inc - tools.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 38 0.0 %
Date: 2014-04-11 Functions: 0 23 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_TOOLS_HXX
      21             : #define INCLUDED_SLIDESHOW_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             : 
      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             :             return static_cast< ::std::size_t >(
     297           0 :                 double(n) * rand() / (RAND_MAX + 1.0) );
     298             :         }
     299             : 
     300             :         /// To work around ternary operator in initializer lists
     301             :         /// (Solaris compiler problems)
     302             :         template <typename T>
     303             :         inline T const & ternary_op(
     304             :             const bool cond, T const & arg1, T const & arg2 )
     305             :         {
     306             :             if (cond)
     307             :                 return arg1;
     308             :             else
     309             :                 return arg2;
     310             :         }
     311             : 
     312             :         template <typename ValueType>
     313           0 :         inline bool getPropertyValue(
     314             :             ValueType & rValue,
     315             :             com::sun::star::uno::Reference<
     316             :             com::sun::star::beans::XPropertySet> const & xPropSet,
     317             :             OUString const & propName )
     318             :         {
     319             :             try {
     320             :                 const com::sun::star::uno::Any& a(
     321           0 :                     xPropSet->getPropertyValue( propName ) );
     322           0 :                 bool const bRet = (a >>= rValue);
     323             : #if OSL_DEBUG_LEVEL > 0
     324             :                 if( !bRet )
     325             :                     OSL_TRACE( "%s: while retrieving property %s, cannot extract Any of type %s\n",
     326             :                                OUStringToOString( propName,
     327             :                                                          RTL_TEXTENCODING_ASCII_US ).getStr(),
     328             :                                BOOST_CURRENT_FUNCTION,
     329             :                                OUStringToOString( a.getValueTypeRef()->pTypeName,
     330             :                                                          RTL_TEXTENCODING_ASCII_US ).getStr() );
     331             : #endif
     332           0 :                 return bRet;
     333             :             }
     334           0 :             catch (com::sun::star::uno::RuntimeException &)
     335             :             {
     336           0 :                 throw;
     337             :             }
     338           0 :             catch (com::sun::star::uno::Exception &)
     339             :             {
     340           0 :                 return false;
     341             :             }
     342             :         }
     343             : 
     344             :         template <typename ValueType>
     345           0 :         inline bool getPropertyValue(
     346             :             com::sun::star::uno::Reference< ValueType >& rIfc,
     347             :             com::sun::star::uno::Reference<
     348             :             com::sun::star::beans::XPropertySet> const & xPropSet,
     349             :             OUString const & propName )
     350             :         {
     351             :             try
     352             :             {
     353             :                 const com::sun::star::uno::Any& a(
     354           0 :                     xPropSet->getPropertyValue( propName ));
     355           0 :                 rIfc.set( a,
     356             :                           com::sun::star::uno::UNO_QUERY );
     357             : 
     358           0 :                 bool const bRet = rIfc.is();
     359             : #if OSL_DEBUG_LEVEL > 0
     360             :                 if( !bRet )
     361             :                     OSL_TRACE( "%s: while retrieving property %s, cannot extract Any of type %s to interface\n",
     362             :                                OUStringToOString( propName,
     363             :                                                          RTL_TEXTENCODING_ASCII_US ).getStr(),
     364             :                                BOOST_CURRENT_FUNCTION,
     365             :                                OUStringToOString( a.getValueTypeRef()->pTypeName,
     366             :                                                          RTL_TEXTENCODING_ASCII_US ).getStr() );
     367             : #endif
     368           0 :                 return bRet;
     369             :             }
     370           0 :             catch (com::sun::star::uno::RuntimeException &)
     371             :             {
     372           0 :                 throw;
     373             :             }
     374           0 :             catch (com::sun::star::uno::Exception &)
     375             :             {
     376           0 :                 return false;
     377             :             }
     378             :         }
     379             : 
     380             :         /// Get the content of the BoundRect shape property
     381             :         basegfx::B2DRange getAPIShapeBounds( const ::com::sun::star::uno::Reference<
     382             :                                                 ::com::sun::star::drawing::XShape >& xShape );
     383             : 
     384             : /*
     385             :         TODO(F1): When ZOrder someday becomes usable enable this
     386             : 
     387             :         /// Get the content of the ZOrder shape property
     388             :         double getAPIShapePrio( const ::com::sun::star::uno::Reference<
     389             :                                       ::com::sun::star::drawing::XShape >& xShape );
     390             : */
     391             : 
     392             :         basegfx::B2IVector getSlideSizePixel( const basegfx::B2DVector&         rSize,
     393             :                                               const boost::shared_ptr<UnoView>& pView );
     394             :     }
     395             : 
     396             :     // TODO(Q1): this could possibly be implemented with a somewhat
     397             :     // more lightweight template, by having the actual worker receive
     398             :     // only a function pointer, and a thin templated wrapper around
     399             :     // that which converts member functions into that.
     400             : 
     401             :     /** Apply given functor to every animation node child.
     402             : 
     403             :         @param xNode
     404             :         Parent node
     405             : 
     406             :         @param rFunctor
     407             :         Functor to apply. The functor must have an appropriate
     408             :         operator()( const ::com::sun::star::uno::Reference<
     409             :         ::com::sun::star::animations::XAnimationNode >& ) member.
     410             : 
     411             :         @return true, if the functor was successfully applied to
     412             :         all children, false otherwise.
     413             :     */
     414           0 :     template< typename Functor > inline bool for_each_childNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >&    xNode,
     415             :                                                                  Functor&                                                                                  rFunctor )
     416             :     {
     417             :         try
     418             :         {
     419             :             // get an XEnumerationAccess to the children
     420             :             ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumerationAccess >
     421             :                    xEnumerationAccess( xNode,
     422           0 :                                        ::com::sun::star::uno::UNO_QUERY_THROW );
     423             :             ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >
     424           0 :                    xEnumeration( xEnumerationAccess->createEnumeration(),
     425           0 :                                  ::com::sun::star::uno::UNO_QUERY_THROW );
     426             : 
     427           0 :             while( xEnumeration->hasMoreElements() )
     428             :             {
     429             :                 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >
     430           0 :                            xChildNode( xEnumeration->nextElement(),
     431           0 :                                       ::com::sun::star::uno::UNO_QUERY_THROW );
     432           0 :                 rFunctor( xChildNode );
     433             :             }
     434           0 :                                                                                                                                                                                                                            return true;
     435             :         }
     436           0 :         catch( ::com::sun::star::uno::Exception& )
     437             :         {
     438           0 :             return false;
     439             :         }
     440             :     }
     441             : }
     442             : 
     443             : #endif /* INCLUDED_SLIDESHOW_TOOLS_HXX */
     444             : 
     445             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10