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 .
21 #include <com/sun/star/drawing/XShape.hpp>
22 #include <o3tl/safeint.hxx>
23 #include <osl/diagnose.h>
25 #include "mediashape.hxx"
26 #include "viewmediashape.hxx"
27 #include "externalshapebase.hxx"
28 #include <slideshowcontext.hxx>
35 using namespace ::com::sun::star
;
38 namespace slideshow::internal
42 /** Represents a media shape.
44 This implementation offers support for media shapes.
45 Such shapes need special treatment.
47 class MediaShape
: public ExternalShapeBase
50 /** Create a shape for the given XShape for a media object
53 The XShape to represent.
56 Externally-determined shape priority (used e.g. for
57 paint ordering). This number _must be_ unique!
59 MediaShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
,
61 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
68 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
69 bool bRedrawLayer
) override
;
70 virtual bool removeViewLayer( const ViewLayerSharedPtr
& rNewLayer
) override
;
71 virtual void clearAllViewLayers() override
;
74 // ExternalShapeBase methods
77 virtual bool implRender( const ::basegfx::B2DRange
& rCurrBounds
) const override
;
78 virtual void implViewChanged( const UnoViewSharedPtr
& rView
) override
;
79 virtual void implViewsChanged() override
;
80 virtual bool implStartIntrinsicAnimation() override
;
81 virtual bool implEndIntrinsicAnimation() override
;
82 virtual void implPauseIntrinsicAnimation() override
;
83 virtual bool implIsIntrinsicAnimationPlaying() const override
;
84 virtual void implSetIntrinsicAnimationTime(double) override
;
85 void implSetLooping(bool bLooping
) override
;
87 /// the list of active view shapes (one for each registered view layer)
88 typedef ::std::vector
< ViewMediaShapeSharedPtr
> ViewMediaShapeVector
;
89 ViewMediaShapeVector maViewMediaShapes
;
91 OUString maFallbackDir
;
96 MediaShape::MediaShape( const uno::Reference
< drawing::XShape
>& xShape
,
98 const SlideShowContext
& rContext
) :
99 ExternalShapeBase( xShape
, nPrio
, rContext
),
102 maFallbackDir(rContext
.maFallbackDir
)
107 void MediaShape::implViewChanged( const UnoViewSharedPtr
& rView
)
109 const ::basegfx::B2DRectangle aBounds
= getBounds();
110 // determine ViewMediaShape that needs update
111 for( const auto& pViewMediaShape
: maViewMediaShapes
)
112 if( pViewMediaShape
->getViewLayer()->isOnView( rView
) )
113 pViewMediaShape
->resize( aBounds
);
117 void MediaShape::implViewsChanged()
119 const ::basegfx::B2DRectangle aBounds
= getBounds();
120 // resize all ViewShapes
121 for( const auto& pViewMediaShape
: maViewMediaShapes
)
122 pViewMediaShape
->resize( aBounds
);
126 void MediaShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
129 maViewMediaShapes
.push_back(
130 std::make_shared
<ViewMediaShape
>( rNewLayer
,
135 // push new size to view shape
136 maViewMediaShapes
.back()->resize( getBounds() );
138 // render the Shape on the newly added ViewLayer
140 maViewMediaShapes
.back()->render( getBounds() );
144 bool MediaShape::removeViewLayer( const ViewLayerSharedPtr
& rLayer
)
146 const ViewMediaShapeVector::iterator
aEnd( maViewMediaShapes
.end() );
148 OSL_ENSURE( ::std::count_if(maViewMediaShapes
.begin(),
151 ( const ViewMediaShapeSharedPtr
& pShape
)
152 { return rLayer
== pShape
->getViewLayer(); } ) < 2,
153 "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" );
155 // TODO : needed for the moment since ANDROID doesn't know size_t return from std::erase_if
157 ViewMediaShapeVector::iterator aIter
;
159 if( (aIter
=::std::remove_if( maViewMediaShapes
.begin(),
162 ( const ViewMediaShapeSharedPtr
& pShape
)
163 { return rLayer
== pShape
->getViewLayer(); } ) ) == aEnd
)
165 // view layer seemingly was not added, failed
169 // actually erase from container
170 maViewMediaShapes
.erase( aIter
, aEnd
);
174 size_t nb
= std::erase_if(maViewMediaShapes
,
176 ( const ViewMediaShapeSharedPtr
& pShape
)
177 { return rLayer
== pShape
->getViewLayer(); } );
178 // if nb == 0, it means view media shape seemingly was not added, failed
184 void MediaShape::clearAllViewLayers()
186 maViewMediaShapes
.clear();
190 bool MediaShape::implRender( const ::basegfx::B2DRange
& rCurrBounds
) const
192 // redraw all view shapes, by calling their update() method
193 if( o3tl::make_unsigned(::std::count_if( maViewMediaShapes
.begin(),
194 maViewMediaShapes
.end(),
196 ( const ViewMediaShapeSharedPtr
& pShape
)
197 { return pShape
->render( rCurrBounds
); } ))
198 != maViewMediaShapes
.size() )
200 // at least one of the ViewShape::update() calls did return
201 // false - update failed on at least one ViewLayer
209 bool MediaShape::implStartIntrinsicAnimation()
211 for( const auto& pViewMediaShape
: maViewMediaShapes
)
212 pViewMediaShape
->startMedia();
220 bool MediaShape::implEndIntrinsicAnimation()
222 for( const auto& pViewMediaShape
: maViewMediaShapes
)
223 pViewMediaShape
->endMedia();
231 void MediaShape::implPauseIntrinsicAnimation()
233 for( const auto& pViewMediaShape
: maViewMediaShapes
)
234 pViewMediaShape
->pauseMedia();
240 bool MediaShape::implIsIntrinsicAnimationPlaying() const
246 void MediaShape::implSetIntrinsicAnimationTime(double fTime
)
248 for( const auto& pViewMediaShape
: maViewMediaShapes
)
249 pViewMediaShape
->setMediaTime( fTime
);
252 void MediaShape::implSetLooping(bool bLooping
)
254 for (const auto& pViewMediaShape
: maViewMediaShapes
)
256 pViewMediaShape
->setLooping(bLooping
);
260 ShapeSharedPtr
createMediaShape(
261 const uno::Reference
< drawing::XShape
>& xShape
,
263 const SlideShowContext
& rContext
)
265 return std::make_shared
<MediaShape
>(xShape
, nPrio
, rContext
);
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */