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
;
95 MediaShape::MediaShape( const uno::Reference
< drawing::XShape
>& xShape
,
97 const SlideShowContext
& rContext
) :
98 ExternalShapeBase( xShape
, nPrio
, rContext
),
105 void MediaShape::implViewChanged( const UnoViewSharedPtr
& rView
)
107 const ::basegfx::B2DRectangle
& rBounds
= getBounds();
108 // determine ViewMediaShape that needs update
109 for( const auto& pViewMediaShape
: maViewMediaShapes
)
110 if( pViewMediaShape
->getViewLayer()->isOnView( rView
) )
111 pViewMediaShape
->resize( rBounds
);
115 void MediaShape::implViewsChanged()
117 const ::basegfx::B2DRectangle
& rBounds
= getBounds();
118 // resize all ViewShapes
119 for( const auto& pViewMediaShape
: maViewMediaShapes
)
120 pViewMediaShape
->resize( rBounds
);
124 void MediaShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
127 maViewMediaShapes
.push_back(
128 std::make_shared
<ViewMediaShape
>( rNewLayer
,
130 mxComponentContext
));
132 // push new size to view shape
133 maViewMediaShapes
.back()->resize( getBounds() );
135 // render the Shape on the newly added ViewLayer
137 maViewMediaShapes
.back()->render( getBounds() );
141 bool MediaShape::removeViewLayer( const ViewLayerSharedPtr
& rLayer
)
143 const ViewMediaShapeVector::iterator
aEnd( maViewMediaShapes
.end() );
145 OSL_ENSURE( ::std::count_if(maViewMediaShapes
.begin(),
148 ( const ViewMediaShapeSharedPtr
& pShape
)
149 { return rLayer
== pShape
->getViewLayer(); } ) < 2,
150 "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" );
152 ViewMediaShapeVector::iterator aIter
;
154 if( (aIter
=::std::remove_if( maViewMediaShapes
.begin(),
157 ( const ViewMediaShapeSharedPtr
& pShape
)
158 { return rLayer
== pShape
->getViewLayer(); } ) ) == aEnd
)
160 // view layer seemingly was not added, failed
164 // actually erase from container
165 maViewMediaShapes
.erase( aIter
, aEnd
);
171 void MediaShape::clearAllViewLayers()
173 maViewMediaShapes
.clear();
177 bool MediaShape::implRender( const ::basegfx::B2DRange
& rCurrBounds
) const
179 // redraw all view shapes, by calling their update() method
180 if( o3tl::make_unsigned(::std::count_if( maViewMediaShapes
.begin(),
181 maViewMediaShapes
.end(),
183 ( const ViewMediaShapeSharedPtr
& pShape
)
184 { return pShape
->render( rCurrBounds
); } ))
185 != maViewMediaShapes
.size() )
187 // at least one of the ViewShape::update() calls did return
188 // false - update failed on at least one ViewLayer
196 bool MediaShape::implStartIntrinsicAnimation()
198 for( const auto& pViewMediaShape
: maViewMediaShapes
)
199 pViewMediaShape
->startMedia();
207 bool MediaShape::implEndIntrinsicAnimation()
209 for( const auto& pViewMediaShape
: maViewMediaShapes
)
210 pViewMediaShape
->endMedia();
218 void MediaShape::implPauseIntrinsicAnimation()
220 for( const auto& pViewMediaShape
: maViewMediaShapes
)
221 pViewMediaShape
->pauseMedia();
227 bool MediaShape::implIsIntrinsicAnimationPlaying() const
233 void MediaShape::implSetIntrinsicAnimationTime(double fTime
)
235 for( const auto& pViewMediaShape
: maViewMediaShapes
)
236 pViewMediaShape
->setMediaTime( fTime
);
239 void MediaShape::implSetLooping(bool bLooping
)
241 for (const auto& pViewMediaShape
: maViewMediaShapes
)
243 pViewMediaShape
->setLooping(bLooping
);
247 ShapeSharedPtr
createMediaShape(
248 const uno::Reference
< drawing::XShape
>& xShape
,
250 const SlideShowContext
& rContext
)
252 return std::make_shared
<MediaShape
>(xShape
, nPrio
, rContext
);
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */