merge the formfield patch from ooo-build
[ooovba.git] / slideshow / source / engine / shapes / mediashape.cxx
blob2c398c2ac76ca772586b625530bd7e451028d791
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mediashape.cxx,v $
10 * $Revision: 1.3.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 // must be first
35 #include <canvas/debug.hxx>
36 #include <canvas/verbosetrace.hxx>
37 #include <canvas/canvastools.hxx>
39 #include <com/sun/star/drawing/XShape.hpp>
41 #include "mediashape.hxx"
42 #include "viewmediashape.hxx"
43 #include "externalshapebase.hxx"
44 #include "slideshowcontext.hxx"
45 #include "shape.hxx"
46 #include "tools.hxx"
48 #include <boost/bind.hpp>
49 #include <algorithm>
52 using namespace ::com::sun::star;
55 namespace slideshow
57 namespace internal
59 /** Represents a media shape.
61 This implementation offers support for media shapes.
62 Such shapes need special treatment.
64 class MediaShape : public ExternalShapeBase
66 public:
67 /** Create a shape for the given XShape for a media object
69 @param xShape
70 The XShape to represent.
72 @param nPrio
73 Externally-determined shape priority (used e.g. for
74 paint ordering). This number _must be_ unique!
76 MediaShape( const ::com::sun::star::uno::Reference<
77 ::com::sun::star::drawing::XShape >& xShape,
78 double nPrio,
79 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
81 private:
83 // View layer methods
84 //------------------------------------------------------------------
86 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
87 bool bRedrawLayer );
88 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer );
89 virtual bool clearAllViewLayers();
92 // ExternalShapeBase methods
93 //------------------------------------------------------------------
95 virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const;
96 virtual void implViewChanged( const UnoViewSharedPtr& rView );
97 virtual void implViewsChanged();
98 virtual bool implStartIntrinsicAnimation();
99 virtual bool implEndIntrinsicAnimation();
100 virtual bool implPauseIntrinsicAnimation();
101 virtual bool implIsIntrinsicAnimationPlaying() const;
102 virtual void implSetIntrinsicAnimationTime(double);
104 /// the list of active view shapes (one for each registered view layer)
105 typedef ::std::vector< ViewMediaShapeSharedPtr > ViewMediaShapeVector;
106 ViewMediaShapeVector maViewMediaShapes;
107 bool mbIsPlaying;
111 MediaShape::MediaShape( const uno::Reference< drawing::XShape >& xShape,
112 double nPrio,
113 const SlideShowContext& rContext ) :
114 ExternalShapeBase( xShape, nPrio, rContext ),
115 maViewMediaShapes(),
116 mbIsPlaying(false)
120 // ---------------------------------------------------------------------
122 void MediaShape::implViewChanged( const UnoViewSharedPtr& rView )
124 // determine ViewMediaShape that needs update
125 ViewMediaShapeVector::const_iterator aIter(maViewMediaShapes.begin());
126 ViewMediaShapeVector::const_iterator const aEnd (maViewMediaShapes.end());
127 while( aIter != aEnd )
129 if( (*aIter)->getViewLayer()->isOnView(rView) )
130 (*aIter)->resize(getBounds());
132 ++aIter;
136 // ---------------------------------------------------------------------
138 void MediaShape::implViewsChanged()
140 // resize all ViewShapes
141 ::std::for_each( maViewMediaShapes.begin(),
142 maViewMediaShapes.end(),
143 ::boost::bind(
144 &ViewMediaShape::resize,
146 ::boost::cref( getBounds())) );
149 // ---------------------------------------------------------------------
151 void MediaShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
152 bool bRedrawLayer )
154 maViewMediaShapes.push_back(
155 ViewMediaShapeSharedPtr( new ViewMediaShape( rNewLayer,
156 getXShape(),
157 mxComponentContext )));
159 // push new size to view shape
160 maViewMediaShapes.back()->resize( getBounds() );
162 // render the Shape on the newly added ViewLayer
163 if( bRedrawLayer )
164 maViewMediaShapes.back()->render( getBounds() );
167 // ---------------------------------------------------------------------
169 bool MediaShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
171 const ViewMediaShapeVector::iterator aEnd( maViewMediaShapes.end() );
173 OSL_ENSURE( ::std::count_if(maViewMediaShapes.begin(),
174 aEnd,
175 ::boost::bind<bool>(
176 ::std::equal_to< ViewLayerSharedPtr >(),
177 ::boost::bind( &ViewMediaShape::getViewLayer, _1 ),
178 ::boost::cref( rLayer ) ) ) < 2,
179 "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" );
181 ViewMediaShapeVector::iterator aIter;
183 if( (aIter=::std::remove_if( maViewMediaShapes.begin(),
184 aEnd,
185 ::boost::bind<bool>(
186 ::std::equal_to< ViewLayerSharedPtr >(),
187 ::boost::bind( &ViewMediaShape::getViewLayer,
188 _1 ),
189 ::boost::cref( rLayer ) ) )) == aEnd )
191 // view layer seemingly was not added, failed
192 return false;
195 // actually erase from container
196 maViewMediaShapes.erase( aIter, aEnd );
198 return true;
201 // ---------------------------------------------------------------------
203 bool MediaShape::clearAllViewLayers()
205 maViewMediaShapes.clear();
206 return true;
209 // ---------------------------------------------------------------------
211 bool MediaShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
213 // redraw all view shapes, by calling their update() method
214 if( ::std::count_if( maViewMediaShapes.begin(),
215 maViewMediaShapes.end(),
216 ::boost::bind<bool>(
217 ::boost::mem_fn( &ViewMediaShape::render ),
219 ::boost::cref( rCurrBounds ) ) )
220 != static_cast<ViewMediaShapeVector::difference_type>(maViewMediaShapes.size()) )
222 // at least one of the ViewShape::update() calls did return
223 // false - update failed on at least one ViewLayer
224 return false;
227 return true;
230 // ---------------------------------------------------------------------
232 bool MediaShape::implStartIntrinsicAnimation()
234 ::std::for_each( maViewMediaShapes.begin(),
235 maViewMediaShapes.end(),
236 ::boost::mem_fn( &ViewMediaShape::startMedia ) );
238 mbIsPlaying = true;
240 return true;
243 // ---------------------------------------------------------------------
245 bool MediaShape::implEndIntrinsicAnimation()
247 ::std::for_each( maViewMediaShapes.begin(),
248 maViewMediaShapes.end(),
249 ::boost::mem_fn( &ViewMediaShape::endMedia ) );
251 mbIsPlaying = false;
253 return true;
256 // ---------------------------------------------------------------------
258 bool MediaShape::implPauseIntrinsicAnimation()
260 ::std::for_each( maViewMediaShapes.begin(),
261 maViewMediaShapes.end(),
262 ::boost::mem_fn( &ViewMediaShape::pauseMedia ) );
264 mbIsPlaying = false;
266 return true;
269 // ---------------------------------------------------------------------
271 bool MediaShape::implIsIntrinsicAnimationPlaying() const
273 return mbIsPlaying;
276 // ---------------------------------------------------------------------
278 void MediaShape::implSetIntrinsicAnimationTime(double fTime)
280 ::std::for_each( maViewMediaShapes.begin(),
281 maViewMediaShapes.end(),
282 ::boost::bind( &ViewMediaShape::setMediaTime,
283 _1, boost::cref(fTime)) );
286 // ---------------------------------------------------------------------
288 ShapeSharedPtr createMediaShape(
289 const uno::Reference< drawing::XShape >& xShape,
290 double nPrio,
291 const SlideShowContext& rContext)
293 boost::shared_ptr< MediaShape > pMediaShape(
294 new MediaShape(xShape, nPrio, rContext));
296 return pMediaShape;