fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / shapes / mediashape.cxx
blobb658e5090b3a89eac0a3054155e866347652b069
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 // must be first
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <canvas/canvastools.hxx>
26 #include <com/sun/star/drawing/XShape.hpp>
28 #include "mediashape.hxx"
29 #include "viewmediashape.hxx"
30 #include "externalshapebase.hxx"
31 #include "slideshowcontext.hxx"
32 #include "shape.hxx"
33 #include "tools.hxx"
35 #include <boost/bind.hpp>
36 #include <algorithm>
39 using namespace ::com::sun::star;
42 namespace slideshow
44 namespace internal
46 /** Represents a media shape.
48 This implementation offers support for media shapes.
49 Such shapes need special treatment.
51 class MediaShape : public ExternalShapeBase
53 public:
54 /** Create a shape for the given XShape for a media object
56 @param xShape
57 The XShape to represent.
59 @param nPrio
60 Externally-determined shape priority (used e.g. for
61 paint ordering). This number _must be_ unique!
63 MediaShape( const ::com::sun::star::uno::Reference<
64 ::com::sun::star::drawing::XShape >& xShape,
65 double nPrio,
66 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
68 private:
70 // View layer methods
73 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
74 bool bRedrawLayer ) SAL_OVERRIDE;
75 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) SAL_OVERRIDE;
76 virtual bool clearAllViewLayers() SAL_OVERRIDE;
79 // ExternalShapeBase methods
82 virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const SAL_OVERRIDE;
83 virtual void implViewChanged( const UnoViewSharedPtr& rView ) SAL_OVERRIDE;
84 virtual void implViewsChanged() SAL_OVERRIDE;
85 virtual bool implStartIntrinsicAnimation() SAL_OVERRIDE;
86 virtual bool implEndIntrinsicAnimation() SAL_OVERRIDE;
87 virtual bool implPauseIntrinsicAnimation() SAL_OVERRIDE;
88 virtual bool implIsIntrinsicAnimationPlaying() const SAL_OVERRIDE;
89 virtual void implSetIntrinsicAnimationTime(double) SAL_OVERRIDE;
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;
98 MediaShape::MediaShape( const uno::Reference< drawing::XShape >& xShape,
99 double nPrio,
100 const SlideShowContext& rContext ) :
101 ExternalShapeBase( xShape, nPrio, rContext ),
102 maViewMediaShapes(),
103 mbIsPlaying(false)
109 void MediaShape::implViewChanged( const UnoViewSharedPtr& rView )
111 // determine ViewMediaShape that needs update
112 ViewMediaShapeVector::const_iterator aIter(maViewMediaShapes.begin());
113 ViewMediaShapeVector::const_iterator const aEnd (maViewMediaShapes.end());
114 while( aIter != aEnd )
116 if( (*aIter)->getViewLayer()->isOnView(rView) )
117 (*aIter)->resize(getBounds());
119 ++aIter;
125 void MediaShape::implViewsChanged()
127 // resize all ViewShapes
128 ::std::for_each( maViewMediaShapes.begin(),
129 maViewMediaShapes.end(),
130 ::boost::bind(
131 &ViewMediaShape::resize,
133 getBounds()) );
138 void MediaShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
139 bool bRedrawLayer )
141 maViewMediaShapes.push_back(
142 ViewMediaShapeSharedPtr( new ViewMediaShape( rNewLayer,
143 getXShape(),
144 mxComponentContext )));
146 // push new size to view shape
147 maViewMediaShapes.back()->resize( getBounds() );
149 // render the Shape on the newly added ViewLayer
150 if( bRedrawLayer )
151 maViewMediaShapes.back()->render( getBounds() );
156 bool MediaShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
158 const ViewMediaShapeVector::iterator aEnd( maViewMediaShapes.end() );
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!" );
168 ViewMediaShapeVector::iterator aIter;
170 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 ::boost::cref( rLayer ) ) )) == aEnd )
178 // view layer seemingly was not added, failed
179 return false;
182 // actually erase from container
183 maViewMediaShapes.erase( aIter, aEnd );
185 return true;
190 bool MediaShape::clearAllViewLayers()
192 maViewMediaShapes.clear();
193 return true;
198 bool MediaShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
200 // redraw all view shapes, by calling their update() method
201 if( ::std::count_if( maViewMediaShapes.begin(),
202 maViewMediaShapes.end(),
203 ::boost::bind<bool>(
204 ::boost::mem_fn( &ViewMediaShape::render ),
206 ::boost::cref( rCurrBounds ) ) )
207 != static_cast<ViewMediaShapeVector::difference_type>(maViewMediaShapes.size()) )
209 // at least one of the ViewShape::update() calls did return
210 // false - update failed on at least one ViewLayer
211 return false;
214 return true;
219 bool MediaShape::implStartIntrinsicAnimation()
221 ::std::for_each( maViewMediaShapes.begin(),
222 maViewMediaShapes.end(),
223 ::boost::mem_fn( &ViewMediaShape::startMedia ) );
225 mbIsPlaying = true;
227 return true;
232 bool MediaShape::implEndIntrinsicAnimation()
234 ::std::for_each( maViewMediaShapes.begin(),
235 maViewMediaShapes.end(),
236 ::boost::mem_fn( &ViewMediaShape::endMedia ) );
238 mbIsPlaying = false;
240 return true;
245 bool MediaShape::implPauseIntrinsicAnimation()
247 ::std::for_each( maViewMediaShapes.begin(),
248 maViewMediaShapes.end(),
249 ::boost::mem_fn( &ViewMediaShape::pauseMedia ) );
251 mbIsPlaying = false;
253 return true;
258 bool MediaShape::implIsIntrinsicAnimationPlaying() const
260 return mbIsPlaying;
265 void MediaShape::implSetIntrinsicAnimationTime(double fTime)
267 ::std::for_each( maViewMediaShapes.begin(),
268 maViewMediaShapes.end(),
269 ::boost::bind( &ViewMediaShape::setMediaTime,
270 _1, boost::cref(fTime)) );
275 ShapeSharedPtr createMediaShape(
276 const uno::Reference< drawing::XShape >& xShape,
277 double nPrio,
278 const SlideShowContext& rContext)
280 boost::shared_ptr< MediaShape > pMediaShape(
281 new MediaShape(xShape, nPrio, rContext));
283 return pMediaShape;
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */