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 "appletshape.hxx"
22 #include "externalshapebase.hxx"
23 #include "viewappletshape.hxx"
26 #include <o3tl/safeint.hxx>
27 #include <osl/diagnose.h>
33 using namespace ::com::sun::star
;
36 namespace slideshow::internal
40 /** Represents an applet shape.
42 This implementation offers support for applet shapes (both
43 Java applets, and Netscape plugins). Such shapes need
46 class AppletShape
: public ExternalShapeBase
49 /** Create a shape for the given XShape for an applet object
52 The XShape to represent.
55 Externally-determined shape priority (used e.g. for
56 paint ordering). This number _must be_ unique!
59 Service name to use, when creating the actual viewer
63 Table of plain ASCII property names, to copy from
66 @param nNumPropEntries
67 Number of property table entries (in pPropCopyTable)
69 AppletShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
,
71 OUString aServiceName
,
72 const char** pPropCopyTable
,
73 std::size_t nNumPropEntries
,
74 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
81 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
82 bool bRedrawLayer
) override
;
83 virtual bool removeViewLayer( const ViewLayerSharedPtr
& rNewLayer
) override
;
84 virtual void clearAllViewLayers() override
;
87 // ExternalShapeBase methods
90 virtual bool implRender( const ::basegfx::B2DRange
& rCurrBounds
) const override
;
91 virtual void implViewChanged( const UnoViewSharedPtr
& rView
) override
;
92 virtual void implViewsChanged() override
;
93 virtual bool implStartIntrinsicAnimation() override
;
94 virtual bool implEndIntrinsicAnimation() override
;
95 virtual void implPauseIntrinsicAnimation() override
;
96 virtual bool implIsIntrinsicAnimationPlaying() const override
;
97 virtual void implSetIntrinsicAnimationTime(double) override
;
99 const OUString maServiceName
;
100 const char** mpPropCopyTable
;
101 const std::size_t mnNumPropEntries
;
103 /// the list of active view shapes (one for each registered view layer)
104 typedef ::std::vector
< ViewAppletShapeSharedPtr
> ViewAppletShapeVector
;
105 ViewAppletShapeVector maViewAppletShapes
;
111 AppletShape::AppletShape( const uno::Reference
< drawing::XShape
>& xShape
,
113 OUString aServiceName
,
114 const char** pPropCopyTable
,
115 std::size_t nNumPropEntries
,
116 const SlideShowContext
& rContext
) :
117 ExternalShapeBase( xShape
, nPrio
, rContext
),
118 maServiceName(std::move( aServiceName
)),
119 mpPropCopyTable( pPropCopyTable
),
120 mnNumPropEntries( nNumPropEntries
),
121 maViewAppletShapes(),
127 void AppletShape::implViewChanged( const UnoViewSharedPtr
& rView
)
129 const ::basegfx::B2DRectangle
& rBounds
= getBounds();
130 // determine ViewAppletShape that needs update
131 for( const auto& pViewAppletShape
: maViewAppletShapes
)
133 if( pViewAppletShape
->getViewLayer()->isOnView( rView
) )
134 pViewAppletShape
->resize( rBounds
);
139 void AppletShape::implViewsChanged()
141 // resize all ViewShapes
142 const ::basegfx::B2DRectangle
& rBounds
= getBounds();
143 for( const auto& pViewAppletShape
: maViewAppletShapes
)
144 pViewAppletShape
->resize( rBounds
);
148 void AppletShape::addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
153 maViewAppletShapes
.push_back(
154 std::make_shared
<ViewAppletShape
>( rNewLayer
,
159 mxComponentContext
));
161 // push new size to view shape
162 maViewAppletShapes
.back()->resize( getBounds() );
164 // render the Shape on the newly added ViewLayer
166 maViewAppletShapes
.back()->render( getBounds() );
168 catch(uno::Exception
&)
170 // ignore failed shapes - slideshow should run with
171 // the remaining content
176 bool AppletShape::removeViewLayer( const ViewLayerSharedPtr
& rLayer
)
178 const ViewAppletShapeVector::iterator
aEnd( maViewAppletShapes
.end() );
180 OSL_ENSURE( ::std::count_if(maViewAppletShapes
.begin(),
183 ( const ViewAppletShapeSharedPtr
& pShape
)
184 { return rLayer
== pShape
->getViewLayer(); } ) < 2,
185 "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
187 ViewAppletShapeVector::iterator aIter
;
189 if( (aIter
=::std::remove_if( maViewAppletShapes
.begin(),
192 ( const ViewAppletShapeSharedPtr
& pShape
)
193 { return rLayer
== pShape
->getViewLayer(); } ) ) == aEnd
)
195 // view layer seemingly was not added, failed
199 // actually erase from container
200 maViewAppletShapes
.erase( aIter
, aEnd
);
206 void AppletShape::clearAllViewLayers()
208 maViewAppletShapes
.clear();
212 bool AppletShape::implRender( const ::basegfx::B2DRange
& rCurrBounds
) const
214 // redraw all view shapes, by calling their update() method
215 if( o3tl::make_unsigned(::std::count_if( maViewAppletShapes
.begin(),
216 maViewAppletShapes
.end(),
218 ( const ViewAppletShapeSharedPtr
& pShape
)
219 { return pShape
->render( rCurrBounds
); } ))
220 != maViewAppletShapes
.size() )
222 // at least one of the ViewShape::update() calls did return
223 // false - update failed on at least one ViewLayer
231 bool AppletShape::implStartIntrinsicAnimation()
233 const ::basegfx::B2DRectangle
& rBounds
= getBounds();
234 for( const auto& pViewAppletShape
: maViewAppletShapes
)
235 pViewAppletShape
->startApplet( rBounds
);
243 bool AppletShape::implEndIntrinsicAnimation()
245 for( const auto& pViewAppletShape
: maViewAppletShapes
)
246 pViewAppletShape
->endApplet();
254 void AppletShape::implPauseIntrinsicAnimation()
256 // TODO(F1): any way of temporarily disabling/deactivating
261 bool AppletShape::implIsIntrinsicAnimationPlaying() const
267 void AppletShape::implSetIntrinsicAnimationTime(double)
269 // No way of doing this, or?
272 std::shared_ptr
<Shape
> createAppletShape(
273 const uno::Reference
< drawing::XShape
>& xShape
,
275 const OUString
& rServiceName
,
276 const char** pPropCopyTable
,
277 std::size_t nNumPropEntries
,
278 const SlideShowContext
& rContext
)
280 return std::make_shared
<AppletShape
>(xShape
,
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */