android: Update app-specific/MIME type icons
[LibreOffice.git] / slideshow / source / engine / shapes / appletshape.cxx
blob6cc16ad6e500f7923ef0027aa0e36c48b9eada46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 #include <tools.hxx>
26 #include <o3tl/safeint.hxx>
27 #include <osl/diagnose.h>
29 #include <algorithm>
30 #include <utility>
33 using namespace ::com::sun::star;
36 namespace slideshow::internal
38 namespace {
40 /** Represents an applet shape.
42 This implementation offers support for applet shapes (both
43 Java applets, and Netscape plugins). Such shapes need
44 special treatment.
46 class AppletShape : public ExternalShapeBase
48 public:
49 /** Create a shape for the given XShape for an applet object
51 @param xShape
52 The XShape to represent.
54 @param nPrio
55 Externally-determined shape priority (used e.g. for
56 paint ordering). This number _must be_ unique!
58 @param rServiceName
59 Service name to use, when creating the actual viewer
60 component
62 @param pPropCopyTable
63 Table of plain ASCII property names, to copy from
64 xShape to applet.
66 @param nNumPropEntries
67 Number of property table entries (in pPropCopyTable)
69 AppletShape( const css::uno::Reference< css::drawing::XShape >& xShape,
70 double nPrio,
71 OUString aServiceName,
72 const char** pPropCopyTable,
73 std::size_t nNumPropEntries,
74 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
76 private:
78 // View layer methods
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;
106 bool mbIsPlaying;
111 AppletShape::AppletShape( const uno::Reference< drawing::XShape >& xShape,
112 double nPrio,
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(),
122 mbIsPlaying(false)
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,
149 bool bRedrawLayer )
153 maViewAppletShapes.push_back(
154 std::make_shared<ViewAppletShape>( rNewLayer,
155 getXShape(),
156 maServiceName,
157 mpPropCopyTable,
158 mnNumPropEntries,
159 mxComponentContext ));
161 // push new size to view shape
162 maViewAppletShapes.back()->resize( getBounds() );
164 // render the Shape on the newly added ViewLayer
165 if( bRedrawLayer )
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(),
181 aEnd,
182 [&rLayer]
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(),
190 aEnd,
191 [&rLayer]
192 ( const ViewAppletShapeSharedPtr& pShape )
193 { return rLayer == pShape->getViewLayer(); } ) ) == aEnd )
195 // view layer seemingly was not added, failed
196 return false;
199 // actually erase from container
200 maViewAppletShapes.erase( aIter, aEnd );
202 return true;
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(),
217 [&rCurrBounds]
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
224 return false;
227 return true;
231 bool AppletShape::implStartIntrinsicAnimation()
233 const ::basegfx::B2DRectangle& rBounds = getBounds();
234 for( const auto& pViewAppletShape : maViewAppletShapes )
235 pViewAppletShape->startApplet( rBounds );
237 mbIsPlaying = true;
239 return true;
243 bool AppletShape::implEndIntrinsicAnimation()
245 for( const auto& pViewAppletShape : maViewAppletShapes )
246 pViewAppletShape->endApplet();
248 mbIsPlaying = false;
250 return true;
254 void AppletShape::implPauseIntrinsicAnimation()
256 // TODO(F1): any way of temporarily disabling/deactivating
257 // applets?
261 bool AppletShape::implIsIntrinsicAnimationPlaying() const
263 return mbIsPlaying;
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,
274 double nPrio,
275 const OUString& rServiceName,
276 const char** pPropCopyTable,
277 std::size_t nNumPropEntries,
278 const SlideShowContext& rContext )
280 return std::make_shared<AppletShape>(xShape,
281 nPrio,
282 rServiceName,
283 pPropCopyTable,
284 nNumPropEntries,
285 rContext);
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */