1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*70f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*70f497fbSAndrew Rist  * distributed with this work for additional information
6*70f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*70f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*70f497fbSAndrew Rist  *
11*70f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist  *
13*70f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist  * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
17*70f497fbSAndrew Rist  * specific language governing permissions and limitations
18*70f497fbSAndrew Rist  * under the License.
19*70f497fbSAndrew Rist  *
20*70f497fbSAndrew Rist  *************************************************************/
21*70f497fbSAndrew Rist 
22*70f497fbSAndrew 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 
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 
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 
131cdf0e10cSrcweir         void MediaShape::implViewsChanged()
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             // resize all ViewShapes
134cdf0e10cSrcweir             ::std::for_each( maViewMediaShapes.begin(),
135cdf0e10cSrcweir                              maViewMediaShapes.end(),
136cdf0e10cSrcweir                              ::boost::bind(
137cdf0e10cSrcweir                                  &ViewMediaShape::resize,
138cdf0e10cSrcweir                                  _1,
139cdf0e10cSrcweir                                  ::boost::cref( getBounds())) );
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 		// ---------------------------------------------------------------------
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         void MediaShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
145cdf0e10cSrcweir                                        bool						 bRedrawLayer )
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             maViewMediaShapes.push_back(
148cdf0e10cSrcweir                 ViewMediaShapeSharedPtr( new ViewMediaShape( rNewLayer,
149cdf0e10cSrcweir                                                              getXShape(),
150cdf0e10cSrcweir                                                              mxComponentContext )));
151cdf0e10cSrcweir 
152cdf0e10cSrcweir             // push new size to view shape
153cdf0e10cSrcweir             maViewMediaShapes.back()->resize( getBounds() );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir             // render the Shape on the newly added ViewLayer
156cdf0e10cSrcweir             if( bRedrawLayer )
157cdf0e10cSrcweir                 maViewMediaShapes.back()->render( getBounds() );
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		// ---------------------------------------------------------------------
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         bool MediaShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
163cdf0e10cSrcweir         {
164cdf0e10cSrcweir             const ViewMediaShapeVector::iterator aEnd( maViewMediaShapes.end() );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir             OSL_ENSURE( ::std::count_if(maViewMediaShapes.begin(),
167cdf0e10cSrcweir                                         aEnd,
168cdf0e10cSrcweir                                         ::boost::bind<bool>(
169cdf0e10cSrcweir                                             ::std::equal_to< ViewLayerSharedPtr >(),
170cdf0e10cSrcweir                                             ::boost::bind( &ViewMediaShape::getViewLayer, _1 ),
171cdf0e10cSrcweir                                             ::boost::cref( rLayer ) ) ) < 2,
172cdf0e10cSrcweir                         "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir             ViewMediaShapeVector::iterator aIter;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir             if( (aIter=::std::remove_if( maViewMediaShapes.begin(),
177cdf0e10cSrcweir                                          aEnd,
178cdf0e10cSrcweir                                          ::boost::bind<bool>(
179cdf0e10cSrcweir                                              ::std::equal_to< ViewLayerSharedPtr >(),
180cdf0e10cSrcweir                                              ::boost::bind( &ViewMediaShape::getViewLayer,
181cdf0e10cSrcweir                                                             _1 ),
182cdf0e10cSrcweir                                              ::boost::cref( rLayer ) ) )) == aEnd )
183cdf0e10cSrcweir             {
184cdf0e10cSrcweir                 // view layer seemingly was not added, failed
185cdf0e10cSrcweir                 return false;
186cdf0e10cSrcweir             }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             // actually erase from container
189cdf0e10cSrcweir             maViewMediaShapes.erase( aIter, aEnd );
190cdf0e10cSrcweir 
191cdf0e10cSrcweir             return true;
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 		// ---------------------------------------------------------------------
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         bool MediaShape::clearAllViewLayers()
197cdf0e10cSrcweir         {
198cdf0e10cSrcweir             maViewMediaShapes.clear();
199cdf0e10cSrcweir             return true;
200cdf0e10cSrcweir         }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 		// ---------------------------------------------------------------------
203cdf0e10cSrcweir 
204cdf0e10cSrcweir         bool MediaShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
205cdf0e10cSrcweir         {
206cdf0e10cSrcweir             // redraw all view shapes, by calling their update() method
207cdf0e10cSrcweir             if( ::std::count_if( maViewMediaShapes.begin(),
208cdf0e10cSrcweir                                  maViewMediaShapes.end(),
209cdf0e10cSrcweir                                  ::boost::bind<bool>(
210cdf0e10cSrcweir                                      ::boost::mem_fn( &ViewMediaShape::render ),
211cdf0e10cSrcweir                                      _1,
212cdf0e10cSrcweir                                      ::boost::cref( rCurrBounds ) ) )
213cdf0e10cSrcweir                 != static_cast<ViewMediaShapeVector::difference_type>(maViewMediaShapes.size()) )
214cdf0e10cSrcweir             {
215cdf0e10cSrcweir                 // at least one of the ViewShape::update() calls did return
216cdf0e10cSrcweir                 // false - update failed on at least one ViewLayer
217cdf0e10cSrcweir                 return false;
218cdf0e10cSrcweir             }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir             return true;
221cdf0e10cSrcweir         }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 		// ---------------------------------------------------------------------
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         bool MediaShape::implStartIntrinsicAnimation()
226cdf0e10cSrcweir         {
227cdf0e10cSrcweir             ::std::for_each( maViewMediaShapes.begin(),
228cdf0e10cSrcweir                              maViewMediaShapes.end(),
229cdf0e10cSrcweir                              ::boost::mem_fn( &ViewMediaShape::startMedia ) );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir             mbIsPlaying = true;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir             return true;
234cdf0e10cSrcweir         }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 		// ---------------------------------------------------------------------
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         bool MediaShape::implEndIntrinsicAnimation()
239cdf0e10cSrcweir         {
240cdf0e10cSrcweir             ::std::for_each( maViewMediaShapes.begin(),
241cdf0e10cSrcweir                              maViewMediaShapes.end(),
242cdf0e10cSrcweir                              ::boost::mem_fn( &ViewMediaShape::endMedia ) );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir             mbIsPlaying = false;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir             return true;
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 		// ---------------------------------------------------------------------
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         bool MediaShape::implPauseIntrinsicAnimation()
252cdf0e10cSrcweir         {
253cdf0e10cSrcweir             ::std::for_each( maViewMediaShapes.begin(),
254cdf0e10cSrcweir                              maViewMediaShapes.end(),
255cdf0e10cSrcweir                              ::boost::mem_fn( &ViewMediaShape::pauseMedia ) );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir             mbIsPlaying = false;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir             return true;
260cdf0e10cSrcweir         }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 		// ---------------------------------------------------------------------
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         bool MediaShape::implIsIntrinsicAnimationPlaying() const
265cdf0e10cSrcweir         {
266cdf0e10cSrcweir             return mbIsPlaying;
267cdf0e10cSrcweir         }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 		// ---------------------------------------------------------------------
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         void MediaShape::implSetIntrinsicAnimationTime(double fTime)
272cdf0e10cSrcweir         {
273cdf0e10cSrcweir             ::std::for_each( maViewMediaShapes.begin(),
274cdf0e10cSrcweir                              maViewMediaShapes.end(),
275cdf0e10cSrcweir                              ::boost::bind( &ViewMediaShape::setMediaTime,
276cdf0e10cSrcweir                                             _1, boost::cref(fTime)) );
277cdf0e10cSrcweir         }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 		// ---------------------------------------------------------------------
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         ShapeSharedPtr createMediaShape(
282cdf0e10cSrcweir             const uno::Reference< drawing::XShape >& xShape,
283cdf0e10cSrcweir             double                                   nPrio,
284cdf0e10cSrcweir             const SlideShowContext&                  rContext)
285cdf0e10cSrcweir         {
286cdf0e10cSrcweir             boost::shared_ptr< MediaShape > pMediaShape(
287cdf0e10cSrcweir                 new MediaShape(xShape, nPrio, rContext));
288cdf0e10cSrcweir 
289cdf0e10cSrcweir             return pMediaShape;
290cdf0e10cSrcweir         }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir }
294