170f497fbSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 370f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 470f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file 570f497fbSAndrew Rist * distributed with this work for additional information 670f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file 770f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the 870f497fbSAndrew Rist * "License"); you may not use this file except in compliance 970f497fbSAndrew Rist * with the License. You may obtain a copy of the License at 1070f497fbSAndrew Rist * 1170f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1270f497fbSAndrew Rist * 1370f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing, 1470f497fbSAndrew Rist * software distributed under the License is distributed on an 1570f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1670f497fbSAndrew Rist * KIND, either express or implied. See the License for the 1770f497fbSAndrew Rist * specific language governing permissions and limitations 1870f497fbSAndrew Rist * under the License. 1970f497fbSAndrew Rist * 2070f497fbSAndrew Rist *************************************************************/ 2170f497fbSAndrew Rist 2270f497fbSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // must be first 28cdf0e10cSrcweir #include <canvas/debug.hxx> 29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 30cdf0e10cSrcweir #include <canvas/canvastools.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include "mediashape.hxx" 35cdf0e10cSrcweir #include "viewmediashape.hxx" 36cdf0e10cSrcweir #include "externalshapebase.hxx" 37cdf0e10cSrcweir #include "slideshowcontext.hxx" 38cdf0e10cSrcweir #include "shape.hxx" 39cdf0e10cSrcweir #include "tools.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <boost/bind.hpp> 42cdf0e10cSrcweir #include <algorithm> 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir using namespace ::com::sun::star; 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir namespace slideshow 49cdf0e10cSrcweir { 50cdf0e10cSrcweir namespace internal 51cdf0e10cSrcweir { 52cdf0e10cSrcweir /** Represents a media shape. 53cdf0e10cSrcweir 54cdf0e10cSrcweir This implementation offers support for media shapes. 55cdf0e10cSrcweir Such shapes need special treatment. 56cdf0e10cSrcweir */ 57cdf0e10cSrcweir class MediaShape : public ExternalShapeBase 58cdf0e10cSrcweir { 59cdf0e10cSrcweir public: 60cdf0e10cSrcweir /** Create a shape for the given XShape for a media object 61cdf0e10cSrcweir 62cdf0e10cSrcweir @param xShape 63cdf0e10cSrcweir The XShape to represent. 64cdf0e10cSrcweir 65cdf0e10cSrcweir @param nPrio 66cdf0e10cSrcweir Externally-determined shape priority (used e.g. for 67cdf0e10cSrcweir paint ordering). This number _must be_ unique! 68cdf0e10cSrcweir */ 69cdf0e10cSrcweir MediaShape( const ::com::sun::star::uno::Reference< 70cdf0e10cSrcweir ::com::sun::star::drawing::XShape >& xShape, 71cdf0e10cSrcweir double nPrio, 72cdf0e10cSrcweir const SlideShowContext& rContext ); // throw ShapeLoadFailedException; 73cdf0e10cSrcweir 74cdf0e10cSrcweir private: 75cdf0e10cSrcweir 76cdf0e10cSrcweir // View layer methods 77cdf0e10cSrcweir //------------------------------------------------------------------ 78cdf0e10cSrcweir 79cdf0e10cSrcweir virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer, 80cdf0e10cSrcweir bool bRedrawLayer ); 81cdf0e10cSrcweir virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ); 82cdf0e10cSrcweir virtual bool clearAllViewLayers(); 83cdf0e10cSrcweir 84cdf0e10cSrcweir 85cdf0e10cSrcweir // ExternalShapeBase methods 86cdf0e10cSrcweir //------------------------------------------------------------------ 87cdf0e10cSrcweir 88cdf0e10cSrcweir virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const; 89cdf0e10cSrcweir virtual void implViewChanged( const UnoViewSharedPtr& rView ); 90cdf0e10cSrcweir virtual void implViewsChanged(); 91cdf0e10cSrcweir virtual bool implStartIntrinsicAnimation(); 92cdf0e10cSrcweir virtual bool implEndIntrinsicAnimation(); 93cdf0e10cSrcweir virtual bool implPauseIntrinsicAnimation(); 94cdf0e10cSrcweir virtual bool implIsIntrinsicAnimationPlaying() const; 95cdf0e10cSrcweir virtual void implSetIntrinsicAnimationTime(double); 96cdf0e10cSrcweir 97cdf0e10cSrcweir /// the list of active view shapes (one for each registered view layer) 98cdf0e10cSrcweir typedef ::std::vector< ViewMediaShapeSharedPtr > ViewMediaShapeVector; 99cdf0e10cSrcweir ViewMediaShapeVector maViewMediaShapes; 100cdf0e10cSrcweir bool mbIsPlaying; 101cdf0e10cSrcweir }; 102cdf0e10cSrcweir 103cdf0e10cSrcweir MediaShape(const uno::Reference<drawing::XShape> & xShape,double nPrio,const SlideShowContext & rContext)104cdf0e10cSrcweir MediaShape::MediaShape( const uno::Reference< drawing::XShape >& xShape, 105cdf0e10cSrcweir double nPrio, 106cdf0e10cSrcweir const SlideShowContext& rContext ) : 107cdf0e10cSrcweir ExternalShapeBase( xShape, nPrio, rContext ), 108cdf0e10cSrcweir maViewMediaShapes(), 109cdf0e10cSrcweir mbIsPlaying(false) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // --------------------------------------------------------------------- 114cdf0e10cSrcweir implViewChanged(const UnoViewSharedPtr & rView)115cdf0e10cSrcweir void MediaShape::implViewChanged( const UnoViewSharedPtr& rView ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir // determine ViewMediaShape that needs update 118cdf0e10cSrcweir ViewMediaShapeVector::const_iterator aIter(maViewMediaShapes.begin()); 119cdf0e10cSrcweir ViewMediaShapeVector::const_iterator const aEnd (maViewMediaShapes.end()); 120cdf0e10cSrcweir while( aIter != aEnd ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir if( (*aIter)->getViewLayer()->isOnView(rView) ) 123cdf0e10cSrcweir (*aIter)->resize(getBounds()); 124cdf0e10cSrcweir 125cdf0e10cSrcweir ++aIter; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir // --------------------------------------------------------------------- 130cdf0e10cSrcweir implViewsChanged()131cdf0e10cSrcweir void MediaShape::implViewsChanged() 132cdf0e10cSrcweir { 133cdf0e10cSrcweir // resize all ViewShapes 134*a72d41dcSDamjan Jovanovic ::basegfx::B2DRange aBounds = getBounds(); 135cdf0e10cSrcweir ::std::for_each( maViewMediaShapes.begin(), 136cdf0e10cSrcweir maViewMediaShapes.end(), 137cdf0e10cSrcweir ::boost::bind( 138cdf0e10cSrcweir &ViewMediaShape::resize, 139cdf0e10cSrcweir _1, 140*a72d41dcSDamjan Jovanovic ::boost::cref( aBounds ) ) ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir // --------------------------------------------------------------------- 144cdf0e10cSrcweir addViewLayer(const ViewLayerSharedPtr & rNewLayer,bool bRedrawLayer)145cdf0e10cSrcweir void MediaShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer, 146cdf0e10cSrcweir bool bRedrawLayer ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir maViewMediaShapes.push_back( 149cdf0e10cSrcweir ViewMediaShapeSharedPtr( new ViewMediaShape( rNewLayer, 150cdf0e10cSrcweir getXShape(), 151cdf0e10cSrcweir mxComponentContext ))); 152cdf0e10cSrcweir 153cdf0e10cSrcweir // push new size to view shape 154cdf0e10cSrcweir maViewMediaShapes.back()->resize( getBounds() ); 155cdf0e10cSrcweir 156cdf0e10cSrcweir // render the Shape on the newly added ViewLayer 157cdf0e10cSrcweir if( bRedrawLayer ) 158cdf0e10cSrcweir maViewMediaShapes.back()->render( getBounds() ); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir // --------------------------------------------------------------------- 162cdf0e10cSrcweir removeViewLayer(const ViewLayerSharedPtr & rLayer)163cdf0e10cSrcweir bool MediaShape::removeViewLayer( const ViewLayerSharedPtr& rLayer ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir const ViewMediaShapeVector::iterator aEnd( maViewMediaShapes.end() ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir OSL_ENSURE( ::std::count_if(maViewMediaShapes.begin(), 168cdf0e10cSrcweir aEnd, 169cdf0e10cSrcweir ::boost::bind<bool>( 170cdf0e10cSrcweir ::std::equal_to< ViewLayerSharedPtr >(), 171cdf0e10cSrcweir ::boost::bind( &ViewMediaShape::getViewLayer, _1 ), 172cdf0e10cSrcweir ::boost::cref( rLayer ) ) ) < 2, 173cdf0e10cSrcweir "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir ViewMediaShapeVector::iterator aIter; 176cdf0e10cSrcweir 177cdf0e10cSrcweir if( (aIter=::std::remove_if( maViewMediaShapes.begin(), 178cdf0e10cSrcweir aEnd, 179cdf0e10cSrcweir ::boost::bind<bool>( 180cdf0e10cSrcweir ::std::equal_to< ViewLayerSharedPtr >(), 181cdf0e10cSrcweir ::boost::bind( &ViewMediaShape::getViewLayer, 182cdf0e10cSrcweir _1 ), 183cdf0e10cSrcweir ::boost::cref( rLayer ) ) )) == aEnd ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir // view layer seemingly was not added, failed 186cdf0e10cSrcweir return false; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir // actually erase from container 190cdf0e10cSrcweir maViewMediaShapes.erase( aIter, aEnd ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir return true; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir // --------------------------------------------------------------------- 196cdf0e10cSrcweir clearAllViewLayers()197cdf0e10cSrcweir bool MediaShape::clearAllViewLayers() 198cdf0e10cSrcweir { 199cdf0e10cSrcweir maViewMediaShapes.clear(); 200cdf0e10cSrcweir return true; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir // --------------------------------------------------------------------- 204cdf0e10cSrcweir implRender(const::basegfx::B2DRange & rCurrBounds) const205cdf0e10cSrcweir bool MediaShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const 206cdf0e10cSrcweir { 207cdf0e10cSrcweir // redraw all view shapes, by calling their update() method 208cdf0e10cSrcweir if( ::std::count_if( maViewMediaShapes.begin(), 209cdf0e10cSrcweir maViewMediaShapes.end(), 210cdf0e10cSrcweir ::boost::bind<bool>( 211cdf0e10cSrcweir ::boost::mem_fn( &ViewMediaShape::render ), 212cdf0e10cSrcweir _1, 213cdf0e10cSrcweir ::boost::cref( rCurrBounds ) ) ) 214cdf0e10cSrcweir != static_cast<ViewMediaShapeVector::difference_type>(maViewMediaShapes.size()) ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir // at least one of the ViewShape::update() calls did return 217cdf0e10cSrcweir // false - update failed on at least one ViewLayer 218cdf0e10cSrcweir return false; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir return true; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir // --------------------------------------------------------------------- 225cdf0e10cSrcweir implStartIntrinsicAnimation()226cdf0e10cSrcweir bool MediaShape::implStartIntrinsicAnimation() 227cdf0e10cSrcweir { 228cdf0e10cSrcweir ::std::for_each( maViewMediaShapes.begin(), 229cdf0e10cSrcweir maViewMediaShapes.end(), 230cdf0e10cSrcweir ::boost::mem_fn( &ViewMediaShape::startMedia ) ); 231cdf0e10cSrcweir 232cdf0e10cSrcweir mbIsPlaying = true; 233cdf0e10cSrcweir 234cdf0e10cSrcweir return true; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir // --------------------------------------------------------------------- 238cdf0e10cSrcweir implEndIntrinsicAnimation()239cdf0e10cSrcweir bool MediaShape::implEndIntrinsicAnimation() 240cdf0e10cSrcweir { 241cdf0e10cSrcweir ::std::for_each( maViewMediaShapes.begin(), 242cdf0e10cSrcweir maViewMediaShapes.end(), 243cdf0e10cSrcweir ::boost::mem_fn( &ViewMediaShape::endMedia ) ); 244cdf0e10cSrcweir 245cdf0e10cSrcweir mbIsPlaying = false; 246cdf0e10cSrcweir 247cdf0e10cSrcweir return true; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir // --------------------------------------------------------------------- 251cdf0e10cSrcweir implPauseIntrinsicAnimation()252cdf0e10cSrcweir bool MediaShape::implPauseIntrinsicAnimation() 253cdf0e10cSrcweir { 254cdf0e10cSrcweir ::std::for_each( maViewMediaShapes.begin(), 255cdf0e10cSrcweir maViewMediaShapes.end(), 256cdf0e10cSrcweir ::boost::mem_fn( &ViewMediaShape::pauseMedia ) ); 257cdf0e10cSrcweir 258cdf0e10cSrcweir mbIsPlaying = false; 259cdf0e10cSrcweir 260cdf0e10cSrcweir return true; 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir // --------------------------------------------------------------------- 264cdf0e10cSrcweir implIsIntrinsicAnimationPlaying() const265cdf0e10cSrcweir bool MediaShape::implIsIntrinsicAnimationPlaying() const 266cdf0e10cSrcweir { 267cdf0e10cSrcweir return mbIsPlaying; 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir // --------------------------------------------------------------------- 271cdf0e10cSrcweir implSetIntrinsicAnimationTime(double fTime)272cdf0e10cSrcweir void MediaShape::implSetIntrinsicAnimationTime(double fTime) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir ::std::for_each( maViewMediaShapes.begin(), 275cdf0e10cSrcweir maViewMediaShapes.end(), 276cdf0e10cSrcweir ::boost::bind( &ViewMediaShape::setMediaTime, 277cdf0e10cSrcweir _1, boost::cref(fTime)) ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir // --------------------------------------------------------------------- 281cdf0e10cSrcweir createMediaShape(const uno::Reference<drawing::XShape> & xShape,double nPrio,const SlideShowContext & rContext)282cdf0e10cSrcweir ShapeSharedPtr createMediaShape( 283cdf0e10cSrcweir const uno::Reference< drawing::XShape >& xShape, 284cdf0e10cSrcweir double nPrio, 285cdf0e10cSrcweir const SlideShowContext& rContext) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir boost::shared_ptr< MediaShape > pMediaShape( 288cdf0e10cSrcweir new MediaShape(xShape, nPrio, rContext)); 289cdf0e10cSrcweir 290cdf0e10cSrcweir return pMediaShape; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir } 294cdf0e10cSrcweir } 295