Use o3tl::convert in Math
[LibreOffice.git] / slideshow / source / engine / shapes / appletshape.cxx
blob102dc6aaf3f4ccc6793c07cb11295fd1fd648a01
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 <osl/diagnose.h>
28 #include <algorithm>
31 using namespace ::com::sun::star;
34 namespace slideshow::internal
36 namespace {
38 /** Represents an applet shape.
40 This implementation offers support for applet shapes (both
41 Java applets, and Netscape plugins). Such shapes need
42 special treatment.
44 class AppletShape : public ExternalShapeBase
46 public:
47 /** Create a shape for the given XShape for an applet object
49 @param xShape
50 The XShape to represent.
52 @param nPrio
53 Externally-determined shape priority (used e.g. for
54 paint ordering). This number _must be_ unique!
56 @param rServiceName
57 Service name to use, when creating the actual viewer
58 component
60 @param pPropCopyTable
61 Table of plain ASCII property names, to copy from
62 xShape to applet.
64 @param nNumPropEntries
65 Number of property table entries (in pPropCopyTable)
67 AppletShape( const css::uno::Reference< css::drawing::XShape >& xShape,
68 double nPrio,
69 const OUString& rServiceName,
70 const char** pPropCopyTable,
71 std::size_t nNumPropEntries,
72 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
74 private:
76 // View layer methods
79 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
80 bool bRedrawLayer ) override;
81 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) override;
82 virtual void clearAllViewLayers() override;
85 // ExternalShapeBase methods
88 virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const override;
89 virtual void implViewChanged( const UnoViewSharedPtr& rView ) override;
90 virtual void implViewsChanged() override;
91 virtual bool implStartIntrinsicAnimation() override;
92 virtual bool implEndIntrinsicAnimation() override;
93 virtual void implPauseIntrinsicAnimation() override;
94 virtual bool implIsIntrinsicAnimationPlaying() const override;
95 virtual void implSetIntrinsicAnimationTime(double) override;
97 const OUString maServiceName;
98 const char** mpPropCopyTable;
99 const std::size_t mnNumPropEntries;
101 /// the list of active view shapes (one for each registered view layer)
102 typedef ::std::vector< ViewAppletShapeSharedPtr > ViewAppletShapeVector;
103 ViewAppletShapeVector maViewAppletShapes;
104 bool mbIsPlaying;
109 AppletShape::AppletShape( const uno::Reference< drawing::XShape >& xShape,
110 double nPrio,
111 const OUString& rServiceName,
112 const char** pPropCopyTable,
113 std::size_t nNumPropEntries,
114 const SlideShowContext& rContext ) :
115 ExternalShapeBase( xShape, nPrio, rContext ),
116 maServiceName( rServiceName ),
117 mpPropCopyTable( pPropCopyTable ),
118 mnNumPropEntries( nNumPropEntries ),
119 maViewAppletShapes(),
120 mbIsPlaying(false)
125 void AppletShape::implViewChanged( const UnoViewSharedPtr& rView )
127 const ::basegfx::B2DRectangle& rBounds = getBounds();
128 // determine ViewAppletShape that needs update
129 for( const auto& pViewAppletShape : maViewAppletShapes )
131 if( pViewAppletShape->getViewLayer()->isOnView( rView ) )
132 pViewAppletShape->resize( rBounds );
137 void AppletShape::implViewsChanged()
139 // resize all ViewShapes
140 const ::basegfx::B2DRectangle& rBounds = getBounds();
141 for( const auto& pViewAppletShape : maViewAppletShapes )
142 pViewAppletShape->resize( rBounds );
146 void AppletShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
147 bool bRedrawLayer )
151 maViewAppletShapes.push_back(
152 std::make_shared<ViewAppletShape>( rNewLayer,
153 getXShape(),
154 maServiceName,
155 mpPropCopyTable,
156 mnNumPropEntries,
157 mxComponentContext ));
159 // push new size to view shape
160 maViewAppletShapes.back()->resize( getBounds() );
162 // render the Shape on the newly added ViewLayer
163 if( bRedrawLayer )
164 maViewAppletShapes.back()->render( getBounds() );
166 catch(uno::Exception&)
168 // ignore failed shapes - slideshow should run with
169 // the remaining content
174 bool AppletShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
176 const ViewAppletShapeVector::iterator aEnd( maViewAppletShapes.end() );
178 OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(),
179 aEnd,
180 [&rLayer]
181 ( const ViewAppletShapeSharedPtr& pShape )
182 { return rLayer == pShape->getViewLayer(); } ) < 2,
183 "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
185 ViewAppletShapeVector::iterator aIter;
187 if( (aIter=::std::remove_if( maViewAppletShapes.begin(),
188 aEnd,
189 [&rLayer]
190 ( const ViewAppletShapeSharedPtr& pShape )
191 { return rLayer == pShape->getViewLayer(); } ) ) == aEnd )
193 // view layer seemingly was not added, failed
194 return false;
197 // actually erase from container
198 maViewAppletShapes.erase( aIter, aEnd );
200 return true;
204 void AppletShape::clearAllViewLayers()
206 maViewAppletShapes.clear();
210 bool AppletShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
212 // redraw all view shapes, by calling their update() method
213 if( ::std::count_if( maViewAppletShapes.begin(),
214 maViewAppletShapes.end(),
215 [&rCurrBounds]
216 ( const ViewAppletShapeSharedPtr& pShape )
217 { return pShape->render( rCurrBounds ); } )
218 != static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) )
220 // at least one of the ViewShape::update() calls did return
221 // false - update failed on at least one ViewLayer
222 return false;
225 return true;
229 bool AppletShape::implStartIntrinsicAnimation()
231 const ::basegfx::B2DRectangle& rBounds = getBounds();
232 for( const auto& pViewAppletShape : maViewAppletShapes )
233 pViewAppletShape->startApplet( rBounds );
235 mbIsPlaying = true;
237 return true;
241 bool AppletShape::implEndIntrinsicAnimation()
243 for( const auto& pViewAppletShape : maViewAppletShapes )
244 pViewAppletShape->endApplet();
246 mbIsPlaying = false;
248 return true;
252 void AppletShape::implPauseIntrinsicAnimation()
254 // TODO(F1): any way of temporarily disabling/deactivating
255 // applets?
259 bool AppletShape::implIsIntrinsicAnimationPlaying() const
261 return mbIsPlaying;
265 void AppletShape::implSetIntrinsicAnimationTime(double)
267 // No way of doing this, or?
270 std::shared_ptr<Shape> createAppletShape(
271 const uno::Reference< drawing::XShape >& xShape,
272 double nPrio,
273 const OUString& rServiceName,
274 const char** pPropCopyTable,
275 std::size_t nNumPropEntries,
276 const SlideShowContext& rContext )
278 return std::make_shared<AppletShape>(xShape,
279 nPrio,
280 rServiceName,
281 pPropCopyTable,
282 nNumPropEntries,
283 rContext);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */