Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : // must be first
22 : #include <canvas/debug.hxx>
23 : #include <canvas/verbosetrace.hxx>
24 : #include <canvas/canvastools.hxx>
25 :
26 : #include <com/sun/star/drawing/XShape.hpp>
27 :
28 : #include "mediashape.hxx"
29 : #include "viewmediashape.hxx"
30 : #include "externalshapebase.hxx"
31 : #include "slideshowcontext.hxx"
32 : #include "shape.hxx"
33 : #include "tools.hxx"
34 :
35 : #include <boost/bind.hpp>
36 : #include <algorithm>
37 :
38 :
39 : using namespace ::com::sun::star;
40 :
41 :
42 : namespace slideshow
43 : {
44 : namespace internal
45 : {
46 : /** Represents a media shape.
47 :
48 : This implementation offers support for media shapes.
49 : Such shapes need special treatment.
50 : */
51 0 : class MediaShape : public ExternalShapeBase
52 : {
53 : public:
54 : /** Create a shape for the given XShape for a media object
55 :
56 : @param xShape
57 : The XShape to represent.
58 :
59 : @param nPrio
60 : Externally-determined shape priority (used e.g. for
61 : paint ordering). This number _must be_ unique!
62 : */
63 : MediaShape( const ::com::sun::star::uno::Reference<
64 : ::com::sun::star::drawing::XShape >& xShape,
65 : double nPrio,
66 : const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
67 :
68 : private:
69 :
70 : // View layer methods
71 :
72 :
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;
77 :
78 :
79 : // ExternalShapeBase methods
80 :
81 :
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;
90 :
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;
95 : };
96 :
97 :
98 0 : MediaShape::MediaShape( const uno::Reference< drawing::XShape >& xShape,
99 : double nPrio,
100 : const SlideShowContext& rContext ) :
101 : ExternalShapeBase( xShape, nPrio, rContext ),
102 : maViewMediaShapes(),
103 0 : mbIsPlaying(false)
104 : {
105 0 : }
106 :
107 :
108 :
109 0 : void MediaShape::implViewChanged( const UnoViewSharedPtr& rView )
110 : {
111 : // determine ViewMediaShape that needs update
112 0 : ViewMediaShapeVector::const_iterator aIter(maViewMediaShapes.begin());
113 0 : ViewMediaShapeVector::const_iterator const aEnd (maViewMediaShapes.end());
114 0 : while( aIter != aEnd )
115 : {
116 0 : if( (*aIter)->getViewLayer()->isOnView(rView) )
117 0 : (*aIter)->resize(getBounds());
118 :
119 0 : ++aIter;
120 : }
121 0 : }
122 :
123 :
124 :
125 0 : void MediaShape::implViewsChanged()
126 : {
127 : // resize all ViewShapes
128 0 : ::basegfx::B2DRectangle bounds( getBounds() );
129 : ::std::for_each( maViewMediaShapes.begin(),
130 : maViewMediaShapes.end(),
131 : ::boost::bind(
132 : &ViewMediaShape::resize,
133 : _1,
134 0 : ::boost::cref( bounds )) );
135 0 : }
136 :
137 :
138 :
139 0 : void MediaShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
140 : bool bRedrawLayer )
141 : {
142 : maViewMediaShapes.push_back(
143 : ViewMediaShapeSharedPtr( new ViewMediaShape( rNewLayer,
144 0 : getXShape(),
145 0 : mxComponentContext )));
146 :
147 : // push new size to view shape
148 0 : maViewMediaShapes.back()->resize( getBounds() );
149 :
150 : // render the Shape on the newly added ViewLayer
151 0 : if( bRedrawLayer )
152 0 : maViewMediaShapes.back()->render( getBounds() );
153 0 : }
154 :
155 :
156 :
157 0 : bool MediaShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
158 : {
159 0 : const ViewMediaShapeVector::iterator aEnd( maViewMediaShapes.end() );
160 :
161 : OSL_ENSURE( ::std::count_if(maViewMediaShapes.begin(),
162 : aEnd,
163 : ::boost::bind<bool>(
164 : ::std::equal_to< ViewLayerSharedPtr >(),
165 : ::boost::bind( &ViewMediaShape::getViewLayer, _1 ),
166 : ::boost::cref( rLayer ) ) ) < 2,
167 : "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" );
168 :
169 0 : ViewMediaShapeVector::iterator aIter;
170 :
171 0 : if( (aIter=::std::remove_if( maViewMediaShapes.begin(),
172 : aEnd,
173 : ::boost::bind<bool>(
174 : ::std::equal_to< ViewLayerSharedPtr >(),
175 : ::boost::bind( &ViewMediaShape::getViewLayer,
176 : _1 ),
177 0 : ::boost::cref( rLayer ) ) )) == aEnd )
178 : {
179 : // view layer seemingly was not added, failed
180 0 : return false;
181 : }
182 :
183 : // actually erase from container
184 0 : maViewMediaShapes.erase( aIter, aEnd );
185 :
186 0 : return true;
187 : }
188 :
189 :
190 :
191 0 : bool MediaShape::clearAllViewLayers()
192 : {
193 0 : maViewMediaShapes.clear();
194 0 : return true;
195 : }
196 :
197 :
198 :
199 0 : bool MediaShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
200 : {
201 : // redraw all view shapes, by calling their update() method
202 0 : if( ::std::count_if( maViewMediaShapes.begin(),
203 : maViewMediaShapes.end(),
204 : ::boost::bind<bool>(
205 : ::boost::mem_fn( &ViewMediaShape::render ),
206 : _1,
207 0 : ::boost::cref( rCurrBounds ) ) )
208 0 : != static_cast<ViewMediaShapeVector::difference_type>(maViewMediaShapes.size()) )
209 : {
210 : // at least one of the ViewShape::update() calls did return
211 : // false - update failed on at least one ViewLayer
212 0 : return false;
213 : }
214 :
215 0 : return true;
216 : }
217 :
218 :
219 :
220 0 : bool MediaShape::implStartIntrinsicAnimation()
221 : {
222 : ::std::for_each( maViewMediaShapes.begin(),
223 : maViewMediaShapes.end(),
224 0 : ::boost::mem_fn( &ViewMediaShape::startMedia ) );
225 :
226 0 : mbIsPlaying = true;
227 :
228 0 : return true;
229 : }
230 :
231 :
232 :
233 0 : bool MediaShape::implEndIntrinsicAnimation()
234 : {
235 : ::std::for_each( maViewMediaShapes.begin(),
236 : maViewMediaShapes.end(),
237 0 : ::boost::mem_fn( &ViewMediaShape::endMedia ) );
238 :
239 0 : mbIsPlaying = false;
240 :
241 0 : return true;
242 : }
243 :
244 :
245 :
246 0 : bool MediaShape::implPauseIntrinsicAnimation()
247 : {
248 : ::std::for_each( maViewMediaShapes.begin(),
249 : maViewMediaShapes.end(),
250 0 : ::boost::mem_fn( &ViewMediaShape::pauseMedia ) );
251 :
252 0 : mbIsPlaying = false;
253 :
254 0 : return true;
255 : }
256 :
257 :
258 :
259 0 : bool MediaShape::implIsIntrinsicAnimationPlaying() const
260 : {
261 0 : return mbIsPlaying;
262 : }
263 :
264 :
265 :
266 0 : void MediaShape::implSetIntrinsicAnimationTime(double fTime)
267 : {
268 : ::std::for_each( maViewMediaShapes.begin(),
269 : maViewMediaShapes.end(),
270 : ::boost::bind( &ViewMediaShape::setMediaTime,
271 0 : _1, boost::cref(fTime)) );
272 0 : }
273 :
274 :
275 :
276 0 : ShapeSharedPtr createMediaShape(
277 : const uno::Reference< drawing::XShape >& xShape,
278 : double nPrio,
279 : const SlideShowContext& rContext)
280 : {
281 : boost::shared_ptr< MediaShape > pMediaShape(
282 0 : new MediaShape(xShape, nPrio, rContext));
283 :
284 0 : return pMediaShape;
285 : }
286 :
287 : }
288 6 : }
289 :
290 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|