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

Generated by: LCOV version 1.10