1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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"
35 #include <boost/bind.hpp>
39 using namespace ::com::sun::star
;
46 /** Represents a media shape.
48 This implementation offers support for media shapes.
49 Such shapes need special treatment.
51 class MediaShape
: public ExternalShapeBase
54 /** Create a shape for the given XShape for a media object
57 The XShape to represent.
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
,
66 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
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
;
98 MediaShape::MediaShape( const uno::Reference
< drawing::XShape
>& xShape
,
100 const SlideShowContext
& rContext
) :
101 ExternalShapeBase( xShape
, nPrio
, rContext
),
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());
125 void MediaShape::implViewsChanged()
127 // resize all ViewShapes
128 ::std::for_each( maViewMediaShapes
.begin(),
129 maViewMediaShapes
.end(),
131 &ViewMediaShape::resize
,
138 void MediaShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
141 maViewMediaShapes
.push_back(
142 ViewMediaShapeSharedPtr( new ViewMediaShape( rNewLayer
,
144 mxComponentContext
)));
146 // push new size to view shape
147 maViewMediaShapes
.back()->resize( getBounds() );
149 // render the Shape on the newly added ViewLayer
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(),
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(),
173 ::std::equal_to
< ViewLayerSharedPtr
>(),
174 ::boost::bind( &ViewMediaShape::getViewLayer
,
176 ::boost::cref( rLayer
) ) )) == aEnd
)
178 // view layer seemingly was not added, failed
182 // actually erase from container
183 maViewMediaShapes
.erase( aIter
, aEnd
);
190 bool MediaShape::clearAllViewLayers()
192 maViewMediaShapes
.clear();
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(),
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
219 bool MediaShape::implStartIntrinsicAnimation()
221 ::std::for_each( maViewMediaShapes
.begin(),
222 maViewMediaShapes
.end(),
223 ::boost::mem_fn( &ViewMediaShape::startMedia
) );
232 bool MediaShape::implEndIntrinsicAnimation()
234 ::std::for_each( maViewMediaShapes
.begin(),
235 maViewMediaShapes
.end(),
236 ::boost::mem_fn( &ViewMediaShape::endMedia
) );
245 bool MediaShape::implPauseIntrinsicAnimation()
247 ::std::for_each( maViewMediaShapes
.begin(),
248 maViewMediaShapes
.end(),
249 ::boost::mem_fn( &ViewMediaShape::pauseMedia
) );
258 bool MediaShape::implIsIntrinsicAnimationPlaying() const
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
,
278 const SlideShowContext
& rContext
)
280 boost::shared_ptr
< MediaShape
> pMediaShape(
281 new MediaShape(xShape
, nPrio
, rContext
));
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */