Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / shapes / appletshape.cxx
blobce20c907ae1bb1e7a4abfc01ad6b63416fd11f41
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 <canvas/canvastools.hxx>
23 #include "appletshape.hxx"
24 #include "externalshapebase.hxx"
25 #include <vieweventhandler.hxx>
26 #include "viewappletshape.hxx"
27 #include <tools.hxx>
29 #include <algorithm>
32 using namespace ::com::sun::star;
35 namespace slideshow
37 namespace internal
39 /** Represents an applet shape.
41 This implementation offers support for applet shapes (both
42 Java applets, and Netscape plugins). Such shapes need
43 special treatment.
45 class AppletShape : public ExternalShapeBase
47 public:
48 /** Create a shape for the given XShape for a applet object
50 @param xShape
51 The XShape to represent.
53 @param nPrio
54 Externally-determined shape priority (used e.g. for
55 paint ordering). This number _must be_ unique!
57 @param rServiceName
58 Service name to use, when creating the actual viewer
59 component
61 @param pPropCopyTable
62 Table of plain ASCII property names, to copy from
63 xShape to applet.
65 @param nNumPropEntries
66 Number of property table entries (in pPropCopyTable)
68 AppletShape( const css::uno::Reference< css::drawing::XShape >& xShape,
69 double nPrio,
70 const OUString& rServiceName,
71 const char** pPropCopyTable,
72 std::size_t nNumPropEntries,
73 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
75 private:
77 // View layer methods
80 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
81 bool bRedrawLayer ) override;
82 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) override;
83 virtual void clearAllViewLayers() override;
86 // ExternalShapeBase methods
89 virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const override;
90 virtual void implViewChanged( const UnoViewSharedPtr& rView ) override;
91 virtual void implViewsChanged() override;
92 virtual bool implStartIntrinsicAnimation() override;
93 virtual bool implEndIntrinsicAnimation() override;
94 virtual void implPauseIntrinsicAnimation() override;
95 virtual bool implIsIntrinsicAnimationPlaying() const override;
96 virtual void implSetIntrinsicAnimationTime(double) override;
98 const OUString maServiceName;
99 const char** mpPropCopyTable;
100 const std::size_t mnNumPropEntries;
102 /// the list of active view shapes (one for each registered view layer)
103 typedef ::std::vector< ViewAppletShapeSharedPtr > ViewAppletShapeVector;
104 ViewAppletShapeVector maViewAppletShapes;
105 bool mbIsPlaying;
108 AppletShape::AppletShape( const uno::Reference< drawing::XShape >& xShape,
109 double nPrio,
110 const OUString& rServiceName,
111 const char** pPropCopyTable,
112 std::size_t nNumPropEntries,
113 const SlideShowContext& rContext ) :
114 ExternalShapeBase( xShape, nPrio, rContext ),
115 maServiceName( rServiceName ),
116 mpPropCopyTable( pPropCopyTable ),
117 mnNumPropEntries( nNumPropEntries ),
118 maViewAppletShapes(),
119 mbIsPlaying(false)
124 void AppletShape::implViewChanged( const UnoViewSharedPtr& rView )
126 const ::basegfx::B2DRectangle& rBounds = getBounds();
127 // determine ViewAppletShape that needs update
128 for( const auto& pViewAppletShape : maViewAppletShapes )
130 if( pViewAppletShape->getViewLayer()->isOnView( rView ) )
131 pViewAppletShape->resize( rBounds );
136 void AppletShape::implViewsChanged()
138 // resize all ViewShapes
139 const ::basegfx::B2DRectangle& rBounds = getBounds();
140 for( const auto& pViewAppletShape : maViewAppletShapes )
141 pViewAppletShape->resize( rBounds );
145 void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
146 bool bRedrawLayer )
150 maViewAppletShapes.push_back(
151 std::make_shared<ViewAppletShape>( rNewLayer,
152 getXShape(),
153 maServiceName,
154 mpPropCopyTable,
155 mnNumPropEntries,
156 mxComponentContext ));
158 // push new size to view shape
159 maViewAppletShapes.back()->resize( getBounds() );
161 // render the Shape on the newly added ViewLayer
162 if( bRedrawLayer )
163 maViewAppletShapes.back()->render( getBounds() );
165 catch(uno::Exception&)
167 // ignore failed shapes - slideshow should run with
168 // the remaining content
173 bool AppletShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
175 const ViewAppletShapeVector::iterator aEnd( maViewAppletShapes.end() );
177 OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(),
178 aEnd,
179 [&rLayer]
180 ( const ViewAppletShapeSharedPtr& pShape )
181 { return rLayer == pShape->getViewLayer(); } ) < 2,
182 "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
184 ViewAppletShapeVector::iterator aIter;
186 if( (aIter=::std::remove_if( maViewAppletShapes.begin(),
187 aEnd,
188 [&rLayer]
189 ( const ViewAppletShapeSharedPtr& pShape )
190 { return rLayer == pShape->getViewLayer(); } ) ) == aEnd )
192 // view layer seemingly was not added, failed
193 return false;
196 // actually erase from container
197 maViewAppletShapes.erase( aIter, aEnd );
199 return true;
203 void AppletShape::clearAllViewLayers()
205 maViewAppletShapes.clear();
209 bool AppletShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
211 // redraw all view shapes, by calling their update() method
212 if( ::std::count_if( maViewAppletShapes.begin(),
213 maViewAppletShapes.end(),
214 [&rCurrBounds]
215 ( const ViewAppletShapeSharedPtr& pShape )
216 { return pShape->render( rCurrBounds ); } )
217 != static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) )
219 // at least one of the ViewShape::update() calls did return
220 // false - update failed on at least one ViewLayer
221 return false;
224 return true;
228 bool AppletShape::implStartIntrinsicAnimation()
230 const ::basegfx::B2DRectangle& rBounds = getBounds();
231 for( const auto& pViewAppletShape : maViewAppletShapes )
232 pViewAppletShape->startApplet( rBounds );
234 mbIsPlaying = true;
236 return true;
240 bool AppletShape::implEndIntrinsicAnimation()
242 for( const auto& pViewAppletShape : maViewAppletShapes )
243 pViewAppletShape->endApplet();
245 mbIsPlaying = false;
247 return true;
251 void AppletShape::implPauseIntrinsicAnimation()
253 // TODO(F1): any way of temporarily disabling/deactivating
254 // applets?
258 bool AppletShape::implIsIntrinsicAnimationPlaying() const
260 return mbIsPlaying;
264 void AppletShape::implSetIntrinsicAnimationTime(double)
266 // No way of doing this, or?
269 std::shared_ptr<Shape> createAppletShape(
270 const uno::Reference< drawing::XShape >& xShape,
271 double nPrio,
272 const OUString& rServiceName,
273 const char** pPropCopyTable,
274 std::size_t nNumPropEntries,
275 const SlideShowContext& rContext )
277 std::shared_ptr< AppletShape > pAppletShape(
278 new AppletShape(xShape,
279 nPrio,
280 rServiceName,
281 pPropCopyTable,
282 nNumPropEntries,
283 rContext) );
285 return pAppletShape;
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */