1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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"
48 #include <boost/bind.hpp>
52 using namespace ::com::sun::star
;
59 /** Represents a media shape.
61 This implementation offers support for media shapes.
62 Such shapes need special treatment.
64 class MediaShape
: public ExternalShapeBase
67 /** Create a shape for the given XShape for a media object
70 The XShape to represent.
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
,
79 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
84 //------------------------------------------------------------------
86 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
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
;
111 MediaShape::MediaShape( const uno::Reference
< drawing::XShape
>& xShape
,
113 const SlideShowContext
& rContext
) :
114 ExternalShapeBase( xShape
, nPrio
, rContext
),
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());
136 // ---------------------------------------------------------------------
138 void MediaShape::implViewsChanged()
140 // resize all ViewShapes
141 ::std::for_each( maViewMediaShapes
.begin(),
142 maViewMediaShapes
.end(),
144 &ViewMediaShape::resize
,
146 ::boost::cref( getBounds())) );
149 // ---------------------------------------------------------------------
151 void MediaShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
154 maViewMediaShapes
.push_back(
155 ViewMediaShapeSharedPtr( new ViewMediaShape( rNewLayer
,
157 mxComponentContext
)));
159 // push new size to view shape
160 maViewMediaShapes
.back()->resize( getBounds() );
162 // render the Shape on the newly added ViewLayer
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(),
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(),
186 ::std::equal_to
< ViewLayerSharedPtr
>(),
187 ::boost::bind( &ViewMediaShape::getViewLayer
,
189 ::boost::cref( rLayer
) ) )) == aEnd
)
191 // view layer seemingly was not added, failed
195 // actually erase from container
196 maViewMediaShapes
.erase( aIter
, aEnd
);
201 // ---------------------------------------------------------------------
203 bool MediaShape::clearAllViewLayers()
205 maViewMediaShapes
.clear();
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(),
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
230 // ---------------------------------------------------------------------
232 bool MediaShape::implStartIntrinsicAnimation()
234 ::std::for_each( maViewMediaShapes
.begin(),
235 maViewMediaShapes
.end(),
236 ::boost::mem_fn( &ViewMediaShape::startMedia
) );
243 // ---------------------------------------------------------------------
245 bool MediaShape::implEndIntrinsicAnimation()
247 ::std::for_each( maViewMediaShapes
.begin(),
248 maViewMediaShapes
.end(),
249 ::boost::mem_fn( &ViewMediaShape::endMedia
) );
256 // ---------------------------------------------------------------------
258 bool MediaShape::implPauseIntrinsicAnimation()
260 ::std::for_each( maViewMediaShapes
.begin(),
261 maViewMediaShapes
.end(),
262 ::boost::mem_fn( &ViewMediaShape::pauseMedia
) );
269 // ---------------------------------------------------------------------
271 bool MediaShape::implIsIntrinsicAnimationPlaying() const
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
,
291 const SlideShowContext
& rContext
)
293 boost::shared_ptr
< MediaShape
> pMediaShape(
294 new MediaShape(xShape
, nPrio
, rContext
));