LCOV - code coverage report
Current view: top level - slideshow/source/engine/shapes - mediashape.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 60 0.0 %
Date: 2012-08-25 Functions: 0 17 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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                 :            : 
      21                 :            : // must be first
      22                 :            : #include <canvas/debug.hxx>
      23                 :            : #include <canvas/verbosetrace.hxx>
      24                 :            : #include <canvas/canvastools.hxx>
      25                 :            : 
      26                 :            : #include <com/sun/star/drawing/XShape.hpp>
      27                 :            : 
      28                 :            : #include "mediashape.hxx"
      29                 :            : #include "viewmediashape.hxx"
      30                 :            : #include "externalshapebase.hxx"
      31                 :            : #include "slideshowcontext.hxx"
      32                 :            : #include "shape.hxx"
      33                 :            : #include "tools.hxx"
      34                 :            : 
      35                 :            : #include <boost/bind.hpp>
      36                 :            : #include <algorithm>
      37                 :            : 
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : 
      41                 :            : 
      42                 :            : namespace slideshow
      43                 :            : {
      44                 :            :     namespace internal
      45                 :            :     {
      46                 :            :         /** Represents a media shape.
      47                 :            : 
      48                 :            :             This implementation offers support for media shapes.
      49                 :            :             Such shapes need special treatment.
      50                 :            :          */
      51                 :          0 :         class MediaShape : public ExternalShapeBase
      52                 :            :         {
      53                 :            :         public:
      54                 :            :             /** Create a shape for the given XShape for a media object
      55                 :            : 
      56                 :            :                 @param xShape
      57                 :            :                 The XShape to represent.
      58                 :            : 
      59                 :            :                 @param nPrio
      60                 :            :                 Externally-determined shape priority (used e.g. for
      61                 :            :                 paint ordering). This number _must be_ unique!
      62                 :            :              */
      63                 :            :             MediaShape( const ::com::sun::star::uno::Reference<
      64                 :            :                                ::com::sun::star::drawing::XShape >& xShape,
      65                 :            :                         double                                      nPrio,
      66                 :            :                         const SlideShowContext&                     rContext ); // throw ShapeLoadFailedException;
      67                 :            : 
      68                 :            :         private:
      69                 :            : 
      70                 :            :             // View layer methods
      71                 :            :             //------------------------------------------------------------------
      72                 :            : 
      73                 :            :             virtual void addViewLayer( const ViewLayerSharedPtr&    rNewLayer,
      74                 :            :                                        bool                         bRedrawLayer );
      75                 :            :             virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer );
      76                 :            :             virtual bool clearAllViewLayers();
      77                 :            : 
      78                 :            : 
      79                 :            :             // ExternalShapeBase methods
      80                 :            :             //------------------------------------------------------------------
      81                 :            : 
      82                 :            :             virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const;
      83                 :            :             virtual void implViewChanged( const UnoViewSharedPtr& rView );
      84                 :            :             virtual void implViewsChanged();
      85                 :            :             virtual bool implStartIntrinsicAnimation();
      86                 :            :             virtual bool implEndIntrinsicAnimation();
      87                 :            :             virtual bool implPauseIntrinsicAnimation();
      88                 :            :             virtual bool implIsIntrinsicAnimationPlaying() const;
      89                 :            :             virtual void implSetIntrinsicAnimationTime(double);
      90                 :            : 
      91                 :            :             /// the list of active view shapes (one for each registered view layer)
      92                 :            :             typedef ::std::vector< ViewMediaShapeSharedPtr > ViewMediaShapeVector;
      93                 :            :             ViewMediaShapeVector                             maViewMediaShapes;
      94                 :            :             bool                                             mbIsPlaying;
      95                 :            :         };
      96                 :            : 
      97                 :            : 
      98                 :          0 :         MediaShape::MediaShape( const uno::Reference< drawing::XShape >& xShape,
      99                 :            :                                   double                                     nPrio,
     100                 :            :                                 const SlideShowContext&                  rContext ) :
     101                 :            :             ExternalShapeBase( xShape, nPrio, rContext ),
     102                 :            :             maViewMediaShapes(),
     103                 :          0 :             mbIsPlaying(false)
     104                 :            :         {
     105                 :          0 :         }
     106                 :            : 
     107                 :            :         // ---------------------------------------------------------------------
     108                 :            : 
     109                 :          0 :         void MediaShape::implViewChanged( const UnoViewSharedPtr& rView )
     110                 :            :         {
     111                 :            :             // determine ViewMediaShape that needs update
     112                 :          0 :             ViewMediaShapeVector::const_iterator       aIter(maViewMediaShapes.begin());
     113                 :          0 :             ViewMediaShapeVector::const_iterator const aEnd (maViewMediaShapes.end());
     114                 :          0 :             while( aIter != aEnd )
     115                 :            :             {
     116                 :          0 :                 if( (*aIter)->getViewLayer()->isOnView(rView) )
     117                 :          0 :                     (*aIter)->resize(getBounds());
     118                 :            : 
     119                 :          0 :                 ++aIter;
     120                 :            :             }
     121                 :          0 :         }
     122                 :            : 
     123                 :            :         // ---------------------------------------------------------------------
     124                 :            : 
     125                 :          0 :         void MediaShape::implViewsChanged()
     126                 :            :         {
     127                 :            :             // resize all ViewShapes
     128                 :            :             ::std::for_each( maViewMediaShapes.begin(),
     129                 :            :                              maViewMediaShapes.end(),
     130                 :            :                              ::boost::bind(
     131                 :            :                                  &ViewMediaShape::resize,
     132                 :            :                                  _1,
     133                 :          0 :                                  ::boost::cref( getBounds())) );
     134                 :          0 :         }
     135                 :            : 
     136                 :            :         // ---------------------------------------------------------------------
     137                 :            : 
     138                 :          0 :         void MediaShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
     139                 :            :                                        bool                      bRedrawLayer )
     140                 :            :         {
     141                 :            :             maViewMediaShapes.push_back(
     142                 :            :                 ViewMediaShapeSharedPtr( new ViewMediaShape( rNewLayer,
     143                 :          0 :                                                              getXShape(),
     144                 :          0 :                                                              mxComponentContext )));
     145                 :            : 
     146                 :            :             // push new size to view shape
     147                 :          0 :             maViewMediaShapes.back()->resize( getBounds() );
     148                 :            : 
     149                 :            :             // render the Shape on the newly added ViewLayer
     150                 :          0 :             if( bRedrawLayer )
     151                 :          0 :                 maViewMediaShapes.back()->render( getBounds() );
     152                 :          0 :         }
     153                 :            : 
     154                 :            :         // ---------------------------------------------------------------------
     155                 :            : 
     156                 :          0 :         bool MediaShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
     157                 :            :         {
     158                 :          0 :             const ViewMediaShapeVector::iterator aEnd( maViewMediaShapes.end() );
     159                 :            : 
     160                 :            :             OSL_ENSURE( ::std::count_if(maViewMediaShapes.begin(),
     161                 :            :                                         aEnd,
     162                 :            :                                         ::boost::bind<bool>(
     163                 :            :                                             ::std::equal_to< ViewLayerSharedPtr >(),
     164                 :            :                                             ::boost::bind( &ViewMediaShape::getViewLayer, _1 ),
     165                 :            :                                             ::boost::cref( rLayer ) ) ) < 2,
     166                 :            :                         "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" );
     167                 :            : 
     168                 :          0 :             ViewMediaShapeVector::iterator aIter;
     169                 :            : 
     170                 :          0 :             if( (aIter=::std::remove_if( maViewMediaShapes.begin(),
     171                 :            :                                          aEnd,
     172                 :            :                                          ::boost::bind<bool>(
     173                 :            :                                              ::std::equal_to< ViewLayerSharedPtr >(),
     174                 :            :                                              ::boost::bind( &ViewMediaShape::getViewLayer,
     175                 :            :                                                             _1 ),
     176                 :          0 :                                              ::boost::cref( rLayer ) ) )) == aEnd )
     177                 :            :             {
     178                 :            :                 // view layer seemingly was not added, failed
     179                 :          0 :                 return false;
     180                 :            :             }
     181                 :            : 
     182                 :            :             // actually erase from container
     183                 :          0 :             maViewMediaShapes.erase( aIter, aEnd );
     184                 :            : 
     185                 :          0 :             return true;
     186                 :            :         }
     187                 :            : 
     188                 :            :         // ---------------------------------------------------------------------
     189                 :            : 
     190                 :          0 :         bool MediaShape::clearAllViewLayers()
     191                 :            :         {
     192                 :          0 :             maViewMediaShapes.clear();
     193                 :          0 :             return true;
     194                 :            :         }
     195                 :            : 
     196                 :            :         // ---------------------------------------------------------------------
     197                 :            : 
     198                 :          0 :         bool MediaShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
     199                 :            :         {
     200                 :            :             // redraw all view shapes, by calling their update() method
     201                 :          0 :             if( ::std::count_if( maViewMediaShapes.begin(),
     202                 :            :                                  maViewMediaShapes.end(),
     203                 :            :                                  ::boost::bind<bool>(
     204                 :            :                                      ::boost::mem_fn( &ViewMediaShape::render ),
     205                 :            :                                      _1,
     206                 :          0 :                                      ::boost::cref( rCurrBounds ) ) )
     207                 :          0 :                 != static_cast<ViewMediaShapeVector::difference_type>(maViewMediaShapes.size()) )
     208                 :            :             {
     209                 :            :                 // at least one of the ViewShape::update() calls did return
     210                 :            :                 // false - update failed on at least one ViewLayer
     211                 :          0 :                 return false;
     212                 :            :             }
     213                 :            : 
     214                 :          0 :             return true;
     215                 :            :         }
     216                 :            : 
     217                 :            :         // ---------------------------------------------------------------------
     218                 :            : 
     219                 :          0 :         bool MediaShape::implStartIntrinsicAnimation()
     220                 :            :         {
     221                 :            :             ::std::for_each( maViewMediaShapes.begin(),
     222                 :            :                              maViewMediaShapes.end(),
     223                 :          0 :                              ::boost::mem_fn( &ViewMediaShape::startMedia ) );
     224                 :            : 
     225                 :          0 :             mbIsPlaying = true;
     226                 :            : 
     227                 :          0 :             return true;
     228                 :            :         }
     229                 :            : 
     230                 :            :         // ---------------------------------------------------------------------
     231                 :            : 
     232                 :          0 :         bool MediaShape::implEndIntrinsicAnimation()
     233                 :            :         {
     234                 :            :             ::std::for_each( maViewMediaShapes.begin(),
     235                 :            :                              maViewMediaShapes.end(),
     236                 :          0 :                              ::boost::mem_fn( &ViewMediaShape::endMedia ) );
     237                 :            : 
     238                 :          0 :             mbIsPlaying = false;
     239                 :            : 
     240                 :          0 :             return true;
     241                 :            :         }
     242                 :            : 
     243                 :            :         // ---------------------------------------------------------------------
     244                 :            : 
     245                 :          0 :         bool MediaShape::implPauseIntrinsicAnimation()
     246                 :            :         {
     247                 :            :             ::std::for_each( maViewMediaShapes.begin(),
     248                 :            :                              maViewMediaShapes.end(),
     249                 :          0 :                              ::boost::mem_fn( &ViewMediaShape::pauseMedia ) );
     250                 :            : 
     251                 :          0 :             mbIsPlaying = false;
     252                 :            : 
     253                 :          0 :             return true;
     254                 :            :         }
     255                 :            : 
     256                 :            :         // ---------------------------------------------------------------------
     257                 :            : 
     258                 :          0 :         bool MediaShape::implIsIntrinsicAnimationPlaying() const
     259                 :            :         {
     260                 :          0 :             return mbIsPlaying;
     261                 :            :         }
     262                 :            : 
     263                 :            :         // ---------------------------------------------------------------------
     264                 :            : 
     265                 :          0 :         void MediaShape::implSetIntrinsicAnimationTime(double fTime)
     266                 :            :         {
     267                 :            :             ::std::for_each( maViewMediaShapes.begin(),
     268                 :            :                              maViewMediaShapes.end(),
     269                 :            :                              ::boost::bind( &ViewMediaShape::setMediaTime,
     270                 :          0 :                                             _1, boost::cref(fTime)) );
     271                 :          0 :         }
     272                 :            : 
     273                 :            :         // ---------------------------------------------------------------------
     274                 :            : 
     275                 :          0 :         ShapeSharedPtr createMediaShape(
     276                 :            :             const uno::Reference< drawing::XShape >& xShape,
     277                 :            :             double                                   nPrio,
     278                 :            :             const SlideShowContext&                  rContext)
     279                 :            :         {
     280                 :            :             boost::shared_ptr< MediaShape > pMediaShape(
     281                 :          0 :                 new MediaShape(xShape, nPrio, rContext));
     282                 :            : 
     283                 :          0 :             return pMediaShape;
     284                 :            :         }
     285                 :            : 
     286                 :            :     }
     287                 :          0 : }
     288                 :            : 
     289                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10